summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2016-12-22 19:32:32 +0200
committerJustin Worthe <justin.worthe@gmail.com>2016-12-22 19:32:32 +0200
commit94367f2f07eff977101900fa68a3a04986d2a4d5 (patch)
tree5fad00c0962917fc256698844e40d275c7f7bf9e
parent2f2c1fe8e23e353ac97e1c7d250f587dbe1ba1c2 (diff)
AOC part 2
The trick is to round to the nearest 100, so states can be considered 'equivalent' through multiple paths.
-rw-r--r--aoc22/src/main.rs38
1 files changed, 12 insertions, 26 deletions
diff --git a/aoc22/src/main.rs b/aoc22/src/main.rs
index c07d628..bd374d5 100644
--- a/aoc22/src/main.rs
+++ b/aoc22/src/main.rs
@@ -76,32 +76,7 @@ impl Grid {
next_col.push(node);
}
grid_nodes.push(next_col);
-
- for x in 0..grid_nodes.len() {
- for y in 0..grid_nodes[x].len() {
- let mut is_blocker = true;
- if x > 0 && grid_nodes[x-1][y].size >= grid_nodes[x][y].used {
- is_blocker = false;
- }
- if x < grid_nodes.len()-1 && grid_nodes[x+1][y].size >= grid_nodes[x][y].used {
- is_blocker = false;
- }
- if y > 0 && grid_nodes[x][y-1].size >= grid_nodes[x][y].used {
- is_blocker = false;
- }
- if y < grid_nodes[x].len()-1 && grid_nodes[x][y+1].size >= grid_nodes[x][y].used {
- is_blocker = false;
- }
- grid_nodes[x][y].blocker = is_blocker;
- }
- }
- for x in 0..grid_nodes.len() {
- for y in 0..grid_nodes[x].len() {
- grid_nodes[x][y].size = if grid_nodes[x][y].blocker { 2 } else { 1 };
- grid_nodes[x][y].used = if grid_nodes[x][y].used > 0 { grid_nodes[x][y].size } else { 0 };
- grid_nodes[x][y].avail = grid_nodes[x][y].size - grid_nodes[x][y].used;
- }
- }
+ grid_nodes = Grid::normalize(grid_nodes);
Grid {
nodes: grid_nodes,
@@ -110,6 +85,17 @@ impl Grid {
}
}
+ fn normalize(mut nodes: Vec<Vec<Node>>) -> Vec<Vec<Node>> {
+ for x in 0..nodes.len() {
+ for y in 0..nodes[x].len() {
+ nodes[x][y].size = ((nodes[x][y].size + 50)/100) * 100;
+ nodes[x][y].used = ((nodes[x][y].used + 50)/100) * 100;
+ nodes[x][y].avail = ((nodes[x][y].avail + 50)/100) * 100;
+ }
+ }
+ nodes
+ }
+
fn is_final(&self) -> bool {
self.goal_x == 0 && self.goal_y == 0
}