vbakhtyr


Joined 1 year ago
Homeworks submitted:
Homework comments:
3
0

About Me

No description provided.

Classes

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming

Class status: Established
Role: Student
. 17% complete

Submitted Assignments

MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 3, HW 1
# Prob 1

def combos(n): 
   for a in range (0,n): 
      for b in range (0,n):
         for c in range (0,n):
            if (6*a) + (9*b) + (20*c) == n:
               print a, "x6pcks + ",b,"x9pcks+ ",c, "x20pcks = ", n, "nuggets."
            c = c + 1
         b = b + 1
      a = a + 1
      
combos (12)

# Prob 2
#Magic

# Prob 3

answer=[]
n_counter=0
n=0
for n in range(1, 200):
    ans=False
    for a in range(0,n/6+1):
        for b in range(0,n/9+1):
            for c in range(0,n/20+1):
                if (6*a)+(9*b)+(20*c)==n:
                    ans = True
    if ans:
        n_counter+=1
        if n_counter==6:
            print 'the largest impossible quantity of nuggets is: ',  answer[-1]
    else:
        answer.append(n)
        n_counter = 0


# Prob 4
packages=(6, 9, 20)
answer=0

for n in range(1, 200):
    ans=False
    for a in range(0,n/6+1):
        for b in range(0,n/9+1):
            for c in range(0,n/20+1):
                if (packages[0]*a)+(packages[1]*b)+(packages[2]*c)==n:
                    ans=True
    if (ans==False):
        if (n>answer): answer=n
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(answer)

vbakhtyr 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1
##Problem 1a

prime_counter=1  #How many prime numbers have been found, up to 1000
test_number=3  #Starting prime number
while (prime_counter<1000): #until prime_counter reaches 1000
    divisor=test_number/2 #divisor is test_number divided by 2
    while (divisor>1): #Do until divisor reaches 1
        if test_number%divisor==0: #if remainder of test_number divided by the divisor is 0
            test_number=test_number+2 #increase test_number by 2
            divisor=test_number/2 #redefine divisor to reflect new test_number
        else: divisor=divisor-1 #otherwise decrese divisor by 1
    prime_counter=prime_counter+1 #add another prime to the prime_counter, so at 5 prime_counter = 2
    test_number=test_number+2 #increase test_number by 2
print test_number-2 #print the last working test_number

##Problem 1b
import math

prime=3
counter=1
n=int(raw_input("enter n"))
sumoflogs=math.log(2)
while prime<n:
    divisor=3
    while (divisor<math.sqrt(prime) and prime%divisor <> 0):
        divisor=divisor+2
    if divisor > math.sqrt(prime):
            sumoflogs = sumoflogs + math.log(prime)
    prime=prime+2
print sumoflogs
print prime
ratio=sumoflogs/prime
print ratio

vbakhtyr 1 year ago
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 1, HW 1
last_name = raw_input('What is your last name?')
first_name = raw_input('What is your first name?')
print last_name
print first_name

vbakhtyr 1 year ago