day10 part2
This commit is contained in:
parent
4984ad4801
commit
9fb5de6cac
@ -20,29 +20,33 @@ fn main() {
|
||||
}
|
||||
|
||||
let mut finished = false;
|
||||
let mut count = 1;
|
||||
|
||||
let mut first_pre = start_dirs[0].reverse();
|
||||
let mut second_pre = start_dirs[1].reverse();
|
||||
let mut first_pos = ((start.0 as i32 + start_dirs[0].to_ind().1) as usize, (start.1 as i32 + start_dirs[0].to_ind().0) as usize);
|
||||
let mut second_pos = ((start.0 as i32 + start_dirs[1].to_ind().1) as usize, (start.1 as i32 + start_dirs[1].to_ind().0) as usize);
|
||||
let mut pre = start_dirs[0].reverse();
|
||||
let mut pos = ((start.0 as i32 + start_dirs[0].to_ind().1) as usize, (start.1 as i32 + start_dirs[0].to_ind().0) as usize);
|
||||
|
||||
let mut the_loop = vec![start, pos];
|
||||
let mut area = 0;
|
||||
|
||||
while !finished {
|
||||
let first_next = &input[first_pos.0][first_pos.1].iter().filter(|x| x != &&first_pre).next().unwrap();
|
||||
first_pos = ((first_pos.0 as i32 + first_next.to_ind().1) as usize, (first_pos.1 as i32 + first_next.to_ind().0) as usize);
|
||||
first_pre = first_next.reverse();
|
||||
|
||||
let second_next = &input[second_pos.0][second_pos.1].iter().filter(|x| x != &&second_pre).next().unwrap();
|
||||
second_pos = ((second_pos.0 as i32 + second_next.to_ind().1) as usize, (second_pos.1 as i32 + second_next.to_ind().0) as usize);
|
||||
second_pre = second_next.reverse();
|
||||
|
||||
count += 1;
|
||||
finished = first_pos == second_pos;
|
||||
let first_next = &input[pos.0][pos.1].iter().filter(|x| x != &&pre).next().unwrap();
|
||||
pos = ((pos.0 as i32 + first_next.to_ind().1) as usize, (pos.1 as i32 + first_next.to_ind().0) as usize);
|
||||
pre = first_next.reverse();
|
||||
|
||||
finished = pos == start;
|
||||
the_loop.push(pos);
|
||||
}
|
||||
|
||||
|
||||
println!("{:?}", count)
|
||||
for win in the_loop.windows(2) {
|
||||
area += (win[0].1 * win[1].0) as i64;
|
||||
area -= (win[0].0 * win[1].1) as i64;
|
||||
}
|
||||
let area = i64::abs(area) / 2;
|
||||
|
||||
let spaces = area - (the_loop.len() as i64 / 2) + 1;
|
||||
|
||||
println!("{}", spaces)
|
||||
|
||||
}
|
||||
|
||||
fn parse_input(input: &String) -> Vec<Vec<Vec<Direction>>> {
|
||||
|
Loading…
Reference in New Issue
Block a user