File tree Expand file tree Collapse file tree 1 file changed +2
-24
lines changed
project_euler/problem_301 Expand file tree Collapse file tree 1 file changed +2
-24
lines changed Original file line number Diff line number Diff line change 33
33
"""
34
34
35
35
36
- def x (n : int , n2 : int , n3 : int ) -> int :
37
- """
38
- Returns:
39
- - zero if, with perfect strategy, the player about to
40
- move will eventually lose; or
41
- - non-zero if, with perfect strategy, the player about
42
- to move will eventually win.
43
-
44
- >>> x(1, 2, 3)
45
- 0
46
- >>> x(3, 6, 9)
47
- 12
48
- >>> x(8, 16, 24)
49
- 0
50
- >>> x(11, 22, 33)
51
- 60
52
- >>> x(1000, 2000, 3000)
53
- 3968
54
- """
55
- return n ^ n2 ^ n3
56
-
57
-
58
36
def solution (n : int = 2 ** 30 ) -> int :
59
37
"""
60
38
For a given integer n <= 2^30, returns how many Nim games are lost.
@@ -65,11 +43,11 @@ def solution(n: int = 2 ** 30) -> int:
65
43
"""
66
44
loss_count = 0
67
45
for i in range (1 , n + 1 ):
68
- if x ( i , 2 * i , 3 * i ) == 0 :
46
+ if ( i ^ ( 2 * i ) ^ ( 3 * i ) ) == 0 :
69
47
loss_count += 1
70
48
71
49
return loss_count
72
50
73
51
74
52
if __name__ == "__main__" :
75
- print (solution ())
53
+ print (f" { solution () = } " )
You can’t perform that action at this time.
0 commit comments