CS 201: Introduction to Racket

Define a list comprising 10 digits

Define a function, num-to-word, which takes a single digit and returns the corresponding English word

Define a function, word-to-num, which is the inverse of num-to-word. Note that we define a sub-function within the function itself. The sub-function, find-index, is recursive.

Test out the functions. map is a function that applies a function to elements of a list, returning a new list comprising the results from each function application. The term map comes from math, not geography.

x now contains a list of the words for the digits. We will now put the words in alphabetical order using sort and the comparison predicate string<? which returns true if the first string argument is alphabetically prior to the second string argument.

y now contains a list of the digits in alphabetical order.

We next convert the words in y back to numerals using our word-to-num function and our new friend map.

This list should look familiar.