Sorting as a Means of Shuffling in Racket
Racket is a derivative of Lisp, and it was also the language used in my first computer science class in college. It is a functional language which encourages thinking in terms of composing simple functions to accomplish possibly complex goals. When I was a lab assistant for the class, I recall having a conversation with the professor about how to shuffle a list of numbers in the language, and I came up with an interesting solution which I will talk about in this post. In Racket, you can sort a list of anything by calling the sort function along with a list, and a function to compare any two items in the list. An example use is (sort (list 4 1 3 2) <) which produces (list 1 2 3 4) . Since shuffling isn't natively supported in Racket and the simplest shuffling algorithms are not suitable for functional languages with lists instead of arrays, we have to be creative to achieve shuffling behavior. My idea to shuffle a list was simple: replace the function ...