m_b_metcalf wrote:Fine. But where is the 'mathematical complexity'? This code, for rows:
- Code: Select all
-       do row = 1, 9
 if(count(sudoku(row, :) == 0) > count(sum(pm(row, :, :), dim=1 ) /= 0)) then
 zero_solutions = .true.
 exit
 end if
 end do
 
thanks for that, to be honest i cannot read the syntax for the "code" per-say so I'm not sure how it functions exactly as i don't use C# code
.... my language of choice is free pascal with turbo pascal enabled... 
i do get that it added up all the pm's across each row and fount out that it was missing a "4"  for the row leaving 6  cells with 5 candidates. 
yes pretty easy zero state check, i over thought it too much,  
i have/had a balancing calculation that shows these areas are always equal in a non "zero" state... 
- Code: Select all
- (R+C+B)*3 * 9 = cells * digits 
 (27)*3*9 =  81 * 9
 729 = 729
the complicated part of my code is that it prevents it from selecting a clue addition randomly into a cell that would generate the above substate. 
for example:  using your grid  i removed the 4 at R5C2 
C2 & box 47  has 2 spots for digit 4 left which is a zero solution state. 
- Code: Select all
- .---------------------.--------------------.------------------------.
 | 1     358     3578  | 4      6     3578  | 2       9       378    |
 | 5678  23568   4     | 1      9     23578 | 35678   35678   3678   |
 | 5678  9       23578 | 237    2357  23578 | 135678  4       13678  |
 :---------------------+--------------------+------------------------:
 | -4689  7       389   | 5      234@   236   | 368     1       23468@  |
 | 2     3456&   35    | 367    8     1     | 3567    3567    9      |
 |-4568  -134568  1358  | 2367   2347@  9     | 35678   235678  234678@ |
 :---------------------+--------------------+------------------------:
 | 3     1248&   12789 | 2679   27    267   | 16789   2678    5      |
 | 579   125     6     | 8      2357  4     | 1379    237     1237   |
 | 5789  258     25789 | 23679  1     23567 | 4       23678   23678  |
 '---------------------'--------------------'------------------------'
notes: the * cells remove all the "-" cells for candidate 4
& represents a grid state check error 
this state exists from a previous clue adding i cannot  guess what order the clues where added  however picking  an easy example is removing the "2" @ 
in short my old code would prevent me from adding any other clue except a "4" @ R5C1 because of the above state, without having to backtrack after adding said clue.
- Code: Select all
- .-----------------------.--------------------.------------------------.
 | 1      358      3578  | 4      6     3578  | 2       9       378    |
 | 25678  23568    4     | 1      9     23578 | 35678   35678   3678   |
 | 25678  9        23578 | 237    2357  23578 | 135678  4       13678  |
 :-----------------------+--------------------+------------------------:
 |-24689  7        2389  | 5      234*   236   | 368     1       23468*  |
 | 2456&  -23456    235   | 2367   8     1     | 3567    23567   9      |
 |- 24568  -1234568  12358 | 2367   2347*  9     | 35678   235678  234678* |
 :-----------------------+--------------------+------------------------:
 | 3      1248*     12789 | 2679   27    267   | 16789   2678    5      |
 | 2579   125      6     | 8      2357  4     | 1379    237     1237   |
 | 25789  258      25789 | 23679  1     23567 | 4       23678   23678  |
 '-----------------------'--------------------'------------------------'
notes: the * cells remove all the "-" cells for candidate 4
& represents a grid state check error
------------------
 most of this is from memory on a code i wrote 3+ years back and haven't reviewed, the idea probably can be scrapped and upgraded with simpler code making it less "complicated " then i originally envisioned.... 
 {once i find a copy of my generator and review it.. the loss of the programmers forum sucks  i had copies posted on there and its all gone.}