Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- CycleGAN
- NeuralTalk
- 젠센부등식
- ResNet
- GAN
- MachineLearning
- AlexNet
- Bayes'Theorem
- SWEA #Python #알고리즘
- 머신러닝
- 체비셰프부등식
- Bayes'Rule
- ImageCaptioning
- TorchHub
- tensor
- bayesian
- PRML
- Python
- pytorch
- DeepLearing
- DeepLearning
- 마코프부등식
- bayes
Archives
- Today
- Total
euphoriaO-O
[Python][프로그래머스] 키패드 누르기 본문
#2020카카오인턴십 문제
def solution(numbers, hand):
ans = ''
L, R = 10,12 # 거리 계산이 편하도록
# 자명
for n in numbers:
if n in [1,4,7]:
ans += 'L'
L = n
elif n in [3,6,9]:
ans += 'R'
R = n
else:
n = 11 if n == 0 else n # 거리 계산이 편하도록
# 거리 계산
i,j = (n-1)//3, (n-1)%3 #1,1
Li,Lj = (L-1)//3, (L-1)%3 #1,0
Ri,Rj = (R-1)//3, (R-1)%3 #0,2
Ld = abs(i-Li) + j-Lj
Rd = abs(Ri-i) + Rj-j
# 가까운 손 & ~손잡이 확인
if Ld == Rd:
ans += hand[0].upper()
if ans[-1]=='L':
L = n
else:
R = n
elif Ld < Rd:
ans += 'L'
L = n
else:
ans += 'R'
R = n
return ans
'Programming > Algorithm' 카테고리의 다른 글
[Python][프로그래머스] 보석 쇼핑 (0) | 2020.07.11 |
---|---|
[Python][프로그래머스] 수식 최대화 (0) | 2020.07.11 |
[Python] SWEA 1234 비밀번호 (0) | 2020.07.11 |
Comments