Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jurisk committed Dec 10, 2024
1 parent f7258a5 commit 54cbf88
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 6 additions & 12 deletions rust/y2024/src/bin/solution_2024_09.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,21 @@ impl Disk {
head += 1;
tail -= 1;
} else if free_count < full_count {
let new_nodes = vec![
self.nodes[0 .. head].to_vec(),
let new_nodes = [self.nodes[0 .. head].to_vec(),
vec![Node::Full(free_count, file_id)],
self.nodes[head + 1 .. tail].to_vec(),
vec![Node::Full(full_count - free_count, file_id)],
self.nodes[tail + 1 ..].to_vec(),
]
self.nodes[tail + 1 ..].to_vec()]
.concat();
self.nodes = new_nodes;
} else if free_count > full_count {
let new_nodes = vec![
self.nodes[0 .. head].to_vec(),
let new_nodes = [self.nodes[0 .. head].to_vec(),
vec![
Node::Full(full_count, file_id),
Node::Free(free_count - full_count),
],
self.nodes[head + 1 .. tail].to_vec(),
self.nodes[tail + 1 ..].to_vec(),
]
self.nodes[tail + 1 ..].to_vec()]
.concat();
self.nodes = new_nodes;
}
Expand Down Expand Up @@ -122,13 +118,11 @@ impl Disk {
self.nodes[found_idx] = Node::Full(*count, *file_id);
self.nodes[pointer] = Node::Free(free);
} else if *count < free {
let new_nodes = vec![
self.nodes[0 .. found_idx].to_vec(),
let new_nodes = [self.nodes[0 .. found_idx].to_vec(),
vec![Node::Full(*count, *file_id), Node::Free(free - *count)],
self.nodes[found_idx + 1 .. pointer].to_vec(),
vec![Node::Free(*count)],
self.nodes[pointer + 1 ..].to_vec(),
]
self.nodes[pointer + 1 ..].to_vec()]
.concat();
self.nodes = new_nodes;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jurisk.adventofcode.y2024

import jurisk.geometry.{Coords2D, Field2D}
import jurisk.geometry.Coords2D
import jurisk.geometry.Field2D
import jurisk.utils.FileInput._

object Advent10 {
Expand Down

0 comments on commit 54cbf88

Please sign in to comment.