Created
May 5, 2025 09:52
-
-
Save einarwh/1abf70781d748615ee16f6670f1d14b7 to your computer and use it in GitHub Desktop.
FizzBuzz without conditionals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace FizzBuzzEnumerable; | |
using System.Collections; | |
using System.Collections.Generic; | |
class Program | |
{ | |
public class FizzBuzzEnumerable : IEnumerable<string> | |
{ | |
public IEnumerator<string> GetEnumerator() | |
{ | |
int n = 0; | |
Loop: | |
yield return (n + 1).ToString(); | |
yield return (n + 2).ToString(); | |
yield return "Fizz"; | |
yield return (n + 4).ToString(); | |
yield return "Buzz"; | |
yield return "Fizz"; | |
yield return (n + 7).ToString(); | |
yield return (n + 8).ToString(); | |
yield return "Fizz"; | |
yield return "Buzz"; | |
yield return (n + 11).ToString(); | |
yield return "Fizz"; | |
yield return (n + 13).ToString(); | |
yield return (n + 14).ToString(); | |
yield return "Fizz Buzz"; | |
n += 15; | |
goto Loop; | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return GetEnumerator(); | |
} | |
} | |
static void Main(string[] args) | |
{ | |
foreach (var s in new FizzBuzzEnumerable().Take(int.Parse(args[0]))) | |
{ | |
Console.WriteLine(s); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment