I3V4KTYU5VJZPGLNIUND3HSX54ZZZ5SQ6RK3LHTBUGEFHAXM75JAC use std::fmt::Display;use aoc::termion::{color, style};use parse_display::FromStr;#[derive(Debug, Clone, Copy, FromStr)]#[display("move {number} from {from} to {to}")]pub struct Instruction {pub number: usize,pub from: usize,pub to: usize,}pub struct Crates {pub crates: Vec<Vec<char>>,}impl std::str::FromStr for Crates {type Err = ();fn from_str(s: &str) -> Result<Self, Self::Err> {let s = s.lines().rev().skip(1).map(|s| s.chars().collect::<Vec<char>>()).collect::<Vec<_>>();let mut crates = Vec::new();for line in s.iter() {for (i, c) in line.iter().skip(1).step_by(4).enumerate() {if crates.len() <= i {crates.push(Vec::new());}if c.is_alphabetic() {crates[i].push(*c);}}}Ok(Crates { crates })}}impl Display for Crates {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {let longest_stack = self.crates.iter().map(|s| s.len()).max().unwrap();let mut highest_stack = vec![true; self.crates.len()];for i in (0..longest_stack).rev() {for (si, stack) in self.crates.iter().enumerate() {if let Some(c) = stack.get(i) {if highest_stack[si] {highest_stack[si] = false;write!(f," [{}{}{}{}{}{}] ",style::Bold,style::Blink,color::Fg(color::Yellow),c,style::Reset,color::Fg(color::LightWhite))?;} else {write!(f, " [{c}] ")?;}} else {write!(f, " ")?;}}writeln!(f)?;}for i in 1..self.crates.len() + 1 {write!(f, " {i} ")?;}writeln!(f)?;Ok(())}}
use day5::*;use aoc::{answer, parser};fn main() {let input = parser::input::<String>();let mut input = input.split("\n\n");let setup = input.next().unwrap();let mut setup: Crates = setup.parse().unwrap();let instructions = input.next().unwrap();let instructions = instructions.lines().map(|s| s.parse::<Instruction>().unwrap()).collect::<Vec<_>>();for instr in instructions {let len = setup.crates[instr.from - 1].len();let mut crates = setup.crates[instr.from - 1].drain(len - instr.number..).collect::<Vec<char>>();setup.crates[instr.to - 1].append(&mut crates);}let answer = setup.crates.iter().filter_map(|stack| stack.last()).collect::<String>();answer!("After the rearrangement procedure completes the crates that ends up on top of each stack are {}.",answer);}
use day5::*;use aoc::{answer, parser};fn main() {let input = parser::input::<String>();let mut input = input.split("\n\n");let setup = input.next().unwrap();let mut setup: Crates = setup.parse().unwrap();let instructions = input.next().unwrap();let instructions = instructions.lines().map(|s| s.parse::<Instruction>().unwrap()).collect::<Vec<_>>();for instr in instructions {println!("{}", setup);println!(" {} ", "-".repeat(setup.crates.len() * 5 - 2));println!();let len = setup.crates[instr.from - 1].len();let mut crates = setup.crates[instr.from - 1].drain(len - instr.number..).collect::<Vec<char>>();setup.crates[instr.to - 1].append(&mut crates);}let answer = setup.crates.iter().filter_map(|stack| stack.last()).collect::<String>();answer!("After the rearrangement procedure completes the crates that ends up on top of each stack are {}.",answer);}
use day5::*;use aoc::{answer, parser};fn main() {let input = parser::input::<String>();let mut input = input.split("\n\n");let setup = input.next().unwrap();let mut setup: Crates = setup.parse().unwrap();let instructions = input.next().unwrap();let instructions = instructions.lines().map(|s| s.parse::<Instruction>().unwrap()).collect::<Vec<_>>();for instr in instructions {let mut crates = (0..instr.number).map(|_| setup.crates[instr.from - 1].pop().unwrap()).collect::<Vec<char>>();setup.crates[instr.to - 1].append(&mut crates);}let answer = setup.crates.iter().filter_map(|stack| stack.last()).collect::<String>();answer!("After the rearrangement procedure completes the crates that ends up on top of each stack are {}.",answer);}
use day5::*;use aoc::{answer, parser};fn main() {let input = parser::input::<String>();let mut input = input.split("\n\n");let setup = input.next().unwrap();let mut setup: Crates = setup.parse().unwrap();let instructions = input.next().unwrap();let instructions = instructions.lines().map(|s| s.parse::<Instruction>().unwrap()).collect::<Vec<_>>();for instr in instructions {println!("{}", setup);println!(" {} ", "-".repeat(setup.crates.len() * 5 - 2));println!();let mut crates = (0..instr.number).map(|_| setup.crates[instr.from - 1].pop().unwrap()).collect::<Vec<char>>();setup.crates[instr.to - 1].append(&mut crates);}let answer = setup.crates.iter().filter_map(|stack| stack.last()).collect::<String>();answer!("After the rearrangement procedure completes the crates that ends up on top of each stack are {}.",answer);}
[D][N] [C][Z] [M] [P]1 2 3move 1 from 2 to 1move 3 from 1 to 3move 2 from 2 to 1move 1 from 1 to 2
[G] [D] [Q][P] [T] [L] [M] [Z][Z] [Z] [C] [Z] [G] [W][M] [B] [F] [P] [C] [H] [N][T] [S] [R] [H] [W] [R] [L] [W][R] [T] [Q] [Z] [R] [S] [Z] [F] [P][C] [N] [H] [R] [N] [H] [D] [J] [Q][N] [D] [M] [G] [Z] [F] [W] [S] [S]1 2 3 4 5 6 7 8 9move 7 from 6 to 8move 5 from 2 to 6move 2 from 4 to 1move 1 from 4 to 5move 5 from 7 to 6move 7 from 6 to 3move 5 from 9 to 2move 6 from 2 to 3move 2 from 7 to 9move 20 from 3 to 1move 11 from 1 to 6move 1 from 9 to 8move 3 from 8 to 2move 8 from 1 to 5move 10 from 8 to 4move 7 from 6 to 4move 1 from 8 to 3move 8 from 1 to 7move 16 from 4 to 8move 1 from 9 to 8move 1 from 5 to 2move 4 from 7 to 4move 5 from 6 to 7move 1 from 6 to 1move 8 from 7 to 4move 1 from 6 to 9move 12 from 4 to 5move 3 from 2 to 5move 1 from 6 to 2move 1 from 3 to 7move 1 from 3 to 2move 1 from 9 to 3move 1 from 7 to 8move 1 from 7 to 5move 1 from 3 to 2move 4 from 5 to 7move 5 from 5 to 7move 1 from 4 to 3move 1 from 3 to 9move 3 from 1 to 8move 1 from 9 to 1move 2 from 2 to 1move 2 from 2 to 7move 8 from 8 to 1move 3 from 5 to 2move 8 from 7 to 5move 7 from 1 to 3move 3 from 1 to 7move 1 from 1 to 5move 1 from 3 to 7move 7 from 5 to 8move 2 from 2 to 8move 1 from 3 to 2move 1 from 2 to 4move 1 from 4 to 8move 13 from 8 to 1move 13 from 5 to 9move 2 from 5 to 2move 7 from 9 to 3move 12 from 8 to 3move 4 from 9 to 3move 1 from 3 to 4move 2 from 2 to 3move 1 from 1 to 6move 1 from 2 to 3move 1 from 5 to 9move 7 from 7 to 4move 10 from 1 to 8move 1 from 1 to 4move 1 from 9 to 5move 2 from 5 to 1move 1 from 6 to 5move 3 from 8 to 9move 5 from 4 to 3move 4 from 4 to 1move 7 from 1 to 6move 2 from 5 to 7move 35 from 3 to 4move 4 from 9 to 1move 19 from 4 to 8move 1 from 7 to 6move 1 from 9 to 2move 10 from 4 to 5move 2 from 4 to 7move 3 from 4 to 3move 1 from 2 to 8move 1 from 1 to 9move 3 from 3 to 6move 4 from 8 to 6move 4 from 5 to 2move 2 from 8 to 3move 3 from 5 to 9move 12 from 6 to 1move 8 from 8 to 6move 2 from 9 to 1move 1 from 4 to 1move 1 from 3 to 8move 3 from 7 to 8move 2 from 9 to 7move 1 from 6 to 7move 10 from 6 to 8move 4 from 2 to 5move 1 from 3 to 7move 7 from 5 to 7move 13 from 8 to 1move 29 from 1 to 4move 8 from 7 to 8move 1 from 1 to 3move 3 from 7 to 6move 1 from 1 to 9move 15 from 4 to 1move 1 from 3 to 6move 10 from 1 to 6move 10 from 6 to 7move 1 from 4 to 9move 1 from 9 to 1move 1 from 9 to 7move 6 from 7 to 8move 1 from 1 to 6move 5 from 6 to 5move 21 from 8 to 9move 5 from 1 to 9move 2 from 9 to 5move 3 from 5 to 6move 3 from 7 to 9move 4 from 4 to 6move 6 from 8 to 7move 6 from 6 to 3move 2 from 7 to 9move 1 from 7 to 2move 6 from 3 to 2move 1 from 6 to 4move 4 from 5 to 9move 1 from 4 to 5move 9 from 4 to 6move 7 from 6 to 4move 10 from 9 to 2move 5 from 7 to 5move 10 from 2 to 7move 2 from 5 to 4move 2 from 5 to 9move 4 from 9 to 4move 1 from 8 to 6move 7 from 7 to 2move 1 from 5 to 4move 2 from 7 to 1move 1 from 5 to 7move 3 from 6 to 2move 4 from 4 to 5move 1 from 2 to 7move 10 from 4 to 7move 3 from 7 to 3move 17 from 9 to 4move 1 from 1 to 4move 1 from 1 to 5move 5 from 2 to 7move 1 from 9 to 2move 5 from 4 to 8move 2 from 9 to 7move 4 from 8 to 1move 3 from 4 to 8move 1 from 2 to 5move 1 from 9 to 2move 6 from 4 to 8move 3 from 7 to 5move 1 from 4 to 9move 1 from 9 to 1move 3 from 1 to 9move 4 from 8 to 5move 2 from 9 to 8move 4 from 2 to 5move 8 from 7 to 2move 5 from 8 to 5move 2 from 7 to 8move 1 from 3 to 5move 1 from 1 to 2move 1 from 1 to 6move 2 from 3 to 6move 5 from 2 to 8move 4 from 7 to 1move 7 from 8 to 5move 1 from 1 to 5move 3 from 8 to 3move 1 from 9 to 3move 7 from 2 to 3move 2 from 2 to 8move 2 from 4 to 8move 1 from 8 to 5move 1 from 1 to 4move 2 from 4 to 7move 2 from 7 to 1move 3 from 2 to 3move 3 from 5 to 2move 1 from 8 to 3move 3 from 3 to 2move 5 from 2 to 1move 17 from 5 to 8move 9 from 8 to 1move 11 from 3 to 5move 8 from 8 to 5move 2 from 8 to 5move 16 from 1 to 4move 13 from 4 to 7move 6 from 5 to 2move 2 from 4 to 8move 5 from 7 to 9move 2 from 1 to 2move 7 from 7 to 1move 1 from 1 to 4move 1 from 9 to 8move 7 from 2 to 8move 1 from 4 to 7move 2 from 9 to 4move 1 from 4 to 1move 1 from 3 to 5move 2 from 9 to 8move 11 from 8 to 7move 2 from 6 to 5move 1 from 6 to 9move 1 from 1 to 9move 1 from 9 to 1move 4 from 1 to 4move 2 from 1 to 8move 1 from 1 to 2move 1 from 9 to 5move 2 from 4 to 3move 2 from 2 to 7move 2 from 3 to 9move 1 from 9 to 1move 1 from 9 to 1move 5 from 5 to 1move 19 from 5 to 6move 5 from 1 to 4move 1 from 2 to 9move 1 from 1 to 3move 7 from 5 to 8move 1 from 3 to 6move 8 from 7 to 3move 7 from 4 to 8move 3 from 8 to 5move 1 from 4 to 1move 1 from 9 to 4move 1 from 4 to 9move 1 from 5 to 2move 2 from 5 to 6move 2 from 8 to 2move 7 from 8 to 1move 1 from 1 to 7move 3 from 6 to 9move 2 from 3 to 2move 1 from 2 to 1move 1 from 8 to 7move 2 from 9 to 6move 2 from 9 to 5move 1 from 5 to 6move 1 from 2 to 8move 2 from 1 to 7move 1 from 4 to 3move 3 from 2 to 5move 7 from 1 to 3move 10 from 3 to 4move 3 from 5 to 4move 1 from 3 to 8move 3 from 3 to 2move 1 from 8 to 1move 1 from 1 to 3move 3 from 8 to 3move 5 from 4 to 6move 1 from 2 to 3move 4 from 6 to 4move 1 from 5 to 7move 4 from 3 to 4move 1 from 2 to 8move 12 from 7 to 6move 1 from 8 to 2move 2 from 2 to 7move 1 from 8 to 4move 23 from 6 to 3move 14 from 3 to 6move 15 from 4 to 6move 1 from 8 to 6move 10 from 3 to 7move 2 from 4 to 2move 11 from 7 to 8move 2 from 2 to 6move 44 from 6 to 9move 21 from 9 to 3move 12 from 3 to 6move 1 from 7 to 4move 1 from 4 to 7move 9 from 3 to 2move 2 from 8 to 6move 3 from 2 to 4move 17 from 9 to 1move 3 from 4 to 6move 2 from 2 to 9move 4 from 9 to 2move 10 from 6 to 9move 1 from 7 to 6move 4 from 9 to 5move 4 from 2 to 4move 14 from 1 to 5move 4 from 4 to 3move 3 from 2 to 9move 9 from 9 to 7move 1 from 2 to 5move 9 from 8 to 5move 8 from 7 to 2move 4 from 3 to 8move 5 from 6 to 2move 3 from 1 to 6move 1 from 7 to 1move 4 from 2 to 4move 3 from 6 to 4move 3 from 8 to 3move 13 from 5 to 2move 2 from 3 to 5move 12 from 5 to 9move 1 from 3 to 5move 1 from 5 to 9move 1 from 8 to 3move 4 from 9 to 5move 6 from 4 to 5move 12 from 9 to 7move 1 from 9 to 3move 1 from 3 to 2move 12 from 5 to 6move 12 from 7 to 2move 1 from 3 to 7move 1 from 4 to 8move 33 from 2 to 8move 1 from 7 to 5move 1 from 1 to 2move 4 from 5 to 4move 3 from 2 to 5move 34 from 8 to 6move 1 from 4 to 3move 1 from 5 to 7move 1 from 7 to 5move 3 from 4 to 9move 2 from 9 to 7move 1 from 9 to 4move 1 from 3 to 7move 1 from 5 to 8move 1 from 5 to 1move 1 from 5 to 7move 1 from 4 to 8move 1 from 1 to 4move 1 from 4 to 2move 3 from 7 to 5move 2 from 8 to 5move 1 from 2 to 8move 4 from 6 to 2move 1 from 8 to 6move 1 from 7 to 9move 29 from 6 to 7move 4 from 2 to 3move 2 from 5 to 8move 1 from 9 to 5move 2 from 8 to 1move 23 from 7 to 5move 2 from 6 to 1move 23 from 5 to 6move 1 from 3 to 6move 4 from 5 to 9move 2 from 1 to 3move 5 from 3 to 8move 2 from 6 to 5move 2 from 1 to 4move 1 from 9 to 8move 1 from 9 to 1move 1 from 4 to 6move 2 from 5 to 6move 6 from 7 to 8move 2 from 9 to 2move 18 from 6 to 5move 21 from 6 to 4move 1 from 1 to 6move 2 from 6 to 7move 2 from 7 to 9move 2 from 2 to 8move 7 from 4 to 3move 12 from 5 to 3move 1 from 9 to 5move 1 from 9 to 4move 6 from 5 to 2move 17 from 3 to 4move 3 from 4 to 3move 1 from 2 to 4move 5 from 2 to 8move 1 from 5 to 8move 19 from 8 to 7move 1 from 3 to 6move 1 from 8 to 4move 1 from 6 to 1move 15 from 4 to 6move 1 from 1 to 4move 3 from 3 to 5move 4 from 6 to 7move 1 from 4 to 7move 10 from 6 to 7move 16 from 4 to 5move 24 from 7 to 2move 8 from 7 to 8move 1 from 4 to 2move 6 from 8 to 7move 1 from 8 to 7move 1 from 6 to 9move 14 from 5 to 4move 9 from 7 to 8move 4 from 5 to 1move 2 from 1 to 5move 3 from 8 to 6move 2 from 6 to 9move 2 from 2 to 8move 6 from 2 to 7move 3 from 4 to 6move 1 from 3 to 4move 3 from 5 to 7move 1 from 6 to 9move 5 from 7 to 2move 4 from 9 to 1move 1 from 7 to 9move 9 from 8 to 4move 5 from 1 to 2move 2 from 6 to 1move 6 from 4 to 7move 1 from 7 to 3move 1 from 3 to 9move 1 from 9 to 7move 1 from 6 to 7move 9 from 4 to 5move 7 from 7 to 9move 3 from 7 to 5move 1 from 9 to 2move 6 from 9 to 8move 4 from 4 to 5move 1 from 4 to 2move 1 from 4 to 2move 2 from 1 to 2move 1 from 9 to 8move 10 from 2 to 4move 8 from 2 to 7move 12 from 2 to 9move 6 from 7 to 4move 1 from 1 to 2move 8 from 9 to 8move 7 from 5 to 1move 9 from 4 to 3move 14 from 8 to 4move 1 from 8 to 4move 1 from 1 to 5move 1 from 5 to 2move 3 from 2 to 4move 1 from 7 to 1move 1 from 7 to 3move 2 from 1 to 7move 3 from 5 to 7move 2 from 7 to 6move 1 from 6 to 5move 3 from 7 to 1move 1 from 6 to 8move 1 from 8 to 7move 1 from 3 to 6move 1 from 7 to 1move 4 from 1 to 4move 6 from 3 to 2move 3 from 1 to 2move 3 from 3 to 6move 3 from 2 to 6move 6 from 6 to 5move 1 from 1 to 4move 1 from 9 to 6move 5 from 2 to 1move 3 from 1 to 2move 2 from 9 to 8move 3 from 1 to 5move 1 from 9 to 7move 25 from 4 to 1move 1 from 1 to 7move 2 from 8 to 3move 13 from 1 to 9move 2 from 3 to 5move 8 from 5 to 9move 4 from 2 to 1move 2 from 6 to 7move 10 from 5 to 9move 4 from 7 to 2move 2 from 2 to 3move 9 from 9 to 2move 4 from 4 to 5move 4 from 5 to 4move 5 from 1 to 4move 10 from 4 to 5move 22 from 9 to 1move 2 from 2 to 7move 3 from 2 to 1move 6 from 2 to 6move 1 from 7 to 1move 10 from 5 to 7move 15 from 1 to 4move 13 from 1 to 5move 3 from 6 to 8move 1 from 8 to 9
[package]name = "day5"version = "0.1.0"edition = "2021"# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html[dependencies]aoc = { git = "https://github.com/irevoire/aoc" }parse-display = "0.6.0"