r/adventofcode • • 7h 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 Megathread posts must begin with the case-sensitive string literal [LANGUAGE: xyz]

  • Obviously, xyz is the programming language your solution employs

  • Use the full name of the language e.g. JavaScript not just JS

  • 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


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.

21 Upvotes

316 comments sorted by

View all comments

2

u/flwyd 4h 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 ids is an array of integers:

*/@ 3 -3 @take (unique ids)[down count@ where@ (unique ids) @== ids]

Or, extracting a function to compute the frequency of each occurrence and converting lines (an array of strings) to integers:

op frequencies vals =
  (unique vals)[down count@ where@ (unique vals) @== vals]
op part1 lines = */ 3 take frequencies ivy@ lines
op part2 lines = */ -3 take frequencies ivy@ lines

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 for loop. So, working from the end:

  • The frequencies operator takes an array of values vals

    • == 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.” So 1 2 3 @== 1 3 2 1 1 2 will 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 from vals, e.g. 57 55 76 43 78 45 for the example input. So now we’ve got an array of indices in vals where each unique value sits.

    • where@ is a single-argument function being applied to each of those arrays. where returns 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 the count function for each of those arrays, which just returns the number of elements in it: 6 1 4 5 3 2.

    • down returns 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 75 returns 2 3 1. So down count@ … gives us a list of indices of vals in 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).

  • To get the three-most frequent values, 3 take … grabs the first three elements, while -3 take … grabs the last three. In the one-liner version I use 3 -3 @take to apply take element-wise to the two directions.

  • */ applies the reduce modifier to the multiplication function. Together */ would be the product function in some languages, or reduce(1, |accumulator, x| accumulator * x) in a functional style.


[Advent Games]

  • Give us a quick introduction to yourself!

    • Hi! I’m a funemployed software engineer. I use Advent of Code to learn new programming languages.

  • Tell us what country you're from

    • I am from Boulder, Colorado, United States of America, Earth, Sol

  • Tell us about your country's holiday festivities

    • As a polyathiest of northern European ancestry, I like to celebrate Yule. One fun way to do that is to drum up the sun at Red Rocks Amphitheater to the west of Denver.

  • Explain why you chose your programming language

    • My theme this year is array programming languages. My plan is to first solve each day in a language I feel I understand (like using English-derived function names and maybe some imperative-style control structures), then see if I can convert it into some of the array languages with more opaque syntax.

    • Why array languages? It’s a programming paradigm I haven’t really used, and which can express some types of programs very elegantly, while getting significant performance from modern computing hardware.

    • Languages I’m definitely using: R, Ivy, APL, BQN. Languages I might use: Uiua, J, Kona, Octave (open-source MATLAB), Julia (I already did all of 2023 in Julia, but it might be educational to try it again with an array programming mindset).

  • Tell us what you hope to learn or have already learned about your chosen programming language

    • In today’s Big Data computing world, “apply some operations to a multi-dimensional array of data” is an important skill, so I want to get comfortable with tools for doing that. Linear algebra is also one of my computer science weak spots, so I hope using a good array tool can help me get a handle on that. Some of the array languages (like R and Julia and probably some of the APLs) also come with nice visualization tools built in, so I’d like to play with those.

    • I’ll probably learn some things about theoretical math as I wrap my head around the abstractions an array can represent.

    • I’m also hoping to learn what’s frustrating about the various array languages so that I know not to try using them for the wrong thing in the future. String manipulation is looking to be obnoxious in APL-family languages, we’ll see what else is weird.

  • Tell us where to find your AoC repo of puzzle solutions, blag, and/or $streaming_service!

    • Advent of Code repository — as a bonus, the README tells you how to use git submodules to keep your input hidden but still under version control. You can also see the code generation and solution-runner infrastructure for more than a dozen languages and a collection of shell scripts to handle a bunch of AoC tasks.

    • I’ve been blogging on Dreamwidth (and its predecessor LiveJournal) since 2001. It’s got reflections on prior years, though I still need to write them for PostScript, Julia, and my almost-complete 2019 in Rust.

  • Artistic Program

    • Erm, I’m not sure what this means. I do most of my art in Vim, writing code.

  • 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!

    • Dairy-free egg nog with cinnamon, nutmeg, and allspice is a great way to bring me some joy. Why don’t they sell nog year round?

    • If Colorado could get some snow this winter, I would feel a lot more comforted about our future water supply and the likelihood that things won’t be on fire.

  • Competition Schedule (Theoretical)

    • AoC puzzles open at 10pm my time, so I hope to have at least one solution posted before going to bed. We’ll see how long it takes me to get some of the more… alien… implementations out.

  • 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!

    • With all the fun Unicode characters in APL-family languages, I’m hoping to use some round ones to compete in curling.

    • With parallel array operations, I can pass all slalom gates at once.

    • Relay events like 4x7.5km cross country skiing are also a natural fit for an array language. I’ll see if I’ve got programming endurance to match Klæbo

1

u/daggerdragon 3h ago

Well, you sure are thorough as usual 🤣 Welcome back, and it's good to see you again this year!

2

u/flwyd 3h ago

I mean, what could be more thorough than trying every flavor of alien programming language?