文字版本
生命是一段漫长的旅程
想了,就去做。 输了,从头再来。 摔了,爬起来继续。 赢了,还要继续往前走。 死了,没留下任何遗憾。
我的理解
人总是充满各种各样的欲望,欲望促使人们做着能够满足这些欲望的事。当做完一件事,暂时满足了欲望,没有了遗憾。
但是不久,人又会有新的欲望产生,人又要为新欲望而循环反覆做着一样或者不一样的事。但是人的欲望没有止境,做的事就不会有止境。
所以,没有遗憾也只是暂时的,在你临死时你觉得没有遗憾,那只是你运气好而已。你只是上一个欲望得到了满足,而新的欲望没有开始而已。
啥时候 放下 你才是真的没有遗憾。
代码版本
Python 版本:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
import random import time class Person(object): UNKNOWN = "UNKNOWN" THOUGHT = "THOUGHT" LOST = "LOST" WON = "WON" DIED = "DIED" FELL = "FELL" def __init__(self, lose_interval=0.03, win_interval=0.03, fall_interval=0.01): super(Person, self).__init__() self.thing = None self.__status = self.UNKNOWN self.__lose_interval = lose_interval self.__win_interval = win_interval self.__fall_interval = fall_interval def __repr__(self): return "Person: {0}".format(self.__status) def __str__(self): return repr(self) def get_status(self): return self.thing.status if self.thing else Thing.UNKNOWN def thought(self): self.__status = self.THOUGHT self.thing = Thing() self.thing.start_do() def lost(self): self.__status = self.LOST if self.thing: self.thing.stop_do() time.sleep(self.__lose_interval) self.thing = Thing() self.thing.start_do() def won(self): self.__status = self.WON if self.thing: self.thing.end_do() time.sleep(self.__win_interval) def died(self): self.__status = self.DIED self.thing and self.thing.stop_do() def fell(self): self.__status = self.FELL if self.thing: self.thing.stop_do() time.sleep(self.__fall_interval) self.thing.restart_do() class Thing(object): UNKNOWN = 'UNKNOWN' REGRETS = 'REGRETS' NO_REGRETS = 'NO REGRETS' def __init__(self): super(Thing, self).__init__() self.status = self.UNKNOWN def start_do(self): self.status = self.REGRETS def stop_do(self): if self.status == self.UNKNOWN: self.status = self.REGRETS def end_do(self): self.status = self.NO_REGRETS def restart_do(self): self.status = self.REGRETS class Life(object): MIN_TIMES = 0 MAX_TIMES = 120 def __init__(self): super(Life, self).__init__() self.__person = Person() self.__times = float(random.randint(self.MIN_TIMES, self.MAX_TIMES)) * random.random() self.__progress = ( self.__person.thought, self.__person.lost, self.__person.fell, self.__person.won, ) def __is_end(self): return self.__times <= 0.0 def __elapse(self, default=None): interval = default if default is not None else random.random() if self.__times >= 0.0: self.__times -= interval def start(self): if self.__is_end(): self.__person.died() return while 1: for going in self.__progress: going() self.__elapse() if self.__is_end(): self.__person.died() return def get_status(self): return self.__person.get_status() def main(): life = Life() life.start() print life.get_status() if __name__ == '__main__': main()
comments powered by Disqus