Sudan function: Difference between revisions

added RPL
m (→‎{{header|Pascal}}: forget "Free " in sub- header)
(added RPL)
 
(3 intermediate revisions by 3 users not shown)
Line 947:
sudan(2, 2, 1) = 27
sudan(3, 1, 1) = 10228</pre>
 
=={{header|EasyLang}}==
{{trans|C}}
<syntaxhighlight>
func f n x y .
if n = 0
return x + y
.
if y = 0
return x
.
return f (n - 1) f n x (y - 1) (f n x (y - 1) + y)
.
print "F(1,3,3) = " & f 1 3 3
</syntaxhighlight>
 
{{out}}
<pre>
F(1,3,3) = 35
</pre>
 
=={{header|F_Sharp|F#}}==
Line 1,259 ⟶ 1,279:
sudan(2, 2, 1) = 27
</pre>
 
=={{header|Lua}}==
<syntaxhighlight lang="lua">function F (n, x, y)
if n == 0 then
return x + y
elseif y == 0 then
return x
else
return F(n - 1, F(n, x, y - 1), F(n, x, y - 1) + y)
end
end
 
local testCases = {
{0, 0, 0},
{1, 1, 1},
{1, 3, 3},
{2, 1, 1},
{2, 2, 1},
{3, 1, 1}
}
 
for _, v in pairs(testCases) do
io.write("F(" .. table.concat(v, ",") .. ") = ")
print(F(unpack(v)))
end</syntaxhighlight>
{{out}}
<pre>F(0,0,0) = 0
F(1,1,1) = 3
F(1,3,3) = 35
F(2,1,1) = 8
F(2,2,1) = 27
F(3,1,1) = 10228</pre>
 
=={{header|MAD}}==
Line 1,744 ⟶ 1,796:
|14||14||29||60||123||250||505||1016||2039||4086||8181||16372||32755||65522||131057||262128
|}
 
=={{header|RPL}}==
{{works with|RPL|HP|48-R}}
« '''IF''' DUP2 2 GET AND '''THEN'''
DUP 2 GET 3 PICK ROT { 0 1 } - <span style="color:blue">SUDAN</span>
SWAP OVER + 2 →LIST SWAP 1 - SWAP <span style="color:blue">SUDAN</span>
'''ELSE''' ∑LIST SWAP DROP '''END'''
» '<span style="color:blue">SUDAN</span>' STO <span style="color:grey">''@ ( n { x y } ) → F<sub>n</sub>(x,y) )''</span>
 
{ { 0 { 0 0 } } { 1 { 1 1 } } { 1 { 3 3 } } { 2 { 1 1 } } { 2 { 2 1 } } { 3 { 1 1 } } } 1 « EVAL <span style="color:blue">SUDAN</span> » DOLIST
 
{{out}}
<pre>
1: { 0 3 35 8 27 10228 }
</pre>
 
=={{header|Ruby}}==
Line 1,851 ⟶ 1,918:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
var F = Fn.new { |n, x, y|
1,150

edits