Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>3rd edit:</p> <p>Here is one way to "get rid of the bool" from your version (that is replace the for loop in your original question with this):</p> <pre><code>for (int i = 1; i &lt;= 100; i++) { var x = combinations.Where(n =&gt; i % n.Item1 == 0); if (x.Count() == 0) Console.Write(i); else Console.Write(string.Join("",x.Select(e =&gt; e.Item2))); Console.Write(Environment.NewLine); } </code></pre> <hr> <p>Prior answers:</p> <p>For a pure C# solution check out <a href="https://github.com/Keith-S-Thompson/fizzbuzz-polyglot/blob/master/fizzbuzz.cs">Keith Thompson's</a> solution.</p> <pre><code>using System; class FizzBuzz { static void Main() { for (int n = 1; n &lt;= 100; n ++) { if (n % 15 == 0) { Console.WriteLine("FizzBuzz"); } else if (n % 3 == 0) { Console.WriteLine("Fizz"); } else if (n % 5 == 0) { Console.WriteLine("Buzz"); } else { Console.WriteLine(n); } } } } </code></pre> <p>I worked a bit on FixBuzz using linq. These are the solutions I came up with -- I believe they represent the best way to express the solution to this problem using Linq. (<a href="https://github.com/hoganlong/fizzbuzz-polyglot">GitHub</a>)</p> <pre><code>using System; using System.Linq; class FizzBuzz { static void Main() { var list = Enumerable.Range(1,100) .Select(n =&gt; { if (n % 15 == 0) { return "FizzBuzz"; } if (n % 3 == 0) { return "Fizz"; } if (n % 5 == 0) { return "Buzz"; } return n.ToString(); }); foreach(string item in list) Console.WriteLine(item); } } </code></pre> <p>and the crazy one line version: </p> <pre><code>using System; using System.Linq; class FizzBuzz { static void Main() { Console.WriteLine( String.Join( Environment.NewLine, Enumerable.Range(1, 100) .Select(n =&gt; n % 15 == 0 ? "FizzBuzz" : n % 3 == 0 ? "Fizz" : n % 5 == 0 ? "Buzz" : n.ToString()) )); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload