Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let cur_max = ref 0;;
- let next n =
- match n with
- | n when (n mod 2 = 0) -> n/2
- | n -> 3*n + 1
- in
- let rec calc num steps =
- if num = 1 then steps else calc (next num) (steps + 1)
- in
- let rec check_million start =
- let steps = calc start 1 in
- Printf.printf "Checking %d\n" start;
- if start mod 10000 = 0 then (Printf.printf "Starting at %d\n" start);
- if steps > !cur_max then (
- Printf.printf "New maximum value: %d for number %d\n" steps start;
- flush stdout;
- cur_max := steps;
- ()
- );
- if start <= 1000000 then check_million (start + 1);
- in
- check_million 1;;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement