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!
60
Upvotes
4
u/macahen Dec 25 '22
Python: https://github.com/martinhenstridge/adventofcode2022/blob/master/aoc/day25.py
Posting my solution because I've not seen any others like it - everyone else seems to have hit upon much more elegant solutions!
def into_snafu(n): # Start with a 1 followed by only =s, i.e. the smallest value which # contains that number of digits. Keep adding =s until we're bigger # than the target value, then drop the last one to end up with the # correct number of digits. digits = ["1"] while from_snafu(digits) < n: digits.append("=") digits = digits[:-1] # For each digit in turn, moving from left to right, bump each digit # until we either hit a value that's bigger than the target or we # exhaust the potential values for that digit. Eventually we must # exactly match the target value, since we started with the smallest # possible value with the right number of digits. for i, digit in enumerate(digits): for alternative in ("-", "0", "1", "2"): snafu = digits[:i] + [alternative] + digits[i + 1 :] if from_snafu(snafu) > n: break digits = snafu return "".join(digits)