comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: advent of code day 11
Date: Fri, 11 Dec 2020 23:40:48 +0100	[thread overview]
Message-ID: <rr0shg$pc4$1@dont-email.me> (raw)
In-Reply-To: <eb14771e-910b-4ad7-bad9-00928a4eb10fn@googlegroups.com>

On 12/11/20 8:29 PM, gautier...@hotmail.com wrote:
> 
> So you'd need above "Tmp : Chart_Array := Source" to have a correct swap with 3 copies.
> Of course it feels a bit heavy to make all those copies. And you understandably want to avoid playing with pointers. So a solution is to define:
> Map : array (0 .. 1) of Chart_Array;
> ...
> current := 0;
> loop
>    next := 1 - current;
>    Perform_Round( Source => Map (current), Result => Map (next) , ... );
>    current := next;
> end loop;

I don't see a need for a swap, or to avoid copying. I did

Current : Floorplan := Read;
Future  : Floorplan := (others => (others => Floor) );
...
All_Rounds : loop
    for R in ... loop
       for S in ... loop
          if Current (R, S) /= Floor then -- It's a seat
             Future (R, S) :=
                Next_State (Current (R, S), Num_Occupied (Current, R, S) );
          end if; -- else Future (R, S) = Floor
       end loop;
    end loop;

    exit All_Rounds when Current = Future;

    Current := Future;
end loop All_Rounds;

which took 34 ms, well within the timing requirements for the problem.

-- 
Jeff Carter
"[I]f we should ever separate, my little plum,
I want to give you one little bit of fatherly advice. ... Never
give a sucker an even break."
Poppy
97

  parent reply	other threads:[~2020-12-11 22:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-11 17:07 advent of code day 11 Stephen Leake
2020-12-11 18:24 ` John Perry
2020-12-11 19:07   ` Jeffrey R. Carter
2020-12-11 19:29   ` gautier...@hotmail.com
2020-12-11 19:35     ` gautier...@hotmail.com
2020-12-11 22:40     ` Jeffrey R. Carter [this message]
2020-12-11 23:45       ` John Perry
2020-12-11 23:49     ` John Perry
2020-12-12  9:38       ` Maxim Reznik
2020-12-12 20:27   ` 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