#๐Ÿ”’ Need some help make a Sudoku generator

27 messages ยท Page 1 of 1 (latest)

crude lagoonBOT
#

@gilded spoke

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gilded spoke
#

well

#

ig ill skip the gui part

#
import turtle as t

t.ht()
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
lst = []
def write_num(typenum, cords):
    t.penup()
    t.setpos(cords)
    t.pendown()
    t.write(f'{typenum}', font=("Arial", 30))

def assign_valid(dis, number_values):
    if len(dis) != 0:
        values = [x for x in number_values if x not in dis]
        return values

    else:
        random.shuffle(number_values)
        return number_values

def generate_row():
    global numbers
    row = []
    used_numbers = []
    for pos in range(9):
        available_values = assign_valid(used_numbers, numbers)
        value = random.choice(available_values)
        row.append(value)
        used_numbers.append(value)
    return row

def checkc():
    row_id = 0
    row_pos = 0
    while row_pos != 9:
        if lst[row_id][row_pos] == lst[row_id+1][row_pos]:
            print("tru")
        row_pos += 1


for i in range(2):
    lst.append(generate_row())
for i in lst:
    print(i)
checkc()


#buildmainstruct()
#buildinnerstruct()

#write_num('5', (200, -200))

t.mainloop()```
#

so iv just been messing around with this for a side project

#

and I cant think of an easy way to check the columns for duplicates

#

without like 80 loops

#

thanks if anyone decides to help :)

livid scarab
#

I may overcomplicate it, but here is my thoughts

#

If you turn the board at 90 degrees, the columns become rows. So when a user enters the columns, you could actually treat them as rows and store them in a seperate variable, (a list of lists)

#

but each sublist to contain the column

#

and then you can use a set (which eliminates any duplicate) and check if the length of the set is the same as the sublist

gilded spoke
#

how should I change the values

#

cuz then it might match with the original rows

livid scarab
#

well you could store them in 2 separate variables

#

1 variable is rows and another one is column, and then appending to the column as column[row_pos][row_id] = user_input

gilded spoke
#

i cant really visualize it off the top of my head but ill test that out when I have time

livid scarab
#

write the coordonates for rows and columns, and then turn it at 90 degrees

#

what coordonates will the columns have?

gilded spoke
#

i was just thinking positions in 9 lists

#

sorta like this:

[5, 8, 4, 1, 6, 7, 9, 2, 3]
[3, 5, 6, 4, 1, 9, 2, 7, 8]
[6, 7, 8, 5, 2, 3, 4, 1, 9]
[1, 3, 7, 9, 4, 6, 2, 8, 5]
[8, 3, 2, 5, 4, 7, 1, 6, 9]
[1, 9, 4, 3, 6, 5, 2, 7, 8]
[4, 1, 5, 2, 9, 8, 6, 3, 7]
[7, 5, 1, 3, 2, 9, 6, 4, 8]
[9, 4, 6, 3, 1, 7, 2, 5, 8]
#

no idea how im gonna do the squares tbh

livid scarab
#

the same probably? using modulo?

sharp grove
#

im not sure if its a good idea or how it would work but u could try to store the same addreses in 3 list things one in rows one in colomns and one in the 3x3 squares and just tell witch list ist in from coordinates and check if its in that list

crude lagoonBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.