From 0444d97d13da5170561b76634201108765acdfac Mon Sep 17 00:00:00 2001 From: Acvaxoort Date: Tue, 26 Dec 2023 02:13:31 +0100 Subject: [PATCH] day 24 --- day24/Cargo.lock | 1374 +++++++++++++++++++++++++++++++++++++++++++++ day24/Cargo.toml | 11 + day24/input.txt | 300 ++++++++++ day24/src/main.rs | 192 +++++++ 4 files changed, 1877 insertions(+) create mode 100644 day24/Cargo.lock create mode 100644 day24/Cargo.toml create mode 100644 day24/input.txt create mode 100644 day24/src/main.rs diff --git a/day24/Cargo.lock b/day24/Cargo.lock new file mode 100644 index 0000000..b65b1e7 --- /dev/null +++ b/day24/Cargo.lock @@ -0,0 +1,1374 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59d2a3357dde987206219e78ecfbbb6e8dad06cbb65292758d3270e6254f7355" + +[[package]] +name = "approx" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f2a05fd1bd10b2527e20a2cd32d8873d115b8b39fe219ee25f42a8aca6ba278" +dependencies = [ + "num-traits", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.21.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35636a1494ede3b646cc98f74f8e62c773a38a659ebc777a2cf26b9b74171df9" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f30e7476521f6f8af1a1c4c0b8cc94f0bee37d91763d0ca2665f299b6cd8aec" + +[[package]] +name = "cauchy" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff11ddd2af3b5e80dd0297fee6e56ac038d9bdc549573cdb51bd6d2efe7f05e" +dependencies = [ + "num-complex", + "num-traits", + "rand", + "serde", +] + +[[package]] +name = "cblas-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6feecd82cce51b0204cf063f0041d69f24ce83f680d87514b004248e7b0fa65" +dependencies = [ + "libc", +] + +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "chrono" +version = "0.4.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.48.5", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" + +[[package]] +name = "cpufeatures" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce420fe07aecd3e67c5f910618fe65e94158f6dcc0adf44e00d69ce2bdfe0fd0" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "darling" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" +dependencies = [ + "darling_core", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "day24" +version = "0.1.0" +dependencies = [ + "ndarray", + "ndarray-linalg", + "num", +] + +[[package]] +name = "derive_builder" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07adf7be193b71cc36b193d0f5fe60b918a3a9db4dad0449f57bcfd519704a3" +dependencies = [ + "derive_builder_macro", +] + +[[package]] +name = "derive_builder_core" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive_builder_macro" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f0314b72bed045f3a68671b3c86328386762c93f82d98c65c3cb5e5f573dd68" +dependencies = [ + "derive_builder_core", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "directories" +version = "4.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f51c5d4ddabd36886dd3e1438cb358cdcb0d7c499cb99cb4ac2e38e18b5cb210" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + +[[package]] +name = "filetime" +version = "0.2.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "windows-sys 0.52.0", +] + +[[package]] +name = "flate2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46303f565772937ffe1d394a4fac6f411c6013172fadde9dcdb1e147a086940e" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getset" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e45727250e75cc04ff2846a66397da8ef2b3db8e40e0cef4df67950a07621eb9" +dependencies = [ + "proc-macro-error", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8326b86b6cff230b97d0d312a6c40a60726df3332e721f72a1b035f451663b20" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "intel-mkl-src" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ee70586cd5b3e772a8739a1bd43eaa90d4f4bf0fb2a4edc202e979937ee7f5e" +dependencies = [ + "anyhow", + "intel-mkl-tool", + "ocipkg", +] + +[[package]] +name = "intel-mkl-tool" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "887a16b4537d82227af54d3372971cfa5e0cde53322e60f57584056c16ada1b4" +dependencies = [ + "anyhow", + "log", + "walkdir", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "js-sys" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cee9c64da59eae3b50095c18d3e74f8b73c0b86d2792824ff01bbce68ba229ca" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "katexit" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb1304c448ce2c207c2298a34bc476ce7ae47f63c23fa2b498583b26be9bc88c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "lapack-sys" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447f56c85fb410a7a3d36701b2153c1018b1d2b908c5fbaf01c1b04fac33bcbe" +dependencies = [ + "libc", +] + +[[package]] +name = "lax" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f96a229d9557112e574164f8024ce703625ad9f88a90964c1780809358e53da" +dependencies = [ + "cauchy", + "intel-mkl-src", + "katexit", + "lapack-sys", + "num-traits", + "thiserror", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4" + +[[package]] +name = "libredox" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85c833ca1e66078851dba29046874e38f08b2c883700aa29a03ddd3b23814ee8" +dependencies = [ + "bitflags 2.4.1", + "libc", + "redox_syscall", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" + +[[package]] +name = "log" +version = "0.4.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" + +[[package]] +name = "matrixmultiply" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2" +dependencies = [ + "autocfg", + "rawpointer", +] + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + +[[package]] +name = "ndarray" +version = "0.15.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb12d4e967ec485a5f71c6311fe28158e9d6f4bc4a447b474184d0f91a8fa32" +dependencies = [ + "approx", + "cblas-sys", + "libc", + "matrixmultiply", + "num-complex", + "num-integer", + "num-traits", + "rawpointer", +] + +[[package]] +name = "ndarray-linalg" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b0e8dda0c941b64a85c5deb2b3e0144aca87aced64678adfc23eacea6d2cc42" +dependencies = [ + "cauchy", + "katexit", + "lax", + "ndarray", + "num-complex", + "num-traits", + "rand", + "thiserror", +] + +[[package]] +name = "num" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05180d69e3da0e530ba2a1dae5110317e49e3b7f3d41be227dc5f92e49ee7af" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "608e7659b5c3d7cba262d894801b9ec9d00de989e8a82bd4bef91d08da45cdc0" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ba157ca0885411de85d6ca030ba7e2a83a28636056c7c699b07c8b6f7383214" +dependencies = [ + "num-traits", + "rand", + "serde", +] + +[[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-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39e3200413f237f41ab11ad6d161bc7239c84dcb631773ccd7de3dfe4b5c267c" +dependencies = [ + "autocfg", +] + +[[package]] +name = "oci-spec" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98135224dd4faeb24c05a2fac911ed53ea6b09ecb09d7cada1cb79963ab2ee34" +dependencies = [ + "derive_builder", + "getset", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "ocipkg" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60cf01280832705a4e4c4d046d9e67a54b900297c69191457a8fc6d198ddefa2" +dependencies = [ + "base16ct", + "base64 0.13.1", + "chrono", + "directories", + "flate2", + "lazy_static", + "log", + "oci-spec", + "regex", + "serde", + "serde_json", + "sha2", + "tar", + "thiserror", + "toml", + "ureq", + "url", + "uuid", + "walkdir", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75cb1540fadbd5b8fbccc4dddad2734eba435053f725621c070711a14bb5f4b8" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rawpointer" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" + +[[package]] +name = "redox_syscall" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +dependencies = [ + "bitflags 1.3.2", +] + +[[package]] +name = "redox_users" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18479200779601e498ada4e8c1e1f50e3ee19deb0259c25825a98b5603b2cb4" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "regex" +version = "1.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "ring" +version = "0.17.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" +dependencies = [ + "cc", + "getrandom", + "libc", + "spin", + "untrusted", + "windows-sys 0.48.0", +] + +[[package]] +name = "rustix" +version = "0.38.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72e572a5e8ca657d7366229cdde4bd14c4eb5499a9573d4d366fe1b599daa316" +dependencies = [ + "bitflags 2.4.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustls" +version = "0.21.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" +dependencies = [ + "log", + "ring", + "rustls-webpki", + "sct", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "ryu" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f98d2aa92eebf49b69786be48e4477826b256916e84a57ff2a4f21923b48eb4c" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "sct" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" +dependencies = [ + "ring", + "untrusted", +] + +[[package]] +name = "serde" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.193" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.43", +] + +[[package]] +name = "serde_json" +version = "1.0.108" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "spin" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tar" +version = "0.4.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] +name = "thiserror" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f11c217e1416d6f036b870f14e0413d480dbf28edbee1f877abaf0206af43bb7" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01742297787513b79cf8e29d1056ede1313e2420b7b3b15d0a768b4921f549df" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.43", +] + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + +[[package]] +name = "toml" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" +dependencies = [ + "serde", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "unicode-bidi" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f2528f27a9eb2b21e69c95319b30bd0efd85d09c379741b0f78ea1d86be2416" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "ureq" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cdd25c339e200129fe4de81451814e5228c9b771d57378817d6117cc2b3f97" +dependencies = [ + "base64 0.21.5", + "flate2", + "log", + "once_cell", + "rustls", + "rustls-webpki", + "serde", + "serde_json", + "url", + "webpki-roots", +] + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + +[[package]] +name = "uuid" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" +dependencies = [ + "getrandom", +] + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wasm-bindgen" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ed0d4f68a3015cc185aff4db9506a015f4b96f95303897bfa23f846db54064e" +dependencies = [ + "cfg-if", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b56f625e64f3a1084ded111c4d5f477df9f8c92df113852fa5a374dbda78826" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn 2.0.43", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0162dbf37223cd2afce98f3d0785506dcb8d266223983e4b5b525859e6e182b2" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.43", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ab9b36309365056cd639da3134bf87fa8f3d86008abf99e612384a6eecd459f" + +[[package]] +name = "webpki-roots" +version = "0.25.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1778a42e8b3b90bff8d0f5032bf22250792889a5cdc752aa0020c84abe3aaf10" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-core" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.0", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a18201040b24831fbb9e4eb208f8892e1f50a37feb53cc7ff887feb8f50e7cd" +dependencies = [ + "windows_aarch64_gnullvm 0.52.0", + "windows_aarch64_msvc 0.52.0", + "windows_i686_gnu 0.52.0", + "windows_i686_msvc 0.52.0", + "windows_x86_64_gnu 0.52.0", + "windows_x86_64_gnullvm 0.52.0", + "windows_x86_64_msvc 0.52.0", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7764e35d4db8a7921e09562a0304bf2f93e0a51bfccee0bd0bb0b666b015ea" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbaa0368d4f1d2aaefc55b6fcfee13f41544ddf36801e793edbbfd7d7df075ef" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a28637cb1fa3560a16915793afb20081aba2c92ee8af57b4d5f28e4b3e7df313" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffe5e8e31046ce6230cc7215707b816e339ff4d4d67c65dffa206fd0f7aa7b9a" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d6fa32db2bc4a2f5abeacf2b69f7992cd09dca97498da74a151a3132c26befd" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a657e1e9d3f514745a572a6846d3c7aa7dbe1658c056ed9c3344c4109a6949e" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" + +[[package]] +name = "xattr" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7dae5072fe1f8db8f8d29059189ac175196e410e40ba42d5d4684ae2f750995" +dependencies = [ + "libc", + "linux-raw-sys", + "rustix", +] diff --git a/day24/Cargo.toml b/day24/Cargo.toml new file mode 100644 index 0000000..02ea664 --- /dev/null +++ b/day24/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "day24" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +ndarray = "0.15.6" +ndarray-linalg = { version = "0.16", features = ["intel-mkl-static"] } +num = "0.4.1" diff --git a/day24/input.txt b/day24/input.txt new file mode 100644 index 0000000..4f41a8b --- /dev/null +++ b/day24/input.txt @@ -0,0 +1,300 @@ +200027938836082, 135313515251542, 37945458137479 @ 133, 259, 506 +285259862606823, 407476720802151, 448972585175416 @ 12, -120, -241 +329601664688534, 370686722303193, 178908568819244 @ -133, -222, 168 +224985900829298, 214925632111185, 149368039079818 @ 77, 81, 242 +296437806379588, 68696864488553, 9964503372160 @ 34, 338, 300 +232239129106374, 223028585546926, 246426150966661 @ 89, 147, 48 +271805776381363, 498745349607170, 241968934263498 @ -70, -773, 21 +334618297909998, 287662575776141, 307715065462604 @ -33, 80, -24 +209686250664760, 187819441819935, 272042848835366 @ 52, -231, -357 +277500761149058, 333431119693601, 114011249139706 @ 44, 41, 206 +312118668181768, 495014609197265, 186766093899598 @ 16, -106, 119 +299683250085970, 97849820660305, 270011660400330 @ -44, 330, -5 +229720558256611, 150910727673562, 243270833145468 @ -68, 117, -77 +304248494909992, 219767581530113, 254465655656873 @ -137, 38, -6 +246750940858792, 233990979047981, 210953288389140 @ -62, -168, 120 +233067759142206, 198113631860301, 199711852215930 @ 32, 61, 145 +194273010182062, 231126869346983, 175766437001790 @ 147, 25, 191 +422437581013498, 520681737761805, 551376558156718 @ -149, -221, -336 +213621024566196, 152714072145937, 231042606220912 @ -54, -74, -76 +196857076420466, 257330625183425, 151562284105578 @ 149, -379, 427 +369318041141350, 320601489876785, 404752437430854 @ -56, 62, -122 +177717686542186, 261386998367960, 271529522712591 @ 189, -59, -46 +262701995382254, 313552465631125, 382611373509334 @ -24, -189, -324 +170297191018136, 178309134118657, 225360885518954 @ 212, 142, 69 +227622713436232, 154353931514341, 280415902687702 @ 58, 204, -81 +314948926503302, 408416248916028, 453190315236620 @ -39, -143, -265 +293223113430502, 423607642677073, 319619656107050 @ -38, -266, -99 +252020827135166, 156505968362865, 310375343290926 @ -136, 126, -386 +263439342121787, 301341574163972, 252713891021320 @ 38, 17, 35 +198791366653612, 97037164135423, 237475860248930 @ 148, 643, -135 +265515753922082, 77028908701403, 372580955540610 @ -67, 431, -383 +244122754125607, 216118441735598, 251141183508785 @ -32, -55, -34 +368405242763362, 487076527780613, 257997522712470 @ -63, -141, 40 +255316322983682, 108881920473485, 223486097050440 @ -67, 344, 70 +248202087006514, 332313273894033, 299629715190090 @ 79, 48, -5 +242526038555392, 172309277470091, 281968246773090 @ 38, 177, -55 +377029210698079, 355128725572901, 168339101770659 @ -44, 50, 136 +195247088386282, 207400901771393, 179202560974770 @ 176, -444, 446 +305350369740094, 318546425948691, 359769376111386 @ 7, 49, -83 +220238585738990, 301135827650157, 178425231826166 @ 92, -75, 168 +293134188318610, 455585245138889, 178821007816418 @ 25, -103, 132 +296805282994282, 477461073094877, 160305288302868 @ 33, -84, 146 +551484833298770, 430831686261581, 415123879556900 @ -235, -40, -120 +264263487126684, 475446609663063, 234719810787824 @ 62, -107, 68 +208118421230229, 186370297031592, 162445108177304 @ 102, 51, 303 +379457876720978, 470069791102841, 319907054392598 @ -115, -196, -54 +307081543504480, 345947348356843, 333126004018988 @ -26, -47, -84 +275592475604044, 268751187599757, 291577264394906 @ -26, -20, -67 +223538882701191, 241874529688322, 236884948735720 @ 66, -49, 35 +217306880344022, 228332316074413, 132327655645815 @ 105, 114, 226 +288613631151179, 344112266171307, 264129986825655 @ 44, 60, 40 +391925053763340, 380982015060763, 513639079473102 @ -90, -17, -257 +317349509030790, 434745366987169, 209235218174754 @ -76, -270, 103 +265019875952157, 100779004627568, 193342693392940 @ -52, 353, 159 +239497638093832, 145125270103727, 21043699168434 @ 8, 221, 713 +235688079024824, 236070451305047, 249110777938228 @ 24, -55, -6 +254338369110232, 284989404572389, 149097978418136 @ 58, 60, 182 +170962227947302, 78199807246080, 77886341913974 @ 193, 379, 377 +188700869304678, 17975326303209, 364531904960094 @ 144, 384, -56 +188146734972721, 198414310422359, 31503292875758 @ 154, 152, 417 +209859086224528, 126699646051391, 242207571947277 @ 87, 280, -22 +339514053892582, 305669314514513, 358205645006730 @ -92, -10, -139 +364239230823630, 134872902901983, 261941454368215 @ -79, 268, 30 +224460476321604, 296552716035239, 275414144435650 @ 11, -568, -195 +87643762120749, 180316544924259, 270813136963950 @ 264, 216, 25 +396704525151872, 86365100440993, 193863226488620 @ -60, 318, 110 +287579264392312, 541282922916881, 310697373167610 @ 18, -266, -35 +219115359852829, 425077073845073, 255652122856596 @ 92, -362, 7 +345130946591991, 463544251720861, 528954166317265 @ -24, -86, -250 +211798361516338, 169917478027707, 240060316499404 @ 37, -71, -84 +234073712530041, 208961882726755, 261193905624604 @ 24, 16, -49 +260673598074478, 273125896519813, 303569550514920 @ 25, 18, -65 +234225942126142, 334594973868557, 249357715571756 @ -47, -814, -73 +194503280378341, 83543670520014, 234685741733095 @ 142, 349, 60 +256825512968734, 217098465735509, 281163376366062 @ 20, 99, -38 +206903429582962, 285693092592113, 419158418070570 @ 101, -460, -845 +249311051976182, 213020513000653, 83458884867380 @ -7, 34, 471 +330368645477374, 263338996885345, 221100829139928 @ -89, 46, 82 +236262398273986, 184664223382601, 209185855979298 @ -49, -11, 136 +298064517145996, 438537394814861, 176088036632055 @ 31, -46, 130 +295490246929342, 397446098278553, 339376231881390 @ 32, -8, -42 +254324790454585, 336889283238461, 196599761151279 @ 16, -174, 134 +182262064412882, 206007569681201, 374257893209674 @ 158, 167, -133 +223426344993655, 424185113242685, 393301531410891 @ 110, -14, -86 +320760904752983, 184993183332542, 87890558602034 @ -36, 197, 269 +283961007648219, 176128474236562, 79127578720829 @ -40, 177, 374 +301136921143282, 385966081948625, 343703516477226 @ 33, 22, -38 +341468210661298, 388247589073361, 257419541423082 @ -23, -10, 43 +222094532764222, 104419022560328, 149419156083345 @ -39, 455, 630 +225621024483212, 179835009574931, 225426472393282 @ -52, -103, 41 +180590209225432, 174387449432793, 273841337539820 @ 235, 30, -201 +279247881380594, 520526120105281, 153622924992218 @ -43, -596, 231 +273158965208722, 315710335804973, 173971146323010 @ -83, -279, 219 +267979293363034, 227311776608853, 274876632996975 @ -179, -182, -170 +273267030106312, 298860128841353, 250487127745100 @ 46, 74, 48 +197562635430598, 271758220363921, 190988479076304 @ 139, -74, 154 +165710284540612, 156670111374815, 125338936908300 @ 248, 179, 400 +317944886562946, 216904763352419, 309117144349596 @ -131, 77, -116 +546731571529402, 506707788552983, 357821666355380 @ -215, -103, -54 +286105887874482, 276472328823817, 289923386450858 @ -67, -69, -79 +235388770625038, 237793394137259, 342120134173245 @ 25, -60, -290 +477732253201002, 251586033009398, 395444643202490 @ -195, 131, -123 +204705827128732, 308629152997013, 302605879848540 @ 123, -110, -93 +376997830155931, 369071431413774, 285168848102309 @ -74, -5, 8 +311831859199679, 310731690408100, 346529249203462 @ 24, 99, -39 +255467223349492, 135838974808586, 248643090053601 @ 63, 267, 48 +264148672257454, 174903319987529, 153123286013378 @ -20, 164, 243 +316205705123896, 286786590620183, 277768052454294 @ -209, -192, -87 +280868990296682, 274007307501593, 307012157851570 @ -9, 20, -69 +201753536198032, 242396991020453, 245568548141010 @ 128, -56, 9 +328051439833898, 434546576899369, 249510611786626 @ -24, -99, 48 +264640019914610, 227935465050577, 245725553705994 @ -58, -20, 7 +352390492484930, 534651025917425, 264313956967042 @ -33, -166, 36 +533833867672880, 553611320645473, 476050170268652 @ -274, -242, -228 +251119099939790, 304280134982224, 248772419744767 @ 41, -41, 32 +283071362253322, 364191219048673, 310190393003530 @ 16, -56, -43 +356295539800102, 392581665802868, 314502430364895 @ -23, 13, -10 +227633359450920, 191503364565333, 214102076185962 @ -120, -312, 133 +269699389153161, 105374462482562, 184661370796480 @ -88, 347, 195 +295865488902134, 146498506936395, 370232632173154 @ 39, 259, -63 +247392543884764, 337636443014113, 281040486310450 @ -128, -882, -255 +326411290618424, 365653413141261, 422264849974398 @ -9, 10, -143 +258418426189826, 121673030731129, 300829489051738 @ -49, 295, -169 +307292563519186, 377127442654401, 392722234592218 @ -245, -603, -526 +205781583202267, 265470269558019, 197731337175253 @ 88, -804, 254 +249711429057846, 265531095717107, 268515984071116 @ 35, 5, -12 +165360322069199, 134996423563510, 157235516730598 @ 296, 241, 377 +171467775968482, 219947616561893, 195539332516370 @ 181, 122, 125 +292438097454242, 374099369566833, 283127011356330 @ 20, -24, 7 +285218340510922, 293119294141957, 338864183316494 @ -197, -365, -378 +176387437668760, 162256430098307, 145987632841698 @ 240, 119, 417 +258595198656378, 238121490933883, 284046844008568 @ 9, 43, -52 +332209231670784, 442465418130361, 510375408965104 @ -90, -254, -406 +142029660870022, 199302722044401, 48566760894860 @ 223, 166, 350 +178734727735972, 283277301976333, 330773939663279 @ 163, 58, -72 +373166187989528, 283639478033222, 517458307841330 @ -169, 5, -435 +328013730776722, 356434964469173, 313551231751230 @ -11, 20, -21 +227260751593414, 267181552851329, 315951113497524 @ 91, 62, -64 +324116670655010, 269566969541385, 71656400088674 @ -9, 115, 254 +203495944150856, 292645522720043, 254019521387110 @ 122, -247, -25 +173036351405092, 151745787866063, 201246206335080 @ 224, 195, 146 +231766047638707, 247936662684443, 190672789320870 @ 40, -76, 169 +215754528047932, 173734978906403, 241928569107300 @ 78, 115, 6 +251992212847102, 120693415221781, 40186447363282 @ 28, 291, 447 +208441458326038, 331856061497789, 152732438943885 @ 97, -598, 370 +229223718072877, 200402768463953, 200257259587870 @ -20, -106, 185 +197147995569574, 379602113606061, 228459288583312 @ 139, -248, 66 +291172692753310, 372021072514745, 352834309835310 @ 34, 12, -60 +217546833794162, 191290040026161, 253501313407626 @ 53, -15, -71 +249400409134386, 300702178134668, 313455739745512 @ 69, 53, -37 +215236809500751, 131312078498914, 165853238519326 @ -16, 237, 609 +438453432810582, 255940860832443, 411360000299370 @ -165, 117, -155 +206755963901242, 211675935561037, 110793997188122 @ 103, -99, 569 +236951124070132, 297466048455277, 256754962609874 @ 58, -68, 9 +148871580460682, 208977260642833, 283796479792374 @ 233, 118, -41 +337533398001784, 127917348501766, 371069630077386 @ -41, 277, -107 +231076785232567, 316464170169778, 303962794692535 @ 82, -33, -54 +295230931636387, 148283307864483, 231544980136845 @ 16, 252, 70 +286684562586450, 418045752689857, 311412130974136 @ 21, -98, -34 +195325542326857, 296413361574293, 180152830662495 @ 142, -46, 160 +293562234234353, 253195050605080, 258263678125607 @ -28, 61, 18 +216627802440430, 191786233378484, 218670118900485 @ 9, -205, 90 +212444194265086, 242160041952083, 408504771540078 @ 99, -37, -433 +399468503044708, 237747966985439, 380022351954012 @ -114, 141, -114 +203034431104332, 153584219202793, 169732345813245 @ 123, 190, 250 +336522604758118, 378765298159913, 115634023739946 @ -46, -52, 221 +411855682188620, 289560020485619, 168044857741446 @ -90, 107, 139 +239686437684766, 146178719042051, 247333702720794 @ 31, 229, 13 +328763578487386, 275729337950797, 210598159374158 @ -191, -96, 107 +267869747483902, 305658162631193, 241953404455310 @ 19, -22, 47 +233945494232562, 163881852595793, 235975835715210 @ -130, -7, -44 +210963216216681, 173665593303812, 207386955753599 @ 90, 95, 132 +211774017429793, 221451657767448, 198694845256484 @ 100, 13, 143 +201122974777881, 173694931503961, 187410525515336 @ 114, -530, 639 +371613372690436, 483053706628323, 446474143269594 @ -284, -587, -467 +380537549453506, 427500787123361, 332068790285034 @ -120, -143, -73 +199833661019450, 230482885690417, 270628811830218 @ 134, -254, -179 +359597808018575, 202976442100239, 275153144455668 @ -90, 172, 7 +190311437668434, 54253328484833, 255169066295072 @ 149, 398, 26 +427211286234874, 320791580106737, 186751692997740 @ -111, 70, 120 +182156336120309, 90705213353086, 152603736579205 @ 212, 439, 380 +272080371889046, 200763090252365, 472710661392650 @ 42, 185, -235 +250649446980406, 276179305667147, 269492258715691 @ 25, -40, -22 +255098527784527, 200845917950958, 258384224425040 @ -56, 25, -49 +340406502141208, 486235039883213, 318910309653471 @ -125, -382, -98 +482001492375650, 263042397221697, 446541180443914 @ -145, 144, -139 +250747569743782, 478592698602593, 289346846111970 @ 62, -214, -13 +240995947673902, 145335091170113, 81413838485376 @ 43, 238, 388 +378259953533280, 143771322077729, 377459699176962 @ -124, 254, -143 +295822845200538, 441223847533342, 333556471981606 @ 29, -63, -39 +290337153909832, 257774418382218, 290984778864545 @ -17, 61, -34 +251648926041376, 62269949471439, 128010029337696 @ 55, 376, 223 +192425556641514, 176775297492433, 211659510716286 @ 231, -362, 184 +247773132592477, 263236520189528, 103420788870610 @ -68, -295, 573 +216098157036706, 190834023680381, 366267177502218 @ 105, 167, -171 +219949293285996, 207455129378943, 224159150767575 @ 71, 28, 70 +217743395935322, 90553240327633, 283457993611458 @ -22, 598, -476 +262647153477247, 347326523342993, 206953249958700 @ 42, -42, 103 +236510128651939, 170111053460876, 285079651867944 @ 32, 159, -97 +232424660720782, 236304039993632, 238777501370190 @ 33, -59, 25 +194098673191672, 179897551477442, 251357502719184 @ 163, 11, -77 +215590056284422, 169708095720473, 210174049374090 @ -30, -168, 181 +389953474749235, 325106002770038, 285108735092688 @ -150, -17, -13 +75073384713112, 25765351030553, 131958661160370 @ 276, 394, 185 +201493678702066, 196383295909937, 323040563757738 @ 129, 89, -198 +339871829605604, 301592523784752, 287903705946757 @ -73, 21, -16 +264880646188178, 271635837320233, 237667407273658 @ -51, -132, 33 +443396947040705, 345039086220391, 242759916727681 @ -106, 64, 62 +259698470412892, 280522544679548, 120491314920210 @ -65, -231, 413 +202040412653747, 278867613094134, 208069614860446 @ 128, -99, 113 +250301573762772, 306866454590713, 227347657873710 @ 20, -126, 67 +156475137204672, 230116653452939, 187571542343518 @ 218, 77, 147 +257455927978132, 145886897028596, 309692837822862 @ -17, 229, -151 +209164030957770, 209515060839558, 201556717502513 @ 77, -227, 194 +189737946436922, 173014891184393, 204877857300010 @ 207, -52, 189 +166598000701104, 268840955423078, 92160355769345 @ 179, 83, 260 +226193194431032, 160418199680023, 223236421200320 @ -102, -21, 50 +184919377653217, 233255517014513, 167626425491515 @ 256, -586, 506 +316454485542526, 346799816876993, 313798741982334 @ -26, -22, -44 +368059091363419, 367009944722297, 307598255425446 @ -164, -146, -71 +232588322065552, 229873185432965, 234896095782339 @ 43, -6, 42 +226614096902854, 205663209347485, 250203858638726 @ 46, 21, -16 +256892558569042, 284768449724121, 227553246645242 @ -47, -221, 59 +311747525787082, 246161647148318, 337709030604120 @ -35, 99, -93 +230806682829532, 287176556008133, 212773336187434 @ 58, -112, 101 +173288955408256, 245810645263947, 138653412983474 @ 190, 25, 257 +244082013066922, 265815839450393, 308535371620330 @ 52, 23, -79 +142898137072258, 256462610679739, 193948445233226 @ 277, -48, 149 +244168244022010, 251871427985033, 238530905276730 @ 41, 18, 45 +261012816944908, 197858407057909, 409255846642198 @ -86, 24, -597 +212041885321831, 210916662732545, 209276504516264 @ 16, -538, 183 +297787953120938, 257896976480377, 335508835863582 @ -21, 72, -98 +205969343213662, 124866770359418, 191246958410595 @ 41, 313, 520 +185495105794072, 182028900956453, 314125834857813 @ 223, -62, -502 +246335901706586, 333469921797527, 335790374869608 @ 65, -25, -86 +392960680861072, 347343247331323, 211544205935330 @ -65, 52, 93 +261644860722838, 485350956642647, 177657432845388 @ 31, -315, 154 +270920640787087, 227132466169943, 221561809993320 @ -186, -172, 75 +358923751946616, 301992328806047, 300783553351302 @ -66, 59, -17 +224485337894317, 154469205163707, 223102145017560 @ -62, 60, 55 +450561343198590, 487035149479378, 407239521511251 @ -135, -107, -116 +299853372809677, 48476745323603, 467390546598000 @ -32, 408, -325 +298830936266626, 291798749626433, 485433904501176 @ -131, -162, -626 +277523562889083, 300234195516429, 337092559332891 @ 56, 106, -32 +248653804580626, 262874295779045, 238924886386478 @ -11, -124, 27 +255806245934219, 318844142777107, 367636284715854 @ -34, -296, -359 +223522959259682, 395910120888177, 285125525425450 @ 108, -8, 15 +228730009573754, 222519263517397, 323173430025654 @ 99, 165, -38 +229946667709342, 192117214961330, 253579791283212 @ -47, -113, -121 +257628032013062, 217468286014509, 232678437185618 @ 38, 129, 63 +271556835748734, 345202992463693, 259465434800126 @ 51, 28, 39 +336487836502395, 186878758409691, 85301935620388 @ -36, 204, 251 +251528770085594, 333887777405675, 260994552338240 @ 65, 5, 30 +219577653809182, 154577029498943, 237951868111020 @ -13, 73, -54 +279821188982786, 312453345647441, 288836815141338 @ 9, -10, -23 +496808769097352, 529365960101157, 515544025043822 @ -382, -420, -429 +316511122733995, 110486632399634, 356160985833744 @ -56, 305, -137 +219514532695492, 195113648040579, 276500143560306 @ 43, -36, -179 +282196269411606, 249000919840789, 317500292685298 @ -16, 57, -93 +203148590203482, 94672313021233, 87023850261610 @ 123, 382, 509 +221765864569372, 198750765619828, 121797493795120 @ 55, 21, 435 +180230161063155, 162295810490995, 227824230142053 @ 294, -8, 16 +365112164680882, 478434372728993, 227392357304970 @ -31, -71, 77 +193967007526857, 360109286768802, 136183490676803 @ 158, -683, 428 +178928293374594, 133840610798121, 252427548622158 @ 177, 264, 16 +313972661483208, 430389904970724, 474830430199696 @ -189, -579, -637 +243671340770666, 239787962003561, 378942374151308 @ -39, -166, -544 +330942104453366, 294562372023097, 197426796741198 @ -100, -20, 124 +219569261003863, 280342381340302, 195266824989205 @ 64, -263, 170 +314991842177074, 258058199380545, 362245986975742 @ -155, -50, -273 +228170987436690, 216833054656631, 274746095171817 @ 101, 176, 22 +359722074153721, 183065145941027, 231068416031061 @ -44, 216, 72 +300699721344811, 296229362436594, 258818598634950 @ -20, 21, 25 +175246559001112, 239018771951603, 234733961773215 @ 199, -20, 44 +195503841965434, 292822135129676, 126595482391086 @ 141, -15, 249 +210122253097426, 117663667622183, 64139386471206 @ 117, 293, 331 +267858396535087, 183865771984128, 276078152981305 @ -26, 145, -48 +238651110653899, 159691722304274, 353384593960029 @ 82, 235, -92 +227633012565742, 286842156678083, 183847230586950 @ 105, 116, 121 +333288134138558, 310005440370059, 289513720020993 @ -55, 20, -14 +364060312830814, 275331776026907, 404235609101853 @ -95, 72, -172 +285036868217538, 195280797866981, 290058103457564 @ -99, 92, -108 +212639762301738, 360074885372545, 71706946494338 @ 116, -36, 284 +336830103228052, 364902277732998, 208265007312401 @ -77, -87, 102 +326239698790313, 163971514061130, 208364532591176 @ -28, 231, 99 +331845161397556, 300298732568051, 283094203334462 @ -20, 77, 11 +228533587686617, 202201370353503, 235991282914435 @ 32, 12, 26 +246667455209470, 195051752027597, 192733032724350 @ -165, -156, 255 +306304636512517, 223742266948043, 444396004495350 @ -54, 108, -311 +296039899934322, 145129329948113, 402362269082890 @ 5, 254, -159 +202999771762228, 146240051943681, 237753178134706 @ 82, -50, -231 +382805429868506, 336410075463609, 440218611480970 @ -198, -101, -315 +408884926032706, 202770803758919, 369957487852320 @ -179, 165, -140 +187454478565317, 171799851968911, 251734618819341 @ 218, -24, -134 +209476850606455, 145318450089827, 235058218661112 @ 26, 72, -93 +237143661838570, 267500655008013, 319742257387126 @ 55, -17, -126 +264297070549015, 252770344735044, 261027553674786 @ 22, 61, 13 +223813420961976, 158033971202187, 224609305596604 @ -34, 61, 48 +247955936421811, 430129512657056, 185221232669868 @ 74, -95, 127 +196439322869622, 266185955942518, 344761596267147 @ 153, -497, -614 diff --git a/day24/src/main.rs b/day24/src/main.rs new file mode 100644 index 0000000..6725419 --- /dev/null +++ b/day24/src/main.rs @@ -0,0 +1,192 @@ +use num::ToPrimitive; +use std::fs::read_to_string; +use std::time::Instant; + +fn get_numbers_in_line_split_iter(str: &str) -> impl Iterator + '_ { + str.split([' ', ',']).filter_map(|substr| substr.parse::().ok()) +} + +struct Hailstone { + pos: (i64, i64, i64), + vel: (i64, i64, i64), +} + +enum LineIntersection { + // Has position of intersection + Intersects((T, T)), + // Has coefficient of the line (a, b, c), with line being ax + bx + c = 0 + Colinear((T, T, T)), + None, +} + +// lXpY = line X point Y +fn xy_intersection(l1p1: (T, T), l1p2: (T, T), l2p1: (T, T), l2p2: (T, T)) -> LineIntersection + where T: PartialOrd + std::ops::Neg + std::ops::Sub + num::Zero, + for<'a> &'a T: std::ops::Sub + std::ops::Mul + std::ops::Div +{ + let l1xdiff = &l1p1.0 - &l1p2.0; + let l1ydiff = &l1p1.1 - &l1p2.1; + let l2xdiff = &l2p1.0 - &l2p2.0; + let l2ydiff = &l2p1.1 - &l2p2.1; + let denom = &l1xdiff * &l2ydiff - &l1ydiff * &l2xdiff; + if denom == T::zero() { + let proj1 = &l1p1.0 * &l1ydiff - &l1p1.1 * &l1xdiff; + let proj2 = &l2p1.0 * &l1ydiff - &l2p1.1 * &l1xdiff; + if &proj1 - &proj2 == T::zero() { + return LineIntersection::Colinear((l1xdiff, -l1ydiff, -proj1)); + } else { + return LineIntersection::None; + } + } + let l1det = (&l1p1.0 * &l1p2.1) - (&l1p1.1 * &l1p2.0); + let l2det = (&l2p1.0 * &l2p2.1) - (&l2p1.1 * &l2p2.0); + let detx = &l1det * &l2xdiff - &l2det * &l1xdiff; + let dety = &l1det * &l2ydiff - &l2det * &l1ydiff; + LineIntersection::Intersects((&detx / &denom, &dety / &denom)) +} + +fn vec_add(v1: (T, T, T), v2: (T, T, T)) -> (T, T, T) + where T: std::ops::Add { + (v1.0 + v2.0, v1.1 + v2.1, v1.2 + v2.2) +} + +fn cross_prod(v1: (T, T, T), v2: (T, T, T)) -> (T, T, T) + where T: std::ops::Sub, for<'a> &'a T: std::ops::Mul<&'a T, Output=T> { + (&v1.1 * &v2.2 - &v1.2 * &v2.1, &v1.2 * &v2.0 - &v1.0 * &v2.2, &v1.0 * &v2.1 - &v1.1 * &v2.0) +} + + +// Get integer intersecting line at the right timeframes: (x, y, z), (vx, vy, vz) +fn get_intersecting_line(hailstones: &[Hailstone]) -> ((i64, i64, i64), (i64, i64, i64)) { + // Moving the frame of reference to hailstones[0] so we can compute the rest around origin + // With one line being reduced to start (0, 0, 0) and velocity (0, 0, 0) it'll be simpler + let map_pos = hailstones[0].pos; + let map_vel = hailstones[0].vel; + let hails = hailstones[1..=2].iter().map( + |hail| { + let pos = ((hail.pos.0 - map_pos.0) as i128, (hail.pos.1 - map_pos.1) as i128, (hail.pos.2 - map_pos.2) as i128); + let vel = ((hail.vel.0 - map_vel.0) as i128, (hail.vel.1 - map_vel.1) as i128, (hail.vel.2 - map_vel.2) as i128); + (pos, vel) + } + ).collect::>(); + // cross product of vectors from origin to two points of the first other line + let plane1 = cross_prod(hails[0].0, vec_add(hails[0].0, hails[0].1)); + // cross product of vectors from origin to two points of the second other line + let plane2 = cross_prod(hails[1].0, vec_add(hails[1].0, hails[1].1)); + // cross product of thw two planes to reduce the space to a single line + let line = cross_prod(plane1, plane2); + // The line now represents a good direction with potentially wrong length (not a problem), + // and potentially wrong sign (a problem) + // find the smallest possible vel using gcd + let gcd = [line.0, line.1, line.2].iter() + .fold(0i128, |acc, &elem| num::integer::gcd(acc, elem)); + let mut vel = (line.0 / gcd, line.1 / gcd, line.2 / gcd); + // We need to find the start point + // We know of one line at (0, 0, 0) due to mapping, we'll use it with another line to figure + // out the exact starting position (mapped) + // start + t0 * vel = 0 - the line at 0 + // start + t1 * vel = p1 + t1*vel1 - the other line + // becomes + // start = p1 + t1 * (vel1 - vel) + // start = -t0 * vel + // get rid of start + // t0 * vel + t1 * (vel1 - vel) = -p1 - the vectors are 3 dimensional and we have 2 variables + // solve system of just taking the x and y from vectors + let mut det = vel.0 * (hails[1].1.1 - vel.1) - vel.1 * (hails[1].1.0 - vel.0); + let mut t0 = -hails[1].0.0 * (hails[1].1.1 - vel.1) / det + hails[1].0.1 * (hails[1].1.0 - vel.0) / det; + let mut start = (-t0 * vel.0, -t0 * vel.1, -t0 * vel.2); + // check on other 2 hailstones if the answer is consistent, otherwise flip sign + let mut wrong = false; + let rock_pos = [start.0, start.1, start.2]; + let rock_vel = [vel.0, vel.1, vel.2]; + 'outer: for i in 0..2 { + let mut last_solution: Option = None; + let hail_pos = [hails[i].0.0, hails[i].0.1, hails[i].0.2]; + let hail_vel = [hails[i].1.0, hails[i].1.1, hails[i].1.2]; + for j in 0..3 { + let denom = rock_vel[j] - hail_vel[j]; + if denom != 0 { + let new_solution = (hail_pos[j] - rock_pos[j]) / denom; + if new_solution < 0 { + wrong = true; + break 'outer; + } + match last_solution { + None => last_solution = Some(new_solution), + Some(s) => { + if s != new_solution { + wrong = true; + break 'outer; + } + } + } + } + } + } + // flip the sign + if wrong { + vel = (-vel.0, -vel.1, -vel.2); + det = vel.0 * (hails[1].1.1 - vel.1) - vel.1 * (hails[1].1.0 - vel.0); + t0 = -hails[1].0.0 * (hails[1].1.1 - vel.1) / det + hails[1].0.1 * (hails[1].1.0 - vel.0) / det; + start = (-t0 * vel.0, -t0 * vel.1, -t0 * vel.2); + } + let start_unmapped = (start.0 as i64 + map_pos.0, start.1 as i64 + map_pos.1, start.2 as i64 + map_pos.2); + let vel_unmapped = (vel.0 as i64 + map_vel.0, vel.1 as i64 + map_vel.1, vel.2 as i64 + map_vel.2); + (start_unmapped, vel_unmapped) +} + +fn main() { + let time_start = Instant::now(); + let input_str = read_to_string("input.txt").unwrap(); + let time_start_no_io = Instant::now(); + // Shift the interval to be centered around 0, avoids numerical errors + const COORD_SHIFT: i64 = -3e14 as i64; + const MIN_POS: f64 = -1e14; + const MAX_POS: f64 = 1e14; + let hailstones = input_str.lines().map(|line| { + let mut it = get_numbers_in_line_split_iter::(line); + Hailstone { + pos: (it.next().unwrap() + COORD_SHIFT, it.next().unwrap() + COORD_SHIFT, it.next().unwrap() + COORD_SHIFT), + vel: (it.next().unwrap(), it.next().unwrap(), it.next().unwrap()), + } + }).collect::>(); + // Part 1 + let mut count1 = 0; + for (i, h1) in hailstones.iter().enumerate() { + for h2 in hailstones[i + 1..].iter() { + let l1p1 = (h1.pos.0 as f64, h1.pos.1 as f64); + let l1p2 = ((h1.pos.0 + h1.vel.0) as f64, (h1.pos.1 + h1.vel.1) as f64); + let l2p1 = (h2.pos.0 as f64, h2.pos.1 as f64); + let l2p2 = ((h2.pos.0 + h2.vel.0) as f64, (h2.pos.1 + h2.vel.1) as f64); + match xy_intersection(l1p1, l1p2, l2p1, l2p2) { + LineIntersection::Intersects((xr, yr)) => { + let (x, y) = (xr.to_f64().unwrap(), yr.to_f64().unwrap()); + // Check if it's not in the past, thankfully velocity components are never 0 + if (x - h1.pos.0 as f64) / h1.vel.0 as f64 >= 0. + && (x - h2.pos.0 as f64) / h2.vel.0 as f64 >= 0. { + if x >= MIN_POS && x <= MAX_POS && y >= MIN_POS && y <= MAX_POS { + count1 += 1; + } + } + } + LineIntersection::Colinear((_, _, _)) => { + // Seems this case isn't used + // otherwise I'd have to check if they go in the same direction + } + LineIntersection::None => { + } + } + } + } + // Part 2 + let (start, vel) = get_intersecting_line(&hailstones); + let corrected_start = (start.0 - COORD_SHIFT, start.1 - COORD_SHIFT, start.2 - COORD_SHIFT); + let summed_coords = corrected_start.0 + corrected_start.1 + corrected_start.2; + let elapsed = time_start.elapsed().as_micros(); + let elapsed_no_io = time_start_no_io.elapsed().as_micros(); + println!("Time: {}us", elapsed); + println!("Time without file i/o: {}us", elapsed_no_io); + println!("Count1: {}", count1); + println!("Start: {:?}, vel: {:?}", corrected_start, vel); + println!("Summed start coords: {:?}", summed_coords); +}