Created
December 19, 2014 17:07
-
-
Save rchowe/6cf3d1dab29e93c6c63f to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python | |
| from __future__ import print_function | |
| import numpy as np | |
| import time | |
| def clear(): | |
| print(chr(27) + "[2J") | |
| mapping = {} | |
| clear() | |
| try: | |
| while True: | |
| name, number = None, None | |
| while not name: | |
| name = raw_input('Please enter your name: ') | |
| while number is None: | |
| try: | |
| number = int(raw_input('Please enter your number: ')) | |
| except ValueError: | |
| print("That's not a number.") | |
| if number in mapping: | |
| print('That number is already taken.') | |
| number = None | |
| mapping[number] = name | |
| signal = raw_input('Thank you!\nPress ENTER to clear the screen, or type \'END\' to finish. ') | |
| if signal == 'END': | |
| break | |
| clear() | |
| except EOFError: | |
| pass | |
| clear() | |
| name_length = max([len(name) for name in mapping.values()]) | |
| while True: | |
| presents = set(mapping.keys()) | |
| new_mapping = {} | |
| try: | |
| for number, name in mapping.items(): | |
| n = np.random.choice(list(presents - set([number]))) | |
| presents -= set([n]) | |
| new_mapping[n] = name | |
| except ValueError: | |
| continue | |
| break | |
| for number, name in new_mapping.items(): | |
| print('{} {}'.format((name + ':').ljust(name_length + 1), number)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment