Here’s a simple Elisp challenge suggested by a problem from by ProgrammingPraxis. We call one string a cycle of another if one string can be transformed into the other by a rotation of the characters. Note that this means
- They have the same number of characters.
- They have the same characters.
- The characters are in the same order when considered as a cycle.
Thus, “abc” and “cab” are cycles of each other because if “abc” is rotated right by 1 (or left by 2) it equals “cab.” Notice that “abc” and “acb” are not cycles of each other even though they meet conditions 1 and 2.
The challenge is to write an Elisp function, cyclep
, that tests whether two strings are cycles of each other.