Triangular numbers: Difference between revisions
Content added Content deleted
(Added AppleScript.) |
(Added XPL0 example.) |
||
Line 818: | Line 818: | ||
tetrahedral: 44355.77738407326 |
tetrahedral: 44355.77738407326 |
||
pentatopic: 4321 |
pentatopic: 4321 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
Some "interesting" loss of precision in the Pow function.... |
|||
<syntaxhighlight lang "XPL0">real T(13, 30); |
|||
proc ShowRoots(X); |
|||
real X, SR, CR1, CR2; |
|||
[Format(1, 0); |
|||
Text(0, "Roots of "); RlOut(0, X); CrLf(0); |
|||
Format(7, 13); |
|||
Text(0, " triangular: "); |
|||
RlOut(0, (sqrt(8.*X + 1.) - 1.) / 2.); |
|||
Text(0, "^m^jtetrahedral: "); |
|||
SR:= sqrt(9.*X*X - 1./27.); |
|||
CR1:= Pow(3.*X + SR, 1./3.); |
|||
CR2:= Pow(3.*X - SR, 1./3.); |
|||
RlOut(0, CR1 + CR2 -1.); |
|||
Text(0, "^m^j pentatopic: "); |
|||
RlOut(0, (sqrt(5. + 4.*sqrt(24.*X + 1.)) - 3.) / 2.); |
|||
CrLf(0); CrLf(0); |
|||
]; |
|||
proc Print(Str, Places, R); |
|||
int Str, Places, R, N; |
|||
[Text(0, Str); CrLf(0); |
|||
Format(Places, 0); |
|||
for N:= 0 to 29 do |
|||
[RlOut(0, T(R,N)); |
|||
if rem(N/6) = 5 then CrLf(0); |
|||
]; |
|||
CrLf(0); |
|||
]; |
|||
int R, N; |
|||
[for N:= 0 to 29 do |
|||
T(1,N):= float(N); |
|||
for R:= 2 to 12 do |
|||
[T(R,0):= 0.; |
|||
for N:= 1 to 29 do |
|||
T(R,N):= T(R,N-1) + T(R-1,N); |
|||
]; |
|||
Print("The first 30 triangular numbers are:", 4, 2); |
|||
Print("The first 30 tetrahedral numbers are:", 5, 3); |
|||
Print("The first 30 pentatopic numbers are:", 6, 4); |
|||
Print("The first 30 12-simplex numbers are:", 11, 12); |
|||
ShowRoots(7140.); |
|||
ShowRoots(21408696.); |
|||
ShowRoots(26728085384.); |
|||
ShowRoots(14_545_501_785_001.); |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
The first 30 triangular numbers are: |
|||
0 1 3 6 10 15 |
|||
21 28 36 45 55 66 |
|||
78 91 105 120 136 153 |
|||
171 190 210 231 253 276 |
|||
300 325 351 378 406 435 |
|||
The first 30 tetrahedral numbers are: |
|||
0 1 4 10 20 35 |
|||
56 84 120 165 220 286 |
|||
364 455 560 680 816 969 |
|||
1140 1330 1540 1771 2024 2300 |
|||
2600 2925 3276 3654 4060 4495 |
|||
The first 30 pentatopic numbers are: |
|||
0 1 5 15 35 70 |
|||
126 210 330 495 715 1001 |
|||
1365 1820 2380 3060 3876 4845 |
|||
5985 7315 8855 10626 12650 14950 |
|||
17550 20475 23751 27405 31465 35960 |
|||
The first 30 12-simplex numbers are: |
|||
0 1 13 91 455 1820 |
|||
6188 18564 50388 125970 293930 646646 |
|||
1352078 2704156 5200300 9657700 17383860 30421755 |
|||
51895935 86493225 141120525 225792840 354817320 548354040 |
|||
834451800 1251677700 1852482996 2707475148 3910797436 5586853480 |
|||
Roots of 7140 |
|||
triangular: 119.0000000000000 |
|||
tetrahedral: 34.0000000017903 |
|||
pentatopic: 18.8766466159280 |
|||
Roots of 21408696 |
|||
triangular: 6543.0000000000000 |
|||
tetrahedral: 503.5611663345480 |
|||
pentatopic: 149.0609473752660 |
|||
Roots of 26728085384 |
|||
triangular: 231205.4055652560000 |
|||
tetrahedral: 5431.9999386465400 |
|||
pentatopic: 893.4424567516850 |
|||
Roots of 14545501785001 |
|||
triangular: 5393607.1581451700000 |
|||
tetrahedral: 44355.7773765584000 |
|||
pentatopic: 4321.0000000000000 |
|||
</pre> |
</pre> |