For PS1 - does everyone have a good math background to get through figuring this stuff out? I will admit that this may not be my strong suit and was looking to see what everyone else had. I assume I could look up and find the algorithm on how to do it but both tasks are currently out of grasp trying to go from memory.
Not really, the only math background for implementing a working solution for ps1 is to know what a prime number is. Firstly, try to implement a working solution for one prime number, then work your way up to expand to several prime numbers. To be honest, this pset looks a lot harder at first glance, but after you start working on it, it seems a lot less scary.
I will second that the problems are not as difficult as they first seem. The last time I took a math class was 10 years ago, and the farthest I went in math was precalculus. (I just finished problem set 4 over the weekend. So far so good.) Doing the readings and the examples in them will help a lot. Also, breaking down the problem as bmp suggested will help a lot. If you decide you want to learn some math, I know there are classes on OCW. FWIW, I really enjoy http://www.khanacademy.org/. The videos on the site tackle math from basic arithmetic through differential equations and linear algebra, and I find them to be very helpful.
I am still having a hard time wrapping my head around this. I have watched the first lecture and read chapters 1 and 2 but just can't get it. I am not a programmer at all and I am not sure where I am going wrong. I know that I probably need a while loop to check all divisors < sqrt of n.So for the number 7 I need to check if it divides by 2 since that is the only number less than the sqrt. I am having a hard time translating this in to code.
Thinking out loud here, this is what I have. prime = 3 divisor = 2 isPrime == True //we know n/n = 1 while divisor < sqrt prime if prime % divisor != 0 divisor ++ else return isPrime false
1. It looks like you are on the right track. If you were to look at the documentation you could find a way to write code for a square root. Based on your code above, you could write while divisor < int(prime**0.5) The int() function will truncate the float number that is returned from prime**0.5 and convert it to an integer. 2. For ease of editing purposes, I have two tips. First, in the future please post your code to http://codepad.org/ or a similar site. Also, be careful with your variable names. Naming a variable that points to every number that will be tested and calling it prime may trip you (or others on this site) up a bit when reviewing your code. (This is not so much a problem here, where the amount of code is minimal.) 3. Once you get the "code" you typed above into proper Python syntax, if you still have questions, post the code on codepad and copy the link into the post with your question. Someone will be around to help. Good luck.
Join our real-time social learning platform and learn together with your friends!