Didn't see a C# solution, so here's mine (with some linq love):
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FizzBuzz { static class Program { static void Main(string[] args) { var buzzMap = new Dictionary<int, string> { { 3, "Fizz" }, { 5, "Buzz" }, }; Func<int, string> buzzer = i => { var buzzed = buzzMap.Keys .Where(k => i % k == 0) .Select(k => buzzMap[k]); return buzzed.Any() ? buzzed.Aggregate((prev, next) => prev += next) : null; }; var output = Enumerable.Range(1, 100) .Select(i => buzzer(i) ?? i.ToString()) .Aggregate(new StringBuilder(), (sb, s) => sb.AppendLine(s)) .ToString(); Console.WriteLine(output); } } }
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Didn't see a C# solution, so here's mine (with some linq love):