[Python] Generate a randomized hitori board that can be solved with python

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I have successfully created a clingo asp to solve hitori and it works well for examples of hitori boards found online but on trying to generate a hitori puzzle with random values for my clingo solver, it returns unsatisfiable, below is the code I am using for creating the board

    import clingo
    import random
    N = clingo.Number

    def randNum(R, n):
    n = n.number
    val = random.randint(1, n)
    if random.randint(0, 9) > 5:
    if val != n:
    n += 1
    else:
    if val != 1:
    val -= 1
    return N(val)


    I then reference the value for the board with

    board(1..n, 1..n, @RandNum(R,n)).


    The table is created successfully and populated with random values but the solver returns unsatisfialbe Is there a specific method required to create a valid solvable table

    Continue reading...

Compartilhe esta Página