Multifactorial: Difference between revisions
Content added Content deleted
m (→{{header|AppleScript}}: Modified to observe the !0 = 1 convention.) |
(added Ol) |
||
Line 1,708: | Line 1,708: | ||
4 : [1, 2, 3, 4, 5, 12, 21, 32, 45, 120] |
4 : [1, 2, 3, 4, 5, 12, 21, 32, 45, 120] |
||
5 : [1, 2, 3, 4, 5, 6, 14, 24, 36, 50] |
5 : [1, 2, 3, 4, 5, 6, 14, 24, 36, 50] |
||
</pre> |
|||
=={{header|Ol}}== |
|||
<syntaxhighlight lang="scheme"> |
|||
(define (multifactorial n d) |
|||
(fold * 1 (iota (div n d) n (negate d)))) |
|||
(for-each (lambda (i) |
|||
(display "Degree ") |
|||
(display i) |
|||
(display ":") |
|||
(for-each (lambda (n) |
|||
(display " ") |
|||
(display (multifactorial n i))) |
|||
(iota 10 1)) |
|||
(print)) |
|||
(iota 5 1)) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Degree 1: 1 2 6 24 120 720 5040 40320 362880 3628800 |
|||
Degree 2: 1 2 3 8 15 48 105 384 945 3840 |
|||
Degree 3: 1 1 3 4 5 18 28 40 162 280 |
|||
Degree 4: 1 1 1 4 5 6 7 32 45 60 |
|||
Degree 5: 1 1 1 1 5 6 7 8 9 50 |
|||
</pre> |
|||
By the way, we can create few multifactorial functions and use them directly or as part of infix math notation (inside "//" macro). |
|||
<syntaxhighlight lang="scheme"> |
|||
(define (!!!!! n) (multifactorial n 5)) |
|||
(print (!!!!! 74)) |
|||
(import (math infix-notation)) |
|||
; register !!!!! as a postfix function |
|||
(define \\postfix-functions (put \\postfix-functions '!!!!! #t)) |
|||
; now use "\\" as usual |
|||
(print (\\ |
|||
2 + 74!!!!! |
|||
)) |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
4959435223298761261056 |
|||
4959435223298761261058 |
|||
</pre> |
</pre> |
||