52 lines
1 KiB
Text
52 lines
1 KiB
Text
( ( calculated-!n
|
|
= memo answ
|
|
. (memo==)
|
|
& ( !arg:0&1
|
|
| !arg:1&0
|
|
| !(memo.):? (!arg.?answ) ?&!answ
|
|
| (!arg+-1)
|
|
* (calculated-!n$(!arg+-1)+calculated-!n$(!arg+-2))
|
|
: ?answ
|
|
& (!arg.!answ) !(memo.):?(memo.)
|
|
& !answ
|
|
)
|
|
)
|
|
& ( counted-!n
|
|
= p P h H A Z L
|
|
. !arg:(%?p ?P.?H.?L)
|
|
& !H
|
|
: ?A
|
|
(%@?h:~!p)
|
|
(?Z&counted-!n$(!P.!A !Z.!h !L))
|
|
| !arg:(..?L)
|
|
& 1+!count:?count
|
|
& (!count.!L) !D:?D
|
|
& ~
|
|
)
|
|
& out$"Derangements of 1 2 3 4"
|
|
& :?D
|
|
& 0:?count
|
|
& ( counted-!n$(4 3 2 1.4 3 2 1.)
|
|
| out$!D
|
|
)
|
|
& ( pad
|
|
= len w
|
|
. @(!arg:? [?len)
|
|
& @(" ":? [!len ?w)
|
|
& !w !arg
|
|
)
|
|
& :?K
|
|
& -1:?N
|
|
& out$(str$(N pad$List pad$Calc))
|
|
& whl
|
|
' ( !N+1:<10:?N
|
|
& ( 0:?count
|
|
& :?D
|
|
& counted-!n$(!K.!K.)
|
|
| out$(str$(!N pad$!count pad$(calculated-!n$!N)))
|
|
)
|
|
& !N !K:?K
|
|
)
|
|
& out$("!20 =" calculated-!n$20)
|
|
& lst$calculated-!n
|
|
)
|