On and off for around 2 years now, I have been attempting to make a program here on snap that can solve takuzu puzzles (i saw loucheman had made one already which is really cool but i don't yet understand the concepts necessary to solve this and the amount of code within the "resolve" block made chrome unresponsive for a good 10 seconds, so its quite a lot to unravel.)
So far, my solver can check if there are 2 of the same number on either side of the current cell, and if there is, it sets that cell to the opposite number. 1_1 = 101, 0_0 = 010. It can also check if there are 2 consecutive numbers. 11 = 0110, 00 = 1001.
Getting to this point wasn't that bad. All I really had to do was figure out how to navigate 2D lists, which still horrify me but i actually know how to deal with them now. (sort of.)
Now, I'm stumped. I don't know where to start with actually finishing it. You generally can't solve takuzu puzzles with just those two checks - 2 in a row and 2 on each side. There are still going to be many blank cells. So, after it repeats those checks for the entire grid until it doesn't change it anymore, it sets the original grid (not proud of it but there are 2 separate copies of the main starting puzzle: "start" var and "edited puzzle" var. The "start" var is for checking if the current cell was filled in at the start, and if it is, it will not change that cell and skip to the next one. "edited puzzle" is where the actual solving happens.) to the current edited puzzle, because you can't go wrong with those 2 checks, and they don't need to be checked anymore for being updated.
quick note before i end this: i just took a random unsolved 8x8 binary puzzle and set the list to that. figured someone would ask why its just arbitrarily filled and thats why
Im losing track of what I'm writing at this point, it's 8 am at school and i was not expecting to write a multi-paragraph plea for help on the Snap! forums. Here's the project: Takuzu Solver (WIP ARCHIVE FOR FORUMS)
The takuzu should be solveable... not sure your's is solveable...
from your project:
try with this one:
The rules (wikipedia)
Each row and each column must contain an equal number of 0s and 1s. Therefore, if the required number of 0s or 1s is reached in a row or a column, the remaining cells must contain the other digit (1xx101 → 100101).
More than two of the same digits can't be adjacent. Therefore, if two adjacent cells contain the same digit, the cells next to the digits must contain the other digit (xxx00x → xx1001). Likewise, if two cells contain the same digit with one empty cell in between, this empty cell must contain the other digit, because otherwise three same digit appears (x1x1xx → x101xx).
Eliminate the impossible. For example, if the sixth cell in 110xxx is made a 1, balancing the number of 0s and 1s forces a trio to appear (110xxx → 110xx1 → 110001), so it can't be a 1. Therefore, the sixth cell must contain a 0 (110xxx → 110xx0).
Each row and column is unique (100101 & 1001xx → 100101 & 100110).
you have to test differents strategy: cell strategy, line strategy, culums strategy (same as line strategy but for column)
did you already play to takuzu in a book or online ?
I was able to solve the one in my project. Although that one looks more... varied? I think that one would be better for testing. And yes, I have played takuzu before. Theres this brain puzzles book that has a bunch of puzzles, and takuzu happened to be one of them. (in the book its called "binary puzzle" idek how i found that its called takuzu)
...also please ignore the comment in the project i dont even know what i was trying to say there. this project has been driving me insane. getting rule 2 to be checked (the 0x0 and x00x rules) was pretty easy, just had to get the 2d list stuff working, but doing the rest of the solving... i don't know where to start. (yes i could look at your project and just analyze the code you have but thats no fun)
i may end up doing something with random numbers but like... thats boring. and also i may have had an idea.