// Copyright 2022 Christian Ulrich
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
use std::io;
#[derive(Debug)]
pub struct Stacks {
inner: Vec>,
}
pub struct Moves {}
#[derive(Debug)]
pub struct Move {
count: usize,
from: usize,
to: usize,
}
impl Stacks {
pub fn from_stdin() -> Result {
let mut stacks = vec![];
for line in io::stdin().lines() {
match Self::parse_line(&line.unwrap())? {
None => break,
Some(items) => {
if items.len() != stacks.len() {
if !stacks.is_empty() {
return Err("input file contains invalid line");
}
stacks = vec![vec![]; items.len()];
}
for i in 0..items.len() {
if let Some(item) = items[i] {
stacks[i].push(item);
}
}
}
}
}
for stack in stacks.iter_mut() {
stack.reverse();
}
Ok(Self { inner: stacks })
}
fn parse_line(input: &str) -> Result