If you add 6 to those totals, you get 56,57,58,59,60,61. If you add 6 to those totals, you get 62,63,64,65,66,67.
Problem 2:
So basically, once the condition is true for any run of six, it's true for that run of six + 6, which works out to every number greater than the start of the first run of six. If it were true for a run of nine, it would also be true for that run of nine + 9, etc.
Your other code allowed James T. Kirk to get laid. It us CRUCIALLY IMPORTANT!
As for this one, I had no problem with questions 1 & 2, stumbled into a nice solution for the original McNugget problem that solved it with math rather than exhaustive search, and then faceplanted in problem 4 because I'm pretty sure that assignment 2 isn't supposed to be NP-hard, even at MIT. I... need to step away from it and find some other practice problem with the same logical structure. Sigh.
I got a little intimidated looking at the problem set, because it's been a loooong time since I took math, but it really is mostly "can you loop through stuff until you come up with an answer?"
Yep. I tend to get stuck on "but what's the solution?" rather than "what am I practicing here?"
So with that in mind, I'm off to play with possible combinations of Hardison, Eliot, and Parker; they're better than McNuggets in so many ways. Thanks for posting your solution - it was a good clarifier when I was letting things get too complicated.
This is my answer to #4, which is a lot like my answer to #3:
# Takes a tuple of three package sizes and a number of nuggets
# Returns True or False depending on whether the exact
# given number of McNuggets can be purchased
def divisible_by_mcnuggets(packages, nuggets):
# We shouldn't bother trying numbers that are greater than the
# total number we're looking for. For example, if the total number
# of nuggets is 50 and one of the packages contains 20 nuggets, we'll
# never want more than 2 of them
maximum_a = nuggets/packages[0] + 1
maximum_b = nuggets/packages[1] + 1
maximum_c = nuggets/packages[2] + 1
# Loop through all possible combinations of the three package sizes
# from 0 to the maximum
for a in range(0, maximum_a):
for b in range(0, maximum_b):
for c in range(0, maximum_c):
if (packages[0]*a) + (packages[1]*b) + (packages[2]*c) == nuggets:
return True
return False
# Prints the largest number of McNuggets that can't be bought up to 150
# for a given set of 3 package sizes
def diophantine_mcnuggets():
bestSoFar = 0 # variable that keeps track of largest number
# of McNuggets that cannot be bought in exact quantity
packages = (6,9,20) # variable that contains package sizes
consecutive_divisibles = []
while len(consecutive_divisibles) < 6:
for n in range(1, 150): # only search for solutions up to size 150
if divisible_by_mcnuggets(packages, n) == True:
consecutive_divisibles.append(n)
else:
consecutive_divisibles = []
bestSoFar = n
print "Given package sizes %i, %i, and %i, the largest number of McNuggets that cannot be bought in exact quantity is: %i" % (packages[0], packages[1], packages[2], bestSoFar)
diophantine_mcnuggets()
ELZ - My script wound up being very similar to yours. I couldn't figure out how to stop looking after 6 consecutive successful results, so I just put all successful results in a list. I then looked for numbers not in that list and used the highest number that was missing. I'm not sure if I'm happy to find this thread AFTER I finally figured it out (hours), or if I'm glad I didn't because I think I learned more.....
## This program looks for the maximum number that can't be ## created using combinations of package sizes.
# variables - change to manipulate how what numbers to try and max range # to try within. If the result is close to your max range, you should # probably increase the range. packages = [6,9,20] # variable that contains package sizes n = range(0, 201) # range to test within. Max number must be at least TWO more than expected result.
# tests all possible combinations. Saves numbers that were successfully computed to numworks. numworks = [] for count in n: for a in range(0, count/packages[0]+1): #instead of using all combinations, only combinations that # wouldn't be higher than max range (so max range divided by package size). Adding one because # of remainders. This cuts WAY down on the time to process the program vs just using "range (0, count)" for b in range(0, count/packages[1]+1): for c in range(0, count/packages[2]+1): if ((a*packages[0] + b*packages[1] + c*packages[2]) == count): numworks = numworks + [count]
### found that entire section is not needed to get correct results. It makes numworks look nicer, but isn't needed. ### Sort then Remove duplicates from numworks ##cycle = 0 ##if numworks: ## numworks.sort() ## last = numworks[-1] ## for i in range(len(numworks)-2, -1, -1): ## if last == numworks[i]: ## del numworks[i] ## else: ## last = numworks[i]
# create numbad which is list of numbers that didn't work. This is based on numbers that are not in numworks. numbad = [0] for ii in range (0,numworks[-1]): if ii not in numworks: numbad = numbad + [ii]
# prints results. Also accounts for no results. if numbad == [0]: print "No numbers were generated. \nYou likely used a 1 (one) or a negitive number as a package size." else: print "Given package sizes %i, %i, and %i, the largest number of McNuggets that \ncannot be bought in exact quantity is: %i. \n \n*** Note: the highest number tested was %i ***" % (packages[0], packages[1], packages[2], numbad[-1], n[-1])
#asks for the diffrent package sizes and checks that they are suitable (error handling) while corr_pack==False: print('What are the three packet sizes (in rising order)?') packets=input() if len(packets)!=3: print ('There must be three and only three packet sizes') elif type(packets[0])!=int or type(packets[1])!=int or type(packets[2])!=int: print ('All packet sizes must be given in integrers') elif packets[0]<0 or packets[1]<0 or packets[2]<0: print ('The packet sizes must be positive numbers') elif packets[0]>packets[1] or packets [0]>packets[2] or packets[1]>packets[2]: print ('The packets must be given in a rising order') else: corr_pack=True
while n<200 and no_right< packets[0] : #n loops all possible combinations from 1 and up to a works=False #consecutive number of possibles the same length as the minimum package n+=1 #works turns true as soon as a solution is found, c=0 #a,b,c is how many packages of each size are needed while c*packets[2]<=n and works==False: #each loop goes until the combined number of nuggets is bigger b=0 #than the wanted number. while c*packets[2]+b*packets[1]<=n and works==False: a=0 while c*packets[2]+b*packets[1]+a*packets[0]<=n and works==False:#Goes though all combinations if c*packets[2]+b*packets[1]+a*packets[0]==n: #of a,b&c till a solution is works=True #found or all combinations are tried. else: #starts with a and works it way out. a+=1 #if a correct solution are found works turns True if c*packets[2]+b*packets[1]+a*packets[0]==n: works=True else: b+=1 if c*packets[2]+b*packets[1]+a*packets[0]==n: works=True else: c+=1 if works==True: #if there exists a correct solution the n_right counter incerases no_right+=1 #print n,a,b,c else: #if there isn't, it resets to zero and that number is stored in highest. highest=n no_right=0 #print n,no_right print highest #the highest non-solvable number is printed.
I'm pretty sure this is ugly and I know it's inefficient, but they asked for exhaustive search...
# Solving a Diophantine Equation.
# Helper function
def consecutiveValues(n1, n2, n3, n4, n5, n6):
value = (n1 + 1 == n2) and (n2 + 1 == n3) and (n3 + 1 == n4) and (n4 + 1 == n5) and (n5 + 1 == n6)
return value
# Helper function
def nuggetsTest(n):
answer = False
for a in range(0,11):
for b in range(0,11):
for c in range(0,11):
if (a*6 + b*9 + c*20) == n:
return True
return answer
def mcnuggets():
# Possible instance of number of McNuggets that cannot be purchased
# exactly.
n = 1
# Stores successful values of n.
successful_n = [0,0,0,0,0,0]
# Stores failed values of n.
failed_n = [0]
# We already know from Problem 1 that 50, 51, ..., 55 (and all
# instances thereafter) have exact solutions. So let's set an
# upper bound for a, b, and c as 10, which should catch all
# feasible possibilities for each variable (6*10 = 60).
while consecutiveValues(successful_n[-6], successful_n[-5], successful_n[-4], successful_n[-3], successful_n[-2], successful_n[-1]) == False:
if nuggetsTest(n) == True:
successful_n = successful_n + [n]
print n
else:
failed_n = failed_n + [n]
n = n + 1
print "Largest number of McNuggets that cannot be bought in exact quantity: " + str(failed_n[-1])
Very similar to problem 3. I didn't bother with the other cases they suggested trying, but it would be simple to make the changes.
packages = (6,9,20) # variable that contains package sizes
# helper function #1
def consecutiveValues(n1, n2, n3, n4, n5, n6):
value = (n1 + 1 == n2) and (n2 + 1 == n3) and (n3 + 1 == n4) and (n4 + 1 == n5) and (n5 + 1 == n6)
return value
# helper function #2
def nuggetsTest(n):
answer = False
for a in range(0,34):
for b in range(0,34):
for c in range(0,34):
if (a*packages[0] + b*packages[1] + c*packages[2]) == n:
return True
return answer
def mcnuggets_search():
n = 1
# Stores successful values of n.
successful_n = [0,0,0,0,0,0]
bestSoFar = [0] # variable that keeps track of largest
# number of McNuggets that cannot be
# bought in exact quantity
while consecutiveValues(successful_n[-6], successful_n[-5], successful_n[-4], successful_n[-3], successful_n[-2], successful_n[-1]) == False and n < 200:
if nuggetsTest(n) == True:
successful_n = successful_n + [n]
print n
else:
bestSoFar = bestSoFar + [n]
n = n + 1
print "Given package sizes " + str(packages[0]) + ", " + str(packages[1]) + ", and " + str(packages[2]) + ", the largest number of McNuggets that cannot be bought in exact quantity is: " + str(bestSoFar[-1]) + "."
Does anyone know if there is a limit to how many indentations/levels of nested loops is viable in Python? I'm having an issue with problem 3 in that my nested loops work fine until I add another while loop outside of them, and I can't figure out why.
There's no limit. Maybe if you posted a code snippet, someone might be able to spot something that you're not seeing?
(edit: on further research, I'm seeing a couple of references to limits between 20 and several hundred layers of indentation -- I'm not sure if the varying numbers are different versions or implementations or what, but even if it's 20, it's *way* more than anything you'd find in these problem sets, and possibly any sane software design.)
We used to work together http://gykepugurohy.blog.free.fr/ naked angel bbs I hate the fingernails, but she's a damn pretty natural latin girl, anyway! and she can suck cock and loves it!!! I'd ove to get sucked by her! beautiful lips!!!
How many are there in a book? http://aquytyiqyha.blog.free.fr/ young european models Hate to double post but fuck.. I can't get over how much I love it when women grind like that... No contest if a girl wants to get me off.
The National Gallery http://ofapolyykeg.blog.free.fr/ schoolgirl model samples wtf, why don't asian women stop fuckin crying like dying cats and fuck for once. I only fuck asian americans, women who have seen real fucking, not this bullshit where little dick having guys slowly fuck these hairy pussy squeelers. Go to Cali, not Tokyo.
We went to university together http://opaolate.blog.free.fr/ dee lily model What eyes! Class and style! Fantasic confident woman enjoying her job. Best film I've seen in years, all because of her! (And yes, I am typing with one hand, other is busy) :D
I wanted to live abroad http://anicucegei.blog.free.fr/ pedo modell oh my god he giving it to her right!! shit, i'd take that dick in like a fucking soldier! i was that was my pussy getting fucked like that
How do you know each other? http://anisumoute.blog.free.fr/ voyeur preteen pics hold on im just gonna cum on your face...thats fuckin hilarious if i was a porn cameraman id do that every shoot
I'm doing a phd in chemistry http://ekynecirolasu.blog.free.fr/ nonude child model This girl is fucking sexy. I love her tight pussy. I love her so much. That guy is fucking lucky.
We need someone with qualifications http://enytosyjaqo.blog.free.fr/ only porn bbs Pinky is hella fine... i wanna eat her PUSSY so bad... DAMN SHE THE SHIT... THAT FAT ASS CLAPPIN AND SHIT...
I'm on work experience http://yypidugenur.de.tl photo cp bbs I don't think she's ugly.. She's just an average looking everday chick... And she deffently ain't fat. Ya'll have gotten use to seeing all these supermodel looking chicks doing porn
How do you do? http://ogatenetif.de.tl petite model links She is soooo much better at fucking than he is!!!! He had a nice cock though... The first half was pretty good. Eye contact,kissing,intensity..they seemed to be really enjoying fucking each other..He got lazy in the last half thou.. too much doggy style, boring!! he was sitting on his ass and she was doing most of the work..Cumshot was sooo weak. he shoulda just came on her ass.. An internal shot woulda been really HOTTT!!! Oh well...
How many are there in a book? http://bynupaigera.de.tl pretty hot bbs SMOKIN!! I think i'd have a sex change to be with these three! The dark gal is particularly sweet...would love them to grind on my face n cock while they do each other, ahhh. Whats that that just fell into my hand, oh must be my cock...again :p
I've just graduated http://kiduymidisy.de.tl nymphets angel pussy I think her pussy is cute. I would eat it, but I would love to get fucked by his dick =]. It looks so good ;]. LOL
Directory enquiries http://ausouar.de.tl nymphet brazil he puts my small white dick to shame he is fukin sexc fuckin that white bitch tho she looks like shes lovin it
My battery's about to run out http://oqepuhylinys.de.tl nymphets image yooo..she is fuckin loud as hell! lol she can't be makin all the noise for real.. she gotta be fakin!
I'm doing a masters in law http://sajudyfane.de.tl dark portal nymphets That's definitely a MILF! Nice to see MILF is an international term! I would have banged her a lot better. Also noticed maybe they don't eat pussy...their loss!
I can't stand football http://oqepuhylinys.de.tl all pics nymphets THat girl is a fucking CHAMP!!! Holla! And Erik knew what he was doing, getting the nasty ass frenchman to cumming in her second! LOL! She is such a good girl!
I'd like to speak to someone about a mortgage http://onasurubym.de.tl composites bbs Valentina is such a sexy woman and looks great getting worked over in this vid. She takes a DP well and looks hot doing it. Very good scene!
Have you read any good books lately? http://umaceudyfytu.de.tl girl bbs post the only thing i can think of that is funny to say (( is that yellow thing on the counter top a butt plug))
Where did you go to university? http://ubuekujuqim.de.tl non nude nymphs I would love to be sucked by this girl she is an expert, would like to spurt in her mouth
I wanted to live abroad http://komufypipy.de.tl japan teen models bbs lol. i dont know what u losers are getting upset about. this is the world of porn. money buys it all. u losers are so upset about the fact that hes fucking her and shit... dont forget morons, she agreed to it like a cheap slut she is.. shit.. u guys makin her look all glorious and victimized.. gimme a fuckin break. get a life losers hahaha.
How many more years do you have to go? http://olafuynyjik.de.tl daughter bbs I have always wanted to try my hand, rather mouth, at eating pussy. I am curious to eat a woman out. Feel the pussy squeeze my tongue and such... I have a feeling I would be good at it.
What do you study? http://olafuynyjik.de.tl pr teen bbs mhmm she want that naughty pussy fucked hard...needed another guy just forced fucked her...she would have had that bed soaking wet
Gloomy tales http://necikuekyir.de.tl nymphet lingerie models His dicks average bro...Hes fucking this slut and your not. Your watching him fuck this slut. enough about dick size im sick of hearing about it. huge dick or not if you got fuck game you can make any bitch enjoy it...
real beauty page http://igujyfagehu.de.tl sexy virgins nymphets like her tits but god dam it why do they need two black guys there getting in the way i cant see her ass or pussy or boobs
Do you know the address? http://igujyfagehu.de.tl planet lo nymphet I hate when the music drowns out the story and the moaning. I was getting into it then I can't hear what the two females are saying. Sucks
I've got a very weak signal http://edeboteler.de.tl nymphet boy sex can someone tell me what is the name of that blond and does anyone who the name of the movie she did with Kay Parker as a babysitter?
I love this site http://ynulofoti.de.tl underage filipina nymphet She is fucking HOT!!! and would be great to fuck. The guys are lucky and know what there doing.. love the black guy who is he?
no subject
Date: 2009-11-19 12:10 am (UTC)Problem 1:
6a,9b,20c = n
2,2,1 = 50
1,5,0 = 51
2,0,2 = 52
1,3,1 = 53
0,6,0 = 54
1,1,2 = 55
If you add 6 to those totals, you get 56,57,58,59,60,61.
If you add 6 to those totals, you get 62,63,64,65,66,67.
Problem 2:
So basically, once the condition is true for any run of six, it's true for that run of six + 6, which works out to every number greater than the start of the first run of six. If it were true for a run of nine, it would also be true for that run of nine + 9, etc.
no subject
Date: 2009-11-19 02:25 am (UTC)As for this one, I had no problem with questions 1 & 2, stumbled into a nice solution for the original McNugget problem that solved it with math rather than exhaustive search, and then faceplanted in problem 4 because I'm pretty sure that assignment 2 isn't supposed to be NP-hard, even at MIT. I... need to step away from it and find some other practice problem with the same logical structure. Sigh.
no subject
Date: 2009-11-19 02:44 am (UTC)I got a little intimidated looking at the problem set, because it's been a loooong time since I took math, but it really is mostly "can you loop through stuff until you come up with an answer?"
no subject
Date: 2009-11-19 02:55 am (UTC)So with that in mind, I'm off to play with possible combinations of Hardison, Eliot, and Parker; they're better than McNuggets in so many ways. Thanks for posting your solution - it was a good clarifier when I was letting things get too complicated.
Problem #4
Date: 2009-11-19 02:21 am (UTC)Re: Problem #4
Date: 2009-11-19 06:45 pm (UTC)to:
Re: Problem #4
Date: 2010-03-03 03:59 pm (UTC)## This program looks for the maximum number that can't be
## created using combinations of package sizes.
# variables - change to manipulate how what numbers to try and max range
# to try within. If the result is close to your max range, you should
# probably increase the range.
packages = [6,9,20] # variable that contains package sizes
n = range(0, 201) # range to test within. Max number must be at least TWO more than expected result.
# tests all possible combinations. Saves numbers that were successfully computed to numworks.
numworks = []
for count in n:
for a in range(0, count/packages[0]+1): #instead of using all combinations, only combinations that
# wouldn't be higher than max range (so max range divided by package size). Adding one because
# of remainders. This cuts WAY down on the time to process the program vs just using "range (0, count)"
for b in range(0, count/packages[1]+1):
for c in range(0, count/packages[2]+1):
if ((a*packages[0] + b*packages[1] + c*packages[2]) == count):
numworks = numworks + [count]
### found that entire section is not needed to get correct results. It makes numworks look nicer, but isn't needed.
### Sort then Remove duplicates from numworks
##cycle = 0
##if numworks:
## numworks.sort()
## last = numworks[-1]
## for i in range(len(numworks)-2, -1, -1):
## if last == numworks[i]:
## del numworks[i]
## else:
## last = numworks[i]
# create numbad which is list of numbers that didn't work. This is based on numbers that are not in numworks.
numbad = [0]
for ii in range (0,numworks[-1]):
if ii not in numworks:
numbad = numbad + [ii]
# prints results. Also accounts for no results.
if numbad == [0]:
print "No numbers were generated. \nYou likely used a 1 (one) or a negitive number as a package size."
else:
print "Given package sizes %i, %i, and %i, the largest number of McNuggets that \ncannot be bought in exact quantity is: %i. \n \n*** Note: the highest number tested was %i ***" % (packages[0], packages[1], packages[2], numbad[-1], n[-1])
#4
Date: 2009-11-20 12:39 am (UTC)If anyone have any questions, just ask!
#packets = (6,9,20)
no_right = 0
n=0
highest=0
corr_pack=False
print'Hi!'
#asks for the diffrent package sizes and checks that they are suitable (error handling)
while corr_pack==False:
print('What are the three packet sizes (in rising order)?')
packets=input()
if len(packets)!=3:
print ('There must be three and only three packet sizes')
elif type(packets[0])!=int or type(packets[1])!=int or type(packets[2])!=int:
print ('All packet sizes must be given in integrers')
elif packets[0]<0 or packets[1]<0 or packets[2]<0:
print ('The packet sizes must be positive numbers')
elif packets[0]>packets[1] or packets [0]>packets[2] or packets[1]>packets[2]:
print ('The packets must be given in a rising order')
else:
corr_pack=True
while n<200 and no_right< packets[0] : #n loops all possible combinations from 1 and up to a
works=False #consecutive number of possibles the same length as the minimum package
n+=1 #works turns true as soon as a solution is found,
c=0 #a,b,c is how many packages of each size are needed
while c*packets[2]<=n and works==False: #each loop goes until the combined number of nuggets is bigger
b=0 #than the wanted number.
while c*packets[2]+b*packets[1]<=n and works==False:
a=0
while c*packets[2]+b*packets[1]+a*packets[0]<=n and works==False:#Goes though all combinations
if c*packets[2]+b*packets[1]+a*packets[0]==n: #of a,b&c till a solution is
works=True #found or all combinations are tried.
else: #starts with a and works it way out.
a+=1 #if a correct solution are found works turns True
if c*packets[2]+b*packets[1]+a*packets[0]==n:
works=True
else:
b+=1
if c*packets[2]+b*packets[1]+a*packets[0]==n:
works=True
else:
c+=1
if works==True: #if there exists a correct solution the n_right counter incerases
no_right+=1
#print n,a,b,c
else: #if there isn't, it resets to zero and that number is stored in highest.
highest=n
no_right=0
#print n,no_right
print highest #the highest non-solvable number is printed.
Problem 3
Date: 2009-11-20 02:04 am (UTC)Problem 4
Date: 2009-11-20 02:05 am (UTC)nPtLQmypptMQSGzKShM
Date: 2012-01-09 04:20 am (UTC)no subject
Date: 2009-11-23 03:21 am (UTC)no subject
Date: 2009-11-23 04:14 am (UTC)(edit: on further research, I'm seeing a couple of references to limits between 20 and several hundred layers of indentation -- I'm not sure if the varying numbers are different versions or implementations or what, but even if it's 20, it's *way* more than anything you'd find in these problem sets, and possibly any sane software design.)
YVvTOOWgrt
Date: 2011-10-28 04:06 am (UTC)mIRbCqsQuQnOU
Date: 2012-01-25 08:50 pm (UTC)dPzltTGLFjDkdVBUxLl
Date: 2012-02-22 08:15 am (UTC)umoQpLTIdMpUCHX
Date: 2012-05-02 01:37 am (UTC)BdDZTcKQWKMK
Date: 2012-05-02 01:45 am (UTC)wDBtnTZDJukJCkXlo
Date: 2012-05-02 01:45 am (UTC)xxpPSSnDaNxbf
Date: 2012-05-02 01:45 am (UTC)XrHLRyVIqQOTeYRru
Date: 2012-05-02 01:45 am (UTC)NjkPzLmmQFAxQ
Date: 2012-05-02 01:46 am (UTC)jTEcmknKyDXPhAdB
Date: 2012-05-02 07:10 am (UTC)qVqxpTvbvc
Date: 2012-05-02 07:22 am (UTC)QUhKdWvGWmI
Date: 2012-05-02 09:30 am (UTC)rxhNCRdmMGvxQDYc
Date: 2012-05-02 07:35 pm (UTC)PRMuioDhrgiAkOh
Date: 2012-05-02 07:43 pm (UTC)rNPRfOoZsWEvSz
Date: 2012-05-03 06:01 am (UTC)lySJoSJheSWeeLkf
Date: 2012-05-03 09:31 am (UTC)EGeLbbQFhVl
Date: 2012-05-03 12:15 pm (UTC)OSBFQpQJFFaUQ
Date: 2012-05-03 12:15 pm (UTC)TtMIeJpyHiwEnVKYbFE
Date: 2012-05-03 12:16 pm (UTC)HiInWgLOPXRLgmFHpZ
Date: 2012-05-03 12:16 pm (UTC)YFiuWPjktIY
Date: 2012-05-03 01:48 pm (UTC)FxBqFlWqyIFSEZIHbZk
Date: 2012-05-03 04:31 pm (UTC)ytrYTxVXTUqBatpJZJ
Date: 2012-05-03 11:19 pm (UTC)NolgLHaXCcyWEOAzfdF
Date: 2012-05-04 05:29 am (UTC)rGBUzvmjXy
Date: 2012-05-04 08:01 am (UTC)vBeYrBABrmj
Date: 2012-05-04 08:02 am (UTC)PFxzelbIreSvqTEUqb
Date: 2012-05-04 01:30 pm (UTC)nRtlHJEJAQP
Date: 2012-05-04 01:30 pm (UTC)TUEZbmHydKOA
Date: 2012-05-04 01:31 pm (UTC)IGQVTmkKEJE
Date: 2012-05-04 01:31 pm (UTC)DidoudVTrfpRW
Date: 2012-05-04 01:31 pm (UTC)