← Back to challenges

Nth Star Number

PythonMediumalgebramath

Instructions

Create a function that takes a positive integer n and returns the nth "star number".

A star number is a centered figurate number that represents a centered hexagram (six-pointed star), such as the one that Chinese checkers is played on.

star numbers for 1, 2 and 3

Examples

star_number(2) ➞ 13
# n = 2
# 2nd star number = 13

star_number(3) ➞ 37
# n = 3
# 3rd star number = 37

star_number(5) ➞ 121
# n = 5
# 5th star number = 121

Notes

  • n will always be a positive integer.
  • The nth term of a star number can be represented as 6n(n-1) + 1
  • See Resources for more information.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Among Us Imposter Formula