#!/usr/bin/python # Find the sum of all the multiples of 3 or 5 below 1000. import unittest from multiprocessing import Pool class main_test(unittest.TestCase): def test_multisum(self): self.assertEqual(multisum(3, 10), 18) # 3,6,9 self.assertEqual(multisum(5, 10), 5) # 5 self.assertEqual((multisum(3, 10) + multisum(5, 10)), 23) # 3,5,6,9 # the solver def multisum(multiple, limit): value = 0 result = [ ] while (value + multiple) < limit: # preflight check value += multiple result.append(value) return result if __name__ == "__main__": #unittest.main() pool = Pool(processes=2) # Setting up the processes and process pool. threes = pool.apply_async(multisum, (3, 1000)) fives = pool.apply_async(multisum, (5, 1000)) # because each process is running without a shared state, it's # required to find a union of the two results. "multiples of 3 OR # 5 below 1000" result_set = set.union(set(threes.get()), set(fives.get())) print sum(result_set)