comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Advent of Code day 5
Date: Sun, 06 Dec 2020 08:21:24 -0800	[thread overview]
Message-ID: <86sg8igb23.fsf@stephe-leake.org> (raw)
In-Reply-To: rqiong$cus$1@dont-email.me

Björn Lundin <b.f.lundin@gmail.com> writes:

> Den 2020-12-06 kl. 10:14, skrev Jeffrey R. Carter:
>> On 12/5/20 3:54 PM, Stephen Leake wrote:
>>> that was trivial
>> I'm curious: Did everyone do this by treating the input as a coded 
>> 10-digit binary number, or did some take another approach?
>> 
>
>
> I uses it as binary 7 +3, but I did the calculaions through the shell
> text utilities
>
>
> First I decoded and printed all rows, seats and ids like
>
> loop file and decode
>   ...
>   Text_Io.Put_Line (Row'Img & Seat'Img & Id'Img);
> end loop

I didn't bother computing row and seat, since they are not actually
needed to find the answer.

> and ran it through cut/sort/uniq

Next time, try ada.containers.generic_array_sort;
http://www.ada-auth.org/standards/2xrm/html/RM-A-18-26.html

I used a boolean array to do the sort:

   declare
      Present : array (Integer range 1 .. Max_ID) of Boolean := (others => False);
   begin
      for ID of IDs loop
         Present (ID) := True;
      end loop;

      for ID in Present'First + 1 .. Present'Last - 1 loop
         if Present (ID - 1) and (not Present (ID)) and Present (ID + 1) then
            Put_Line ("my seat id:" & ID'Image);
         end if;
      end loop;
   end;

-- 
-- Stephe

  reply	other threads:[~2020-12-06 16:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-05 14:54 Advent of Code day 5 Stephen Leake
2020-12-05 15:16 ` John Perry
2020-12-06 16:16   ` Stephen Leake
2020-12-05 15:56 ` Jeffrey R. Carter
2020-12-05 17:57   ` John Perry
2020-12-05 19:03     ` Jeffrey R. Carter
2020-12-06  9:14 ` Jeffrey R. Carter
2020-12-06 14:09   ` Björn Lundin
2020-12-06 16:21     ` Stephen Leake [this message]
2020-12-06 16:27       ` Stephen Leake
2020-12-06 21:09       ` Björn Lundin
2020-12-09  1:18         ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox