Jan 27, 2008

The one line C#3.0 program for Fibonacci numbers.

I wrote one line Ruby program for Fibonacci numbers.
The one line Ruby program for Fibonacci numbers.

And I wrote one line C#2.0 program for it.
The one line C#2.0 program for Fibonacci numbers.


C#3.0 program is more elegant than C#2.0 program.

Let's write one line C#3.0 program for Fibonacci numbers.

This is the result.

1
1
2
3
5
8
13
21
34
55

This is the one line C#2.0 program.

new EventHandler(delegate(object s,EventArgs e){while(((int[])s)[2]++<10)if(Console.WriteLine(((int[])s)[1]=(((int[])s)[0]=((int[])s)[0]+((int[])s)[1])-((int[])s)[1])is Object){}}).Invoke(new int[]{1,0,0},null);


And this is the one line C#3.0 program.

Enumerable.Repeat(new[]{1,0},10).All(x=>!(Console.WriteLine(x[1]=((x[0]=x[0]+x[1])-x[1]))is Object));


More elegant!

No comments: