28 lines
683 B
OCaml
Executable File
28 lines
683 B
OCaml
Executable File
let file = "data/sample.txt"
|
|
|
|
let rec next previous map =
|
|
let apply destination source range value =
|
|
let delta = value - source in
|
|
destination + delta
|
|
in match map with
|
|
| [] -> None
|
|
| (destination, source, range)::q when
|
|
previous >= previous && previous <= previous + range
|
|
-> Some(apply destination source range previous)
|
|
| h::q -> next previous q
|
|
|
|
let res = next 98 [(50,98,2);(52,50,48)]
|
|
|
|
|
|
let () =
|
|
let ic = open_in file in
|
|
let line = input_line ic in
|
|
(* read line *)
|
|
print_endline line;
|
|
flush stdout;
|
|
close_in ic
|
|
with e -> close_in_noerr ic;
|
|
raise e
|
|
|
|
let () = print_endline file
|