Unable to load image

Advent of Code Day 5, AKA Stacks 101 :marseyinabox:

I actually stayed up to get a semi-decent score for once (being a eurocel for this is suffering). How are you all faring with shifting boxes around?

![](/images/16702184438592093.webp)

26
Jump in the discussion.

No email address required.

:marseybrainlet: don't bully

use std::fs;

pub fn day05() {
    let s1 = vec!['R', 'G', 'J', 'B', 'T', 'V', 'Z'];
    let s2 = vec!['J', 'R', 'V', 'L'];
    let s3 = vec!['S', 'Q', 'F'];
    let s4 = vec!['Z', 'H', 'N', 'L', 'F', 'V', 'Q', 'G'];
    let s5 = vec!['R', 'Q', 'T', 'J', 'C', 'S', 'M', 'W'];
    let s6 = vec!['S', 'W', 'T', 'C', 'H', 'F'];
    let s7 = vec!['D', 'Z', 'C', 'V', 'F', 'N', 'J'];
    let s8 = vec!['L', 'G', 'Z', 'D', 'W', 'R', 'F', 'Q'];
    let s9 = vec!['J', 'B', 'W', 'V', 'P'];
    let mut ss1 = vec![s1, s2, s3, s4, s5, s6, s7, s8, s9];
    let mut ss2 = ss1.clone();

    let ls = read_input("input.txt");
    for l in &ls {
        for _i in 0..l.0 {
            let a = (ss1[l.1 - 1]).pop().unwrap();
            ss1[l.2 - 1].push(a);
        }
        let mut temp: Vec<char> = Vec::new();
        for _i in 0..l.0 {
            let a = (ss2[l.1 - 1]).pop().unwrap();
            temp.push(a);
        }
        for _i in 0..l.0 {
            let a = temp.pop().unwrap();
            ss2[l.2 - 1].push(a);
        }
    }

    let ss1: String = ss1.iter().map(|x| x.last().unwrap()).collect();
    let ss2: String = ss2.iter().map(|x| x.last().unwrap()).collect();
    println!("1: {ss1}, 2: {ss2}");
}

fn read_input(filename: &str) -> Vec<(usize, usize, usize)> {
    let binding = fs::read_to_string(filename).unwrap();
    let input: Vec<_> = binding
        .lines()
        .map(|x| x.split(' ').collect::<Vec<_>>())
        .map(|x| {
            (
                x[1].parse::<usize>().unwrap(),
                x[3].parse::<usize>().unwrap(),
                x[5].parse::<usize>().unwrap(),
            )
        })
        .collect::<Vec<_>>();
    input
}

Jump in the discussion.

No email address required.

:#marseytrans2:

Jump in the discussion.

No email address required.

nice moral solution strag

Jump in the discussion.

No email address required.

Darn, you're really mad over this, but thanks for the effort you put into typing that all out! Sadly I won't read it all.

Jump in the discussion.

No email address required.



Now playing: In A Snow-Bound Land (DKC2).mp3

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.