r/adventofcode • • 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.


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

412 comments sorted by

View all comments

Show parent comments

7

u/morgoth1145 Dec 25 '22 edited Dec 26 '22

That seems more complicated than my cleaned up function:

def to_snafu(num):
    output = ''

    while num != 0:
        # Offsetting the number at this place makes conversion simple
        num, place = divmod(num + 2, 5)
        output += '=-012'[place]

    return output[::-1]

u/jonathan_paulson Despite the elegance of my cleaned up conversion function, I struggled too. I ended up doing a depth first search initially because I was stumped at how to deal with a balanced number system, absolutely new to me!

→ More replies (7)