LoginSignup
3
1

More than 5 years have passed since last update.

Ruby で「114514」になったら勝ち

Last updated at Posted at 2015-08-20

http://shindanmaker.com/536869 という診断メーカーを見つけたのでrubyで書いてみた。
もう少しきれいなコードで書けると思うので誰か教えてください。

maker.rb
test = %w(1 1 4 5 1 4)
count = 0
loop do
    t = Array.new
    test.size.times do 
        t.push(test[rand(test.size - 1)])
    end

    t = t.join
    count += 1
    if t == "114514"
        print (t + "!\n")
        puts (count.to_s+"回目で成功")
        break
    else
        puts (t+"!\n")
    end
end

114514って出るまでひたすら繰り返す ただそれだけ

3
1
2

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
3
1