Esempio n. 1
0
# The same as the coinage problem
from eulermath import coinage

if __name__ == "__main__":
    print ("Check: %d ways to write 5 as the sum of >=2 ints." %
           (coinage(5, range(1, 5))))
    print ("Solution: %d ways to write 100 as the sum of >=2 ints." %
           (coinage(100, range(1, 100))))
Esempio n. 2
0
from eulermath import coinage

# Very similar to the coinage probelm (Euler31)
# We want to write a number as combinations of sums of primes smaller
#  than itself. What is the first number to have over 5000 ways of
#  writing it usnig this condition?

# Start with 3, read the primes off of our prime list and use these
#  to make the list of prime 'coins'. Then use coinage to cout the ways
pfile = open("eplist.dat")

plist = []
n = 3
nways = 0
for line in pfile:
    cprime = int(line)
    while (n <= cprime):
        nways = coinage(n, plist)
        if (nways > 5000):
            print (repr(n) + " is the first value that can be " +
                   "written as a sum of primes in more than 5000 ways.")
            break
        n += 1
    # Check again with our condition - there has to be a better way for this...
    if (nways > 5000):
        break
        # Debugging
        # print ("Value: " + repr(n) + " has " + repr(nways) +
        #        " ways of being written with smaller primes.")
    plist.append(cprime)
Esempio n. 3
0
from eulermath import coinage

# Ways of making change using a set list of coins

if __name__ == "__main__":
    coinlist = [1, 2, 5, 10, 20, 50, 100, 200]
    print "There are " + str(coinage(12, coinlist)) +
    " ways to make change for 12c, and"
    print str(coinage(200, coinlist)) +
    " ways to make change for 200c using euroinas."