Live data from Hacker News

Advent of Code 2024

adventofcode.com

371–380 of 580 posts

Re: Advent of Code 2024

#371
post #359

Earlier quoted context omitted.

Ada.Integer_Text_IO with Get will happily read across all whitespace, including new lines, to find the next integer. This is true for most (all?) instances of Get , though that may not always be what you want. with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure main is Left : Integer; Right : Integer; begin Get(Left); Get(Right); Put(Left); Put(Right); end main; If you give it any of these pairs it'll work a…

I know that now, even though some of the details remain fuzzy (Get_Line reads 100 characters?), but it's just that the documentation is a big pile of facts with very little to guide you towards the right function/type. And then to get it to use in the rest of the code. And of course, many 'modern' helpers are simply not available, so that too takes a bit of time to find out. But that's learning.

It stops at 100 or the length of the supplied string or the end of the line, whichever is shorter. You can also use unbounded strings which allows you to skip specifying the size for the output.

  with Ada.Strings.Unbounded.Text_IO;
  use Ada.Strings.Unbounded.Text_IO;

  with Ada.Strings.Unbounded;
  use Ada.Strings.Unbounded;

  procedure main is
    Line: Unbounded_String;
  begin
    Line := Get_Line;
    Put_Line(Line);
  end main;
https://learn.adacore.com - good source of tutorials, unfortunately a lot of the better learning materials beyond this are books, not online tutorials.

Re: Advent of Code 2024

#373
post #325

This years challenge for me: write it in C without the standard library or an allocator. Has to be runnable on an STM32 with 32kb of SRAM. I tried doing it in Assembly two years ago, ended up spending hours and hours writing an Assembly standard library, then gave up and switched to Rust...

Symmetrically, I would consider only using sh and standard non-Turing-complete CLI tools (grep yes, awk no). About as limiting, but without devastating memory corruption bugs.

Awk is turing complete. You could do the challenges only in Awk if you wanted.

Re: Advent of Code 2024

#375
post #325

Earlier quoted context omitted.

Symmetrically, I would consider only using sh and standard non-Turing-complete CLI tools (grep yes, awk no). About as limiting, but without devastating memory corruption bugs.

Awk is turing complete. You could do the challenges only in Awk if you wanted.

That would be too easy! :)

Well, awk suffices to write a first-person shooter: https://news.ycombinator.com/item?id=34442528

Re: Advent of Code 2024

#376

Earlier quoted context omitted.

Good luck! Personally, I'm still going with CL but decided to try it in all the languages I "know" for the first day. Including C which doesn't have hash tables (inb4 hsearch)... what a pain, let me tell you. https://git.sr.ht/~q3cpma/aoc2024/tree/master/item/01 If you could post a repo link so I can look at some of the progress, I'd be grateful.

I don't think there are enough entries to make it worth the cost of a hash. I know it's not "efficient" exactly, but just repeatedly looping through and counting just isn't that slow.

The numbers are so small that you can also just use a big array

Re: Advent of Code 2024

#380
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 to.

Post reply on HN