Prefer this syntax for only taking the second part of a split

This commit is contained in:
Dreaded_X 2023-12-05 22:02:46 +01:00
parent a5c515f64a
commit 408473c50a
Signed by: Dreaded_X
GPG Key ID: FA5F485356B0D2D4
2 changed files with 8 additions and 6 deletions

View File

@ -88,7 +88,7 @@ impl aoc::Solver for Day {
// If valid, get the id and add it to the sum
if valid {
let (_, id) = game.split_once(' ').unwrap();
let id = game.split_once(' ').unwrap().1;
let id: usize = id.parse().unwrap();
Some(id)
} else {
@ -107,7 +107,7 @@ impl aoc::Solver for Day {
.lines()
.map(|line| {
// Split the game id from the actual game played
let (_, line) = line.split_once(": ").unwrap();
let line = line.split_once(": ").unwrap().1;
// Get the required minimum amount for each color
let required = line.split(", ").fold((0, 0, 0), |acc, entry| {

View File

@ -61,9 +61,10 @@ impl aoc::Solver for Day {
.lines()
.map(|line| {
// Get rid of the first part
let (_, line) = line
let line = line
.split_once(": ")
.expect("Input should be formatted properly");
.expect("Input should be formatted properly")
.1;
// Seperate the winning numbers and numbers we have
let (winning, numbers) = line
@ -96,9 +97,10 @@ impl aoc::Solver for Day {
input.lines().enumerate().for_each(|(i, line)| {
// Get rid of the first part
let (_, line) = line
let line = line
.split_once(": ")
.expect("Input should be formatted properly");
.expect("Input should be formatted properly")
.1;
// Seperate the winning numbers and numbers we have
let (winning, numbers) = line