Author Topic: 01 Puzzle for JB  (Read 1200 times)

B+

  • Guest
01 Puzzle for JB
« on: September 28, 2018, 04:01:39 PM »
While attempting to figure out what bluatigro was trying to solve with his AI, I made a game of the puzzle to get a feel of what a Solver would need to do.

Code: [Select]
'bluatigro 01 Puzzle 2018-09-28 B+ attempt

'This is solved when an equal amount of 0's and 1' are in each row and col
'AND there are no more than 2 0's or 1's in each row or col.
'I think it might be also assumed that at least a 0, 1 pair exist in each row and column.

'puzzle data
data "1.0....."
data ".....0.."
data "....1..1"
data ".11....."
data "0......."
data "....0..1"
data "..00...1"
data ".1....1."

'read in puzzle to numeric array
dim p(8, 8)
for row = 1 to 8
    read dLine$
    for col = 1 to 8
        select case mid$(dLine$, col, 1)
        case "1" : p(col, row) = 1
        case "0" : p(col, row) = -1
        case "." : p(col, row) = 0
        end select
    next
next

global SOLVED
turns = 0
while 1
    call drawP
    if SOLVED = 16 then
        print "Congratulations!!! You solved the puzzle in "; turns; " turns."
        end
    else
        print
        print "To quit: Enter other than 1 to 8 for row,"
        print "         enter other than 1 to 8 for col,"
        print "         or enter other than -1, 0, 1 for array."
        print
        input "   Enter a row to change > "; dr
        dr = int(dr)
        if dr < 1 or dr > 8 then end
        input "Enter a column to change > "; dc
        dc = int(dc)
        if dc < 1 or dc > 8 then end
        input "Enter 0 for a dot, -1 for a zero, or enter 1 for a 1 > "; dn
        dn = int(dn)
        if dn < -1 or dn > 1 then end
        p(dc, dr) = dn
        turns = turns + 1
    end if
wend

sub drawP
    SOLVED = 0
    print
    for row = 1 to 8
        for col = 1 to 8
            select case p(col, row)
            case 0 : print " . ";
            case 1 : print " 1 ";
            case -1: print " 0 ";
            end select
        next
        print "  Row ";row;" = ";sumRow(row)
        if sumRow(row) = 0 then SOLVED = SOLVED + 1
    next
    print
    for i = 1 to 8
        print "C";i;" ";
    next
    print
    for i = 1 to 8
        print right$(" ";sumCol(i);" ", 3);
        if sumCol(i) = 0 then SOLVED = SOLVED + 1
    next
    print:print
    print "There are ";16 - SOLVED;" rows and columns remaining unsolved."
end sub

function sumRow(row)
    for i = 1 to 8
        sumRow = sumRow + p(i, row)
    next
end function

function sumCol(col)
    for i = 1 to 8
        sumCol = sumCol + p(col, i)
    next
end function