1. Qiita
  2. Items
  3. R

Rでズンドコ

  • 3
    Like
  • 0
    Comment

こういうのをPythonでも書きたいだけの人生だった

zun.R
(function(a,b){if(b==5){c(a,'キ・ヨ・シ!')}else if(rbinom(1,1,0.5)>0){Recall(c(a,'ズン'),b-1)}else{Recall(c(a,'ドコ'),4+(b<=0)*1)}})('',4)

JavaScriptでも同じようにかけるけど、ちょっと長くなる。

実行結果
Rscript zun.R
 [1] ""             "ズン"         "ズン"         "ズン"         "ドコ"        
 [6] "ドコ"         "ズン"         "ドコ"         "ドコ"         "ズン"        
[11] "ドコ"         "ズン"         "ズン"         "ドコ"         "ドコ"        
[16] "ドコ"         "ズン"         "ドコ"         "ドコ"         "ズン"        
[21] "ドコ"         "ドコ"         "ズン"         "ドコ"         "ドコ"        
[26] "ドコ"         "ズン"         "ドコ"         "ズン"         "ズン"        
[31] "ドコ"         "ドコ"         "ドコ"         "ズン"         "ドコ"        
[36] "ズン"         "ズン"         "ズン"         "ドコ"         "ズン"        
[41] "ドコ"         "ドコ"         "ドコ"         "ドコ"         "ズン"        
[46] "ズン"         "ズン"         "ドコ"         "ドコ"         "ドコ"        
[51] "ドコ"         "ドコ"         "ドコ"         "ドコ"         "ズン"        
[56] "ドコ"         "ドコ"         "ドコ"         "ズン"         "ズン"        
[61] "ズン"         "ズン"         "ズン"         "ズン"         "ズン"        
[66] "ズン"         "ズン"         "ズン"         "ズン"         "ドコ"        
[71] "キ・ヨ・シ!"

妥協したPython版

Comments Loading...