A Stumbling Count

  • izblank (6/1/2011)


    Tom.Thomson (6/1/2011)


    izblank (6/1/2011)


    Or, suppose you need to calculate sum of squares of consecutive integers. You could do it in a loop, or you could expand your Tally table to hold running sum of squares, thus reducing your calculation to mere subtraction of two numbers found in the table.

    It would be much simpler to do the arithmetic in the obvious way, using n*(n+1)*(2n+1)/6 for the sum of the squares of the first n natural numbers and getting the sum of sqares of integers between m+1 and n inclusive by using that twice and subtracting.

    Doing a three way join onto a Tally table with a lot of rows (and containg all extra stuff in addition to the single number of the traditional Tally table so that it occupies more space) may not be sufficiently efficient to justify the additional code complexity. Doing it in a loop would be just plain crazy.

    Right, and now instead of sum of squares, I will ask you to get a count of prime numbers within a range. Can you come up with a formula for that?:-)

    No, as far as I know there is no formula using simple operations; so that's one to build a table for.

    Tom

Viewing post 16 (of 15 total)

You must be logged in to reply to this topic. Login to reply