-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.fs
34 lines (26 loc) · 954 Bytes
/
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
module Day15
type State = int * int * Map<int, int>
let nextNumber ((number, turn, numbers): State) =
match Map.tryFind number numbers with
| None -> Some((number, turn), (0, turn + 1, numbers.Add(number, turn)))
| Some previous -> Some ((number, turn), (turn - previous, turn + 1, numbers.Add(number, turn)))
let generate input =
let (lastNumber, lastTurn) :: previous =
input
|> List.mapi (fun i n -> (n, i + 1))
|> List.rev
Seq.unfold nextNumber (lastNumber, lastTurn, Map.ofList previous)
let partOne input =
generate input
|> Seq.find (fun (_, turn) -> turn = 2020)
|> fst
let partTwo input =
generate input
|> Seq.find (fun (_, turn) -> turn = 30000000)
|> fst
[<EntryPoint>]
let main argv =
let input = [9;6;0;10;18;2;1]
partOne input |> printfn "Part one: %d"
partTwo input |> printfn "Part two: %d"
0