Exemple #1
0
def detect_invalid_solutions(filename):
    from sudoku import Board, is_valid
    puzzles = read_sudokus_from_csv(filename, read_solutions=True)
    list_invalids = []
    for puzzle in puzzles:
        puzzle_obj = Board(puzzle)
        if not is_valid(puzzle_obj):
            list_invalids.append(puzzle)
    return np.array(list_invalids)
Exemple #2
0
def generate(board):
    # generate random value to put at a random place
    count = 0
    while count < 17:
        row = random.randint(0, 8)
        col = random.randint(0, 8)
        value = random.randint(1, 9)
        if board[row][col] == 0 and is_valid(board, value, row, col):
            board[row][col] = value
            count += 1
Exemple #3
0
def test_is_invalid():
    board = Board(INVALID_BOARD_ARR)
    assert is_valid(board) is False
Exemple #4
0
def test_is_valid():
    board = Board(VALID_BOARD_ARR)
    assert is_valid(board) is True
        print("There is not a value that occurs the most")

    # dungeon
    print("\nChallenge #4: Find the best path through the dungeon")
    width = input("What is the width of the dungeon?\n")
    height = input("What is the height of the dungeon?\n")
    try:
        width = int(width)
        height = int(height)
    except ValueError:
        print("The width and height must be integers")
    dungeon_map = dungeon.generate_dungeon(width, height)
    dungeon.print_dungeon(dungeon_map)
    paths, health = dungeon.find_best_paths(dungeon_map)
    if len(paths) > 1:
        print("The best paths through the dungeon are:")
        for path in paths:
            print(", ".join(path))
    else:
        print("The best path through the dungon is:")
        print(", ".join(paths[0]))
    print("The minimum health needed is", health)


    # sudoku
    print("\nChallenge #5: Is a sudoku board valid?")
    file_name = input("What is the full name of the sudoku board file? (with extension)\n")
    if sudoku.is_valid(file_name):
        print("The sudoku board is valid")
    else:
        print("The sudoku board is not valid")
Exemple #6
0
def test_is_valid_solved_grid():
    grid = '417369825632158947958724316825437169791586432346912758289643571573291684164875293'
    assert su.is_valid(grid)
Exemple #7
0
def test_solve_unsolveable():
    bad_grid = '..235..47..54...63.4.92..8.38.19.27.2.6...8.4.54.83.19.3..76.2.87...19..62..481..'
    assert su.is_valid(bad_grid)
    assert not list(su.solve(bad_grid))
Exemple #8
0
def test_is_valid_empty_grid():
    grid = '.' * 81
    assert su.is_valid(grid)
Exemple #9
0
def test_is_valid_not():
    grid = '747' + '.' * 78
    assert not su.is_valid(grid)
Exemple #10
0
def test_is_valid():
    grid = '4.....8.5.3..........7......2.....6.....8.4......1.......6.3.7.5..2.....1.4......'
    assert su.is_valid(grid)
Exemple #11
0
 def testIsValidReturnFalse(self):
     self.assertEqual(is_valid(self.board, 6, (6, 0)), False)
Exemple #12
0
 def testIsValidReturnTrue(self):
     self.assertEqual(is_valid(self.board, 5, (6, 0)), True)