Live data from Hacker News

I wear your shirt

iwearyourshirt.com

31–34 of 34 posts

Re: I wear your shirt

#32
post #28
post #6

Earlier quoted context omitted.

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 rememb…

I was referring to the fact that Wolfram actually understood the input, not that it answered a trivial math question :)

  (loop for x from 1 to 365 summing x)  ==> 66795

Re: I wear your shirt

#33
post #21
post #18

Earlier quoted context omitted.

Python: reduce (operator.add, range(366))

or sum(range(366))

  (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))
Post reply on HN