Skip to content
Snippets Groups Projects
Commit 0c683379 authored by Philip Molares's avatar Philip Molares :popcorn:
Browse files

added day03

parent 06f4fd9d
No related branches found
No related tags found
No related merge requests found
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "day03"
version = "0.1.0"
[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]
i......#..........##......#.####
.##...###....#.....#...#.#.....
#..##..#.....#............#.#.#
##.#....#####..#....#..#.#.....
..#.#...##.##.......#.#..#..##.
##.#.......#.#.#..#...#.#...#..
...#...#..#.##....##..#.#......
.......##.#.#.#.##...#.........
..#...##.##...##..##.##...#....
.#.#...#.....####..#.#...#.##..
.#...#......##......##....#....
..#.....#.........##.#...#.#...
...#.#...#..##...#....#.....##.
..#.....#..#..#......###.......
...##.#....##..##...........#..
....#......#..#....###...#.....
.....#...#.#.....#..##........#
....#...#....##.#.##.#...#..#.#
.......##.#......##....#....#..
...#.#...##..#...#..#..#..##.#.
##.#...#..#..................##
##........#....##...#..#..#....
.#.#..............#######.##...
##..#..#.#.##..#...............
..#........#..#...##.......#...
............##.##.#..........##
.....##..#.....##..#.....#.....
..#.##.###.#..##.............#.
.........##...........#.....#..
..#....#.#.###.#.#.......##....
..###..##..#.#.##......#.#.##..
##......#.#....##.#..#.#..#.#.#
..##.#.###.#...#...............
..####.......#...#.##....#.....
..#....##...#.#.#.#....#.##..##
.#...####..###....#.###...##...
..#.#..........#.#..#..#.....##
.#....#.........###...#.....##.
..#.#.#.##........#.##.#.....#.
#....#....###...#..#.........#.
#..#.###....#..............#...
............#....##.#......#.#.
...#..#.####...............##..
....##......#.#.........####..#
.#....###..#.#..##........##...
#..##.....###..#...............
..#...........#........#...#..#
......................#.#..#...
.#.##.#..#.#....#...#...#.#....
..#..#.........#..#.#..........
.#......#####...#......#..#....
..........#.....#..#.##.####.##
##.##..#............#####...#.#
..##..#..###......#...#...#....
....#####........#.##...###....
......#...##..#..#............#
...#....##.##...#..#...#.......
....#####.#...............###..
.#....#..##....#.#.#..##.##...#
...#..#..#........#.#####.....#
......##.#...#..#..#.....#..###
###.......#.#........#......#.#
..#.#..#..#........#..#......#.
...##.........#..........#.....
...#..###.#.......#.#.........#
....#..#.##...##.....#.....##..
#.#.#.#.....##.##.###..#.#....#
..#....#.....##.####..#........
...#..#.##.....##.#..#....###..
.#..#.....#....#...#.#.......##
..#..#.......#.#.###......#.##.
.###.####....##............##.#
#....###.#......##.#......##.#.
.##...........#.#....#.........
#.##..##...#...........###....#
#.#..#...#.#..#..###.#.##...#..
..#...#.#..##....#..#..#.......
#..##..#.####...#...#..####.##.
###..#.##....#...#.###..##...##
##..#..#.#....#.....##.......#.
..#..##.##.#.......###.#.....#.
..........#.####....#.......#..
#...#.#..#.......##......##..##
##...##.##..###...............#
....##.#...#.......##...##..#..
.#.........#...#.#...##.#.....#
.#...#.#..#...#..##....#..#...#
.#.#...#..#..###...##....#.....
.........#.#...####..#...#.#...
...#.............#.#..........#
...#...#..##.#........#.#......
...#...#.....#....#..###.##.###
.#.#........#....#...#.###.#.#.
##.....#.......#..##.#....#..##
...###...#.#.#.#....#.#....#...
#...#.#.......##.#..#....#.#...
#...#......###.....###........#
..#.##...##....#...#....#.#....
#....#..###....##.#......##...#
##.#...#..........#.##....#..#.
.##....#............###.#...#..
###.##.#####.##.....##..#####..
..###.###.......#.#...#....#...
.#...#....####.........#.......
..##.#.#......#....#.#....#.#.#
#.####.....#....#..#.....#.##..
###.###.##...##.#.#.#.....#.#..
.......#.....#.......##.#.....#
#..#.##...#........#.#.......##
#.#........#...#....#..........
..#....##.#......#..#..........
#....##.....#.....#.##.#...#...
....#.#.....#....####...#.#.##.
......#.......##...##.#......#.
.#.........##...#..#..##..#....
.#...##.....##.#....#..........
....#.###..##..#...#..........#
......#...#.#.#........##......
.#..........#.#.....#..##..#.#.
.......###.#......#....#.#..#..
..##.......#....#....#.#...##.#
#.##.#.......#..###..##...#.#..
......####....#.#.....#...#..#.
#.##.###..#..#.#.....###..#.#.#
#.#.#..#.#..##...#...#..##.###.
....##..##.#...............#.#.
..###.#.#.##..#....##.......#..
#.#....#..........##......#####
.#.#.......##.#.#......##..#.#.
......#.###.##.#..#....#.##....
..###........#.......##.#.#....
.#..##.............#.##.###...#
.#####...#......#.......##.....
##..###.#...#....#..#....#.#..#
.#.........###.##.....##.....##
.##.#....#..#.#..##..#....##...
.#..#..#......###...#.......#..
#.#...#.....#..#.#.#..#..###...
....#....#..#..#....#..#.#.#...
......#.......#.#.#.#.....#....
###...#...#......#..#.#.#..#.#.
#...##.##.##........##....#....
.....#.......#...#...#.#.#....#
...##.....##.#...#.#.#.#..#..#.
.#.......##...........#...#.##.
.##..........#......#.#...###..
.....##...#.....#...#......#...
...........#.....#..#...#..#.#.
#.....##..#...........##....#..
#.##...###.###....##..#..#....#
#.#.##...##....###....##.##....
.#..###.....#......#...#...#..#
..#...#....#.#.###.#..#......#.
......#.........#..#.##...#...#
..#.#....##.#..##..##...#....#.
#.....#....##.........##.#.....
...#...#..###.###......##...###
.##.###...##..#.##....##.#..#..
..#..#.......#................#
.....#..#.#.#..........##..#...
......###.#.#............#..#.#
..#.##.....##....#...#...#.#...
..#......##...#...##........#..
#.....#.....#..#......#.###...#
....#..#.#.....#...#....#.#...#
#.......#..#...##..#.#..#.##...
..#......###...#.........##...#
...#.......##.....#..##........
.#....#.#.....##.#.#...........
##..#..#...#.##.#.#.#.#.#..##.#
##...####.#.#.##...#..#......#.
#.##..####.##.#.........#...###
#...#.......#.#..####.#.#.#....
#....#........#........#.......
..#..####.....#....##...###.##.
...#.#..####.........#....#.##.
##.#...#...#..#.#..##.....##...
....#.........#.##........##.#.
##...#......#....#..#....#....#
###.....#......##...#...##...#.
#.##...............#.......#...
.##.#...#..#....#.#.....###..#.
.....##...#.##.....##...#....#.
#.#..#..........#####..##......
..#.........##...#.........#.##
...#..##.#.#..#......#..###.###
#..#...#.#...##..........#.....
.###..#....###.....#....#..###.
#..#....#...#........##.....#..
.#..###........#....#..####..##
.#..#.#.#.......##.#..##.#..##.
..#..###......##....#..#..#..#.
.......###..##....#......#...##
#........#.##.............##.#.
...#.#.#....##....##.###...#...
..#.....#..##..#.#.......#.####
.#......##.........##...#.....#
.#.###........##....###.#.#...#
##...#.#....#.....##.......#..#
#...........#...........####...
#..#.#..##..#...#....#.##....#.
................##.............
..##...#.#....##....#...#......
.#.....#....#....#..#..#.#..##.
.....######.#.#.##.###.#.......
..#####....#..#...........#.#..
.......#..#..##.#...###.#.#.###
###...#...#..##.#.##..#...#..#.
.#..#..............#...........
.#.....#.....##....#....##..#..
....#####.#....#......#.......#
.#.#.....##.####..#...#.......#
.#...##.#.......#.....##.#..##.
..........#...#....###....#...#
..#......#...#...#..#.#........
.......#.......#..####..##.....
.#..#.....###...#...#...#...#..
##..#.......#.#...#..#..#.##..#
#..#...#.#.....#.##.#........#.
......#......#.#..###.##..###..
.#..#..#.##.#...........#...##.
.#....#...#.#..#.#.#...##.#..#.
##.#....#..#..#.#...#......#.#.
..#.#............##...#........
...####...#...#.....##..#...###
....###.......###.##..#.###....
#......#.#....#.#.##.#.##..###.
.....##.....#..##.....##....#..
..#...#..##.#.##.#.#.#.......##
#....#..##.......#......#..#.##
#.....##...#..##......##.#.#..#
....#..##..#.##...#.#.##..#..##
#..#...##....##..#...#....#...#
.##.#.#....#.....#........##.#.
..##..#....#........#.....#....
.##.#..##...#.....#...###.....#
#..#..#........#..#.....#.#.#.#
..##..###.#..#...#.#......#..#.
#.....#.....#.###......##..#.#.
.........#...##.........#...#..
.##.#.##......#.#...###..#....#
...##.#..###........##......#..
...#.#...#......#.#.#....#..#..
..####.........#..#....#.......
#..#.........##.#.##....#.....#
..#..#..#.#........#.###.......
##.#..#..#....#...##.......#..#
..#.#.....#.............#...##.
..........#...##.....#..#.#..#.
....#..#...#..##..#...##.#.....
##....#......#..#.....#..#.....
...#.#.#.#...........##...#.#..
....#.###...#............#.....
.#.#.#.......#.#......#....#.#.
#.#.#.#..##.#..#..##...##.#..#.
.#.##....##..#........#....#...
####...#....#.#...#..#..###...#
.....#.#.##.......##..#.######.
.......#.#.#.....#.#..##....#..
..#....#.#..#.#.#..#..#........
.....##......#.........#.#...##
#....##.#.....#..........#.#...
#...#.#..#.#..#.#....#..#.#....
....##........#................
###.#.#...#..##...#...#.##...#.
...#....###..#..##..#..#.......
.....#..........#.#........##.#
.#........#.##.#..##..#...#...#
..##....#...#.#.........##.#...
......#...#......#.....#.......
....##.##..#.##...#.#.#.##.#.#.
..#...#.....#.#....##.#........
.#.#.......#.......###..#..#...
#...#..#..#..##....#...#.....#.
.#..####.##.....##.........#.#.
#...###.......#...####..##.....
#.##.#....#.#.##.......#...#...
..#.......#.#.##.##..#...##....
.#.......#.#..#.....#.....#.#..
..#..#.......##.....#.#.....#.#
#...###..#..#..##...#.....#..##
......#................#.......
..#.....##..#.......#...#...##.
...##...####.#..#...#.......##.
..#...#..#...#...#..#..#####...
#..#...#....#....#...........#.
..#.......#..#.##...##..###...#
.#..#..#......##...#....#......
...#..##....#..........#.....#.
###...#.#......#.#.....#.....##
#.#..#.....#........#.##.#.##..
....#...#.....#..#.......#.#...
#.#...##....#..#.....#...#.#.#.
.#......#...##..#.......#......
...#...#.#.#.###.#..#.#..#.....
###...#..###.#...#..##...####..
.#.#.#..#........#..#......#..#
.#..#....#......#....#.#...#...
.##..........###...##.....#.#..
.#...#.#.##.##..###.#...#..###.
......#......#......#.##......#
..#.##..#.#..#....##..##...#...
.#......#..#...##....#...#.....
.#.....#.##..........#..#......
###.#..#.##..#..##...#..#...#..
#.....###........#.#..##.#.....
.....#.......##.....##.....#.##
...##.#......####....##........
..#..#..#....#.##.....##.####..
...#..#....#.#..#.#..#.#.#..#..
#..........#....#.#.#.#...#..#.
...####.##...#..#.......#.#..##
#........#..#..................
.#..#....#.#.#..#..........#...
###...#....####....#......#..#.
#.........####..#..#...........
.....##..#..##.##.##.#..#.....#
.#..#.#.##..#..#.#.#.##.###....
......##......#...#.##....#..#.
.#.#....#..#......#..#...###...
.##...#......##...###...#.#...#
.......#.#....#............#..#
.#..##.#.######...#...#......#.
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(())
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment