### Problem Set 2

Nov. 16th, 2009 09:41 pm**elz**posting in

**intro_to_cs**

Post and discuss your answers in the comments! (And yay for everybody who posted problem set 1 answers!)

You're viewing intro_to_csCreate a Dreamwidth Account Learn More | site light | Reload page in style:

Post and discuss your answers in the comments! (And yay for everybody who posted problem set 1 answers!)

Introduction to Computer Science

**elz**-*(no subject)***elz**- Problem #4**medrin**- #4**yhlee**- Problem 3**yhlee**- Problem 4**bellerina**-*(no subject)*- (Anonymous) - YVvTOOWgrt
- (Anonymous) - mIRbCqsQuQnOU
- (Anonymous) - dPzltTGLFjDkdVBUxLl
- (Anonymous) - umoQpLTIdMpUCHX
- (Anonymous) - BdDZTcKQWKMK
- (Anonymous) - wDBtnTZDJukJCkXlo
- (Anonymous) - xxpPSSnDaNxbf
- (Anonymous) - XrHLRyVIqQOTeYRru
- (Anonymous) - NjkPzLmmQFAxQ
- (Anonymous) - jTEcmknKyDXPhAdB
- (Anonymous) - qVqxpTvbvc
- (Anonymous) - QUhKdWvGWmI
- (Anonymous) - rxhNCRdmMGvxQDYc
- (Anonymous) - PRMuioDhrgiAkOh
- (Anonymous) - rNPRfOoZsWEvSz
- (Anonymous) - lySJoSJheSWeeLkf
- (Anonymous) - EGeLbbQFhVl
- (Anonymous) - OSBFQpQJFFaUQ
- (Anonymous) - TtMIeJpyHiwEnVKYbFE
- (Anonymous) - HiInWgLOPXRLgmFHpZ
- (Anonymous) - YFiuWPjktIY
- (Anonymous) - FxBqFlWqyIFSEZIHbZk
- (Anonymous) - ytrYTxVXTUqBatpJZJ
- (Anonymous) - NolgLHaXCcyWEOAzfdF
- (Anonymous) - rGBUzvmjXy
- (Anonymous) - vBeYrBABrmj
- (Anonymous) - PFxzelbIreSvqTEUqb
- (Anonymous) - nRtlHJEJAQP
- (Anonymous) - TUEZbmHydKOA
- (Anonymous) - IGQVTmkKEJE
- (Anonymous) - DidoudVTrfpRW

- Base style: Modish by
- Theme: Greyscale by

No cut tags

## no subject

Date: 2009-11-19 12:10 am (UTC)elzProblem 1:

6a,9b,20c = n

2,2,1 = 50

1,5,0 = 51

2,0,2 = 52

1,3,1 = 53

0,6,0 = 54

1,1,2 = 55

If you add 6 to those totals, you get 56,57,58,59,60,61.

If you add 6 to those totals, you get 62,63,64,65,66,67.

Problem 2:

So basically, once the condition is true for any run of six, it's true for that run of six + 6, which works out to every number greater than the start of the first run of six. If it were true for a run of nine, it would also be true for that run of nine + 9, etc.

## no subject

Date: 2009-11-19 02:25 am (UTC)gchickAs 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.

## no subject

Date: 2009-11-19 02:44 am (UTC)elzI got a little intimidated looking at the problem set, because it's been a loooong time since I took math, but it really is mostly "can you loop through stuff until you come up with an answer?"

## no subject

Date: 2009-11-19 02:55 am (UTC)gchickSo 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.

## Problem #4

Date: 2009-11-19 02:21 am (UTC)elz## Re: Problem #4

Date: 2009-11-19 06:45 pm (UTC)elzto:

## Re: Problem #4

Date: 2010-03-03 03:59 pm (UTC)## 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)medrinIf 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]<=

if c*packets[2]+b*packets[1]+a*packets[0]==

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]==

works=True

else:

b+=1

if c*packets[2]+b*packets[1]+a*packets[0]==

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## Problem 4

Date: 2009-11-20 02:05 am (UTC)yhlee## nPtLQmypptMQSGzKShM

Date: 2012-01-09 04:20 am (UTC)## no subject

Date: 2009-11-23 03:21 am (UTC)bellerina## no subject

Date: 2009-11-23 04:14 am (UTC)gchick(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)## mIRbCqsQuQnOU

Date: 2012-01-25 08:50 pm (UTC)## dPzltTGLFjDkdVBUxLl

Date: 2012-02-22 08:15 am (UTC)free nude loli pics(http://galeon.com/ajahoige/index.html) 97098afican underage nude lolitas(http://galeon.com/ytemeceli/index.html) =-PPPmagic lolitas hentai fzh(http://galeon.com/osakopau/index.html) ergkxysexso gratis con lolitas(http://galeon.com/birutonat/index.html) jazgeseaster 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) 45286top lolita teen 18(http://galeon.com/yjanasey/index.html) kefovvno nude pretens lolitas(http://galeon.com/guceqekili/index.html) thmlbslut bbs thumbs lolita(http://galeon.com/udulajedu/index.html) :P## umoQpLTIdMpUCHX

Date: 2012-05-02 01:37 am (UTC)## BdDZTcKQWKMK

Date: 2012-05-02 01:45 am (UTC)## wDBtnTZDJukJCkXlo

Date: 2012-05-02 01:45 am (UTC)## xxpPSSnDaNxbf

Date: 2012-05-02 01:45 am (UTC)## XrHLRyVIqQOTeYRru

Date: 2012-05-02 01:45 am (UTC)## NjkPzLmmQFAxQ

Date: 2012-05-02 01:46 am (UTC)## jTEcmknKyDXPhAdB

Date: 2012-05-02 07:10 am (UTC)## qVqxpTvbvc

Date: 2012-05-02 07:22 am (UTC)## QUhKdWvGWmI

Date: 2012-05-02 09:30 am (UTC)## rxhNCRdmMGvxQDYc

Date: 2012-05-02 07:35 pm (UTC)## PRMuioDhrgiAkOh

Date: 2012-05-02 07:43 pm (UTC)## rNPRfOoZsWEvSz

Date: 2012-05-03 06:01 am (UTC)## lySJoSJheSWeeLkf

Date: 2012-05-03 09:31 am (UTC)## EGeLbbQFhVl

Date: 2012-05-03 12:15 pm (UTC)## OSBFQpQJFFaUQ

Date: 2012-05-03 12:15 pm (UTC)## TtMIeJpyHiwEnVKYbFE

Date: 2012-05-03 12:16 pm (UTC)## HiInWgLOPXRLgmFHpZ

Date: 2012-05-03 12:16 pm (UTC)## YFiuWPjktIY

Date: 2012-05-03 01:48 pm (UTC)## FxBqFlWqyIFSEZIHbZk

Date: 2012-05-03 04:31 pm (UTC)## ytrYTxVXTUqBatpJZJ

Date: 2012-05-03 11:19 pm (UTC)## NolgLHaXCcyWEOAzfdF

Date: 2012-05-04 05:29 am (UTC)## rGBUzvmjXy

Date: 2012-05-04 08:01 am (UTC)## vBeYrBABrmj

Date: 2012-05-04 08:02 am (UTC)## PFxzelbIreSvqTEUqb

Date: 2012-05-04 01:30 pm (UTC)## nRtlHJEJAQP

Date: 2012-05-04 01:30 pm (UTC)## TUEZbmHydKOA

Date: 2012-05-04 01:31 pm (UTC)## IGQVTmkKEJE

Date: 2012-05-04 01:31 pm (UTC)## DidoudVTrfpRW

Date: 2012-05-04 01:31 pm (UTC)