To find the nth decagonal number, we can use the formula:
Dn = 3n^2 - 2n
where n
is the index of the decagonal number.
We can write a Ruby function that takes an integer n
as input and returns the nth decagonal number using this formula:
main.rb47 chars4 lines
Here's an example of how we can use this function:
main.rb72 chars3 lines
This will output 133
, which is the 5th decagonal number.
gistlibby LogSnag