day22 part1

This commit is contained in:
Johannes
2018-12-22 15:07:46 +01:00
parent 8badd4a416
commit d5aa1ddc74
3 changed files with 34 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
fn main() { fn main() {
aoc_2018::tasks::day20::task1(); aoc_2018::tasks::day22::task1();
// aoc_2018::tasks::day15::task2(); // aoc_2018::tasks::day15::task2();
} }

32
src/tasks/day22.rs Normal file
View File

@@ -0,0 +1,32 @@
pub fn task1() {
let depth: usize = 3879;
//let target: (usize, usize) = (8, 713);
const TARGET_X: usize = 8;
const TARGET_Y: usize = 713;
let mut map: Vec<Vec<usize>> = Vec::with_capacity(TARGET_X + 1);
let mut inner_vec = Vec::with_capacity(TARGET_Y + 1);
inner_vec.resize(TARGET_Y + 1, 0);
map.resize(TARGET_X + 1, inner_vec);
for x in 0..=TARGET_X {
for y in 0..=TARGET_Y {
let geo_index = match (x, y) {
(0, 0) => 0,
(TARGET_X, TARGET_Y) => 0,
(x, 0) => x * 16807,
(0, y) => y * 48271,
(x, y) => map[x - 1][y] * map[x][y - 1],
};
let erosion_index = (geo_index + depth) % 20183;
map[x][y] = erosion_index;
}
}
// println!("{:?}", map);
let result: usize = (0..=TARGET_X)
.map(|x| (0..=TARGET_Y).map(|y| map[x][y] % 3).sum::<usize>())
.sum();
println!("Sum of erosion indexes: {}", result);
}

View File

@@ -14,3 +14,4 @@ pub mod day13;
pub mod day14; pub mod day14;
pub mod day15; pub mod day15;
pub mod day20; pub mod day20;
pub mod day22;