-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay07.fs
More file actions
37 lines (27 loc) · 713 Bytes
/
Day07.fs
File metadata and controls
37 lines (27 loc) · 713 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
32
33
34
35
36
37
module Day07
open System
let parse =
Seq.map (
splitOn ':'
>> pair
>> map2 (int64, allInt64 >> Seq.toList)
)
let concat a b =
let p =
MathF.Log10(float32 b)
|> fun l -> pown 10L (int l + 1)
(a * p) + b
let run ops (n, xs) =
let rec go a =
function
| x :: xs' ->
ops
|> Seq.tryPick (flip uncurry (a, x) >> flip go xs')
| [] when a = n -> Some n
| _ -> None
match go 0L xs with
| Some v -> v
| _ -> 0L
let part1 = Seq.map (run [ (+); (*) ]) >> Seq.sum
let part2 = Seq.map (run [ (+); (*); concat ]) >> Seq.sum
let Solve: string seq -> int64 * int64 = parse >> both part1 part2