Created
November 7, 2019 09:05
-
-
Save emadb/9d9afacd06ae3b56f76c5d2b462bea70 to your computer and use it in GitHub Desktop.
Fizzbuzz
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.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