Created
March 7, 2013 00:00
-
-
Save andrew-d/5104368 to your computer and use it in GitHub Desktop.
Snarky prime number guesser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import random | |
import subprocess | |
SNARK_CHANCE = 0.5 | |
MAX_PRIME = 100 | |
snark = [ | |
'Are you kidding me?', | |
'Not yet, really?', | |
"C'mon, gimme a break here.", | |
'Hurry up and say yes!', | |
] | |
def random_snark(): | |
if random.random() > SNARK_CHANCE: | |
s = random.choice(snark) | |
subprocess.check_call(['say', s]) | |
def primes_sieve(limit): | |
a = [True] * limit | |
a[0] = a[1] = False | |
for i, isprime in enumerate(a): | |
if isprime: | |
yield i | |
for n in xrange(i*i, limit, i): | |
a[n] = False | |
subprocess.check_call(['say', 'Is it?']) | |
for i in primes_sieve(MAX_PRIME): | |
subprocess.check_call(['say', "%d" % (i,)]) | |
random_snark() | |
time.sleep(0.2) | |
subprocess.check_call(['say', 'All done!']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment