Created
June 9, 2010 10:27
-
-
Save passy/431305 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
""" | |
welcal | |
~~~~~~ | |
Erzeut eine Liste mit Wochen und zwei Namen als CSV auf STDOUT. | |
:copyright: 2010, Pascal Hartig <phartig@weluse.de> | |
:license: BSD | |
""" | |
import random | |
NAMES = ( | |
'Oliver', | |
'Marten', | |
'Daniel', | |
'Markus', | |
'Marc', | |
'Passy' | |
) | |
def print_header(): | |
print("Woche,Opfer 1,Opfer 2") | |
def main(): | |
print_header() | |
last_name1, last_name2 = None, None | |
iterations = 0 | |
for week in xrange(1, 53): | |
iterations += 1 | |
name1 = random.choice(NAMES) | |
name2 = random.choice(NAMES) | |
lastset = set([last_name1, last_name2]) | |
while name2 == name1 or \ | |
name1 in lastset or \ | |
name2 in lastset: | |
name1 = random.choice(NAMES) | |
name2 = random.choice(NAMES) | |
iterations += 1 | |
print("{0},{1},{2}".format(week, name1, name2)) | |
last_name1 = name1 | |
last_name2 = name2 | |
print("\nTotal Iterations: {0}".format(iterations)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment