Split the input in two in a better way
This commit is contained in:
parent
9a155dbda7
commit
4aa5bd00f9
|
@ -172,17 +172,17 @@ impl FromStr for Instruction {
|
||||||
|
|
||||||
// -- Helpers --
|
// -- Helpers --
|
||||||
fn solution(input: &str, part1: bool) -> String {
|
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
|
// The current layout description ends with an empty line
|
||||||
let mut boat: Boat = input.lines()
|
let mut boat: Boat = boat.lines()
|
||||||
.take_while(|line| !line.is_empty())
|
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into();
|
.into();
|
||||||
|
|
||||||
// Each instruction starts with an 'm'
|
// Each instruction starts with an 'm'
|
||||||
input
|
moves
|
||||||
.lines()
|
.lines()
|
||||||
.skip_while(|line| !line.starts_with('m'))
|
.map(|line| line.parse().expect("Input is invalid"))
|
||||||
.map(|line| line.parse().unwrap())
|
|
||||||
.for_each(|i: Instruction| {
|
.for_each(|i: Instruction| {
|
||||||
let mut taken = boat.take(i.from, i.amount);
|
let mut taken = boat.take(i.from, i.amount);
|
||||||
if part1 {
|
if part1 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user