top | item 9802706

(no title)

arocks | 10 years ago

If you liked this then you might find my Python one liner games interesting [1]. They fit a tweet in most cases.

[1]: http://arunrocks.com/python-one-liner-games/

discuss

order

throwathrowaway|10 years ago

I like that lambda trick. I was hoping Crash would actually crash the program so you could tell if you won by looking at the error it gives (if its KeyboardInterrupt or something else).

Here's mine.

  $ python -c 'import random;L=sorted(str(random.randint(1,9)) for i in range(4));a=raw_input(L);print(eval(a)==24,sorted(filter(str.isdigit,a))==L)'
  ['2', '6', '7', '8']8*(7+2-6)
  (True, True)
Try to make it print (True, True) without abusing eval too much (intended to be +-*/() only with digits as tokens).

A nicer interface, but too long:

  import random;L=sorted(str(random.randint(1,9)) for i in range(4));a=raw_input(" ".join(L)+"\n> ");print(eval(a)==24,sorted(filter(str.isdigit,a))==L)

simi_|10 years ago

For some reason copy-pasting some of those into iTerm2 doesn't work.

http://i.imgur.com/GEMAeM8.png

vanous|10 years ago

not on a mac myself, but make sure to use python 3

   python3 -c "import random;p=lambda:random.choice('7♪♫♣♠♦♥◄☼☽');[print('|'.join([p(),p(),p()]),end='\r') for i in range(8**5)]"

eigenbom|10 years ago

These are pretty neat and very concise! :D