Пример #1
0
 def test_valid(self):
     input = to_passport(
         "pid:087499704 hgt:74in ecl:grn iyr:2012 eyr:2030 byr:1980 hcl:#623a2f"
     )
     assert valid(input) == True
     input = to_passport(
         "eyr:2029 ecl:blu cid:129 byr:1989 iyr:2014 pid:896056539 hcl:#a97842 hgt:165cm"
     )
     assert valid(input) == True
Пример #2
0
    def solveGui(self):
        find = findEmpty(self.model)
        if not find:
            return True
        else:
            row, col = find

        for i in range(1, 10):
            if valid(self.model, i, (row, col)):
                self.model[row][col] = i
                self.cubes[row][col].set(i)
                self.cubes[row][col].drawChange(self.win, True)
                self.updateModel()
                pygame.display.update()
                pygame.time.delay(100)

                if self.solveGui():
                    return True

                self.model[row][col] = 0
                self.cubes[row][col].set(0)
                self.updateModel()
                self.cubes[row][col].drawChange(self.win, False)
                pygame.display.update()
                pygame.time.delay(100)

        return False
Пример #3
0
    def Solver(self):
        self.update_board()
        find = find_empty(self.board)
        if find is None:
            return True
        else:
            row, col = find
        for i in range(1, 10):
            if valid(self.board, i, (row, col)):
                self.board[row][col] = i
                self.cubes[row][col].set(i)
                self.cubes[row][col].draw_changes(self.screen, False)
                self.update_board()
                pygame.display.update()
                pygame.time.delay(100)
                if self.Solver():
                    return True
                self.board[row][col] = 0
                self.cubes[row][col].set(0)
                self.update_board()
                self.cubes[row][col].draw_changes(self.screen, True)
                pygame.display.update()
                pygame.time.delay(100)

        return False
Пример #4
0
    def place(self, val):
        row, col = self.selected
        if self.cubes[row][col].value == 0:
            self.cubes[row][col].set(val)
            self.update_board()

            if valid(self.board, val, (row, col)) and solve(self.board):
                return True
            else:
                self.cubes[row][col].set_temp(0)
                self.cubes[row][col].set(0)
                self.update_board()
Пример #5
0
    def place(self, val):
        row, col = self.selected
        if self.cubes[row][col].value == 0:
            self.cubes[row][col].set(val)
            self.updateModel()

            if valid(self.model, val, (row,col)) and self.solve():
                return True
            else:
                self.cubes[row][col].set(0)
                self.cubes[row][col].setTemp(0)
                self.updateModel()
                return False
Пример #6
0
    def place(self, val):
        row, col = self.selected
        if self.cubes[col][row].value = 0:
            self.cubes[col][row].set(val)
            self.update_model()

            if valid(self.model, val, (col, row)) and solve(self.model):
                return True
            else:
                self.cubes[col][row].set(0)
                self.cubes[col][row].set_temp(0)
                self.update_model()
                return False
Пример #7
0
 def test_valid(self):
     testinput = [{
         'ecl': 'gry',
         'pid': '860033327',
         'eyr': '2020',
         'hcl': '#fffffd',
         'byr': '1937',
         'iyr': '2017',
         'cid': '147',
         'hgt': '183cm'
     }, {
         'iyr': '2013',
         'ecl': 'amb',
         'cid': '350',
         'eyr': '2023',
         'pid': '028048884',
         'hcl': '#cfa07d',
         'byr': '1929'
     }, {
         'hcl': '#ae17e1',
         'iyr': '2013',
         'eyr': '2024',
         'ecl': 'brn',
         'pid': '760753108',
         'byr': '1931',
         'hgt': '179cm'
     }, {
         'hcl': '#cfa07d',
         'eyr': '2025',
         'pid': '166559648',
         'iyr': '2011',
         'ecl': 'brn',
         'hgt': '59in'
     }]
     assert valid(testinput[0]) == True
     assert valid(testinput[1]) == False
     assert valid(testinput[2]) == True
     assert valid(testinput[3]) == False
Пример #8
0
    def solve(self):
        find = findEmpty(self.model)
        if not find:
            return True
        else:
            row, col = find

        for i in range(1, 10):
            if valid(self.model, i, (row, col)):
                self.model[row][col] = i

                if self.solve():
                    return True

                self.model[row][col] = 0

        return False
Пример #9
0
    def place(self, val):
        # Get grid coordinates
        row, col = self.selected

        # Check if cell is empty
        if self.cells[row][col].value == 0:
            # Add value
            self.cells[row][col].set(val, False)
            self.updateModel()

            # Check if entered value is valid
            if valid(self.model, val, (row, col)):
                return True
            else:
                self.cells[row][col].set(0, False)
                self.updateModel()
                return False
Пример #10
0
 def test_valid_number(self):
     previous = list(range(1, 26))
     self.assertEqual(main.valid(previous, 26), True)
     self.assertEqual(main.valid(previous, 49), True)
     self.assertEqual(main.valid(previous, 100), False)
     self.assertEqual(main.valid(previous, 50), False)
Пример #11
0
from util import *
from main import prepare, valid, submit
from bagging import build_models

prepare(CountVectorizer, 'bag_of_words')
build_models('bag_of_words', 1, [0, 1, 2, 3])
for name in names:
    valid('bag_of_words', name, 1, 32)
    submit('bag_of_words', name, 1, 32)