Skip to content

Instantly share code, notes, and snippets.

@otobrglez
Created September 6, 2014 08:48
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 otobrglez/9a6c7d4d6bcdc58d3185 to your computer and use it in GitHub Desktop.
Save otobrglez/9a6c7d4d6bcdc58d3185 to your computer and use it in GitHub Desktop.
FizzBuzz in C# w/ bit of Linq and generics (v3)
using System;
using System.Linq;
using System.Collections.Generic;
public class FizzBuzz {
public static List<String> FizzBuzzMe3(int to){
return Enumerable.Range(1, to).Select(i =>
new Dictionary<int, String>(){
{1, i.ToString()}, {5, "Buzz"}, {3, "Fizz"}, {3*5, "Fizz Buzz"}
}.Last(a => i % a.Key == 0).Value
).ToList();
}
public static void Main(String[] args){
foreach(var k in FizzBuzz.FizzBuzzMe3(20)) Console.Write("'"+k+"' ");
}
}
.PHONY: FizzBuzz.cs
all: run
FizzBuzz.exe: FizzBuzz.cs
@dmcs FizzBuzz.cs
clean:
@rm -f FizzBuzz.exe
run: FizzBuzz.exe
@mono FizzBuzz.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment