solve_1.ml 749 B

123456789101112131415161718192021
  1. open Stdio
  2. open Str
  3. let read_input =
  4. let rec aux rules updates=
  5. let line = In_channel.input_line In_channel.stdin in
  6. match line with
  7. | None -> rules, updates
  8. | Some x -> if (Str.string_match (regexp {|[0-9]+|[0-9]+|}) x 0) then
  9. let z = (List.map int_of_string (Str.split (regexp {|||}) x)) in
  10. aux ((List.nth z 0, List.nth z 1)::rules) updates else
  11. (if (Str.string_match (regexp {|[0-9]+\|,|}) x 0) then
  12. aux rules ((List.map int_of_string (Str.split (regexp {|,|}) x))::updates) else aux rules updates)
  13. in
  14. aux [] []
  15. ;;
  16. let rules = (fst read_input)
  17. let updates = (snd read_input)
  18. let () = List.iter (fun x -> printf "(%d, %d)\n" (fst x) (snd x)) rules