aoc2022/bin/d1/main.ml

22 lines
592 B
OCaml
Raw Permalink Normal View History

2022-12-01 23:45:12 +01:00
let sum_callories input =
let rec aux elv res = function
| [] -> elv :: res
| x :: xs -> if x = "" then aux 0 (elv :: res) xs
else aux (elv + (int_of_string x)) res xs in
aux 0 [] input
open Utils
let summed = read_file "bin/d1/input.txt"
|> sum_callories
|> List.sort compare
|> List.rev ;;
open Core
let first = List.hd summed |> Option.value ~default:0 ;;
let second = List.take summed 3 |> List.fold ~init:0 ~f:(+) ;;
"\n1: " ^ (string_of_int first) ^
"\n2: " ^ (string_of_int second) |> print_endline