Special factorials: Difference between revisions

m (→‎{{header|Wren}}: Minor tidy)
 
(One intermediate revision by the same user not shown)
Line 318:
rf(3628800) = 10
rf(119) = null</pre>
 
=={{header|Bruijn}}==
 
Implementation for numbers encoded in balanced ternary using Mixfix syntax defined in the Math module:
 
<syntaxhighlight lang="bruijn">
:import std/Combinator .
:import std/List .
:import std/Math .
 
factorial [∏ (+1) → 0 | [0]]
 
superfactorial [∏ (+1) → 0 | factorial]
 
hyperfactorial [∏ (+1) → 0 | [0 ** 0]]
 
alternating-factorial y [[=?0 0 ((factorial 0) - (1 --0))]]
 
exponential-factorial y [[=?0 0 (0 ** (1 --0))]]
 
:test ((factorial (+4)) =? (+24)) ([[1]])
:test ((superfactorial (+4)) =? (+288)) ([[1]])
:test ((hyperfactorial (+4)) =? (+27648)) ([[1]])
:test ((alternating-factorial (+3)) =? (+5)) ([[1]])
:test ((exponential-factorial (+4)) =? (+262144)) ([[1]])
 
invfac y [[[compare-case 1 (2 ++1 0) (-1) 0 (∏ (+0) → --1 | ++‣)]]] (+0)
 
:test ((invfac (+1)) =? (+0)) ([[1]])
:test ((invfac (+2)) =? (+2)) ([[1]])
:test ((invfac (+6)) =? (+3)) ([[1]])
:test ((invfac (+24)) =? (+4)) ([[1]])
:test ((invfac (+120)) =? (+5)) ([[1]])
:test ((invfac (+720)) =? (+6)) ([[1]])
:test ((invfac (+5040)) =? (+7)) ([[1]])
:test ((invfac (+40320)) =? (+8)) ([[1]])
:test ((invfac (+362880)) =? (+9)) ([[1]])
:test ((invfac (+3628800)) =? (+10)) ([[1]])
:test ((invfac (+119)) =? (-1)) ([[1]])
 
seq-a [((superfactorial 0) : ((hyperfactorial 0) : {}(alternating-factorial 0)))] <$> (iterate ++‣ (+0))
 
seq-b exponential-factorial <$> (iterate ++‣ (+0))
 
# return first 10/4 elements of both sequences
main [(take (+10) seq-a) : {}(take (+5) seq-b)]
</syntaxhighlight>
 
=={{header|C}}==
55

edits