refactor: some stuff
This commit is contained in:
parent
f1c0c453d3
commit
0a709e9309
15
src/day11.rs
15
src/day11.rs
@ -17,8 +17,8 @@ pub fn execute_task02(content: &str) {
|
||||
let command_steps = solve_02(content).unwrap();
|
||||
let duration = start.elapsed();
|
||||
|
||||
//assert_eq!(957, command_steps);
|
||||
println!("Day11 - Task02 - Duration: {duration:?} - SUm of closest million Points: {}", command_steps)
|
||||
assert_eq!(678728808158, command_steps);
|
||||
println!("Day11 - Task02 - Duration: {duration:?} - Sum of closest million Points: {}", command_steps)
|
||||
}
|
||||
|
||||
|
||||
@ -34,6 +34,10 @@ fn solve(content: &str, expansion: usize) -> anyhow::Result<usize> {
|
||||
let height = content.lines().count();
|
||||
let width = content.lines().next().unwrap().chars().count();
|
||||
|
||||
let mut empty_y: Vec<usize> = (0..height).collect();
|
||||
let mut empty_x: Vec<usize> = (0..width).collect();
|
||||
|
||||
// Find all Galaxies
|
||||
let mut galaxies = content
|
||||
.lines()
|
||||
.enumerate()
|
||||
@ -51,9 +55,8 @@ fn solve(content: &str, expansion: usize) -> anyhow::Result<usize> {
|
||||
)
|
||||
.collect::<Vec<(usize, usize)>>();
|
||||
|
||||
let mut empty_y: Vec<usize> = (0..height).collect();
|
||||
let mut empty_x: Vec<usize> = (0..width).collect();
|
||||
|
||||
// TODO move this shit in the first loop but ownership and move....
|
||||
galaxies
|
||||
.iter()
|
||||
.for_each(|(y, x)| {
|
||||
@ -61,13 +64,15 @@ fn solve(content: &str, expansion: usize) -> anyhow::Result<usize> {
|
||||
empty_x.retain(|value| *value != *x);
|
||||
});
|
||||
|
||||
// Expand all cords
|
||||
galaxies = galaxies
|
||||
.iter()
|
||||
.map(|(y, x)| {
|
||||
(y + (empty_y.iter().filter(|filler| filler < &y).count() * (expansion - 1)), x + (empty_x.iter().filter(|filler| filler < &x).count() * (expansion - 1)))
|
||||
(y + (empty_y.iter().take_while(|filler| filler < &y).count() * (expansion - 1)), x + (empty_x.iter().take_while(|filler| filler < &x).count() * (expansion - 1)))
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Calculate diff and sum them up
|
||||
Ok(galaxies.clone().iter()
|
||||
.combinations(2)
|
||||
.map(|data| (data[0], data[1]))
|
||||
|
Loading…
Reference in New Issue
Block a user