-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay11.fs
More file actions
31 lines (24 loc) · 761 Bytes
/
Day11.fs
File metadata and controls
31 lines (24 loc) · 761 Bytes
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
module Day11
let parse = splitOn ' ' >> Seq.map int64
let digits =
Seq.unfold (function
| 0L -> None
| x -> Some(x % 10L, x / 10L))
>> Seq.rev
let toint = Seq.fold (fun n d -> n * 10L + d) 0L
let rec blink =
let go =
function
| 0, _ -> 1L
| n, x ->
match x with
| 0L -> blink (n - 1, 1L)
| b when digits b |> Seq.length |> isEven ->
digits b
|> Seq.splitInto 2
|> Seq.sumBy (toint >> curry blink (n - 1))
| b -> blink (n - 1, b * 2024L)
memo go
let part1 = Seq.sumBy (curry blink 25)
let part2 = Seq.sumBy (curry blink 75)
let Solve: string seq -> int64 * int64 = Seq.head >> parse >> both part1 part2