Last active
August 29, 2015 14:06
-
-
Save otobrglez/97d8270382820570a163 to your computer and use it in GitHub Desktop.
FizzBuzz in C# w/ bit of Linq and generics (v2)
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> FizzBuzzMe2(int to){ | |
List<String> list = new List<String>(); | |
int i = 1; | |
for(; i<=to; list.Add(i.ToString()), i++); | |
foreach(var a in new Dictionary<int, String>(){ {3, "Fizz"}, {5, "Buzz"}, {3*5, "Fizz Buzz"}}) | |
for(i = a.Key; i<=to; list[i-1] = a.Value, i+= a.Key); | |
return list; | |
} | |
public static void Main(String[] args){ | |
foreach(var k in FizzBuzz.FizzBuzzMe2(100)) 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