Skip to content

Instantly share code, notes, and snippets.

@leifmetcalf
Created December 1, 2022 05:51
Show Gist options
  • Save leifmetcalf/35b0390c5d125ab1129ac3db8dbc67df to your computer and use it in GitHub Desktop.
Save leifmetcalf/35b0390c5d125ab1129ac3db8dbc67df to your computer and use it in GitHub Desktop.
open Core
let () =
let f (elves, acc) line =
if String.is_empty line then
(acc :: elves, 0)
else
(elves, acc + int_of_string line)
in
let (elves, acc) = In_channel.fold_lines In_channel.stdin ~init:([], 0) ~f in
let elves = List.sort ~compare:Int.descending (acc :: elves) in
printf "%d\n" @@ List.fold (List.take elves 3) ~init:0 ~f:(+)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment