summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--2018/src/day17.rs25
1 files changed, 15 insertions, 10 deletions
diff --git a/2018/src/day17.rs b/2018/src/day17.rs
index 3730e60..f920421 100644
--- a/2018/src/day17.rs
+++ b/2018/src/day17.rs
@@ -174,8 +174,9 @@ fn apply_patterns(grid: &mut Grid, (x, y): (i32, i32)) -> Vec<(i32, i32)> {
}
for dx in &[-1, 1] {
- // WP···PW -> W~···~W
- // W···W W···W
+ // if dx = 1:
+ // WP?···?W -> W~···~W where ? in {P, .}
+ // W····W W···W
if grid.get(x, y).produces() && grid.get(x, y+1).is_wall() && grid.get(x-dx, y).is_wall() {
let mut x2 = x + dx;
let make_still;
@@ -186,20 +187,20 @@ fn apply_patterns(grid: &mut Grid, (x, y): (i32, i32)) -> Vec<(i32, i32)> {
break;
}
- if !(grid.get(x2, y).produces() && grid.get(x2, y+1).is_wall()) {
+ if (grid.get(x2, y).produces() || grid.get(x2, y) == Cell::Sand) && grid.get(x2, y+1).is_wall() {
+ x2 += dx;
+ } else {
make_still = false;
break;
}
-
- x2 += dx;
}
if make_still {
- x2 = x;
- while !grid.get(x2, y).is_wall() {
- grid.set(x2, y, Cell::Still);
- res.push((x2, y-1));
- x2 += dx;
+ let mut x3 = x;
+ while x3 != x2 {
+ grid.set(x3, y, Cell::Still);
+ res.push((x3, y-1));
+ x3 += dx;
}
}
}
@@ -253,6 +254,10 @@ pub fn main<T: BufRead>(reader: T) -> io::Result<(String, String)> {
// inqueue.remove(&(x, y));
// let pos = (x, y);
+ if grid.get(pos.0, pos.1) == Cell::Still {
+ continue;
+ }
+
for &(x, y) in apply_patterns(&mut grid, pos).iter().filter(|&&(x, y)| grid.inrange(x, y)) {
let p = (-y, x);
// let p = (x, y);