how to get all elements of the blocks in prolog? the size can change dynamic in my code, so the blocksize differs, 4x4 = 4 elements, 9x9= 9 elements etc. the blocks are cut into squares, so in 4x4 the horizontal length is round(sqrt(4))= 2 and vertical length of the block is round(sqrt(4)) = 2. and 9x9 ... sqrt(9).. so height and width of the blocks are 3. i need an algorithm to get the elements efficient.
my sudokulists are build up this way:
L=[ [4,3,1,2], [2,1,4,3], [3,4,2,1], [1,2,3,4] ],
so a list, with lists of the rows in sudoku. checking rows and columns is no problem, -> all_different check with rows, transpose the whole List, all_different check with the transposed list.
but because of the dynamic size of the sudoku, i cannot code fix code for the blocks. so anyone any idea? i thought about flatten(L) and working with offsets to get the correct blocks, but it seems pretty hard to do that this way?
please help me!
A possible solution goes as follows (assuming you have blocksizexblocksize blocks of size blocksizexblocksize - in standard sudoku all numbers are equal, can be adjusted to match other layouts)
a = [],...,[] be a list of blocksize buckets.blocksize parts.a completelyblocksizexblocksize blocksIn your example:
L=[ [4,3,1,2], [2,1,4,3], [3,4,2,1], [1,2,3,4] ]
Partitions => [[4,3] [1,2] [2,1] [4,3] [3,4] [2,1] [1,2] [3,4]]
Bucketed => [[4,3] [2,1] [3,4] [1,2]] [[1,2] [4,3] [2,1] [3,4]]
Flattened => [4,3,2,1,3,4,1,2,1,2,4,3,2,1,3,4]
Partitioned => [4,3,2,1], [3,4,1,2], [1,2,4,3], [2,1,3,4]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With