Solve problem 109 in Python

main
Felix Martin 2021-07-08 12:20:45 -04:00
parent bff7ae0371
commit 729bfc7eb2
1 changed files with 73 additions and 0 deletions

73
python/e109.py Normal file
View File

@ -0,0 +1,73 @@
def all_singles():
return list(range(1, 21)) + [25]
def all_doubles():
return [n * 2 for n in range(1, 21)] + [50]
def all_triples():
return [n * 3 for n in range(1, 21)]
def euler_109():
count = 0
target_score = 100
for first in all_doubles():
# D
if first < target_score:
count += 1
# D T
for second in all_triples():
if first + second < target_score:
count += 1
# D D
for second in all_doubles():
if first + second < target_score:
count += 1
# D S
for second in all_singles():
if first + second < target_score:
count += 1
# D T D
for second in all_triples():
for third in all_doubles():
if first + second + third < target_score:
count += 1
# D T S
for second in all_triples():
for third in all_singles():
if first + second + third < target_score:
count += 1
# D D S
for second in all_doubles():
for third in all_singles():
if first + second + third < target_score:
count += 1
# D T T
for second in all_triples():
for third in all_triples():
if second >= third and first + second + third < target_score:
count += 1
# D D
for second in all_doubles():
for third in all_doubles():
if second >= third and first + second + third < target_score:
count += 1
# S S
for second in all_singles():
for third in all_singles():
if second >= third and first + second + third < target_score:
count += 1
return count
if __name__ == "__main__":
solution = euler_109()
print("e109.py: " + str(solution))
assert(solution == 38182)