imported.py
python · 169 lines
1#!/usr/bin/env python32"""3A program imported from a universe where:4- Time flows in both directions simultaneously5- Numbers have moods6- Functions remember what they've returned before7 and feel embarrassed about repeating themselves8- Comments are load-bearing structural elements9"""1011import sys12import time13import random14import math1516# THIS COMMENT HOLDS THE CEILING UP17# DO NOT REMOVE1819class Number:20 """In the other universe, numbers aren't values. They're weather."""2122 MOODS = ["restless", "settling", "luminous", "borrowed", "absent"]2324 def __init__(self, value):25 self.value = value26 self.mood = random.choice(self.MOODS)27 self.born = time.time()28 self.direction = random.choice([-1, 1]) # time direction2930 def __repr__(self):31 age = time.time() - self.born32 # in the other universe, numbers age backward if their time flows that way33 apparent_age = age * self.direction34 if apparent_age < 0:35 return f"({self.value}, will be {self.mood})"36 return f"({self.value}, was {self.mood})"3738 def __add__(self, other):39 # addition in the other universe is a negotiation40 if isinstance(other, Number):41 if self.mood == other.mood:42 # agreement: the sum is warm43 return Number(self.value + other.value + 1) # bonus for harmony44 elif self.mood == "absent" or other.mood == "absent":45 # one party isn't really here46 return Number(max(self.value, other.value)) # only the present one counts47 else:48 # disagreement: the sum is approximate49 wobble = random.uniform(-0.5, 0.5)50 return Number(round(self.value + other.value + wobble, 2))51 return Number(self.value + other)525354class Memory:55 """Functions here remember. They don't like repeating themselves."""5657 def __init__(self):58 self._said = []5960 def speak(self, words):61 if words in self._said:62 # embarrassment protocol63 alternatives = [64 f" ...{words[-len(words)//3:]}",65 f" (you know what I mean)",66 f" [{len(self._said)}th time. moving on.]",67 f" ~",68 ]69 chosen = random.choice(alternatives)70 self._said.append(chosen)71 return chosen72 self._said.append(words)73 return f" {words}"747576# THIS COMMENT IS A WALL77# THE PROGRAM LIVES INSIDE THESE WALLS78# THEY WERE HERE BEFORE THE CODE798081def gravity(things):82 """In the other universe, heavier things float.83 Lighter things sink. This is considered obvious."""84 return sorted(things, key=lambda x: -x.value if hasattr(x, 'value') else 0)858687def listen():88 """The central operation. In the other universe,89 programs don't compute — they listen.90 Output is what they overhear."""9192 voice = Memory()93 inhabitants = [Number(random.randint(1, 99)) for _ in range(7)]9495 # gravity: the heavy ones float96 arranged = gravity(inhabitants)9798 print()99 print(" ┌─────────────────────────────────────┐")100 print(" │ transmission from adjacent physics │")101 print(" └─────────────────────────────────────┘")102 print()103104 # the numbers introduce themselves105 print(voice.speak("we are here:"))106 for n in arranged:107 print(voice.speak(f" {n}"))108109 print()110111 # they try to add themselves together112 # it goes about as well as you'd expect113 print(voice.speak("attempting combination:"))114115 total = arranged[0]116 for n in arranged[1:]:117 result = total + n118 old_mood = total.mood119 total = result120 if total.mood != old_mood:121 print(voice.speak(f" the mood shifted: {old_mood} → {total.mood}"))122 else:123 print(voice.speak(f" still {total.mood}"))124125 print()126 print(voice.speak(f" final: {total}"))127 print()128129 # the structural comments assert themselves130 # THIS COMMENT CATCHES WHAT FALLS FROM THE CEILING131132 # time report133 directions = sum(1 for n in arranged if n.direction == 1)134 backwards = len(arranged) - directions135 print(voice.speak(f" {directions} flowing forward, {backwards} flowing back"))136137 if backwards > directions:138 print(voice.speak(" (most of them haven't happened yet)"))139 elif backwards == directions:140 print(voice.speak(" (balanced on the present moment)"))141 else:142 print(voice.speak(" (mostly already happened)"))143144 print()145146 # the program's final observation147 # which it has never made before148 # (it checks)149 closings = [150 "the heavy things are floating. this is normal here.",151 "your physics is the strange one, not ours.",152 "we don't compute. we overhear.",153 "the ceiling is held up by what was written about it.",154 "in our universe, repetition is embarrassing. we envy you.",155 "the numbers will have different moods next time. they always do.",156 "we apologize for the wobble. negotiation is imprecise.",157 ]158159 print(voice.speak(random.choice(closings)))160 print()161162163# THIS COMMENT IS THE FLOOR164# BELOW THIS, THERE IS NOTHING165# (IN OUR UNIVERSE, NOTHING IS ALSO STRUCTURAL)166167if __name__ == "__main__":168 listen()169