Skip to content

Instantly share code, notes, and snippets.

@otobrglez
Created September 5, 2014 19:47
Show Gist options
  • Save otobrglez/5d41c5633026ecf3cba5 to your computer and use it in GitHub Desktop.
Save otobrglez/5d41c5633026ecf3cba5 to your computer and use it in GitHub Desktop.
FizzBuzz in C# w/ bit of Linq and generics
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+"' ");
}
}
.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