Created
October 12, 2014 06:00
-
-
Save damonjmurray/8d2af8edfd05914e9a13 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
using FizzBuzzMap = System.Func<int, string>; | |
namespace FizzBuzz | |
{ | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var maps = new List<FizzBuzzMap>() | |
{ | |
n => n%3 == 0 ? "Fizz" : null, | |
n => n%5 == 0 ? "Buzz" : null, | |
n => n%3*n%5 != 0 ? n.ToString() : null | |
}; | |
Func<int, string> transform = | |
n => string.Join(string.Empty, | |
maps.Where(f => f(n) != null) | |
.Select(f => f(n))); | |
Enumerable.Range(1, 100) | |
.Select(transform) | |
.ToList() | |
.ForEach(Console.WriteLine); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment