Sudan function: Difference between revisions
Content added Content deleted
(Sudan function in various dialects BASIC (QBasic, Run BASIC and True BASIC)) |
(Created Nim solution.) |
||
Line 1,260: | Line 1,260: | ||
sudan(3, 1, 1) = 10228 |
sudan(3, 1, 1) = 10228 |
||
sudan(2, 2, 1) = 27</pre> |
sudan(2, 2, 1) = 27</pre> |
||
=={{header|Nim}}== |
|||
<syntaxhighlight lang="Nim">import std/[unicode, strformat] |
|||
func sedan(n, x, y: Natural): int = |
|||
if n == 0: return x + y |
|||
if y == 0: return x |
|||
let z = sedan(n, x, y - 1) |
|||
return sedan(n - 1, z, z + y) |
|||
const Delta = ord("₀".toRunes()[0]) - ord('0') |
|||
func subscript(n: Natural): string = |
|||
for c in $n: |
|||
result.add Rune(ord(c) + Delta) |
|||
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}) = {sedan(n, x, y)}" |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre>F₀(0, 0) = 0 |
|||
F₁(1, 1) = 3 |
|||
F₂(1, 1) = 8 |
|||
F₂(2, 1) = 27 |
|||
F₂(2, 2) = 15569256417 |
|||
F₃(1, 1) = 10228 |
|||
</pre> |
|||
=={{header|OCaml}}== |
=={{header|OCaml}}== |