After seeing @stevon8ter post on Binairo, that got me thinking about the solutions for that type of puzzle. So here is a totally useless program that displays all of the solutions for a 6x6 puzzle. A 6x6 square can have 2^36 combinations of 0’s and 1’s. That was a little too many tries to go thru, so I just selected the valid combinations of 0’s and 1’s that worked for a single row. That turned out to be 14 combinations. So, using those 14 combinations on 6 rows amounts to 14^6 combinations or 7,529,536 tries, which was reasonable. So if you run this, it will go thru all 7,529,536 combinations and show 11,222 solutions. Of course there are less solutions or duplicates if you rotate a puzzle, but I’m not excluding those. The program is set up to stop after each solution, tap screen for next solution. Or you can slide “stop” to “off” and it will show each solution without stopping. All of the processing is done from draw(), so there will be times when the display doesn’t seem to be updating. That’s because it’s trying to find the next solution before exiting draw(), which will then update the display. After writing this, I tried an 8x8 puzzle. That has 2^64 combinations. I selected all of the combinations just for a single row, and that turned out to be 34. So 34^8 turned out to be 1,785,793,904,896 tries. That’s a little too many to do, so I gave up on that idea. If you turn “stop” to “off” and run this, it takes about 21 minutes to complete. I have a different way of doing this, so maybe the next time I have nothing better to do, I’ll try that and see if it’s faster.
EDIT: changed the code to eliminate duplicate rows or columns
function setup()
parameter.boolean("stop",true)
print("Searching for a solution.")
print("\
When a solution is showing,")
print("tap the screen for the next")
print("solution. Some solutions may")
print("take several seconds before")
print("they show.")
print("\
\
Sliding the 'stop', parameter to")
print("'off' will show the solutions")
print("without stopping.")
done=false
solved=false
tries=0
solutions=0
colTab={}
tab={{0,0,1,0,1,1},{0,0,1,1,0,1},{0,1,0,0,1,1},{0,1,0,1,0,1},
{0,1,0,1,1,0},{0,1,1,0,0,1},{0,1,1,0,1,0},{1,0,0,1,0,1},
{1,0,0,1,1,0},{1,0,1,0,0,1},{1,0,1,0,1,0},{1,0,1,1,0,0},
{1,1,0,0,1,0},{1,1,0,1,0,0} }
tab1={1,1,1,1,1,1}
getBin()
end
function draw()
background(40,40,50)
fill(255)
if done then
text("Done",200,700)
else
while not solved do
tries=tries+1
add()
if not done then
solve()
end
end
if not stop and solved then
solved=false
end
show()
end
text("Solution "..solutions,200,650)
text("Tries "..string.format("%d",tries),200,600)
end
function show()
c=0
for z=1,6 do
for y=1,6 do
c=c+1
text(tab2[c],100+y*40,500-40*z)
end
end
end
function solve()
if dupRows() then
return
end
if dupCol() then
return
end
for z=1,6 do
diff=0
zero=0
one=0
zeroes=0
ones=0
for y=1,6 do
if tab2[diff+z]==0 then
zero=zero+1
zeroes=zeroes+1
ones=0
if zeroes>2 or zero>3 then
return
end
else
one=one+1
ones=ones+1
zeroes=0
if ones>2 or one>3 then
return
end
end
diff=diff+6
end
if zero~=3 or one~=3 then
return
end
end
solved=true
solutions=solutions+1
end
function dupRows()
for x=1,6 do
for y=x,6 do
if x~=y then
if tab1[x]==tab1[y] then
return true
end
end
end
end
return false
end
function dupCol()
for z=1,6 do
dd=0
colTab[z]=0
for y=1,6 do
if tab2[dd+z]==1 then
colTab[z]=colTab[z]+2^(6-y)
end
dd=dd+6
end
end
for x=1,6 do
for y=x,6 do
if x~=y then
if colTab[x]==colTab[y] then
return true
end
end
end
end
return false
end
function add()
carry=0
for z=6,1,-1 do
tab1[z]=tab1[z]+1
if tab1[z]>#tab then
carry=1
tab1[z]=1
if z==1 then
done=true
solved=true
return
end
else
getBin()
return
end
end
end
function getBin()
tab2={}
for z=1,#tab1 do
for y=1,6 do
table.insert(tab2,tab[tab1[z]][y])
end
end
end
function touched(t)
if t.state==BEGAN then
solved=false
end
end