done with part 2
This commit is contained in:
parent
e7c4253f1c
commit
5779749423
1 changed files with 25 additions and 10 deletions
|
@ -2,7 +2,7 @@ use aoc_runner_derive::{aoc as aoc_run, aoc_generator};
|
|||
use itertools::Itertools;
|
||||
|
||||
type Stax = Vec<Vec<char>>;
|
||||
type Inst = (u8, u8, u8);
|
||||
type Inst = (usize, usize, usize);
|
||||
|
||||
enum Pstate {
|
||||
Setup,
|
||||
|
@ -42,8 +42,8 @@ fn parse_input_day1(input: &str) -> (Stax, Vec<Inst>) {
|
|||
let ins = re.captures(line).unwrap();
|
||||
inst.push((
|
||||
ins[1].parse().unwrap(),
|
||||
ins[2].parse::<u8>().unwrap() - 1,
|
||||
ins[3].parse::<u8>().unwrap() - 1,
|
||||
ins[2].parse::<usize>().unwrap() - 1,
|
||||
ins[3].parse::<usize>().unwrap() - 1,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -59,14 +59,13 @@ fn part1((stax, inst): &(Stax, Vec<Inst>)) -> String {
|
|||
let mut stax = stax.to_owned();
|
||||
for ins in inst.iter() {
|
||||
let (amt, from, to) = ins;
|
||||
let mut from = &mut stax[*from as usize];
|
||||
let mut tmp = Vec::with_capacity(*amt as usize);
|
||||
let from = &mut stax[*from];
|
||||
let mut tmp = Vec::with_capacity(*amt);
|
||||
for _ in 0..*amt {
|
||||
let from = &mut from;
|
||||
let t = from.pop().unwrap();
|
||||
tmp.push(t);
|
||||
}
|
||||
stax[*to as usize].append(&mut tmp);
|
||||
stax[*to].append(&mut tmp);
|
||||
}
|
||||
let mut s = String::with_capacity(9);
|
||||
for stack in stax {
|
||||
|
@ -76,7 +75,23 @@ fn part1((stax, inst): &(Stax, Vec<Inst>)) -> String {
|
|||
}
|
||||
|
||||
#[aoc_run(day5, part2)]
|
||||
fn p2((stax, inst): &(Stax, Vec<Inst>)) -> u32 {
|
||||
//
|
||||
0
|
||||
fn p2((stax, inst): &(Stax, Vec<Inst>)) -> String {
|
||||
let mut stax = stax.to_owned();
|
||||
for ins in inst.iter() {
|
||||
let (amt, from, to) = ins;
|
||||
let from = &mut stax[*from];
|
||||
let mut tmp = Vec::with_capacity(*amt);
|
||||
for _ in 0..*amt {
|
||||
let c = from.pop().unwrap();
|
||||
tmp.push(c);
|
||||
}
|
||||
for c in tmp.into_iter().rev() {
|
||||
stax[*to].push(c);
|
||||
}
|
||||
}
|
||||
let mut s = String::with_capacity(9);
|
||||
for stack in stax {
|
||||
s.push(stack.last().copied().unwrap());
|
||||
}
|
||||
s
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue