Task

Solve a partially filled-in normal   9x9   Sudoku grid   and display the result in a human-readable format.

references

 Algorithmics of Sudoku   may help implement this.
 Python Sudoku Solver Computerphile video.


with javascript_semantics
sequence board = split("""
.......39
.....1..5
..3.5.8..
..8.9...6
.7...2...
1..4.....
..9.8..5.
.2....6..
4..7.....""",'\n')

function valid_move(integer y, x, ch)
    for i=1 to 9 do
        if ch=board[i][x] then return false end if
        if ch=board[y][i] then return false end if
    end for
    y -= mod(y-1,3)
    x -= mod(x-1,3)
    for ys=y to y+2 do
        for xs=x to x+2  do
            if ch=board[ys][xs] then return false end if
        end for
    end for
    return true
end function

sequence solution = {}

procedure brute_solve()
    for y=1 to 9 do
        for x=1 to 9 do
            if board[y][x]<='0' then
                for ch='1' to '9' do
                    if valid_move(y,x,ch) then
                        board[y][x] = ch
                        brute_solve()
                        board[y][x] = ' '
                        if length(solution) then return end if
                    end if
                end for
                return
            end if
        end for
    end for
    solution = deep_copy(board) -- (already solved case)
end procedure

atom t0 = time()
brute_solve()
printf(1,"%s\n(solved in %3.2fs)\n",{join(solution,"\n"),time()-t0})
