Exemple #1
0
def puzzle8() -> None:
    puzzles = [
        '925631847364578219718429365153964782249387156687215934472853691531796428896142573',  # Diary, Red
        '398541672517263894642987513865372941123894756974156238289435167456718329731629485',  # Ring, Purple
        '369248715152769438784531269843617952291854376675392184526973841438125697917486523',  # Locket, Orangeish
        '817325496396487521524691783741952638963148257285763149158279364632814975479536812',  # Cup, Yellow
        '527961384318742596694853217285619473473528169961437852152396748746285931839174625',  # Crown, Blue
        '196842753275361489384759126963125847548937261721684935612578394837496512459213678',  # Snake, Green
        '213845679976123854548976213361782945859314762724569381632458197185297436497631528',  # Enigma, Gray
    ]

    grid = '+.y..o+.+...Gb.......p...r.+..+b.b+...........+g.g+..+.o...........ry...+.+g..g.+'
    features = [
        ColorFeature(grid, 'rpoybgG', puzzles),
        SnakeFeature.major_diagonal(),
        SnakeFeature.minor_diagonal(),
    ]
    Sudoku().solve('.' * 81, features=features)
Exemple #2
0
def puzzle5() -> None:
    previo = '..7......3.....5......................3..8............15.............9....9......'
    puzzle = '......3...1...............72.........................2..................8........'
    diadem = SnakeFeature([(4, 2), (2, 1), (3, 3), (1, 4), (3, 5), (1, 6),
                           (3, 7), (2, 9), (4, 8)])
    thermometers = [
        ThermometerFeature(name, [(row, column) for row in (9, 8, 7, 6, 5, 4)])
        for column in (2, 4, 6, 8) for name in [f'Thermometer #{column // 2}']
    ]
    features = [diadem, *thermometers]
    sudoku = Sudoku()
    sudoku.solve(merge(puzzle, previo), features=features)
Exemple #3
0
def puzzle_08_31(*, show: bool = False) -> None:
    thermos = [
        "1,5,SW,SW,E,S", "1,8,W,W", "3,8,SW,S,SE,E", "7,3,NW,NW", "9,1,E,E",
        "9,8,NW,SW,NW,N,N,N,N"
    ]
    thermometers = [
        ThermometerFeature(f'Thermo#{i}', Feature.parse_line(line))
        for i, line in enumerate(thermos, start=1)
    ]
    snake_squares = [thermometer.squares[0] for thermometer in thermometers]
    snake_squares.extend(((2, 2), (4, 1), (7, 2)))
    snake = SnakeFeature(snake_squares, line=False)
    puzzle = ".....8....................9.................6.....4.................6.......7.9.."
    Sudoku().solve(puzzle, features=[*thermometers, snake], show=show)
Exemple #4
0
def puzzle_08_07(*, show: bool = False) -> None:
    class FoobarFeature(Feature):
        def reset(self, grid: Grid) -> None:
            Cell.remove_value_from_cells([grid.matrix[5, 5]], 1)
            Cell.remove_value_from_cells([grid.matrix[1, 9]], 6)
            Cell.remove_value_from_cells([grid.matrix[9, 9]], 6)

    thermos = [
        "1,1,S,S,S", "9,1,N,N,N", "1,4,E,E,E,E,E,S", "2,4,E,E,E",
        "5,5,E,E,E,E", "6,5,SW", "9,4,E,E,E,E,E"
    ]
    thermometers = [
        ThermometerFeature(f'Thermo#{i}', Feature.parse_line(line))
        for i, line in enumerate(thermos, start=1)
    ]

    features = [
        SnakeFeature.major_diagonal(),
        SnakeFeature.minor_diagonal(),
        *thermometers,
        # FoobarFeature()
    ]
    Sudoku().solve('.' * 81, features=features, show=show)
Exemple #5
0
def puzzle3() -> None:
    previo = '....4........6.............8.....9..........6.........2..........................'
    puzzle = '..9...7...5.....3.7.4.....9.............5.............5.....8.1.3.....9...7...5..'

    evens = [(2, 3), (3, 2), (3, 3), (1, 4), (1, 5), (1, 6)]
    evens = evens + [(column, 10 - row) for row, column in evens]
    evens = evens + [(10 - row, 10 - column) for row, column in evens]

    features = [
        SnakeFeature([(3, 6), (3, 5), (4, 4), (5, 4), (5, 5), (5, 6), (6, 6),
                      (7, 5), (7, 4)]),
        LimitedValuesFeature(evens, (2, 4, 6, 8)),
    ]
    sudoku = Sudoku()
    sudoku.solve(merge(puzzle, previo), features=features)
Exemple #6
0
def puzzle_hunt(*, show: bool = False) -> None:
    puzzle = "...48...7.8.5..6...9.....3.4...2.3..1...5...2..8..7......8.3.7...5...1.39...15.4."
    features = [SnakeFeature.major_diagonal(), SnakeFeature.minor_diagonal()]
    Sudoku().solve(puzzle, features=features, show=show)
Exemple #7
0
def puzzle_09_16(*, show: bool = False) -> None:
    puzzle = "529784361............2......4....2..361529784..2....3......2............784361529"
    features = [SnakeFeature.major_diagonal(), SnakeFeature.minor_diagonal()]
    Sudoku().solve(puzzle, features=features, show=show)