Skip to content

Instantly share code, notes, and snippets.

@jumboly
Created April 5, 2012 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jumboly/2310873 to your computer and use it in GitHub Desktop.
Save jumboly/2310873 to your computer and use it in GitHub Desktop.
FizzBuzz 2012/04/05
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