-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday25_part01.fs
28 lines (23 loc) · 975 Bytes
/
day25_part01.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
module day25_part01
open AdventOfCode_Utilities
open AdventOfCode_2018.Modules
let manhattan p0 p1 = Array.zip p0 p1 |> Array.sumBy (fun (c0, c1) -> abs (c0 - c1))
let asIntArray : string [] -> int [] = Array.map int
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 execute =
let path = "day25/day25_input.txt"
let content = LocalHelper.GetLinesFromFile path
let points = content |> Seq.map (splitByFn "," asIntArray)
solve points