diff --git a/day03/Cargo.lock b/day03/Cargo.lock new file mode 100644 index 0000000000000000000000000000000000000000..21127a294c5de6a60de31858783f0739a4f94dd4 --- /dev/null +++ b/day03/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "day03" +version = "0.1.0" diff --git a/day03/Cargo.toml b/day03/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..ff17ccc138d204cfe406bad9f51b6be61af16b34 --- /dev/null +++ b/day03/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "day03" +version = "0.1.0" +authors = ["Philip Molares <philip.molares@udo.edu>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day03/input.txt b/day03/input.txt new file mode 100644 index 0000000000000000000000000000000000000000..92b6208b86961cf5fb321628bf4c4e61a5600ff0 --- /dev/null +++ b/day03/input.txt @@ -0,0 +1,323 @@ +i......#..........##......#.#### +.##...###....#.....#...#.#..... +#..##..#.....#............#.#.# +##.#....#####..#....#..#.#..... +..#.#...##.##.......#.#..#..##. +##.#.......#.#.#..#...#.#...#.. +...#...#..#.##....##..#.#...... +.......##.#.#.#.##...#......... +..#...##.##...##..##.##...#.... +.#.#...#.....####..#.#...#.##.. +.#...#......##......##....#.... +..#.....#.........##.#...#.#... +...#.#...#..##...#....#.....##. +..#.....#..#..#......###....... +...##.#....##..##...........#.. +....#......#..#....###...#..... +.....#...#.#.....#..##........# +....#...#....##.#.##.#...#..#.# +.......##.#......##....#....#.. +...#.#...##..#...#..#..#..##.#. +##.#...#..#..................## +##........#....##...#..#..#.... +.#.#..............#######.##... +##..#..#.#.##..#............... +..#........#..#...##.......#... +............##.##.#..........## +.....##..#.....##..#.....#..... +..#.##.###.#..##.............#. +.........##...........#.....#.. +..#....#.#.###.#.#.......##.... +..###..##..#.#.##......#.#.##.. +##......#.#....##.#..#.#..#.#.# +..##.#.###.#...#............... +..####.......#...#.##....#..... +..#....##...#.#.#.#....#.##..## +.#...####..###....#.###...##... +..#.#..........#.#..#..#.....## +.#....#.........###...#.....##. +..#.#.#.##........#.##.#.....#. +#....#....###...#..#.........#. +#..#.###....#..............#... +............#....##.#......#.#. +...#..#.####...............##.. +....##......#.#.........####..# +.#....###..#.#..##........##... +#..##.....###..#............... +..#...........#........#...#..# +......................#.#..#... +.#.##.#..#.#....#...#...#.#.... +..#..#.........#..#.#.......... +.#......#####...#......#..#.... +..........#.....#..#.##.####.## +##.##..#............#####...#.# +..##..#..###......#...#...#.... +....#####........#.##...###.... +......#...##..#..#............# +...#....##.##...#..#...#....... +....#####.#...............###.. +.#....#..##....#.#.#..##.##...# +...#..#..#........#.#####.....# +......##.#...#..#..#.....#..### +###.......#.#........#......#.# +..#.#..#..#........#..#......#. +...##.........#..........#..... +...#..###.#.......#.#.........# +....#..#.##...##.....#.....##.. +#.#.#.#.....##.##.###..#.#....# +..#....#.....##.####..#........ +...#..#.##.....##.#..#....###.. +.#..#.....#....#...#.#.......## +..#..#.......#.#.###......#.##. +.###.####....##............##.# +#....###.#......##.#......##.#. +.##...........#.#....#......... +#.##..##...#...........###....# +#.#..#...#.#..#..###.#.##...#.. +..#...#.#..##....#..#..#....... +#..##..#.####...#...#..####.##. +###..#.##....#...#.###..##...## +##..#..#.#....#.....##.......#. +..#..##.##.#.......###.#.....#. +..........#.####....#.......#.. +#...#.#..#.......##......##..## +##...##.##..###...............# +....##.#...#.......##...##..#.. +.#.........#...#.#...##.#.....# +.#...#.#..#...#..##....#..#...# +.#.#...#..#..###...##....#..... +.........#.#...####..#...#.#... +...#.............#.#..........# +...#...#..##.#........#.#...... +...#...#.....#....#..###.##.### +.#.#........#....#...#.###.#.#. +##.....#.......#..##.#....#..## +...###...#.#.#.#....#.#....#... +#...#.#.......##.#..#....#.#... +#...#......###.....###........# +..#.##...##....#...#....#.#.... +#....#..###....##.#......##...# +##.#...#..........#.##....#..#. +.##....#............###.#...#.. +###.##.#####.##.....##..#####.. +..###.###.......#.#...#....#... +.#...#....####.........#....... +..##.#.#......#....#.#....#.#.# +#.####.....#....#..#.....#.##.. +###.###.##...##.#.#.#.....#.#.. +.......#.....#.......##.#.....# +#..#.##...#........#.#.......## +#.#........#...#....#.......... +..#....##.#......#..#.......... +#....##.....#.....#.##.#...#... +....#.#.....#....####...#.#.##. +......#.......##...##.#......#. +.#.........##...#..#..##..#.... +.#...##.....##.#....#.......... +....#.###..##..#...#..........# +......#...#.#.#........##...... +.#..........#.#.....#..##..#.#. +.......###.#......#....#.#..#.. +..##.......#....#....#.#...##.# +#.##.#.......#..###..##...#.#.. +......####....#.#.....#...#..#. +#.##.###..#..#.#.....###..#.#.# +#.#.#..#.#..##...#...#..##.###. +....##..##.#...............#.#. +..###.#.#.##..#....##.......#.. +#.#....#..........##......##### +.#.#.......##.#.#......##..#.#. +......#.###.##.#..#....#.##.... +..###........#.......##.#.#.... +.#..##.............#.##.###...# +.#####...#......#.......##..... +##..###.#...#....#..#....#.#..# +.#.........###.##.....##.....## +.##.#....#..#.#..##..#....##... +.#..#..#......###...#.......#.. +#.#...#.....#..#.#.#..#..###... +....#....#..#..#....#..#.#.#... +......#.......#.#.#.#.....#.... +###...#...#......#..#.#.#..#.#. +#...##.##.##........##....#.... +.....#.......#...#...#.#.#....# +...##.....##.#...#.#.#.#..#..#. +.#.......##...........#...#.##. +.##..........#......#.#...###.. +.....##...#.....#...#......#... +...........#.....#..#...#..#.#. +#.....##..#...........##....#.. +#.##...###.###....##..#..#....# +#.#.##...##....###....##.##.... +.#..###.....#......#...#...#..# +..#...#....#.#.###.#..#......#. +......#.........#..#.##...#...# +..#.#....##.#..##..##...#....#. +#.....#....##.........##.#..... +...#...#..###.###......##...### +.##.###...##..#.##....##.#..#.. +..#..#.......#................# +.....#..#.#.#..........##..#... +......###.#.#............#..#.# +..#.##.....##....#...#...#.#... +..#......##...#...##........#.. +#.....#.....#..#......#.###...# +....#..#.#.....#...#....#.#...# +#.......#..#...##..#.#..#.##... +..#......###...#.........##...# +...#.......##.....#..##........ +.#....#.#.....##.#.#........... +##..#..#...#.##.#.#.#.#.#..##.# +##...####.#.#.##...#..#......#. +#.##..####.##.#.........#...### +#...#.......#.#..####.#.#.#.... +#....#........#........#....... +..#..####.....#....##...###.##. +...#.#..####.........#....#.##. +##.#...#...#..#.#..##.....##... +....#.........#.##........##.#. +##...#......#....#..#....#....# +###.....#......##...#...##...#. +#.##...............#.......#... +.##.#...#..#....#.#.....###..#. +.....##...#.##.....##...#....#. +#.#..#..........#####..##...... +..#.........##...#.........#.## +...#..##.#.#..#......#..###.### +#..#...#.#...##..........#..... +.###..#....###.....#....#..###. +#..#....#...#........##.....#.. +.#..###........#....#..####..## +.#..#.#.#.......##.#..##.#..##. +..#..###......##....#..#..#..#. +.......###..##....#......#...## +#........#.##.............##.#. +...#.#.#....##....##.###...#... +..#.....#..##..#.#.......#.#### +.#......##.........##...#.....# +.#.###........##....###.#.#...# +##...#.#....#.....##.......#..# +#...........#...........####... +#..#.#..##..#...#....#.##....#. +................##............. +..##...#.#....##....#...#...... +.#.....#....#....#..#..#.#..##. +.....######.#.#.##.###.#....... +..#####....#..#...........#.#.. +.......#..#..##.#...###.#.#.### +###...#...#..##.#.##..#...#..#. +.#..#..............#........... +.#.....#.....##....#....##..#.. +....#####.#....#......#.......# +.#.#.....##.####..#...#.......# +.#...##.#.......#.....##.#..##. +..........#...#....###....#...# +..#......#...#...#..#.#........ +.......#.......#..####..##..... +.#..#.....###...#...#...#...#.. +##..#.......#.#...#..#..#.##..# +#..#...#.#.....#.##.#........#. +......#......#.#..###.##..###.. +.#..#..#.##.#...........#...##. +.#....#...#.#..#.#.#...##.#..#. +##.#....#..#..#.#...#......#.#. +..#.#............##...#........ +...####...#...#.....##..#...### +....###.......###.##..#.###.... +#......#.#....#.#.##.#.##..###. +.....##.....#..##.....##....#.. +..#...#..##.#.##.#.#.#.......## +#....#..##.......#......#..#.## +#.....##...#..##......##.#.#..# +....#..##..#.##...#.#.##..#..## +#..#...##....##..#...#....#...# +.##.#.#....#.....#........##.#. +..##..#....#........#.....#.... +.##.#..##...#.....#...###.....# +#..#..#........#..#.....#.#.#.# +..##..###.#..#...#.#......#..#. +#.....#.....#.###......##..#.#. +.........#...##.........#...#.. +.##.#.##......#.#...###..#....# +...##.#..###........##......#.. +...#.#...#......#.#.#....#..#.. +..####.........#..#....#....... +#..#.........##.#.##....#.....# +..#..#..#.#........#.###....... +##.#..#..#....#...##.......#..# +..#.#.....#.............#...##. +..........#...##.....#..#.#..#. +....#..#...#..##..#...##.#..... +##....#......#..#.....#..#..... +...#.#.#.#...........##...#.#.. +....#.###...#............#..... +.#.#.#.......#.#......#....#.#. +#.#.#.#..##.#..#..##...##.#..#. +.#.##....##..#........#....#... +####...#....#.#...#..#..###...# +.....#.#.##.......##..#.######. +.......#.#.#.....#.#..##....#.. +..#....#.#..#.#.#..#..#........ +.....##......#.........#.#...## +#....##.#.....#..........#.#... +#...#.#..#.#..#.#....#..#.#.... +....##........#................ +###.#.#...#..##...#...#.##...#. +...#....###..#..##..#..#....... +.....#..........#.#........##.# +.#........#.##.#..##..#...#...# +..##....#...#.#.........##.#... +......#...#......#.....#....... +....##.##..#.##...#.#.#.##.#.#. +..#...#.....#.#....##.#........ +.#.#.......#.......###..#..#... +#...#..#..#..##....#...#.....#. +.#..####.##.....##.........#.#. +#...###.......#...####..##..... +#.##.#....#.#.##.......#...#... +..#.......#.#.##.##..#...##.... +.#.......#.#..#.....#.....#.#.. +..#..#.......##.....#.#.....#.# +#...###..#..#..##...#.....#..## +......#................#....... +..#.....##..#.......#...#...##. +...##...####.#..#...#.......##. +..#...#..#...#...#..#..#####... +#..#...#....#....#...........#. +..#.......#..#.##...##..###...# +.#..#..#......##...#....#...... +...#..##....#..........#.....#. +###...#.#......#.#.....#.....## +#.#..#.....#........#.##.#.##.. +....#...#.....#..#.......#.#... +#.#...##....#..#.....#...#.#.#. +.#......#...##..#.......#...... +...#...#.#.#.###.#..#.#..#..... +###...#..###.#...#..##...####.. +.#.#.#..#........#..#......#..# +.#..#....#......#....#.#...#... +.##..........###...##.....#.#.. +.#...#.#.##.##..###.#...#..###. +......#......#......#.##......# +..#.##..#.#..#....##..##...#... +.#......#..#...##....#...#..... +.#.....#.##..........#..#...... +###.#..#.##..#..##...#..#...#.. +#.....###........#.#..##.#..... +.....#.......##.....##.....#.## +...##.#......####....##........ +..#..#..#....#.##.....##.####.. +...#..#....#.#..#.#..#.#.#..#.. +#..........#....#.#.#.#...#..#. +...####.##...#..#.......#.#..## +#........#..#.................. +.#..#....#.#.#..#..........#... +###...#....####....#......#..#. +#.........####..#..#........... +.....##..#..##.##.##.#..#.....# +.#..#.#.##..#..#.#.#.##.###.... +......##......#...#.##....#..#. +.#.#....#..#......#..#...###... +.##...#......##...###...#.#...# +.......#.#....#............#..# +.#..##.#.######...#...#......#. diff --git a/day03/src/main.rs b/day03/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..bde5bfac82304aa1e1fef420ca9d1ab0c8ad13f0 --- /dev/null +++ b/day03/src/main.rs @@ -0,0 +1,51 @@ +use std::fs::File; +use std::io::{self, prelude::*, BufReader}; + +fn count_trees(input: &Vec<Vec<bool>>, right: usize, down: usize) -> i64 { + let mut hit_trees = 0; + let mut cord_x = 0; + let mut cord_y = 0; + + while cord_y < input.len() { + if input[cord_y][cord_x] { + hit_trees += 1; + } + + cord_x = (cord_x + right) % input[cord_y].len(); + cord_y += down; + } + hit_trees +} + +fn main() -> io::Result<()> { + println!("Advent of Code 2020 – Day 3:"); + + let file = File::open("input.txt")?; + let reader = BufReader::new(file); + + let input = reader + .lines() + .map(|l| { + l.unwrap() + .chars() + .map(|c| c == '#') + .collect::<Vec<bool>>() + }) + .collect::<Vec<Vec<bool>>>(); + + + let answer = count_trees(&input, 3, 1); + + println!("Answer Part 1: {}", answer); + + let answer2 = count_trees(&input, 1, 1); + let answer3 = count_trees(&input, 5, 1); + let answer4 = count_trees(&input, 7, 1); + let answer5 = count_trees(&input, 1, 2); + + let product = answer * answer2 * answer3 * answer4 * answer5; + + println!("Answer Part 2: {}", product); + + Ok(()) +}