stack machineを愛でる。 その8
1406 ワード
概要
stack machineが、好きだ。
練習問題、やってみた。
練習問題
fizzbuzzを、表示せよ。
考え方
剰余の求め方
iの3の剰余が0ならばskip0へ飛ぶ。
push "i"
get
push "3"
%
push "1"
>
if skip0
サンプルコード
push "x"
push ""
set
push "i"
push "0"
set
loop push "i"
push "i"
get
++
set
get
push "i"
get
push "15"
%
push "1"
>
if skip2
push "i"
get
push "5"
%
push "1"
>
if skip1
push "i"
get
push "3"
%
push "1"
>
if skip0
push "x"
push "x"
get
push "i"
get
add
set
push "x"
push "x"
get
push " "
jp skip3
skip0 push "x"
push "x"
get
push "fizz "
jp skip3
skip1 push "x"
push "x"
get
push "buzz "
jp skip3
skip2 push "x"
push "x"
get
push "fizzbuzz "
skip3 add
set
push "i"
get
push "100"
>
if loop
end
成果物
push "x"
push ""
set
push "i"
push "0"
set
loop push "i"
push "i"
get
++
set
get
push "i"
get
push "15"
%
push "1"
>
if skip2
push "i"
get
push "5"
%
push "1"
>
if skip1
push "i"
get
push "3"
%
push "1"
>
if skip0
push "x"
push "x"
get
push "i"
get
add
set
push "x"
push "x"
get
push " "
jp skip3
skip0 push "x"
push "x"
get
push "fizz "
jp skip3
skip1 push "x"
push "x"
get
push "buzz "
jp skip3
skip2 push "x"
push "x"
get
push "fizzbuzz "
skip3 add
set
push "i"
get
push "100"
>
if loop
end
以上。
Author And Source
この問題について(stack machineを愛でる。 その8), 我々は、より多くの情報をここで見つけました https://qiita.com/ohisama@github/items/e21fd67c2e16f86998dc著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .