Skip to content

Commit e2550e9

Browse files
committed
fixed code as per bot comments to pass automated tests
1 parent d1e4849 commit e2550e9

1 file changed

Lines changed: 58 additions & 16 deletions

File tree

project_euler/problem_061/sol1.py

Lines changed: 58 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@ def fill_triangle(int_range: tuple[int, int] = (1000, 9999)) -> list[int]:
6060
6161
"""
6262

63-
def triangle(n: int) -> int:
64-
return n * (n + 1) // 2
63+
def triangle(num: int) -> int:
64+
"""
65+
Gives the Nth triangle number.
66+
>>> triangle(2)
67+
3
68+
>>> triangle(5)
69+
15
70+
"""
71+
return num * (num + 1) // 2
6572

6673
st, end = int_range
6774
arr = []
@@ -89,8 +96,15 @@ def fill_square(int_range: tuple[int, int] = (1000, 9999)) -> list[int]:
8996
9097
"""
9198

92-
def square(n: int) -> int:
93-
return n**2
99+
def square(num: int) -> int:
100+
"""
101+
Gives the Nth square number.
102+
>>> square(2)
103+
4
104+
>>> square(5)
105+
25
106+
"""
107+
return num**2
94108

95109
st, end = int_range
96110
arr = []
@@ -118,8 +132,15 @@ def fill_pentagonal(int_range: tuple[int, int] = (1000, 9999)) -> list[int]:
118132
119133
"""
120134

121-
def pentagon(n: int) -> int:
122-
return n * (3 * n - 1) // 2
135+
def pentagon(num: int) -> int:
136+
"""
137+
Gives the Nth pentagon number.
138+
>>> pentagon(2)
139+
5
140+
>>> pentagon(5)
141+
35
142+
"""
143+
return num * (3 * num - 1) // 2
123144

124145
st, end = int_range
125146
arr = []
@@ -147,8 +168,15 @@ def fill_hexagonal(int_range: tuple[int, int] = (1000, 9999)) -> list[int]:
147168
148169
"""
149170

150-
def hexagon(n: int) -> int:
151-
return n * (2 * n - 1)
171+
def hexagon(num: int) -> int:
172+
"""
173+
Gives the Nth hexagon number.
174+
>>> hexagon(2)
175+
6
176+
>>> hexagon(5)
177+
45
178+
"""
179+
return num * (2 * num - 1)
152180

153181
st, end = int_range
154182
arr = []
@@ -176,8 +204,15 @@ def fill_heptagonal(int_range: tuple[int, int] = (1000, 9999)) -> list[int]:
176204
177205
"""
178206

179-
def heptagon(n: int) -> int:
180-
return n * (5 * n - 3) // 2
207+
def heptagon(num: int) -> int:
208+
"""
209+
Gives the Nth heptagon number.
210+
>>> heptagon(2)
211+
7
212+
>>> heptagon(5)
213+
55
214+
"""
215+
return num * (5 * num - 3) // 2
181216

182217
st, end = int_range
183218
arr = []
@@ -206,8 +241,15 @@ def fill_octagonal(int_range: tuple[int, int] = (1000, 9999)) -> list[int]:
206241
207242
"""
208243

209-
def octagon(n: int) -> int:
210-
return n * (3 * n - 2)
244+
def octagon(num: int) -> int:
245+
"""
246+
Gives the Nth octagon number.
247+
>>> octagon(2)
248+
8
249+
>>> octagon(5)
250+
65
251+
"""
252+
return num * (3 * num - 2)
211253

212254
st, end = int_range
213255
arr = []
@@ -224,7 +266,7 @@ def octagon(n: int) -> int:
224266
return arr
225267

226268

227-
def check_cyclic(x: int, y: int) -> bool:
269+
def check_cyclic(num1: int, num2: int) -> bool:
228270
"""
229271
This function checks if two 4 digit numbers are cyclic.
230272
For this problem we are only concerned with 4 digit numbers.
@@ -240,12 +282,12 @@ def check_cyclic(x: int, y: int) -> bool:
240282
241283
"""
242284

243-
if x < 1000 or y < 1000:
285+
if num1 < 1000 or num2 < 1000:
244286
raise ValueError("Both integers must be greater than 999")
245-
if x > 9999 or y > 9999:
287+
if num1 > 9999 or num2 > 9999:
246288
raise ValueError("Both integers must be less than 10000")
247289

248-
return (x % 100) == (y // 100)
290+
return (num1 % 100) == (num2 // 100)
249291

250292

251293
def solution() -> int:

0 commit comments

Comments
 (0)