Rust Day 2 - Handle crlf line endings
This commit is contained in:
parent
747e69fbfb
commit
8ad6df2ab6
1 changed files with 5 additions and 2 deletions
|
@ -125,11 +125,12 @@ impl FromStr for GameResult {
|
||||||
|
|
||||||
fn parse_input_part_1() -> Vec<[Shape; 2]> {
|
fn parse_input_part_1() -> Vec<[Shape; 2]> {
|
||||||
INPUT
|
INPUT
|
||||||
.split('\n')
|
.lines()
|
||||||
.map(|round_string| {
|
.map(|round_string| {
|
||||||
let round = round_string
|
let round = round_string
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.map(|play| {
|
.map(|play| {
|
||||||
|
assert_eq!(play.len(), 1, "play: {play}");
|
||||||
Shape::from_str(play).unwrap_or_else(|_| panic!("Found invalid play {play}"))
|
Shape::from_str(play).unwrap_or_else(|_| panic!("Found invalid play {play}"))
|
||||||
})
|
})
|
||||||
.take(2)
|
.take(2)
|
||||||
|
@ -141,10 +142,12 @@ fn parse_input_part_1() -> Vec<[Shape; 2]> {
|
||||||
|
|
||||||
fn parse_input_part_2() -> Vec<(Shape, GameResult)> {
|
fn parse_input_part_2() -> Vec<(Shape, GameResult)> {
|
||||||
INPUT
|
INPUT
|
||||||
.split('\n')
|
.lines()
|
||||||
.map(|round_string| {
|
.map(|round_string| {
|
||||||
let round = round_string.split(' ').take(2).collect::<Vec<_>>();
|
let round = round_string.split(' ').take(2).collect::<Vec<_>>();
|
||||||
assert_eq!(round.len(), 2);
|
assert_eq!(round.len(), 2);
|
||||||
|
assert_eq!(round[0].len(), 1);
|
||||||
|
assert_eq!(round[1].len(), 1);
|
||||||
let enemy_shape = Shape::from_str(round[0])
|
let enemy_shape = Shape::from_str(round[0])
|
||||||
.unwrap_or_else(|_| panic!("Found invalid play {}", round[0]));
|
.unwrap_or_else(|_| panic!("Found invalid play {}", round[0]));
|
||||||
let desired_result = GameResult::from_str(round[1])
|
let desired_result = GameResult::from_str(round[1])
|
||||||
|
|
Loading…
Reference in a new issue