>>>On the 1st day of Xmas, my true love gave to me:
>>>1 item
>>>On the 2nd day of Xmas, my true love gave to me:
>>>2 items + 1 item
>>>On the 3rd day of Xmas, my true love gave to me:
>>>3 items + 2 items + 1 item
>>>.
>>>.
>>>On the n-1 day of Xmas, my true love gave to me:
>>>n-1 items + n-2 items + ... + 1 item
>>>On the nth day of Xmas, my true love gave to me:
>>>n items + n-1 items + ... + 1 item
>>>
>>>How many total items did my true love give to me, as a function of n?
>>
>>Number of gifts = gifts(n)
>>
>>
>>FUNCTION gifts(n)
>>lnReturn = 0
>>FOR I = 1 TO n
>> FOR H = 1 TO I
>> lnReturn = lnReturn + H
>> ENDFOR
>>ENDFOR
>>RETURN lnReturn
>>
>>
>>not arithmetic, but it works
>
>Er, yes, but there is an elegant mathematical solution that even a computer would like! (no looping involved)
This is fun, but it also begs the question as to where to draw the line when programming for profit:
1. Evaluate the situation for how often the calculation is necessary.
2. If frequent, then spend the reaseach time necessary to find the most (reasonably) elegant solution.
3. If occaisionally, the first method you think of that works: use it and move on.
That's how I do it.
The geek in me is still trying to find the elegant answer though....
Matt McDonnell
...building a better mousetrap with moldy cheese...