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

solutions to problem set 1.... please just post solution... been trying for a few days now

OpenStudy (anonymous):

both problems

OpenStudy (anonymous):

Here is what i finally managed to get a hold of for part 1: def primes(n): """ returns a list of prime numbers from 2 to n """ if n < 2: return [] if n == 2: return [2] # create a list of odd numbers from 3 to n nums = list(range(3, n+1, 2)) nums_len = (n // 2) - 1 + (n % 2) idx = 0 idx_sqrtn = (int(n**0.5) - 3) // 2 while idx <= idx_sqrtn: nums_idx = (idx << 1) + 3 for j in range(idx*(nums_idx+3)+3, nums_len, nums_idx): # if not a prime replace with zero nums[j] = 0 idx += 1 while idx <= idx_sqrtn: if nums[idx] != 0: break idx += 1 # remove all the zero entries return [2] + [x for x in nums if x != 0] print('-' * 50) # print 50 dashes, cosmetic num = 7919 primeList = primes(num) print("List of prime numbers from 2 to %d:" % num) print(primeList)

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!
Latest Questions
Arriyanalol: So on this pretty tuesday we loss a beautiful soul dolly parton
4 hours ago 2 Replies 1 Medal
Mari103: How to pop out like a Jacc In the box
1 day ago 0 Replies 0 Medals
Breathless: Spooky witch but cute
1 day ago 3 Replies 1 Medal
Arriyanalol: help
1 day ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
2 days ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
1 day ago 6 Replies 1 Medal
Arriyanalol: bro how
1 day ago 2 Replies 3 Medals
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!