Make a dictionary first. A hash is probably best for easy lookup.
You can attack this problem in two ways. There's a brute force approach and there's a better approach.
You'll probably either use recursion or build strings to test. Be careful if you use recursion, you might get into an infinitely deep loop and run out of memory.