Skip to content

Instantly share code, notes, and snippets.

@TomColBee
Created July 16, 2018 19:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomColBee/57cbcb8258ed70e9c54750a8af284711 to your computer and use it in GitHub Desktop.
Save TomColBee/57cbcb8258ed70e9c54750a8af284711 to your computer and use it in GitHub Desktop.
Coderbyte Python Challenge: PentagonalNumber
# PentagonalNumber(num) reads num which will be a positive integer and determine how many dots exist in a pentagonal shape
# around a center dot on the Nth iteration.
# For example, in the image below you can see that on the first iteration there is only a single dot,
# on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are 31 dots.
# The formula for this sequence is (5(n-1)^2 + 5(n-1) + 2) / 2
def PentagonalNumber(num):
num = num - 1
number = ((5*(num**2)) + (5*num) + 2) / 2
return number
# keep this function call here
print(PentagonalNumber(input()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment