From: Mace Ayres <mace.ayres@gmail.com>
Subject: Re: Arrays, slices, case, and ‘in’ strategies
Date: Sat, 30 Dec 2017 15:52:34 -0800 (PST)
Date: 2017-12-30T15:52:34-08:00 [thread overview]
Message-ID: <3a9443fe-9540-4124-8fac-16f7ef96c810@googlegroups.com> (raw)
In-Reply-To: <lyy3lkcdum.fsf@pushface.org>
On Saturday, December 30, 2017 at 9:41:56 AM UTC-8, Simon Wright wrote:
> Simon Wright <simon@pushface.org> writes:
>
> > Mace Ayres <mace.ayres@gmail.com> writes:
> >
> >> if ... OR also, the cell/record has a field with its triad, a constant
> >> property.
> >
> > Don't understand this.
>
> Oh, I see, it's Sudoku, and those are the given cells.
>
> Anyway, this looks simple enough for checking whether the value is
> already in the block:
=============
Thanks Simon. This is exactly what I needed. My thoughts were moving toward the rythm of threes and increments in start and length of each block, but it would have taken me a while toga to the parenthesized leitmotif you capture.
Excellent!
Are you a professional Ada programmer?
=====================
>
> function Check_Block (For_Value : Integer;
> At_Row : Grid_Coordinate;
> At_Column : Grid_Coordinate;
> In_Grid : Grid) return Boolean
> is
> Row_First : constant Grid_Coordinate := ((At_Row - 1) / 3) * 3 + 1;
> Col_First : constant Grid_Coordinate := ((At_Column - 1) / 3) * 3 + 1;
> begin
> for Row in Row_First .. Row_First + 2 loop
> for Col in Col_First .. Col_First + 2 loop
> if In_Grid (Row, Col).X = For_Value then
> return False;
> end if;
> end loop;
> end loop;
> return True;
> end Check_Block;
next prev parent reply other threads:[~2017-12-30 23:52 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-30 0:51 Arrays, slices, case, and ‘in’ strategies Mace Ayres
2017-12-30 8:34 ` Jacob Sparre Andersen
2017-12-30 17:20 ` Mace Ayres
2017-12-30 17:30 ` Mace Ayres
2017-12-30 9:58 ` Jeffrey R. Carter
2017-12-30 17:32 ` Mace Ayres
2017-12-30 10:55 ` Simon Wright
2017-12-30 17:12 ` Mace Ayres
2017-12-30 17:41 ` Simon Wright
2017-12-30 23:52 ` Mace Ayres [this message]
2017-12-31 9:09 ` Simon Wright
2017-12-31 20:14 ` Robert Eachus
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox