Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created October 28, 2020 08:24
Show Gist options
  • Save inspirit941/02eaa35e97969b3170767e95f2c6b332 to your computer and use it in GitHub Desktop.
Save inspirit941/02eaa35e97969b3170767e95f2c6b332 to your computer and use it in GitHub Desktop.
def solution(n,a,b):
# a < b 이도록 변환.
a, b = min(a,b), max(a,b)
count = 1
# b-a == 1 이면 a와 b가 만나는 시점.
# 더 큰 값인 b가 홀수면, b는 a가 아니라 b 오른쪽 사람과 겨뤄야 한다.
# ex) a, b = 2, 3일 경우
# 1-2, 3-4 형태로 먼저 대전한 다음에야 만날 수 있음.
while b - a != 1 or b % 2 != 0:
o_a, r_a = divmod(a, 2)
# a가 이겼을 경우 다음 라운드에서 본인의 번호
a = o_a + r_a
# b가 이겼을 경우 다음 라운드에서 본인의 번호
o_b, r_b = divmod(b, 2)
b = o_b + r_b
count += 1
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment