Anagrams are words or phrases that are created from the letters of another word or phrase. They are useful in games like Scrabble or Boggle as well as being a fun way to show your skill in coding.
This challenge was inspired by a code kata from Dave Thomas that can be found here. We’re taking his kata and making it our own. Though since he’s already created a thorough word list we’ll be using that as part of this challenge.
In the challenge we’ll be looking at the characters in a word, counting them, and manipulating them. We’ll even turn it into a fun text based game. For each level you may use the command line for input and output or create a view to display on the web.
Like in past challenges we’ll be using our tests to drive our development. No matter the level you choose to work with write a test case before you start your code. Then write just enough code to pass the test. Once you have passing code refactor to pass other test cases.
For level 1 we’ll build a useful tool for counting the number of characters in a word or phrase. Start out by taking in a word or phrase as input. Then ignoring the spaces return the total number of characters in that word or phrase. Write unit tests for both words and phrases. Next return only the letters. Finally return the number of punctuation marks (.:;,!?)
Going a step further we’ll add some math into the mix. Calculate the possible number of combinations of the letters in the phrase.
Hint: The formula for calculating the possible combinations is n! or n(n - 1)(n - 2)…
Instead of looking for the number of possible combinations of letters from the input create a list of combinations and then check that on the word list provided to see if the combination is an anagram or just gibberish.
Going a step further include in your results phrases or multiple words with the same set of characters.
Now the fun begins. We are creating a game of anagrams. Instead of taking in a word or phrase have the player input the number of characters for the word with a minimum of three characters. Next randomly select a word from the word list with that number of characters and display it to the player.
Allow the player to input different anagrams for the word selected. Calculate points based on the following scheme:
Display the player’s score after they input their anagrams.
The display should look something like this:
Make the game more interesting by adding a timer to limit the amount of time the player has to enter anagrams. If you have time make the game multiplayer and track scores for each player in the round.