Skip to content

Instantly share code, notes, and snippets.

@0e4ef622
Created December 16, 2019 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0e4ef622/2cddd47b5fcda28898b76807635c4161 to your computer and use it in GitHub Desktop.
Save 0e4ef622/2cddd47b5fcda28898b76807635c4161 to your computer and use it in GitHub Desktop.
day 16 phase calculator
fn next_phase(nums: &[i64], strt: usize) -> Vec<i64> {
let mut pfs = vec![0];
pfs.extend(nums);
for i in 1..pfs.len() {
pfs[i] += pfs[i-1];
}
let mut newl = Vec::with_capacity(nums.len());
for n in strt..nums.len()+strt {
let mut newn = 0;
let mut j = n;
while j < nums.len()+strt {
newn += pfs[(j+n-strt+1).min(pfs.len()-1)] - pfs[j-strt];
j += 4*(n+1);
}
let mut j = 2*(n+1)+n;
while j < nums.len()+strt {
newn -= pfs[(j+n-strt+1).min(pfs.len()-1)] - pfs[j-strt];
j += 4*(n+1);
}
newl.push(newn.abs() % 10);
}
newl
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment