-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathDay25.fs
20 lines (17 loc) · 838 Bytes
/
Day25.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module Year2018Day25
open AdventOfCode.FSharp.Common
let manhattan p0 p1 = Array.zip p0 p1 |> Array.sumBy (fun (c0, c1) -> abs (c0 - c1))
let solve points =
let rec countComponents count unseen =
let rec findComponent queue unseen =
match queue with
| p0 :: ps ->
let toAdd, toKeep = List.partition (fun p1 -> manhattan p0 p1 <= 3) unseen
let newQueue = List.foldBack (fun t q -> t :: q) toAdd ps
findComponent newQueue toKeep
| [] -> unseen
match unseen with
| p :: _ -> countComponents (count + 1) (findComponent [p] unseen)
| [] -> count
countComponents 0 (Seq.toList points)
let solver = {parse = id; part1 = parseEachLine (splitBy "," asIntArray) >> solve; part2 = (fun _ -> "Advent of Code Finished!")}