Skip to content

Instantly share code, notes, and snippets.

@julius-datajunkie
Last active December 26, 2015 03:19
Show Gist options
  • Save julius-datajunkie/7084889 to your computer and use it in GitHub Desktop.
Save julius-datajunkie/7084889 to your computer and use it in GitHub Desktop.
There must be a faster way than simply iterating through all the numbers
import unittest
def SumMultiplesOfThreeOrFive(number):
return sum(i for i in range(1,number) if (i % 3 == 0 or i % 5 == 0))
#for i in range(1,number):
# if (i % 3 == 0 or i % 5 == 0):
# sum += i
#return sum
class TestSumMultiplesOfThreeOrFive(unittest.TestCase):
def test_case(self):
self.assertEqual(SumMultiplesOfThreeOrFive(10),23)
if __name__ == '__main__':
unittest.main(exit=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment