mirror of
https://github.com/wezm/advent-of-code.git
synced 2024-12-18 18:29:55 +00:00
Day 3 part 2
This commit is contained in:
parent
bdf11def27
commit
7d282f886f
1 changed files with 13 additions and 0 deletions
|
@ -34,6 +34,19 @@ fn main() -> io::Result<()> {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
println!("Part 1: {}", result);
|
println!("Part 1: {}", result);
|
||||||
|
|
||||||
|
// Part 2, count steps (length of path)
|
||||||
|
// For each common point find it's position in each wire paths, that is the steps
|
||||||
|
let result = wire1
|
||||||
|
.intersection(&wire2)
|
||||||
|
.map(|point| {
|
||||||
|
paths[0].iter().position(|other| point == other).unwrap()
|
||||||
|
+ paths[1].iter().position(|other| other == point).unwrap()
|
||||||
|
+ 2 // to account for 0 based index
|
||||||
|
})
|
||||||
|
.min()
|
||||||
|
.unwrap();
|
||||||
|
println!("Part 2: {}", result);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue