Triangular numbers: Difference between revisions

m
→‎{{header|Raku}}: reformat slightly
m (Add another related task)
m (→‎{{header|Raku}}: reformat slightly)
Line 81:
sub polytopic (Int $r, @range) { @range.map: { binomial $_ + $r - 1, $r } }
 
sub triangular-root ($x) { (round ((8 × $x + 1).&root - 1) / 2).round:, ε }
 
sub tetrahedral-root ($x) {
Line 88:
}
 
sub pentatopic-root ($x) { (round ((5 + 4 × (24 × $x + 1).&root).&root - 3) / 2).round:, ε }
 
sub display (@values) {
Line 95:
}
 
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 '';
10,327

edits