LOADING: An error occurred. Update Chrome, try Firefox, or visit this post for more details.

⚠️Reddit changed how removals work, which breaks Reveddit's website. Install the extension to track removed content:Add to chromeAdd to firefoxWhat changed?
✖︎
about reveddit
⚙F.A.Q.add-ons
r/
status
copy sharelink
[+] show filters
88
SOLUTION MEGATHREAD-🎄- 2022 Day 5 Solutions -🎄-(self.adventofcode)
submitted 3 years, 1 month ago* (edited 1 day, 4 hours after) by daggerdragon to /r/adventofcode (134.8k)
1337 commentsredditother-discussionssubreddit-indexmessage modsop-focus
  • All of our rules, FAQs, resources, etc. are in our community wiki.
  • A reque...

... view full text

since 3 years, 1 month ago
2 of 2

Tip Reveddit Real-Time can notify you when your content is removed.

your account history
(check your username's removed content. why?)
Tip Check if your account has any removed comments.
view my removed comments
you are viewing a single comment's thread.
view all comments
[–][deleted]4 points3 years, 1 month ago* (edited 13 minutes after)

Rust

499/478

Totally overkill parsing with itertools and scan_fmt today:

fn parse(input: &str) -> (Vec<VecDeque<char>>, impl Iterator<Item = Instruction> + '_) {
    let (crates, instructions) = input.split("\n\n").into_iter().collect_tuple().unwrap();

    let crates = crates
        .lines()
        .flat_map(|l|
            l.chars().skip(1).step_by(4)
                .enumerate()  // this gives the crane number
                .filter(|(_, c)| c.is_alphabetic())  // remove crates which do not exist
        )
        .into_grouping_map() // itertools magic - this gets the crates for each crane
        .collect::<VecDeque<char>>();

    let crates = crates
        .into_iter()
        .sorted_by_key(|(i, _)| *i)  // grouping_map is unordered
        .map(|(_, stack)| stack)
        .collect();

    let instructions = instructions
        .lines()
        .filter_map(|l| scan_fmt!(l, "move {d} from {d} to {d}", usize, usize, usize).ok())
        .map(|(qty, from, to)| Instruction { qty, from: from - 1, to: to - 1 });

    (crates, instructions)
}

It should work with any number of stacks and items as a result.

Full solution here (GitHub).

permalinkhide replies (1)as-of
[–]Sh4d13 points3 years, 1 month ago
pub fn input_generator(input: &str) -> Game {
    let (stacks, insts) = input.split_once("\n\n").unwrap();
    let n = (stacks.lines().take(1).next().unwrap().len() + 1) / 4;
    let mut crates = vec![Vec::new(); n];
    stacks.lines().rev().skip(1).for_each(|l| {
        let mut i = 0;
        l.chars().collect::<Vec<char>>().chunks(4).for_each(|c| {
            if c[1] != ' ' {
                crates[i].push(c[1]);
            }
            i += 1;
        });
    });

    let inst = insts
        .lines()
        .map(|l| scan_fmt!(l, "move {d} from {d} to {d}", usize, usize, usize).unwrap())
        .collect::<Vec<_>>();
    Game { crates, inst }
}

Pretty much the same for mine, I just completely ignore the crane numbers

permalinkparentcontextauthor-focusas-ofpreserve
r/revedditremoved.substack.com
🚨 NEWS 🚨
✖︎

Important: Reddit Changed How Removals Work

A recent Reddit update makes mod-removed content disappear from profile pages, which breaks Reveddit's website.

Install the browser extension to receive removal alerts.

Add to chromeAdd to firefox

What changed?

r/revedditremoved.substack.com