Weekly Challenge

Solve the challenge, share your solution and summit the ranks of our Community!
New content is available in Academy! You may need to clear your browser cache for an optimal viewing experience

Challenge #200: Sudoku Solver

Highlighted
Asteroid

Thanks for taking a look at this John.

 


@JohnJPS wrote:

 grabbing "First" in the Summary tool is not reliable


It only uses that "First" when the count of remaining candidate digits is 1, so I think using First should be fine. When the count is > 1, it replaces First with a "0".

 

The real problem is where none of the "0" cells can be resolved down to a single digit. That then causes the exact same macro output to be fed back into the input, and it loops infinitely.

 

The only way I can think to get around that is to "guess" an answer and see if the puzzle can be completed from there. If it can't, make a different guess and try again. I was wondering if your R-code does that somehow, but I can't see it.

Highlighted
ACE Emeritus
ACE Emeritus

@PaulRB,

Yes, you're correct that it's an infinite loop due to it passing in the same value it started with; if it could instead pass in candidate guesses to iterate over, that might he interesting.

 

I believe the difference in the R code is in the while loop of the sudoku.solve() function. I do not believe the base tools code has that iterative equivalent.

Highlighted
Asteroid

@JohnJPS wrote:

I believe the difference in the R code is in the while loop of the sudoku.solve() function. I do not believe the base tools code has that iterative equivalent.


Comparing sudoku.solve() to my iterative macro, the only difference I can see is that if, for all "0" cells it finds, the R code can't find a solution for any of them, it stops iterating. It gives up rather than looping forever. But clearly that's not happening with this puzzle. In some cases, where my macro can't find a solution for a "0" cell, the R code can.

 

So I think the extra "cleverness" is somewhere in sudoku.square(). I'm not used to reading R code, so I'm struggling to figure out what its doing... I know its not really very important, but its bugging me.

Highlighted
Asteroid

@JohnJPS 

To help me understand what the R code is doing, I am reading the page mentioned at the top of the R-code:

https://www.kaggle.com/dmartin0409/sudoku-solver-in-r 

 

It says:

"2. If step 1 has more than 1 possible value, step through each of these numbers and check the two rows and two columns of the adjacent squares in the 3x3 set. For example, if I'm examining the top left square of a 3x3 set, and I'm trying to see if the number 9 fits in there, look for a 9 in the two columns (middle and right) and the two rows (middle and bottom)."

 

I think this point #2 is what my macro is missing. Points #1, #3 & #4 correspond to the 3 join tools in my macro. Just need to get my head around it!

Highlighted

This was my first challenge!  Will work on trying to solve the Intermediate next...

 

Beginner:

Spoiler
kramberry_0-1580826863724.png
Highlighted
Alteryx Partner

I just started doing the weekly challenges yesterday with challenge #201, but spotted also this very intriguing challenge #200 and had to solve it.

 

I have no idea, whether this is still allowed, but here we go, that's the overview.

AlteryxGui_2020-02-04_16-40-04.png

For the beginner step a simple parser (and a printer for checking the results) is constructed:

Spoiler
AlteryxGui_2020-02-04_16-50-45.png

 

AlteryxGui_2020-02-04_16-51-06.png

 

For intermediate/advanced, a solver macro is implemented.

Spoiler

 

AlteryxGui_2020-02-04_16-40-51.png

 

AlteryxGui_2020-02-04_16-41-11.png

 

I hope this still counts.

 

Best,

 

Johannes 

Highlighted
Asteroid

I got there in the end! Previously unsolvable puzzle now solved.

Spoiler
PaulRB_0-1580837778112.png

 

Highlighted
ACE Emeritus
ACE Emeritus

Very nice @PaulRB ... hey @AYXAcademy and @TerryT, based on Paul's research, consider adding the following quiz to the challenge:

000000190230000600000240000000000960000160070048070000001003405009008000006005800

... it defeats some of the posted solutions.  Very cool and great job Paul - all I did was borrow from Kaggle; you recreated it with base tools. Nice!

 - John

Highlighted
Alteryx Partner

Iterative approach for the advanced, and "CEIL" help for the grid calculation. The assumption is at least one cell can be solved per iteration (i.e. there's a unique value for that cell).

Spoiler
Main WorkflowMain WorkflowIterativeIterativeGrid CalculationGrid Calculation

.  

Highlighted
Meteoroid

my solution for beginner level:

 

Spoiler
ErikaLoz_0-1580987488809.png