When nature meets network, even bees start mining your browser history.
Every now and then I catch myself staring at the ceiling, wondering why existence insists on happening at me, and in a moment of questionable optimism I decided the only sensible response was to try coding the meaning of life, as if a compiler might finally explain what the cosmos refuses to footnote.
This is a first cut.
CONSTANT ZERO = 0
CONSTANT ONE_THOUSAND_MINUS_ONE = 999
CONSTANT MAX_ATTEMPTS = ONE_THOUSAND_MINUS_ONE - 995 // equals 4
GLOBAL ATTEMPT_COUNT = 0
GLOBAL SEED
VARIABLE TRYING
VARIABLE FAILED
VARIABLE SUCCEEDED
VARIABLE ALIVE
MAIN:
create a new Life instance L
print "THE MEANING OF LIFE"
L.randomize()
L.beBorn()
L.live()
L.die()
print "--"
FUNCTION beBorn:
randomize()
ALIVE = true
FUNCTION live:
randomize()
WHILE event(899):
doStuff()
FUNCTION doStuff:
randomize()
WHILE event(899) AND ATTEMPT_COUNT < MAX_ATTEMPTS:
attempt()
FUNCTION attempt:
TRYING = true
ATTEMPT_COUNT += 1
print "we try"
IF ATTEMPT_COUNT < MAX_ATTEMPTS:
IF successful():
SUCCEEDED = true
print "we succeed"
ELSE:
SUCCEEDED = false
print "we fail"
TRYING = false
FUNCTION die:
IF ATTEMPT_COUNT == ZERO:
print "we didn't get a turn"
ELSE:
print "we die"
ALIVE = false
FUNCTION event(threshold):
randomize()
RETURN (SEED < threshold)
FUNCTION successful:
RETURN event(199)
FUNCTION randomize:
SEED = random integer from 0 to 999
FUNCTION print(text):
output text