Still looking for a sponsor ## Single-line Solution: Fibonacci number

As I mention in my previous post, next single-line function to implement is Fibonacci number. By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s. (by Wikipedia) There are some variants to calculate Fibonacci number. First one is recursion: Func<int, int> fib = null; fib = n => (n < 2) ? 1 : fib(n-1) +...

## Single-Line Solution: Factorial

Recently my colleagues started a dispute whether it is possible to calculate a factorial using just one line of code. In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. (by Wikipedia) One line means a line that ends with a semicolon: bla-bla-bla; Of course, following sample is not the single-row code: for(;;;) bla-bla-bla; First idea is using recursion (let’s arrange, it is the single-line...