We're gonna write a program that can unscramble a word. Inspired by the "Jumble" puzzle in the newspaper, the program should accept a single, scrambled word and return a matching entry from the English dictionary.
> ./unscramble cofer
force
> ./unscramble sasewe
seesaw
Basic guidelines:
- A scrambled or jumbled word has only one valid answer.
- Use the contents of
/usr/share/dict/words
as a dictionary.
Bonus points:
- Make it fast (try testing longer words, for example).
- Complete the exercise using a programming language that is new to you.
To start:
- Clone this repository.
- Create a directory based on the name of your implementation language (e.g.
languages/C
) - Create a simple
Rakefile
that has, at a minimum, abuild
task within your language's namespace (e.g.C:build
). You should check the environment and fail fast if dependencies aren't met. - Create your implementation.
- From the project root run
rake run[<language>]
to test your language (e.g.rake run[bash]
; zsh users will have to quote the argument, e.g.rake run'[bash]'
), orrake
to test all languages.
Note that the tests run against English words. If you use a different language, symlink /usr/share/dict/words
to an English word list to run the tests. If your system does not come with an English word list installed, install wamerican
or wbritish
(e.g. Ubuntu apt-get install wamerican
); english-words's words.txt
will do as well.
namespace :C do
task :check do
`which cc`
raise "Please ensure that you have a valid C compiler" unless $?.success?
end
task :build => :check do
path = File.dirname(__FILE__)
`cd #{path}; make unscramble`
end
end