Part 1 solved
This commit is contained in:
parent
9b79bdeefa
commit
6aa3307d38
@ -23,18 +23,37 @@ impl LocationList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_dupes(&mut self) {
|
fn solve(&mut self) {
|
||||||
for (outer_pos, entry_outer) in self.left.iter().enumerate() {
|
self.left.sort();
|
||||||
for (inner_pos, entry_inner) in self.right.iter().enumerate() {
|
self.right.sort();
|
||||||
if entry_inner == entry_outer {
|
|
||||||
println!(
|
let mut nums = Vec::<i64>::new();
|
||||||
"Outer: {}, Inner: {}, O_Pos: {}, I_POS: {}",
|
for (pos, entry) in self.left.iter().enumerate() {
|
||||||
entry_outer, entry_inner, outer_pos, inner_pos
|
if entry > &self.right[pos] {
|
||||||
)
|
nums.push(entry - self.right[pos])
|
||||||
|
} else {
|
||||||
|
nums.push(self.right[pos] - entry)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let mut total = 0;
|
||||||
|
for num in nums {
|
||||||
|
total += num;
|
||||||
}
|
}
|
||||||
|
println!("{}", total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fn check_dupes(&mut self) {
|
||||||
|
// for (outer_pos, entry_outer) in self.left.iter().enumerate() {
|
||||||
|
// for (inner_pos, entry_inner) in self.right.iter().enumerate() {
|
||||||
|
// if entry_inner == entry_outer {
|
||||||
|
// println!(
|
||||||
|
// "Outer: {}, Inner: {}, O_Pos: {}, I_POS: {}",
|
||||||
|
// entry_outer, entry_inner, outer_pos, inner_pos
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for LocationList {
|
impl fmt::Debug for LocationList {
|
||||||
@ -66,5 +85,5 @@ fn main() {
|
|||||||
|
|
||||||
location_list.parse_data(data);
|
location_list.parse_data(data);
|
||||||
|
|
||||||
println!("{:?}", location_list.check_dupes());
|
location_list.solve();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user