From 3620d3732192833395c3d856a02472dad103ddd9 Mon Sep 17 00:00:00 2001 From: Andrej Orsula Date: Sun, 10 Dec 2023 15:32:09 +0100 Subject: [PATCH] aoc2023/day10: Add solution Signed-off-by: Andrej Orsula --- README.md | 25 ++-- aoc2023/Cargo.toml | 1 + aoc2023/input/2023/day10.txt | 140 ++++++++++++++++++++ aoc2023/src/day10.rs | 243 +++++++++++++++++++++++++++++++++++ aoc2023/src/lib.rs | 1 + 5 files changed, 399 insertions(+), 11 deletions(-) create mode 100644 aoc2023/input/2023/day10.txt create mode 100644 aoc2023/src/day10.rs diff --git a/README.md b/README.md index ab2701d..70be6fa 100644 --- a/README.md +++ b/README.md @@ -17,17 +17,18 @@ My solutions to [Advent of Code](https://adventofcode.com) puzzles. DayPart 1 PerformancePart 2 Performance -| D | Puzzle | Code | -| :---: | ------------------------------------------------------------- | :------------------------------: | -| 1 | [Trebuchet?!](https://adventofcode.com/2023/day/1) | [`day1.rs`](aoc2023/src/day1.rs) | -| 2 | [Cube Conundrum](https://adventofcode.com/2023/day/2) | [`day2.rs`](aoc2023/src/day2.rs) | -| 3 | [Gear Ratios](https://adventofcode.com/2023/day/3) | [`day3.rs`](aoc2023/src/day3.rs) | -| 4 | [Scratchcards](https://adventofcode.com/2023/day/4) | [`day4.rs`](aoc2023/src/day4.rs) | -| 5 | [If You Give A Seed ...](https://adventofcode.com/2023/day/5) | [`day5.rs`](aoc2023/src/day5.rs) | -| 6 | [Wait For It](https://adventofcode.com/2023/day/6) | [`day6.rs`](aoc2023/src/day6.rs) | -| 7 | [Camel Cards](https://adventofcode.com/2023/day/7) | [`day7.rs`](aoc2023/src/day7.rs) | -| 8 | [Haunted Wasteland](https://adventofcode.com/2023/day/8) | [`day8.rs`](aoc2023/src/day8.rs) | -| 9 | [Mirage Maintenance](https://adventofcode.com/2023/day/9) | [`day9.rs`](aoc2023/src/day9.rs) | +| D | Puzzle | Code | +| :---: | ------------------------------------------------------------- | :--------------------------------: | +| 1 | [Trebuchet?!](https://adventofcode.com/2023/day/1) | [`day1.rs`](aoc2023/src/day1.rs) | +| 2 | [Cube Conundrum](https://adventofcode.com/2023/day/2) | [`day2.rs`](aoc2023/src/day2.rs) | +| 3 | [Gear Ratios](https://adventofcode.com/2023/day/3) | [`day3.rs`](aoc2023/src/day3.rs) | +| 4 | [Scratchcards](https://adventofcode.com/2023/day/4) | [`day4.rs`](aoc2023/src/day4.rs) | +| 5 | [If You Give A Seed ...](https://adventofcode.com/2023/day/5) | [`day5.rs`](aoc2023/src/day5.rs) | +| 6 | [Wait For It](https://adventofcode.com/2023/day/6) | [`day6.rs`](aoc2023/src/day6.rs) | +| 7 | [Camel Cards](https://adventofcode.com/2023/day/7) | [`day7.rs`](aoc2023/src/day7.rs) | +| 8 | [Haunted Wasteland](https://adventofcode.com/2023/day/8) | [`day8.rs`](aoc2023/src/day8.rs) | +| 9 | [Mirage Maintenance](https://adventofcode.com/2023/day/9) | [`day9.rs`](aoc2023/src/day9.rs) | +| 10 | [Pipe Maze](https://adventofcode.com/2023/day/10) | [`day10.rs`](aoc2023/src/day10.rs) | @@ -42,6 +43,7 @@ My solutions to [Advent of Code](https://adventofcode.com) puzzles. | 117.3 µs | 70.08 µs | | 109.8 µs | 314.2 µs | | 88.05 µs | 38.84 µs | +| 126.5 µs | 147.0 µs | @@ -56,6 +58,7 @@ My solutions to [Advent of Code](https://adventofcode.com) puzzles. | 136.1 µs | 65.87 µs | | 82.85 µs | 703.8 µs | | 80.19 µs | 45.75 µs | +| 134.1 µs | 196.6 µs | diff --git a/aoc2023/Cargo.toml b/aoc2023/Cargo.toml index d3b544f..7e8f895 100644 --- a/aoc2023/Cargo.toml +++ b/aoc2023/Cargo.toml @@ -19,6 +19,7 @@ arrayvec = { version = "0.7" } itertools = { version = "0.12" } num = { version = "0.4" } num-integer = { version = "0.1" } +pathfinding = { version = "4.4" } rayon = { version = "1.8" } regex = { version = "1.10" } rustc-hash = { version = "1.1" } diff --git a/aoc2023/input/2023/day10.txt b/aoc2023/input/2023/day10.txt new file mode 100644 index 0000000..ea22a11 --- /dev/null +++ b/aoc2023/input/2023/day10.txt @@ -0,0 +1,140 @@ +F--F7F7|7FJ..JF-7F|77FL-L7.L.L7LFFJ-77|7.L777LF7L|FJJ-7-F|J7-7FF-7..FFF7JF--L77FL--77-7-77-|7FJ.LL.|7L7-|-FJJ.-J.F-77|F---|7.F--|--.F-7-7.F7 +FJ-|J|JJLF7F77|||FJ7J-|J|LF7.L||LJ|L77LL-JL--F--.LLJ|-..7|FJ..FJ7F.J.|7L-L7.|--F.7J||L|J.JJLFJF77|-LJ-|-J-FJ-F|J|-7|-L|JJ.L7.|-F77-FFJLLF.L- +.||..|J.-|-JL777LJLF7LF7FFL-7-F7.F--LF7||FL.|JJ|F7J.-J.|LJ--7-JLFJ7.7L7|F7LJ7J|LL|FF|.|-7L|F7JL-LF-L7LJJ|L|7.L|-FJLLJLL-F|JLJ7JLJJ-FJ7J-LFL7 +F7--|L|7|FJLL7-L7L7.|LJJJ.|F77||.L-JF|-7J.||.|JF||-|J|F|-||FF7.L.FF-L7L|L-7L--|-L|J|L--7F7F|....FL7L777F7L|J--.F77JJ|.LFJ|J.LJ.F|F7LF-.F7JF| +.--FJ-J--J7.LF-LJLFFJF|.||F-.FJLF7.F7LF7|F|7.FF7|||L-7F|-J7F||7.7J|7.|.L-.FL|L|7--7L77L|LL|J-7FFJ-|JLF-J|7|-7JF||JF7|7F|---77---JL7.-JFLF.-| +JJ.|7.|-FL-7F--FJ-LL-7--L7-77J-FJ|-F--J|F7LF|7||||7F7.JJ..FFJL7J.FJL.||F|7J.L-L7-LL-|7L|.||7.|F---J-JL-7L7F-7-L||LJJ-J.LFJFJ7F|7FLFF|-FF77-| +F--J-LJ-7|.|J-F7J7JL--7.|||-7.LL7|-L7F-J|L-7LFJ||L-7F77FF7FJF-J|-|F|.FFJ7|--||J|..|-77-J-F|-J7|JJFL77L|L7L7||LL|L7LL7F-7|.FJ|FJFL..LL7..|7FF +JFFJ7.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F7|||L--7F7L7|JFJF--JFJFJF-7F--JL7L7L7F7L-------7|||F7FJL7|F-7FJF7|||L77LJ7.L-7.|L7 +F|7L7J-FJ-LJ|L-7|-F----7||L7L--7L--7L7||L7LJ|L-7||LJLJL7||LJ||F--J||FJL7L7|F7JL7L7L7LJF-7FJFL7|||FF7F7F--JLJ||LJF-J||LLJFJ||||FJ7JJJFJFLFL-| +|-JL|7LF7-FLF-FJL7L---7LJL-JF--JFF7L7||L7|F-JF7||L7F--7L7L-7|||F77||L-7L7|||L-7L7L7L-7|FJL-7FJLJ|FJLJ|L----7||F7L7J|L7F-JFJ|LJL-7..FF-L.|J|| +L-F7--FJF7-F7FL7FJF7F7L----7|F7F7||FJ|L7||L7FJ||L7|L-7L-JF-JLJLJ|FJL--JFJ|||F-J7L7|F7||L7F-JL7F-JL--7|F7F-7||||L7L7|FJ|F-JFJF--7L77J|.LL|-7. +J.-7-FJF|L-J|F-JL7|LJ|.F7F7|LJ|||||L7|FJLJFJL7|L7LJF-JF-7|F----7||F7F-7|FJLJL-7F-J|||LJFJL-7FJL7F7F-JLJ|L7LJ||||L-J|L-JL--JFJ.LL7|||F7F||F-7 +FL-L-F7LL--7|L--7|L-7L-JLJLJF-J||||FJ|L7F-JF-JL7L7FJF-JFJLJJF7-||LJLJ.||L7F---JL7FJ|L7FJF--JL-7||LJF7F-J.L-7LJL-7F7|F------J-FJLLJJF|JF|-7F- +|FF7.L7JFLFJL-7FJL7JL------7|LFJ|||L7|FJL7FJF-7|FJL7|F-JF7JFJL-JL7F7F-J|FJL-7F7FJL-JFJL7L7LF7L||L7FJ||F77F7|F7F-J|||L-------7F7F|.|-77L-JLFJ +LLJLJ7J.F7L--7LJF7L-7F-----JL7L7||L-J||F-J|FJFJ||F7LJ|F7|L7L---7FJ||L-7LJF--J|||F---JF7L7L7|L-JL7LJFJ||L7||||LJF7|||F-------J||F--77|7-L.F-J +7.L7L|F7|||F7L--JL7FJL---7F-7L7||L-7FJ|L-7LJ|L7|LJL7FJ||L7L7F--JL7||F-JF-J7F7|||L7LF7||L|FJL--7FJF7|FJL7LJLJ|F-JLJLJL-7F---7FJLJF-J-|7.JFL-7 +L7.77|JFJL-JL-----JL---7LLJFL7LJL--JL7|F-JF-7FJL7F7||FJL7|FJL---7LJ|L7FJF-7||||L7L7|LJ|FJL7F7FJL7|LJL-7|F---JL7F--7F-7LJF-7LJF--JJL|L7777-FJ +FLFF7LLL7F-----7F---7F7L--7F7L7F----7|||F7L7|L7FJ|||LJF-J||F7F7-L-7L7||J|FJ||||FJFJ|F-JL-7|||L7FJL--7FJ||F7F7FJL-7|L7L7FJFJF7L--77-JJJLJ--|7 +77.LF7F-J|F----J|F--J|L7F7LJL-J|F---J||LJL7||FJ|FJ||F-JF-J|||||F7LL7LJ|FJL7||||L7L7|L7F7FJLJ|FJ|F-7FJL7|LJLJLJF7FJL-JLLJ|L-JL-7FJF7-L-7|||L| +|7F-F7L--JL----7||F7FJ||||F7F--JL---7||F--J||L7||FJ||F7L7FJ||||||F7L-7|L7FJ||||7|FJ|FJ||L7F-JL7||FJL7FJ|F-----JLJLF7F----7|F7-LJL||F7LF7F--7 +F.7||||F7F7|F7FJ|||LJF-J|||||F--7F--J|||F7FJL7|||L7|LJ|FJL7||||||||F7||FJL7||||FJL7||FJL7||F7FJ||L7FJL-JL----7F--7|||F---JFJL-7F-J||L-J|J||| +.7JF|L-JLJL-JLJFJLJ7FJF7|||||L-7|L-7LLJLJ||F-J|||7|L-7|L-7||||||||||LJ|L-7LJ|||L7FJ||L-7LJLJ|||LJFJL7F-------J|F-J|LJL--7LL7F7|L7FJ|F--J77-F +LF.LL7F-7F7F-7FJF7F-JFJLJLJLJF-J|F7L---7|LJL-7|||FJF7||F-J||||||||LJF-JF7L7JLJ|FJL7|L7FJF---JL7F7L7FJ|F7F7F7F7||F-JF---7L7FJ|LJFJ|.|L-7JFJFF +|.--L||.LJ|||LJ-||L--J7F7F7F-JF7LJL---7L--7F7|||||FJ||LJF-J|||||LJF7|F7|L7L--7LJF7||FJL7L7F-7FJ|L-J|-LJLJLJLJLJLJF7L--7L7||FJFLL7L-JF-JF77LJ +|FL|F||F--J|F7F7||F77F7|LJ|L--JL7F---7L---J|LJ||||L7|L-7L7FJ|||L7FJLJ||L7|F-7L7FJLJ||F7L7|L7|L7L7F7L7-F7-F7F-----JL---J7LJ||F7F7|F--JF-JL7J7 +J-FF-LJL7F7||LJLJLJL-JLJF-JFF7F7LJ.F-JF7F7JL7FJ|||FJ|F7L7||FJ||FJ|F-7|L-JLJFJFJ|F-7||||FJL7||FJFJ|L7|FJL-JLJF--------7F7F7|||||||L-7-L7F-J-J +|FFF-F-7LJLJL7F--------7|.F7||||F--J|FJLJL-7|L7||||FJ|L-JLJL-J||FJ|FJL--7F7L-JFJ|FJ|||LJ|FJ|||FJFJJLJL----7FJF------7LJ||||||LJLJF7L7L|L7L|J +|-||FL7|F-7F7LJF-------JLS||||||L----JF7F7FJL-J||||L7L-7F7F--7|||FJ|F7F7LJL--7L7|L7||L-7FJFJ|||FJF-7F7F---J|FJJF--77L--J|||||F--7|L7L-JFJ.J7 +F-|-F-J|L7|||F7L--------7LJLJLJL7F----JLJLJF--7LJLJFJF7LJ||F7LJ|||FJ|||L7F7F7L7||7LJL7FJL-JFJ|||.L7|||L----JL-7L7FJF77F7|||||L-7LJ-|F--JF7|L +|7|FL-7L-JLJLJL-7F7F7|F-JF7F-7F7LJF7F------JF-JF-7LL7||F7|LJL7FJ|||FJ||FJ|LJ|FJ||F---JL---7L-J||F-JLJL--------JFJ|-||FJLJLJLJF-JLF7LJF7F77F| +FF----JF7F-7F7F7LJLJ|FJF7|||-LJL--JLJF7F---7L-7|FJF7LJ||LJF--JL7|||L7LJL7L-7||-||L--7F7F--JF-7LJL------7F7F-7F7L7L-JLJF-7F7F-JLF7||.FJLJ|7F7 +LL-7F7FJ|L7||LJL---7LJFJLJLJF7F7F----JLJJF7L--J||FJL-7|L7LL--7FJLJ|FJF7F|F-J|L7LJF--J|||FF7L7|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LJLJ-|FJ7J.L-JJ.F||JLLJFL---7F7LJL7||LJF-JL7L7FJF--J|.F7L7LF7-LJ||LJLJ7LJLJ-.LFL7.|-JJ-LF +F||.F-F7FL----7L---7F7|||||LJF-7F7F----7F7LJF--7L7L----7||J7-7||.-F-JL7||F7FF7FJ|L--7LJL-7L7F-JLLJJL7F7L-JL-JFJ|F7FJL--7F7F-7FJ.7J--LL-J..F- +-JF-F7J7F.F7F-JF--7LJLJ|LJL--J.||||F---J|L--JF7L7L7F-7FJLJ7J.L|7-LL---J-F||FJ|L-J7F7L--7FJJLJF7F---7||L7F7F-7L7||||F---J|||FJ-7F|7.|LJFF7FLJ +|L7-|L7-F7||L--JF7|F7F-JF-----7LJLJ|F---JF---JL-JFJ|FLJF7F7F77J|||F|-F|7F||L7|F7F7|L-7FJL7F-7||L-7FJ||FJ|||FJFJLJLJL7F--JLJL7||7|F|JLLLFJ..| +-F||L7L-JLJL7LF-JLJ|LJF7L----7|LF-7LJF---JF-7F--7L7L--7|||||L7FF7-FF7JJ-FJL-JLJLJLJF7|L-7LJFJ|L7FJL7||L-JLJL-JF-7F-7LJF-----J7|F7F7-7|||J-F| +||JFJL7F7F-7L7L---7|F-JL-----JL7L7|F7L----JFJ|F-JLL---J|||||FJ7F7.F7JL7FJF-7F-7F7F7|||F-JF7L7L7|L7FJLJF----7F7L7LJ7L-7L-------7F7||F---77.LF +-JJ|-FJ|LJ.L7L-7F7||L-7F-7F-7F7L7|LJL---7F-JF||F7F7JF-7|LJLJL--JL-JL7.FL-JFJL7||LJLJ|LJF7|L7L-JL-J|F7FJF--7||L-J|F--7L---7F--7||LJ||F--J.|J| +FJ7LFL7L7F7JL-7LJ|LJF-J||LJFJ|L7LJF----7|L--7||||||FJFJL7F---------7|-L7JF|F-JLJ-F--JF7|LJFL--7F-7LJLJFJF-JLJ|F7FJF7L---7||F7LJL-7||L7-L7.F| +L-L--FJFJ||7F7L-7L--JF7|F--JFJLL7FJF7F-JL---J|||||LJFJ|FJL-7F-----7LJ7LJ|FJL7F---JF7FJLJF7F---JL7L7F--JFL7F7JFJLJFJ|F---J|LJL7F-7|||FJ7F|7F| +|7|-LL-JFJL-JL--JF---JLJL---J|FLLJF|LJF7F7|F7|||LJF-JF7L7F-J|F-7F7|JJ|J.FJF7|L---7|LJF7FJLJF7F--JFJ|F---7LJL-JF7FJFJL-7F7L---J|FJ|LJL7F777L7 +|-7-LLJF|F7F--7F7|F7-F7F--7F-7-F7F7L-7||||FJLJLJF7L--JL-JL--JL7|||L7.|7.L-J||JF7-LJF-JLJF-7|||F-7L-J|F-7|F-7F7|LJ||F-7LJ|LF7JFJL7|F-7LJL-7JJ +L..F7JJFLJLJF7LJLJ||FJ|L-7LJFJFJLJL--J||||L7F-7FJ|F7F-7F--7F--JLJL-J.L|7L|JLJFJ|F--JF-7FJ|||||L7L-7.LJFJ|L7LJ|L--7LJLL-7L7|L-JF7LJL7|F-7FJ7| +|--7JLFL|-F-JL7F7F||L7L-7L7FJFJF------JLJL-JL7LJLLJLJFJL-7|L--------7L|-L|J|-L7|L-7FJFJ|FFJ|||FJF7L7F7L7L-J.FJF-7L----7L7LJF--JL7F-JLJLLJLF7 +L--JJF|7JLL--7|||FJ|.|F-JFJL-JFJF--------7F-7L-7F---7L---J|F7F-7F---J.|JL7-JJFJL--JL7L7|FJFJLJ|FJL7LJL-JF7F7L7|LL-7F7FJL|F7|F--7|||F7-||.|L| +7-|.FL7F7-F7FJLJ|L7|FJL--JF---J.L-------7||FJF7LJF-7L----7LJLJLLJJL|FFF7FJ||.L---7F7|FJ|L-JJF7LJF7L-7F--JLJL7|L--7LJ|L-7|||LJF-J|L-JL77JF|-F +LF7FF7|.F7||L7F7L-J|L-----JF------------JLJL-JL-7L7|F-7F7L-7F-7|J..LF-J|-|-7J-F--J|LJL7|F7F-JL--JL--JL7F----JL--7L-7|F7||||F7L-7L7F--J|.FJ|L +L-JF-F7FJLJL-J|L--7|7F---7JL---7F--------7F----7L-J|L7||L--JL7|7LJ..L7FJ.F-7J7L7F7L7F7LJ|LJF7F-7F7F-7FJ|F7F---77L--JLJLJLJ||L--JFJL--777|J|7 +.|FFJ||L------JF--JL-JF-7L7F---J|F------7LJF--7L--7L-JLJF7F7.|L77.77F|L-7L7L7F-J|L-J|L--JF7||L7LJ||FJ|FJ|LJF-7L7F-7F-----7|L--7FJF-7FJ.J77F| +FFF7-|L7F-----7L--7F-7|JL7|L-7F-J|F----7|F7L-7L---JF7F-7||||FJFJF7F7-|F-JF|FJL--JF--JF-7FJ||L7|F-J|L7|L-JF7L7L7LJFJL7F---JL---JL-J-LJJ.|.|-J +-F|L-JFJL----7|FF-JL7||F-JL7LLJF7LJF-7FJLJL--J7F7F7||L7|||||L7L-J||L-J|F7FJL---7LL--7L7LJF|L7LJL-7|7||F--JL7L7|F-JF-JL---7F7F7.F----7J|-FL7J +|||F-7L7|F7FFJL7|F7FJLJL7F7L--7||F7L7LJF7FF-77FJLJLJL7|||LJL7|F--JL--7||||F----J-F-7L-J7F-JFJF---JL7LJL---7|FJ|L-7|F----7LJLJ|FJF---JF-J.||J +FFLJ-L7L7|L-JF7LJ|LJFF-7LJL7F7LJLJL-J|FJL7L7L-JF-----J|LJF--J|L--7F7FJLJLJL----7JL7|F---JF7L7L7F---JF7JF--JLJ.L-7LJL--77L----J|FJFL.|-L7--J| +|J|-F7L7|L-7FJL--J7F7|FJF7FJ||F7F7F7|FJF7L-JF-7L----7FL-7|F7JL7F-J||L--7F------JF7||L7F-7|L-JFJ|F---JL-JF7F7F7F7L7F--7L7F7F-7-|L-7.F|7.|.LFL +-F--J|-||F7LJ-F-7F7||||FJ|L-JLJLJLJL-JFJ|F--J.L-7F--JF--JLJ|F7||F7||F7FJL7F7F7F7|LJ|.LJLLJ|F7L-JL-------JLJLJLJL7|L-7|FJ||L7|FJF7L-7JJFF7777 +FL--7|FJLJ|JF7L7LJLJ||||FJLF-7F7F7|F-7L7|L-----7LJF-7L--7F-J|LJ||||LJ|L-7LJLJ|||L-7|F7F-7F-JL7F-----------7F----JL7FJLJJ|L7||L7|L--JF7F|L77J +-LF-J||F-7L-J|LL---7LJ|||F7L7||LJL-JF|FJL--7F--JF7L7|F7FJL77|F-J|LJF-JF-JF---J|L7.|||||FJL-7FJL7F----7F--7LJJF7|F7LJF7F7|FJ||F|L-7F7F7FJFJ|7 +.LL-7|LJJL--7L----7L-7LJ|||FJ||F----7|L---7|L-7FJL-J||||F-JFJ|F7|F-JF7L-7L7F7FJFJFJLJLJL-7FJL7LLJJF--J|F7L--7|L7|L7FJ||||L-JL7|F-J|||LJFJJJ- +L7JFJL-7F---JF-7F-JF7|F7||LJFJLJF-7FJ|F7F-JL--JL-7F7LJ|||F7L7|||||F7||F7L7|||L7|.L-----7FJ|F-JF---JF--J|L-7FJ|FJ|FJL7||||F---J||F7|||F-JJ7JJ +F7.L--7|L-7F-JF||F7||LJ||L-7|F7JL7|L7||LJJF----7JLJL7FJ|LJ|FJLJLJ||||LJL7|LJ|FJ|F7F7F7FJL7||F7L----JF7FJF7LJ.|L-JL-7|||||||F--JLJLJLJL-7||.- +L|FF--JL--J|F--JLJ|||F-J|F7||||F7|L-J||F--JF7F-JF--7|L7|F-JL--7F-J|LJF--JL7FJ|FJ|LJLJ|L7FJ|||L7F7F--JLJFJL--7|F7F--J||||||FJF7F7F-7F-7FJJJ|J +LF-JF7F----JL----7LJ|L-7LJLJLJLJLJF7F||L7F-JLJF7L-7LJFJ|L7F7F7|L7FJF-JF-7F|L7|L7L---7|7||.|LJFJ||L-----JF---J||LJF7FJLJLJLJFJLJLJ-LJ-LJFL-J- +.L--J||.F--------JF7L--JF7F-----7FJL7||FJL---7|L-7L-7|FJFJ|||LJFJL7|F7L7L7|FJL7L7F7FJ|FJL7L-7L-JL7F7F--7L--77|L7FJ|L7F--7F7L7F--7LF77F7F7F-J +FF77.LJFJF-7F---7FJL-7F7|||F----J|F-JLJL7F---JL7FJF7|LJFJL|||F-JFFJ|||7|FJ|L7.|FJ||L7||F-JF-JF--7LJ|L-7L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||||||L7L7||L--7F7FF-7|F7L||LJFJ|||-||F7JLJ|L77J.| +JJ7.|.LJ|F--J||L77FJLJ|||F7LJF-JL7L---7F7||F7|FJ-|F-JF-JLJ|F7FJL7L-7||L7FJFJ|FJ|F7F-J|||L7||||||FJFJ|L-7FJ|L-JFJFJL-JL77L-J||FJLJL-7JL-J--|7 +|-J-7-LLLL---JL7L-JF-7LJ|||F7L--7L----J||||||||F7||F7L--7FJ||L7FJF7|||FJL7|||||||LJF7|||FJ||||||L7|JL-7|L-JF7FJJL--7F7L7F7|LJ|F-7F-J7J.|7..J +|.|7JFLJ|F----7L7F7L7L-7LJLJL---JF7F-7FJ|||||||||||||F-7||FJ|FJ|FJ|||||F-JL7|L7|L7FJ||LJ|FJLJ||L7||F7FJL7F-JLJJFF7FJ|L7LJL-7FJ|FJ|F7|F777F-J +.F77--7-L|F--7L-J|L7|F-JF--7F7F-7|||FJL7||LJLJ||||||||FJ||||LJFJL7|||||L--7||L|L7||FJ|F-J|F7FJ|FJ|||||F-JL-7F7.FJ||FJJL7F--JL7|L7LJL-JL7--J| +FF-7-LF-7LJF7L--7|.LJL--JF-J|||FJ|||L7FJ||F---J|||||||L7||L-7FJF7|||||L7F7|||FJFJLJL7|L-7LJ|L-JL7||||||F7F7LJL-JFJ|L7FFJL--7J|L7L7F7F7FJ.|7- +LJ-|77F.F--JL---JL7-F7F--JF7|LJL7||L7||FJ||F-7FJ|||||||||L7FJL7|||LJ||-||||||L7L-7F7||F-JF7L-7F-J|LJLJ|||||F7F-7L7|FJFJF7F7L7|FJ7||LJLJJ7..| +|JF77LF-JF7F----7FJFJLJF7FJLJF--J||FJ||L7|||FJL7||||||FJL7|L7FJ||L-7LJFJ||||L7L7FJ|LJ||F7||F7||F7L---7||LJ|||L7|FJLJFJFJ|||FJLJFFJL7J.J.|F-J +-.LJJ.L7FJLJ.F--JL7|F7FJ|||F7L-7FJ|L7||7||||L7FJLJLJLJL7FJL7|L7||F7L-7|FJLJL-JFJL7L7FJ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7|.LF7-L777L|L-JL---JLFJF7FJLF.L7FJL7L-J.F|.|JF|.-7JJJ.LF-F.| +J7J|F|-JJ|J|F--JJLJLJ.L--L7LLJJ7F7|.F-7L--JL-F-JL--FLJ-F-F-JL7|J.F|L7F7F-7|.L|J7-F-|F.LLFJ-|.|LLJL|7.L7||L7FJ7JLF7|JJFL7FJ-|7F-7LJJ.-FJ.L--| +LJ.J-F-.|F-7JFLLF-F77LL7LLJ.|L|7|.7FFJL.LL7JF-J--J7FJF||-J.-7JJ.--|L7.-JLL-L7|L.L||L.|7.L|7.-L7L.7J-LFJ|L7L7.77J.|JJ.|.F7.FL7LL|J||.|..F.FL. +FFJJ7||FJ-7L.7|-LJJ|J.||7J|-7-FJFF7JL-F|..LF7J||..JL7J|JF|.LJ7FFJLL7|-|F7..LL77.7LF77.FF|||-L7L..--|.L7|JL7|F-.F7J||.F-J|-7F-7J|7J7.J--F77.F +-J.FL|JJ|.J|-LJ7||FJJFJ||--7L-|-|LJ7.LLJ77F|J.---7.||LJF|LJFFF7-JLL7|.LJ-777..-7LFLL-7F7J-J--7FF7..L|L|||FLJ--7-|7-LF7.F7.7J|.F||.L.L|.LLJ77 +||FL-|L-JFL-.L-FF-7|.F7F77LFJL|JJ|.F.||7.L-|FJL7-7J--7--J.LL-JLL77-||77J.||---J|.J-JF7-|JFL7|||JL-7JJFJ|77-LJ7JLJ.|-J|F|J||JF|-J7|J7..|77..7 +FL..F-.J.7J-LJJ|LL-J-LL7JLJLJ..|.F7L7-F|J-LJJJ-L.LLJJ.FJL|...-.FJL-LJJLF7.J.F-J.-|LL-.LFJ.L-F-J.LJJJJL-JJF.JJL-7J-JJLLJJ-JL.LL7LJJL-7-LJJJ-. diff --git a/aoc2023/src/day10.rs b/aoc2023/src/day10.rs new file mode 100644 index 0000000..6e411ad --- /dev/null +++ b/aoc2023/src/day10.rs @@ -0,0 +1,243 @@ +use aoc_runner_derive::{aoc, aoc_generator}; + +#[aoc_generator(day10)] +fn parse(input: &str) -> utils::Map { + let mut grid = pathfinding::matrix::Matrix::new( + input.lines().count(), + input.lines().next().unwrap().len(), + utils::Tile::Ground, + ); + input.lines().enumerate().for_each(|(x, line)| { + line.chars().enumerate().for_each(|(y, c)| { + grid[(x, y)] = c.try_into().unwrap(); + }); + }); + + let start_position = grid + .items() + .find_map(|((x, y), &tile)| (tile == utils::Tile::Start).then_some((x, y))) + .unwrap(); + + utils::Map { + grid, + start_position, + } +} + +mod utils { + #[derive(Debug, Clone, Copy, PartialEq)] + pub enum Tile { + PipeNorthSouth, + PipeWestEast, + BendNorthEast, + BendNorthWest, + BendSouthWest, + BendSouthEast, + Ground, + Start, + } + + impl TryFrom for Tile { + type Error = &'static str; + fn try_from(c: char) -> Result { + match c { + '|' => Ok(Self::PipeNorthSouth), + '-' => Ok(Self::PipeWestEast), + 'L' => Ok(Self::BendNorthEast), + 'J' => Ok(Self::BendNorthWest), + '7' => Ok(Self::BendSouthWest), + 'F' => Ok(Self::BendSouthEast), + '.' => Ok(Self::Ground), + 'S' => Ok(Self::Start), + _ => Err("Unknown tile type!"), + } + } + } + + pub struct Map { + pub grid: pathfinding::matrix::Matrix, + pub start_position: (usize, usize), + } + + impl Map { + pub fn get_loop(&self) -> Vec<(usize, usize)> { + let mut position = self.start_position; + let mut direction = self.get_initial_direction(); + let mut loop_indices = Vec::new(); + loop { + // Move in the direction of the pipe + position = self.grid.move_in_direction(position, direction).unwrap(); + + // Add the position to the loop indices + loop_indices.push(position); + + // Return once the loop is closed + if position == self.start_position { + return loop_indices; + } + + // Determine the next direction + direction = match (direction, self.grid[position]) { + ((-1 | 1, 0), Tile::PipeNorthSouth) | ((0, -1 | 1), Tile::PipeWestEast) => { + direction + } + ((1, 0), Tile::BendNorthWest) | ((-1, 0), Tile::BendSouthWest) => (0, -1), + ((1, 0), Tile::BendNorthEast) | ((-1, 0), Tile::BendSouthEast) => (0, 1), + ((0, -1), Tile::BendNorthEast) | ((0, 1), Tile::BendNorthWest) => (-1, 0), + ((0, -1), Tile::BendSouthEast) | ((0, 1), Tile::BendSouthWest) => (1, 0), + _ => unreachable!("All possible directions are covered!"), + }; + } + } + + fn get_initial_direction(&self) -> (isize, isize) { + let (x, y) = self.start_position; + if let Some(x_minus_1) = x.checked_sub(1) { + if let Tile::PipeNorthSouth | Tile::BendSouthWest | Tile::BendSouthEast = + self.grid[(x_minus_1, y)] + { + return (-1, 0); + } + } + if x + 1 < self.grid.rows { + if let Tile::PipeNorthSouth | Tile::BendNorthWest | Tile::BendNorthEast = + self.grid[(x + 1, y)] + { + return (1, 0); + } + } + if let Some(y_minus_1) = y.checked_sub(1) { + if let Tile::PipeWestEast | Tile::BendNorthEast | Tile::BendSouthEast = + self.grid[(x, y_minus_1)] + { + return (0, -1); + } + } + if y + 1 < self.grid.columns { + if let Tile::PipeWestEast | Tile::BendNorthWest | Tile::BendSouthWest = + self.grid[(x, y + 1)] + { + return (0, 1); + } + } + unreachable!("All possible initial directions are covered!") + } + } +} + +#[aoc(day10, part1)] +fn part1(input: &utils::Map) -> usize { + // The furthest point from the start is always the middle of the loop + input.get_loop().len() / 2 +} + +#[aoc(day10, part2)] +fn part2(input: &utils::Map) -> usize { + // Construct a grid that only contains the loop + let mut enclosure = + pathfinding::matrix::Matrix::new(input.grid.rows, input.grid.columns, utils::Tile::Ground); + for position in input.get_loop() { + enclosure[position] = input.grid[position]; + } + + // Iterate over the rows of the enclosure, while skipping the first and last rows (not inside the enclosure) + enclosure + .iter() + .skip(1) + .take(enclosure.rows - 2) + .map(|row| { + row.iter() + .fold((0, false), |(mut n_inside, mut is_inside), &tile| { + // Detect the start and discontinuities of the enclosure + if let utils::Tile::PipeNorthSouth + | utils::Tile::BendNorthWest + | utils::Tile::BendNorthEast = tile + { + is_inside = !is_inside; + } + + // Count only the ground tiles inside the enclosure + if is_inside && tile == utils::Tile::Ground { + n_inside += 1; + } + + (n_inside, is_inside) + }) + .0 + }) + .sum() +} + +#[cfg(test)] +mod tests { + use super::*; + use indoc::indoc; + + #[test] + fn part1_example() { + const SAMPLES: [&str; 2] = [ + indoc! {" + ..... + .S-7. + .|.|. + .L-J. + ..... + "}, + indoc! {" + ..F7. + .FJ|. + SJ.L7 + |F--J + LJ... + "}, + ]; + + assert_eq!(part1(&parse(SAMPLES[0])), 4); + assert_eq!(part1(&parse(SAMPLES[1])), 8); + } + + #[test] + fn part2_example() { + const SAMPLES: [&str; 3] = [ + indoc! {" + ........... + .S-------7. + .|F-----7|. + .||.....||. + .||.....||. + .|L-7.F-J|. + .|..|.|..|. + .L--J.L--J. + ........... + "}, + indoc! {" + .F----7F7F7F7F-7.... + .|F--7||||||||FJ.... + .||.FJ||||||||L7.... + FJL7L7LJLJ||LJ.L-7.. + L--J.L7...LJS7F-7L7. + ....F-J..F7FJ|L7L7L7 + ....L7.F7||L7|.L7L7| + .....|FJLJ|FJ|F7|.LJ + ....FJL-7.||.||||... + ....L---J.LJ.LJLJ... + "}, + indoc! {" + FF7FSF7F7F7F7F7F---7 + L|LJ||||||||||||F--J + FL-7LJLJ||||||LJL-77 + F--JF--7||LJLJ7F7FJ- + L---JF-JLJ.||-FJLJJ7 + |F|F-JF---7F7-L7L|7| + |FFJF7L7F-JF7|JL---7 + 7-L-JL7||F7|L7F-7F7| + L.L7LFJ|||||FJL7||LJ + L7JLJL-JLJLJL--JLJ.L + "}, + ]; + + assert_eq!(part2(&parse(SAMPLES[0])), 4); + assert_eq!(part2(&parse(SAMPLES[1])), 8); + assert_eq!(part2(&parse(SAMPLES[2])), 10); + } +} diff --git a/aoc2023/src/lib.rs b/aoc2023/src/lib.rs index efcdf9f..344502b 100644 --- a/aoc2023/src/lib.rs +++ b/aoc2023/src/lib.rs @@ -1,4 +1,5 @@ pub mod day1; +pub mod day10; pub mod day2; pub mod day3; pub mod day4;