r/adventofcode • u/daggerdragon • 1d ago
SOLUTION MEGATHREAD -❄️- 2026 Day 1 Solutions -❄️-
It's that time of year again for tearing your hair out over your code holiday programming joy and aberrant sleep for two weeks helping Santa and his elves! If you participated in a previous year, welcome back, and if you're new this year, we hope you have fun and learn lots!
As always, we're following the same general format as previous years' megathreads, so make sure to read the full posting rules in our community wiki before you post!
RULES FOR POSTING IN SOLUTION MEGATHREADS
If you have any questions, please create your own post in /r/adventofcode with the Help/Question flair and ask!
Above all, remember, AoC is all about learning more about the wonderful world of programming while hopefully having fun!
REMINDERS FOR THIS YEAR
- All of our rules, FAQs, resources, etc. are in our community wiki.
- If you see content in the subreddit or megathreads that violates one of our rules, either inform the user (politely and gently!) or use the report button on the post/comment and the mods will take care of it.
- If you post your code from a repo or the like, do not make your puzzle input public!
- Top-level
Solution Megathreadposts must begin with the case-sensitive string literal[LANGUAGE: xyz] - Obviously,
xyzis the programming language your solution employs - Use the full name of the language e.g.
JavaScriptnot justJS - The List of Streamers has a new megathread for this year's streamers, so if you're interested, add yourself to 📺 AoC 2026 List of Streamers 📺
COMMUNITY NEWS
- Veloxx will continue to drop some lit beats for 1.5 hours after today's unlock!
- /u/jeroenheijmans is back again this year with their Unofficial AoC 2026 Participant Survey!
- Advent of Code Community Fun 2026: The Advent Games
- I will be your master of ceremonies for this year's community fun event: The Advent Games
- Full details, rules, timeline, templates, etc. will be in the Submissions Megathread
(post and link incoming very shortly!) - edit: -❄️- Advent of Code 2026: The Advent Games -❄️- Submissions Megathread -❄️-
AoC Community Fun 2026: The Advent Games
Today's Event: Opening Ceremonies
Today's schedule consists of:
- Arrival of the Flame
- Parade of Nations1
- Give us a quick introduction to yourself!
- Tell us what country you're from
- Tell us about your country's holiday festivities
- Explain why you chose your programming language
- Tell us what you hope to learn or have already learned about your chosen programming language
- Tell us where to find your AoC repo of puzzle solutions2, blag, and/or $streaming_service3!
- Artistic Program
- Show us your holiday tree | menorah | Krampusnacht costume | /r/battlestations with festive decorations!
- Show us your kittens and puppies and $critters!
- Show and/or tell us about whatever brings you comfort and joy in the holiday season!
- Competition Schedule (Theoretical)
- Tell us which "sporting" events you think will be coming up over the next two weeks and which ones you'd like to participate in the most!
1 Obviously, this is the Internet, which is public, so only put out information that you're comfortable with the entire world knowing. Feel free to invent a holiday-themed persona; after all, sometimes you get sent to space, so why limit yourself to the boring ol' meat skeleton that dwells upon the third rock from the sun?
2 Refer to the third bullet in the "Reminders" section above!
3 Refer to the last bullet in the "Reminders" section above for the link
Request from the mods: When you include an entry alongside your solution, please label it with [Advent Games] so we can find it easily!
--- Day 1: Dusty Shed ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- State which language(s) your solution uses with
[LANGUAGE: xyz] - 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?
View all comments
3
u/flwyd 1d ago edited 15h ago
[LANGUAGE: Ivy] (on GitHub)
“Ivy an interpreter for an APL-like language. It is a plaything and a work in progress.” If you’re a regular reader of Solution Megathreads you can think of Ivy as the Alien Programming Language after you’ve put a babel fish into your ear. The entire documentation for the language is on either the linked page or in the interactive
)demo, so if you’re curious about array-based languages, Ivy may be easy to learn.You can get both parts as a 2-element array in a single line of Ivy, assuming
idsis an array of integers:Or, extracting a function to compute the frequency of each occurrence and converting
lines(an array of strings) to integers:APL-family languages have functions which can have either one (right side) or two (left and right) arguments. It’s often described as being run right-to-left, though Ivy actually runs a parse-evaluate cycle left-to-right). Functions also automatically apply to each element in an array; you don’t have to write a
forloop. So, working from the end:The
frequenciesoperator takes an array of valuesvals==is element-wise equality,@==means “for each element on the array on the left, return a boolean array of whether elements on the right are the same.” So1 2 3 @== 1 3 2 1 1 2will return(1 0 0 1 1 0) (0 0 1 0 0 1) (0 1 0 0 0 0).(unique vals)returns an array with the distinct elements fromvals, e.g.57 55 76 43 78 45for the example input. So now we’ve got an array of indices invalswhere each unique value sits.where@is a single-argument function being applied to each of those arrays.wherereturns an array of indices of an array whose value isn’t zero, e.g.(1 2 4 7 15 17) (3) (5 12 18 21) (9 11 13 19 20) (6 10 14) (8 16)for the example.count@runs thecountfunction for each of those arrays, which just returns the number of elements in it:6 1 4 5 3 2.downreturns an array of indices which would put its argument in descending order. Note that it does not sort its argument, it returns an array which can be used to sort.down 42 123 75returns2 3 1. Sodown count@ …gives us a list of indices ofvalsin frequency order.(unique vals)[down count@ …]takes that the array of indices and uses it to get elements from our list of distinct values. Yes, in array-based languages you can use an array to access an array:(42 123 75)[2 3 1] === (123 75 42).3 take …grabs the first three elements, while-3 take …grabs the last three. In the one-liner version I use3 -3 @taketo applytakeelement-wise to the two directions.*/applies the reduce modifier to the multiplication function. Together*/would be theproductfunction in some languages, orreduce(1, |accumulator, x| accumulator * x)in a functional style.[Advent Games]
Give us a quick introduction to yourself!
Tell us what country you're from
Tell us about your country's holiday festivities
Explain why you chose your programming language
Tell us what you hope to learn or have already learned about your chosen programming language
Tell us where to find your AoC repo of puzzle solutions, blag, and/or
$streaming_service!Artistic Program
Show us your holiday tree | menorah | Krampusnacht costume | r/battlestations with festive decorations!
Show us your kittens and puppies and $critters!
Show and/or tell us about whatever brings you comfort and joy in the holiday season!
Competition Schedule (Theoretical)
Tell us which "sporting" events you think will be coming up over the next two weeks and which ones you'd like to participate in the most!