comp.lang.ada
 help / color / mirror / Atom feed
From: "gautier...@hotmail.com" <gautier_niouzes@hotmail.com>
Subject: Re: advent of code day 11
Date: Fri, 11 Dec 2020 11:29:56 -0800 (PST)	[thread overview]
Message-ID: <eb14771e-910b-4ad7-bad9-00928a4eb10fn@googlegroups.com> (raw)
In-Reply-To: <b4611f34-d553-4f7c-806a-c799cad8cc0bn@googlegroups.com>

> Perform_Round( Source => Source , Result => Result , ... ); 
> declare Tmp: Chart_Array renames Source; 
> begin 
> Source := Result; 
> Result := Tmp; 
> end; 

To complete Jeff's answer, what you are doing is not a swap: it's equivalent to 
Source := Result;
Result := Source;
Ooops.
The ":=" makes a complete copy of the arrays.
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;

  parent reply	other threads:[~2020-12-11 19:29 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 [this message]
2020-12-11 19:35     ` gautier...@hotmail.com
2020-12-11 22:40     ` Jeffrey R. Carter
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