6 ms·
Ruby (1..1000000000).inject(:+)
by epochwolf 13y ago
Ruby
(1..1000000000).inject(:+)
- RussianCow 13y agoPython: sum(range(1000000000)) :)
- dragonwriter 13y agoDid you intend to demonstrate a very common off-by-one error in Python?
- knome 13y agoProbably should've used xrange as well. In the 2.x series, Python's range function returns an actual list. I believe in 3.x range has been replaced with xrange.
- masklinn 13y ago> I believe in 3.x range has been replaced with xrange. Correct.
- RussianCow 13y agoI was assuming Python 3, but yes, you are correct.
- DerekL 13y agoIt's not right. You should add one to the bound because "range" uses half-open intervals. Also, it only works in Python 3; in Python 2, it creates a list of a 1000000000 integers, so you should use "xrange" instead.
- RussianCow 13y agoYep, my bad. Didn't really think before I posted. And yes, I was assuming Python 3, so use xrange on Python 2.