Skip to content

Commit

Permalink
알고리즘
Browse files Browse the repository at this point in the history
  • Loading branch information
sunyeongchoi committed Jan 8, 2021
1 parent f72b6be commit 9ba3fec
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
18 changes: 18 additions & 0 deletions argorithm/collatz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 500번을 반복해도 1이 되지 않는다면 –1을 반환해 주세요.
def solution(num):
answer = 0
while num != 1:
if num % 2 == 0:
num /= 2
answer += 1
else:
num = num*3 + 1
answer += 1
if answer >= 500:
return -1
return answer


if __name__ == '__main__':
real_answer = solution(6)
print('정답 : ', real_answer)
23 changes: 22 additions & 1 deletion argorithm/quadtree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
def solution(arr):
answer = []
answer = [0, 0]
N = len(arr)

def comp(x, y, n):
print('x, y, N : ', x, y, N)
init = arr[x][y] # 해당 네모값중 하나 # 모두 같아야 통과임
print('init : ', init)
for i in range(x, x + n):
for j in range(y, y + n):
if arr[i][j] != init: # 한번이라도 다르면 그 네모는 압축불가
nn = n // 2
comp(x, y, nn)
comp(x, y + nn, nn)
comp(x + nn, y, nn)
comp(x + nn, y + nn, nn)
return

# 무사히 다 통과했다면 압축가능
answer[init] += 1
print('answer : ', answer)

comp(0, 0, N)
return answer


Expand Down
11 changes: 11 additions & 0 deletions argorithm/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import numpy as np


def solution(arr):
n = 1
return arr[:n, :n]


if __name__ == '__main__':
real_answer = solution([[1, 1, 0, 0], [1, 0, 0, 0], [1, 0, 0, 1], [1, 1, 1, 1]])
print('정답 : ', real_answer)

0 comments on commit 9ba3fec

Please sign in to comment.