NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import numpy as np
import random

def Print_Board(board):
for i in range(9):
for j in range(9):
if j==0:
print("|",end='')
if j!=8:
print(board[i,j],end=' ')
else:
print(board[i,j],end='')
if (j+1)%3==0:
print("|",end='')
if (i+1)%3==0:
print("n---------------------",end='')
print()


#Այս ֆունկցիան գտնում է դատարկ վանդակ

def Find_Empty_Cell(board):
for i in range(9):
for j in range(9):
if board[i,j]==0:
row=i
col=j
Fill_Chk=1
res=np.array([row,col,Fill_Chk],dtype="int8")
return res
res=np.array([-1,-1,0])
return res


#Այս ֆունկցիան ստուգում է թվի վավերականությունը փազլի տվյալ դիրքում
#Կատարված է սուդոկուի կանոնների համաձայն

def Check_Validity(board,row,col,num):
row_start=(row//3)*3
col_start=(col//3)*3
if num in board[:,col] or num in board[row,:]:
return False
if num in board[row_start:row_start+3,col_start:col_start+3]:
return False
return True

# Ստեղծում է չլուծված սուդոկու տախտակ՝ հիմնված պահանջվող դժվարության վրա
#Դժվարության առաջացման ալգորիթմը մի փոքր պարզունակ է, բայց իսկապես օգտակար է ճշգրտության համար

def Generate_Unsolved_Puzzle(board,difficulty):
count,done=0,False
if difficulty is "Easy":
print("Հեշտ դժվարության գլուխկոտրուկների ստեղծում:..nn")
upper_limit=35
elif difficulty is "Medium":
print("Միջին դժվարության գլուխկոտրուկների ստեղծում...nn")
upper_limit=41
else:
print("Դժվար դժվարության գլուխկոտրուկների ստեղծում...nn")
upper_limit=47
while True:
i=random.randint(0,8)
j=random.randint(0,8)
if count<=upper_limit:
if board[i,j]!=0:
not_check=board[i,j]
board[i,j]=0
board_copy=board
if Solve_Sudoku(board_copy,not_check):
board[i,j]=not_check
continue
row_start=(i//3)*3
col_start=(j//3)*3
if difficulty is "Easy":
if np.count_nonzero(board[row_start:row_start+3,col_start:col_start+3])<5:
board[i,j]=not_check
continue
elif difficulty is "Medium":
if np.count_nonzero(board[row_start:row_start+3,col_start:col_start+3])<4:
board[i,j]=not_check
continue
else:
if np.count_nonzero(board[row_start:row_start+3,col_start:col_start+3])<3:
board[i,j]=not_check
continue
count+=1
else:
done=True
break

#Ստուգման համար տողի, սյունակի և համարի մուտքագրումը կատարվում է այստեղ

def Play_Sudoku(Solved_Board,Unsolved_Board):
while True:
row=int(input("Մուտքագրեք տողը համարը տեղադրելու համար:")) - 1
col=int(input("Մուտքագրեք սյունակը համարը տեղադրելու համար:")) - 1
number_check=int(input("Մուտքագրեք համարը (կամ սեղմեք 10՝ դուրս գալու համար):"))
if number_check!=10:
if Unsolved_Board[row,col]==0:
print(Solved_Board[row,col])
if Solved_Board[row,col]==number_check:
print("Ճիշտ! Թարմացված տախտակ:")
Unsolved_Board[row,col]=number_check
Print_Board(Unsolved_Board)
else:
print("Սխալ է: Թարմացված տախտակ:")
Print_Board(Unsolved_Board)
else:
print("Այդ վայրն արդեն ճիշտ է լրացված:")
if np.array_equal(Solved_Board,Unsolved_Board):
print("Շնորհավորում եմ սուդոկուն լուծելու համար!")
break
else:
print("nԼուծված տախտակն է:")
Print_Board(Solved_Board)
print("nՇնորհակալություն խաղալու համար!")
return

#Սուդոկու ցանկացած չլուծված գլուխկոտրուկ լուծելը կատարվում է այստեղ, առաջին զանգը առաջացնում է լուծված գլուխկոտրուկ
#Օգտագործում է հետընթացի ալգորիթմ

def Solve_Sudoku(board,not_check):
x=Find_Empty_Cell(board)
if x[2]==0:
return True
else:
row=x[0]
col=x[1]
for i in np.random.permutation(10):
if i!=0 and i!=not_check:
if Check_Validity(board,row,col,i):
board[row,col]=i
if Solve_Sudoku(board,not_check):
return True
board[row,col]=0
return False

#Մուտքագրում է դժվարությունը և սկզբնավորում է խաղատախտակը

def main():
ch=int(input("Բարև: Ընտրեք դժվարության մակարդակը-n1.Easyn2.Mediumn3.HardnՁեր ընտրությունը:"))
if ch==1:
difficulty="Easy"
elif ch==2:
difficulty="Medium"
else:
difficulty="Hard"
board=np.zeros((9,9),dtype="int8")
if Solve_Sudoku(board,-1):
Solved_Board=board.copy()
print("nnՉլուծված գլուխկոտրուկն է:n")
Generate_Unsolved_Puzzle(board,difficulty)
Print_Board(board)
Unsolved_Board=board.copy()
Play_Sudoku(Solved_Board,Unsolved_Board)
else:
print("Տախտակը հնարավոր չէ!")
return

if __name__=="__main__":
main()
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.