add bounding area score to solution results
This commit is contained in:
parent
997297ab68
commit
157ee0de51
5 changed files with 60 additions and 7 deletions
|
@ -123,6 +123,48 @@ impl Grid {
|
|||
sum
|
||||
}
|
||||
|
||||
pub fn used_bounds_area(&self) -> usize {
|
||||
let row_clear = |a, max, f: fn(usize, usize) -> (usize, usize)| {
|
||||
for b in 0..max {
|
||||
if !self.get_unchecked(f(a, b).into()).is_blank() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
};
|
||||
let mut height = self.height;
|
||||
for y in 0..self.height {
|
||||
if row_clear(y, self.width, |y, x| (x, y)) {
|
||||
height -= 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for y in (0..self.height).rev() {
|
||||
if row_clear(y, self.width, |y, x| (x, y)) {
|
||||
height -= 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let mut width = self.width;
|
||||
for x in 0..self.width {
|
||||
if row_clear(x, self.height, |x, y| (x, y)) {
|
||||
width -= 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
for x in (0..self.width).rev() {
|
||||
if row_clear(x, self.width, |x, y| (x, y)) {
|
||||
width -= 1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
width * height
|
||||
}
|
||||
|
||||
fn in_bounds(&self, p: Pos) -> bool {
|
||||
p.x >= 0 && p.y >= 0 && p.x < self.width as PosInt && p.y < self.height as PosInt
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue