Clean up Day 21
This commit is contained in:
@@ -106,18 +106,18 @@ fn bfs(plot: &Plot) -> Vec<u64> {
|
||||
distance += 1;
|
||||
}
|
||||
|
||||
return distances;
|
||||
distances
|
||||
}
|
||||
|
||||
fn interpolate(x0: usize, mut ys: [i64; 4], x: usize) -> Option<i64> {
|
||||
assert!(x >= x0);
|
||||
if x <= x0 + 3 {
|
||||
Some(ys[(x - x0) as usize])
|
||||
Some(ys[x - x0])
|
||||
} else {
|
||||
let mut f = [0; 4];
|
||||
|
||||
for i in 0..4 {
|
||||
f[i] = ys[0];
|
||||
for coef in &mut f {
|
||||
*coef = ys[0];
|
||||
for i in 0..ys.len() - 1 {
|
||||
ys[i] = ys[i + 1] - ys[i];
|
||||
}
|
||||
@@ -125,7 +125,7 @@ fn interpolate(x0: usize, mut ys: [i64; 4], x: usize) -> Option<i64> {
|
||||
|
||||
let xa = (x - x0) as i64;
|
||||
let xb = xa * (x - x0 - 1) as i64;
|
||||
(f[3] == 0).then_some(f[0] + f[1] * xa as i64 + f[2] * xb / 2)
|
||||
(f[3] == 0).then_some(f[0] + f[1] * xa + f[2] * xb / 2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ fn main() -> Result<()> {
|
||||
assert!(plot.height == plot.width);
|
||||
let side_length = width;
|
||||
let required_scale =
|
||||
|step_count| (step_count - plot.start.0 as usize + side_length) / side_length;
|
||||
|step_count| (step_count - plot.start.0 + side_length) / side_length;
|
||||
|
||||
let offset = STEPS_P2 % side_length;
|
||||
let max_scale = required_scale(STEPS_P2);
|
||||
@@ -168,8 +168,8 @@ fn main() -> Result<()> {
|
||||
|
||||
plot.scale_to(scale0 + 3);
|
||||
let distances = bfs(&plot);
|
||||
for i in 0..4 {
|
||||
sequence[i] = positions(&distances, (offset + i * side_length) as u64) as i64;
|
||||
for (i, seq) in sequence.iter_mut().enumerate() {
|
||||
*seq = positions(&distances, (offset + i * side_length) as u64) as i64;
|
||||
}
|
||||
|
||||
let mut n = 0;
|
||||
|
||||
Reference in New Issue
Block a user