Last active
March 26, 2018 09:32
-
-
Save gouf/9d1d6b0481e63d6a63b60491ae16c12b to your computer and use it in GitHub Desktop.
Yet Another Zundoko
This file contains 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
# frozen_string_literal: true | |
# Ref: <https://en.wikipedia.org/wiki/Kiyoshi_Hikawa> | |
# Ref: <https://twitter.com/kumiromilk/status/707437861881180160> | |
# See also: <https://qiita.com/shunsugai@github/items/971a15461de29563bf90> | |
# 「ズン」「ドコ」のいずれかをランダムで出力し続けて | |
# 「ズン」「ズン」「ズン」「ズン」「ドコ」の配列が出たら | |
# 「キ・ヨ・シ!」って出力して終了 | |
class Zundoko | |
WORD_PAIR = %w[ズン ドコ] | |
TERMINATE_RULE = %w[ズン ズン ズン ズン ドコ] | |
SUFFIX_WORD = ' キ・ヨ・シ!' | |
private_constant :WORD_PAIR, :TERMINATE_RULE, :SUFFIX_WORD | |
def self.ki_yo_shi!(buf = [], count = 0) | |
return [buf.join(' ') << SUFFIX_WORD, count] if buf.last(TERMINATE_RULE.size).eql?(TERMINATE_RULE) | |
ki_yo_shi!(buf << WORD_PAIR.sample, count + 1) | |
end | |
end | |
puts Zundoko.ki_yo_shi! | |
# => ズン ズン ドコ ズン ドコ ズン ドコ ドコ ズン ズン ドコ ドコ ズン ズン ドコ ズン ドコ ドコ ドコ ズン ドコ ズン ドコ ズン ドコ ズン ドコ ドコ ドコ ズン ズン ズン ドコ ズン ズン ドコ ズン ズン ドコ ドコ ズン ドコ ズン ドコ ドコ ドコ ズン ドコ ズン ズン ズン ドコ ドコ ズン ズン ドコ ドコ ドコ ドコ ズン ズン ドコ ズン ズン ズン ドコ ドコ ズン ドコ ズン ドコ ドコ ドコ ズン ズン ズン ズン ズン ドコ キ・ヨ・シ! | |
# 79 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment