Jump to content

Special factorials: Difference between revisions

added Arturo
(Added Algol 68)
(added Arturo)
Line 247:
3628800 -> 10
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">; Rosetta Code task: "Special factorials"
; https://rosettacode.org/wiki/Special_factorials
 
super: $ => [fold.seed:1 1..& [x y] -> x * factorial y]
 
hyper: $ => [fold.seed:1 1..& [x y] -> x * y^y]
 
alternating: $[n][
fold 1..n [x y] ->
x + (factorial y) * (neg 1)^n-y
]
 
exponential: $ => [fold.seed:1 0..& [x y] -> y^x]
 
rf: function [n][
if 1 = n -> return 0
b: a: <= 1
while -> n > a [
'b + 1
'a * b
]
if a = n -> return b
return null
]
 
print "First 10 superfactorials:"
print map 0..9 => super
 
print "\nFirst 10 hyperfactorials:"
print map 0..9 => hyper
 
print "\nFirst 10 alternating factorials:"
print map 0..9 => alternating
 
print "\nFirst 5 exponential factorials:"
print map 0..4 => exponential
 
prints "\nNumber of digits in $5: "
print size ~"|exponential 5|"
print ""
 
[1 2 6 24 120 720 5040 40320 362880 3628800 119]
| loop 'x -> print ~"rf(|x|) = |rf x|"</syntaxhighlight>
 
{{out}}
 
<pre>First 10 superfactorials:
1 1 2 12 288 34560 24883200 125411328000 5056584744960000 1834933472251084800000
 
First 10 hyperfactorials:
1 1 4 108 27648 86400000 4031078400000 3319766398771200000 55696437941726556979200000 21577941222941856209168026828800000
 
First 10 alternating factorials:
0.0 1 1 5 19 101 619 4421 35899 326981
 
First 5 exponential factorials:
0 1 2 9 262144
 
Number of digits in $5: 183231
 
rf(1) = 0
rf(2) = 2
rf(6) = 3
rf(24) = 4
rf(120) = 5
rf(720) = 6
rf(5040) = 7
rf(40320) = 8
rf(362880) = 9
rf(3628800) = 10
rf(119) = null</pre>
 
=={{header|C}}==
1,532

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.