diff --git a/week06-implementation/leGit-y/.gitkeep b/week06-implementation/leGit-y/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/week06-implementation/leGit-y/1966.py b/week06-implementation/leGit-y/1966.py new file mode 100644 index 0000000..f282191 --- /dev/null +++ b/week06-implementation/leGit-y/1966.py @@ -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)) diff --git a/week06-implementation/leGit-y/2239.py b/week06-implementation/leGit-y/2239.py new file mode 100644 index 0000000..12a3dd0 --- /dev/null +++ b/week06-implementation/leGit-y/2239.py @@ -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() + +