Hacker News new | past | comments | ask | show | jobs | submit login

Going to use it to learn a bit of Ada. I've always been curious about it. It's not a popular language, and it has some serious documentation problems. Sure, there are guides for "hello, world" and other basics, but how to use a generic integer vector or even how to read lines with two numbers from stdin or a file? That was a bit of a puzzle. I saw a solution that allocates an array of 99999 elements, just to track the number of occurrences of each number in the input.

Ada took me somewhere between 90-120 minutes, whereas I had the first problem done in JavaScript in about 30s-60s, just for verification.




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 as expected, put it in a loop and you'll get all of them:

  1 2
  3      4
  5
       6
Sometimes thinking about lines is a red herring in AoC, the lines often don't matter, only getting each value into the appropriate collection (a pair of vectors in this case since you don't know the size). For the counts, you can use a hashed map, they're built into the standard library. If you learn to use them now that'll help you out in later days, they're a commonly used collection (for me) in these challenges.


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.




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: