News for hackers. Stuff that matters.
Re:I wear your shirt by m0th87 on Wednesday November 25, 2009 @03:13AM (#960832)
This is one of those domain-specific areas in which Wolfram is awesome: http://www.wolframalpha.com/input/?i=sum+of+n+from+1+to+365
Re:I wear your shirt by patio11 on Wednesday November 25, 2009 @03:35AM (#960853)
We can't all be Gauss but, then again, we're not in fourth grade anymore, either. You can sum over any range trivially: average of the endpoints times length of the range. The average of 1 and 365 is 183. There are 365 elements between 1 and 365 (both inclusive). 183 * 365 = 66795. Yay, right answer.

(There is a formula. I have a poor memory for formulas but am good at transforming English into them, so I just remember the English gloss.)

I'm decently impressed that Wolfram was able to spit out something equivalent to the right formula with only a little massaging of the inputs from me:

http://www.wolframalpha.com/input/?i=sum+of+n+from+n%3Da+to+...

Re:I wear your shirt by m0th87 on Wednesday November 25, 2009 @01:03PM (#961533)
I was referring to the fact that Wolfram actually understood the input, not that it answered a trivial math question :)
Re:I wear your shirt by mahmud on Thursday November 26, 2009 @08:10PM (#963299)

  (loop for x from 1 to 365 summing x)  ==> 66795
Re:I wear your shirt by three14 on Wednesday November 25, 2009 @03:40AM (#960860)
There's a famous possibly true story about Gauss having to sum the numbers 1 to 100 as a child. Most versions tell it that he noticed that 1 + 100 = 2 + 99 = 3 + 98 and so on, yielding a general formula of n * (n + 1) / 2, so you could probably skip Wolfram for this one. (Explanation: you have n numbers, on average each is equal to the first + the last divided by 2)

Unless you want it for this: http://www.wolframalpha.com/input/?i=sum+of+n+from+1+to+n

Re:I wear your shirt by icey on Wednesday November 25, 2009 @08:18AM (#961047)
A REPL is nice too:

  (reduce + (range 366))
Re:I wear your shirt by Torn on Wednesday November 25, 2009 @09:56AM (#961169)
Python:

  reduce (operator.add, range(366))
Re:I wear your shirt by tome on Wednesday November 25, 2009 @10:11AM (#961190)
or

   sum(range(366))
Re:I wear your shirt by mahmud on Thursday November 26, 2009 @08:15PM (#963303)

  (sum (range 1 365))
assuming you defined these already; I have them in my utils library ;-)

  (defun range (start end)
    (loop for x from start to end collecting x))

  (defun sum (sequence)
    (reduce #'+ sequence))
Re:I wear your shirt by Torn on Wednesday November 25, 2009 @11:47AM (#961377)
didn't even think of that one! :)
Re:I wear your shirt by karanbhangui on Wednesday November 25, 2009 @12:52PM (#961519)
or plain math: n(n+1)/2
Re:I wear your shirt by mahmud on Thursday November 26, 2009 @08:20PM (#963304)
How quickly can you generalize the plain math formula to these sequences: http://www.research.att.com/njas/sequences/index.html
Re:I wear your shirt by seldo on Wednesday November 25, 2009 @05:11AM (#960922)
I knew there must be a formula but I totally just broke out a spreadsheet and auto-generated the sequence and then auto-summed it.

Math/brain fail.

Re:I wear your shirt by RyanMcGreal on Wednesday November 25, 2009 @09:36AM (#961143)
Alternately: fast repetition of trivial operations win.
Re:I wear your shirt by Raphael on Wednesday November 25, 2009 @03:57AM (#960874)
Preaching to the choir. I used it all day for physics homework.