While I was reading this (page 14) I came across this algorithm:
function fib2(n)
if n = 0 return 0
create an array f[0 : : : n]
f[0] = 0, f[1] = 1
for i = 2 : : : n:
f[i] = f[i 1] + f[i 2]
return f[n]
If I wanted to implement this in Scala using pattern matching, is there a way to create a List in the pattern match part in order to use it in the final return statement?
these are great answers, but I think I'd still like to know if it's possible to define a variable that you only use in your pattern match. I know you can do it in Haskell, but I'm wondering if it's doable in Scala.
just check here for more interesting code.