reformatting

This commit is contained in:
kageru 2020-12-15 10:57:59 +01:00
parent c95653f24d
commit c339f51ec5

View File

@ -12,17 +12,16 @@ fn parse_input(raw: &str) -> Parsed {
raw.split(',').filter_map(|x| x.parse().ok()).collect() raw.split(',').filter_map(|x| x.parse().ok()).collect()
} }
fn part1(parsed: &Parsed, limit: usize) -> usize { #[rustfmt::skip]
(parsed.len()..limit - 1) fn part1(initial: &Parsed, limit: usize) -> usize {
.fold( (initial.len()..limit - 1).fold(
(parsed.iter().enumerate().map(|(i, n)| (*n, i)).collect::<HashMap<_, _>>(), 0), (initial.iter().enumerate().map(|(i, n)| (*n, i)).collect::<HashMap<_, _>>(), 0),
|(mut prev, curr), i| { |(mut prev, curr), i| {
let next = prev.get(&curr).map(|p| i - p).unwrap_or(0); let next = prev.get(&curr).map(|p| i - p).unwrap_or(0);
prev.insert(curr, i); prev.insert(curr, i);
(prev, next) (prev, next)
}, },
) ).1
.1
} }
// only here so the test/bench macro works // only here so the test/bench macro works