22 lines
592 B
OCaml
22 lines
592 B
OCaml
|
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
|