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
103
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
6 of 6

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
[–]tav_stuff20 points3 years, 1 month ago* (edited 3 hours, 23 minutes after)

AWK

Part 1

#!/usr/bin/awk -f

/X/ { s += 1 }
/Y/ { s += 2 }
/Z/ { s += 3 }

/A X|B Y|C Z/ { s += 3 }
/A Y|B Z|C X/ { s += 6 }

END { print s }

Part 2

#!/usr/bin/awk -f

/Y/ { s += 3 }
/Z/ { s += 6 }

/A Y|B X|C Z/ { s += 1 }
/B Y|C X|A Z/ { s += 2 }
/C Y|A X|B Z/ { s += 3 }

END { print s }
permalinkhide replies (2)author-focusas-ofpreserve
[–][deleted]5 points3 years, 1 month ago

Awk is actually really good for this because it's really tailor made for cases like this, when you need to patternmatch on a stream of lines :)

permalinkparentcontexthide replies (1)as-of
[–]tav_stuff2 points3 years, 1 month ago

Awk is fantastic for AOC. Lots of puzzles have easy awk solutions.

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

By the way, do you know by any chance (except maybe the infopages) any learning resources for AWK? I only really know about BEGIN{}, {} and END{} blocks (I learned about awk's regex feature because of your post though).

permalinkparentcontexthide replies (1)as-of
[–]tav_stuff2 points3 years, 1 month ago

You can read the POSIX awk manual page. If you have posix manpages installed it’s man 1p awk. If you have GNU awk installed you can read the gawk manual. I prefer the HTML version (just google β€žgawk manualβ€œ online) but you can also use infopages if you hate yourself.

Unfortunately I don’t really know any other good source :/

permalinkparentcontextauthor-focusas-ofpreserve
[–]daggerdragon4 points3 years, 1 month ago

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.

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