I finally got around to working on Brent Simmons’s challenge (or, rather, his pointer to a challenge) for implementing a Secret Santa sort. His original post is here and my Gist implementation is here. I like this solution as it effectively treats an array as a circularly linked-list in order to find a valid Santa assignment. This is meant to be run from the command line with the command cat secret_santa.txt | swift santa_sort.swift on a file like this:
1 2 3 4 5 6 7 |
Luke Skywalker luke@theforce.net Leia Skywalker leia@therebellion.org Toula Portokalos toula@manhunter.org Gus Portokalos gus@weareallfruit.net Bruce Wayne bruce@imbatman.com Virgil Brigman virgil@rigworkersunion.org Lindsey Brigman lindsey@iseealiens.net |
Let me know if you have any suggestions or spot any errors!