Split the input in two in a better way

This commit is contained in:
Dreaded_X 2022-12-06 05:25:55 +01:00
parent 9a155dbda7
commit 4aa5bd00f9
Signed by: Dreaded_X
GPG Key ID: 76BDEC4E165D8AD9

View File

@ -172,17 +172,17 @@ impl FromStr for Instruction {
// -- Helpers --
fn solution(input: &str, part1: bool) -> String {
let (boat, moves) = input.split_once("\n\n").expect("Input is invalid");
// The current layout description ends with an empty line
let mut boat: Boat = input.lines()
.take_while(|line| !line.is_empty())
let mut boat: Boat = boat.lines()
.collect::<Vec<_>>()
.into();
// Each instruction starts with an 'm'
input
moves
.lines()
.skip_while(|line| !line.starts_with('m'))
.map(|line| line.parse().unwrap())
.map(|line| line.parse().expect("Input is invalid"))
.for_each(|i: Instruction| {
let mut taken = boat.take(i.from, i.amount);
if part1 {