Daniele Fucini 9e8d530d9e
Add more solutions in python
Added solutions for problem 51, 52, 53, 54 and 55 in python
2019-09-27 11:58:54 +02:00

41 lines
1014 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/python
# There are exactly ten ways of selecting three from five, 12345:
#
# 123, 124, 125, 134, 135, 145, 234, 235, 245, and 345
#
# In combinatorics, we use the notation, (5 3) = 10.
#
# In general, (n r)=n!/(r!(nr)!), where r≤n, n!=n×(n1)×...×3×2×1, and 0!=1.
#
# It is not until n=23, that a value exceeds one-million: (23 10)=1144066.
#
# How many, not necessarily distinct, values of (n r) for 1≤n≤100, are greater than one-million?
from scipy.special import comb
from timeit import default_timer
def main():
start = default_timer()
LIMIT = 1000000
count = 0
# Use the scipy comb function to calculate the binomial values
for i in range(23, 101):
for j in range(1, i+1):
if comb(i, j) > LIMIT:
count = count + 1
end = default_timer()
print('Project Euler, Problem 53')
print('Answer: {}'.format(count))
print('Elapsed time: {:.9f} seconds'.format(end - start))
if __name__ == '__main__':
main()