Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 17 Online
OpenStudy (anonymous):

Has anyone attempted problem set 2 on PS1 yet?

OpenStudy (anonymous):

Yup, why do you ask? (I have done ps1-5 now)

OpenStudy (anonymous):

how was it?

OpenStudy (anonymous):

Jwalker, do you have a particular question about PS 1? If so I might be able to help. For seanlerner or anyone else, I'm stuck on Problem 3 of PS2. I feel that I have the overall structure of my program, but I can't devise a test for whether or not a particular n satisfies the equation 6a + 9b + 20c.

OpenStudy (anonymous):

@Max E, you should post your question as its own question. That way more people will see it. But, from what you've described, it sounds like you've written the whole program without making sure your inner test (is this number buyable) works. Get that test to work all by itself before trying to surround it with code that will use it. As for devising the test, they explain in the pdf what the test should be. You iterate over all possible values for a, b, and c and see if any combination satisfies the equation. Your code for just this test will have the form of three nested loops.

OpenStudy (anonymous):

your code Could have the form of three nested loops

OpenStudy (anonymous):

Max-E. I want to attempt the problem. I'm thinking of putting in a variable (log) that will calculate the logarithms of all of the primes I find math.log(primes). Than in the function that gives us the 1000th prime, I'll add command that adds up all of the logarithms.

OpenStudy (anonymous):

Here is my solution to the problem for those of you who care. http://codepad.org/KFq3ZvOR

OpenStudy (anonymous):

cool. for expression that evaluate to True or False you dont have to compare them to truee or false - in line 16 you can just use "if primality(number)" - which is really cool if you give your functions 'readable' names the built-in function sum() works across an entire list which makes it handy. if you make a list of the logs of those primes then you could use that function. one way to easily make a list of the logs is to use a list expression. list expressions are worth learning if you like Python - the documentation good. check this out: http://pastebin.com/gcavWrXy

OpenStudy (anonymous):

can you give me the source code

OpenStudy (anonymous):

rats - list comprehensions is the term, not list expressions. source for what? here are the docs: http://docs.python.org/tutorial/datastructures.html#list-comprehensions http://docs.python.org/howto/functional.html#generator-expressions-and-list-comprehensions

OpenStudy (anonymous):

Thanks

OpenStudy (anonymous):

http://codepad.org/OLOSxrkA Here is version 2

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!