Cleaner Day2

This commit is contained in:
Sebastian 2021-12-02 20:17:07 +01:00
parent 3b7d3c5462
commit 34fd8b3639
1 changed files with 3 additions and 10 deletions

View File

@ -27,16 +27,9 @@ fn main() -> Result<(), Box<dyn Error>> {
println!("Answer1: {}", pos.0 * pos.1);
let mut aim = 0;
let mut pos = (0, 0);
for m in moves.iter() {
aim = aim + m.1;
println!("{} {}", m.0, m.1);
pos = (pos.0 + m.0, pos.1 + m.0 * aim);
println!("{} {}", pos.0, pos.1);
}
let pos = moves.iter().fold((0, 0, 0), |(x, y, aim), (mx, maim)| {
(x + mx, y + mx * (maim + aim), aim + maim)
});
println!("Answer2: {}", pos.0 * pos.1);