반응형
기술면접 준비하기위해 블로그 글 읽기 (하루에 하나씩 읽을 예정)
프로그래머스 [1차] 비밀지도 문제 풀기
def solution(n, arr1, arr2):
answer = []
for i in range(n):
item1 = bin(arr1[i]).lstrip("0b").zfill(n)
item2 = bin(arr2[i]).lstrip("0b").zfill(n)
print(item1, item2)
temp = ""
for j in range(n):
if item1[j] == item2[j] and item1[j] == "1":
temp += "#"
elif item1[j] == "1" or item2[j] == "1":
temp += "#"
else:
temp += " "
answer.append(temp)
return answer
프로그래머스 키패드 문제 풀기
def moveCount(start, end):
if start == "*":
start = 10
elif start == "#":
start = 12
elif start == 0:
start = 11
if end == "*":
end = 10
elif end == "#":
end = 12
elif end == 0:
end = 11
count = 0
# 같으면 종료
while start != end:
if start - end == 1 or start - end == -1:
start = end
return 1
elif start == 2 or start == 5 or start == 8 or start == 11:
if start < end:
start += 3
count += 1
else:
start -= 3
count += 1
elif start == 1:
start += 1
count += 1
elif start == 3:
start -= 1
count += 1
elif start == 4:
start += 1
count += 1
elif start == 6:
start -= 1
count += 1
elif start == 7:
start += 1
count += 1
elif start == 9:
start -= 1
count += 1
elif start == 10:
start += 1
count += 1
elif start == 12:
start -= 1
count += 1
return count
def solution(numbers, hand):
answer = ""
left = "*"
right = "#"
for i in numbers:
if i == 1 or i == 4 or i == 7:
left = i
answer += "L"
elif i == 3 or i == 6 or i == 9:
right = i
answer += "R"
else:
leftCount = moveCount(left, i)
rightCount = moveCount(right, i)
if leftCount == rightCount:
if hand == "left":
left = i
answer += "L"
else:
right = i
answer += "R"
elif leftCount < rightCount:
left = i
answer += "L"
else:
right = i
answer += "R"
return answer
반응형
'대내 활동 > 2020년 겨울방학 모각코' 카테고리의 다른 글
2021/2/2 모각코 종료 (0) | 2021.02.02 |
---|---|
2021/2/2 모각코 시작 (0) | 2021.02.02 |
2021/1/26 모각코 시작 (0) | 2021.01.26 |
2021/1/19 모각코 종료 (0) | 2021.01.19 |
2021/1/19 모각코 시작 (0) | 2021.01.19 |