diff options
author | Brian Chu <brianmchu42@gmail.com> | 2022-02-21 00:11:06 -0800 |
---|---|---|
committer | Brian Chu <brianmchu42@gmail.com> | 2022-02-21 00:11:06 -0800 |
commit | 0a4fe70d367f0bf1a78602af600052f58a377c34 (patch) | |
tree | 69c2bcd2b54b48968fd52728aaf0e21ca154784c /day24.fsx | |
parent | 1e2642d8793e6a4fb6cba16cd651d5fdca3e4581 (diff) | |
download | AdventOfCode2017-0a4fe70d367f0bf1a78602af600052f58a377c34.tar.gz |
solutions to day 25 main
Diffstat (limited to 'day24.fsx')
-rw-r--r-- | day24.fsx | 21 |
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 |