Created
April 3, 2012 10:55
-
-
Save jumboly/2291019 to your computer and use it in GitHub Desktop.
FizzBuzz 2012/04/03
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.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