Skip to content

Instantly share code, notes, and snippets.

@emadb
Created November 7, 2019 09:05
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 emadb/9d9afacd06ae3b56f76c5d2b462bea70 to your computer and use it in GitHub Desktop.
Save emadb/9d9afacd06ae3b56f76c5d2b462bea70 to your computer and use it in GitHub Desktop.
Fizzbuzz
using System;
using System.Linq;
using System.Collections.Generic;
namespace CodicePlastico
{
public class FizzBuzz
{
private static readonly IDictionary<int, string> _cases = new Dictionary<int, string>
{
{3, "fizz"},
{5, "buzz"}
};
public static string Play(int n)
{
var result = _cases
.Where(x => n % x.Key == 0) .Aggregate("", (c, a) => c + a.Value);
return string.IsNullOrEmpty(result) ? n.ToString() : result;
}
public static void Main()
{
for(int i=1;i<=100;i++)
{
Console.WriteLine(Play(i));
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment