Using a list for Delegate (I learned that this is called a linear function, is that right?) I decrement the list so it gets its values, but I can not do a simple arithmetic operation with "X", because I have a list and "X" happens to be this list, as Omni and ramaral explained me in the posts below.
Fibonacci I know how to do, I want to do it in the way mentioned.
I know Fibonacci is: Fn = F(n-1) + F(n-2)
.
x - 1
and x - 2
give error.
In this case the function return would be a list (Fibonacci)
See how my method got.
List<int> lista = new List<int>();
Func<List<int>, List<int>> calcFib = null;
for(int i = 0; i <= tamanho-1; i++)
lista.Add(i);
calcFib = x => x.Count == 0 ? 0 : (x - 1 + x - 2) + calcFib(x.Take(x.Count - 1).ToList<int>());
return calcFib(lista);
My list, is the limit of the sequence I want to implement Fibonacci. In this case, the var tamanho
. If tamanho for 10
, for example, would be the result: 0,1,1,2,3,5,8,13,21,34
public List<int> novoFibonacci(int tamanho)
{
List<int> lista = new List<int>();
Func<List<int>, List<int>> calcFib = null;
for(int i = 0; i <= tamanho-1; i++)
lista.Add(i);
calcFib = x => x
return calcFib(lista);
}