Advertisement
carlsmith

MuckChecker

May 6th, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. def checker(nuggets, packs):
  2.  
  3.     # First get the values out of `packs` for convenience.
  4.     x, y, z = packs[0], packs[1], packs[2]
  5.    
  6.     # Check the truth of the equation for every
  7.     # permutation.
  8.     for a in range(nuggets):
  9.         for b in range(nuggets):
  10.             for c in range(nuggets):
  11.                 if (x*a) + (y*b) + (z*c) == nuggets:
  12.                     return True
  13.  
  14. def do():
  15.     # get pack sizes
  16.     packs = []
  17.     while len(packs) < 3:
  18.         usrin = raw_input('Enter a pack size: ')
  19.         try:
  20.             if int(usrin) > 1:
  21.                 if not int(usrin) in packs:
  22.                     packs.append(int(usrin))
  23.                 else:
  24.                     print '// You already entered', usrin
  25.             else:
  26.                 print '...that\'s greater than one??'
  27.         except:
  28.             print 'Huh?...'
  29.    
  30.     # Check every number that's less than 200 to find the
  31.     # highest number that can not be purchased evenly.
  32.     tally = 200
  33.     while tally:
  34.         tally -= 1
  35.         if not checker(tally, packs):
  36.             return str(tally)
  37.  
  38.  
  39. print '''
  40.    #######################################
  41.    #>   Welcome to MuckNugget Checker   <#
  42.    #######################################
  43. '''
  44. bye_message = '''
  45.    = = = = = = = = = =
  46.    |    God Bless    |
  47.    = = = = = = = = = =
  48. '''
  49. loop = True
  50. while loop:
  51.     # This print statement can not run until its call to `do()` has
  52.     # returned. The `do()` function will print its input prompts
  53.     # before it returns and allows this to print.
  54.     print '''
  55.    The greatest number below 200 that can
  56.    not be purchased in the pack sizes you
  57.    have entered is ''' +do()+ '.\n'
  58.    
  59.     if raw_input('Press Enter to continue.\nAnything else to quit. '):
  60.         print bye_message
  61.         loop = False
  62.     else:
  63.         print '\n    Let\'s go again...\n'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement