elz: (ada-tubes)
elz ([personal profile] elz) wrote in [community profile] intro_to_cs2009-11-11 05:21 pm
Entry tags:

Lecture 2







Problem set 1: Computing prime numbers, product of primes

This one's a little trickier, so feel free to comment if you run into any problems or want to brainstorm with other people!

(eta: having issues with poll, alas)
phoenix: ink-and-watercolour drawing -- girl looking calmly over her shoulder (Default)

[personal profile] phoenix 2009-11-11 10:42 pm (UTC)(link)
Ooh, I'm proud of myself. I watched this lecture earlier in the week because I knew my time later in the week would be pretty limited and so I'd started the problem set too. I couldn't understand the second one, though. I was going to ask here and see if someone could help me out, and in phrasing the question, worked out what I'd misunderstood before. :)

[personal profile] elz, you may need to create the poll in another (public) entry. I think polls can only be created at entry posting time, not at edit time.
gchick: Small furry animal wearing a tin-foil hat (Default)

[personal profile] gchick 2009-11-12 12:06 am (UTC)(link)
while box == ticky:
    [x]

[personal profile] ex_wicker969 2009-11-12 12:13 am (UTC)(link)
Man it is times like these when I know how non-mathy my brain is. I got all the primes between 1 and 1000 but my code is ungainly and ugly and I kind of just printed 2, 3, 5, and 7 before I got the ball rolling on the rest by nesting 'if' and n%2!=0, n%3!=0 ... etc.

Anybody else make a pretty ugly program? I'm gonna go try it again at some point tonight. How'd your approach differ from mine?
rodo: chuck on a roof in winter (Default)

[personal profile] rodo 2009-11-12 12:16 am (UTC)(link)
I give up. I've been staring at the first problem for an hour and still have no clue where to start, while I don't even understand the second problem.
erda: (Default)

[personal profile] erda 2009-11-12 12:35 am (UTC)(link)
Is anybody else trying to do just one lecture a week? I know I won't have time for two.
bookchan: endless sky (Default)

Examples used in Lecture

[personal profile] bookchan 2009-11-14 12:06 pm (UTC)(link)
I typed up the examples he used while teaching since we don't have the handouts. This might help to get a better understanding of what he was doing. Everything is commented out also, so don't forget to remove the pound sign before playing. ^_^ Hopefully I typed it all correctly, I haven't played around with it yet.

ETA or you can just go to the lecture video at the MIT website and they have the handout right there.

Examples of overloading
3*4
3*'ab'
'a' + 'bcd'
3 + 'ab'
str(3)+'ab'
'a'<3
4<'3'
'4'<'3'
The code he used

##x=3 #create variable x and assign value 3 to it
##x=x*x # bind x to value 9
##print x
##n = raw_input('Enter a number; ')
##print n
##print n/n

##x=15
##if (x/2)*2 == x:
## print 'Even'
##else: print 'Odd'

##x=15
##if (x/2)*2 == x: print 'Even'
##else: print 'Odd'

##z='b'
##if 'x' < z :
## print 'Hello'
## print 'Mom'

##if 'x'< z :
## print 'Hello'
##print 'Mom'

##x=15
##y=5
##z=11
##print x,y,z
###Is this right?
##if x< y:
## if x< z : print 'x is least'
## else: print 'z is least'
##else: print 'y is least'
##
##if x < y and x < z : print 'x is least'
##elif y < z : print 'y is least'
##else: print 'z is least'


##y=0
##x=3
##itersLeft = x

##while (itersLeft>0):
## y= y+x
## itersLeft = itersLeft -1
###print 'y =',y,',intersLeft=',intersLeft
##print y

##x=10
##i=1
##while(i<x): ## if x%i == 0: ## print 'divisor ',i ## i = i+1 ##x = 10 ##for i in range(1,x): ## if x%i == 0: ## print 'divisor ',i
Edited 2009-11-15 08:37 (UTC)