Triangular numbers

func pentatopic_root(x) {
    (sqrt(5 + 4*sqrt(24*x + 1)) - 3)/2
}

func polytopic (r, range) {
    range.map {|n| binomial(n + r - 1, r) }
}

[
    2, 'triangular', 3, 'tetrahedral', 4, 'pentatopic', 12, '12-simplex'
].slices(2).each_2d {|r,label|
    say "\nFirst 30 #{label} numbers:"
    polytopic(r, ^30).slices(6).each{.join(' ').say}
}

for n in (7140, 21408696, 26728085384, 14545501785001) {
    printf ("\nRoots of #{n}:
   triangular-root: %s
  tetrahedral-root: %s
   pentatopic-root: %s\n",
        polygonal_root(n,3), pyramidal_root(n,3), pentatopic_root(n))
}

Output:

Last updated

Was this helpful?