5
Using a list for the Delegate(I learned it’s called linear function, is that right? ) I decrease the list to get the respective values, but I can’t do a simple arithmetic operation with "X", because I have a list and "X" happens to be this list, as Omni and ramaral explained to me in the posts below.
Fibonacci I know how to do, I want to do it.
I know Fibonacci is: Fn = F(n-1) + F(n-2)
.
The x - 1
and the x - 2
makes a mistake.
In this case the return of the function would be a list(Fibonacci)
Look how my method turned out.
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);
}
What is this
lista
?– ramaral
Sorry, it’s just that I copied from my previous post. I will edit and relocate, so I explain better.
– pnet