Skip to content

Instantly share code, notes, and snippets.

@ssuing8825
Created January 31, 2013 00:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ssuing8825/4678721 to your computer and use it in GitHub Desktop.
Save ssuing8825/4678721 to your computer and use it in GitHub Desktop.
FizzBuzz
[TestMethod]
public void TestingFizzBuzz()
{
var f = new FizzBuzz();
for (int i = 0; i < 100; i++)
{
Console.Write(f.FizzBuzzList(i));
}
}
}
public class FizzBuzz
{
public string FizzBuzzList(int i)
{
var rules = new Dictionary<Func<int, bool>, Func<int, string>>
{
{x => x%3 == 0, x => "fizz"},
{x => x%5 == 0, x => "buzz"},
{x => x%5 != 0 && x%3 != 0, x => x.ToString()},
{x => true, x =>
{
Console.WriteLine();
return string.Empty;
}
}
};
string t = string.Empty;
foreach (var func in rules)
{
if (func.Key(i))
{
t += func.Value(i);
}
}
return t;
//var output = from n in Enumerable.Range(1, 100)
// from f in rules
// where f.Key(n)
// select f.Value(n);
//output.ToList().ForEach(Console.Write);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment