mad_casual


Joined 2 years ago
Homeworks submitted:
Homework comments:
2
0

About Me

No description provided.

Classes

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class status: Established
Role: Student
. 11% complete

Submitted Assignments

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1

I don't understand iterating over all the factors and all the possible numbers for every prime candidate. Doesn't it waste time doing tests on 4, 6, 9, and 64... when you already know 2 and 3 are factors and, therefore the candidate isn't prime?

#problem 1
    isprime = [2] #initializes the list of primes
    i = 3

    while len(isprime) < 1000:    #continue until 1000th prime
        prime = True                 #assume i is prime
        for j in isprime:              #compare it to the list
            if i%j == 0:               #to see if it divides evenly
                prime = False
            else:
                pass
            
        if prime:
            isprime.append(i)       #if it doesn't, add it to the list
        
        i += 1
    
    print isprime[-1]

#problem 2
isprime = [2]
for i in range (3, n, 2):
    prime = True
    for j in isprime:
        if i%j == 0:
            prime = False
        else:
            pass
    if prime:
        isprime.append(i)           #like above, collect all the primes
j = 0
    
for prime in isprime:
    j = j + log(prime)               #calculate the log of the sum of 'em
print 'The sum of the log of primes <= n is:',j
print 'n is:', n
print 'The ratio is:',j/n

mad_casual 2 years ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1

Problem Set 0

Name: mad_casual

Collaborators:N/A

Time: As fast as I could type it.

lastname = raw_input('Enter your last name\n**')
firstname = raw_input('Enter your first name\n**')

print firstname,'\n',lastname

mad_casual 2 years ago