Skip to content

Commit

Permalink
advent_of_code 2022-9: setup
Browse files Browse the repository at this point in the history
  • Loading branch information
msyfls123 committed Sep 3, 2023
1 parent 30d7494 commit 6dfa50d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions advent_of_code/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,7 @@ path = "src/aoc2022/7.rs"
[[bin]]
name = "2022-8"
path = "src/aoc2022/8.rs"

[[bin]]
name = "2022-9"
path = "src/aoc2022/9.rs"
50 changes: 50 additions & 0 deletions advent_of_code/src/aoc2022/9.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use itertools::{Itertools, assert_equal};

#[derive(Debug, Eq, PartialEq)]
enum Direction {
Left,
Right,
Up,
Down,
}

#[derive(Debug, Eq, PartialEq)]
struct Motion {
direction: Direction,
step: isize
}

fn parse_motion(text: &str) -> Motion {
let (dir, step) = text.split(" ").collect_tuple().unwrap();
let mut direction = Direction::Up;

Check warning on line 19 in advent_of_code/src/aoc2022/9.rs

View workflow job for this annotation

GitHub Actions / unit-test

value assigned to `direction` is never read
match dir {
"L" => {
direction = Direction::Left;
},
"R" => {
direction = Direction::Right;
},
"U" => {
direction = Direction::Up;
},
"D" => {
direction = Direction::Down
},
_ => panic!("no exists")
}
Motion { direction, step: step.parse::<isize>().unwrap() }
}

#[test]
fn test_parse_motion() {
assert_eq!(
parse_motion("R 50"),
Motion {
direction: Direction::Right,
step: 50
}
);
}

fn main() {
}

0 comments on commit 6dfa50d

Please sign in to comment.