add dev scafold and day 1 solution

This commit is contained in:
Vladan Popovic 2022-12-01 23:45:12 +01:00
parent 49e961c0fd
commit 739b24dfbe
15 changed files with 2631 additions and 0 deletions

4
bin/d1/dune Normal file
View file

@ -0,0 +1,4 @@
(executable
(public_name d1)
(name main)
(libraries core utils))

2267
bin/d1/input.txt Normal file

File diff suppressed because it is too large Load diff

21
bin/d1/main.ml Normal file
View file

@ -0,0 +1,21 @@
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

3
bin/dune Normal file
View file

@ -0,0 +1,3 @@
(executable
(public_name aoc2022)
(name main))

3
bin/main.ml Normal file
View file

@ -0,0 +1,3 @@
print_endline "\n" ;;
print_endline "Nothing here. You can run an executable for a single day with:" ;;
print_endline "dune exec d1" ;;