-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay1.fs
More file actions
31 lines (24 loc) · 710 Bytes
/
Copy pathDay1.fs
File metadata and controls
31 lines (24 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
namespace Adventofcode2021
module Day1 =
[<Literal>]
let InputFile = "Day1Input.txt"
let getMeasurements file =
file
|> System.IO.File.ReadAllLines
|> Array.map int
|> List.ofArray
let countIncs f measurements =
let rec helper sum m =
match m with
| x :: y :: rest ->
let sum' = if (f x) < (f y) then sum + 1 else sum
helper sum' (y :: rest)
| _ -> sum
helper 0 measurements
let day1 () =
InputFile |> getMeasurements |> countIncs id
let day1Part2 () =
InputFile
|> getMeasurements
|> List.windowed 3
|> countIncs List.sum