working 15part2, but slower
This commit is contained in:
parent
f2ad6c7ad8
commit
84fce2b379
1 changed files with 4 additions and 3 deletions
|
@ -52,6 +52,7 @@ impl Map {
|
||||||
|
|
||||||
fn walk(&mut self, start: &XY, computer: &intcode::Computer, steps: usize) -> Option<usize> {
|
fn walk(&mut self, start: &XY, computer: &intcode::Computer, steps: usize) -> Option<usize> {
|
||||||
let steps = steps + 1;
|
let steps = steps + 1;
|
||||||
|
let mut result = None;
|
||||||
for dir in 1..=4 {
|
for dir in 1..=4 {
|
||||||
let direction = Direction::from(dir);
|
let direction = Direction::from(dir);
|
||||||
let xy = start.add((&direction).into());
|
let xy = start.add((&direction).into());
|
||||||
|
@ -66,17 +67,17 @@ impl Map {
|
||||||
match status {
|
match status {
|
||||||
Status::HitWall => (),
|
Status::HitWall => (),
|
||||||
Status::MoveComplete => match self.walk(&xy, &computer, steps) {
|
Status::MoveComplete => match self.walk(&xy, &computer, steps) {
|
||||||
Some(i) => return Some(i + 1),
|
Some(i) => result = Some(i + 1),
|
||||||
None => (),
|
None => (),
|
||||||
},
|
},
|
||||||
Status::Finished => return Some(1),
|
Status::Finished => result = Some(1),
|
||||||
_ => unreachable!("unknown status"),
|
_ => unreachable!("unknown status"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unreachable!("computer unexpectedly halted");
|
unreachable!("computer unexpectedly halted");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fill(&mut self) -> usize {
|
fn fill(&mut self) -> usize {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue