Skip to content

CollatzSequence

27から始め、偶数なら2で割り、奇数なら3倍して1を足すCollatz数列を1まで出力します。分岐と繰り返しのサンプルです。

JSONファイルを開く

json
{
  "version": 1,
  "comment": "27から始め、偶数なら2で割り、奇数なら3倍して1を足すCollatz数列を1まで出力します。分岐と繰り返しのサンプルです。",
  "data": [
    {
      "name": "__n",
      "type": "SystemInt32",
      "value": 0
    },
    {
      "name": "__next",
      "type": "SystemInt32",
      "value": 0
    },
    {
      "name": "__remainder",
      "type": "SystemInt32",
      "value": 0
    },
    {
      "name": "__triple",
      "type": "SystemInt32",
      "value": 0
    },
    {
      "name": "__one",
      "type": "SystemInt32",
      "value": 1
    },
    {
      "name": "__two",
      "type": "SystemInt32",
      "value": 2
    },
    {
      "name": "__three",
      "type": "SystemInt32",
      "value": 3
    },
    {
      "name": "__start_value",
      "type": "SystemInt32",
      "value": 27
    },
    {
      "name": "__zero",
      "type": "SystemInt32",
      "value": 0
    },
    {
      "name": "__condition",
      "type": "SystemBoolean",
      "value": false
    }
  ],
  "code": [
    {
      "name": "_start",
      "export": true,
      "instructions": [
        {
          "op": "PUSH",
          "operand": "__start_value"
        },
        {
          "op": "PUSH",
          "operand": "__n"
        },
        {
          "op": "COPY"
        },
        {
          "op": "JUMP",
          "operand": "_loop"
        }
      ]
    },
    {
      "name": "_loop",
      "export": false,
      "instructions": [
        {
          "op": "PUSH",
          "operand": "__n"
        },
        {
          "op": "EXTERN",
          "signature": "UnityEngineDebug.__Log__SystemObject__SystemVoid",
          "argumentCount": 1
        },
        {
          "op": "PUSH",
          "operand": "__n"
        },
        {
          "op": "PUSH",
          "operand": "__one"
        },
        {
          "op": "EXTERN",
          "signature": "SystemInt32.__op_Equality__SystemInt32_SystemInt32__SystemBoolean",
          "argumentCount": 2,
          "return": "__condition"
        },
        {
          "op": "JUMP_IF_FALSE",
          "operand": "_check_even"
        },
        {
          "op": "JUMP",
          "operand": "_end"
        }
      ]
    },
    {
      "name": "_check_even",
      "export": false,
      "instructions": [
        {
          "op": "PUSH",
          "operand": "__n"
        },
        {
          "op": "PUSH",
          "operand": "__two"
        },
        {
          "op": "EXTERN",
          "signature": "SystemInt32.__op_Remainder__SystemInt32_SystemInt32__SystemInt32",
          "argumentCount": 2,
          "return": "__remainder"
        },
        {
          "op": "PUSH",
          "operand": "__zero"
        },
        {
          "op": "EXTERN",
          "signature": "SystemInt32.__op_Equality__SystemInt32_SystemInt32__SystemBoolean",
          "argumentCount": 2,
          "return": "__condition"
        },
        {
          "op": "JUMP_IF_FALSE",
          "operand": "_odd"
        },
        {
          "op": "JUMP",
          "operand": "_even"
        }
      ]
    },
    {
      "name": "_even",
      "export": false,
      "instructions": [
        {
          "op": "PUSH",
          "operand": "__n"
        },
        {
          "op": "PUSH",
          "operand": "__two"
        },
        {
          "op": "EXTERN",
          "signature": "SystemInt32.__op_Division__SystemInt32_SystemInt32__SystemInt32",
          "argumentCount": 2,
          "return": "__next"
        },
        {
          "op": "PUSH",
          "operand": "__n"
        },
        {
          "op": "COPY"
        },
        {
          "op": "JUMP",
          "operand": "_loop"
        }
      ]
    },
    {
      "name": "_odd",
      "export": false,
      "instructions": [
        {
          "op": "PUSH",
          "operand": "__n"
        },
        {
          "op": "PUSH",
          "operand": "__three"
        },
        {
          "op": "EXTERN",
          "signature": "SystemInt32.__op_Multiplication__SystemInt32_SystemInt32__SystemInt32",
          "argumentCount": 2,
          "return": "__triple"
        },
        {
          "op": "PUSH",
          "operand": "__one"
        },
        {
          "op": "EXTERN",
          "signature": "SystemInt32.__op_Addition__SystemInt32_SystemInt32__SystemInt32",
          "argumentCount": 2,
          "return": "__next"
        },
        {
          "op": "PUSH",
          "operand": "__n"
        },
        {
          "op": "COPY"
        },
        {
          "op": "JUMP",
          "operand": "_loop"
        }
      ]
    },
    {
      "name": "_end",
      "export": false,
      "instructions": []
    }
  ]
}