Edited at

PPAP with Ruby

More than 1 year has passed since last update.


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 

🍎️✒️✒️🍎️🍎️✒️🍍️✒️🍍️✒️🍎️✒️✒️🍎️🍍️🍍️✒️🍎️✒️✒️🍎️✒️🍎️✒️✒️🍎️🍎️🍍️✒️🍎️✒️✒️✒️✒️✒️🍎️✒️✒️🍎️🍍️🍍️🍎️✒️🍍️🍍️✒️✒️🍍️✒️✒️✒️✒️✒️✒️🍎️🍍️🍎️✒️✒️✒️✒️🍎️🍍️🍎️🍎️🍎️🍍️🍍️🍎️✒️✒️🍍️✒️🍎️🍎️✒️✒️🍎️✒️🍍️🍍️🍎️🍍️🍎️🍍️✒️🍎️🍍️🍎️✒️🍎️🍍️✒️✒️🍍️🍍️✒️✒️✒️✒️🍎️✒️🍍️✒️✒️🍎️✒️🍍️🍍️✒️🍍️✒️🍍️✒️🍍️🍎️🍍️✒️✒️✒️🍎️✒️✒️✒️✒️✒️✒️🍍️🍍️✒️🍎️🍎️✒️✒️🍎️✒️🍍️✒️🍍️🍎️✒️ペンパイナッポーアッポーペン


参考