Skip to content

Instantly share code, notes, and snippets.

@alexandre
Created July 26, 2014 21:03
Show Gist options
  • Select an option

  • Save alexandre/d5ad36a27bef7a0cb187 to your computer and use it in GitHub Desktop.

Select an option

Save alexandre/d5ad36a27bef7a0cb187 to your computer and use it in GitHub Desktop.
the sum of multiples of 3 and 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. Find the sum of all the multiples of 3 or 5 below 1000.
https://projecteuler.net/problem=1
'''
# is a multiple of 5?
# list(str(N))[-1] in ('0','5') => should return True if N is a multiple of 5.
# is a multiple of 3?
# sum([int(x) for x in list(str(493))]) % 3 => should return 0 if N is a multple of 3 (or 9)
numbers = [x for x in range(1000)]
# mult... of 5
m5 = [int(num) for num in filter(lambda x: list(str(x))[-1] in ('0','5'), numbers)]
# mult... of 3
m3 = [int(num) for num in filter(lambda x: sum([int(d) for d in list(str(x))]) % 3 == 0, numbers)]
#result = 233168
sum( list( set(m5) | set(m3) ) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment