Just looking to verify the ps2 problems and make sure my program is generating the right answer and looking for any general feedback.
If someone could provide some insight into the actual proof of the theorem that would be great, my math is incredibly rusty and while I can pen and paper and see that it is true I'm having trouble explaining it.
MIT 6.00 Intro Computer Science (OCW)
Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Your code seems pretty good. I particularly like the way you use a function to solve a part of the problem and the way you use variable names that make sense. All this makes the code easy to read.
I didn't know you could do something like findHighestImpossibleCombo(*packageSizes). Do you have a reference explaining how it works ?
I noted 2 things though:
1. In findHighestImpossibleCombo(), you are passing the package sizes. But sadly, in the function you are using constants where you could reuse the package sizes. For example:
comboNumberTest = x; # start at the lowest possible combo of nuggets which is 6
while possibleCount < x:
This way, if the package sizes change, you don't have to change the code inside the function
2. In isComboPossible(), you are mixing 2 return types. When you find a solution, your return a tuple, when not you return a boolean. It is better to be coherent, always return a boolean, or always return a value (empty tuple or None if not found).
Thanks for the feedback. I was wondering if there was an easier way to pass the values of a tuple to a function instead of referencing each individual value and was able to find http://stackoverflow.com/questions/6699592/how-to-pass-tuple-as-parameters-of-a-function
I'm not sure if in python you are passing a true reference or not, i'll have to spend more time reading the docs.
Also in regards to isComboPossible you're correct about the return types however I wasn't sure if that was a feature of the language or not. Normally I would consider it best practice to use a flag and then base return type around that but I've run into some weird things in python so I wasn't quite sure what to do in this case.
Best practices in mind I'll definitely remember that in the future.
Not sure why I used a constant in findHighestImpossibleCombo when I had already gone to the trouble of making isComboPossible() able to handle generic cases. Thanks for pointing that out!
Gotta say python is definitely one of the most interesting languages I've worked with.
@kl365. "I was wondering if there was an easier way to pass the values of a tuple to a function instead of referencing each individual value." Don't understand your question. Tuples can be used as arguments for functions just like other data objects. You don't need to reference individual values. For example, the following is perfectly valid.
Not the answer you are looking for? Search for more explanations.
An elegant answer, my code is quite messy compared to yours! I also haven't utilized functions because they were not yet included in the lecture (up to lec. 3).
Question for you... given that problem 1 includes the following, "however you chose to solve this problem, list the combinations of 6, 9 and 20 packs of McNuggets you need to buy in order to get each of the exact amounts." How does your code handle listing the combinations possible?
Your function, isComboPossible(n,x,y,z) will return the first and only the first combination.
Here is my work http://pastebin.com/9xGNaB7F (feedback is welcome)
Also, I do recognize that my code takes a lot of run time because it iterates through all possible values of a, b, and c.
I was interested in passing the values of the tuple as such
def myFunction(x, y, z):
stuff goes here
myTuple = (1, 2, 3)
myFunction(myTuple, myTuple, myTuple)
You're correct in that I haven't checked for all possible combinations, the way I've written the function now it exits on the first possible combination it finds.
I think to handle all possible combinations I would fix my function to include a variable to track the number of possible combinations, returning 0 if none. Then add a list which can store the tuple combinations as they are found.
let me try it out and see what i can find.
I'm not sure when working on these problems if we're bound to the features in python that have been brought up in the lectures or since the course isn't strictly about python if we're free to use what we're comfortable with.
Could always just build a string to return instead of a list but lists are easier to work with in this case i think.
The question of the assignment is 'does it exist a combination that meets the requirements ?'. You are not expected to find all the combinations and it won't help you to solve the problem.
It may be interesting to code, but I think it should be noted that it is out of the range of the problem.
@ mairtre_kaio Listing the combinations is a part of problem 1 from the set, though it does not specify that it needed to be coded. I actually was only working on this part of the problem set without reading further.. hehe
@kl365 Apologies if I am misguiding you with my question, I will work further into the problem sets before my commentary in the open study group!! Thanks for sharing your work and the response.