forked from Srinivas11789/AlgorithmNuggets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
83 lines (68 loc) · 1.79 KB
/
game.py
File metadata and controls
83 lines (68 loc) · 1.79 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/python
import sys
def counterGame(n):
# Simple bit manipulation hacker rank solution - from discussions
# Count the number of ones in the value n-1 and reduce the value to 0 or 1 based on the count
# Debug
# print bin(n-1).count("1"), n, bin(n-1).count("1")%2
players = "Richard", "Louise"
# Based on awesome solution from AbhishekVermaIIT
return (players[bin(n-1).count("1")%2])
"""
# Type 2
# Debug
print bin(n-1)[2:]
test = sum(b=='1' for b in bin(input()-1)[2:])
print test
for i in range(n):
value = sum(bit=='1' for bit in bin(n-1)[2:])
if value&1:
print "Louise"
else:
print "Richard"
"""
"""
# Runtime Error
# Power of two function
def powerOf2(n):
count = 0
while n%2 == 0:
n = n//2
count += 1
if n == 1:
return ["True", count]
else:
return ["False", 0]
# Game function
def game(n):
if powerOf2(n)[0] == "True":
return n//2
else:
# Memory error when large numbers occur hence fails.
# 5
# 1560834904
# 1768820483
# 1533726144
# 1620434450
# 1463674015
for i in range(n,1,-1):
result = powerOf2(i)
if result[0] == "True":
return result[1]
# Turns
i = 0
while n > 1:
i = i + 1
#print n
n = game(n)
if i%2 == 0:
return "Richard"
else:
return "Louise"
"""
if __name__ == "__main__":
t = int(raw_input().strip())
for a0 in xrange(t):
n = long(raw_input().strip())
result = counterGame(n)
print result