From f12e99c1f41db7b1ebc5c2867b71ec9b697ed964 Mon Sep 17 00:00:00 2001 From: Keenan Tims Date: Tue, 12 Dec 2023 22:05:32 -0800 Subject: [PATCH] day13: problem 1 solution --- 13/Cargo.lock | 7 + 13/Cargo.toml | 8 + 13/input | 1349 ++++++++++++++++++++++++++++++++++++++++++++++++ 13/src/main.rs | 183 +++++++ 4 files changed, 1547 insertions(+) create mode 100644 13/Cargo.lock create mode 100644 13/Cargo.toml create mode 100644 13/input create mode 100644 13/src/main.rs diff --git a/13/Cargo.lock b/13/Cargo.lock new file mode 100644 index 0000000..74e24a1 --- /dev/null +++ b/13/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "day13" +version = "0.1.0" diff --git a/13/Cargo.toml b/13/Cargo.toml new file mode 100644 index 0000000..36c9510 --- /dev/null +++ b/13/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day13" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/13/input b/13/input new file mode 100644 index 0000000..56b48d6 --- /dev/null +++ b/13/input @@ -0,0 +1,1349 @@ +#..#.#........# +#..######..#### +.##..#.#.##.#.# +#..##.......... +######........# +#..####......## +.##.##.#...##.# + +..######. +..######. +....#..## +##.....## +##..#...# +..##..... +.#..#.#.. +.#..###.. +..##..... + +###..#....#####.. +.#........#.#.### +.#........#.#.### +###..#....#####.. +#.#.#####....#### +.#.###..####.#..# +#..#..#.####...#. +#..#..#.####...#. +.#.###..##.#.#..# + +..###..######.. +...#####.##.### +##....#..##..#. +##.......##.... +.#.##..#....#.. +#########..#### +..###.##.##.##. +..##.#.######.# +#####.#.#..#.#. +..##.##..##..## +###.########### +..#...###..###. +..#.#.#.####.#. +###.#.########. +...#.##.#..#.## + +..#.### +.###..# +.###..# +..#.### +.#..#.. +.##.#.# +####.## +#.##.## +#.#..## +####.## +.##.#.# +.#..#.. +..#.### + +....#..#.#... +.#.#..#..##.. +.#.#..#..##.. +.#..#..#.#... +..####...##.. +..####.#.#.## +.#..##..#.#.. +#..#..##..### +.###.##.###.# +.###.##.###.# +#..#..##..### +.#..##..#.#.. +..####.#.#.## + +.##.#.##. +..##.#### +..####### +###...... +..##.#### +....##..# +###.#.... +.....#### +###.#.##. +....#.##. +..####### +...##.##. +##..##### +##..##..# +..#...##. +...###..# +..###.... + +....#..#######..# +......#.#.###.##. +.##.#.#..#...#..# +#########.##..... +####..##.##..#..# +######.#....##..# +####..#...#...##. +.##.##.....#.#### +.##.##..##.###..# +#..####.##..##..# +.##..###.#..##..# +#..##...#####.... +#..####.#.#.#.##. +.##..#..##..##### +#..#.#...#.#..##. +######..########. +....###.##...#..# + +...#..#........ +.#.#..#.#.##.#. +..#....#..##..# +.#..##..#....#. +..######......# +...#..#..#..#.. +...#..#........ +#...##...#..#.. +.##.##.##....## +...#..#...##... +#..####..####.. +..#.##.#......# +..#.##.#......# +###....###..### +#........####.. + +...##..##.#.# +.##.#####.### +##.#....####. +#.#....#.#..# +.#..#.#...#.# +.#..#.#...#.# +#.#....#.#..# +##.#....####. +.########.### +...##..##.#.# +#.#.###.....# +#.#.###.....# +...##..##.#.# + +....#.#.##. +....####### +######....# +#..#....### +#..#..#..#. +####...##.. +#..#...#..# +#..##..#..# +####...##.. +#..#..#..#. +#..#....### + +.#..##..##..#..#. +..#...##...#..... +##...####...##### +#.##......##.#..# +#.##......##.#..# +##...####...##### +..#...##...#..... +.#..##..##..#..#. +.#..#.##.#..#.#.. +.##...##...##.#.# +.#...#..#...#.#.. +#.#........#.#... +.#...####.#.#.#.# +#.##.####.##.##.. +#............##.# +##...####...##... +#............#### + +#..#.#..# +####..... +.##.##..# +.##.#.##. +#####.##. +.##.#.### +#..#.#..# + +###..##.####..### +###..##.####..### +##..###.#.#...### +#.#.#..##..####.# +#.#..#...#..###.. +..#....####.#.### +#..#...##.###.#.. +.###......####.## +#..#.#...######## + +#.##.#..#...#.. +.#...#.....#... +#.#..#.#.##.### +.#####.#.#..#.# +.#####.#.#..#.# +#.#..#.#.##.### +.#...#.#...#... +#.##.#..#...#.. +#.#.#.###.####. +#..###....###.. +#..###....###.. + +#...##......##. +..###..#..#..## +###.#.##..##.#. +.##.####..####. +..###..#..#..## +...#...####...# +###....#..#.... +###....#..#.... +...#...####...# +..###..#..#..## +.##.####..####. +###.#.##..##.#. +..###..#..#..## +#...##......##. +.##.####..####. +....##.####.##. +.#...##.##..#.. + +.....#.## +...###.#. +...###.#. +.....#.#. +..#.##### +..##..##. +...#...#. +..##.#.## +####..... +.....##.# +##.##.### +####.#... +##...##.# + +..#..#....#..##.. +#.#.#.#####..#### +..#....#..#..#..# +.##.############# +##.###.#..#..#..# +...#.##.##.##.##. +.#.#..##.#.##.#.# +..#..#..########. +##.####.##....##. +#####.#..#.##.#.. +#.####..#.#..#.#. +#.####..#.#..#.#. +#####.#..#.##.#.. + +#.#....## +#...#..#. +.##..#..# +.#.#..### +##.#..### +.##..#..# +#...#..#. +#.#....## +.#.#....# +.#.###### +##.#..#.. +##..##### +...#.#... +...##.... +...##.... +...#.#... +##..##### + +##..##### +.#.##.... +.#.#..##. +.....#..# +.##.##### +.######## +.....#..# +.#.#..##. +.#.##.... +##..##### +..#.#.##. + +#.#.##.#.##...... +.###..###...#.##. +.#......#.###...# +.#......#.###...# +.###..###...#.##. +#.#.##.#.##...... +#.#.##.#.#......# +.###..###.###.#.# +####..####.##.##. +#.#.#..#.###.#### +.#.####.#...#.#.. +.##....##....#.#. +.##.##.##.###.#.. +.#.#..#.#.#.#.#.. +#.#.##.#.#.#####. + +..##.###### +##.#.#####. +##.#.#####. +..##.###### +..###..##.. +....###..## +.#.#....... + +####.#####..##### +#......#......#.. +....#..#......#.. +....#..#......#.. +#......#......#.. +####.#####..##### +...#............. +...#####.#..#.### +.###..###...####. +#.##..#........#. +.#.#.#..##..##..# +..#.#..#.####.#.. +#.#..##..#..#..## + +######.###... +#..#.#.#.##.. +....#.##..... +#..#..#.###.. +...#.#...#### +.....##.##### +.##..#..##... +#..#.#.###### +#######.#.### + +.####..## +#.#...#.. +...###.## +.##..#.## +.##.###.. +.######.. +...#..#.. +#.#..#.## +.#####... +####.#.## +.###.#### +.###...#. +..#....## +.#.###### +##..##... +##..##... +.#.###### + +.##....##....##.. +.###...##...##### +##.####..####.### +..##.##..##.##... +##..#.#..#.#..### +....#..##..#..... +.#..###..###..#.. +#.#...#..#...#.## +...#.######.#.... +#.##........##.## +#.#.#.####.#.#.## + +#..##.#......## +#..##.#......## +..##.###.#...## +.#........##.## +..########.#... +##.#.#..##..... +#.#..#...#..### +##...###.#.#.## +#..#..#.##.#.## +#..##.....##### +##.#.#####.#### +.###..#..#..#.. +....##....###.. +###.#.###.####. +.#...##.#..#... + +.##.##.##.... +..#....#..### +.#..##..#..## +#..#..#..#... +##......##### +.#..##..#.#.. +###.#######.. +##########... +###....####.. +..#.##.#..### +#.######.###. +..........#.. +..........#.. +#.######.###. +..#.##.#..### + +.##...##.#### +#.###.#.#.... +....#.#.##..# +#########.##. +.##..#.#..##. +....##..##..# +#..#.#..##..# +.##.##...#### +#..#....#.... + +#..#..#..##.### +#.###..##...### +##.###....#.#.. +#.##..#.##.#### +.#..######.#.## +#.##.##..#..#.. +##..###....#... +##..###....#... +#..#.##..#..#.. +.#..######.#.## +#.##..#.##.#### +##.###....#.#.. +#.###..##...### +#..#..#..##.### +####..###.#.... +#.#.###....##.. +..###.###...### + +####.###.#### +###..#.#####. +#.###..####.. +#.##...####.. +###..#.#####. +####.###.#### +..##.###..#.. +#....##.#.### +#.##.#..##.## +#.##.#..##.## +#....##.#.### +..##.###..#.. +####.###.#### + +.#.#....# +.#.#....# +.#.#####. +###...#.. +...###.## +....#.#.# +....#.#.# +...###.## +##....#.. +.#.#####. +.#.#....# + +##.#####... +#..#..##... +###...#..## +....#.###.. +#.#..#..### +#.#..#..### +....#.###.. +#.#...#..## +#..#..##... +##.#####... +...##...### +.#...##.### +...#..#.... + +###...##..##... +##..#.#.##.#.#. +..##..######..# +###.##.####.##. +...#.###..##### +##.###.#..#.### +##.####....#### +...#.#..##..#.# +..#...#....#... +###.##########. +##..##.####.##. +###.#.#.##.#.#. +#####..#..#..## + +#.##.##.##. +#.#.#..#.#. +#.#.#..#.#. +#.##.##.##. +#.##.##.##. +#####..#### +.#.#.##.#.# +....##.#... +##..####..# +.##......## +.#........# + +####......##..# +#####.###.##... +....####...#### +.#......##.#... +####.#.#..#.### +##....#.#.#..#. +#..#.###..#..## +#..#.###..#..## +##....#.#.#..#. +####.#.#..#.### +.#......##.#... +....####...#### +#####.###.##... +####......###.# +##....####.#.#. +...####.###.... +...####.###.... + +..##...##..##.# +..##...##..##.# +####..#.#..#... +..##..####.#.#. +..##.#...###..# +##...###..#.### +##..########..# +.#.##.#...#..#. +...##.#.#..##.# +#########.##..# +..#.##.#.##.... +..#####...##.#. +##...##..#.#... + +........#.# +#.....###.# +##....##### +#..##..##.. +..#..#..### +.#....#..#. +.#....#..#. + +..##.## +.#.##.. +#.###.. +..#..## +####.## +.####.. +#.##... +....### +...#... +##..### +#...### + +##.#....######..# +..##.#.##....#### +##...#..#....#..# +#.###..#####.#..# +#####..###...#### +..#.######.###..# +...#.#.####..#..# +#...#..##.#...... +...#...#...###### +...#...#...###### +#...#..##.#...... +...#...####..#..# +..#.######.###..# + +####.##.# +.#..#..#. +#..#.##.# +.##...... +#..##..## +....#..#. +.##.####. +####.##.# +....####. +.##..##.. +....#..#. +....####. +####....# +....####. +....####. +....####. +.##.#..#. + +#.######.###.## +#..#..#..#....# +.#......#.##... +.#..##..#.####. +#..####..#.##.. +##..##..######. +.#.#..#.#.##### +.#.#..#.#..##.# +.#.#..#.#.###.# + +.###.###. +#.#.....# +#.#.#.#.. +.##.##..# +...#.#.## +#..#.#.## +.##.##..# +#.#.#.#.. +#.#.....# +.###.###. +...##.##. +..#####.# +..#####.# + +...#.####..#.#### +##........#.#.#.# +..###...#.##..... +..###...#.##..... +##........#.#.#.# +...#.####..#.#### +#..##.#...####### +....#.##.....#..# +###.##.#.#..##..# +...####.#.#...#.# +..#.#..####....#. +....#.####...#### +###.#..#..#..#.## +.....#######..#.. +....##......#.##. +##.#####.....#..# +###..##.##...###. + +#..##.##### +#..##.##### +.##.#.##... +#...##.###. +#..##.###.# +#######.#.# +#.#..#####. +#.#..#####. +#######.#.# +#...#.###.# +#...##.###. + +..#.####.##..##.# +.#.##.#####..#### +#.#.###.#.####.#. +###..###........# +#...##..#......#. +#..###.#.######.# +.###...########## +#.#.#.#.##.##.##. +######...##..##.. +#.......#......#. +#.###.#####..#### +###...##.#.##.#.# +#.##..#####..#### +..###.#...####... +.#.....##.#..#.## +##....##.#.##.#.# +#.....##.#.##.#.# + +#..#.##....## +#..#.##.....# +######.###... +##########.## +.##..#.....#. +#..#....##.## +......##....# +........#.... +....##.##.#.. +.......#.#..# +......##..#.. +.##..#.###### +.....#.#.###. + +...#.#..### +...#.#..### +.##....#### +###...#.### +....#..#.#. +....####... +...#.#...## +####.####.# +....#.##.#. + +..###..##.. +.#.######## +.###....### +..#..#####. +####...#.## +####...#.## +..#..#####. +.###....### +.#.######## +..###...#.. +##..#...#.. +.#.....#..# +########..# +.#.##.#.... +.#.##.#.... +########..# +.#.....#..# + +#..##.. +..#..#. +.###### +..####. +..####. +##....# +.#.##.# +.#.##.# +##....# +..####. +..####. +.###### +#.#..#. +#..##.. +#.#..#. + +.##...##.## +..##.##.### +###...##... +....#..##.. +....#..##.. +###...##... +...#.##.### +.##...##.## +..#....#.## +.###..##.## +.##....###. +.##....###. +.###..##.## +..#....#.## +.##...##.## + +.....#.##...#..## +#.#...###..###### +###.#...#.#.##### +###.#...#.#.##### +#.#...###..###### +.....#.##..##..## +#####.#.###.#..## +##.#.####..###### +#.##.###.#....... + +###.#..#..# +..#.#..#.#. +..#.#..#.#. +###.#..#..# +...#.#..##. +###..#.###. +..#..###.#. +##.#.#...#. +.#.###..#.. +###.##..### +..#....#.#. +##.#.##.#.# +..#...#...# +....#.#...# +..#..#.#### + +.##.####.##.####. +.##.####.##.####. +..#....##..##.... +#...###......###. +..#.#.#.#..#.#.#. +##..##.#....#.#.. +#.#.##.#.##.#.##. +#....###....###.. +........####..... +.#.#.....##.....# +###.##...##...##. + +#.#####.##.## +...#...#..... +.##.#.##..### +.###.##...### +#..#..##....# +..###...#.##. +..###...#.##. +#..#..##....# +.###.##...### +.#..#.##..### +...#...#..... +#.#####.##.## +#.#####.##.## + +.#.#.#..#..##.. +.#....##.###..# +###..##.#.##.## +.#####.#######. +.#####.#######. +###..##.#.##.## +.#....##.###.## +.#.#.#..#..##.. +########....#.# +#..##.##.##.#.. +#..##.##.##.#.. +########....#.# +.#.#.#..#..##.. +.#....##.###.## +###..##.#.##.## + +..#..##.... +#..#....##. +##.##...... +###...#.##. +#.#..###### +#.##....##. +.##.#####.# +..##.#.#..# +..##.#.#..# + +..##..##.....###. +#.#....#.#..#.#.. +#...##...####...# +..#.##.#..##..#.# +.###..###....###. +##.####.######.## +..######..##..### +#........####.... +#.#.##.#.#..#.#.# +####..####..####. +##.####.######.## +.#......#.##.#... +#..####..#..#..## +.#.####.#.##.#.## +.###..###....###. +...####...##...## +#...##...#..#...# + +#.#..#..# +.###.##.# +.###.##.# +#.#..#..# +#.##..### +.####.##. +.###..#.# +##.#..### +.#.#..... +.#.#..... +.#.#..### +.###..#.# +.####.##. + +#...###.#.##.#### +##..##.###..##..# +..##...###...#..# +#.##.###.##...##. +#.##.###.#....... +..##....#..##.... +......###....#..# + +.#.....##.... +.#.....##.... +......#..#... +#..#...##...# +#.#.#..##.##. +##..##....##. +##.#.##..##.# + +####.##.. +.##..#... +.##..#... +####.##.. +####..#.. +#..#..#.# +.....#.## +#..#.##.. +.....#..# +#..#.#.#. +....###.# +#####.#.# +####..... +####.##.. +....#..## +..#.###.. +#..##.#.. + +....##.## +..#....#. +..#...... +....##.## +.....##.. +##.#.##.# +#...#.##. +#..#.##.# +.#.##.### +.#..##.#. +.#..##.#. +.#.##.### +#..#.##.# +#...#.##. +##.#.##.# + +#.##########.## +.#..######..#.. +####.#..#.##### +###.#.##.#.#### +...#..##..#.... +.##.#.##.#.##.. +..#..####..#... +#.#........#.## +..###.##.###... +..#...##.#.#... +###...##...#### + +#.#.#.#.. +####.##.. +.#....### +.#....### +####.##.. +#.#.#.#.. +.#####... +.####..#. +..####... +.#....... +#..###### + +#..#......#.. +#####....#### +#.###.##.###. +#.###.##.###. +#####....#### +#..#......#.. +###.######.## +#.##########. +..###.##.###. +.#..#.##.#..# +.#...#......# +#.#..####..#. +###.##..##.## + +.####..######## +#.##.#..###.... +..##..#.#..##.. +.#..#...#...... +.####...##.#### +##..##########. +##..##..#..##.# +##..##..#..#### +##..##########. +.####...##.#### +.#..#...#...... +..##..#.#..##.. +#.##.#..###.... +.####..######## +######....###.# +..##..#.#.#.### +.#..#.....##.#. + +......#..#. +.......##.. +##..##....# +######....# +######....# +#.##.#....# +#.##.#....# +#.##.###### +...#....... + +##..#..#..###.. +##..#..#..###.. +.###....###..#. +#...####...#### +####.##.#####.# +...##..##...##. +.##..##..#....# + +.#..#.##..###.#.# +#....###.#.##.##. +#....###.#.##.##. +.#..#.##..###.#.# +######.#.#...#.## +.......##.#.#.... +#########..#..... +.#..#...#...###.# +.####.###.#....## +#....##.##..#...# +#......##.####..# + +.#...#.###.## +..######..... +###..###.#### +#...##.#...## +.#####.#.##.. +.##..#..#.#.. +#.##...###.## +##..#.###.### +###..#...#### +#..#..##..... +...##..#.#### +...##..#.#### +#..#..##..... +###..#...#### +##..#.###.### +#.#....###.## +.##..#..#.#.. + +.#..##.#..#.#.#.. +...##..##....#.## +..#......#......# +..##....##....#.. +.##..##..##.....# +#.#..##..#.#...#. +#.#..##..#.#...#. + +##..... +.....#. +.###.#. +.###.#. +....##. +##..... +#..##.# +#....## +#....## +#..##.# +##..... + +##..### +..###.. +##.#.## +.####.. +..#.#.. +.#.##.. +.#..... +.#..... +.#.##.. +..#.#.. +#####.. +##.#.## +..###.. + +####.##.....###.# +#####.......#..#. +#####.......#..#. +####..#.....###.# +#..####..#.#.##.# +.##..#..........# +######..#.##....# +#..####...###...# +####..#..###..... +.......#.##.##... +....##.###.##..#. +#..##..###...#.#. +....#...#.##...## +.##........##.... +.....#.####..##.# +#..#..#..#.#.#..# +#######.#.#.#.... + +##.##.##. +#.#..#.## +#.#..#.## +##.##.### +.#....#.. +##.##.### +.##..##.. +.#....#.# +#.####.## +.######.# +.#.##.#.# + +.#.#..#.#.##. +#..#..#..#### +..#.##.#..##. +##..##.###### +#..#..#..#### +.##....##.... +#..#..#..#### + +#.##.####.####### +..#.#...###.####. +.#.#....##...##.. +..#.###.##..####. +##.#####..#.#..#. +.##.##.######..#. +.##....#.#..####. +...#..##.##.####. +...#..##.##.####. + +#.#..#. +.##..## +###..## +###..## +.##..## +#.#..#. +.#.##.# +#.#..## +.#....# + +...#.....#.## +..#.#.#....#. +#####..##.##. +####...##.... +#####.#.#..#. +..####..###.# +..#.#...#.... +..####..##... +...####.#.### +##.##.####..# +##..#....#.## +##.###....#.# +..##.#....### +..##.#....### +##.###......# +##..#....#.## +##.##.####..# + +.##.#..#.##.. +.##.#..#.##.. +..#######...# +.####..####.# +..########... +#.###..###.#. +#...#..#...#. +#####..#####. +.###.##.###.. + +#######...... +....#...####. +####.#.#....# +.#.#..##.##.# +####.###....# +#.###.#.#..#. +...#.####..## +.##.###...... +.#..###.#..#. +.#.#.##..##.. +..#..##...... +#.......#..#. +##...##..##.. +.###......... +.##.......... + +##..####. +.###.##.# +#..#....# +#..#....# +.###.##.# +##..#..#. +###...... +#..#.##.# +...#.##.# + +######..... +#..###..### +####..##..# +#####..#..# +#..#....##. +.##...#.... +####..##..# +######..... +.##..#..##. + +..###.#.####.#.## +##.##..#....#..## +..#..###....###.. +.....##......##.. +....#.#..##..###. +##.#...#.##.#...# +..##...#....#...# +..#....#.##.#.... +####..#.####.#..# + +.########..#### +#...##...##...# +#.##..##.##.##. +##..###.####.## +#..####..##..## +##..##..####..# +..##..##....##. +...####......## +#...##...##...# +#.#....#.##.#.. +.#.####.#..#.## +..##..##....##. +.########..#### +##.#..#.####.#. +#..#..#..##..#. + +##..#.... +###...### +.###.#..# +..###..## +..#...... +##.#....# +##.#....# + +####.#. +#..#... +###.### +...##.. +.#...## +##.#.#. +##.#.#. +.#...## +...##.# +###.### +#..#... +####.#. +##.##.. +###..## +.....## +.....## +###..## + +#####.###....## +.######.#.##.#. +..####..######. +##....###.##.## +...##...#.##.#. +.######...##... +#......##....## +.#.##.#........ +..#..#..#.##.#. +###..###.####.# +#.####.##.##.## +..#..#......... +..####......... +###..###......# +.##..##.#.##.#. +###..#####..### +...##...##..##. + +#...#.### +.#.##..#. +#....###. +....###.# +#.######. +#.######. +....###.# +#....###. +.#.##..#. +#...#..## +...#...#. +...#...#. +#...#..## +.#.##..#. +#....###. + +#.#.... +#####.# +.####.# +.##..## +......# +###.#.# +##.#.## +...#..# +...#..# +##.#.## +###.#.# +...#..# +.##..## +.####.# +#####.# +#.#.... +#.#.... + +...##.# +###.#.# +...#.#. +..#.#.# +..#.#.# +...#.#. +###.#.# +...#..# +##.#.## +####.## +...#... +##..... +...#.#. +##.###. +####... + +.#.#.#...##.. +.#.#.#...##.. +.##..##.##..# +#.###.###.#.. +#########..#. +..##..#..##.# +...##...###.# +###.####.###. +.#####.#.##.# +.#####.#.##.# +###.####.###. +..###...###.# +..##..#..##.# + +.####...... +.####..#..# +#.####.#..# +.####..#..# +..##..##..# +.#..#...... +#.##.#.#### +.#..#..#..# +.#..#.##### +#.##.##.... +.#..#.##..# + +.######.##....# +#.####.#..#..#. +.#....#...####. +##########....# +........##....# +.#....#.#.#..#. +#.......###..## +.#.##.#.##.##.# +#..##..##.####. +###..#####....# +.######.##....# +##....###.#..#. +..........#..#. + +.##..###.## +####.##..## +######.##.# +#..#...##.. +.##..#....# +#..#...##.. +.##..###### +####.###### +.##..###### + +..#.### +#.#.### +..#.### +#.##### +.##.#.. +##...## +#.#..## +#..##.. +...#### + +......##... +.#..#.##.#. +##..##..##. +.#..#.##.#. +#....####.. +.####....## +#....#..#.. +#....####.. +######..### +##..#####.. +#.##.####.# + +##...#....#.. +...##......## +##.#.#....#.# +.############ +.############ +##.#.#....#.# +...##......## +##...#....#.. +#....#####... +..###.####.## +#............ +#.#..##..##.. +.#.#.######.# + +#.##......#.##### +.#.#..####.#####. +##..##.##.##.#..# +..##.##..#.#.#.#. +..##.##..#.#.#.#. +##..##.##.##.#..# +.#.#..###..#####. +#.##......#.##### +..#......#..#.### +########.#...#.## +########...##.### +####......#.##..# +#.##.#.###..####. +#.##.#.###..####. +####......#.##..# diff --git a/13/src/main.rs b/13/src/main.rs new file mode 100644 index 0000000..d380727 --- /dev/null +++ b/13/src/main.rs @@ -0,0 +1,183 @@ +use std::fs::File; +use std::io::{BufRead, BufReader, Lines}; +use std::ops::Index; +use std::time::Instant; + +// BOILERPLATE +type InputIter = Lines>; + +fn get_input() -> InputIter { + let f = File::open("input").unwrap(); + let br = BufReader::new(f); + br.lines() +} + +fn main() { + let start = Instant::now(); + let ans1 = problem1(get_input()); + let duration = start.elapsed(); + println!("Problem 1 solution: {} [{}s]", ans1, duration.as_secs_f64()); + + let start = Instant::now(); + let ans2 = problem2(get_input()); + let duration = start.elapsed(); + println!("Problem 2 solution: {} [{}s]", ans2, duration.as_secs_f64()); +} + +// PARSE + +#[derive(Debug)] +struct Pattern { + mirrors: Vec>, +} + +impl Pattern { + fn width(&self) -> usize { + self.mirrors[0].len() + } + fn height(&self) -> usize { + self.mirrors.len() + } + fn col(&self, idx: usize) -> Vec { + self.mirrors.iter().map(|row| row[idx]).collect() + } + + fn find_horizontal_reflection(&self) -> Option { + println!("looking for horiz: {:?}", (1..self.height() - 1).collect::>()); + (1..self.height()).find(|idx| self.is_horizontal_reflection(*idx)) + } + + fn is_horizontal_reflection(&self, idx: usize) -> bool { + let row_pairs = std::cmp::min(idx, self.height() - idx); + (0..row_pairs).all(|offset| { + println!( + "{}: [{} == {}] {:?} == {:?}", + idx, + idx - offset - 1, + idx + offset, + self.mirrors[idx - offset - 1], + self.mirrors[idx + offset] + ); + self.mirrors[idx - offset - 1] == self.mirrors[idx + offset] + }) + } + + fn find_vertical_reflection(&self) -> Option { + println!("looking for vert: {:?}", (1..self.width() - 1).collect::>()); + (1..self.width() ).find(|idx| self.is_vertical_reflection(*idx)) + } + + fn is_vertical_reflection(&self, idx: usize) -> bool { + let col_pairs = std::cmp::min(idx, self.width() - idx); + (0..col_pairs).all(|offset| { + println!( + "{}: [{} == {}] {:?} == {:?}", + idx, + idx - offset - 1, + idx + offset, + self.col(idx - offset - 1), + self.col(idx + offset) + ); + self.col(idx - offset - 1) == self.col(idx + offset) + }) + } + + fn reflection_cost(&self) -> u64 { + if let Some(refl) = self.find_horizontal_reflection() { + println!("horizontal found at {}", refl); + 100 * refl as u64 + } else if let Some(refl) = self.find_vertical_reflection() { + println!("vertical found at {}", refl); + refl as u64 + } else { + panic!("no reflection"); + } + } +} + +#[derive(Debug)] +struct Patterns { + patterns: Vec, +} + +impl From> for Patterns { + fn from(mut lines: Lines) -> Self { + let mut patterns = Vec::new(); + let mut cur_lines = Vec::new(); + while let Some(Ok(line)) = lines.next() { + if line.len() == 0 { + patterns.push(Pattern { mirrors: cur_lines }); + cur_lines = Vec::new(); + } else { + cur_lines.push(line.chars().collect()); + } + } + patterns.push(Pattern { mirrors: cur_lines }); + Self { patterns } + } +} + +// PROBLEM 1 solution + +fn problem1(input: Lines) -> u64 { + let patterns = Patterns::from(input); + + patterns + .patterns + .iter() + .map(|pat| { println!("{:?}", pat); pat.reflection_cost() }) + .sum() +} + +// PROBLEM 2 solution +fn problem2(input: Lines) -> u64 { + 0 +} + +#[cfg(test)] +mod tests { + use crate::*; + use std::io::Cursor; + + const EXAMPLE: &str = &"#.##..##. +..#.##.#. +##......# +##......# +..#.##.#. +..##..##. +#.#.##.#. + +#...##..# +#....#..# +..##..### +#####.##. +#####.##. +..##..### +#....#..#"; + + #[test] + fn problem1_find_horizontal() { + let c = Cursor::new(EXAMPLE); + let patterns = Patterns::from(c.lines()); + assert_eq!(patterns.patterns[1].find_horizontal_reflection(), Some(4)); + } + + #[test] + fn problem1_find_vertical() { + let c = Cursor::new(EXAMPLE); + let patterns = Patterns::from(c.lines()); + assert_eq!(patterns.patterns[0].find_vertical_reflection(), Some(5)); + } + + #[test] + fn problem1_example() { + let c = Cursor::new(EXAMPLE); + assert_eq!(problem1(c.lines()), 405); + } + + #[test] + fn problem2_example() { + let c = Cursor::new(EXAMPLE); + assert_eq!(problem2(c.lines()), 0); + } +}