def resolver(self, event): matRes = numpy.zeros((9, 9), int) for i in range(9): for j in range(9): matRes[i][j] = self.intMio(self.myGrid.GetCellValue(i, j)) matRes = sudoku.main(matRes) for i in range(9): for j in range(9): self.myGrid.SetCellValue(i, j, str(matRes[i][j]))
def POST(self): try: webData = web.data() print "Handle Post webdata is ", webData #后台打日志 recMsg = receive.parse_xml(webData) if isinstance(recMsg, receive.Msg): toUser = recMsg.FromUserName fromUser = recMsg.ToUserName if recMsg.MsgType == 'text': if recMsg.Content.split('.')[0] == 'king': page = recMsg.Content.split('.')[1] head = recMsg.Content.split('.')[0] content, txt = novel.Choose(head, page) email_sample.email(page, txt) replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() elif recMsg.Content.split(':')[0] == 'sudoku': a = recMsg.Content.split(':')[1] sudoku.main(a) content = sudoku.fin1 replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() else: keywo = recMsg.Content content = movice.Search_main(keywo) replyMsg = reply.TextMsg(toUser, fromUser, content) return replyMsg.send() if recMsg.MsgType == 'image': mediaId = recMsg.MediaId replyMsg = reply.ImageMsg(toUser, fromUser, mediaId) return replyMsg.send() else: return reply.Msg().send() else: print "暂且不处理" return reply.Msg().send() except Exception, Argment: return Argment
def test_get_dependent_indexes(): sudoku = [[0, 0, 0, 0, 6, 0, 7, 0, 0], [0, 5, 9, 0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0], [6, 0, 0, 5, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 4, 6, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 9, 1], [8, 0, 0, 7, 4, 0, 0, 0, 0]] sudoku_cells = main(sudoku) for row in sudoku: for cell in row: candidat = choice(cell.ge)
def test_get_dependent_indexes(): sudoku = [[0, 0, 0, 0, 6, 0, 7, 0, 0], [0, 5, 9, 0, 0, 0, 0, 0, 0], [0, 1, 0, 2, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0], [6, 0, 0, 5, 0, 0, 0, 0, 0], [3, 0, 0, 0, 0, 0, 4, 6, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 9, 1], [8, 0, 0, 7, 4, 0, 0, 0, 0]] sudoku_cells = main(sudoku) sudoku_cells[0][0].use(2) exclude(sudoku_cells, 2, 0, 0) sudoku_cells[0][1].use(3) exclude(sudoku_cells, 3, 0, 1) sudoku_cells[0][2].use(4) exclude(sudoku_cells, 4, 0, 2) sudoku_cells[0][3].use(8) exclude(sudoku_cells, 8, 0, 3) sudoku_cells[0][5].use(5) exclude(sudoku_cells, 5, 0, 5) sudoku_cells[0][7].use(1) exclude(sudoku_cells, 1, 0, 7) sudoku_cells[0][8].use(9) exclude(sudoku_cells, 9, 0, 8) sudoku_cells[1][0].use(7) exclude(sudoku_cells, 7, 1, 0) sudoku_cells[1][3].use(4) exclude(sudoku_cells, 4, 1, 3) sudoku_cells[1][4].use(3) exclude(sudoku_cells, 3, 1, 4) sudoku_cells[1][5].use(1) exclude(sudoku_cells, 1, 1, 5) sudoku_cells[1][6].use(2) exclude(sudoku_cells, 2, 1, 6) sudoku_cells[1][7].use(8) exclude(sudoku_cells, 8, 1, 7) sudoku_cells[1][8].use(6) exclude(sudoku_cells, 6, 1, 8) dependent_indexes = get_dependent_indexes(sudoku_cells, 6, 1, 8) print(dependent_indexes)
checks if the solved matrix rows have all the numbers from 1 to 9 each present once """ for row in matrix: self.assertEquals(sorted(row),range(1,10)) def test_columnCheck(self): """ checks if the solved matrix columns have all the numbers from 1 to 9 each present once """ for column in [getColumnNumbers(matrix,i) for i in xrange(9)]: self.assertEquals(sorted(column),range(1,10)) def test_box(self): """ checks if the solved matrix having 3x3 small boxes have all the numbers from 1 to 9 each present once """ for row in xrange(0,8,3): for column in xrange(0,8,3): self.assertEquals(sorted(getBoxNumbers(row,column)), range(1,10)) if __name__=="__main__": inputfile = raw_input("Enter CSV file name[data.csv]:") if inputfile=='': inputfile='data1.csv' print 'Reading '+inputfile matrix = main(inputfile,inputfile[:-4]+"_output.csv") unittest.main()
width:11px; text-align:center; } .ptable { width:47px; line-height:.7; } </style> ''' print '<div id="board">' if STEPMODE: sudoku.main(Solve_step, user_board, oo=True) maxsteps = sudoku.GAMESTEPS[0] if SOLVED: Solve_step = 999 sudoku.SOLVE.append(True) sudoku.main(Solve_step, user_board, oo=True) maxsteps = sudoku.GAMESTEPS[0] Solve_step = maxsteps # check to prevent the steps from going beyond the end after the board is complete/failed if sudoku.STEPSREQUIRED[0] != 0: if maxsteps < Solve_step: Solve_step = maxsteps def step_calc(increment):
d2 = list(b[s])[0] for p in peers[s]: if not eliminate_digit(b, p, d2): return False return True def propagate_to_unit(b, s, d): # Now see if it's apparent where d must go if not in s. for u in units[s]: places = [ s2 for s2 in u if d in b[s2] ] if len(places) == 0: # Ooops, we just eliminated the last possible place. return False elif len(places) == 1: if not set_digit(b, places[0], d): return False return True def solve(givens): b = search(board(givens)) if b is not None: return [ None if len(b[s]) > 1 else list(b[s])[0] for s in squares ] else: return None def board(givens): b = [ set(digits) for _ in squares ] for s, d in enumerate(givens): if d and not set_digit(b, s, d): return None return b main(solve)
from sudoku import main if __name__ == '__main__': main()
width:11px; text-align:center; } .ptable { width:47px; line-height:.7; } </style> ''' print '<div id="board">' if STEPMODE: sudoku.main(Solve_step, user_board, oo=True) maxsteps = sudoku.GAMESTEPS[0] if SOLVED: Solve_step = 999 sudoku.SOLVE.append(True) sudoku.main(Solve_step, user_board, oo=True) maxsteps = sudoku.GAMESTEPS[0] Solve_step = maxsteps # check to prevent the steps from going beyond the end after the board is complete/failed if sudoku.STEPSREQUIRED[0] != 0: if maxsteps < Solve_step: Solve_step = maxsteps def step_calc(increment): # if the puzzle isnt solved increment normally??