Created
December 16, 2019 20:01
-
-
Save 0e4ef622/2cddd47b5fcda28898b76807635c4161 to your computer and use it in GitHub Desktop.
day 16 phase calculator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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