elz: (ada-tubes)
[personal profile] elz posting in [community profile] intro_to_cs
Post and discuss your answers in the comments! (And yay for everybody who posted problem set 1 answers!)

Date: 2009-11-19 02:25 am (UTC)
gchick: Small furry animal wearing a tin-foil hat (Default)
From: [personal profile] gchick
Your other code allowed James T. Kirk to get laid. It us CRUCIALLY IMPORTANT!

As for this one, I had no problem with questions 1 & 2, stumbled into a nice solution for the original McNugget problem that solved it with math rather than exhaustive search, and then faceplanted in problem 4 because I'm pretty sure that assignment 2 isn't supposed to be NP-hard, even at MIT. I... need to step away from it and find some other practice problem with the same logical structure. Sigh.

Date: 2009-11-19 02:55 am (UTC)
gchick: Small furry animal wearing a tin-foil hat (Default)
From: [personal profile] gchick
Yep. I tend to get stuck on "but what's the solution?" rather than "what am I practicing here?"

So with that in mind, I'm off to play with possible combinations of Hardison, Eliot, and Parker; they're better than McNuggets in so many ways. Thanks for posting your solution - it was a good clarifier when I was letting things get too complicated.

Re: Problem #4

Date: 2010-03-03 03:59 pm (UTC)
From: (Anonymous)
ELZ - My script wound up being very similar to yours. I couldn't figure out how to stop looking after 6 consecutive successful results, so I just put all successful results in a list. I then looked for numbers not in that list and used the highest number that was missing. I'm not sure if I'm happy to find this thread AFTER I finally figured it out (hours), or if I'm glad I didn't because I think I learned more.....

## This program looks for the maximum number that can't be
## created using combinations of package sizes.


# variables - change to manipulate how what numbers to try and max range
# to try within. If the result is close to your max range, you should
# probably increase the range.
packages = [6,9,20] # variable that contains package sizes
n = range(0, 201) # range to test within. Max number must be at least TWO more than expected result.

# tests all possible combinations. Saves numbers that were successfully computed to numworks.
numworks = []
for count in n:
for a in range(0, count/packages[0]+1): #instead of using all combinations, only combinations that
# wouldn't be higher than max range (so max range divided by package size). Adding one because
# of remainders. This cuts WAY down on the time to process the program vs just using "range (0, count)"
for b in range(0, count/packages[1]+1):
for c in range(0, count/packages[2]+1):
if ((a*packages[0] + b*packages[1] + c*packages[2]) == count):
numworks = numworks + [count]

### found that entire section is not needed to get correct results. It makes numworks look nicer, but isn't needed.
### Sort then Remove duplicates from numworks
##cycle = 0
##if numworks:
## numworks.sort()
## last = numworks[-1]
## for i in range(len(numworks)-2, -1, -1):
## if last == numworks[i]:
## del numworks[i]
## else:
## last = numworks[i]

# create numbad which is list of numbers that didn't work. This is based on numbers that are not in numworks.
numbad = [0]
for ii in range (0,numworks[-1]):
if ii not in numworks:
numbad = numbad + [ii]

# prints results. Also accounts for no results.
if numbad == [0]:
print "No numbers were generated. \nYou likely used a 1 (one) or a negitive number as a package size."
else:
print "Given package sizes %i, %i, and %i, the largest number of McNuggets that \ncannot be bought in exact quantity is: %i. \n \n*** Note: the highest number tested was %i ***" % (packages[0], packages[1], packages[2], numbad[-1], n[-1])

#4

Date: 2009-11-20 12:39 am (UTC)
medrin: matlab code with everything but 'hold on' blurred (Default)
From: [personal profile] medrin
Here is my solution! (but I could not get the indentations to work, anyone know how?)

If anyone have any questions, just ask!


#packets = (6,9,20)
no_right = 0
n=0
highest=0
corr_pack=False
print'Hi!'


#asks for the diffrent package sizes and checks that they are suitable (error handling)
while corr_pack==False:
print('What are the three packet sizes (in rising order)?')
packets=input()
if len(packets)!=3:
print ('There must be three and only three packet sizes')
elif type(packets[0])!=int or type(packets[1])!=int or type(packets[2])!=int:
print ('All packet sizes must be given in integrers')
elif packets[0]<0 or packets[1]<0 or packets[2]<0:
print ('The packet sizes must be positive numbers')
elif packets[0]>packets[1] or packets [0]>packets[2] or packets[1]>packets[2]:
print ('The packets must be given in a rising order')
else:
corr_pack=True

while n<200 and no_right< packets[0] : #n loops all possible combinations from 1 and up to a
works=False #consecutive number of possibles the same length as the minimum package
n+=1 #works turns true as soon as a solution is found,
c=0 #a,b,c is how many packages of each size are needed
while c*packets[2]<=n and works==False: #each loop goes until the combined number of nuggets is bigger
b=0 #than the wanted number.
while c*packets[2]+b*packets[1]<=n and works==False:
a=0
while c*packets[2]+b*packets[1]+a*packets[0]<=n and works==False:#Goes though all combinations
if c*packets[2]+b*packets[1]+a*packets[0]==n: #of a,b&c till a solution is
works=True #found or all combinations are tried.
else: #starts with a and works it way out.
a+=1 #if a correct solution are found works turns True
if c*packets[2]+b*packets[1]+a*packets[0]==n:
works=True
else:
b+=1
if c*packets[2]+b*packets[1]+a*packets[0]==n:
works=True
else:
c+=1
if works==True: #if there exists a correct solution the n_right counter incerases
no_right+=1
#print n,a,b,c
else: #if there isn't, it resets to zero and that number is stored in highest.
highest=n
no_right=0
#print n,no_right
print highest #the highest non-solvable number is printed.


Problem 3

Date: 2009-11-20 02:04 am (UTC)
yhlee: wax seal (BPAL Peony Moon (julebug))
From: [personal profile] yhlee
I'm pretty sure this is ugly and I know it's inefficient, but they asked for exhaustive search...

# Solving a Diophantine Equation.

# Helper function
def consecutiveValues(n1, n2, n3, n4, n5, n6):
	value = (n1 + 1 == n2) and (n2 + 1 == n3) and (n3 + 1 == n4) and (n4 + 1 == n5) and (n5 + 1 == n6)
	return value

# Helper function
def nuggetsTest(n):
	answer = False
	for a in range(0,11):
		for b in range(0,11):
			for c in range(0,11):
				if (a*6 + b*9 + c*20) == n:
					return True
	return answer

def mcnuggets():
	# Possible instance of number of McNuggets that cannot be purchased
	# exactly.
	n = 1

	# Stores successful values of n.
	successful_n = [0,0,0,0,0,0]

	# Stores failed values of n.
	failed_n = [0]

	# We already know from Problem 1 that 50, 51, ..., 55 (and all
	# instances thereafter) have exact solutions.  So let's set an
	# upper bound for a, b, and c as 10, which should catch all
	# feasible possibilities for each variable (6*10 = 60).

	while consecutiveValues(successful_n[-6], successful_n[-5], successful_n[-4], successful_n[-3], successful_n[-2], successful_n[-1]) == False:
		if nuggetsTest(n) == True:
			successful_n = successful_n + [n]
			print n
		else:
			failed_n = failed_n + [n]
		n = n + 1

	print "Largest number of McNuggets that cannot be bought in exact quantity: " + str(failed_n[-1])

Problem 4

Date: 2009-11-20 02:05 am (UTC)
yhlee: wax seal (Default)
From: [personal profile] yhlee
Very similar to problem 3. I didn't bother with the other cases they suggested trying, but it would be simple to make the changes.

packages = (6,9,20)	 # variable that contains package sizes

# helper function #1
def consecutiveValues(n1, n2, n3, n4, n5, n6):
	value = (n1 + 1 == n2) and (n2 + 1 == n3) and (n3 + 1 == n4) and (n4 + 1 == n5) and (n5 + 1 == n6)
	return value
	
# helper function #2
def nuggetsTest(n):
	answer = False
	for a in range(0,34):
		for b in range(0,34):
			for c in range(0,34):
				if (a*packages[0] + b*packages[1] + c*packages[2]) == n:
					return True
	return answer

def mcnuggets_search():
	n = 1
	
	# Stores successful values of n.
	successful_n = [0,0,0,0,0,0]
	
	bestSoFar = [0]	# variable that keeps track of largest
				# number of McNuggets that cannot be
				# bought in exact quantity

	while consecutiveValues(successful_n[-6], successful_n[-5], successful_n[-4], successful_n[-3], successful_n[-2], successful_n[-1]) == False and n < 200:
		if nuggetsTest(n) == True:
			successful_n = successful_n + [n]
			print n
		else:
			bestSoFar = bestSoFar + [n]
		n = n + 1
		
	print "Given package sizes " + str(packages[0]) + ", " + str(packages[1]) + ", and " + str(packages[2]) + ", the largest number of McNuggets that cannot be bought in exact quantity is: " + str(bestSoFar[-1]) + "."

nPtLQmypptMQSGzKShM

Date: 2012-01-09 04:20 am (UTC)
From: (Anonymous)
Sharp tihnikng! Thanks for the answer.

Date: 2009-11-23 03:21 am (UTC)
bellerina: (Default)
From: [personal profile] bellerina
Does anyone know if there is a limit to how many indentations/levels of nested loops is viable in Python? I'm having an issue with problem 3 in that my nested loops work fine until I add another while loop outside of them, and I can't figure out why.

Date: 2009-11-23 04:14 am (UTC)
gchick: Small furry animal wearing a tin-foil hat (Default)
From: [personal profile] gchick
There's no limit. Maybe if you posted a code snippet, someone might be able to spot something that you're not seeing?

(edit: on further research, I'm seeing a couple of references to limits between 20 and several hundred layers of indentation -- I'm not sure if the varying numbers are different versions or implementations or what, but even if it's 20, it's *way* more than anything you'd find in these problem sets, and possibly any sane software design.)
Edited Date: 2009-11-23 04:30 am (UTC)

YVvTOOWgrt

Date: 2011-10-28 04:06 am (UTC)
From: (Anonymous)
6bUfIn http://M8bJXXT7yzZFp1CH.com

mIRbCqsQuQnOU

Date: 2012-01-25 08:50 pm (UTC)
From: (Anonymous)
Have you got a telephone directory?

dPzltTGLFjDkdVBUxLl

Date: 2012-02-22 08:15 am (UTC)
From: (Anonymous)
How much does the job pay? free nude loli pics (http://galeon.com/ajahoige/index.html) 97098 afican underage nude lolitas (http://galeon.com/ytemeceli/index.html) =-PPP magic lolitas hentai fzh (http://galeon.com/osakopau/index.html) ergkxy sexso gratis con lolitas (http://galeon.com/birutonat/index.html) jazges easter lola bunny hentai (http://galeon.com/nyeagifa/index.html) %-[ lolita 5 15 bbs (http://galeon.com/jatipogoq/index.html) 8((( beautiful nude lolita pics (http://galeon.com/okocaiqom/index.html) 45286 top lolita teen 18 (http://galeon.com/yjanasey/index.html) kefovv no nude pretens lolitas (http://galeon.com/guceqekili/index.html) thmlb slut bbs thumbs lolita (http://galeon.com/udulajedu/index.html) :P

umoQpLTIdMpUCHX

Date: 2012-05-02 01:37 am (UTC)
From: (Anonymous)
We used to work together http://gykepugurohy.blog.free.fr/ naked angel bbs I hate the fingernails, but she's a damn pretty natural latin girl, anyway! and she can suck cock and loves it!!! I'd ove to get sucked by her! beautiful lips!!!

BdDZTcKQWKMK

Date: 2012-05-02 01:45 am (UTC)
From: (Anonymous)
In a meeting http://ofapolyykeg.blog.free.fr/ pedo grils models I fucking love cumming in a girls pussy to bad I can't find one who will let me do it.

wDBtnTZDJukJCkXlo

Date: 2012-05-02 01:45 am (UTC)
From: (Anonymous)
How many are there in a book? http://aquytyiqyha.blog.free.fr/ young european models Hate to double post but fuck.. I can't get over how much I love it when women grind like that... No contest if a girl wants to get me off.

xxpPSSnDaNxbf

Date: 2012-05-02 01:45 am (UTC)
From: (Anonymous)
The National Gallery http://ofapolyykeg.blog.free.fr/ schoolgirl model samples wtf, why don't asian women stop fuckin crying like dying cats and fuck for once. I only fuck asian americans, women who have seen real fucking, not this bullshit where little dick having guys slowly fuck these hairy pussy squeelers. Go to Cali, not Tokyo.

XrHLRyVIqQOTeYRru

Date: 2012-05-02 01:45 am (UTC)
From: (Anonymous)
We went to university together http://opaolate.blog.free.fr/ dee lily model What eyes! Class and style! Fantasic confident woman enjoying her job. Best film I've seen in years, all because of her! (And yes, I am typing with one hand, other is busy) :D

NjkPzLmmQFAxQ

Date: 2012-05-02 01:46 am (UTC)
From: (Anonymous)
I wanted to live abroad http://anicucegei.blog.free.fr/ pedo modell oh my god he giving it to her right!! shit, i'd take that dick in like a fucking soldier! i was that was my pussy getting fucked like that

jTEcmknKyDXPhAdB

Date: 2012-05-02 07:10 am (UTC)
From: (Anonymous)
How do you know each other? http://anisumoute.blog.free.fr/ voyeur preteen pics hold on im just gonna cum on your face...thats fuckin hilarious if i was a porn cameraman id do that every shoot

qVqxpTvbvc

Date: 2012-05-02 07:22 am (UTC)
From: (Anonymous)
I'm doing a phd in chemistry http://ekynecirolasu.blog.free.fr/ nonude child model This girl is fucking sexy. I love her tight pussy. I love her so much. That guy is fucking lucky.

QUhKdWvGWmI

Date: 2012-05-02 09:30 am (UTC)
From: (Anonymous)
We need someone with qualifications http://enytosyjaqo.blog.free.fr/ only porn bbs Pinky is hella fine... i wanna eat her PUSSY so bad... DAMN SHE THE SHIT... THAT FAT ASS CLAPPIN AND SHIT...

rxhNCRdmMGvxQDYc

Date: 2012-05-02 07:35 pm (UTC)
From: (Anonymous)
I'm on work experience http://yypidugenur.de.tl photo cp bbs I don't think she's ugly.. She's just an average looking everday chick... And she deffently ain't fat. Ya'll have gotten use to seeing all these supermodel looking chicks doing porn

PRMuioDhrgiAkOh

Date: 2012-05-02 07:43 pm (UTC)
From: (Anonymous)
How do you do? http://ogatenetif.de.tl petite model links She is soooo much better at fucking than he is!!!! He had a nice cock though... The first half was pretty good. Eye contact,kissing,intensity..they seemed to be really enjoying fucking each other..He got lazy in the last half thou.. too much doggy style, boring!! he was sitting on his ass and she was doing most of the work..Cumshot was sooo weak. he shoulda just came on her ass.. An internal shot woulda been really HOTTT!!! Oh well...

rNPRfOoZsWEvSz

Date: 2012-05-03 06:01 am (UTC)
From: (Anonymous)
How many are there in a book? http://bynupaigera.de.tl pretty hot bbs SMOKIN!! I think i'd have a sex change to be with these three! The dark gal is particularly sweet...would love them to grind on my face n cock while they do each other, ahhh. Whats that that just fell into my hand, oh must be my cock...again :p

lySJoSJheSWeeLkf

Date: 2012-05-03 09:31 am (UTC)
From: (Anonymous)
I've just graduated http://kiduymidisy.de.tl nymphets angel pussy I think her pussy is cute. I would eat it, but I would love to get fucked by his dick =]. It looks so good ;]. LOL

EGeLbbQFhVl

Date: 2012-05-03 12:15 pm (UTC)
From: (Anonymous)
Directory enquiries http://ausouar.de.tl nymphet brazil he puts my small white dick to shame he is fukin sexc fuckin that white bitch tho she looks like shes lovin it

OSBFQpQJFFaUQ

Date: 2012-05-03 12:15 pm (UTC)
From: (Anonymous)
My battery's about to run out http://oqepuhylinys.de.tl nymphets image yooo..she is fuckin loud as hell! lol she can't be makin all the noise for real.. she gotta be fakin!

TtMIeJpyHiwEnVKYbFE

Date: 2012-05-03 12:16 pm (UTC)
From: (Anonymous)
I'm doing a masters in law http://sajudyfane.de.tl dark portal nymphets That's definitely a MILF! Nice to see MILF is an international term! I would have banged her a lot better. Also noticed maybe they don't eat pussy...their loss!

HiInWgLOPXRLgmFHpZ

Date: 2012-05-03 12:16 pm (UTC)
From: (Anonymous)
I can't stand football http://oqepuhylinys.de.tl all pics nymphets THat girl is a fucking CHAMP!!! Holla! And Erik knew what he was doing, getting the nasty ass frenchman to cumming in her second! LOL! She is such a good girl!

YFiuWPjktIY

Date: 2012-05-03 01:48 pm (UTC)
From: (Anonymous)
I'd like to speak to someone about a mortgage http://onasurubym.de.tl composites bbs Valentina is such a sexy woman and looks great getting worked over in this vid. She takes a DP well and looks hot doing it. Very good scene!

FxBqFlWqyIFSEZIHbZk

Date: 2012-05-03 04:31 pm (UTC)
From: (Anonymous)
Have you read any good books lately? http://umaceudyfytu.de.tl girl bbs post the only thing i can think of that is funny to say (( is that yellow thing on the counter top a butt plug))

ytrYTxVXTUqBatpJZJ

Date: 2012-05-03 11:19 pm (UTC)
From: (Anonymous)
Where did you go to university? http://ubuekujuqim.de.tl non nude nymphs I would love to be sucked by this girl she is an expert, would like to spurt in her mouth

NolgLHaXCcyWEOAzfdF

Date: 2012-05-04 05:29 am (UTC)
From: (Anonymous)
I wanted to live abroad http://komufypipy.de.tl japan teen models bbs lol. i dont know what u losers are getting upset about. this is the world of porn. money buys it all. u losers are so upset about the fact that hes fucking her and shit... dont forget morons, she agreed to it like a cheap slut she is.. shit.. u guys makin her look all glorious and victimized.. gimme a fuckin break. get a life losers hahaha.

rGBUzvmjXy

Date: 2012-05-04 08:01 am (UTC)
From: (Anonymous)
How many more years do you have to go? http://olafuynyjik.de.tl daughter bbs I have always wanted to try my hand, rather mouth, at eating pussy. I am curious to eat a woman out. Feel the pussy squeeze my tongue and such... I have a feeling I would be good at it.

vBeYrBABrmj

Date: 2012-05-04 08:02 am (UTC)
From: (Anonymous)
What do you study? http://olafuynyjik.de.tl pr teen bbs mhmm she want that naughty pussy fucked hard...needed another guy just forced fucked her...she would have had that bed soaking wet

PFxzelbIreSvqTEUqb

Date: 2012-05-04 01:30 pm (UTC)
From: (Anonymous)
Gloomy tales http://necikuekyir.de.tl nymphet lingerie models His dicks average bro...Hes fucking this slut and your not. Your watching him fuck this slut. enough about dick size im sick of hearing about it. huge dick or not if you got fuck game you can make any bitch enjoy it...

nRtlHJEJAQP

Date: 2012-05-04 01:30 pm (UTC)
From: (Anonymous)
real beauty page http://igujyfagehu.de.tl sexy virgins nymphets like her tits but god dam it why do they need two black guys there getting in the way i cant see her ass or pussy or boobs

TUEZbmHydKOA

Date: 2012-05-04 01:31 pm (UTC)
From: (Anonymous)
Do you know the address? http://igujyfagehu.de.tl planet lo nymphet I hate when the music drowns out the story and the moaning. I was getting into it then I can't hear what the two females are saying. Sucks

IGQVTmkKEJE

Date: 2012-05-04 01:31 pm (UTC)
From: (Anonymous)
I've got a very weak signal http://edeboteler.de.tl nymphet boy sex can someone tell me what is the name of that blond and does anyone who the name of the movie she did with Kay Parker as a babysitter?

DidoudVTrfpRW

Date: 2012-05-04 01:31 pm (UTC)
From: (Anonymous)
I love this site http://ynulofoti.de.tl underage filipina nymphet She is fucking HOT!!! and would be great to fuck. The guys are lucky and know what there doing.. love the black guy who is he?

Profile

Introduction to Computer Science

July 2010

S M T W T F S
    123
45678910
11121314151617
18192021222324
2526272829 3031

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 21st, 2017 10:58 pm
Powered by Dreamwidth Studios