From 0ca868fc1c83916ce30d5ad11ad4797bdc182fad Mon Sep 17 00:00:00 2001 From: Kienan Stewart Date: Sun, 18 Dec 2022 18:42:24 -0500 Subject: [PATCH] AOC 2022 day 18 --- 2022/18/.gitignore | 1 + 2022/18/Cargo.lock | 77 ++ 2022/18/Cargo.toml | 10 + 2022/18/input | 2150 +++++++++++++++++++++++++++++++++++++++++++ 2022/18/src/main.rs | 366 ++++++++ 2022/18/test_input | 13 + 2022/18/test_input2 | 2 + 7 files changed, 2619 insertions(+) create mode 100644 2022/18/.gitignore create mode 100644 2022/18/Cargo.lock create mode 100644 2022/18/Cargo.toml create mode 100644 2022/18/input create mode 100644 2022/18/src/main.rs create mode 100644 2022/18/test_input create mode 100644 2022/18/test_input2 diff --git a/2022/18/.gitignore b/2022/18/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/2022/18/.gitignore @@ -0,0 +1 @@ +/target diff --git a/2022/18/Cargo.lock b/2022/18/Cargo.lock new file mode 100644 index 0000000..7586a35 --- /dev/null +++ b/2022/18/Cargo.lock @@ -0,0 +1,77 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "common" +version = "0.1.0" + +[[package]] +name = "day18" +version = "0.1.0" +dependencies = [ + "common", + "ndarray", +] + +[[package]] +name = "matrixmultiply" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "add85d4dd35074e6fedc608f8c8f513a3548619a9024b751949ef0e8e45a4d84" +dependencies = [ + "rawpointer", +] + +[[package]] +name = "ndarray" +version = "0.15.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb12d4e967ec485a5f71c6311fe28158e9d6f4bc4a447b474184d0f91a8fa32" +dependencies = [ + "matrixmultiply", + "num-complex", + "num-integer", + "num-traits", + "rawpointer", +] + +[[package]] +name = "num-complex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ae39348c8bc5fbd7f40c727a9925f03517afd2ab27d46702108b6a7e5414c19" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" diff --git a/2022/18/Cargo.toml b/2022/18/Cargo.toml new file mode 100644 index 0000000..f29a66b --- /dev/null +++ b/2022/18/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "day18" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +common = { path = "../common" } +ndarray = "0.15" diff --git a/2022/18/input b/2022/18/input new file mode 100644 index 0000000..ff3599f --- /dev/null +++ b/2022/18/input @@ -0,0 +1,2150 @@ +13,2,10 +3,6,9 +11,17,9 +7,2,11 +14,6,5 +13,16,8 +9,7,2 +3,9,14 +8,3,5 +3,12,9 +7,3,7 +13,2,13 +4,6,5 +13,4,9 +4,8,10 +15,5,8 +17,14,11 +13,17,11 +13,7,2 +11,14,4 +8,9,17 +14,7,15 +4,10,4 +9,12,2 +8,5,13 +14,15,6 +15,14,11 +8,16,10 +2,13,10 +8,18,8 +14,14,5 +3,5,7 +18,8,10 +13,14,11 +6,8,17 +14,10,16 +15,6,6 +16,13,10 +14,4,7 +5,3,5 +10,14,2 +4,13,5 +12,10,1 +6,7,15 +5,10,3 +6,15,13 +14,13,3 +13,14,16 +9,6,16 +10,14,16 +13,16,10 +4,3,10 +2,11,6 +9,12,16 +8,1,8 +9,2,7 +16,10,16 +5,10,15 +16,5,12 +5,11,13 +7,15,8 +5,14,14 +3,8,8 +5,16,6 +5,12,16 +11,16,4 +3,6,10 +8,12,2 +9,10,2 +4,12,8 +9,13,17 +7,12,16 +5,16,13 +12,11,18 +4,10,17 +5,14,6 +5,13,13 +3,7,5 +6,16,11 +3,11,5 +15,11,15 +4,6,14 +5,2,8 +5,13,12 +14,6,16 +3,5,8 +15,15,14 +15,8,15 +16,7,4 +10,4,3 +17,12,7 +7,16,7 +6,10,17 +9,2,9 +10,18,9 +15,7,8 +16,16,12 +3,4,11 +16,15,11 +13,16,5 +13,4,6 +13,3,13 +15,12,11 +14,3,11 +9,16,11 +3,13,8 +13,6,15 +6,14,6 +12,2,11 +3,5,12 +7,17,8 +5,15,5 +8,11,2 +14,3,10 +11,16,8 +4,12,4 +10,11,3 +16,7,12 +5,5,14 +2,7,10 +13,7,17 +16,5,11 +15,6,13 +8,8,18 +3,10,5 +2,6,11 +10,4,5 +12,7,17 +3,9,6 +17,7,11 +10,5,16 +17,6,11 +10,2,12 +7,10,18 +8,16,11 +11,15,15 +16,10,5 +10,16,4 +4,16,6 +15,4,11 +2,9,9 +3,7,6 +5,3,6 +10,16,5 +13,15,11 +3,4,9 +3,8,12 +6,5,4 +2,9,8 +2,7,7 +16,14,14 +15,10,15 +16,10,13 +9,14,4 +2,7,6 +13,3,11 +17,13,10 +12,2,10 +8,16,13 +16,11,11 +12,10,17 +6,15,11 +10,17,13 +6,10,4 +8,12,4 +3,11,14 +9,5,4 +15,6,14 +6,6,4 +14,5,5 +17,10,9 +18,11,11 +5,4,5 +15,5,15 +12,5,13 +3,8,7 +13,3,14 +13,8,3 +3,5,10 +10,17,7 +15,15,13 +14,13,15 +5,14,12 +12,3,11 +14,13,5 +13,17,9 +5,8,17 +8,2,11 +10,11,2 +9,5,1 +11,3,9 +14,4,10 +11,12,2 +10,14,17 +17,11,11 +11,16,11 +9,11,1 +5,4,13 +17,9,10 +2,11,12 +10,9,17 +12,16,7 +16,12,8 +11,7,1 +12,8,17 +18,7,11 +10,4,17 +5,5,3 +2,10,13 +8,5,14 +3,9,10 +6,5,14 +7,7,2 +8,2,7 +15,9,16 +10,14,4 +5,15,7 +14,13,12 +17,14,8 +16,11,8 +15,6,15 +3,11,15 +10,6,2 +11,14,16 +10,5,14 +2,8,11 +12,4,16 +9,17,12 +4,4,11 +12,16,6 +2,9,6 +15,7,10 +7,8,2 +11,2,11 +5,6,3 +11,18,8 +4,10,10 +12,4,15 +2,14,10 +7,11,2 +13,11,16 +2,9,11 +4,14,6 +12,8,18 +4,7,15 +8,12,17 +3,15,7 +15,16,8 +3,7,15 +10,2,13 +12,16,11 +15,4,13 +14,10,2 +12,15,15 +5,12,15 +12,15,4 +9,10,18 +9,8,2 +14,15,12 +3,13,11 +13,17,10 +2,10,12 +6,17,7 +15,14,7 +8,2,6 +11,5,5 +7,8,3 +4,7,8 +9,3,11 +13,4,3 +14,3,8 +13,4,4 +14,15,5 +4,6,7 +6,14,7 +6,2,7 +6,5,5 +11,3,6 +10,15,5 +6,3,13 +13,14,6 +13,14,15 +3,9,7 +14,3,7 +8,9,18 +14,8,12 +13,3,8 +15,15,9 +7,16,4 +6,18,9 +10,15,3 +6,16,12 +9,14,2 +12,3,8 +9,11,15 +4,15,9 +8,2,9 +8,11,1 +14,11,15 +11,11,1 +1,11,9 +14,7,13 +6,10,16 +15,12,5 +12,3,7 +15,11,7 +12,13,14 +12,10,3 +5,4,7 +12,13,17 +6,9,17 +14,8,3 +2,9,10 +17,9,6 +4,15,5 +4,13,6 +10,12,16 +3,8,4 +11,1,9 +2,6,13 +2,12,4 +11,10,17 +13,15,16 +9,2,6 +6,11,3 +3,7,13 +8,15,13 +15,7,7 +3,12,12 +17,9,11 +13,13,15 +12,2,7 +5,9,15 +7,15,13 +9,4,16 +9,14,14 +11,10,2 +16,8,12 +10,3,5 +11,18,9 +11,13,15 +3,14,9 +8,18,13 +8,10,17 +6,13,3 +5,13,14 +7,4,5 +15,14,8 +8,18,10 +4,5,10 +16,6,11 +15,13,10 +12,16,9 +9,5,16 +4,14,10 +11,17,11 +12,17,10 +17,8,8 +15,3,12 +14,11,17 +16,5,9 +11,8,1 +5,12,3 +9,3,7 +14,7,3 +16,11,14 +15,9,7 +14,11,6 +11,1,7 +2,12,10 +6,3,8 +3,5,9 +10,10,2 +4,6,11 +4,10,8 +6,12,17 +13,3,10 +8,9,1 +4,5,12 +3,13,7 +14,5,4 +10,2,6 +3,14,10 +17,6,8 +15,13,7 +9,5,15 +10,5,4 +11,14,15 +16,5,8 +8,3,11 +4,15,6 +16,15,8 +16,8,6 +13,15,13 +2,6,12 +3,14,15 +16,7,14 +5,14,5 +10,16,14 +17,7,9 +14,15,7 +4,7,5 +14,14,4 +6,7,17 +0,10,7 +6,16,8 +17,15,9 +4,8,14 +14,14,6 +5,5,8 +13,13,4 +3,12,5 +7,17,11 +13,14,14 +15,8,3 +3,10,14 +8,6,1 +7,3,8 +6,12,16 +17,10,8 +11,8,17 +17,8,6 +14,5,6 +7,2,7 +12,16,15 +14,3,14 +17,9,7 +12,18,6 +3,14,12 +15,12,15 +14,5,13 +17,11,6 +7,13,2 +3,6,7 +17,8,5 +14,15,9 +13,11,3 +16,14,11 +8,17,11 +13,6,2 +10,17,14 +12,12,15 +5,7,16 +7,14,4 +7,2,9 +5,6,4 +15,14,5 +16,3,7 +14,4,4 +4,13,9 +9,16,15 +8,17,8 +15,6,11 +11,12,16 +14,17,7 +5,15,6 +16,11,12 +5,16,10 +12,4,6 +3,13,10 +1,8,9 +7,2,10 +7,13,17 +19,9,11 +6,11,16 +9,18,10 +16,11,4 +13,7,16 +10,3,7 +15,13,13 +8,11,4 +5,15,12 +17,10,6 +14,12,15 +17,13,8 +6,13,15 +7,7,16 +10,2,8 +4,13,13 +9,15,14 +9,4,3 +6,4,8 +5,10,16 +4,7,16 +13,10,16 +5,6,15 +8,10,16 +7,16,6 +7,7,17 +3,11,12 +12,7,1 +16,12,15 +6,16,6 +10,17,11 +7,5,13 +10,14,13 +16,7,5 +11,13,17 +7,7,4 +6,5,13 +9,16,6 +4,9,4 +13,16,13 +5,11,5 +5,3,8 +11,4,9 +17,9,9 +6,4,7 +15,9,6 +8,5,16 +3,12,14 +12,17,9 +3,8,9 +6,2,8 +15,9,14 +2,6,10 +18,11,7 +4,3,8 +12,11,16 +17,13,7 +2,10,6 +1,13,7 +16,6,6 +6,14,14 +12,10,2 +3,5,5 +15,9,15 +15,5,6 +3,6,14 +9,5,3 +11,3,11 +7,5,15 +13,11,4 +7,5,5 +13,8,16 +15,13,6 +2,7,8 +16,14,10 +6,6,15 +15,16,9 +10,17,10 +8,4,6 +6,16,13 +17,4,10 +5,9,3 +9,13,2 +6,17,9 +9,13,16 +7,9,18 +9,17,10 +11,2,9 +17,7,7 +7,2,12 +8,13,17 +16,11,5 +18,7,9 +12,13,2 +9,15,9 +9,2,11 +13,3,15 +1,10,12 +3,12,10 +14,4,8 +13,15,5 +7,13,16 +3,15,9 +15,12,16 +12,4,13 +10,6,17 +11,10,18 +6,17,10 +14,6,10 +12,5,15 +7,9,1 +7,5,17 +5,3,9 +13,15,7 +4,4,8 +7,8,17 +3,12,13 +17,8,13 +9,3,12 +1,14,9 +4,14,12 +9,16,16 +10,10,17 +5,8,16 +6,16,15 +11,15,3 +12,9,2 +2,8,6 +6,11,17 +7,8,16 +6,6,3 +3,6,6 +6,2,10 +7,15,12 +9,4,2 +11,3,14 +16,15,13 +13,14,13 +16,15,7 +14,9,7 +6,3,7 +15,16,11 +5,15,13 +2,10,4 +5,11,14 +15,14,14 +7,3,10 +12,15,14 +7,5,4 +14,11,3 +7,1,11 +13,2,12 +5,2,9 +10,4,16 +9,17,6 +6,8,4 +15,5,5 +12,2,6 +3,8,6 +7,12,17 +12,16,10 +16,13,8 +15,3,8 +17,9,8 +10,2,9 +12,8,5 +16,7,13 +14,16,8 +4,12,16 +8,3,6 +7,18,6 +12,5,5 +10,2,14 +17,6,12 +7,9,17 +5,3,10 +15,4,14 +14,2,10 +12,6,4 +7,16,12 +6,17,8 +15,9,4 +15,7,13 +7,9,4 +6,3,6 +2,13,7 +3,12,8 +3,8,15 +8,3,8 +7,16,5 +12,6,2 +3,12,4 +6,10,2 +17,8,10 +11,2,10 +6,16,9 +8,15,4 +9,9,18 +17,13,9 +3,9,13 +9,15,12 +12,11,3 +18,7,8 +12,4,5 +9,5,6 +10,7,2 +2,8,7 +2,8,13 +10,6,16 +9,3,15 +3,7,4 +1,9,9 +13,16,12 +11,5,15 +4,8,16 +14,4,9 +5,6,14 +11,7,18 +12,12,3 +17,6,7 +16,6,13 +14,15,14 +11,11,17 +15,5,11 +7,15,14 +10,3,16 +15,15,5 +2,11,7 +13,13,16 +5,5,4 +7,5,3 +12,3,15 +14,14,7 +8,16,14 +4,10,13 +5,8,13 +17,14,10 +16,12,5 +5,17,12 +2,10,11 +10,1,10 +16,11,6 +11,3,5 +18,9,12 +16,13,12 +15,10,3 +13,2,8 +2,12,7 +8,7,16 +6,15,14 +15,7,3 +16,6,10 +12,15,12 +9,15,4 +10,12,3 +3,13,9 +8,6,4 +8,5,15 +5,3,13 +16,14,5 +4,12,5 +18,12,9 +16,6,9 +16,14,8 +8,5,4 +10,7,3 +13,4,5 +6,14,4 +8,10,2 +12,16,13 +12,11,17 +10,6,5 +4,5,7 +18,8,9 +17,6,9 +9,16,9 +17,8,7 +6,9,2 +10,8,2 +4,16,8 +8,17,14 +8,15,15 +14,12,13 +16,10,9 +8,16,6 +2,9,13 +2,8,14 +5,10,14 +7,15,3 +10,4,15 +5,8,15 +4,10,15 +14,7,6 +15,6,12 +9,16,4 +13,16,11 +5,5,13 +12,3,14 +10,15,2 +8,2,13 +13,12,15 +3,3,9 +4,4,6 +14,7,4 +6,14,12 +14,7,17 +5,9,4 +13,4,13 +8,12,16 +8,2,14 +3,13,12 +10,18,6 +17,11,5 +13,9,3 +14,16,12 +2,13,12 +11,14,17 +8,17,12 +4,14,13 +14,8,2 +11,2,6 +8,13,3 +9,4,15 +10,2,15 +12,11,4 +2,14,9 +4,14,5 +15,4,9 +7,2,13 +9,16,10 +9,12,17 +13,5,4 +16,4,12 +11,16,13 +7,3,14 +7,13,3 +12,7,16 +14,12,16 +9,16,7 +11,12,4 +11,3,12 +13,18,7 +16,9,14 +16,14,6 +1,7,7 +16,12,10 +16,8,14 +14,10,4 +15,10,14 +14,14,15 +15,15,6 +12,14,4 +11,6,3 +16,9,6 +17,12,11 +5,6,5 +8,17,9 +17,8,4 +5,4,14 +17,12,10 +6,4,5 +4,4,10 +15,6,5 +18,6,9 +4,12,9 +12,7,3 +8,10,18 +16,12,13 +9,5,5 +5,13,15 +14,4,12 +4,7,6 +10,9,2 +1,12,10 +12,2,8 +7,14,3 +8,9,2 +3,6,11 +17,9,12 +6,3,9 +4,8,4 +16,7,6 +4,10,16 +5,14,13 +5,15,9 +12,16,4 +6,7,2 +12,2,13 +8,5,3 +9,9,2 +10,6,3 +12,4,11 +11,2,7 +9,10,4 +11,16,5 +13,12,3 +11,8,2 +1,10,8 +9,15,17 +7,11,16 +5,5,11 +11,14,3 +11,17,8 +12,16,8 +4,4,5 +10,3,15 +8,4,5 +1,7,8 +4,2,7 +3,7,14 +11,6,2 +13,17,7 +15,11,3 +13,15,12 +6,5,15 +1,6,10 +4,13,4 +6,2,13 +8,3,13 +5,4,6 +15,12,4 +9,7,17 +14,7,16 +8,11,18 +14,12,4 +7,16,10 +13,2,11 +12,9,18 +10,1,9 +18,9,11 +14,12,5 +9,17,7 +17,7,12 +5,14,9 +13,9,1 +10,5,15 +16,11,16 +4,3,11 +3,4,12 +4,5,5 +14,12,3 +10,6,4 +12,15,7 +2,9,12 +8,6,15 +3,14,11 +9,16,5 +17,11,9 +7,17,7 +3,7,3 +13,10,17 +2,12,13 +7,3,11 +13,7,3 +3,5,6 +11,17,6 +16,10,11 +13,4,14 +6,7,3 +11,7,16 +3,6,13 +9,16,12 +13,16,7 +9,2,10 +9,15,15 +6,12,2 +11,15,5 +5,11,6 +5,13,5 +16,4,9 +13,3,9 +16,8,15 +13,11,2 +9,3,5 +8,16,5 +14,3,12 +4,11,3 +9,2,12 +2,10,8 +3,8,14 +5,11,4 +6,14,11 +16,10,12 +9,17,8 +4,7,7 +7,16,11 +10,9,1 +6,5,12 +12,4,7 +15,14,9 +8,12,18 +14,6,14 +8,7,3 +8,8,17 +8,4,14 +2,8,9 +14,5,14 +4,4,14 +13,3,6 +2,12,11 +6,10,15 +14,8,15 +16,5,13 +11,13,4 +16,13,6 +1,10,6 +17,6,10 +5,7,2 +8,6,17 +11,4,4 +15,4,7 +13,3,5 +13,17,5 +13,4,8 +13,5,14 +8,3,4 +8,3,10 +10,13,2 +8,8,2 +17,11,10 +14,14,14 +11,4,5 +14,16,7 +3,14,8 +8,3,14 +9,3,16 +15,14,12 +12,11,2 +15,4,6 +7,10,17 +5,7,5 +5,5,5 +16,14,9 +11,12,17 +8,7,18 +9,10,1 +11,11,3 +11,2,13 +9,16,14 +6,15,15 +11,2,8 +9,12,18 +3,7,7 +14,15,8 +4,6,8 +4,11,4 +7,4,6 +13,9,15 +6,7,5 +7,15,16 +12,9,1 +10,12,2 +2,11,9 +13,3,12 +3,4,10 +3,8,3 +16,10,4 +10,13,3 +4,4,7 +3,10,12 +9,9,17 +7,14,16 +6,17,12 +6,8,3 +7,18,10 +2,12,9 +8,9,3 +2,5,10 +9,1,8 +17,6,13 +12,3,6 +2,11,8 +2,7,9 +8,4,15 +17,14,9 +16,8,4 +17,12,13 +12,3,5 +10,3,13 +2,10,14 +7,16,8 +5,10,2 +14,5,8 +9,14,16 +11,6,4 +17,5,11 +16,6,7 +16,11,9 +13,16,6 +7,4,14 +5,7,6 +10,5,3 +3,6,12 +14,5,15 +3,10,15 +12,4,3 +8,6,2 +9,8,17 +6,16,7 +12,11,1 +4,12,6 +7,6,3 +12,4,12 +8,14,4 +2,11,11 +14,17,13 +8,16,12 +13,15,4 +6,12,3 +9,16,8 +10,9,0 +7,10,2 +15,10,4 +16,5,6 +12,6,16 +16,9,5 +17,11,15 +5,15,10 +3,12,11 +15,6,9 +6,11,4 +13,10,4 +14,16,11 +12,18,8 +13,10,3 +15,12,7 +11,16,10 +4,7,4 +13,15,6 +10,5,2 +11,7,15 +7,2,8 +17,7,10 +10,17,8 +14,10,3 +15,9,17 +18,11,9 +6,6,16 +13,6,4 +6,4,13 +8,7,17 +7,3,4 +2,13,8 +12,1,6 +5,9,16 +13,5,6 +10,17,12 +13,11,17 +7,12,3 +14,9,15 +11,13,16 +14,9,14 +14,8,4 +12,14,3 +16,13,4 +11,9,2 +2,6,9 +4,9,7 +16,11,10 +17,11,8 +3,4,8 +5,14,11 +3,5,11 +4,14,11 +14,17,12 +3,7,9 +5,11,3 +11,11,2 +11,16,16 +9,16,13 +5,13,4 +15,11,4 +13,15,14 +14,11,14 +10,8,4 +11,7,3 +6,15,5 +11,5,3 +15,15,7 +11,16,15 +16,4,7 +7,16,13 +6,12,15 +3,9,15 +9,15,5 +9,1,10 +10,19,11 +14,4,6 +6,13,2 +18,12,11 +3,15,11 +12,13,16 +9,17,13 +16,10,14 +8,15,5 +6,3,15 +9,11,17 +14,9,17 +12,6,6 +4,9,15 +7,18,8 +9,1,12 +1,10,9 +11,5,17 +17,11,12 +12,18,11 +11,9,4 +14,9,16 +2,12,5 +5,4,9 +17,7,8 +3,10,3 +14,16,13 +6,7,4 +17,12,9 +8,17,5 +10,3,6 +13,3,7 +7,3,9 +8,9,16 +4,14,8 +10,11,16 +10,3,14 +5,17,11 +1,7,11 +0,9,10 +4,7,14 +4,13,14 +8,5,17 +17,13,12 +4,13,15 +17,7,5 +8,10,3 +6,6,6 +7,15,15 +6,12,18 +11,4,15 +4,2,6 +19,10,12 +11,1,12 +4,15,8 +13,10,14 +15,4,12 +15,13,4 +8,14,16 +11,15,6 +4,14,15 +16,6,4 +17,9,14 +12,2,5 +12,14,15 +11,10,16 +4,3,12 +12,16,12 +16,13,11 +10,7,18 +12,3,12 +5,6,13 +13,6,1 +13,4,10 +5,16,8 +15,12,14 +13,16,14 +10,16,13 +16,8,11 +7,14,17 +9,8,1 +15,14,15 +7,4,12 +15,8,4 +11,4,3 +11,18,7 +4,4,9 +5,4,12 +8,3,12 +6,16,10 +1,7,9 +4,11,15 +4,17,11 +4,12,14 +13,17,8 +2,10,10 +12,7,15 +18,9,9 +8,2,12 +14,6,2 +3,7,8 +9,8,3 +5,16,7 +13,9,2 +0,10,8 +13,7,4 +18,11,6 +5,11,17 +3,7,11 +8,17,10 +10,3,10 +1,10,7 +7,9,2 +12,13,4 +15,11,16 +9,18,13 +13,4,7 +11,9,17 +10,15,14 +16,10,15 +7,4,13 +12,9,17 +4,8,12 +10,10,1 +5,7,13 +14,17,9 +14,14,12 +15,12,13 +5,6,16 +18,9,7 +18,11,12 +12,8,3 +4,5,8 +6,7,16 +11,12,18 +16,12,14 +9,2,14 +12,8,16 +2,6,8 +6,5,16 +7,17,6 +8,1,10 +1,13,10 +10,16,15 +2,13,13 +9,3,13 +14,13,14 +14,5,9 +15,10,16 +14,9,4 +5,14,8 +6,6,17 +18,10,13 +15,15,12 +3,10,7 +11,16,9 +10,2,7 +8,18,7 +14,4,5 +8,13,4 +7,12,2 +7,4,7 +16,15,9 +10,9,18 +14,6,15 +11,7,17 +17,10,14 +14,11,4 +14,13,16 +10,8,19 +4,13,3 +11,13,14 +2,7,11 +13,17,13 +14,7,5 +10,1,8 +5,17,9 +3,9,5 +9,8,18 +7,18,9 +11,10,3 +2,8,12 +14,9,3 +10,18,8 +1,9,8 +15,8,5 +4,9,12 +4,6,4 +11,3,13 +15,10,5 +1,9,12 +3,11,7 +8,7,2 +17,9,13 +9,12,1 +3,11,11 +7,2,6 +4,11,16 +5,11,15 +12,6,3 +7,14,5 +15,13,14 +5,17,10 +12,12,17 +3,12,6 +13,11,1 +8,3,15 +10,7,16 +3,9,8 +3,7,10 +12,7,2 +5,12,5 +4,11,13 +11,9,16 +6,2,12 +11,6,6 +10,17,9 +6,12,4 +9,6,3 +3,13,13 +3,5,13 +7,17,12 +11,13,3 +3,10,11 +16,15,10 +2,9,7 +11,11,18 +2,15,9 +17,6,4 +3,6,5 +12,6,15 +14,8,14 +2,8,10 +10,8,1 +10,2,11 +5,3,7 +5,13,2 +12,10,15 +9,2,5 +4,12,15 +2,12,8 +16,13,14 +6,3,11 +16,8,8 +16,13,5 +4,12,3 +15,7,15 +5,5,15 +17,8,15 +10,13,16 +8,1,7 +7,9,3 +9,13,3 +13,13,3 +5,2,12 +13,14,4 +13,5,15 +9,10,17 +11,4,13 +9,3,14 +7,15,4 +13,6,16 +3,5,14 +11,17,13 +2,13,6 +7,6,17 +11,5,16 +2,12,12 +16,11,15 +16,10,10 +4,16,12 +16,9,4 +8,14,7 +7,13,15 +11,17,5 +10,2,5 +16,7,10 +13,5,9 +15,12,6 +12,2,12 +4,13,10 +6,14,16 +9,9,16 +12,15,13 +2,7,5 +10,1,7 +12,1,12 +7,3,5 +13,14,5 +7,14,15 +16,9,10 +16,12,7 +2,10,7 +4,7,12 +4,6,12 +3,15,13 +5,14,10 +7,7,1 +12,16,16 +18,10,8 +4,10,14 +2,12,6 +12,5,16 +5,12,4 +11,15,16 +17,10,13 +11,2,14 +3,13,5 +17,8,9 +13,8,15 +10,3,11 +1,8,11 +3,9,12 +4,8,13 +4,11,9 +4,15,10 +7,11,3 +15,7,6 +14,5,11 +8,11,17 +15,8,13 +10,12,1 +16,9,16 +10,2,4 +17,5,9 +14,11,16 +5,10,4 +17,10,7 +10,8,17 +15,5,7 +15,12,12 +11,17,12 +16,7,7 +14,6,3 +8,4,16 +8,14,3 +4,8,15 +10,15,4 +15,5,9 +18,9,8 +15,14,13 +7,4,11 +12,2,15 +6,9,4 +15,7,16 +10,6,1 +16,9,3 +14,15,10 +8,2,10 +6,4,11 +12,14,17 +10,5,6 +10,3,12 +16,15,6 +14,16,6 +5,3,11 +16,8,13 +9,15,16 +12,5,3 +10,15,17 +12,12,16 +9,6,2 +8,6,18 +12,7,4 +15,10,2 +1,6,11 +5,4,8 +15,14,6 +6,4,16 +10,9,3 +4,4,12 +16,8,10 +11,14,11 +8,4,4 +12,13,3 +15,10,13 +6,15,4 +17,11,7 +1,10,10 +14,4,13 +7,11,1 +11,5,13 +10,11,1 +1,9,10 +5,5,7 +2,8,5 +9,3,8 +10,1,11 +15,5,4 +11,16,6 +6,15,16 +12,5,14 +8,7,1 +9,1,11 +14,11,2 +8,4,3 +13,10,15 +14,2,11 +5,13,3 +5,8,4 +12,16,5 +6,8,2 +17,8,11 +6,2,9 +1,11,8 +13,14,12 +13,5,13 +8,11,3 +6,4,15 +4,10,5 +13,13,14 +7,12,14 +3,13,4 +8,5,8 +4,17,9 +10,16,6 +17,7,6 +7,4,4 +9,5,13 +6,8,14 +10,16,12 +15,3,11 +17,5,12 +4,15,13 +9,7,18 +11,9,15 +18,9,10 +4,5,11 +15,3,6 +15,5,12 +3,14,5 +13,6,3 +9,11,2 +6,11,15 +10,15,15 +14,16,10 +3,11,6 +4,12,13 +14,14,10 +7,16,9 +10,17,5 +8,6,3 +6,9,18 +1,9,11 +11,11,15 +16,8,5 +2,11,10 +13,8,17 +6,1,9 +5,2,11 +0,8,9 +11,1,11 +6,16,5 +17,11,13 +12,3,13 +4,12,17 +18,13,8 +6,15,6 +2,8,8 +14,5,7 +6,14,5 +13,13,5 +1,10,11 +12,1,9 +15,5,13 +11,2,12 +4,15,7 +10,15,16 +13,12,4 +16,8,7 +5,6,10 +14,8,16 +9,13,6 +10,4,14 +14,4,14 +9,8,16 +12,15,16 +14,2,9 +15,5,10 +10,4,4 +7,17,13 +8,17,4 +11,15,14 +7,3,13 +14,7,14 +10,2,10 +2,11,13 +15,14,10 +10,16,7 +9,8,4 +8,16,15 +4,5,4 +5,12,14 +14,6,13 +16,4,10 +16,12,9 +15,12,3 +6,13,16 +11,16,12 +13,13,2 +5,4,11 +18,11,10 +16,13,13 +6,3,10 +17,10,10 +14,13,6 +16,6,15 +15,4,10 +17,10,11 +6,10,3 +10,14,7 +12,9,16 +4,9,5 +11,15,7 +11,12,3 +11,4,7 +9,11,3 +11,9,3 +16,14,12 +13,6,13 +15,9,13 +9,17,9 +9,6,1 +1,8,10 +7,2,14 +6,16,14 +7,5,2 +5,13,6 +14,11,5 +7,2,15 +11,6,17 +4,9,14 +14,14,11 +8,6,16 +3,9,3 +8,13,16 +16,9,7 +6,14,3 +4,9,3 +3,8,13 +15,3,10 +11,9,18 +3,8,5 +17,6,6 +4,3,9 +6,8,16 +13,2,6 +17,15,11 +14,6,4 +4,8,3 +10,10,3 +2,5,9 +9,13,18 +12,4,14 +6,17,11 +2,13,9 +9,7,1 +5,14,7 +8,14,15 +10,10,18 +11,3,15 +3,15,8 +11,15,4 +13,7,15 +14,6,6 +6,9,3 +13,17,12 +8,8,1 +10,4,13 +6,11,18 +12,13,15 +3,11,13 +16,13,7 +10,4,6 +7,6,15 +10,16,16 +5,9,14 +1,6,9 +7,15,11 +7,9,5 +4,5,13 +6,9,6 +12,3,9 +7,7,3 +17,6,5 +14,15,13 +9,11,18 +4,12,7 +6,6,5 +14,3,13 +7,15,5 +6,4,12 +4,6,13 +6,11,5 +7,1,8 +11,18,12 +5,7,12 +16,15,12 +3,14,7 +9,4,14 +3,11,8 +5,17,7 +12,16,14 +9,18,9 +10,12,17 +14,16,9 +6,11,1 +17,5,8 +11,3,4 +10,0,12 +8,17,13 +9,4,12 +4,2,10 +7,13,4 +14,2,7 +18,12,10 +3,7,12 +14,17,11 +11,10,1 +6,6,14 +7,17,10 +13,2,7 +11,16,14 +10,7,1 +7,4,15 +12,4,2 +12,9,3 +3,11,10 +11,5,4 +5,7,14 +16,13,15 +13,9,17 +4,2,11 +7,16,14 +4,11,14 +15,6,4 +16,6,5 +15,7,14 +12,17,12 +5,17,8 +1,12,12 +14,13,8 +10,13,4 +7,18,7 +17,10,12 +5,15,14 +17,8,12 +10,14,3 +7,14,14 +9,1,9 +10,11,18 +5,12,17 +7,6,18 +16,6,8 +6,5,3 +16,5,7 +9,11,16 +11,14,2 +3,10,4 +3,12,7 +6,4,6 +7,17,9 +9,6,17 +5,8,3 +7,13,18 +4,11,5 +6,6,2 +17,12,12 +6,14,15 +11,7,2 +4,9,16 +17,12,8 +5,16,14 +12,4,4 +13,15,8 +9,9,15 +4,8,7 +10,3,3 +13,14,7 +11,15,8 +14,12,14 +13,13,17 +10,16,8 +1,12,9 +12,18,10 +15,10,17 +13,5,3 +7,11,18 +8,18,11 +12,10,16 +14,8,5 +4,6,15 +6,4,14 +6,9,16 +18,6,7 +6,7,6 +16,9,15 +16,5,10 +16,7,11 +9,14,3 +14,5,12 +13,4,15 +16,6,14 +15,9,2 +3,16,9 +17,13,11 +16,10,6 +4,6,9 +10,16,10 +14,15,11 +6,15,10 +7,10,16 +8,13,2 +8,2,8 +2,11,5 +4,11,12 +6,6,13 +6,1,10 +13,12,17 +8,3,7 +3,8,10 +16,3,9 +15,3,13 +5,13,16 +1,11,13 +15,13,15 +15,2,9 +13,2,9 +14,14,8 +13,9,4 +3,13,6 +13,8,2 +7,1,10 +11,13,2 +14,10,17 +3,9,11 +6,5,7 +4,14,14 +8,6,5 +14,4,11 +7,7,15 +12,1,13 +12,5,6 +16,7,15 +15,13,12 +8,15,6 +4,14,7 +9,3,9 +3,11,4 +10,18,10 +9,12,3 +13,5,10 +15,13,11 +12,5,4 +14,9,2 +15,15,11 +5,16,9 +4,7,11 +17,6,14 +12,14,16 +6,15,7 +2,4,12 +11,11,16 +4,14,9 +2,15,11 +4,15,15 +10,18,12 +7,7,5 +9,13,15 +18,8,13 +10,18,11 +11,2,5 +15,9,5 +5,5,6 +7,15,7 +1,8,8 +11,4,12 +16,13,9 +11,14,12 +11,14,5 +9,4,4 +16,9,13 +15,9,3 +15,11,12 +15,16,10 +4,5,6 +1,11,6 +8,18,9 +9,3,4 +4,5,9 +5,18,9 +4,5,14 +8,8,16 +15,13,5 +5,9,2 +10,8,16 +8,4,11 +4,6,3 +3,6,8 +13,6,17 +10,19,9 +14,3,4 +14,14,13 +9,17,14 +6,5,6 +0,10,10 +16,11,13 +11,17,7 +16,10,7 +4,6,6 +11,6,15 +8,12,3 +11,13,18 +12,8,1 +1,7,12 +15,4,8 +16,4,11 +14,3,9 +13,11,14 +11,4,14 +17,14,7 +12,1,11 +8,14,5 +18,10,10 +2,10,5 +4,9,13 +6,18,7 +16,7,9 +15,13,16 +17,4,9 +15,17,11 +8,11,16 +9,4,17 +12,3,10 +3,15,10 +11,3,8 +4,16,11 +8,17,7 +4,13,11 +13,9,18 +10,4,12 +16,11,7 +3,9,4 +15,8,14 +6,14,13 +13,6,14 +2,5,8 +6,4,4 +6,12,5 +5,16,11 +10,6,15 +11,4,10 +11,3,7 +18,8,8 +5,7,3 +3,9,9 +18,10,11 +14,13,4 +16,12,6 +4,2,9 +7,11,17 +11,18,11 +9,7,16 +7,6,5 +13,17,14 +6,4,3 +3,16,8 +7,16,15 +8,16,4 +7,8,18 +10,11,4 +7,9,16 +2,9,14 +9,4,7 +10,0,9 +15,6,7 +13,11,15 +12,12,2 +9,18,11 +8,5,2 +10,12,18 +4,10,2 +4,8,11 +13,12,5 +15,15,8 +13,8,4 +3,15,5 +5,8,5 +7,3,6 +5,10,13 +8,13,1 +17,10,15 +9,9,1 +9,15,3 +8,4,2 +7,17,5 +11,16,7 +10,15,7 +6,3,5 +11,5,2 +13,10,2 +6,18,11 +6,11,2 +4,10,3 +8,10,1 +13,14,3 +3,10,8 +10,6,18 +11,9,14 +5,9,5 +8,5,5 +14,3,6 +1,9,7 +5,13,7 +10,3,4 +8,8,3 +5,16,12 +4,14,4 +8,18,12 +6,3,12 +18,12,6 +9,4,11 +4,4,13 +3,3,12 +1,8,12 +15,11,13 +13,12,16 +5,6,8 +18,6,11 +6,9,5 +15,7,9 +2,6,6 +12,17,7 +4,15,11 +6,13,4 +12,14,5 +3,3,7 +9,1,14 +14,8,6 +7,10,4 +2,14,7 +14,17,8 +3,10,16 +12,14,14 +10,10,16 +4,7,9 +14,6,7 +8,4,13 +16,5,5 +12,8,2 +6,9,1 +11,1,8 +1,7,10 +5,5,16 +13,15,15 +3,7,16 +7,5,7 +7,3,12 +4,13,7 +9,4,5 +14,14,3 +8,14,6 +10,8,3 +5,8,6 +9,18,8 +13,8,5 +13,12,2 +5,10,17 +18,8,12 +9,4,9 +3,10,6 +10,9,16 +9,17,11 +12,13,5 +15,7,12 +8,15,7 +17,4,11 +3,3,8 +8,15,16 +5,7,4 +4,4,15 +13,5,5 +13,16,9 +16,12,12 +10,6,13 +7,12,5 +18,10,12 +9,3,10 +10,3,9 +5,14,15 +6,1,11 +17,7,13 +18,13,10 +12,17,6 +10,7,17 +17,13,13 +2,7,13 +6,18,12 +15,12,8 +12,6,17 +8,17,6 diff --git a/2022/18/src/main.rs b/2022/18/src/main.rs new file mode 100644 index 0000000..be99b56 --- /dev/null +++ b/2022/18/src/main.rs @@ -0,0 +1,366 @@ +use std::str::FromStr; + +fn main() { + let input_file = common::parse_args_input_file(&mut std::env::args()); + let contents = std::fs::read_to_string(input_file).expect("Failed to read input file"); + + let mut space = std::collections::HashSet::<[i32; 3]>::new(); + for line in contents.lines() { + if line.eq("") { + continue; + } + let mut index = 0; + let mut p = [0; 3]; + for word in line.split(',') { + assert!(index < 3); + p[index] = i32::from_str(word).unwrap(); + index += 1; + } + space.insert(p); + } + + println!( + "[PART 1] {} open faces", + count_disjoint_sides(&space, std::vec::Vec::>::new()), + ); + + let part2 = count_part2(&space); + println!("[PART 2] {} open faces", part2); +} + +fn count_part2(space: &std::collections::HashSet::<[i32; 3]>) -> u32 { + // To determine hollows, one approach might be to imagine the space as slices + // of the x,y axis starting from the highest Z value. + // For each slice we produce a list of possible hollow sets which are completely + // enclosed. It could be there are multiple pockets within a a given slice. + // Note: On the top and bottom slices, we can still include enclosed pockets + // despite the view that they are attached to "air" for the moment. + // + // As the slices of the droplet are iterated through, we can fuse potential + // pockets which are not disjoint. + // + // Once all the slices are iterated through we can run a validation step on + // each fused potential pocket. + // If the pocket has no disjoint sides with the union of itself and the droplet, + // it should be a proper pocket. If there is one or more disjoint sides, then + // "air" can move in to the space. + let mut max: [i32; 3] = [i32::MIN; 3]; + let mut min: [i32; 3] = [i32::MAX; 3]; + for point in space.iter() { + max = [ + std::cmp::max(point[0], max[0]), + std::cmp::max(point[1], max[1]), + std::cmp::max(point[2], max[2]), + ]; + min = [ + std::cmp::min(point[0], min[0]), + std::cmp::min(point[1], min[1]), + std::cmp::min(point[2], min[2]), + ]; + } + + let mut potential_pockets = std::vec::Vec::>::new(); + let mut z = max[2]; + // We'll take vertical slices starting a z_max, and each slice will be a grid + // from [x_min-1, y_min-1] to [x_max+1, y+max+1], so we have a bounding outer + // perimeter. + let x_size = (max[0] - min[0] + 1 + 2) as usize; + let y_size = (max[1] - min[1] + 1 + 2) as usize; + // For easing iterations, we offset create an offset such that [x_min-1, y_min-1] is now at [0, 0] + let mut offset: [i32; 2] = [ + (min[0] - 1).abs() * if min[0] >= 0 { 1 } else { -1 }, + (min[1] - 1).abs() * if min[1] >= 0 { 1 } else { -1 }, + ]; + // println!("Obj {}x{} with offset: {:?}", x_size-3, y_size-3, offset); + while z >= min[2] { + // This is actually a place where I feel a bit stymied by rust's safety mechanisms. + // To create a multidimensional array I either have to do a Vec of Vecs, use someone's crate + // or drop into unsafe {} to allocate runtime determined byte arrays. + let mut plane = ndarray::Array2::::zeros((x_size, y_size)); + // Fill in the plane data. If we were storing the underlying shape a 3d array we could + // avoid doing this work every time. + for x in 0..x_size { + for y in 0..y_size { + let p: [i32; 3] = [x as i32 - offset[0], y as i32 - offset[1], z]; + if space.contains(&p) { + plane[[x, y]] = 1; + } + } + } + + // Now we go over it again, and for each point that is 0, + // try to reach 0,0 (or really, any point on the perimiter) + for x in 1..x_size-1 { + for y in 1..y_size-1 { + if plane[[x, y]] == 1 { + continue; + } + // Choose the nearest perimiter point (although the path there + // is not necessarily the shorter path to any point on the + // perimiter. This seems silly, but helps save a lot of time + // pathing around to a fixed point like 0,0. + // distance left, right, up, down + let d = [x, x_size-x, y, y_size - y]; + let mut perim_x = 0; + let mut perim_y = 0; + if d[2] < d[3] { + // We might want to go up, left, or right. + if d[2] <= d[0] && d[2] <= d[1] { + perim_x = x; + } + else { + perim_y = y; + if d[0] > d[1] { + perim_x = x_size-1; + } + } + } + else { + // We might want to go down, left, or right. + if d[3] <= d[0] && d[3] <= d[1] { + perim_x = x; + perim_y = y_size-1; + } + else { + perim_y = y; + if d[0] > d[1] { + perim_x = x_size-1; + } + } + } + if !can_path_to(&plane, [x, y], [perim_x, perim_y]) { + let mut pocket = std::collections::HashSet::<[i32; 3]>::new(); + let point = [x as i32 - offset[0], y as i32 - offset[1], z]; + pocket.insert(point); + potential_pockets.push(pocket); + } + } + } + + // Fuse potential pockets. + let mut index = 0; + let mut pockets_length = potential_pockets.len(); + while index < pockets_length { + if index + 1 > pockets_length { + break; + } + let mut index2 = index + 1; + let mut fused = false; + while index2 < pockets_length { + // If any of the points pocketN and pocketN+1 share a face, + // we can fuse them. + let mut fusable = false; + for point1 in potential_pockets[index].iter() { + for neighbour in neighbours(&point1) { + if potential_pockets[index2].contains(&neighbour) { + fusable = true; + break; + } + } + } + if fusable { + // println!("Merging these two pockets:\n{:?}\n{:?}", potential_pockets[index], potential_pockets[index2]); + // Fuse these two, then re-run the iteration + // println!("Fused {} and {}", index, index2); + let pocket2 = potential_pockets[index2].clone(); + for p in pocket2.iter() { + potential_pockets[index].insert(*p); + } + potential_pockets.remove(index2); + pockets_length = potential_pockets.len(); + fused = true; + continue; + } + index2 += 1; + } + if fused { + // Start the process over. + index = 0; + } + index += 1; + } + + let mut debug = false; + if debug { + println!("Plane at z {}", z); + let mut x = 0; + for row in plane.rows() { + let mut s = String::new(); + let mut y = 0; + for value in row.iter() { + if *value == 0 { + // Is it in pockets? + let mut c = '.'; + let mut pocket_index = 0; + for pocket in potential_pockets.iter() { + let point = [x as i32 - offset[0], y as i32 - offset[1], z]; + if pocket.contains(&point) { + // If potential pockets is less than 52, we'll use the range + // of a-zA-Z to differentiate them + c = pocket_char(pocket_index as u32); + break; + } + pocket_index += 1; + } + s.push(c); + } + else { + s.push('#'); + } + y += 1; + } + x += 1; + println!("{}", s); + } + println!(""); + } + z -= 1; + } + + // println!("{} discrete potential pockets", potential_pockets.len()); + // For each discrete potential pocket, we need to ensure that it's not + // actually open to space at some point. (Aka, it's fully enclosed). + let mut pocket_index = 0; + let mut pockets_removed = 0; + while pocket_index < potential_pockets.len() { + let open_spaces = count_disjoint_sides( + &potential_pockets[pocket_index], + vec![space.clone()], + ); + // println!( + // "Pocket '{}' ({}) has {} open faces", + // pocket_char((pocket_index + pockets_removed) as u32), + // pocket_index + pockets_removed, open_spaces + // ); + if open_spaces > 0 { + potential_pockets.remove(pocket_index); + pockets_removed += 1; + continue; + } + pocket_index += 1; + } + // println!("{} pockets removed after verifying if they were open to air or not", potential_pockets.len()); + + return count_disjoint_sides( + space, + potential_pockets, + ); +} + +fn pocket_char(v: u32) -> char { + if v < 26 { + return char::from_u32(v + 97).unwrap(); + } + else if v < 52 { + return char::from_u32(v + 65 - 26).unwrap(); + } + return '*'; +} + +fn can_path_to(plane: &ndarray::Array, start: [usize; 2], end: [usize; 2]) -> bool { + let (x_max, y_max) = plane.dim(); + + // A* + let mut open_set = std::collections::VecDeque::<[usize; 2]>::new(); + let mut came_from = std::collections::HashMap::<[usize; 2], [usize; 2]>::new(); + let mut scores = std::collections::HashMap::<[usize; 2], u32>::new(); + let mut estimates = std::collections::HashMap::<[usize; 2], u32>::new(); + + open_set.push_back(start); + scores.insert(start, 0); + + while open_set.len() > 0 { + let current = get_next_node_to_test(&open_set, &estimates); + if current == end { + return true; + } + open_set.retain(|&x| x != current); + let mut neighbours = std::vec::Vec::<[usize; 2]>::new(); + // Can go left + if current[0] > 0 { + if plane[[current[0]-1, current[1]]] == 0 { + neighbours.push([current[0]-1, current[1]]); + } + } + // Right + if current[0] + 1 < x_max { + if plane[[current[0]+1, current[1]]] == 0 { + neighbours.push([current[0]+1, current[1]]); + } + } + // Up + if current[1] > 0 { + if plane[[current[0], current[1]-1]] == 0 { + neighbours.push([current[0], current[1]-1]); + } + } + // Down + if current[1] + 1 < y_max { + if plane[[current[0], current[1]+1]] == 0 { + neighbours.push([current[0], current[1]+1]); + } + } + for neighbour in neighbours.iter() { + let score = scores.get(¤t).unwrap() + 1; + let neighbour_score = match scores.get(neighbour) { + None => { u32::MAX }, + Some(v) => { *v }, + }; + if score < neighbour_score { + came_from.insert(*neighbour, current); + scores.insert(*neighbour, score); + estimates.insert(*neighbour, score + 10); + if !open_set.contains(&neighbour) { + open_set.push_back(*neighbour); + } + } + } + } + return false; +} + +fn get_next_node_to_test(open: &std::collections::VecDeque<[usize; 2]>, estimates: &std::collections::HashMap<[usize; 2], u32>) -> [usize; 2] { + let mut current: Option<[usize; 2]> = None; + let mut current_value = u32::MAX; + for n in open.iter() { + let score = match estimates.get(n) { + None => { u32::MAX }, + Some(v) => { *v }, + }; + if current.is_none() || score < current_value { + current = Some(*n); + current_value = score; + } + } + return current.unwrap(); +} + +fn count_disjoint_sides(space: &std::collections::HashSet::<[i32; 3]>, ignore_sets: std::vec::Vec>) -> u32 { + let mut count = 0; + for point in space.iter() { + for tp in neighbours(point) { + let mut ignore = false; + for set in ignore_sets.iter() { + if set.contains(&tp) { + ignore = true; + break; + } + } + if !ignore && !space.contains(&tp) { + count += 1; + } + } + } + return count; +} + +fn neighbours(point: &[i32; 3]) -> [[i32; 3]; 6] { + return [ + [point[0], point[1], point[2]+1], + [point[0], point[1], point[2]-1], + [point[0], point[1]+1, point[2]], + [point[0], point[1]-1, point[2]], + [point[0]+1, point[1], point[2]], + [point[0]-1, point[1], point[2]], + ]; +} diff --git a/2022/18/test_input b/2022/18/test_input new file mode 100644 index 0000000..73a7202 --- /dev/null +++ b/2022/18/test_input @@ -0,0 +1,13 @@ +2,2,2 +1,2,2 +3,2,2 +2,1,2 +2,3,2 +2,2,1 +2,2,3 +2,2,4 +2,2,6 +1,2,5 +3,2,5 +2,1,5 +2,3,5 diff --git a/2022/18/test_input2 b/2022/18/test_input2 new file mode 100644 index 0000000..835425c --- /dev/null +++ b/2022/18/test_input2 @@ -0,0 +1,2 @@ +1,1,1 +2,1,1