Coincidence?
- Google Predict through the API Explorer - tick.
- Through Google's sample code - tick.
- Cut down to my own DLL - failed.
I spent an afternoon on the Word Chain kata. The challenge is given two words of equal length (e.g. CODE and MESS) to find words that change one into the other, altering one letter at a time, so CODE MODE MODS MOSS MESS.
public List<string> GetPossibleNextWords(string word)
{
List<string> result = new List<string>();
int wordhash = HashMap.MyHash(word);
for (int i = 0; i < word.Length; i++)
{
string before = String.Empty, after = String.Empty;
long hash0 = wordhash - HashMap.HashAt(word[i], i, word.Length);
char skipc = word[i];
for (char c = 'a'; c <= 'z'; c++)
{
if (c == skipc)
continue;
long hash = HashMap.HashAt(c, i, word.Length);
if (KnownHash(hash + hash0))
{
if (before == String.Empty && after == String.Empty)
{
before = i > 0 ? word.Substring(0, i) : String.Empty;
after = i + 1 < word.Length ? word.Substring(i + 1) : String.Empty;
}
result.Add(before + c + after);
}
}
}
return result;
}
It's faster, but it's worse. I'm taking advantage of understanding the hash algorithm to calculate the new hash from changing a letter. I'm keeping these strings before and after blank until I really need them, then holding them in memory on the off-chance that I need them again.
essica Hische has this great blog, Daily Drop Cap, with letters to use at the beginning of paragraphs. Just last month, I read Roads to Quoz by William Least Heat-Moon where he admits to a fondness for the letter Q. Johns, Jemimas, Jacks and Juliets around the world may share with me a preference for the tenth letter of our alphabet. Judge me not for having married another. Jump on the opportunity to admit your passion! Jettison timidity and celebrate the letter in whatever way you choose!
Next time I'm interviewing a programmer for a job, I'd like to use this fragment of Algol. It comes from Electronic Computers by Hollingdale and Tootill (published 1965) which I stole from my brother-in-law's bookshelves.
begin comment Evaluate pi from Vieta's formula;
real e, f, product; integer count;
e := read tape;
f := 0; product := 1; count := 0;
for count := count + 1 while f < 2 - e do
begin f:= sqrt( 2 + f );
product := product x f/2
end;
newline; print (2/product); print (count)
end
... the 'bricoleur' is still someone who works with his hands and uses devious means compared to those of a craftsman. The 'bricoleur' is adept at performing a large number of diverse tasks; but, unlike the engineer, he does not subordinate each of them to the availability of raw materials and tools conceived and procured for the purpose of the project. His universe of instruments is closed and the rules of his game are always to make do with 'whatever is at hand' ... the engineer is always trying to make his way out of and go beyond the constraints imposed by a particular state of civilization while the 'bricoleur' by inclination or necessity always remains within them.
MONDAY