-
Notifications
You must be signed in to change notification settings - Fork 3
/
kangaroo.py
35 lines (21 loc) · 903 Bytes
/
kangaroo.py
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
31
32
33
# Solution of the challenge proposed on Hackerrank at https://www.hackerrank.com/challenges/kangaroo/problem
import math
import random
import re
import sys
def kangaroo(x1, v1, x2, v2):
if x2-x1 > v1 and v1 < v2: # if the first kangaroo starts before than the second and has a shorter skip, it will never catch it up
answer = "NO"
else:
if v1 != v2:
if (x2-x1) % (v2-v1) == 0: # if the gap between the initial positions is a multiple of the skips gap, they will meet
answer = "YES"
else:
answer = "NO"
else:
answer = "NO"
return answer
if __name__ == '__main__':
x1V1X2V2 = input().split() # read the input
x1, v1, x2, v2 = int(x1V1X2V2[0]), int(x1V1X2V2[1]), int(x1V1X2V2[2]), int(x1V1X2V2[3]) # split the previous input on different lines
print(kangaroo(x1, v1, x2, v2))