Git Product home page Git Product logo

secret_santa's Introduction

secret santa

secret santa selector program ๐ŸŽ…

Objectives

a python program that will generate double blind secret santa matches based on a TXT file input

fun

this program initially used a different algorithim for selection, simply using the random choice function of python to make selections of gift givers, but i found a problem with that, being that a person could be left out using that algorithim.

the past algorithim to the pool was:

participant_list = ['A', 'B', 'C']
receiver_list = copy(participant_list)

for participant in participant_list:

    possible_receivers = receiver_list.remove(participant) 
    # remove the participant from the list so that our participant could not match with themselves

    match = choice(possible_receivers) 
    # select a random participant as our match using python's random.choice

    receiver_list.remove(match) 
    # remove that participant from the list as they've already found a secret santa ๐Ÿ˜‰-๐ŸŽ…

take this example:

>>> people_pool = ['A', 'B', 'C']
>>> people_pool
['A', 'B', 'C']
>>> receiver_pool = people_pool[::-1] # shallow copy
>>> receiver_pool
['A', 'B', 'C']
>>> for person in people_pool:
...     possible_receivers = receiver_pool.remove(person)
...     match = choice(possible_receivers)
...     receiver_pool.remove(match)

# runs

# 1
person  # A
possible_receivers  # ['A', 'B', 'C'] -> remove self from receiver list -> ['B', 'C']
match  # ['B', 'C'] -> 'B' is chosen 
receiver_pool  # ['A', 'B', 'C'] -> remove choice from receiver list -> ['A', 'C']

# 2
person  # B
possible_receivers  # ['A', 'C'] -> remove self from receiver list (we are not in it) -> ['A', 'C'] 
match  # ['A', 'C'] -> 'A' is chosen 
receiver_pool  # ['A', 'C'] -> remove choice from receiver list -> ['C']

# 3
person  # C
possible_receivers  # ['C'] -> we are the only possible receiver, since: A => B; B => A -> we remove ourself from the pool -> []
match  # [] -> the list is empty and we cannot make a match 
receiver_pool  # [] -> we have no match, and probably error out of range index

this algorithim worked (most of the time, depending on N (number of participants)) but i wanted something that would work 100% of the time with no bugs to have to think about. the new algorithim which i use instead is much simpler and doesnt have this problem. (see santa.py)

Installation

Install Python if you dont already have it

Python

Clone the git repo

git clone https://github.com/JaffarA/secret-santa.git

Install the requirements

pip install -r requirements.txt

Usage

Modify the participants.txt file with all your participants separated with newlines

a
b
c

You can use the program with

python santa.py

Then you can check the 'THIS PROJECT/matches' dir for your match files

NOTE: these files are just .txt files with the match's name, if you want to run a true anonymous secret santa, i recommend you dont open them ๐Ÿ˜Š

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

FAQ

If any questions are ever asked, they will be answered here. ๐Ÿ™‹

License

GPL-3

secret_santa's People

Watchers

Jaffar Almaleki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.