[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: 0RFTmzyOudA.jpg (95 KB, 604x299)
95 KB
95 KB JPG
https://en.wikipedia.org/wiki/Factorial
using Functional Programming?
>>
pay attention in class next time
>>
>>107264252
recursion
>>
>>107264543
i try it, it out of memory at fab(17)
>>
>>107264610
works on my machine
>>
>>107264654
now try:
https://en.wikipedia.org/wiki/Fibonacci_sequence
>>
>>107264674
Done that also, works perfectly
>>
>>107264904
show code
>>
>>107264940
Sure, this is in Lua
function fib(n)
return fib_helper(n, 0, 1)
end

function fib_helper(n, a, b)
if n == 0 then
return a
else
return fib_helper(n - 1, b, a + b)
end
end

print(fib(50))



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.