Factorial: Difference between revisions
Content added Content deleted
Line 3,859: | Line 3,859: | ||
=={{header|Ecstasy}}== |
=={{header|Ecstasy}}== |
||
<syntaxhighlight lang="java"> |
<syntaxhighlight lang="java"> |
||
module ShowFactorials |
module ShowFactorials { |
||
⚫ | |||
{ |
|||
⚫ | |||
{ |
|||
assert:arg n >= Value.zero(); |
assert:arg n >= Value.zero(); |
||
return n <= Value.one() ? n : n * factorial(n-Value.one()); |
return n <= Value.one() ? n : n * factorial(n-Value.one()); |
||
} |
|||
@Inject Console console; |
@Inject Console console; |
||
void run() |
void run() { |
||
{ |
|||
// 128-bit test |
// 128-bit test |
||
UInt128 bigNum = 34; |
UInt128 bigNum = 34; |
||
Line 3,875: | Line 3,872: | ||
// 64-bit test |
// 64-bit test |
||
for (Int i : 10..-1) |
for (Int i : 10..-1) { |
||
{ |
|||
console.print($"factorial({i})={factorial(i)}"); |
console.print($"factorial({i})={factorial(i)}"); |
||
} |
|||
} |
} |
||
} |
} |
||
} |
|||
</syntaxhighlight> |
</syntaxhighlight> |
||