Skip to main content


I just made a git repo for my #AdventOfCode solutions, so if any of you wanna see my spaghetti code you can find it here on #Codeberg - codeberg.org/rokosun/AOC

I'm using the #Nim programming language since I started learning it a while ago, still very much a beginner tho ๐Ÿ™ƒ

P.S. Also check out @amin's private leaderboard for #AOC - alpha.polymaths.social/@amin/sโ€ฆ

#AdventOfNim


For people doing Advent of Code, I have a Private Leaderboard of Fediverse people you're welcome to join!

Join code is 382566-472d5a9a.


This entry was edited (9 months ago)

Rokosun reshared this.

in reply to Rokosun

cc: @sotolf @esh wanna see some spaghetti code in Nim? ๐Ÿ˜„
in reply to sotolf

@sotolf @esh Well I'm trying to improve it in time so hopefully it gets better ๐Ÿ˜„
in reply to Rokosun

I've done all of mine so far in gleam :p so I'm not sure how helpful they would be since they look kind of different:

bin.benjaminhollon.com/tifirtrโ€ฆ

But in a way the language has kind of a similar feel, weirdly enough.

in reply to sotolf

@sotolf @esh

I'll take a look at this, I'm interested in seeing different people's solutions even tho I may not fully understand the language they use, most programming languages tent to have some familiarity with each other so you can make a pretty good guess.

in reply to Rokosun

Well done @Rokosun ! Great that you use #Nim for it! I am skipping this year, too busy at work, but it's a very good practice ๐Ÿ’ช
in reply to Roma

@esh I've actually just finished doing day 4 now, see my code ๐Ÿ™‚ - codeberg.org/rokosun/AOC/src/bโ€ฆ

@sotolf helped me learn custom types in Nim and so far it has been very useful in solving these puzzles and keeping my code more neat and organized in general.

in reply to Rokosun

@amin ah, there you hid your code, personally I would have defined types and parsed it into that first, and then work on that instead of crunching everything ito one omnifunction ;)
@amin
in reply to sotolf

@sotolf @amin

Yeah I'm not familiar with using custom types or objects because my experience with programming so far had been writing shell scripts on Linux - which doesn't support either of those, lol ๐Ÿ˜… So yeah, I'll probably need some practice before I can get into the Nim way of thinking. Thanks for your suggestions BTW ๐Ÿ™‚

in reply to Rokosun

@amin Yeah, it's really worth doing, using object makes your code readable and a lot easier to deal with for yourself as well, I have some examples from my older advent of code that is in nim if you are interested too :)
@amin
in reply to sotolf

@sotolf @amin

Some other folks have also shared their Nim code for this year's AoC so that's gonna come handy - forum.nim-lang.org/t/10717

This might sound like a stupid question, but I'm a bit confused between objects and custom types in Nim - do I actually need to use an object here or would a custom type with named tuples be enough?

in reply to Rokosun

@amin

Here you go, this is how I would have solved day 2 in nim:

I like to keep things as readable for myself as possible for later, and so that it's a lot easier to debug when you inevetably will have to do it :)

bin.benjaminhollon.com/orrivalโ€ฆ

@amin
in reply to Rokosun

@sotolf @amin

Wow your code looks much better and well structured than mine. I still find it a bit hard to wrap my head around these custom types and things but I understand why it can be beneficial - it feels like the initial part of your code that defines all the custom types and the procedures used to parse them provides a sort of scaffolding that makes the rest of the code more easy to manage, I also like how modular everything is compared to my "omnifunction" ๐Ÿ˜„

in reply to Rokosun

@amin yeah, that's exactly how I'm thinking how can I represent the data, and then how can I get closer to what I want, or functions I need to do what I need. My way is just one way to do it, but it's the one I find the easiest to work with :)

Types are a bit daunting in the beginning but when you do they really help you think, and let's the compiler help you not do a quite big group of errors :)

@amin
in reply to sotolf

@sotolf @amin

I think I also learned some new Nim features from your code, for example I was surprised to see how you defined the CubeSet type on line 13 - is Nim using the Color enum for indexing its arrays?! I had no idea this was possible!

โ‡ง