Last active
May 19, 2021 19:40
-
-
Save johnwargo/1ec3516a8ed3394934d9240f12218efe to your computer and use it in GitHub Desktop.
Advent Scheduler
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
# Advent Scheduler | |
# By John M. Wargo | |
# Based on initial work by Jannis Jaeger | |
import random | |
# Constants | |
ADVENT_DAYS = 25 | |
# NAMES = ["Anna", "John", "Elizabeth", "August", "Jannis"] | |
NAMES = ["Anna", "John", "Elizabeth", "August"] | |
NUM_USERS = len(NAMES) | |
# Variables | |
slots = [] | |
def randomize_array(the_array): | |
# get a copy of the list passed in | |
temp_array = list(the_array) | |
# shuffle (randomize) the copied array | |
random.shuffle(temp_array) | |
# return it to the calling function | |
return temp_array | |
def build_calendar(day, name_array): | |
member_calendar = [] | |
# randomize the list of names | |
names = randomize_array(name_array) | |
# set the index we'll use against the names array | |
name_index = 0 | |
num_names = len(names) | |
while day < ADVENT_DAYS: | |
# add the day/name to the array | |
member_calendar.append([day, names[name_index]]) | |
# Increment the day | |
day += NUM_USERS | |
# increment the name index | |
name_index += 1 | |
# check to see if we're at the end of the list | |
if name_index == num_names: | |
# reset the name index | |
name_index = 0 | |
# randomize the name array | |
names = randomize_array(name_array) | |
return member_calendar | |
print("\n Advent Calendar Creator") | |
print("====================================================") | |
for idx in range(len(NAMES)): | |
# add the current name (and a empty array) to the slots array | |
slots.append([NAMES[idx], []]) | |
# get a copy of the names array (randomized) | |
slot_names = list(NAMES) | |
# remove the current name from the list | |
slot_names.remove(NAMES[idx]) | |
# build the calendar for this user | |
slots[idx][1] = build_calendar(idx + 1, slot_names) | |
print(slots[idx][0], slots[idx][1]) | |
print("\nDone!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment