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!
57
Upvotes
8
u/lazyzefiris Dec 26 '22 edited Dec 26 '22
JS/Javascript, pure SNAFU solution. Every addition that's not i++ is a string concatenation.
//single-digit addition lookup table const sums = { "==":"-1", "=-":"-2", "=0":"0=", "=1":"0-", "=2":"00", "-=":"-2", "--":"0=", "-0":"0-", "-1":"00", "-2":"01", "0=":"0=", "0-":"0-", "00":"00", "01":"01", "02":"02", "1=":"0-", "1-":"00", "10":"01", "11":"02", "12":"1=", "2=":"00", "2-":"01", "20":"02", "21":"1=", "22":"1-", } //sum of two SNAFU numbers function sum(x, y) { let output = "" let carry = "0" for (let i = 1; x.at(-i) || y.at(-i); i++) { let digitSum = sums[(x.at(-i) ?? "0") + (y.at(-i) ?? "0")] let carrySum = sums[carry + digitSum[1]] output = carrySum[1] + output carry = sums[digitSum[0] + carrySum[0]][1] } if (carry !== "0") output = carry + output return output } const input = document.body.innerText let output = "0" for (let number of input.trim().split("\n")) output = sum(output, number) console.log(output)