The power of programming in the service of Christmas: Organise an automated Secret Santa

This Christmas, technology in the service of tradition

Christmas is a time of joy, reunions and, of course, presents. One of the most popular traditions at this time of year is the’Secret Santa, A fun and affordable way to spread smiles without emptying your wallet. But let's be honest: organising a Secret Santa isn't as magical as it seems. You've got repeated names, someone always misses out, the assignments are obvious… and in the end, there's always someone complaining.

What if I told you that technology can solve this mess with elegance? With a simple programme, you can run the Secret Santa draw without any complications, errors or cheating. What's more, you won't just be able to use it, but also customise it, understand it and, who knows, perhaps take your first steps into the world of programming.

Optimum Repair SL™, We love combining tradition and innovation. This little Secret Santa programme is just one example of how technology can make our lives easier. If you have any questions, need help running it or want to learn more, please don't hesitate to get in touch with us.

We are not only experts in repairing computer equipment, but also in making technology accessible to everyone. In this article, we're giving you some software and will explain how to use and even modify a small programme written in Java that will make organising your Secret Santa as simple as clicking. Shall we?

Why is programming important, even for an invisible friend?

We often think of programming as something remote, reserved only for experts working in tech companies. But nothing could be further from the truth. Every time you use an app, check your online banking or manage an invoice with an accounting programme, you're using tools created with lines of code.

Learning a bit of programming can open up a world of possibilities:

  • Automate repetitive tasks.

  • Better understand how the tools you use every day work.

  • Create small, useful apps for your everyday life, like the one we're presenting to you today.

This Secret Santa programme is a perfect example: a simple idea that can save you time and headaches while adding a bit of technology to Christmas traditions.

How does the Secret Santa programme work?

This programme is written in Java, a programming language that, despite being very powerful, can seem accessible even to beginners. Its function is simple but effective:

  1. Read a list of names that you can easily edit in a text file.

  2. It carries out a completely random draw among the participants.

  3. Generate an individual file for each person, with the name of the person they are to give the gift to.

Why is it useful? Because it eliminates human error and ensures that each participant can only see the recipient of their gift. And if you're curious, we also provide the full code so you can modify it as you wish or learn a bit more about how it works.

Step-by-step instructions

1. Download the files

The programme consists of two files:

2. Write the names of the participants

Open the participants.txt file with Notepad or any simple text editor. Enter one name per line. For example:

Anna, Marc, Júlia, Pere, Marta

Save the file.

3. Run the programme

Double-click on the AmicInvisible.bat file. The program:

  • It will read the names from the file.

  • They will assign a recipient to each participant.

  • It will generate files like these:

    • Anna.txt: “You have to give Pere a present.”

    • Júlia.txt: “You have to get Marta a present.”

Each file will be saved automatically in the same directory.

4. Send the results

Send each file to its recipient (via email, WhatsApp, etc.). That way, everyone will know who they're meant to give the gift to, and the mystery will be guaranteed!

Learn more: The code explained step by step

Here is the complete code for the programme. Not only is it easy to understand, but it also includes annotations so you can learn exactly what each line does and, if you wish, modify or add complexity and features, even optimise the code!

import Java I/O.*; // Allows managing files

import java.nio.file.*; // Facilitates the reading of the names file

import java.util.*; // To work with lists and shuffle randomly

public class AmicInvisible {

public static void main(String[] args) throws IOException { // Read the names from the file “participants.txt"

List participants = Files.readAllLines(Paths.get(“participants.txt”)); // Create a copy of the names and shuffle them

List recipients = new ArrayList(participants);

Collections.shuffle(recipients); // Checks that nobody gives themselves a gift

while (!assignmentsCorrect(participants, recipients)) {

Shuffle the recipients.;

Generate a .txt file for each participant with the recipient's name.

for (int i = 0; i < participants.size(); i++) {

String participant = participants.get(i);

String recipient = recipients.get(i);

FileWriter writer = new FileWriter(participant + “.txt”);

You must give a gift to: + recipient;

Close the writer.;

}

The files have been generated correctly!;

}// Check that nobody gives themselves a gift

private static boolean correctAssignments(List participants, List recipients) {

for (int i = 0; i < participants.size(); i++) {

if (participants.get(i).equals(destinatari.get(i))) {

return false;

}

}

return true;

}

}

What does each part of the code do?

  • ImportsThey allow you to work with files, lists and random numbers.

  • Reading namesOpen the participants.txt file and save the names.

  • Mixing and validationEnsure that no participant cheats themselves.

  • File creationGenerate a custom .txt file for each participant.

If you want to customise it, you can edit the file's message or add conditions (for example, that couples don't give gifts to each other).

Have a Christmas full of technology… and of very special presents!

Facebook
Twitter
LinkedIn