Skip to content

Instantly share code, notes, and snippets.

@damonjmurray
Created October 12, 2014 06:00
Show Gist options
  • Save damonjmurray/8d2af8edfd05914e9a13 to your computer and use it in GitHub Desktop.
Save damonjmurray/8d2af8edfd05914e9a13 to your computer and use it in GitHub Desktop.
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