-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday04_part02.fs
38 lines (29 loc) · 1.33 KB
/
day04_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
36
37
38
module day04_part02
open System.Collections.Generic
open AdventOfCode_Utilities
open AdventOfCode_2020.Modules
let path = "day04/day04_input.txt"
let inputLines = LocalHelper.GetLinesFromFile(path) |> List.ofArray
let allFields = [|"byr"; "iyr"; "eyr"; "hgt"; "hcl"; "ecl"; "pid"; "cid"|]
let requiredFields = [|"byr"; "iyr"; "eyr"; "hgt"; "hcl"; "ecl"; "pid"|]
let passportList = new List<List<string>>()
passportList.Add(new List<string>())
let values = getLinesGroupBySeparator2 inputLines ""
let passPortIsValid (credentials: string list) =
let allFieldsRequired = requiredFields |> Array.forall (fun field -> credentials |> List.exists(fun cred -> cred.StartsWith(field)))
let cred = credentials |> Array.ofSeq
let valueIsCorret = cred |> Array.forall (fun field ->
let parts = field.Split(':')
match parts with
| [|"byr"; thevalue|] -> byrValid thevalue
| [|"iyr"; thevalue|] -> iyrValid thevalue
| [|"eyr"; thevalue|] -> eyrValid thevalue
| [|"hgt"; thevalue|] -> hgtValid thevalue
| [|"hcl"; thevalue|] -> hclValid thevalue
| [|"ecl"; thevalue|] -> eclValid thevalue
| [|"pid"; thevalue|] -> pidValid thevalue
| _ -> true
)
valueIsCorret && allFieldsRequired
let execute =
values |> List.filter(fun p -> passPortIsValid p) |> List.length