day 3 solution
This commit is contained in:
parent
4a0f4584dd
commit
7321e315bd
9
2020/day_3/Cargo.toml
Normal file
9
2020/day_3/Cargo.toml
Normal file
@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "day_3"
|
||||
version = "0.1.0"
|
||||
authors = ["Ray Slakinski <ray.slakinski@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
323
2020/day_3/input1
Normal file
323
2020/day_3/input1
Normal file
@ -0,0 +1,323 @@
|
||||
........#....#..##..#...#.....#
|
||||
...............#....##........#
|
||||
.#....##...##..#...............
|
||||
.#.......#......#.##..##...#...
|
||||
.....#.#....#..##...#.....#....
|
||||
...#.#..##...###......#..#..#.#
|
||||
.....#..##........#.##......#..
|
||||
..##.....###.........##........
|
||||
..............##..#.#.#.#......
|
||||
.#....##..#.##.#....#..#.#..#..
|
||||
.#.#....#.##.#...#....#.....#..
|
||||
..#...#.#.....#....#.......##..
|
||||
.#.#..##.....#...........#.....
|
||||
.#.##...#.....#......#.##......
|
||||
..#..#..........#.....#..###.#.
|
||||
##....##....#.#...........#..#.
|
||||
.....#.#.......#.#.#..#.##....#
|
||||
...##.#....#..#.....#.........#
|
||||
.....#........#.##...#.........
|
||||
.....#................#.#...#..
|
||||
...#....##.....##....#.......#.
|
||||
....##.#.....#.#.......#.......
|
||||
#...............#..#...........
|
||||
.......###.#.......#.##....#.#.
|
||||
..#........###........#......#.
|
||||
.#.......#...##.....####....##.
|
||||
..##.#....#.....#..#....#......
|
||||
..#...#..#.#..##...#.....#.....
|
||||
.#.......###.......#....#......
|
||||
...#...#.......#........#...#.#
|
||||
..#....#...#.......#.#..##.....
|
||||
##............#.#..#..........#
|
||||
.......###...##..#.....#....#..
|
||||
##..######.#..#.......###....##
|
||||
###..#...#.##......##....#...#.
|
||||
..............##.###..........#
|
||||
.....#........##.#.###....#....
|
||||
..#...#.....##.#......#.#..#.#.
|
||||
#....#.............#.#.........
|
||||
.........##.#........#...#.....
|
||||
..........#..##.#.#.....#..##..
|
||||
........##......#..#..#...#.#..
|
||||
.##.......#..#.#...#.####..#...
|
||||
##...#........#.###...##....#..
|
||||
....###.####...#..#..#......###
|
||||
#....#....#.#.....##.........#.
|
||||
#.......#....#....##...........
|
||||
##...##.#.......#....#...#....#
|
||||
....#....#........##..#.#..#.#.
|
||||
..##.....##...#..........#...#.
|
||||
.#.#.#...#.....##..#........#..
|
||||
#....#.....#..........#....#...
|
||||
...##.#.......#.#.........#....
|
||||
##.##.........##.....##.....##.
|
||||
##.#..##..#...##........##.....
|
||||
.........##.......#....#...#...
|
||||
.#.....#........####.#.#.....#.
|
||||
...........##..#.###...........
|
||||
..#....##....#...#.............
|
||||
#.#............#.......#.......
|
||||
.##........#...#..##.....#.#...
|
||||
#.##..............##..##.......
|
||||
##.........#......#......#..#..
|
||||
##.#....#...#....##....#..#.##.
|
||||
......#...#..#.#...#.#....#.##.
|
||||
##.......#.....#.........#.....
|
||||
...##...#................#.#...
|
||||
....#.####...#.#.....##....##.#
|
||||
#...#..#.#.##................##
|
||||
.........##.....##...#..#......
|
||||
......####....#.##.#.....#.....
|
||||
...#..#.#....#.#.#..#..........
|
||||
.....#........##...#.##....#.#.
|
||||
..##......#...................#
|
||||
.....#..#...............#..#...
|
||||
....#........#..#.#...##...#.##
|
||||
..#.#.......#.##.........#...#.
|
||||
...##......#.#.................
|
||||
.#....#...#.............##.#...
|
||||
........#.##...#..#...###.....#
|
||||
#....#.#........##....#......##
|
||||
.###.......#..#..........#..#..
|
||||
#....#..#....#........#...#...#
|
||||
##.#.###.##.#...##.#......#.#.#
|
||||
#..#..#..##........#..###.#...#
|
||||
....#..#..#.....#...##....#...#
|
||||
.......##.......#..#.##...##..#
|
||||
.##....#..###................##
|
||||
#...#.##.##...#.##......##.....
|
||||
...##.....##..##...#..#........
|
||||
...............##.....##.......
|
||||
.#..#.#..#....#.....#..#...#...
|
||||
.#....#..#........#.#...#.....#
|
||||
##.....####..#......#..........
|
||||
........#.........#.........#..
|
||||
#...####....#.##...#....#...##.
|
||||
.#....####..#...##..#......####
|
||||
...........##.##..#.##...##....
|
||||
..#..#.......#.##....#.#...#.##
|
||||
#...........#..#...............
|
||||
.......#.##..#.....##......#...
|
||||
....##.#.##.....#...........#.#
|
||||
.............#.##..#...#......#
|
||||
#......#...........#........#..
|
||||
#.#..#.............#...#.......
|
||||
#.........##...#....#...##.....
|
||||
##...#..#..#..#....#...........
|
||||
.#.....#........#.....#.##..#.#
|
||||
...#..............##.####.#..#.
|
||||
##.....#..#.#..#..##...........
|
||||
...#...#.......#...............
|
||||
..#..................###..#..##
|
||||
....###..........#.#..#...#.#.#
|
||||
..#..#..#.#..........#.#......#
|
||||
....#....#.#...#.###...##..#...
|
||||
....#.......#...#....##........
|
||||
.#.....#.......###....#........
|
||||
....#..#..#.....#......#.......
|
||||
......#...#..#....#.#.......#..
|
||||
.##.#..#...#.#.#...........#...
|
||||
..#....##.#....#.#....#...#.#.#
|
||||
...##..#.......#....#.#.....##.
|
||||
##.#......#.#.......##...#.....
|
||||
......#...#.##..............#..
|
||||
.##.........#......##.#..#....#
|
||||
#.......#.....#...##...#..#...#
|
||||
..#..##.......#......#......##.
|
||||
#..##...###.#.#...........#....
|
||||
##......#.....####..#..#....#.#
|
||||
.......##...##.#...#...........
|
||||
....#..#.##.#.....#.#....#.#...
|
||||
....#.....#.....####...#..#.##.
|
||||
.##..#..#..###...#....#.##.#.#.
|
||||
..#.#.##..........##...........
|
||||
#.##.#.#....#.##....#..#...##.#
|
||||
#...#....#...###....#.......#..
|
||||
.......#..#............#.......
|
||||
................##.#.#.....#..#
|
||||
..........................#....
|
||||
.##....##...#.#....####..#....#
|
||||
......#...#....#...#.##..###.#.
|
||||
.........#............#.......#
|
||||
.#.#..#........#..#.........#..
|
||||
#..#...#......#.#....#..#.#....
|
||||
...........#.................#.
|
||||
.#.#..#...##..###......##....##
|
||||
.#.#.##......####.........##...
|
||||
..#....#.#..#................#.
|
||||
##.......#....#.........##.#.#.
|
||||
##..#.###...........#..#.#..#.#
|
||||
...#............##.#....#......
|
||||
...#................##.#..#....
|
||||
....#..##.#...#.#.....#.......#
|
||||
......#......#.#........#..##..
|
||||
...##...#.....#.##.......#.....
|
||||
##...#...#.............#..#....
|
||||
..#...##.....#..........#..#.##
|
||||
#.##...#..................#.###
|
||||
.........#..........#.###...#.#
|
||||
#..#.....#.#.#....#......#...#.
|
||||
.............#.##..###.....#.##
|
||||
..#..#.....#..#.............#..
|
||||
.#.....##.#.#..#.........#.....
|
||||
..#.......#....#.....##.#......
|
||||
.#.........#..#....##...#.##...
|
||||
.##..##................###....#
|
||||
.#..##..............#...#......
|
||||
.#..............#.##....##.....
|
||||
.#......#..#..##..#...###.....#
|
||||
................##...#.#..#...#
|
||||
##.#.......#...................
|
||||
....#.#.......#..#.##..........
|
||||
....###............##...#......
|
||||
.......#....#.#.....##.#.....#.
|
||||
....#...............#.#........
|
||||
..#.##....#.#.#......##..#.....
|
||||
.##......#...#.#..#..#.......#.
|
||||
....#...#........#.#..##.......
|
||||
.##...###.#....#..........##..#
|
||||
..#.......##..#.....###......#.
|
||||
...#.#..##.#.#...........#.....
|
||||
##........#.#..##.........#..#.
|
||||
.....###.......#..#.#.....##.#.
|
||||
..#...##.#..............#......
|
||||
......#...#...............##.#.
|
||||
##...#..#....#...#.####.##.....
|
||||
...#............#.##...........
|
||||
...#........##.#.##.......#....
|
||||
...#..#..##....#...#......#..#.
|
||||
#.....#..#......#.#.....##.#.#.
|
||||
.....#.##......#...#..#..###..#
|
||||
...........##..##.#.#..........
|
||||
...#........##........##..##.#.
|
||||
......###...#.....#..###.#..#..
|
||||
#.....#.#....#...##....##.....#
|
||||
.##....#......#.....#.#..##.##.
|
||||
##....###.......#...##.......##
|
||||
...##......#....###............
|
||||
..#...#...#.#..#..........##.#.
|
||||
#.#.###...#..#.....#....#.###..
|
||||
..##.....#.#.#.......#.........
|
||||
...####..#....#..#.........#...
|
||||
.##...........#.##.#...#.#.##..
|
||||
...#.#....#.##......#........#.
|
||||
##....##....#..#...#..#.#......
|
||||
#......#..#...#...#.#.#.#.####.
|
||||
....##.#.#.....#.###........#..
|
||||
....##..#.#.#.#....#....#.#..#.
|
||||
..#.###..#............##..#.#..
|
||||
...#...#..#...#.#.#.....#.....#
|
||||
..........#.....#..#.......##.#
|
||||
..............##...........#...
|
||||
.......#.....#...#.....#.....#.
|
||||
.#.###.....##......##....#...#.
|
||||
.....#.........#.#....#........
|
||||
..#.#....#.##...#.##....##...#.
|
||||
...#......#.#.....#.......###..
|
||||
#.##....##.....#.#.#...#......#
|
||||
#..#...#..........#.........##.
|
||||
....#.#.#.#.....#...###........
|
||||
#.#..#...#......#...#.##...####
|
||||
.#...#......#....##...#........
|
||||
..#.........#............#...#.
|
||||
##......#..#...#....#.##....#..
|
||||
.#...##..#..##.#.#.#........#.#
|
||||
.##.........###...#......#..###
|
||||
...##.....##..#.#.........#....
|
||||
...........##........#...#.....
|
||||
..##..#...#..#..#.....#......#.
|
||||
..#..#.#....#.....#..#.##...#..
|
||||
#....#........##..........#.###
|
||||
......#...#...#....#...##.#....
|
||||
...#......#.#.....##......##...
|
||||
#....#..##............#....#.#.
|
||||
...#...##.#..........##........
|
||||
......#.###......#...#.#.......
|
||||
..................#.##..#..#..#
|
||||
....#.....#...#.....#...#....#.
|
||||
.#....##.#..#..#.....###.##...#
|
||||
#.......#..#....##.##.#.....##.
|
||||
..##........##...#.....#....##.
|
||||
#.........#...........##.#.....
|
||||
.#....#.#...##..###..........#.
|
||||
....##..##....####...#......#..
|
||||
##.##..#..#....#....####...#...
|
||||
..#...............#.##.........
|
||||
...#.#....#..#....#......#.....
|
||||
.#..#...#........#...#.....##..
|
||||
#.....###.......#.....#........
|
||||
...#.##..#.......#....#........
|
||||
....##..###.##...#.#....#.#....
|
||||
#.####...#.......#.....#.#....#
|
||||
#.......#......#.......#.#.#...
|
||||
##....#......#..#...#..#..####.
|
||||
.##.....#........#..#...#......
|
||||
#.#.#....#....#...#.##..##.....
|
||||
....#..#.........###.##.##.....
|
||||
...##...##.###..#..##.....#.###
|
||||
..###.......................#..
|
||||
......##..#.#.........#......#.
|
||||
.###......##....#.....#.......#
|
||||
.....#..#..##........#......##.
|
||||
..##.....#....#.#.............#
|
||||
..##.........##.#..#.........##
|
||||
......#......#.#......#........
|
||||
.#...#..#......##...#..#....#..
|
||||
...............###............#
|
||||
#.####.#....#...#...........#.#
|
||||
............................#.#
|
||||
.#..#...#.#.#.###..##.....##...
|
||||
....##...#.................##..
|
||||
......##....#...............##.
|
||||
.#......#.##.#..#.....##...##..
|
||||
.............#........#......#.
|
||||
#..........#.#....#####.#...#.#
|
||||
.#.#...##..#.#...#.#..#.#..#...
|
||||
#.##.......##......#.#.#....#..
|
||||
##.....##.#.#.##..........##..#
|
||||
....##..#.#.......#....#.##....
|
||||
..#.#.#...#.....#.......#......
|
||||
.#....#..#...........###.......
|
||||
#.#...#.....#......#...#.....#.
|
||||
#........#.#..........#...#.#..
|
||||
...#...#....#.........#........
|
||||
.....................#..##.....
|
||||
...#......##........#.##.#.#.##
|
||||
.............###...#.#...#..#..
|
||||
.#..##........##....#...###..##
|
||||
.#..#.#...............#.....##.
|
||||
...........##.#....#..##.#....#
|
||||
.##.#.#..#.#..#...#.#.#..#.#.##
|
||||
.......#.#..#..#..#..#...#.....
|
||||
.#......##............#.#..#...
|
||||
..#...#..##..#..#...##......#..
|
||||
...##......##....#............#
|
||||
.......#.....##...##.#...#..#..
|
||||
......#.......#..##.........#..
|
||||
..#...#.#.....#.#.......#.#...#
|
||||
.#......##.##.#.#.#.##..#....##
|
||||
#.....#.........#.#....#....##.
|
||||
.......#.........#....#..#.#.##
|
||||
.....##....#..#.#.#...#.....##.
|
||||
#####.#.......######......#....
|
||||
..##.#.......#.#..............#
|
||||
..#.##....#.....#...#.#...##...
|
||||
.....#...#..#....#.#..#........
|
||||
.#....#.#..#.#.#.##..#.......#.
|
||||
....#..#..#..........##...#....
|
||||
.......#.#......#........#.....
|
||||
##.#.#.###....##.#..#..#....#..
|
||||
#.##......#..#.......#.#...#...
|
||||
..##...#.......#.......#...#...
|
||||
........##.........#.#....#.#..
|
||||
..#...#..##.#.#.#...#....#.....
|
||||
.###......#........#....#...#..
|
||||
.#.......##......###..##.......
|
||||
#....#.#....#.##.........####..
|
||||
......#..........#..##.....#...
|
||||
.............#......#..##.#....
|
||||
...................#....#...#..
|
||||
.#..........#...#.#..##...#....
|
||||
.....#...#..........##.##......
|
||||
#...#..#.##........#...#.......
|
37
2020/day_3/src/main.rs
Normal file
37
2020/day_3/src/main.rs
Normal file
@ -0,0 +1,37 @@
|
||||
fn main() {
|
||||
let mut hill: Vec<String> = Vec::new();
|
||||
let contents = std::fs::read_to_string("input1").unwrap();
|
||||
for s in contents.lines() {
|
||||
hill.push(s.parse::<String>().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);
|
||||
}
|
11
2020/day_3/test
Normal file
11
2020/day_3/test
Normal file
@ -0,0 +1,11 @@
|
||||
..##.......
|
||||
#...#...#..
|
||||
.#....#..#.
|
||||
..#.#...#.#
|
||||
.#...##..#.
|
||||
..#.##.....
|
||||
.#.#.#....#
|
||||
.#........#
|
||||
#.##...#...
|
||||
#...##....#
|
||||
.#..#...#.#
|
Reference in New Issue
Block a user