About Me
No description provided.
Classes
|
Class status: Established
Role:
Student
|
.
17% complete
|
Submitted Assignments
 |
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 3, HW 1
MIT Lesson 3: Assignment 1
#Problem Set 2
#Name: Nick
#Time: 00:10
#Collaborators: None
#Problem 1
region = range(50, 55)
for a in range (0, 20):
for b in range(0,20):
for c in range(0,20):
k = 6 * a + 9 * b + 20 * c;
if k in region:
print("{0:2}*6 + {1}*9 + {2}*20 = {3}".format(a,b,c,k));
# 2*6 + 2*9 + 1*20 = 50
# 5*6 + 1*9 + 0*20 = 51
# 2*6 + 0*9 + 2*20 = 52
# 1*6 + 3*9 + 1*20 = 53
# 9*6 + 0*9 + 0*20 = 54
# 1*6 + 1*9 + 2*20 = 55
#Problem 2
"""
Theorem is true because when we had all x, x+1,..., x+5 all next steps will repeat.
For example if we has 54 nugets we can add 6 and get 60 or 51 + 6 =57.
This works for any x, ..., x+5 values
"""
#Problem 3
def can_buy(n, ax, bx, cx):
for a in range(0,20):
for b in range(0,20):
for c in range(0,20):
k = ax * a + bx * b + cx * c
if k == n:
return True
return False
def solve(a,b,c):
count = 0
for n in range(1,200):
if not can_buy(n,a,b,c):
ans = n
count = 0
else: count += 1
if count == 6: break
print("Given package sizes <{0}>, <{1}>, <{2}>, the largest number of McNuggets that cannot be bought in exact quantity is: {3}".format(a,b,c,ans))
solve(6,9,20)
#Problem 4
solve(10,14,15)
nick18
10 months ago
|
 |
MIT OpenCourseWare 6.00 Introduction to Computer Science and Programming: Lesson 2, HW 1
Second program for MIT course.
#Problem Set 1
#Name: Nick
#Collaborators: None
#Time: 1 day
import math
first_prime = 2
max_prime_count = 1000
count = 1
next_prime = first_prime + 1
count = count + 1
while (count < max_prime_count):
next_prime = next_prime + 2
stop_value = math.sqrt(next_prime)
is_prime = True
value = 2
while (value <= stop_value):
if (next_prime%value == 0):
is_prime = False
value = stop_value+1
else: value = value + 1
if (is_prime):
count = count + 1
#print count, ': ', next_prime
print 'The 1000th prime is ' + str(next_prime)
#2
from math import *
first_prime = 2
max_prime_count = raw_input('How many prime numbers: ')
count = 1
log_sum = log(first_prime)
next_prime = first_prime + 1
count = count + 1
log_sum = log_sum + log(next_prime)
while (count < int(max_prime_count)):
next_prime = next_prime + 2
stop_value = sqrt(next_prime)
is_prime = True
value = 2
while (value <= stop_value):
if (next_prime%value == 0):
is_prime = False
value = stop_value+1
else: value = value + 1
if (is_prime):
log_sum = log_sum + log(next_prime)
count = count + 1
ratio = next_prime/log_sum
print count, ': ', next_prime, log_sum, ratio
nick18
10 months ago
|
 |
|
|
|