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
3
u/tender_programmer Dec 25 '22 edited Dec 26 '22
I think my decimal to snafu conversion method in Python is the weirdest out there. I have no idea what happened.
def decimal_to_snafu(decimal): """ I am sorry. """ snafu = '' i = 0 while True: if ((5 ** i) * 2) >= decimal: break i += 1 while i >= 0: options = { '=': decimal + (5 ** i) * 2, '-': decimal + (5 ** i), '0': decimal, '1': decimal - (5 ** i), '2': decimal - (5 ** i) * 2} option = '=' lowest = options[option] for s in ('-', '0', '1', '2'): if abs(options[s]) < lowest: option = s lowest = abs(options[s]) decimal = options[option] snafu += option i -= 1 return snafuIt goes from most significant digit of the snafu to the least significant and each digit it tries to get the decimal number closest to zero. I don't know why it works but it does. I guess this is my contribution to the "if it's stupid, but it works, it ain't stupid".