Sudan function: Difference between revisions
Content added Content deleted
(Sudan function in various BASIC dialents (BASIC256, PureBasic and Yabasic)) |
Thundergnat (talk | contribs) (→{{header|Raku}}: Add a Raku example) |
||
Line 570: | Line 570: | ||
[1] "F(1,3,3) = 35" |
[1] "F(1,3,3) = 35" |
||
</pre> |
</pre> |
||
=={{header|Raku}}== |
|||
Outputting wiki-tables to more closely emulate the wikipedia examples. Not very efficient but good enough. |
|||
<lang perl6>multi F (0, $x, $y) { $x + $y } |
|||
multi F ($n where * > 0, $x, 0) { $x } |
|||
multi F ($n, $x, $y) { F($n-1, F($n, $x, $y-1), F($n, $x, $y-1) + $y) } |
|||
# Testing |
|||
for 0, 6, 1, 15 -> $f, $g { |
|||
my @range = ^$g; |
|||
say "\{|class=\"wikitable\"\n", "|+ F\<sub>$f\</sub> (x,y)\n" ~ '!x\y!!', join '!!', @range; |
|||
-> $r { say "|-\n" ~ '|' ~ join '||', $r, @range.map:{ F($f, $r, $_) } } for @range; |
|||
say( "|}" ); |
|||
} |
|||
</lang> |
|||
{{out}} |
|||
{|class="wikitable" |
|||
|+ F<sub>0</sub> (x,y) |
|||
!x\y!!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 |
|||
|} |
|||
{|class="wikitable" |
|||
|+ F<sub>1</sub> (x,y) |
|||
!x\y!!0!!1!!2!!3!!4!!5!!6!!7!!8!!9!!10!!11!!12!!13!!14 |
|||
|- |
|||
|0||0||1||4||11||26||57||120||247||502||1013||2036||4083||8178||16369||32752 |
|||
|- |
|||
|1||1||3||8||19||42||89||184||375||758||1525||3060||6131||12274||24561||49136 |
|||
|- |
|||
|2||2||5||12||27||58||121||248||503||1014||2037||4084||8179||16370||32753||65520 |
|||
|- |
|||
|3||3||7||16||35||74||153||312||631||1270||2549||5108||10227||20466||40945||81904 |
|||
|- |
|||
|4||4||9||20||43||90||185||376||759||1526||3061||6132||12275||24562||49137||98288 |
|||
|- |
|||
|5||5||11||24||51||106||217||440||887||1782||3573||7156||14323||28658||57329||114672 |
|||
|- |
|||
|6||6||13||28||59||122||249||504||1015||2038||4085||8180||16371||32754||65521||131056 |
|||
|- |
|||
|7||7||15||32||67||138||281||568||1143||2294||4597||9204||18419||36850||73713||147440 |
|||
|- |
|||
|8||8||17||36||75||154||313||632||1271||2550||5109||10228||20467||40946||81905||163824 |
|||
|- |
|||
|9||9||19||40||83||170||345||696||1399||2806||5621||11252||22515||45042||90097||180208 |
|||
|- |
|||
|10||10||21||44||91||186||377||760||1527||3062||6133||12276||24563||49138||98289||196592 |
|||
|- |
|||
|11||11||23||48||99||202||409||824||1655||3318||6645||13300||26611||53234||106481||212976 |
|||
|- |
|||
|12||12||25||52||107||218||441||888||1783||3574||7157||14324||28659||57330||114673||229360 |
|||
|- |
|||
|13||13||27||56||115||234||473||952||1911||3830||7669||15348||30707||61426||122865||245744 |
|||
|- |
|||
|14||14||29||60||123||250||505||1016||2039||4086||8181||16372||32755||65522||131057||262128 |
|||
|} |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Line 586: | Line 652: | ||
> 35 |
> 35 |
||
</pre> |
</pre> |
||
=={{header|Vlang}}== |
=={{header|Vlang}}== |