-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday09_part01.fs
29 lines (21 loc) · 976 Bytes
/
day09_part01.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
module day09_part01
open System
open AdventOfCode_Utilities
open AdventOfCode_2020.Modules
let path = "day09/day09_input.txt"
let inputLines = LocalHelper.GetLinesFromFile(path) |> Array.map (fun x -> Convert.ToUInt64(x)) |> List.ofArray
let preambleSize = 25
let numberIsValid (value: uint64) (listChecker: uint64 list) =
let permu = combination 2 listChecker
(permu |> List.exists(fun x -> x.Item(0) + x.Item(1) = value), value)
let rec findInvalidValue (elements: uint64 list) (preamble: int) : (bool * uint64)=
match elements.Length = 0 with
| true -> (false, uint64(0))
| false ->
let checkList = elements |> List.take(preamble + 1)
let valid = numberIsValid (checkList |> List.rev |> List.head) (checkList |> List.take(preamble))
match fst valid with
| false -> (true, snd valid)
| true -> findInvalidValue (elements |> List.skip(1)) preamble
let execute =
snd (findInvalidValue inputLines preambleSize)