Sudan function: Difference between revisions
Content added Content deleted
(Corrected language tag and credits) |
(Added Go) |
||
Line 114: | Line 114: | ||
F(1,3,3) = 35 |
F(1,3,3) = 35 |
||
</pre> |
</pre> |
||
=={{header|Go}}== |
|||
{{trans|Wren}} |
|||
<lang go>package main |
|||
import "fmt" |
|||
func F(n, x, y int) int { |
|||
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) |
|||
} |
|||
func main() { |
|||
for n := 0; n < 2; n++ { |
|||
fmt.Printf("Values of F(%d, x, y):\n", n) |
|||
fmt.Println("y/x 0 1 2 3 4 5") |
|||
fmt.Println("----------------------------") |
|||
for y := 0; y < 7; y++ { |
|||
fmt.Printf("%d |", y) |
|||
for x := 0; x < 6; x++ { |
|||
fmt.Printf("%4d", F(n, x, y)) |
|||
} |
|||
fmt.Println() |
|||
} |
|||
fmt.Println() |
|||
} |
|||
fmt.Printf("F(2, 1, 1) = %d\n", F(2, 1, 1)) |
|||
fmt.Printf("F(3, 1, 1) = %d\n", F(3, 1, 1)) |
|||
fmt.Printf("F(2, 2, 1) = %d\n", F(2, 2, 1)) |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Identical to Wren example. |
|||
</pre> |
|||
=={{header|Hoon}}== |
=={{header|Hoon}}== |
||
<lang Hoon> |
<lang Hoon> |