Triangular numbers: Difference between revisions

m
→‎{{header|Raku}}: Math::Root now includes the r-simplex root routines
m (→‎{{header|Raku}}: Math::Root now includes the r-simplex root routines)
Line 1,170:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" line>use Math::Root:ver<0.0.4>;
 
my \ε = FatRat.new: 1, 10**24;
 
sub binomial { [×] ($^n … 0) Z/ 1 .. $^p }
 
sub polytopic (Int $r, @range) { @range.map: { binomial $_ + $r - 1, $r } }
 
sub triangular-root ($x) { round ((8 × $x + 1).&root - 1) / 2, ε }
 
sub tetrahedral-root ($x) {
((3 × $x + (9 × $x² - 1/27).&root).&root(3) +
(3 × $x - (9 × $x² - 1/27).&root).&root(3) - 1).round: ε
}
 
sub pentatopic-root ($x) { round ((5 + 4 × (24 × $x + 1).&root).&root - 3) / 2, ε }
 
sub display (@values) {
Line 1,196 ⟶ 1,185:
 
say '';
 
my \ε = FatRat.new: 1, 10**24;
 
for 7140, 21408696, 26728085384, 14545501785001 {
say qq:to/R/;
Roots of $_:
triangular-root: {.&triangular-root.round: ε}
tetrahedral-root: {.&tetrahedral-root.round: ε}
pentatopic-root: {.&pentatopic-root.round: ε}
R
}</syntaxhighlight>
10,333

edits