Last active
August 17, 2016 10:56
-
-
Save Brutt/59e57f434b927ebdd88fd7e8a427458b to your computer and use it in GitHub Desktop.
My version of decision of problem 5 "Smallest multiple"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#https://projecteuler.net/problem=5 | |
#python 3.5.2 | |
import time | |
from functools import reduce as reduce | |
start = time.time() | |
simpleList = [2,3,5,7,11,13,17,19] | |
def DoItSimple(dig): | |
if dig in simpleList: | |
outputList.append(dig) | |
return dig | |
else: | |
for i in simpleList: | |
if dig % i == 0: | |
if dig//i in simpleList: | |
outputList.append(i) | |
outputList.append(dig//i) | |
return (dig//i) | |
else: | |
outputList.append(i) | |
return (DoItSimple(dig//i)) | |
mainList = [] | |
for x in range(2,21): | |
outputList = [] | |
DoItSimple(x) | |
for i in outputList: | |
if mainList.count(i) < outputList.count(i): | |
mainList.append(i) | |
print(mainList) | |
print(reduce(lambda x, y: x * y, mainList)) | |
elapsed = (time.time() - start) | |
print("result returned after {0} seconds." .format(elapsed)) | |
""" | |
[2, 3, 2, 5, 7, 2, 3, 11, 13, 2, 17, 19] | |
232792560 | |
result returned after 0.0 seconds. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment