comp.lang.ada
 help / color / mirror / Atom feed
From: John Perry <john.perry@usm.edu>
Subject: Re: advent of code day 11
Date: Fri, 11 Dec 2020 10:24:01 -0800 (PST)	[thread overview]
Message-ID: <b4611f34-d553-4f7c-806a-c799cad8cc0bn@googlegroups.com> (raw)
In-Reply-To: <86mtykp8yd.fsf@stephe-leake.org>

On Friday, December 11, 2020 at 11:08:00 AM UTC-6, Stephen Leake wrote:
> mildly interesting; variation on Conway's Game of Life. 

I recognized that, too. A solution should not be hard to parallelize, and I'd like to, but for now I have other tasks. (no pun intended, well, OK yes it was)

Here's a couple of questions for the Ada experts. For each round I used two charts, a source and a result. These are arrays, defined like so:

   type Status is ( Floor, Empty, Occupied );

   type Chart_Array is array( Positive range <> , Positive range <> ) of Status;

   Chart1, Chart2: Chart_Array; -- actually defined with appropriate dimensions

A procedure named `Iterate_Seating` applies the given rules to a Chart_Array; an `if` statement determines which iterates into the other.

I thought it would be clearer to use references to switch from one chart to the other, but I had trouble doing that last night. Now I can get it this way:

   Source: Chart_Array renames Chart1;
   Result: Chart_Array renames Chart2;

   while Changed loop

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

   end loop;

Does this technique swap references, or does it copy the arrays element-by-element? The run times are the same even if I compel a copy operation; I suppose it's because the arrays aren't large enough, and there aren't enough copies, to make a difference.

thanks
john perry

  reply	other threads:[~2020-12-11 18:24 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 [this message]
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
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