From: Pit Capitain Date: 2002-02-09T17:36:13+09:00 Subject: Re: Reg: tiny contest: who's faster? (add_a_gram) On 9 Feb 2002, at 14:55, Dave Thomas wrote: > "Pit Capitain" writes: > > > Hi Dave, your code is fast, but you are cheating (a little bit ;-) > > Here are two word lists that break the algorithm: > > > > Longest add-a-gram not beginning at 3 or less letters: (snip) > > I report 'attorneyship' for this sequence (Steven's code reports > 'underestimations', but shows a list starting with 'nitons', which is > five characters long. The challenge says to start at 3 characters). Am > I missing something? No, you didn't. It was me who didn't remember the starting condition - sorry. > > * Should it only work with the given or with any word list? > > * Should it only print the last word or the whole sequence? > > The challenge asks for the longest word, not the chain. However, > adding reporting for the whole chain barely affects the run time. I've > attached the new version. To quote from the website: An "add-a-gram" is a sequence of words (...) What is the longest add-a-gram? From this it is arguable whether the program should report a sequence or the longest word in the sequence. > However I do think it should work with any list. As does your algorithm if you build the "words_of_length" arrays for shorter words, too. So, again, its no problem with your algorithm. The modified version is still the fastest by far ! > > * Is it allowed to use C extensions or has it to be pure Ruby? > > Pure Ruby, I'd say. David's "sort_bytes" extension would be a very nice fit. But I'd prefer pure Ruby, too. Speaking of languages, could it be that some Haskell / FP idioms are showing up, for example the method "test_word" with it's accumulator? Do you think you would have been implementing it this way before starting with LOTY, or is it just me becoming more sensitive for this style? Regards, Pit