Skip to content

Instantly share code, notes, and snippets.

@smith-neil
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save smith-neil/8cd342a303b482b880aa to your computer and use it in GitHub Desktop.

Select an option

Save smith-neil/8cd342a303b482b880aa to your computer and use it in GitHub Desktop.
One line Fizz Buzz.... but why?
Enumerable.Range(1, 100)
.FirstOrDefault(m =>
{
Console.WriteLine(
m % 15 == 0 ? "FizzBuzz" :
m % 5 == 0 ? "Buzz" :
m % 3 == 0 ? "Fizz" :
m.ToString()
);
return false;
}
);
I use the FirstOrDefault hack so I can always return false and therefore move to the next item
in the collection without ever copying the enumeration to a new list.
Yes I know this is bad. Yes it was fun to write.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment