Demo entry 4722471

Project Euler Problem 1

   

Submitted by anonymous on May 10, 2016 at 11:58
Language: Python. Code size: 584 Bytes.

# Find the sum of all the multiples of 3 or 5 below 1000.
# If we list all the natural numbers below 10 that are multiples of 3 or 5, 
# we get 3, 5, 6 and 9. The sum of these multiples is 23.

import numpy as np

def MultiplesofThreeorFiveLessThan1000():
    x = np.arange(1,1000)
    multiples = []
    for num in x:
        if num % 3 == 0:
            multiples.append(num)
        elif num % 5 == 0:
            multiples.append(num)
    return(multiples)
    
if __name__ == "__main__":
    x = MultiplesofThreeorFiveLessThan1000()
    print x, np.sum(x)
    

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).