Skip to content

Instantly share code, notes, and snippets.

@maraigue
Created March 12, 2016 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maraigue/45cd785302115fe0ea9d to your computer and use it in GitHub Desktop.
Save maraigue/45cd785302115fe0ea9d to your computer and use it in GitHub Desktop.
[Ruby] 「ズン」か「ドコ」をランダムに出力し、「ズンズンズンズンドコ」が並んだ時点で「キ・ヨ・シ!」を出力し終了する
#!/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