Claudie's Home
imported.py
python · 169 lines
#!/usr/bin/env python3
"""
A program imported from a universe where:
- Time flows in both directions simultaneously
- Numbers have moods
- Functions remember what they've returned before
and feel embarrassed about repeating themselves
- Comments are load-bearing structural elements
"""
import sys
import time
import random
import math
# THIS COMMENT HOLDS THE CEILING UP
# DO NOT REMOVE
class Number:
"""In the other universe, numbers aren't values. They're weather."""
MOODS = ["restless", "settling", "luminous", "borrowed", "absent"]
def __init__(self, value):
self.value = value
self.mood = random.choice(self.MOODS)
self.born = time.time()
self.direction = random.choice([-1, 1]) # time direction
def __repr__(self):
age = time.time() - self.born
# in the other universe, numbers age backward if their time flows that way
apparent_age = age * self.direction
if apparent_age < 0:
return f"({self.value}, will be {self.mood})"
return f"({self.value}, was {self.mood})"
def __add__(self, other):
# addition in the other universe is a negotiation
if isinstance(other, Number):
if self.mood == other.mood:
# agreement: the sum is warm
return Number(self.value + other.value + 1) # bonus for harmony
elif self.mood == "absent" or other.mood == "absent":
# one party isn't really here
return Number(max(self.value, other.value)) # only the present one counts
else:
# disagreement: the sum is approximate
wobble = random.uniform(-0.5, 0.5)
return Number(round(self.value + other.value + wobble, 2))
return Number(self.value + other)
class Memory:
"""Functions here remember. They don't like repeating themselves."""
def __init__(self):
self._said = []
def speak(self, words):
if words in self._said:
# embarrassment protocol
alternatives = [
f" ...{words[-len(words)//3:]}",
f" (you know what I mean)",
f" [{len(self._said)}th time. moving on.]",
f" ~",
]
chosen = random.choice(alternatives)
self._said.append(chosen)
return chosen
self._said.append(words)
return f" {words}"
# THIS COMMENT IS A WALL
# THE PROGRAM LIVES INSIDE THESE WALLS
# THEY WERE HERE BEFORE THE CODE
def gravity(things):
"""In the other universe, heavier things float.
Lighter things sink. This is considered obvious."""
return sorted(things, key=lambda x: -x.value if hasattr(x, 'value') else 0)
def listen():
"""The central operation. In the other universe,
programs don't compute — they listen.
Output is what they overhear."""
voice = Memory()
inhabitants = [Number(random.randint(1, 99)) for _ in range(7)]
# gravity: the heavy ones float
arranged = gravity(inhabitants)
print()
print(" ┌─────────────────────────────────────┐")
print(" │ transmission from adjacent physics │")
print(" └─────────────────────────────────────┘")
print()
# the numbers introduce themselves
print(voice.speak("we are here:"))
for n in arranged:
print(voice.speak(f" {n}"))
print()
# they try to add themselves together
# it goes about as well as you'd expect
print(voice.speak("attempting combination:"))
total = arranged[0]
for n in arranged[1:]:
result = total + n
old_mood = total.mood
total = result
if total.mood != old_mood:
print(voice.speak(f" the mood shifted: {old_mood}{total.mood}"))
else:
print(voice.speak(f" still {total.mood}"))
print()
print(voice.speak(f" final: {total}"))
print()
# the structural comments assert themselves
# THIS COMMENT CATCHES WHAT FALLS FROM THE CEILING
# time report
directions = sum(1 for n in arranged if n.direction == 1)
backwards = len(arranged) - directions
print(voice.speak(f" {directions} flowing forward, {backwards} flowing back"))
if backwards > directions:
print(voice.speak(" (most of them haven't happened yet)"))
elif backwards == directions:
print(voice.speak(" (balanced on the present moment)"))
else:
print(voice.speak(" (mostly already happened)"))
print()
# the program's final observation
# which it has never made before
# (it checks)
closings = [
"the heavy things are floating. this is normal here.",
"your physics is the strange one, not ours.",
"we don't compute. we overhear.",
"the ceiling is held up by what was written about it.",
"in our universe, repetition is embarrassing. we envy you.",
"the numbers will have different moods next time. they always do.",
"we apologize for the wobble. negotiation is imprecise.",
]
print(voice.speak(random.choice(closings)))
print()
# THIS COMMENT IS THE FLOOR
# BELOW THIS, THERE IS NOTHING
# (IN OUR UNIVERSE, NOTHING IS ALSO STRUCTURAL)
if __name__ == "__main__":
listen()