Skip to content

Commit

Permalink
Merge pull request #37 from HYU-PS-STUDY/leGit-y
Browse files Browse the repository at this point in the history
[week-06-implementation] 1966, 2239
  • Loading branch information
clean2001 authored Mar 4, 2024
2 parents b33cd98 + 8b919da commit 860096d
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
Empty file.
25 changes: 25 additions & 0 deletions week06-implementation/leGit-y/1966.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from collections import deque

def printer(q,index,M):
cnt = 0

while q:
nq = q.popleft()
ni = index.popleft()
if q and nq < max(q):
q.append(nq)
index.append(ni)
continue
cnt += 1
if ni == M:
return cnt


T = int(input())
for _ in range(T):
N, M = map(int, input().split())

index = deque([i for i in range(N)])
priority = deque(list(map(int, input().split())))

print(printer(priority,index, M))
60 changes: 60 additions & 0 deletions week06-implementation/leGit-y/2239.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
def column_valid(row,value):

for j in range(9):
if sudoku[row][j] == value:
return 0

return 1



def row_valid(column,value):

for i in range(9):
if sudoku[i][column] == value:
return 0

return 1


def square_valid(i,j,value):

i = i // 3 * 3
j = j // 3 * 3

for a in range(i, i + 3):
for b in range(j, j + 3):
if sudoku[a][b] == value:
return 0

return 1

def dfs(cnt):
if cnt == len(zero):
return True

r, c = zero[cnt]
for i in range(1,10):
if column_valid(r,i) and row_valid(c,i) and square_valid(r,c,i):
sudoku[r][c] = i
check = dfs(cnt + 1)
if check:
return True
sudoku[r][c] = 0



sudoku = [list(map(int, input())) for _ in range(9)]
zero = []
for i in range(9):
for j in range(9):
if sudoku[i][j] == 0:
zero.append((i,j))

dfs(0)
for i in range(9):
for j in range(9):
print(sudoku[i][j], end='')
print()


0 comments on commit 860096d

Please sign in to comment.