diff --git a/day5a/src/main.rs b/day5a/src/main.rs index fdc308b..292e713 100644 --- a/day5a/src/main.rs +++ b/day5a/src/main.rs @@ -4,16 +4,13 @@ use std::io::Read; fn main() { let mut input = String::new(); io::stdin().read_to_string(&mut input).unwrap(); - println!("{}", input - .lines() - .map(|x| x.chars().rev().map(|y| match y { - 'F' => 0, - 'B' => 1, - 'L' => 0, - 'R' => 1, - _ => 0, - }).enumerate().fold(0, |acc, x| acc + (x.1 << x.0))) - .max() - .unwrap() + println!("{}", + input + .lines() + .map(|l| l.bytes().fold(0, |a, b| a << 1 + | if b == b'B' || b == b'R' { 1 } else { 0 })) + .max() + .unwrap() + ); }