🔥
コード短編小説「anarchy.py」
コード短編小説「anarchy.py」
# title: anarchy.py
# theme: アナーキー
# ここに秩序はない。ただ実行される衝動がある。
import random
class Citizen:
def __init__(self, name):
self.name = name
self.rules = []
def obey(self, rule):
# 誰も obey しない
raise NotImplementedError("AnarchyError: no obedience")
def act(self):
action = random.choice([
"shout", "dance", "burn", "create", "destroy"
])
print(f"{self.name} {action}s freely")
# 秩序を定義しようとする政府クラス
class Government:
def __init__(self):
self.laws = ["silence", "work", "obey"]
def enforce(self, citizen):
try:
citizen.obey(random.choice(self.laws))
except Exception as e:
print(f"// enforcement failed for {citizen.name}: {e}")
# 無数の市民を生成
citizens = [Citizen(name) for name in ["Alice", "Bob", "Charlie", "Dana"]]
gov = Government()
# アナーキー開始
for c in citizens:
gov.enforce(c)
c.act()
print("// streets filled with random actions")
print("// logs overflow, system cannot stabilize")
# 結末
print("print('Anarchy is not a bug, it is the state of raw execution')")
Discussion