Sudan function: Difference between revisions

Added Wren
(Added Wren)
Line 91:
sudan(3, 1, 1) = 10228
sudan(2, 2, 1) = 27
</pre>
 
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<lang ecmascript>import "./fmt" for Fmt
 
var F = Fn.new { |n, x, y|
if (n == 0) return x + y
if (y == 0) return x
return F.call(n - 1, F.call(n, x, y-1), F.call(n, x, y-1) + y)
}
 
for (n in 0..1) {
System.print("Values of F(%(n), x, y):")
System.print("y/x 0 1 2 3 4 5")
System.print("----------------------------")
for (y in 0..6) {
System.write("%(y) |")
for (x in 0..5) {
var sudan = F.call(n, x, y)
Fmt.write("$4d", sudan)
}
System.print()
}
System.print()
}
System.print("F(2, 1, 1) = %(F.call(2, 1, 1))")
System.print("F(3, 1, 1) = %(F.call(3, 1, 1))")
System.print("F(2, 2, 1) = %(F.call(2, 2, 1))")</lang>
 
{{out}}
<pre>
Values of F(0, x, y):
y/x 0 1 2 3 4 5
----------------------------
0 | 0 1 2 3 4 5
1 | 1 2 3 4 5 6
2 | 2 3 4 5 6 7
3 | 3 4 5 6 7 8
4 | 4 5 6 7 8 9
5 | 5 6 7 8 9 10
6 | 6 7 8 9 10 11
 
Values of F(1, x, y):
y/x 0 1 2 3 4 5
----------------------------
0 | 0 1 2 3 4 5
1 | 1 3 5 7 9 11
2 | 4 8 12 16 20 24
3 | 11 19 27 35 43 51
4 | 26 42 58 74 90 106
5 | 57 89 121 153 185 217
6 | 120 184 248 312 376 440
 
F(2, 1, 1) = 8
F(3, 1, 1) = 10228
F(2, 2, 1) = 27
</pre>
9,488

edits