Commits

Michael O'Neill  committed 196d261

Add splitter. Needs better output and maybe sorting.

  • Participants
  • Parent commits 3e12808

Comments (0)

Files changed (1)

+print_endline("Splits a list into two based on divisibility by 2.");;
+
+let rec fr ic l =
+   try
+      fr ic l@[(int_of_string (input_line ic))]
+   with
+      End_of_file -> l
+;;
+
+let rec splitter ll e o = 
+   match ll with 
+     [] -> e,o
+   | h::t -> if (h mod 2) = 0 then (splitter t (h::e) o) else (splitter t e (h::o))
+;;
+
+let ic = open_in "input.dat" in
+let ilist = fr ic [] in 
+let e,o = splitter ilist [] [] in
+
+print_endline (String.concat " " (List.map string_of_int ilist));
+print_endline (String.concat " " (List.map string_of_int e));
+print_endline (String.concat " " (List.map string_of_int o))