Skip to content

Commit

Permalink
Introduce type for Robots
Browse files Browse the repository at this point in the history
  • Loading branch information
Mishco committed Dec 16, 2024
1 parent ee832a1 commit 13dbc8f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
30 changes: 0 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/bin/14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ struct Robot {
velocity: (i32, i32),
}

type Position = (i32, i32);
type Velocity = (i32, i32);
type RobotType = (Position, Velocity);

pub fn part_one(input: &str) -> Option<usize> {
let lines = input.lines().collect_vec();
let regex = Regex::new(r"p=(-?\d+),(-?\d+) v=(-?\d+),(-?\d+)").unwrap();
Expand Down Expand Up @@ -51,7 +55,7 @@ pub fn part_one(input: &str) -> Option<usize> {
let total = quadrants.values().product::<usize>();
Some(total)
}
fn simulate_robots(robots: &[((i32, i32), (i32, i32))], t: i32) -> Vec<(i32, i32)> {
fn simulate_robots(robots: &[RobotType], t: i32) -> Vec<(i32, i32)> {
let max_x = 101;
let max_y = 103;

Expand Down
3 changes: 1 addition & 2 deletions src/bin/15.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ enum Direction {
Right,
}

#[warn(clippy::unnecessary_filter_map)]
fn parse_movements(input: &str) -> Vec<Direction> {
let movements: Vec<Direction> = input
.lines()
Expand All @@ -20,7 +19,7 @@ fn parse_movements(input: &str) -> Vec<Direction> {
'>' => Some(Direction::Right),
'v' => Some(Direction::Down),
'<' => Some(Direction::Left),
_ => panic!("Invalid direction"),
_ => None,
})
})
.collect();
Expand Down

0 comments on commit 13dbc8f

Please sign in to comment.