This commit is contained in:
TriMill 2022-12-05 00:20:36 -05:00
parent e0fa04d075
commit d93ee04c32
4 changed files with 79 additions and 4 deletions

View File

@ -1,5 +1,3 @@
use std::collections::*;
fn main() {
let lines: Vec<String> = std::io::stdin().lines().map(|x| x.unwrap()).collect();
let mut result = 0;

View File

@ -1,5 +1,3 @@
use std::collections::*;
fn main() {
let lines: Vec<String> = std::io::stdin().lines().map(|x| x.unwrap()).collect();
let mut result = 0;

38
examples/day05_1.rs Normal file
View File

@ -0,0 +1,38 @@
fn main() {
let mut lines = std::io::stdin().lines();
let mut crates = Vec::new();
let mut line = lines.next().unwrap().unwrap();
let crate_count = line.len()/4 + 1;
for _ in 0..crate_count {
crates.push(vec![]);
}
loop {
if line.chars().nth(1).unwrap().is_numeric() {
break;
}
for i in 0..crate_count {
let c = line.chars().nth(4*i+1).unwrap();
if c != ' ' {
crates[i].insert(0, c);
}
}
line = lines.next().unwrap().unwrap();
}
lines.next().unwrap().unwrap();
while let Some(Ok(line)) = lines.next() {
let mut parts = line.split(" ");
let n: usize = parts.nth(1).unwrap().parse().unwrap();
let from: usize = parts.nth(1).unwrap().parse().unwrap();
let to: usize = parts.nth(1).unwrap().parse().unwrap();
for _ in 0..n {
let c = crates[from-1].pop().unwrap();
crates[to-1].push(c);
}
}
for c in crates.iter_mut() {
print!("{}", c.pop().unwrap());
}
println!();
}

41
examples/day05_2.rs Normal file
View File

@ -0,0 +1,41 @@
fn main() {
let mut lines = std::io::stdin().lines();
let mut crates = Vec::new();
let mut line = lines.next().unwrap().unwrap();
let crate_count = line.len()/4 + 1;
for _ in 0..crate_count {
crates.push(vec![]);
}
loop {
if line.chars().nth(1).unwrap().is_numeric() {
break;
}
for i in 0..crate_count {
let c = line.chars().nth(4*i+1).unwrap();
if c != ' ' {
crates[i].insert(0, c);
}
}
line = lines.next().unwrap().unwrap();
}
lines.next().unwrap().unwrap();
while let Some(Ok(line)) = lines.next() {
let mut parts = line.split(" ");
let n: usize = parts.nth(1).unwrap().parse().unwrap();
let from: usize = parts.nth(1).unwrap().parse().unwrap();
let to: usize = parts.nth(1).unwrap().parse().unwrap();
let mut crane = Vec::new();
for _ in 0..n {
crane.push(crates[from-1].pop().unwrap());
}
for _ in 0..n {
crates[to-1].push(crane.pop().unwrap());
}
}
for c in crates.iter_mut() {
print!("{}", c.pop().unwrap());
}
println!();
}