let f = function n when n mod 2 = 0 -> n / 2 | n -> (3 * n + 1) / 2 let make_char = function n when n mod 2 = 0 -> " " | n -> "#" let call_nth n f init = let rec inner rv k = function m when n <= m -> List.rev rv | m -> let next = f k in inner ([next] @ rv) next (m + 1) in inner [init] init 0 let make_line n = String.concat "" (List.map make_char (call_nth 63 f n)) let () = for n = 256 downto -256 do Printf.printf "%s|\n" (make_line n) done

Note that non-ascii characters in the above source code will be escaped (such as \x9f).