Thursday December 1st at 5 a.m. UTC will mark the start of the eight incarnation of Advent of Code, popular programming contest started back in 2015. The author describes Advent of Code (AoC) as "a series of small programming puzzles for a variety of skill sets and skill levels in any programming language you like".
The rules of AoC are quite simple. Starting from December 1st until Christmas, every day at 5 a.m. UTC a new task is released. The tasks consist of two parts, where second part is revealed after you solve the first part, and it is a continuation and/or variation of the first part. You don't submit your code, just the result of your calculation.
The participation in AoC is free (although, if you like it, consider donating), all you need to do is log in with your Github, Google, Twitter, or Reddit account.
If you have never participated in AoC before or you want to prepare yourself for the start of the competition by solving some tasks, take a look at the previous events. To bring you up to speed, we recommend solving any of first 10 tasks of any year, as those are usually easier and can be solved relatively fast.
Advent of Code offers private leadearboards, and Nim has not only one but two of them.
The original Nim private leaderboard has previously filled up to the maximum of 200 users. We have opened a new private leaderboard, which you can join by using 681448-60235f8f code on this link.
If you have joined one of these leaderboards in previous years, there's no need to do it again — you're already in.
In this thread you can post links to your AoC repositories, share your solutions, ask for help, discuss the tasks, etc.
People usually share their solutions on r/adventofcode subreddit and we encourage you to share your Nim solutions there too and showcase the beauty of Nim.
If you're sharing your solutions via Twitter, use #AdventOfNim hashtag and/or mention @nim_lang.
You can also use Nim IRC/Gitter/Discord channel (https://discord.gg/7RsJ5uEN, #aoc channel) if you have some Nim-related problem, but have in mind that your snippets might contain spoilers for other who haven't solved the task yet — not everybody will be able to solve the tasks at 5 a.m. UTC. Consider waiting at least couple of hours before asking for help (in that time, try it some more to see if you can solve it by yourself :)).
Have fun!
yeeeee, it's 🎄👑advent of nim time! that time of the year where I am miraculously excited to get out of a bed at 6 am! 😂 I plan to blog about my solutions in nim in my usual repo here: https://github.com/pietroppeter/adventofnim
I also plan to share the link to my solutions in reddit daily threads and likely on twitter, it is a good way to have some interests in nim from outsiders. The adventofcode reddit is definitely worth it during advent of code, lots of people sharing fun or impressing stuff (often both)!
hopefully I will also improve the site, but the main goal for this year is to have fun doing visualizations with https://github.com/pietroppeter/p5nim
🌸👑p5nim is a wrapper of p5.js, a great library (+ ecosystem + community) to visualize and animate stuff, mostly targeting beginners, designers, artists. I picked up some old bindings which were not working, fixed them, adding features (added support for saving a gif that came with a recent p5js release, that will come handy to share on twitter), started adding some examples (love this) and improving the api from nim point of view (some great work has been done recently by @vindaar on instance mode that I plan to use to have multiple p5 instances in the same page). There are still a few rough edges and missing stuff, the idea is that using it in advent of code will help me clean this up and make a proper release.
@PMunch, your streams are great, glad you keep them up!
some generic useful refs:
I'm in for sure, AOC is always good fun, especially in Nim.
https://github.com/auxym/AdventOfCode
Young kids mean programming time is limited. I'll probably get the first couple days in time, and finish it up after christmas. Still managed to solve all days except 24 last year!
I will be uploading my solutions here.
https://gitlab.com/al1ranger/aoc2022
Most likely I will not be able to complete all the challenges during the event, but I plan to do the unsolved ones afterwards.
I'm in a similar situation as some others: I probably won't have time to do all the days as they come.
I plan to share my answers here: https://github.com/bobgeis/aoc2022
I never participated in Advent of Code, but this year I decided to do it and see how it works. I hope it's productive.
My solutions will be here.
Just seeing this thread now, but I've been posting my solutions in this repo. Most days I've used Nim but there are a few Crystal solutions too, especially in the earlier days before I got too lazy. A few times I used ChatGPT to translate my solutions from one language to another. It produces sort-of-mostly correct Nim which is amazing really.
Just for fun I added a little benchmark script using hyperfine, but so far the problems have been very computationally easy so they don't really tell us anything. But I know my Nim solution for today (day 11) is more than 100x faster than someone's Python solution I watched in a stream recording later. Also, I'm really impressed with Nim's memory usage. I'm using --gc:orc but it's frugal either way.
Really enjoying this so far.
so that hack for popping an item out of a set[T].?
someone asked how on stackoverflow and i got nerdsniped and wrote a simd-vectorized fully generic version.
tldr:
min time avg time std dv runs name
0.061 ms 0.069 ms ±0.004 x1000 mod 32 == 0, vectorized
18.571 ms 22.570 ms ±1.302 x219 mod 32 == 0, naive
0.068 ms 0.072 ms ±0.002 x1000 mod 32 == 31, vectorized
18.892 ms 22.742 ms ±0.485 x221 mod 32 == 31, naive
0.791 ms 0.836 ms ±0.016 x1000 mod 32 == 31, clz only
I saw that Noulith has
x max= y
as a (conceptual) shortcut for
x = max(x, y)
which is often handy for AoC in particular.
And just realized you can write that in Nim, for example:
proc `>>=`[T](currentMax: var T, newValue: T) =
if currentMax < newValue:
currentMax = newValue
As you know, if you want it to be an infix operator that does assignment there are some constraints about the symbols you can use in the name, but it works!
You may already be aware of this, but if you don't want to use symbols, you can make a max= proc in nim:
proc `max=`*(a: var int, b: int) = a = max(a,b)
var x = 5
let y = 7
x.max= y
assert x == 7