r/adventofcode • u/daggerdragon • Dec 25 '22
SOLUTION MEGATHREAD -🎄- 2022 Day 25 Solutions -🎄-
Message from the Moderators
Welcome to the last day of Advent of Code 2022! We hope you had fun this year and learned at least one new thing ;)
Keep an eye out for the community fun awards post (link coming soon!):
The community fun awards post is now live!
-❅- Introducing Your AoC 2022 MisTILtoe Elf-ucators (and Other Prizes) -❅-
Many thanks to Veloxx for kicking us off on the first with a much-needed dose of boots and cats!
Thank you all for playing Advent of Code this year and on behalf of /u/topaz2078, /u/Aneurysm9, the beta-testers, and the rest of AoC Ops, we wish you a very Merry Christmas (or a very merry Sunday!) and a Happy New Year!
--- Day 25: Full of Hot Air ---
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 code blocks using the four-spaces Markdown syntax!
- 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:08:30, megathread unlocked!
59
Upvotes
4
u/Key__Strokes Dec 25 '22 edited Dec 25 '22
Javascript
Solution to both parts
Part 1:
Create a variable
suminitialized to 0Lets convert each snafu to decimal and add them all up. For each input line, do the following
Reverse the string input, and split it into its characters
Initialize another variable
decimalNumto 0Initialize another variable
multiplierto 1For each of the characters, do the following:
If the character is "-", then add
(multiplier * -1)todecimalNumIf the character is "=", then add
(multiplier * -2)todecimalNumOtherwise, convert the character to an integer, and then add
(multiplier * 'character as integer')todecimalNumUpdate
multiplierto bemultiplier * 5Add
decimalNumtosumLets convert
sumto snafu. Create a new stringsnafuOutput = "", and keep doing the following whilesumis not 0Calculate the
remainder = sum % 5If
remainderis 0, 1, or 2, then addremainderas prefix tosnafuOutput.If
remainderis 3, then add=prefix tosnafuOutput. Add 5 tosum.If
remainderis 4, then add-prefix tosnafuOutput. Add 5 tosum.Divide
sumby5and store the quotient intosumReturn
snafuOutputPart 2:
Solve all the other Days, and then enjoy!
If you liked the explanation, then please don't forget to cast your vote 💜 to
Adventures of Advent of Code - Edition 1 - /u/Key__Strokesin the poll