Skip to content

Instantly share code, notes, and snippets.

@TheBuzzSaw
Created December 20, 2017 21:12
Show Gist options
  • Select an option

  • Save TheBuzzSaw/f178e2eda0060f47572e165c5da5190c to your computer and use it in GitHub Desktop.

Select an option

Save TheBuzzSaw/f178e2eda0060f47572e165c5da5190c to your computer and use it in GitHub Desktop.
FizzBuzz just because
using System;
namespace FizzBuzz
{
class Program
{
static void PlayTheGame(int maxValue, params (int factor, string phrase)[] rules)
{
for (int i = 1; i <= maxValue; ++i)
{
bool showValue = true;
foreach (var rule in rules)
{
if (i % rule.factor == 0)
{
Console.Write(rule.phrase);
showValue = false;
}
}
if (showValue)
Console.WriteLine(i);
else
Console.WriteLine();
}
}
static void Main(string[] args)
{
PlayTheGame(100, (3, "Fizz"), (5, "Buzz"));
PlayTheGame(100, (3, "Fizz"), (5, "Buzz"), (7, "Baz"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment