Cleaner Day2
This commit is contained in:
parent
3b7d3c5462
commit
34fd8b3639
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue