let rec escapesRec cr ci it zr zi = if it == 0 then false else if (zr*.zr +. zi*.zi) > 4.0 then true else escapesRec cr ci (it-1) (zr*.zr -. zi*.zi +. cr) (2.0*.zr*.zi +. ci) let escapes cr ci it = escapesRec cr ci it 0.0 0.0 let toChar b = if b then ' ' else 'X' let main () = let xmin = -2.0 in let xmax = 1.0 in let ymin = -1.0 in let ymax = 1.0 in let xstep = int_of_string Sys.argv.(1) in let ystep = int_of_string Sys.argv.(2) in let iterations = int_of_string Sys.argv.(3) in for yc = 0 to ystep-1 do let y = (float_of_int yc) *. (ymax -. ymin) /. (float_of_int ystep) +. ymin in for xc = 0 to xstep-1 do let x = (float_of_int xc) *. (xmax -. xmin) /. (float_of_int xstep) +. xmin in print_char (toChar (escapes x y iterations)) done; print_char '\n' done ;; main ()