comp.lang.ada
 help / color / mirror / Atom feed
* Advent of Code day 5
@ 2020-12-05 14:54 Stephen Leake
  2020-12-05 15:16 ` John Perry
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Stephen Leake @ 2020-12-05 14:54 UTC (permalink / raw)


that was trivial
-- 
-- Stephe

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  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-06  9:14 ` Jeffrey R. Carter
  2 siblings, 1 reply; 12+ messages in thread
From: John Perry @ 2020-12-05 15:16 UTC (permalink / raw)


On Saturday, December 5, 2020 at 8:54:31 AM UTC-6, Stephen Leake wrote:
> that was trivial 
> -- 
> -- Stephe

Agree, though I stumbled over Count_Type for a while. (Learning, sorry.) Did you do anything interesting? Your GitHub page is still on Day 4.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-05 14:54 Advent of Code day 5 Stephen Leake
  2020-12-05 15:16 ` John Perry
@ 2020-12-05 15:56 ` Jeffrey R. Carter
  2020-12-05 17:57   ` John Perry
  2020-12-06  9:14 ` Jeffrey R. Carter
  2 siblings, 1 reply; 12+ messages in thread
From: Jeffrey R. Carter @ 2020-12-05 15:56 UTC (permalink / raw)


On 12/5/20 3:54 PM, Stephen Leake wrote:
> that was trivial

Especially in Ada.

That's one big plane, though.

-- 
Jeff Carter
"Premature optimization is the root of all evil ..."
Donald Knuth
182

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-05 15:56 ` Jeffrey R. Carter
@ 2020-12-05 17:57   ` John Perry
  2020-12-05 19:03     ` Jeffrey R. Carter
  0 siblings, 1 reply; 12+ messages in thread
From: John Perry @ 2020-12-05 17:57 UTC (permalink / raw)


On Saturday, December 5, 2020 at 9:56:31 AM UTC-6, Jeffrey R. Carter wrote:
> On 12/5/20 3:54 PM, Stephen Leake wrote: 
> > that was trivial
> Especially in Ada. 
> 
> That's one big plane, though. 

According to the Internet (And Therefore It Is True (TM)) the A380 can seat up 853 people. My problem had up to 894 seats, with the first 5 missing, so it wasn't that far beyond the realm of reason.

Then again, I don't know if anyone would want to fly an A380 configured for 853 people.

john perry

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-05 17:57   ` John Perry
@ 2020-12-05 19:03     ` Jeffrey R. Carter
  0 siblings, 0 replies; 12+ messages in thread
From: Jeffrey R. Carter @ 2020-12-05 19:03 UTC (permalink / raw)


On 12/5/20 6:57 PM, John Perry wrote:
> 
> According to the Internet (And Therefore It Is True (TM)) the A380 can seat up 853 people. My problem had up to 894 seats, with the first 5 missing, so it wasn't that far beyond the realm of reason.

That's many. I was thinking around 800.

The max seat ID in my input was 848, but I was thinking more in terms of the 
range of seat IDs having 1024 values.

-- 
Jeff Carter
"Premature optimization is the root of all evil ..."
Donald Knuth
182

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-05 14:54 Advent of Code day 5 Stephen Leake
  2020-12-05 15:16 ` John Perry
  2020-12-05 15:56 ` Jeffrey R. Carter
@ 2020-12-06  9:14 ` Jeffrey R. Carter
  2020-12-06 14:09   ` Björn Lundin
  2 siblings, 1 reply; 12+ messages in thread
From: Jeffrey R. Carter @ 2020-12-06  9:14 UTC (permalink / raw)


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?

-- 
Jeff Carter
“[T]here are lots of people out there writing software
that should really be out cleaning toilets instead.”
Brian Catlin
173

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-06  9:14 ` Jeffrey R. Carter
@ 2020-12-06 14:09   ` Björn Lundin
  2020-12-06 16:21     ` Stephen Leake
  0 siblings, 1 reply; 12+ messages in thread
From: Björn Lundin @ 2020-12-06 14:09 UTC (permalink / raw)


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


and ran it through cut/sort/uniq

day_05 | cut  -d' ' -f2 | sort -n | uniq -c

which gave a list on the terminal like


...
    8  61
    8  62
    8  63
    8  64
    8  65
    8  66
    8  67
    8  68
    8  69
    7  70
    8  71
    8  72
    8  73
    8  74

...

and that found my row

then I ran it with grep "^ 70" and got
day_05 | grep "^ 70"
  70 3 563
  70 6 566
  70 5 565
  70 0 560
  70 1 561
  70 4 564
  70 7 567

and saw what seat is free

in the end I saved and printed the max seatid as well



but yes , the encoding was with parsing as binary




-- 
Björn

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-05 15:16 ` John Perry
@ 2020-12-06 16:16   ` Stephen Leake
  0 siblings, 0 replies; 12+ messages in thread
From: Stephen Leake @ 2020-12-06 16:16 UTC (permalink / raw)


John Perry <john.perry@usm.edu> writes:

> On Saturday, December 5, 2020 at 8:54:31 AM UTC-6, Stephen Leake wrote:
>> that was trivial 
>> -- 
>> -- Stephe
>
> Agree, though I stumbled over Count_Type for a while. (Learning,
> sorry.) Did you do anything interesting? Your GitHub page is still on
> Day 4.

Sorry, forgot to push; updated now.

The only thing I had not actually used before was this:

      Map : constant Character_Mapping := To_Mapping ("FBLR", "0101");

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-06 14:09   ` Björn Lundin
@ 2020-12-06 16:21     ` Stephen Leake
  2020-12-06 16:27       ` Stephen Leake
  2020-12-06 21:09       ` Björn Lundin
  0 siblings, 2 replies; 12+ messages in thread
From: Stephen Leake @ 2020-12-06 16:21 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-06 16:21     ` Stephen Leake
@ 2020-12-06 16:27       ` Stephen Leake
  2020-12-06 21:09       ` Björn Lundin
  1 sibling, 0 replies; 12+ messages in thread
From: Stephen Leake @ 2020-12-06 16:27 UTC (permalink / raw)


Stephen Leake <stephen_leake@stephe-leake.org> writes:

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

Or Doubly_Linked_Lists.Generic_Sorting:

http://www.ada-auth.org/standards/2xrm/html/RM-A-18-3.html

--
-- Stephe

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-06 16:21     ` Stephen Leake
  2020-12-06 16:27       ` Stephen Leake
@ 2020-12-06 21:09       ` Björn Lundin
  2020-12-09  1:18         ` Stephen Leake
  1 sibling, 1 reply; 12+ messages in thread
From: Björn Lundin @ 2020-12-06 21:09 UTC (permalink / raw)


Den 2020-12-06 kl. 17:21, skrev Stephen Leake:
> 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

So I was thinking -should I do this the 'proper' way - only use a 
language, or should I use whatever tool that makes it quickest, since 
only a number was the final answer.

This way, I did it quicker than implementing all if it in ada,
and I got a good grip of what was happening, by adding the pipes  one by 
one.

This is of course why I posted. Sometimes a combination of tools
gets you (or actually me) faster to the goal.

I haven't used generic_arrray_sort much, but I've done quite some
sorting on Ada.Containers.Doubly_linked_Lists - and I think they are 
close in howto use. But - I think those external tools were faster for me.


-- 
Björn

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Advent of Code day 5
  2020-12-06 21:09       ` Björn Lundin
@ 2020-12-09  1:18         ` Stephen Leake
  0 siblings, 0 replies; 12+ messages in thread
From: Stephen Leake @ 2020-12-09  1:18 UTC (permalink / raw)


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

> Den 2020-12-06 kl. 17:21, skrev Stephen Leake:
>> 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
>
> So I was thinking -should I do this the 'proper' way - only use a
> language, or should I use whatever tool that makes it quickest, since 
> only a number was the final answer.

For the actual competition, any tool that works for you is fine; there
is no restriction to "use only this language".

But some people are doing this as a mechanism to learn Ada, so I'm using
your example to tell them about how to do this in Ada instead of Bash.

In day 7, I'm using WisiToken, which is an Ada parsing library I maintain.
I'm following the rule "use any Ada library available on the web".

-- 
-- Stephe

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-12-09  1:18 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2020-12-06 16:27       ` Stephen Leake
2020-12-06 21:09       ` Björn Lundin
2020-12-09  1:18         ` Stephen Leake

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