LoginSignup
4
4

More than 5 years have passed since last update.

ズンドコキヨシ with Groovy

Posted at

何やら流行っているようなのでGroovyでチャレンジ。
ズンドコキヨシまとめ

こういうコードは凄く苦手。。。
一応末尾再帰になっている(はず)のと、zundokoTimeの値をいじればその分ズンがドコまでズンズン続く回数を指定出来まズン。

def rnd = new Random()
def zun = "ズン"
def doko = "ドコ" 
def zundokoTime = 4

({ lyric, lyrics = [] ->
    if (lyrics == [zun]*zundokoTime + doko) {
       print "\キ・ヨ・シ!/"
    } else {
       print "${lyric} "     
       trampoline([zun, doko][rnd.nextInt(2)], lyrics in (1..zundokoTime).collect{[zun]*it} ? lyrics + lyric : [lyric])
    }
}).trampoline()([zun, doko][rnd.nextInt(2)])

実行結果:

ドコ ドコ ズン ズン ドコ ズン ドコ ドコ ズン ドコ ズン ドコ ズン ズン ズン ドコ ドコ ズン ズン ズン ズン ズン ズン ドコ ドコ ドコ ドコ ドコ ズン ドコ ドコ ズン ズン ドコ ズン ズン ズン ズン ズン ズン ドコ ドコ ズン ドコ ドコ ドコ ドコ ズン ズン ズン ドコ ドコ ズン ドコ ドコ ドコ ズン ズン ドコ ズン ズン ズン ズン ドコ \キ・ヨ・シ!/
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4