Created
September 5, 2014 19:47
-
-
Save otobrglez/5d41c5633026ecf3cba5 to your computer and use it in GitHub Desktop.
FizzBuzz in C# w/ bit of Linq and generics
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 IEnumerable<String> FizzBuzzMe(int to){ | |
return Enumerable.Range(1, to).Select(j => | |
j % 3 == 0 && j % 5 == 0 ? "Fizz Buzz" : ( | |
j % 3 == 0 ? "Fizz" : ( | |
j % 5 == 0 ? "Buzz" : j.ToString() | |
) | |
) | |
); | |
} | |
public static void Main(String[] args){ | |
foreach(var k in FizzBuzz.FizzBuzzMe(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