PPAPアルゴリズム

文化の日らしく芸術鑑賞をしていてインスパイアされたのでアルゴリズムを書いてみた。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
class PikoTaro:
def uh(self, objects):
assert len(objects) == 2
stack = []
for i, o in enumerate(objects[::-1]):
if type(o) == list:
stack += o[::-1] if i == 0 else o
elif type(o) == str and '-' in o:
o = o.split('-')
stack += o[::-1] if i == 0 else o
else:
stack.append(o)
print('Uh!')
return '-'.join(stack)
def ppap(iteration):
pikotaro = PikoTaro()
ap = pikotaro.uh([s.split()[-1] for s in ("I have a Pen", "I have a Apple")])
print(ap)
pp = pikotaro.uh([s.split()[-1] for s in ("I have a Pen", "I have Pineapple")])
print(pp)
ppap = pikotaro.uh((ap, pp))
print(ppap)
if iteration > 0:
print('***')
for i in range(iteration):
ppap = pikotaro.uh((ppap, ppap))
print(ppap)
if __name__ == "__main__":
ppap(iteration=(int(sys.argv[1]) if len(sys.argv) > 1 else 5))

実行結果:

:hiroki $ python ppapp/ppap.py 5
Uh!
Apple-Pen
Uh!
Pineapple-Pen
Uh!
Pen-Pineapple-Apple-Pen
***
Uh!
Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen
Uh!
Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen
Uh!
Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen
Uh!
Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen
Uh!
Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen-Pen-Apple-Pineapple-Pen-Pen-Pineapple-Apple-Pen

https://github.com/chantera/ppapp 🖋🍍🍎🖋

歌詞的に”I have a Apple”, “I have Pineapple”が正しいらしい。

LINEで送る
Pocket

コメントを残す

*