Would greatly appreciate your comments on my problem set 1 solution: http://pastebin.com/567ix4FU
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!
It's little complicated I just gone through it...but it's seriously good....check my solution..
Well, not bad, I think. Though, I suppose, it may lack some generalization and abstraction.
Also, you use definition of prime in order to check if number n is prime. This process takes much time when n is relatively large. There is a faster method called a "trial division" method. I also used definition of prime for the check:
'''the function returns n if n is prime and -1 if n is not prime'''
k = n - 1
while k > 1:
if n % k == 0:
k = k - 1
But them I realized that it's very slow if I need to check a lot of number and if numbers get bigger and bigger, and I looked up definition of primes in wikipedia and found the "trial division" method that is relatively faster.