-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.fs
41 lines (33 loc) · 1.12 KB
/
Program.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
39
40
41
module Day09
open Common.Collections
open System.IO
let rec partOne (preamble: int64 list) (input: int64 list) =
let preamblePairs = combinations 2 preamble
let isMultipleOfAny x =
preamblePairs
|> List.map List.sum
|> List.exists (fun sum -> sum = x)
let newPreamble = List.skip 1 preamble
match input with
| head :: tail when isMultipleOfAny head -> partOne (newPreamble @ [head]) tail
| head :: _ -> head
let rec partTwo number input =
let mutable seen = []
let mutable position = 0
while List.sum seen < number && position < List.length input do
seen <- input.[position] :: seen
position <- position + 1
if List.sum seen = number then
List.min seen + List.max seen
else
partTwo number (List.skip 1 input)
[<EntryPoint>]
let main argv =
let input =
File.ReadLines("Input.txt")
|> Seq.map int64
|> Seq.toList
let found = partOne (List.take 25 input) (List.skip 25 input)
printfn "Part one: %d" found
partTwo found input |> printfn "Part two: %d"
0