Sudan function: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add 8080 Assembly) |
(Added Swift implementation) |
||
Line 1,335: | Line 1,335: | ||
> 35 |
> 35 |
||
</pre> |
</pre> |
||
=={{header|Swift}} |
|||
{{trans|C}} |
|||
I have started working on Swift and am going to practice on RosettaCode. On converting my C implementation to Swift which I contributed last year I found Swift allows statement ending semicolons and enclosing parantheses in if/else statements. I didn't find that anywhere while learning Swift so I am posting both implementations here, the "C like" and the "Pure" Swift. |
|||
Both have been tested with Xcode 14.2 (14C18) |
|||
===C like=== |
|||
<lang swift> |
|||
//Aamrun, 3rd February 2023 |
|||
func F(n: Int,x: Int,y: Int) -> Int { |
|||
if (n == 0) { |
|||
return x + y; |
|||
} |
|||
else if (y == 0) { |
|||
return x; |
|||
} |
|||
return F(n: n - 1, x: F(n: n, x: x, y: y - 1), y: F(n: n, x: x, y: y - 1) + y); |
|||
} |
|||
print("F1(3,3) = " + String(F(n: 1,x: 3,y: 3))); |
|||
</lang> |
|||
===Pure Swift=== |
|||
<lang swift> |
|||
//Aamrun, 3rd February 2023 |
|||
func F(n: Int,x: Int,y: Int) -> Int { |
|||
if n == 0 { |
|||
return x + y |
|||
} |
|||
else if y == 0 { |
|||
return x |
|||
} |
|||
return F(n: n - 1, x: F(n: n, x: x, y: y - 1), y: F(n: n, x: x, y: y - 1) + y) |
|||
} |
|||
print("F1(3,3) = " + String(F(n: 1,x: 3,y: 3))) |
|||
</lang> |
|||
Output is the same for both |
|||
{{out}} |
|||
<pre> |
|||
F1(3,3) = 35 |
|||
</pre> |
|||
=={{header|V (Vlang)}}== |
=={{header|V (Vlang)}}== |