comp.lang.ada
 help / color / mirror / Atom feed
* Arrays, slices, case, and ‘in’ strategies
@ 2017-12-30  0:51 Mace Ayres
  2017-12-30  8:34 ` Jacob Sparre Andersen
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Mace Ayres @ 2017-12-30  0:51 UTC (permalink / raw)


I have a two dimensional array, gird, 1..9, 1..9 index of integer and array of a record type named cell and array is named grid.  So, a grid is a 9x9 array of record type ‘cell, Cell has some properties, and functions in the containing package to enter, change, values in a field called ‘value. So I can traverse the array named grid with
for row in 1..9 loop
   for column 1..9 loop
     grid(row,column).x := y;      — x is some attribute of the cell/record/object that the array is type of
   end loop; — column loop.     — and y is some value I assign to the x field, of the object cell in the array location (row, column)
 end loop;   — row loop

When attempting to assign a y value to the cell’s x field, I want to to check that the y that is to be assigned to the cell’s x field does not adready exist anywhere adready in all the columns of the row, or all the rows of the target column. Easy enough with function: 

Check_row.(r,c, numb: Integer  ... boolean ..
  begin
   for c in 1..9  loop.              — traverse the row in grid that is passed in with parm r
        if grid(r).value = numb — if if grid(r,c).value = numb.     — numb is passed in also a parm
           then bad.                  — proposed value numb already exists in proposed row to put it in
           return false — not ok
.....
function check_column uses some logic. Both work and are fast enough on my 64bit Mac OS x.

Now, challenge is: besides checking to see if a proposed value (integer 1..0) already exists in the proposed row and column to put it in,
I also have an abstraction of triads superimposed (mentally) on the grid, giving 9 triads layer on top of the 9x9 array called ‘grid.’ The 9x9 grid nicely
holds 9 of these imaginary triads,, ie, first 3 rows and first 3 columns are in triad 1 and first 3 rows and columns 4 to 6 are conceived as triad 2,

I need to check, in addition to whether the proposed ingteger value is already in any cells in that row, or column,  whether the proposed value already
exists in any cell.value field for any cell in triad. The in parameters of r,c can reveal what triad is in question, but it looks like some fat code to to
traverse the abstract 3x3 triads.

I know I could create some triad types of arrays, but I am wondering if I can slice the array grid into 9 collections and then check
loop.. if numb (proposed number) already exists in the triad [this would be determined by row, column in parameters) OR also, the cell/record has a field with its triad,
a constant property.

If this is too convoluted and or not clear, I can just delete the question, but if it’s understandable, best approach recommended appreciated.

           



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

end of thread, other threads:[~2017-12-31 20:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2017-12-31  9:09       ` Simon Wright
2017-12-31 20:14 ` Robert Eachus

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