Created
March 12, 2016 13:54
-
-
Save maraigue/45cd785302115fe0ea9d to your computer and use it in GitHub Desktop.
[Ruby] 「ズン」か「ドコ」をランダムに出力し、「ズンズンズンズンドコ」が並んだ時点で「キ・ヨ・シ!」を出力し終了する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
# https://twitter.com/kumiromilk/status/707437861881180160 | |
# 「ズン」か「ドコ」をランダムに出力し、 | |
# 「ズンズンズンズンドコ」が並んだ時点で | |
# 「キ・ヨ・シ!」を出力し終了する | |
Source = %w[ズン ドコ] | |
Pattern = %w[ズン ズン ズン ズン ドコ] | |
stock = [] | |
while true | |
elem = Source.sample | |
print "#{elem}" | |
stock << elem | |
stock = stock[-5..-1] if stock.size >= 5 # 最後5つだけ残す | |
if stock == Pattern | |
puts "キ・ヨ・シ!" | |
break | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment