-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday02_part02.fs
35 lines (25 loc) · 921 Bytes
/
day02_part02.fs
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
32
33
34
35
module day02_part02
open AdventOfCode_2024.Modules
let parseContent (lines: string array) =
lines
|> Array.map(fun line -> line.Split(" ") |> Array.map int)
let skipOnes collection =
[| 0..Array.length collection - 1 |]
|> Array.map(fun i -> Array.removeAt i collection)
let areSafeInc(i: int array) should =
i |> Array.pairwise |> Array.forall (fun (a,b) -> should a b)
let areSafeDec(i: int array) should =
i |> Array.pairwise |> Array.forall (fun (a, b) -> should b a)
let validDiff a b =
b - a >= 1 && b - a <= 3
let isSafe l = areSafeInc l validDiff || areSafeDec l validDiff
let checkWithoutOne(elems: int array) =
skipOnes elems
|> Array.exists isSafe
let execute() =
let path = "day02/day02_input.txt"
let content = LocalHelper.GetLinesFromFile path
let values = parseContent content
values
|> Array.filter checkWithoutOne
|> Array.length