Skip to content

Instantly share code, notes, and snippets.

@jumboly
Created April 3, 2012 10:55
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/2291019 to your computer and use it in GitHub Desktop.
Save jumboly/2291019 to your computer and use it in GitHub Desktop.
FizzBuzz 2012/04/03
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static void Main(string[] args) {
foreach (var s in fizzbuzz(100)) {
Console.Write(s);
}
}
private static IEnumerable<object> fizzbuzz(int num) {
foreach (var i in Enumerable.Range(1, num)) {
var fizz = i % 3 == 0;
var buzz = i % 5 == 0;
if (fizz) yield return "Fizz";
if (buzz) yield return "Buzz";
if (!fizz && !buzz) yield return i;
yield return Environment.NewLine;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment