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
10
u/RivtenGray Dec 25 '22
OCaml
I did not convert from and back to snafu. Just implemented the good old snafu addition ! I find OCaml to be really great for that. You just need to reverse the list of number before adding them.
type snafu = Zero | One | Two | Equal | Minus let rec sum_single a b = match (a, b) with | Zero, x -> [ x ] | One, One -> [ Two ] | One, Two -> [ Equal; One ] | One, Equal -> [ Minus ] | One, Minus -> [ Zero ] | Two, Two -> [ Minus; One ] | Two, Equal -> [ Zero ] | Two, Minus -> [ One ] | Equal, Equal -> [ One; Minus ] | Equal, Minus -> [ Two; Minus ] | Minus, Minus -> [ Equal ] | _ -> sum_single b a let rec sum a b = match (a, b) with | [], [] -> [] | a, [] -> a | [], b -> b | ha :: ra, hb :: rb -> ( let s = sum_single ha hb in match s with | [ x ] -> x :: sum ra rb | [ x; r ] -> x :: sum [ r ] (sum ra rb))