Skip to content

Instantly share code, notes, and snippets.

@mununki
Created December 1, 2021 16:34
Show Gist options
  • Save mununki/a5bda74225c027222bc104d078cbeef5 to your computer and use it in GitHub Desktop.
Save mununki/a5bda74225c027222bc104d078cbeef5 to your computer and use it in GitHub Desktop.
Advent of Code 2021, Day 1
let input = Util.read_file "../input/y2021d1" |> List.map int_of_string
(* let%test _ = input = ["1"] *)
(* let%expect_test _ =
input |> List.iter (fun s -> print_endline s);
[%expect ""] *)
let prevs xs = xs |> List.rev |> List.tl |> List.rev
let nexts = List.tl
let increases input =
List.combine (prevs input) (nexts input)
|> List.map (fun (h, t) -> t - h)
|> List.filter (fun i -> i > 0)
|> List.length
let firsts = input |> List.rev |> List.tl |> List.tl |> List.rev
let seconds = input |> List.tl |> List.rev |> List.tl |> List.rev
let thirds = input |> List.tl |> List.tl
let windows =
List.combine firsts seconds
|> List.map (fun (a, b) -> a + b)
|> List.combine thirds
|> List.map (fun (a, b) -> a + b)
let part1 = increases input
(* let _ = part1 |> string_of_int |> print_endline *)
let part2 = increases windows
(* let _ = part2 |> string_of_int |> print_endline *)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment