Skip to content

Instantly share code, notes, and snippets.

@jbeda
Created December 5, 2012 18:21
Show Gist options
  • Save jbeda/4218134 to your computer and use it in GitHub Desktop.
Save jbeda/4218134 to your computer and use it in GitHub Desktop.
Pick a winner out of a hat
import sys
import random
# Pick the number
magic = random.randint(0, 99)
print "Magic number is %d" % magic
candidates = sys.argv[1:]
for candidate in candidates:
# find the distance to magic in a wrapped space
candidate = int(candidate)
distance1 = abs(magic - candidate)
distance2 = abs(magic - candidate + 100)
distance3 = abs(magic - candidate - 100)
distance = min(distance1, distance2, distance3)
print "%d is %d away" % (candidate, distance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment