TerseMan challenge

Marcel Weiher marcel at metaobject.com
Wed Jan 12 01:13:48 UTC 2000


> From: Travis Griggs <tgriggs at keyww.com>

[recursive multiply doesn't save multiplies, doesn't seem to save time]

I struggled with this for a while as well.

After that, it dawned on me that the purpose was not to reduce the  
number of multiplies, but to keep the integers small for as long as  
possible, if possible in SmallInteger territory.

To illustrate:

Time millisecondsToRun:[ 1000 timesRepeat: [ (1000 * 2000) * (3000 *  
4000) * (5000 * 6000) * (7000 * 8000) * 9000 ]]. -> 1089

whereas

Time millisecondsToRun:[ 1000 timesRepeat: [ 1000 * 2000 * 3000 *  
4000 * 5000 * 6000 * 7000 * 8000 * 9000 ]].  ->  1412

I am sure the effect is much greater with larger collections...

Marcel





More information about the Squeak-dev mailing list