MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / hexagonal_num

Function hexagonal_num

project_euler/problem_045/sol1.py:17–27  ·  view source on GitHub ↗

Returns nth hexagonal number >>> hexagonal_num(143) 40755 >>> hexagonal_num(21) 861 >>> hexagonal_num(10) 190

(n: int)

Source from the content-addressed store, hash-verified

15
16
17def hexagonal_num(n: int) -> int:
18 """
19 Returns nth hexagonal number
20 >>> hexagonal_num(143)
21 40755
22 >>> hexagonal_num(21)
23 861
24 >>> hexagonal_num(10)
25 190
26 """
27 return n * (2 * n - 1)
28
29
30def is_pentagonal(n: int) -> bool:

Callers 1

solutionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected