From 7321e315bd98dc1f91404799014508bfb15e6040 Mon Sep 17 00:00:00 2001 From: Ray Slakinski Date: Thu, 3 Dec 2020 13:07:51 -0500 Subject: [PATCH] day 3 solution --- 2020/day_3/Cargo.toml | 9 ++ 2020/day_3/input1 | 323 +++++++++++++++++++++++++++++++++++++++++ 2020/day_3/src/main.rs | 37 +++++ 2020/day_3/test | 11 ++ 4 files changed, 380 insertions(+) create mode 100644 2020/day_3/Cargo.toml create mode 100644 2020/day_3/input1 create mode 100644 2020/day_3/src/main.rs create mode 100644 2020/day_3/test diff --git a/2020/day_3/Cargo.toml b/2020/day_3/Cargo.toml new file mode 100644 index 0000000..11166f8 --- /dev/null +++ b/2020/day_3/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day_3" +version = "0.1.0" +authors = ["Ray Slakinski "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2020/day_3/input1 b/2020/day_3/input1 new file mode 100644 index 0000000..14ad2d7 --- /dev/null +++ b/2020/day_3/input1 @@ -0,0 +1,323 @@ +........#....#..##..#...#.....# +...............#....##........# +.#....##...##..#............... +.#.......#......#.##..##...#... +.....#.#....#..##...#.....#.... +...#.#..##...###......#..#..#.# +.....#..##........#.##......#.. +..##.....###.........##........ +..............##..#.#.#.#...... +.#....##..#.##.#....#..#.#..#.. +.#.#....#.##.#...#....#.....#.. +..#...#.#.....#....#.......##.. +.#.#..##.....#...........#..... +.#.##...#.....#......#.##...... +..#..#..........#.....#..###.#. +##....##....#.#...........#..#. +.....#.#.......#.#.#..#.##....# +...##.#....#..#.....#.........# +.....#........#.##...#......... +.....#................#.#...#.. +...#....##.....##....#.......#. +....##.#.....#.#.......#....... +#...............#..#........... +.......###.#.......#.##....#.#. +..#........###........#......#. +.#.......#...##.....####....##. +..##.#....#.....#..#....#...... +..#...#..#.#..##...#.....#..... +.#.......###.......#....#...... +...#...#.......#........#...#.# +..#....#...#.......#.#..##..... +##............#.#..#..........# +.......###...##..#.....#....#.. +##..######.#..#.......###....## +###..#...#.##......##....#...#. +..............##.###..........# +.....#........##.#.###....#.... +..#...#.....##.#......#.#..#.#. +#....#.............#.#......... +.........##.#........#...#..... +..........#..##.#.#.....#..##.. +........##......#..#..#...#.#.. +.##.......#..#.#...#.####..#... +##...#........#.###...##....#.. +....###.####...#..#..#......### +#....#....#.#.....##.........#. +#.......#....#....##........... +##...##.#.......#....#...#....# +....#....#........##..#.#..#.#. +..##.....##...#..........#...#. +.#.#.#...#.....##..#........#.. +#....#.....#..........#....#... +...##.#.......#.#.........#.... +##.##.........##.....##.....##. +##.#..##..#...##........##..... +.........##.......#....#...#... +.#.....#........####.#.#.....#. +...........##..#.###........... +..#....##....#...#............. +#.#............#.......#....... +.##........#...#..##.....#.#... +#.##..............##..##....... +##.........#......#......#..#.. +##.#....#...#....##....#..#.##. +......#...#..#.#...#.#....#.##. +##.......#.....#.........#..... +...##...#................#.#... +....#.####...#.#.....##....##.# +#...#..#.#.##................## +.........##.....##...#..#...... +......####....#.##.#.....#..... +...#..#.#....#.#.#..#.......... +.....#........##...#.##....#.#. +..##......#...................# +.....#..#...............#..#... +....#........#..#.#...##...#.## +..#.#.......#.##.........#...#. +...##......#.#................. +.#....#...#.............##.#... +........#.##...#..#...###.....# +#....#.#........##....#......## +.###.......#..#..........#..#.. +#....#..#....#........#...#...# +##.#.###.##.#...##.#......#.#.# +#..#..#..##........#..###.#...# +....#..#..#.....#...##....#...# +.......##.......#..#.##...##..# +.##....#..###................## +#...#.##.##...#.##......##..... +...##.....##..##...#..#........ +...............##.....##....... +.#..#.#..#....#.....#..#...#... +.#....#..#........#.#...#.....# +##.....####..#......#.......... +........#.........#.........#.. +#...####....#.##...#....#...##. +.#....####..#...##..#......#### +...........##.##..#.##...##.... +..#..#.......#.##....#.#...#.## +#...........#..#............... +.......#.##..#.....##......#... +....##.#.##.....#...........#.# +.............#.##..#...#......# +#......#...........#........#.. +#.#..#.............#...#....... +#.........##...#....#...##..... +##...#..#..#..#....#........... +.#.....#........#.....#.##..#.# +...#..............##.####.#..#. +##.....#..#.#..#..##........... +...#...#.......#............... +..#..................###..#..## +....###..........#.#..#...#.#.# +..#..#..#.#..........#.#......# +....#....#.#...#.###...##..#... +....#.......#...#....##........ +.#.....#.......###....#........ +....#..#..#.....#......#....... +......#...#..#....#.#.......#.. +.##.#..#...#.#.#...........#... +..#....##.#....#.#....#...#.#.# +...##..#.......#....#.#.....##. +##.#......#.#.......##...#..... +......#...#.##..............#.. +.##.........#......##.#..#....# +#.......#.....#...##...#..#...# +..#..##.......#......#......##. +#..##...###.#.#...........#.... +##......#.....####..#..#....#.# +.......##...##.#...#........... +....#..#.##.#.....#.#....#.#... +....#.....#.....####...#..#.##. +.##..#..#..###...#....#.##.#.#. +..#.#.##..........##........... +#.##.#.#....#.##....#..#...##.# +#...#....#...###....#.......#.. +.......#..#............#....... +................##.#.#.....#..# +..........................#.... +.##....##...#.#....####..#....# +......#...#....#...#.##..###.#. +.........#............#.......# +.#.#..#........#..#.........#.. +#..#...#......#.#....#..#.#.... +...........#.................#. +.#.#..#...##..###......##....## +.#.#.##......####.........##... +..#....#.#..#................#. +##.......#....#.........##.#.#. +##..#.###...........#..#.#..#.# +...#............##.#....#...... +...#................##.#..#.... +....#..##.#...#.#.....#.......# +......#......#.#........#..##.. +...##...#.....#.##.......#..... +##...#...#.............#..#.... +..#...##.....#..........#..#.## +#.##...#..................#.### +.........#..........#.###...#.# +#..#.....#.#.#....#......#...#. +.............#.##..###.....#.## +..#..#.....#..#.............#.. +.#.....##.#.#..#.........#..... +..#.......#....#.....##.#...... +.#.........#..#....##...#.##... +.##..##................###....# +.#..##..............#...#...... +.#..............#.##....##..... +.#......#..#..##..#...###.....# +................##...#.#..#...# +##.#.......#................... +....#.#.......#..#.##.......... +....###............##...#...... +.......#....#.#.....##.#.....#. +....#...............#.#........ +..#.##....#.#.#......##..#..... +.##......#...#.#..#..#.......#. +....#...#........#.#..##....... +.##...###.#....#..........##..# +..#.......##..#.....###......#. +...#.#..##.#.#...........#..... +##........#.#..##.........#..#. +.....###.......#..#.#.....##.#. +..#...##.#..............#...... +......#...#...............##.#. +##...#..#....#...#.####.##..... +...#............#.##........... +...#........##.#.##.......#.... +...#..#..##....#...#......#..#. +#.....#..#......#.#.....##.#.#. +.....#.##......#...#..#..###..# +...........##..##.#.#.......... +...#........##........##..##.#. +......###...#.....#..###.#..#.. +#.....#.#....#...##....##.....# +.##....#......#.....#.#..##.##. +##....###.......#...##.......## +...##......#....###............ +..#...#...#.#..#..........##.#. +#.#.###...#..#.....#....#.###.. +..##.....#.#.#.......#......... +...####..#....#..#.........#... +.##...........#.##.#...#.#.##.. +...#.#....#.##......#........#. +##....##....#..#...#..#.#...... +#......#..#...#...#.#.#.#.####. +....##.#.#.....#.###........#.. +....##..#.#.#.#....#....#.#..#. +..#.###..#............##..#.#.. +...#...#..#...#.#.#.....#.....# +..........#.....#..#.......##.# +..............##...........#... +.......#.....#...#.....#.....#. +.#.###.....##......##....#...#. +.....#.........#.#....#........ +..#.#....#.##...#.##....##...#. +...#......#.#.....#.......###.. +#.##....##.....#.#.#...#......# +#..#...#..........#.........##. +....#.#.#.#.....#...###........ +#.#..#...#......#...#.##...#### +.#...#......#....##...#........ +..#.........#............#...#. +##......#..#...#....#.##....#.. +.#...##..#..##.#.#.#........#.# +.##.........###...#......#..### +...##.....##..#.#.........#.... +...........##........#...#..... +..##..#...#..#..#.....#......#. +..#..#.#....#.....#..#.##...#.. +#....#........##..........#.### +......#...#...#....#...##.#.... +...#......#.#.....##......##... +#....#..##............#....#.#. +...#...##.#..........##........ +......#.###......#...#.#....... +..................#.##..#..#..# +....#.....#...#.....#...#....#. +.#....##.#..#..#.....###.##...# +#.......#..#....##.##.#.....##. +..##........##...#.....#....##. +#.........#...........##.#..... +.#....#.#...##..###..........#. +....##..##....####...#......#.. +##.##..#..#....#....####...#... +..#...............#.##......... +...#.#....#..#....#......#..... +.#..#...#........#...#.....##.. +#.....###.......#.....#........ +...#.##..#.......#....#........ +....##..###.##...#.#....#.#.... +#.####...#.......#.....#.#....# +#.......#......#.......#.#.#... +##....#......#..#...#..#..####. +.##.....#........#..#...#...... +#.#.#....#....#...#.##..##..... +....#..#.........###.##.##..... +...##...##.###..#..##.....#.### +..###.......................#.. +......##..#.#.........#......#. +.###......##....#.....#.......# +.....#..#..##........#......##. +..##.....#....#.#.............# +..##.........##.#..#.........## +......#......#.#......#........ +.#...#..#......##...#..#....#.. +...............###............# +#.####.#....#...#...........#.# +............................#.# +.#..#...#.#.#.###..##.....##... +....##...#.................##.. +......##....#...............##. +.#......#.##.#..#.....##...##.. +.............#........#......#. +#..........#.#....#####.#...#.# +.#.#...##..#.#...#.#..#.#..#... +#.##.......##......#.#.#....#.. +##.....##.#.#.##..........##..# +....##..#.#.......#....#.##.... +..#.#.#...#.....#.......#...... +.#....#..#...........###....... +#.#...#.....#......#...#.....#. +#........#.#..........#...#.#.. +...#...#....#.........#........ +.....................#..##..... +...#......##........#.##.#.#.## +.............###...#.#...#..#.. +.#..##........##....#...###..## +.#..#.#...............#.....##. +...........##.#....#..##.#....# +.##.#.#..#.#..#...#.#.#..#.#.## +.......#.#..#..#..#..#...#..... +.#......##............#.#..#... +..#...#..##..#..#...##......#.. +...##......##....#............# +.......#.....##...##.#...#..#.. +......#.......#..##.........#.. +..#...#.#.....#.#.......#.#...# +.#......##.##.#.#.#.##..#....## +#.....#.........#.#....#....##. +.......#.........#....#..#.#.## +.....##....#..#.#.#...#.....##. +#####.#.......######......#.... +..##.#.......#.#..............# +..#.##....#.....#...#.#...##... +.....#...#..#....#.#..#........ +.#....#.#..#.#.#.##..#.......#. +....#..#..#..........##...#.... +.......#.#......#........#..... +##.#.#.###....##.#..#..#....#.. +#.##......#..#.......#.#...#... +..##...#.......#.......#...#... +........##.........#.#....#.#.. +..#...#..##.#.#.#...#....#..... +.###......#........#....#...#.. +.#.......##......###..##....... +#....#.#....#.##.........####.. +......#..........#..##.....#... +.............#......#..##.#.... +...................#....#...#.. +.#..........#...#.#..##...#.... +.....#...#..........##.##...... +#...#..#.##........#...#....... \ No newline at end of file diff --git a/2020/day_3/src/main.rs b/2020/day_3/src/main.rs new file mode 100644 index 0000000..2a32ee7 --- /dev/null +++ b/2020/day_3/src/main.rs @@ -0,0 +1,37 @@ +fn main() { + let mut hill: Vec = Vec::new(); + let contents = std::fs::read_to_string("input1").unwrap(); + for s in contents.lines() { + hill.push(s.parse::().unwrap()); + } + + let rounds = [[1, 1], [3, 1], [5, 1], [7, 1], [1, 2]]; + // let rounds = [[1, 2]]; + let mut hit_trees = Vec::new(); + for r in rounds.iter() { + let right_rule = r[0]; + let down_rule = r[1]; + let mut right_pos = 0; + let mut down_pos = 0; + let mut trees: i64 = 0; + loop { + for _ in 0..right_rule { + if right_pos == hill[down_pos].len() - 1 { + right_pos = 0; + } else { + right_pos += 1; + } + } + down_pos += down_rule; + if hill[down_pos].chars().nth(right_pos).unwrap() == '#' { + trees += 1; + } + if hill.len() - 1 == down_pos { + break; + } + } + hit_trees.push(trees); + } + let total = hit_trees[0] * hit_trees[1] * hit_trees[2] * hit_trees[3] * hit_trees[4]; + print!("You hit {} total trees!\n", total); +} diff --git a/2020/day_3/test b/2020/day_3/test new file mode 100644 index 0000000..8f551de --- /dev/null +++ b/2020/day_3/test @@ -0,0 +1,11 @@ +..##....... +#...#...#.. +.#....#..#. +..#.#...#.# +.#...##..#. +..#.##..... +.#.#.#....# +.#........# +#.##...#... +#...##....# +.#..#...#.# \ No newline at end of file