Skip to content

Instantly share code, notes, and snippets.

@andrew-d
Created March 7, 2013 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew-d/5104368 to your computer and use it in GitHub Desktop.
Save andrew-d/5104368 to your computer and use it in GitHub Desktop.
Snarky prime number guesser
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