diff --git a/2023/day14/.gitignore b/2023/day14/.gitignore new file mode 100644 index 0000000..2a7f9d1 --- /dev/null +++ b/2023/day14/.gitignore @@ -0,0 +1,2 @@ +/target +/temp \ No newline at end of file diff --git a/2023/day14/Cargo.lock b/2023/day14/Cargo.lock new file mode 100644 index 0000000..5bdd842 --- /dev/null +++ b/2023/day14/Cargo.lock @@ -0,0 +1,197 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "aoc" +version = "0.1.0" +dependencies = [ + "itertools", + "sscanf", +] + +[[package]] +name = "const_format" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a214c7af3d04997541b18d432afaff4c455e79e2029079647e72fc2bd27673" +dependencies = [ + "const_format_proc_macros", +] + +[[package]] +name = "const_format_proc_macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f6ff08fd20f4f299298a28e2dfa8a8ba1036e6cd2460ac1de7b425d76f2500" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "either" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" + +[[package]] +name = "itertools" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25db6b064527c5d482d0423354fcd07a89a2dfe07b67892e62411946db7f07b0" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "memchr" +version = "2.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" + +[[package]] +name = "proc-macro2" +version = "1.0.70" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +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 = "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 0.8.2", +] + +[[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 0.8.2", +] + +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "sscanf" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c713ebd15ce561dd4a13ed62bc2a0368e16806fc30dcaf66ecf1256b2a3fdde6" +dependencies = [ + "const_format", + "lazy_static", + "regex", + "sscanf_macro", +] + +[[package]] +name = "sscanf_macro" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84955aa74a157e5834d58a07be11af7f0ab923f0194a0bb2ea6b3db8b5d1611d" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "regex-syntax 0.6.29", + "strsim", + "syn", + "unicode-width", +] + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "2.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-segmentation" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" + +[[package]] +name = "unicode-width" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" diff --git a/2023/day14/Cargo.toml b/2023/day14/Cargo.toml new file mode 100644 index 0000000..9123055 --- /dev/null +++ b/2023/day14/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "aoc" +version = "0.1.0" +edition = "2021" + +[dependencies] +itertools = "*" +sscanf = "*" diff --git a/2023/day14/src/input.txt b/2023/day14/src/input.txt new file mode 100644 index 0000000..a4b4ee3 --- /dev/null +++ b/2023/day14/src/input.txt @@ -0,0 +1,100 @@ +.....O..#....O.O.....OO#...#.....#...........O#..OO...#O##..#.....#...O.OO...#.O......OO#...OO...O.. +OOO....#O.#..O#.#.OO...OO..O##...O.....O.O...#.O.......OOO.O...#.....#.#.O....O.O.....#...#.OOOO.O.. +...O..#...#O..#......O#.......#..O##O.#....##......O.O...O..#O.O..##..#..#O......##...OO.#.O#..O...# +.O..#...##O..#....#...O.O...#........O.O..#...O..#O.O.....#O...OO.#....O..O....OO##OO#...O#.O#...#.# +#.O......O.#.O..OO.O..#....#.OO....#.#..#..O#.O....OO......#.##O...#.OO........O..OO...OOO#O.#O#.O.# +...##.O.#O.O.##.#..O....#.#..#.OO.O...#....#.O..O#O.O.O..O...O.O..##...O#..#.......O.O......#O.#O... +.O.O..O..O#.O.O..O.O..O..O..............#...O#O#.O.#.##..........##O....O.O...........O..O..O#...#.. +...#O.O.OO#..O..#.#...#O...O..#...#.........O...#OO#...#.O#....O...##..O...O.#O#.O#...O.O...#OO.O#.. +...##.##.O...O..#..#O.O.O...O.##..#.#.O..OO.O......OO..#..O.O..#..#.......O..O.....OO.OOO.O..O..#O.# +....#O.O...#OO..O.O............O.....#O..#O#...#.........O.O..O...OO....#..O..##.O..####O#O.#....... +.OOO.......##..O..#O.OO.##.....O....#..OO.#O.......OO..........OO..O..O#...#..O..##.O........#....O. +....#.O#...#OO..............O..O.O...O...O...O....O###....O.#OO...O#.OO.#...#.#.##.....O...........O +.......#O##..#......#.O.#.......O#.#.O#O#..#.#...O.....O..O#..O..#.O#....O..#.......O..O..#O........ +O..O.#.O...#....##...#.....O..#.#......O..#O..#.OO..O.##.........O#O.#....#..#.###OOOO..#OO.#O.O.O#. +...O##O.#.............#..O.O....O#.....#OO...OOO......O#.O...#O#.#..#....O..#.#..O..#.O...OO.....O.. +...O......#..O.#.#..##....O..#....#..O.#.......#..O...##O.O.......#..O.OO..O..........O....##.....#. +........#O##..O....#....#.....O...O.O.O.OO..O........#..#.O.........O.....O..O.O..#O.O...O...#..##.. +.O.#.....O.O.#..##O#.....#.#..O......O..##.#.#....##...O...OO.#..........OO.#O#OOO..#....#.#...O.#.. +....#...#.OO....#..OO#.#OO.O....OO..#..O....OO.......##.##O####O.O.O#..#....O.O......O.....#.O..O... +.O#O#........O.#...O#O..#O...O.#..#.#..O#........O###..O..#...#..O.##..#............O.......O..O.... +........#.O.....O...O.....##.....##.#.#.#....OO####.#..O#....#O...#.O#..O.O.#.O......O..#..O.....O.. +..O#..##O.OOOO...OO....OO#.#.O.....#.#......#...#OO#...####O#....O...O.O.O.O#....O.##OO#..O.#.O..##. +.##...............#.O#OO.#.......#...#O.#.OOO#.O...#....#....O#..O.#..O...O#...#..O#.O#O#........OO# +...#......##...#.#O..O......O#O.O..OOO..O##....#....O.#..O....#........OO#.#...#.O#..O....O.O##..O#. +.OO......O.....O...##..#...#....O.#....O....O...........OO.#.#..#...#.O#O.#.#......#.O......O.O#.#.# +O.O....#O...##.O..#O.O...#...O.......O.OO...O.O#.....#..#.O#.....O.O...........O.....O...O.....#.... +.#O#..O....O.......#..OOOO.....O.....####...#.......O...O#O...O..#..#...##.#.....#....O....#...##... +........O.O#OO#..#.O.....#.OOO......OO#.#.....O.#..#O.........#OOO......O..#......O..##....#O....#.# +..O..#O.....##..#.OO..O..........OO..O...#.##O.#.#..O.O#.#.#......OOO......#..O..#.O....O#...OO#.... +...#.OOO.O......O#O...O.O.OO....OO#.....O.O.O#.....O##.OO......#......OOO#O.OO.O#...#.....O....OO... +...#.#O..O...##.#.###.O.#...#.#....O.OO...O.O.O.O...#.#.O....#OO#.OO...#O...#O...OO.O..O..O....O..O# +.##.O......#.##.....O...OO#...O.....O..#.....O.........#....O..#....O.####......#...#........O#..OO. +.#.#.O.#.O#..OO.#....O...#.O...O..#.O.....#OO....#.O.O.O......OO...#.#.O#O#OO.#O.O.....O.........#.. +..#.#..O...#..#.....OO.#O...O#...OO.O...O#....##O....#.#...OO.#.....#.O#.....O.....O...#.#O.....#... +.O..OO#.#OO...O..#..........OO.............##..####...#.O....O...#.#...O#..O.O..OO.#....OOO..#...OO. +#...#....#.........OOOO....OO....O#O..........#..O#..O...#.OOO.....OO.......OO.##...O.#....OOO...##. +#.........#OO#.O.#..##.#.##O...#...OO....O#O......#.......O.O...#O...O.O.#O##O#..O....O#.#......O.#. +...O..O#..#...##..O....O..O......O.O#...OO.......##......OO..#.O....#.##O.OO....#.O.#.OO..O....O.#.. +.O..O.#.O.#............O....#....#....#.#.....#...OO#...OO.##OO.#..#....#....#.O#.OO#.#.O.O#..O..... +.OO#O...#.#......O...#...O##.O....O#...O..O..O..O.#O..#..###OO..#..O##O.#.O...O#O...OO.O..#.#O#..#.# +#..OOOO...OOO.O..#O...OO##....O#..OO...O.O.#....#O#O....#.#....O#...O...O....O...#..O.#O..#..#..#O#. +##.....OO#.....#.O.O..OO.O.#.....O..O....#....#.........OOO.O.....O#...O..#..........O.O.#..#...#..O +##.#.#.O..O.....##.##.#O..#........O#....O..O....O....#..O.##OO#.O.O..O#...###.OO.O#..#.O...##..OO.. +O....#.....O...#.#.OO..OO.###.O.#O.O...#.O.#......O.O#.#O#..O#...O...#.OO##..#.O.......#O....#...... +..#....#..#.O..#.O.O..O#......#O..#...O#.....#..#O..O.O.O.....#O.#.........O..........O.#O..O.O..O.. +OO####.OO..O...#..#O#.O#.#......#...#.#.O##..##.O.....O.OO.O.O#...O...O...O...O.O#........#..O.O.O.. +.O#O......O...O.#O##.OO.O..OO#..#OO...O.O..O.#...#O..OO....O.#OO.#O.#..O...#....#..OO#.......###.... +..#O#O........#.O.#...#O.#.O..O.O#..O.O#OO.O.O#O.#OOO....O#.........#..O..#.O...O........O#.......O# +...O.#.OO....#OO...#.........O..O.O.#OOO....O.....O..O.#.......OO..#O......#.#O..#.OO#O....O#.....O. +O.#OO..............#.O...##....OO#OO.......O#.....O.O....##....O........#......O..#..#..###O...#.... +...O.OO..O#...#.#O..O#...#..OO...OO......O..#..#....O..#.#......#...#....#.OOOO.#....##......O#..#.O +..#.......#...##OOO..O.....O..O.O.O..O#.....#.#O........O..#...#O..#...O#...#.OO....#.O..O#..O.#OO.# +##.#.O.OO..O..##O...O..O..O.......O.O....#...O......O.O.#.O......O......O...O...O.#.#.OO#OO...##..O. +.O...OO...#..O.O.#O..#O......#.#..#...........#O....#.###.#....#O.#...O....##...#.OO....O.#.O.O.O..O +.#..O#..O......#O...O..#.#.....OO...#.##.......#..O.O.......#......#..#....#.##..O.......O...#.OO... +O..O...#O.O#O#.....#O..#..#..#...O...O#.#O........O.OO.O.....#O#.#...O#.#...#O.#...#O.....#..O.O.... +OO.OO.#....O....O##..O#..O...#.......#......#.OO..O......#O#.OO.#...O.......#.#O....#.O...#.O.....O# +.O#.....#O.O....OO..O..O.#O.#O.O.OO..#.#...O.........O#...OO....O...#..O....O#.O#..#O#..O.#..O....O. +OO..##.O.......OO.O..#O...O...O.##...........O#.O...O....O#.#.OO...#O....O.#O......O#.O...........O. +O.#...........#O#.O.##...O#....O.O...#..O...#.OO.....#OO..O#.#.O..........#.#..O.#...#.......##O#O.. +....O......OO.OO..........OO.O...O.....#.#...OO..#.O#.O......OO##O.O...#.OOO...#...#..O......OO.#... +....#..#.#.O..O#....O.#.O#O#.#.#.O...O.....O..........#...##.O#..O#O.O..O#...###..O..#.O...O...#...# +###.....O#.#..##....#..O..#OO.#O.O...#..#O.#..O......O.....#.O..OO##.#.##.#.....#...O#O##....#...O.O +.....#..O.......#..O.#..#..#..O#...#...#O...O#.OO#.O#O#OO..##.O#.O.#..O.#..O..O....#.O.O..O........O +........OO...#OO.#..#.OO#...O..OO....#......OO#O#.#.#...#O.#.O......O.....O#..#...#....#.#O#..#...O. +O#...##..O........#OO##...#......O...........OO#...O.O.##O........#....##O.....##..O.....O.#O#.#.... +......O....##.#.O##.O#........##O.O..##...O..#.O..O....#.OO...OO.#.......#.O.....OO#O.##O.O....O#..O +..O....#...O.O...##.#....O....O..O......#...O..#..O......O.OO.#..#.O#...#..O.OO........#..#O...O..#. +#.O.#.O.....O..###.#.............O.##O.#.OO..#.....#.....O.........O.OOOO#...#.O#.##O.......OO.#OO.. +....OOO..O...OO##.O...#.#.OO..O#...O.#..O..OO.#O.##..##....O.O..OO#O...O#.....O..O##......#.#......O +..O.....O..#.........O#..O..#.OO..O##..O.O.##O#....O.OOO...#...O...O#O.#.O..............O....O#.#... +OO.#....O.......O..O.#.OO....##....OOOO...O.......OOO#....O#...O#.OO..O.....#.##...#..#..O......#O.# +.O...O...O.#O.O..OO##..#..#OO.O.OO....O........#O.....###OO.OO.OO..O##...O.#.O.....O......O...O##... +...O...O..#..O.......O#O....##.O.OO#.O...#OO.#..O.O.#...#O.#.#...O..O...O..OOO..#..O..O..#.#..#.O..O +.....#.......O.O...#.O.........O...#...#..O.##..OO...#.O..........O#.#..O#.#.O.OO.#........OO..O..O. +#O.OO..#..#.###...O....O.#...........#O....O.#O.#..........O.........O.....#..O.#..O.....O....OO.... +O......O..O...O...O..O.OO...O#...O......#..#O.O#.OOO..#.#.....#O.....##..#OO...O.....####O.......... +O....O#..#O..OO#O...O.#..O.....#..#..O..#..O..O#O..#.......O.#.#...O.........O..OO#.......#.O..OO.#. +.#.#...O.#O.....O....O.#O..O.#....OO..O#...#.O.#.OOO.O..O.....O.O..#.#..OO......#.#.O#O.#....O.O.O#. +....#O..##..#.#..#..#....#.#O.#.O####.......##.......##O.O......O..OO.##OO.......#...O..O....O#....O +.......O..OO.#.........O..O...OO...O.O.....#.....#.....O...O..#.##O.O...OO....O...O#O......O..O#.... +.....O....#...O.O.#O...O#..O....O.OO......O......O#O..O.O.O.##O..#...O...O.#.##O....O....O...O..#.#O +..O.O#O.....O#.O........##...#...#.O##O....#.#.#..O.O.OOO.##...O...##.O.O.#...O.#.#...##.....#.O..O# +.O......O.#O...OOO..#..##...#...O...O..O.........O.O#.....##.......##..O.OO...#.#..........OOO..#... +#O............O..#O#..#OO...O..#.O.O.O....O...#.#.#OO....O..##....O#..#...#OO..#.#........#........O +.#....#O#.O.#.....#.O....O#.....O....OOO#O.O.O.....O..OO.#O..#..#.OOOO......#OO.#.........O#.O#..#.# +...O..#..O.#......O....#..#..O.O.O.###.#.....OOO.#O.O.....O.O.#.#O...#.O#..#.....#......##...O.#.#.. +#...O....#.O....#...###...O.#.O..O#.#.#.O...........O#.#..O.#...O...O..#O..O....#O...O.O##....O....O +#O...#.OO#.#O........OO......#..O...O.OOOO.#.#..O#.##.O.O....#..O#..O.......#.O...#..#O......O..O... +...O....O..O.#OO#...O.....O..#........OO.....OO.....#.O..O......O...#.OOO......OO...O.#O...O..O##... +..#O.O.......##..O.OO.........#.........O.O#....O..O#.O...#OOO...O...#O.#O.#O.......#..#.##..##O...# +..O....O......#...O.#......O#....O.....O.....O..O......##.#.#O..OO...#.#.O#.O#O.#.#.O.#.#.O....O...# +...O...O.......#............O#O#..#.O....O#..OOO.#O#..OO.O...........OO...#...OOOO...#..O##O.O..#... +.O.O....O.#O.O#...#.#...........#.O.O#.#..O.#........O..O...#....O........O..O.#.#.#...#.........#O. +.O#..#O...#.O#.#...#...O...#..O##O..O......O.O....#O.#..O#OOO.O.#.........O....O.#.O....#OO....#...O +O#...#....#.#...#...O..##.#.....O.#..#.O....###O..O.OO#.....O...O.......#.....#O......#...OO.#.O..#. +O.O#O.#...OO##.#OO..#...O..OO#.O.....##..OO.....##..#O...#...OO#.O...#......#.O#..##..#.O.....O#.#.O +O..#O.O...OO.#O.O....#.OO...O...#..O.O..#OO............#........O..#.....#OOOO...O......O.##.O....O# +#...#OO.OO.#.#...O...O....O..##.O...#..O.......####.....#......#..O...#.##....#O..O..O.#.#.#......O. +.....O...O..#.O#...O..#.#.O#.O.OO.#..........O...OO#O#.....#.OO.........#OO.O...O..OO.O.#......O##.. diff --git a/2023/day14/src/main.rs b/2023/day14/src/main.rs new file mode 100644 index 0000000..c5b15fb --- /dev/null +++ b/2023/day14/src/main.rs @@ -0,0 +1,138 @@ +// Problem: https://adventofcode.com/2023/day/14 + +use std::collections::HashMap; + +type Result = usize; + +type Input = Vec>; + +fn parse_input(input: &str) -> Input { + input + .trim() + .lines() + .map(|line| line.chars().collect()) + .collect() +} + +// ------------------------------------------ + +fn part1(input: &Input) -> Result { + let l = input.len(); + let mut prev = input.clone(); + loop { + let mut input = prev.clone(); + for r in (1..l).rev() { + for c in 0..input[0].len() { + let mut up = 0; + while up < r && input[r - up][c] == 'O' && input[r - up - 1][c] == '.' { + input[r][c] = '.'; + input[r - 1][c] = 'O'; + up += 1; + } + } + } + if prev == input { + break; + } + prev = input; + } + let input = prev; + + let mut res = 0; + for (i, line) in input.iter().enumerate() { + res += line.iter().filter(|c| **c == 'O').count() * (l - i) + } + res +} + +#[test] +fn test_part1() { + let input = parse_input(include_str!("test.txt")); + assert_eq!(part1(&input), 136); +} + +// ------------------------------------------ + +fn tilt(input: &Vec>) -> Vec> { + let mut prev = input.clone(); + let l = input.len(); + loop { + let mut input = prev.clone(); + for r in (1..l).rev() { + for c in 0..input[0].len() { + let mut up = 0; + while up < r && input[r - up][c] == 'O' && input[r - up - 1][c] == '.' { + input[r][c] = '.'; + input[r - 1][c] = 'O'; + up += 1; + } + } + } + if prev == input { + break; + } + prev = input; + } + prev +} + +fn rotate(v: Vec>) -> Vec> { + assert!(!v.is_empty()); + let len = v[0].len(); + let mut iters: Vec<_> = v.into_iter().map(|n| n.into_iter()).collect(); + (0..len) + .map(|_| { + iters + .iter_mut() + .map(|n| n.next().unwrap()) + .rev() + .collect::>() + }) + .collect() +} + +fn part2(input: &Input) -> Result { + let mut seen = HashMap::new(); + let mut prev = input.clone(); + let mut i = 0; + let mut s = true; + while i < 1000000000 { + let mut cur = prev.clone(); + for _ in 0..4 { + cur = tilt(&cur); + cur = rotate(cur); + } + if s { + if let Some(idx) = seen.get(&cur) { + let cycle_size = i - idx; + let remaining = 1000000000 - i; + i += cycle_size * (remaining / cycle_size); + s = false; + } else { + seen.insert(cur.clone(), i); + } + } + prev = cur; + i += 1; + } + + let mut res = 0; + for (i, line) in prev.iter().enumerate() { + res += line.iter().filter(|c| **c == 'O').count() * (input.len() - i) + } + res +} + +#[test] +fn test_part2() { + let input = parse_input(include_str!("test.txt")); + assert_eq!(part2(&input), 64); +} + +// ------------------------------------------ + +fn main() { + let input = parse_input(include_str!("input.txt")); + println!("Part 1: {:?}", part1(&input)); + println!("Part 2: {:?}", part2(&input)); +} diff --git a/2023/day14/src/test.txt b/2023/day14/src/test.txt new file mode 100644 index 0000000..5a24dce --- /dev/null +++ b/2023/day14/src/test.txt @@ -0,0 +1,10 @@ +O....#.... +O.OO#....# +.....##... +OO.#O....O +.O.....O#. +O.#..O.#.# +..O..#O..O +.......O.. +#....###.. +#OO..#....