Advertisement
LiamBogur

<!> SPOILER <!> Project Euler Q1

Jul 15th, 2018
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. # My First Successful Attempt (made by self)
  2. def multiples(x,r):
  3.     ans = 0
  4.     i = 0
  5.     ret = []
  6.     while True:
  7.         ans = i * x
  8.         if ans in range(r):
  9.             ret.append(ans)
  10.         else:
  11.             return ret
  12.             break
  13.         i += 1
  14. print(sum(list(set(multiples(3,1000) + multiples(5,1000)))))
  15.  
  16. # My Second Successful Attempt (used some help)
  17. print(sum([i for i in range(1, 1000) if any(i % factor == 0 for factor in [3, 5])]))
  18.  
  19. # My Third Successful Attempt (made by self)
  20. a=[]
  21. for factor in [3,5]:
  22.     for l in range(1,1000):
  23.         if l%factor==0:
  24.             a.append(l)
  25. print(sum(list(set(a))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement