Skip to content

Commit 13dbc8f

Browse files
committed
Introduce type for Robots
1 parent ee832a1 commit 13dbc8f

File tree

3 files changed

+6
-33
lines changed

3 files changed

+6
-33
lines changed

Cargo.lock

Lines changed: 0 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin/14.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ struct Robot {
1212
velocity: (i32, i32),
1313
}
1414

15+
type Position = (i32, i32);
16+
type Velocity = (i32, i32);
17+
type RobotType = (Position, Velocity);
18+
1519
pub fn part_one(input: &str) -> Option<usize> {
1620
let lines = input.lines().collect_vec();
1721
let regex = Regex::new(r"p=(-?\d+),(-?\d+) v=(-?\d+),(-?\d+)").unwrap();
@@ -51,7 +55,7 @@ pub fn part_one(input: &str) -> Option<usize> {
5155
let total = quadrants.values().product::<usize>();
5256
Some(total)
5357
}
54-
fn simulate_robots(robots: &[((i32, i32), (i32, i32))], t: i32) -> Vec<(i32, i32)> {
58+
fn simulate_robots(robots: &[RobotType], t: i32) -> Vec<(i32, i32)> {
5559
let max_x = 101;
5660
let max_y = 103;
5761

src/bin/15.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ enum Direction {
99
Right,
1010
}
1111

12-
#[warn(clippy::unnecessary_filter_map)]
1312
fn parse_movements(input: &str) -> Vec<Direction> {
1413
let movements: Vec<Direction> = input
1514
.lines()
@@ -20,7 +19,7 @@ fn parse_movements(input: &str) -> Vec<Direction> {
2019
'>' => Some(Direction::Right),
2120
'v' => Some(Direction::Down),
2221
'<' => Some(Direction::Left),
23-
_ => panic!("Invalid direction"),
22+
_ => None,
2423
})
2524
})
2625
.collect();

0 commit comments

Comments
 (0)