DefconDotNet

Untitled

Sep 17th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Globalization;
  3. using System.Linq;
  4.  
  5. namespace FizzBuzz
  6. {
  7.     class Program
  8.     {
  9.         private static void Main()
  10.         {
  11.             FizzBuzz02();
  12.         }
  13.  
  14.         private static void FizzBuzz02()
  15.         {
  16.             var fizzbuzz = new[]
  17.                 {
  18.                     new[] {"Fizz", "FizzBuzz"},
  19.                     new[] {"Buzz", ""},
  20.                 };
  21.  
  22.             const int n = 100;
  23.             for (var i = 1;i <= n;++i)
  24.             {
  25.                 fizzbuzz[1][1] = i.ToString(CultureInfo.InvariantCulture);
  26.                 var f = (int) Math.Ceiling((i%3)/(double) n);
  27.                 var b = (int) Math.Ceiling((i%5)/(double) n);
  28.                 Console.Write(i + ": " + fizzbuzz[f][b] + Environment.NewLine);
  29.             }
  30.         }
  31.  
  32.         private static void FizzBuzz01(){
  33.             var matchers = new[]
  34.                 {
  35.                     new Tuple<int, string>(3, "Fizz"),
  36.                     new Tuple<int, string>(5, "Buzz")
  37.                 };
  38.  
  39.             for (var i = 1; i <= 100; i++) {
  40.                 var matches = matchers.Where(c => i % c.Item1 == 0).ToList();
  41.                 if (matches.Any())
  42.                     foreach (var comb in matches)
  43.                         Console.Write(comb.Item2);
  44.                 else
  45.                     Console.Write(i);
  46.             }
  47.         }
  48.  
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment