#![allow(non_upper_case_globals)] #![allow(unused_imports)] #![allow(dead_code)] use crate::prelude::*; pub type I = &'static str; pub type O = String; fn checksum (data: &str) -> String { data.chars().array_chunks().map(|[a, b]| if a == b { '1' } else { '0' }).collect() } fn _solve (data: I, disk: usize) -> O { let mut s = data.to_owned(); while s.len() < disk { s = format!("{}0{}", &s, s.chars().rev().map(|e| if e == '1' { '0' } else { '1' }).collect::()); } s = (&s[..disk]).to_owned(); let mut chk = checksum(&s); while chk.len() % 2 == 0 { chk = checksum(&chk); } chk } #[cfg(test)] mod test { use super::*; const input: &'static str = "01110110101001000"; #[test] fn silver () { let ans = _solve(input, 272); assert_eq!(ans, s!("11100111011101111")) } #[test] fn gold () { let ans = _solve(input, 35651584); assert_eq!(ans, s!("10001110010000110")) } }