princeofsudan

Project Euler #31 Coin sums

Mar 31st, 2013
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. #In England the currency is made up of pound, £, and pence, p, and there are
  2. #eight coins in general circulation:
  3.  
  4. #    1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
  5.  
  6. #It is possible to make £2 in the following way:
  7.  
  8. #    1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
  9.  
  10. #How many different ways can £2 be made using any number of coins?
  11.  
  12.  
  13. count = 0
  14. for a in range(2):
  15.     if (200*a) > 200:
  16.         break
  17.     for b in range(3):
  18.         if (200*a + 100*b) > 200:
  19.             break                
  20.         for c in range(5):
  21.             if (200*a + 100*b + 50*c) > 200:
  22.                 break                        
  23.             for d in range(11):
  24.                 if (200*a + 100*b + 50*c + 20*d) > 200:
  25.                     break
  26.                 for e in range(21):
  27.                     if (200*a + 100*b + 50*c + 20*d + 10*e) > 200:
  28.                         break
  29.                     for f in range(41):
  30.                         if (200*a + 100*b + 50*c + 20*d + 10*e + 5*f) > 200:
  31.                             break
  32.                         for g in range(101):
  33.                             if (200*a + 100*b + 50*c + 20*d + 10*e + 5*f
  34.                                   + 2*g) > 200:
  35.                                 break                            
  36.                             for h in range(201):
  37.                                if (200*a + 100*b + 50*c + 20*d +
  38.                                     10*e + 5*f + 2*g + 1*h) > 200:
  39.                                     count += 1
  40.                                     break      
  41.                                
  42.                                    
  43. print count
Advertisement
Add Comment
Please, Sign In to add comment