mecobalamin’s diary

人間万事塞翁が馬

https://help.hatenablog.com/entry/developer-option

次はRで

前回pythonで書いたことを今度はRに移植

p <- c("PEN", "APPLE", "PINEAPPLE")
word <- ""

while(word != "PEN, PINEAPPLE, APPLE, PEN"){
  n <- as.integer(runif(4, min = 1, max = 4))

  word <- c(p[n[1]])
  for(j in 2:4){
    word <- paste(word, p[n[j]], sep = ", ")
  }

  print(word)
}

print("PPAP!")

ベクトル間の比較でTRUE/FALSEは返すが
その数を調べる方法がわからなかった
乱数で単語を選んで文字列に結合
そして正解と比較した
結果はこちら

[1] "PINEAPPLE, APPLE, APPLE, APPLE"
[1] "APPLE, PEN, PEN, PEN"
[1] "APPLE, PINEAPPLE, APPLE, PEN"
~中略~
[1] "PINEAPPLE, APPLE, PEN, APPLE"
[1] "PEN, PEN, APPLE, PINEAPPLE"
[1] "PEN, PINEAPPLE, APPLE, PEN"
[1] "PPAP!"

やっぱりRで書いている人もいるが
1行で書いてたりする
Rでズンドコ - Qiita