From 4aa5bd00f9a69af5181cf6b9618caaf12910056c Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Tue, 6 Dec 2022 05:25:55 +0100 Subject: [PATCH] Split the input in two in a better way --- 2022/src/bin/day5.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/2022/src/bin/day5.rs b/2022/src/bin/day5.rs index b4c657b..467deb2 100644 --- a/2022/src/bin/day5.rs +++ b/2022/src/bin/day5.rs @@ -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::>() .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 {