Created
December 5, 2012 18:21
-
-
Save jbeda/4218134 to your computer and use it in GitHub Desktop.
Pick a winner out of a hat
This file contains hidden or 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 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