Earn extra honor and gain new allies!
Honor is earned for each new codewarrior who joins.
Learn more

Even faster, since it doesn't rely on an iterator. Especially big numbers yield noticeable differences in execution time.

Code
Diff
  • def euler(num):
        sum_range = lambda x: x*(x+1)//2
        return 3*sum_range((num-1)//3) + 5*sum_range((num-1)//5) - 15*sum_range((num-1)//15)
  • 11 def euler(num):
    2- return sum(range(3,num,3)) + sum(range(5,num,5)) - sum(range(15,num,15))
    2+ sum_range = lambda x: x*(x+1)//2
    3+ return 3*sum_range((num-1)//3) + 5*sum_range((num-1)//5) - 15*sum_range((num-1)//15)