Advent of Code 2020 https://adventofcode.com/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

29 lines
711 B

let get_one_line file =
try Some (input_line file) with
End_of_file -> None
let get_lines file =
let rec input lines =
match get_one_line file with
Some line -> input (line :: lines)
| None -> List.rev lines
in input []
let find_pair_and_prod items total =
let len = List.length items in
let rec check idx =
let left = List.nth items (idx mod len) in
let right = List.nth items (idx / len) in
if left + right == total
then left * right
else check (idx+1)
in check 0
let file = "day1.txt"
let channel = open_in(file)
let lines = get_lines channel
let ints = List.map int_of_string lines
let prod = find_pair_and_prod ints 2020;;
Printf.printf "%i" prod