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
102
SOLUTION MEGATHREAD-🎄- 2022 Day 2 Solutions -🎄-(self.adventofcode)
submitted 3 years, 1 month ago* (edited 4 days, 4 hours after) by daggerdragon to /r/adventofcode (134.8k)
1501 commentsredditother-discussionssubreddit-indexmessage modsop-focus

NEW AND NOTEWORTHY

  • All of our rules, FAQs, resources, etc. are in our [community wiki](/r/adve...

... view full text

since 3 years, 1 month ago
5 of 5

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]3 points3 years, 1 month ago* (edited 25 minutes after)

rust:

const INPUT: &str = include_str!("inputs/day02.txt");

pub fn run() -> String {
    format!("Part one: {}\nPart two: {}", part1(INPUT), part2(INPUT))
}

fn part1(input: &str) -> u32 {
    input
        .lines()
        .map(|l| match l {
            "A X" => 1 + 3,
            "B X" => 1,
            "C X" => 1 + 6,
            "A Y" => 2 + 6,
            "B Y" => 2 + 3,
            "C Y" => 2,
            "A Z" => 3,
            "B Z" => 3 + 6,
            "C Z" => 3 + 3,
            _ => panic!(),
        })
        .sum()
}

fn part2(input: &str) -> u32 {
    input
        .lines()
        .map(|l| match l {
            "A X" => 3,
            "B X" => 1,
            "C X" => 2,
            "A Y" => 3 + 1,
            "B Y" => 3 + 2,
            "C Y" => 3 + 3,
            "A Z" => 6 + 2,
            "B Z" => 6 + 3,
            "C Z" => 6 + 1,
            _ => panic!(),
        })
        .sum()
}
permalinkhide replies (2)as-of
[–]lazyzefiris2 points3 years, 1 month ago

I like how values are spelt out as a total instead of magic values. At this point I'd probably also name the values as constants, so that 1 + 3 would become PICK_ROCK + OUTCOME_DRAW.

permalinkparentcontextauthor-focusas-ofpreserve
[–]daggerdragon1 point3 years, 1 month ago* (edited 21 minutes after)

Please edit your post to format your code with the backwards-compatible Markdown syntax instead so your code is easier to read on old.reddit and mobile apps.

Edit: thank you for fixing it <3

permalinkparentcontexthide replies (1)author-focusas-ofpreserve
[–][deleted]2 points3 years, 1 month ago

Apologies, I'm used to stack-overflow and used the same format out of habit. That should fix it.

permalinkparentcontexthide replies (1)as-of
[–]daggerdragon2 points3 years, 1 month ago* (edited 40 minutes after)

Ay, it's all good as long as you fix it when I poke you <3

(psst, the first pair of lines are outside the code block) Nothing to see here, please disperse.

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