1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FizzBuzz_State_Machine
{
    class Program
    {
        static void Main(string[] args)
        {
            Node node = new N(0);
            while (node != null) node = node.NextNode();
            Console.ReadLine();
        }
    }

    abstract class Node
    {
        public int CurrentIteration { get; protected set; }
        public Node(int i) { CurrentIteration = i; }
        public abstract Node NextNode();
    }

    class Fi : Node
    {
        public Fi(int i) : base(i) { }
        public override Node NextNode()
        {
            Console.Write("Fi");
            return new Zz(CurrentIteration, true);
        }
    }

    class Bu : Node
    {
        public Bu(int i) : base(i) { }
        public override Node NextNode()
        {
            Console.Write("Bu");
            return new Zz(CurrentIteration, false);
        }
    }

    class Zz : Node
    {
        bool _canLoop;
        public Zz(int i, bool canLoop) : base(i)
        {
            _canLoop = canLoop;
        }
        public override Node NextNode()
        {
            Console.Write("zz");
            if (CurrentIteration % 15 == 0 && _canLoop) return new Bu(CurrentIteration);
            else
            {
                if (CurrentIteration > 0) Console.WriteLine();
                CurrentIteration += 1;
                if (CurrentIteration > 100) return null;
                else if (CurrentIteration % 3 == 0) return new Fi(CurrentIteration);
                else if (CurrentIteration % 5 == 0) return new Bu(CurrentIteration);
                else return new N(CurrentIteration);
            }
        }
    }

    class N : Node
    {
        public N(int i) : base(i) { }
        public override Node NextNode()
        {
            if (CurrentIteration > 0)
            {
                Console.Write(CurrentIteration.ToString());
                Console.WriteLine();
            }
            CurrentIteration += 1;
            if (CurrentIteration > 100) return null;
            else if (CurrentIteration % 3 == 0) return new Fi(CurrentIteration);
            else if (CurrentIteration % 5 == 0) return new Bu(CurrentIteration);
            else return new N(CurrentIteration);
        }
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//  Microsoft (R) .NET Framework IL Disassembler.  Version 4.0.30319.1
//  Copyright (c) Microsoft Corporation.  All rights reserved.



// Metadata version: v4.0.30319
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 4:0:0:0
}
.assembly Gobiner.CSharpPad.Eval.Evil1139436345
{
  .custom instance void [mscorlib]System.Runtime.CompilerServices.RuntimeCompatibilityAttribute::.ctor() = ( 01 00 01 00 54 02 16 57 72 61 70 4E 6F 6E 45 78   // ....T..WrapNonEx
                                                                                                             63 65 70 74 69 6F 6E 54 68 72 6F 77 73 01 )       // ceptionThrows.
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilationRelaxationsAttribute::.ctor(int32) = ( 01 00 08 00 00 00 00 00 ) 
  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.module Gobiner.CSharpPad.Eval.Evil1139436345.exe
// MVID: {BD553884-71C7-4AA4-954D-145C1ABF4BFC}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x00000000002F0000


// =============== CLASS MEMBERS DECLARATION ===================

.class private auto ansi beforefieldinit FizzBuzz_State_Machine.Program
       extends [mscorlib]System.Object
{
  .method private hidebysig static void  Main(string[] args) cil managed
  {
    .entrypoint
    // 
    .maxstack  2
    .locals init (class FizzBuzz_State_Machine.Node V_0)
    IL_0000:  ldc.i4.0
    IL_0001:  newobj     instance void FizzBuzz_State_Machine.N::.ctor(int32)
    IL_0006:  stloc.0
    IL_0007:  br.s       IL_0010

    IL_0009:  ldloc.0
    IL_000a:  callvirt   instance class FizzBuzz_State_Machine.Node FizzBuzz_State_Machine.Node::NextNode()
    IL_000f:  stloc.0
    IL_0010:  ldloc.0
    IL_0011:  brtrue.s   IL_0009

    IL_0013:  call       string [mscorlib]System.Console::ReadLine()
    IL_0018:  pop
    IL_0019:  ret
  } // end of method Program::Main

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor() cil managed
  {
    // 
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ret
  } // end of method Program::.ctor

} // end of class FizzBuzz_State_Machine.Program

.class private abstract auto ansi beforefieldinit FizzBuzz_State_Machine.Node
       extends [mscorlib]System.Object
{
  .field private int32 '<CurrentIteration>k__BackingField'
  .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 
  .method public hidebysig specialname instance int32 
          get_CurrentIteration() cil managed
  {
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 
    // 
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  ldfld      int32 FizzBuzz_State_Machine.Node::'<CurrentIteration>k__BackingField'
    IL_0006:  ret
  } // end of method Node::get_CurrentIteration

  .method family hidebysig specialname instance void 
          set_CurrentIteration(int32 'value') cil managed
  {
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) 
    // 
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  ldarg.1
    IL_0002:  stfld      int32 FizzBuzz_State_Machine.Node::'<CurrentIteration>k__BackingField'
    IL_0007:  ret
  } // end of method Node::set_CurrentIteration

  .method public hidebysig specialname rtspecialname 
          instance void  .ctor(int32 i) cil managed
  {
    // 
    .maxstack  8
    IL_0000:  ldarg.0
    IL_0001:  call       instance void [mscorlib]System.Object::.ctor()
    IL_0006:  ldarg.0
    IL_0007:  ldarg.1
    IL_0008:  call       instance void FizzBuzz_State_Machine.Node::set_CurrentIteration(int32)
    IL_000d:  ret
  } // end of method Node::.ctor

  .method public hidebysig newslot abstract virtual 
          instance class FizzBuzz_State_Machine.Node 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz