Sudan function: Difference between revisions
Content added Content deleted
(Initial Haskell version.) |
(Add Factor) |
||
Line 360: | Line 360: | ||
<pre> |
<pre> |
||
F(1,3,3) = 35 |
F(1,3,3) = 35 |
||
</pre> |
|||
=={{header|Factor}}== |
|||
{{works with|Factor|0.99 2022-04-03}} |
|||
<lang factor>USING: combinators kernel math prettyprint ; |
|||
: sudan ( n x y -- z ) |
|||
{ |
|||
{ [ pick zero? ] [ nipd + ] } |
|||
{ [ dup zero? ] [ drop nip ] } |
|||
[ |
|||
[ 2drop 1 - ] |
|||
[ 1 - sudan dup ] |
|||
[ 2nip + sudan ] 3tri |
|||
] |
|||
} cond ; |
|||
3 1 1 sudan .</lang> |
|||
{{out}} |
|||
<pre> |
|||
10228 |
|||
</pre> |
|||
Or with locals: |
|||
=={{header|Factor}}== |
|||
{{works with|Factor|0.99 2022-04-03}} |
|||
<lang factor>USING: combinators kernel locals math prettyprint ; |
|||
:: sudan ( n x y -- z ) |
|||
{ |
|||
{ [ n zero? ] [ x y + ] } |
|||
{ [ y zero? ] [ x ] } |
|||
[ n 1 - n x y 1 - sudan dup y + sudan ] |
|||
} cond ; |
|||
3 1 1 sudan .</lang> |
|||
{{out}} |
|||
<pre> |
|||
10228 |
|||
</pre> |
</pre> |
||