Live data from Hacker News

Advent of Code 2024

adventofcode.com

511–520 of 580 posts

Re: Advent of Code 2024

#511

Earlier quoted context omitted.

AmigaOS has no memory protection whatsoever. If your program crashes, so does the entire machine. And it will possibly bring your hard drive with it, too. Not unworkable, but not the most relaxed environment for fast’n’fun cowboy coding. You typically have to reboot a lot.

I thought the Amiga 1k had page protection, just not virtual memory?

No, there's no MMU.

Re: Advent of Code 2024

#512

Earlier quoted context omitted.

the input parsers don't get increasingly complex over the days. The problems themselves do. Even on the most difficult days around 22 or 23, the inputs are all just lines of space separate ints or some grid of points or something, just like the trivial problems on days 1-3

From last year: hot springs, the pipes problem, gears, pulses, range math.. half the problem is turning the text input into the correct data structures to solve it.

yes, that kinda is what the reality of programming is. Correctly representing the problem so that the solution easily follows. Various famous people have various quotes about this, for example Rob Pike: "if you've chosen the right data structures and organized things well, the algorithms will almost always be self-evident".

Re: Advent of Code 2024

#513

Earlier quoted context omitted.

- bsearch + qsort is a great way to implement associative tables - you can implement a hash table in C in about 125 LOC and reuse it. - hash tables are not the only way to solve problems. hammer/nail

> bsearch + qsort is a great way to implement associative tables Only if you write/read your table in two separate passes. A tally needs mixed read/write to increment a counter, not just insertion, so it must be kept sorted during the table creation. Some kind of tree or linked list is probably better in this case. > you can implement a hash table in C in about 125 LOC and reuse it. I know. Anyone who uses C and neve…

> incremental insert vs two pass

Insert each element in its sorted position. It will only degenerate if there are many more inserts than lookups, in which case a hash table would do nothing for you.

This could also be a good case for a radix structure.

> void* hash table

I would stay far from poor implementations of high level languages. Why use C if you want generics?

A reusable hash table can be implemented by implementing open addressing with 64 bit integer keys. Then if you have a fancy type you write a hash function and perform linked list chaining on the values.

Another way is to treat the keys as byte arrays.

> seemed the most intuitive way for the 2nd part.

Intuition is a kind of familiarity. There is no reason to learn C if you just write the techniques you already know in a less safe and more verbose way. You instead should be learning a new way to think about problems.

Re: Advent of Code 2024

#514

Earlier quoted context omitted.

What's so hard about Day 12? It's just +/'{x:".",x;H:(-1+;1+i-)@'+|\m*i:!#m:x=\:"#." R:(x=x)({[h;d;x;y;z](z#0),+\(((-z)_~"#"=x)&z_d>z)*(*y),(-z+1)_y-0^y h}. H)[x]/y (*|R)-R@*|0,&1_*+m}.''1({("?"/:5#,x;,/5#,y)}.')\@[;1;.:]'" "\:'0:`:i/12.txt

Any idea how close that is to valid J code?

My limited understanding is that K and J are very different, despite both being in the same language family. I found K a lot easier to grasp when I was playing with both languages years ago.

Re: Advent of Code 2024

#515

Earlier quoted context omitted.

Personally I loathe golang for the sheer fact that it was created recently enough to have included a much better design. Old languages get a pass. Rust to me is what a modern take on a systems language would be. I think it’s substantially better than go.

To be fair, Go was never a proper "systems language" (and shamefully attempted to redefine what the term means).

I don't think it attempted to redefine the term, but "web" was left off the beginning of the phrase. Go's primary strength is in creating distributed, concurrent services and other networked systems. This makes sense as a language born within Google, though like any language it can be used for other purposes.

Re: Advent of Code 2024

#516

I love AoC! Did it the last 2-3 years in Rust, hanging out in a discord where we all try to make the absolute fastest solutions. Learnt all kinds of crazy performance hacks and some advanced algorithms & SIMD that way. This time I'm trying to do them in Rust and Golang in an effort to either learn to like/tolerate Golang (because we use it at work) or prove my hypothesis that it sucks and never use it unless I have t…

How do you structure your aoc project?

I tried doing Rust, but I'm too dumb to figure out if each day should be a module or if I should use lib (I guess?) files for each day and link everything to a main entry point.

Can you share your repo (if public)?

Re: Advent of Code 2024

#517
post #378

Earlier quoted context omitted.

Claude will do it for you.

What is the point in doing a programming challenge if you aren't learning anything

For me, it's my ability to give feedback directly to a dev team building out an imperative language for use in our products: what was easy, what's a PITA, what are big, glaring gaps making things impossible, etc.

Re: Advent of Code 2024

#518
post #159

I usually do AoC in Common Lisp, but this year I'm giving Swift a chance. It's not half bad at this kind of twiddling for being a statically typed mainstream language. https://github.com/codr7/aoc24/tree/main/swift/Sources/aoc This year is a tiny bit weird, I was just getting ramped up organizing the event at a new job; because I think it's very useful for devs to learn some real problem solving, as opposed to stitch…

Are you writing the solutions / compiling / running all with Emacs? I wanted to try Swift this year as well but feels sort of silly spinning up XCode for this.

You can use VSCode with a swift project created with the SwiftPackageManager (SPM). I find the experience to be good, with a good LSP support. I just have to sometimes trigger the build task for it to find newly defined objects.

That is if you have nothing against using VSCode.

Re: Advent of Code 2024

#519

I love AoC! Did it the last 2-3 years in Rust, hanging out in a discord where we all try to make the absolute fastest solutions. Learnt all kinds of crazy performance hacks and some advanced algorithms & SIMD that way. This time I'm trying to do them in Rust and Golang in an effort to either learn to like/tolerate Golang (because we use it at work) or prove my hypothesis that it sucks and never use it unless I have t…

How do you structure your aoc project? I tried doing Rust, but I'm too dumb to figure out if each day should be a module or if I should use lib (I guess?) files for each day and link everything to a main entry point. Can you share your repo (if public)?

Take a look at my repo - http://github.com/nindalf/advent-2024

Each day is a new module, this way I don't have to think of new names for part1() and part2(). I can still import code from the rest of the crate if I want with `use crate::`.

If you like this style of structuring the project, you may be interested in the generator I use for it - http://github.com/nindalf/aocgen. `aocgen --day 2` will create these files and save you a bit of time. It will even download your problem input if you give it your adventofcode.com cookie.

Also check out https://codspeed.io/advent/day/1 for other Rust solutions that are aimed at being fast. They all use the same project structure. I wouldn't read the top 20 solutions though, they sacrifice readability and idiomaticity for speed.

Re: Advent of Code 2024

#520
AOC follows "Tony's Law of Comprehending Things on the Internet": Reading the content from bottom to top is the most efficient way to grok the content.
Post reply on HN