summary refs log tree commit diff stats
path: root/day24.fsx
diff options
context:
space:
mode:
Diffstat (limited to 'day24.fsx')
-rw-r--r--day24.fsx21
1 files changed, 21 insertions, 0 deletions
diff --git a/day24.fsx b/day24.fsx
new file mode 100644
index 0000000..3acdd7b
--- /dev/null
+++ b/day24.fsx
@@ -0,0 +1,21 @@
+open System.IO
+
+let parseLine (str: string) = str.Split('/') |> Array.map int |> (fun x -> (x[0], x[1]))
+let strength = List.sumBy (fun c -> fst c + snd c)
+
+let edges = File.ReadAllLines "day24.txt" |> Array.map parseLine
+
+let rec build bridge next components =
+    seq { 
+        yield bridge
+        if Set.contains (next, next) components then yield! build ((next, next) :: bridge) next (Set.remove (next, next) components)
+        else
+            let bridgeable = Set.filter (fun c -> fst c = next || snd c = next) components
+            for comp in bridgeable do
+                let next' = if snd comp = next then fst comp else snd comp
+                yield! build (comp :: bridge) next' (Set.remove comp components) }
+
+let solve maximiser = set >> build [] 0 >> Seq.maxBy maximiser >> strength
+
+solve strength edges |> printfn "%A"
+solve (fun c -> (List.length c, strength c)) edges |> printfn "%A"
\ No newline at end of file