Triangular numbers: Difference between revisions

Content added Content deleted
m (Add another related task)
m (→‎{{header|Raku}}: reformat slightly)
Line 81: Line 81:
sub polytopic (Int $r, @range) { @range.map: { binomial $_ + $r - 1, $r } }
sub polytopic (Int $r, @range) { @range.map: { binomial $_ + $r - 1, $r } }


sub triangular-root ($x) { (((8 × $x + 1).&root - 1) / 2).round: ε }
sub triangular-root ($x) { round ((8 × $x + 1).&root - 1) / 2, ε }


sub tetrahedral-root ($x) {
sub tetrahedral-root ($x) {
Line 88: Line 88:
}
}


sub pentatopic-root ($x) { (((5 + 4 × (24 × $x + 1).&root).&root - 3) / 2).round: ε }
sub pentatopic-root ($x) { round ((5 + 4 × (24 × $x + 1).&root).&root - 3) / 2, ε }


sub display (@values) {
sub display (@values) {
Line 95: Line 95:
}
}


for 2, 'triangular', 3, 'tetrahedral',
for 2, 'triangular', 3, 'tetrahedral', 4, 'pentatopic', 12, '12-simplex'
-> $r, $name { say "\nFirst 30 $name numbers:\n" ~ display polytopic $r, ^30 }
4, 'pentatopic', 12, '12-simplex'
-> $r, $name {
say "\nFirst 30 $name numbers:\n" ~
display polytopic( $r, ^Inf )[^30]
}


say '';
say '';