Anagrams

Posted by ErockMahan on Tue 06 Jul 2010 02:42 PM — 2 posts, 15,849 views.

#0
I'm hoping there is an easier way to do this than what I'm thinking, so I thank you in advance for helping me accomplish this.

I've got a variable string that is a set word. I'll use 'Stabs' as an example. I am then given 5 items, each of which has several key letters assigned to it. "Key of Aberforth" "Stick" "Blunt Knife" and "Tablecloth" "Orb of Spheres" (Capital Letters would be the keys for each)

With some difficulty, I've figured out how to obtain the key letters from each item, and I can even add each to a variable per item seperated however I choose.

WHAT I'M TRYING TO DO is run a script that will determine whether or not the letters from these items can be used to obtain the target word. In the example, it works because you use [S]tick [T]ablecloth [A]berforth [B]lunt [S]pheres.

I hope I don't have to explain the difficulty and challenges faced while attempting this?
USA #1
Pseudo-code...


keyWords = set of key words in input strings
for letter in wordToForm:
  word = find a word in keyWords starting with letter
  if 'word' was found:
    remove 'word' from keyWords
    continue to next letter
  else:
    report failure; we can't form wordToForm


VBscript might make this rather annoying due to its container types, but the algorithm isn't really that hard.