Created
September 6, 2014 08:48
-
-
Save otobrglez/9a6c7d4d6bcdc58d3185 to your computer and use it in GitHub Desktop.
FizzBuzz in C# w/ bit of Linq and generics (v3)
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; | |
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+"' "); | |
} | |
} |
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
.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