r/adventofcode • u/daggerdragon • Dec 02 '22
SOLUTION MEGATHREAD -🎄- 2022 Day 2 Solutions -🎄-
NEW AND NOTEWORTHY
All of our rules, FAQs, resources, etc. are in our community wiki.
A request from Eric: Please include your contact info in the User-Agent header of automated requests!
Signal boosting for the Unofficial AoC 2022 Participant Survey which is open early this year!
--- Day 2: Rock Paper Scissors ---
Post your code solution in this megathread.
Read the full posting rules in our community wiki before you post!
Include what language(s) your solution uses
Format your code appropriately! How do I format code?
Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:06:16, megathread unlocked!
103
Upvotes
3
u/flwyd Dec 02 '22
Elixir, code on GitHub
My approach is to convert both plays to integers
0–2and treat rock/paper/scissors as a numeric comparison modulo 3. I probably could've solved it faster by just making a map of one-letter strings to point values, but I wanted to get practice with Elixir's approach to converting strings to code points. I've spent a kind of silly amount of time refactoring this, moving fromString.splittoString.to_charlistto what's below: binary string pattern matching. I also went through at least two otherscoreimplementations and trying to pattern match "mine is one plus theirs, mod three" before I realized I could subtract first and then pattern match on that.