April 30, 2010

Yet Another FizzBuzz

As interesting as I could make it.

private static string FizzBuzz()
    {
      var fizzBuzzMap = 
        Enumerable
          .Range(1, 100)
          .Select(num => MapToFizzBuzz(num));

      return String.Join("\n", fizzBuzzMap.ToArray());
    }

    private static string MapToFizzBuzz(int num)
    {
      if (num % 15 == 0)
        return "FizzBuzz";
      if (num % 5 == 0)
        return "Buzz";
      if (num % 3 == 0)
        return "Fizz";
      return num.ToString();
    }

Before, I lost interest.

No comments:

Post a Comment