Lambda编写斐波那契数列
还需要考虑溢出等问题,闲来无事写了写
Func<float, float, float> a = (arg1, arg2) => 0f;//init var depth = 8; a = (lastNumber, currentNumber) => { if (depth <= 0) return currentNumber; --depth; return a(currentNumber, currentNumber + lastNumber); }; var result = a(0, 1);
顺便科普一个冷知识,1/89的余数刚好符合斐波那契数列。