LoginSignup
9
4

More than 5 years have passed since last update.

PPAP with Ruby

Last updated at Posted at 2016-11-26

PPAP with Ruby

何番煎じと言われようとかまわない。

ループ

PPAP = ["\u2712\ufe0f", "\u{1f34d}\ufe0f", "\u{1f34e}\ufe0f", "\u2712\ufe0f"]

ppap = []

until ppap.last(4) == PPAP do
  ppap << PPAP.sample.tap(&method(:print))
end

puts "ペンパイナッポーアッポーペン"

再帰

PPAP = ["\u2712\ufe0f", "\u{1f34d}\ufe0f", "\u{1f34e}\ufe0f", "\u2712\ufe0f"]

def pikotaro(ppap=[])
  return "ペンパイナッポーアッポーペン" if ppap == PPAP
  pikotaro(ppap.last(3) << PPAP.sample.tap(&method(:print)))
end

puts pikotaro

遅延評価

PPAP = ["\u2712\ufe0f", "\u{1f34d}\ufe0f", "\u{1f34e}\ufe0f", "\u2712\ufe0f"]

loop
  .lazy
  .map {PPAP.sample.tap(&method(:print))}
  .each_cons(4) {|ppap| break puts "ペンパイナッポーアッポーペン" if ppap == PPAP}

実行結果

$ ruby ppap.rb 
🍎️✒️✒️🍎️🍎️✒️🍍️✒️🍍️✒️🍎️✒️✒️🍎️🍍️🍍️✒️🍎️✒️✒️🍎️✒️🍎️✒️✒️🍎️🍎️🍍️✒️🍎️✒️✒️✒️✒️✒️🍎️✒️✒️🍎️🍍️🍍️🍎️✒️🍍️🍍️✒️✒️🍍️✒️✒️✒️✒️✒️✒️🍎️🍍️🍎️✒️✒️✒️✒️🍎️🍍️🍎️🍎️🍎️🍍️🍍️🍎️✒️✒️🍍️✒️🍎️🍎️✒️✒️🍎️✒️🍍️🍍️🍎️🍍️🍎️🍍️✒️🍎️🍍️🍎️✒️🍎️🍍️✒️✒️🍍️🍍️✒️✒️✒️✒️🍎️✒️🍍️✒️✒️🍎️✒️🍍️🍍️✒️🍍️✒️🍍️✒️🍍️🍎️🍍️✒️✒️✒️🍎️✒️✒️✒️✒️✒️✒️🍍️🍍️✒️🍎️🍎️✒️✒️🍎️✒️🍍️✒️🍍️🍎️✒️ペンパイナッポーアッポーペン

参考

9
4
0

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
9
4