-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay08.fs
More file actions
36 lines (25 loc) · 840 Bytes
/
Day08.fs
File metadata and controls
36 lines (25 loc) · 840 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
module Day08
let antennas =
Seq.filter (snd >> (<>) '.')
>> Seq.groupBy snd
>> Seq.map (snd >> Seq.map fst >> Seq.toList >> combinations)
>> Seq.concat
let inbounds =
let clip (mx, my) (x, y) = x >= 0 && x <= mx && y >= 0 && y <= my
Seq.maxBy fst >> fst >> clip
let parse = toGrid2d >> both antennas inbounds
let antinode n ((x, y), (x', y')) =
let dx, dy = (n * (x' - x), n * (y' - y))
[ (x - dx, y - dy); (x' + dx, y' + dy) ]
let count pred =
Seq.concat
>> Seq.filter pred
>> Seq.distinct
>> Seq.length
let part1 (m, valid) =
m |> Seq.map (antinode 1) |> count valid
let part2 (m, valid) =
let lineup n =
Seq.replicate n >> Seq.mapi antinode >> Seq.concat
m |> Seq.map (lineup 50) |> count valid
let Solve: string seq -> int * int = parse >> both part1 part2