Created
April 5, 2012 12:56
-
-
Save jumboly/2310873 to your computer and use it in GitHub Desktop.
FizzBuzz 2012/04/05
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
class Program { | |
static void Main() { | |
var r = Enumerable.Range(1, 100); | |
var fizz = r.Select(i => i % 3 == 0); | |
var buzz = r.Select(i => i % 5 == 0); | |
int n = 0; | |
var fizzbuzz = fizz.Zip(buzz, (f, b) => { | |
++n; | |
return f & b ? "FizzBuzz" : f ? "Fizz" : b ? "Buzz" : ""+n; | |
}); | |
foreach (var fb in fizzbuzz) { | |
Console.WriteLine(fb); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment