Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think I might be doing it wrong, because I didn't do any looping. I'm a bit too lazy and impatient for that, who wants to spend their afternoon adding all those numbers up even with a computer.

  [joe24pack@staropramen ~]$ python
  Python 2.6.6 (r266:84292, May  1 2012, 13:52:17) 
  [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
  Type "help", "copyright", "credits" or "license" for more information.
  >>> def gauss(x):
  ...   return (x+1)*(x/2)
  ... 
  >>> gauss(10)
  55
  >>> gauss(1000000000)
  500000000500000000
  >>>


Hmmmm, make that:

    def gauss(x):
        return (x+1)*x/2
(consider gauss(11), for example)

You gotta admit, on an article about the difference between integer and floating-point arithmetic, that's pretty ironic!


It's odd that the odd numbers slipped my mind. Thank you for your gracious correction.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: