http://sskaje.spaces.live.com/blog/cns!CD0E835D6C568521!911.entry
February 21, 2008
for HTS prog mission 1, find unscrambled words from a wordlist
three ways available:
a) compare the checksum
b) compare the string after been sorted
c) split to array and then use array_diff
for a) : 1278 lines of wordlist, but less than 800 different checksums, this way is somewhat fast but not very accurate.
for b) : i coded a sort function to sort a string, then loop comparing it with sorted strings from the wordlist line by line, this takes about 1.02s.
for c) : a function like this:
function diff($string1, $string2)
{
return array_diff(str_split($string1, 1), str_split($string2, 1));
}
the main part of the two php scripts are almost the same, but in this way it only takes about 0.23s to find unscrambled words from the 1278-line-txt-wordlist file.
No comments:
Post a Comment