Sudan function: Difference between revisions

m
Corrected an error in the function name.
(Created Nim solution.)
m (Corrected an error in the function name.)
Line 1,264:
<syntaxhighlight lang="Nim">import std/[unicode, strformat]
 
func sedansudan(n, x, y: Natural): int =
if n == 0: return x + y
if y == 0: return x
let z = sedansudan(n, x, y - 1)
return sedansudan(n - 1, z, z + y)
 
const Delta = ord("₀".toRunes()[0]) - ord('0')
Line 1,277:
 
for (n, x, y) in [(0, 0, 0), (1, 1, 1), (2, 1, 1), (2, 2, 1), (2, 2, 2), (3, 1, 1)]:
echo &"F{subscript(n)}({x}, {y}) = {sedansudan(n, x, y)}"
</syntaxhighlight>
 
256

edits