楼主: elyn
跳转到指定楼层
上一主题 下一主题
收起左侧

跟课 CS61A FALL 2015

🔗
lyr1994 2015-12-8 13:40:15 | 只看该作者
全局:
elyn 发表于 2015-12-8 12:33
你是说什么有没有类似这样的网站来学?

那个cs61a的课程网站不是berkely自己弄的吗,有lecture、lab、HW什么的,就想类似的课程网站~
回复

使用道具 举报

🔗
 楼主| elyn 2015-12-8 14:18:06 | 只看该作者
全局:
lyr1994 发表于 2015-12-8 13:40
那个cs61a的课程网站不是berkely自己弄的吗,有lecture、lab、HW什么的,就想类似的课程网站~

http://ocw.mit.edu/courses/
回复

使用道具 举报

🔗
calbears 2015-12-12 12:49:59 | 只看该作者
全局:
cs61a.org是官方的网站
回复

使用道具 举报

🔗
 楼主| elyn 2015-12-16 23:12:38 | 只看该作者
全局:
Week 5 lab04
Question 12: Flatten
Write a function flatten that takes a (possibly deep) list and "flattens" it. For example:
>>> lst = [1, [[2], 3], 4, [5, 6]]
>>> flatten(lst)
[1, 2, 3, 4, 5, 6]
Hint: you can check if something is a list by using the built-in type function. For example,

>>> type(3) == list
False
>>> type([1, 2, 3]) == list
True

    new_lst= []
    for x in lst:
        if type(x) == list:
            new_lst += flatten(x)
        else:
            new_lst += [x]
    return new_lst


回复

使用道具 举报

🔗
 楼主| elyn 2015-12-16 23:17:50 | 只看该作者
全局:
本帖最后由 elyn 于 2015-12-16 23:19 编辑

Week 5 lab04
Question 13: Merge
Write a function merge that takes 2 sorted lists lst1 and lst2, and returns a new list that contains all the elements in the two lists in sorted order.

def merge(lst1, lst2):
    """Merges two sorted lists.

    >>> merge([1, 3, 5], [2, 4, 6])
    [1, 2, 3, 4, 5, 6]
    >>> merge([], [2, 4, 6])
    [2, 4, 6]
    >>> merge([1, 2, 3], [])
    [1, 2, 3]
    >>> merge([5, 7], [2, 4, 6])
    [2, 4, 5, 6, 7]
    """
    "*** YOUR CODE HERE ***"
iterative:
    new_lst = []
    while lst1 and lst2:
        if lst1[0] < lst2[0]:
            new_lst += [lst1[0]]
            lst1 = lst1[1:]
        else:
            new_lst += [lst2[0]]
            lst2 = lst2[1:]
    if lst1:
        return new_lst + lst1
    else:
        return new_lst + lst2


recursive:
  if not lst1 or not lst2:
        return lst1 + lst2
    elif lst1[0] < lst2[0]:
        return [lst1[0]] + merge(lst1[1:], lst2)
    else:
        return [lst2[0]] + merge(lst1, lst2[1:])
回复

使用道具 举报

🔗
 楼主| elyn 2015-12-16 23:36:23 | 只看该作者
全局:
本帖最后由 elyn 于 2015-12-17 00:14 编辑

Week 5 Tips:

1. join
print('  '.join(i for i in [1, 2, 3, 4, 5])
>>> 1 2 3 4 5
print(' + '.join(i for i in [1, 2, 3, 4, 5])
>>> 1 + 2 + 3 + 4 + 5

2.list()
不能list(int object)

3.list comprehension
video: https://www.youtube.com/watch?v= ... VLYJsBamd9hSOOSrYgB
example: [x for x in [1,2,3,4] if x > 2]
>>>[3, 4]
4.slicing
list_obj[start:end:step]
start 缺省 从0开始
end 缺省 直到最后
step缺省 默认为1
step为负 从后往前
index 为负从后往前计数

list_num[ 0, 1, 2, 3, 4, 5, 6, 7]
list_num[-1]
>>>7
list_num[2:-2]
>>>[2,3,4,5]
list_num[4:2]
>>>[]
list_num[6::-2]
>>>[6,4,2,0]

回复

使用道具 举报

🔗
 楼主| elyn 2015-12-17 17:49:05 | 只看该作者
全局:
本帖最后由 elyn 于 2015-12-17 17:57 编辑

Week 5 discussion 3

Tree:

def tree(root, branches=[]):
        for branch in branches:
                assert is_tree(branch)
        return [root] + list(branches)

def branches(tree):
        return tree[1:]

def is_tree(tree):
        if type(tree) != list or len(tree) < 1:
                return False
        for branch in branches(tree):
                if not is_tree(branch):
                        return False
        return True

def root(tree):
        return tree[0]

def is_leaf(tree):
        return not branches(tree)

def square_tree(trees):
        return tree(root(trees)**2, [square_tree(branch) for branch in branches(trees)])

def hight(trees):
        if is_leaf(trees):
                return 0
        return max([hight(branch) for branch in branches(trees)])+1
               
def tree_size(trees):
        return sum([tree_size(branch) for branch in branches(trees)]) + 1

def tree_max(trees):
        return max([root(trees)] + [tree_max(branch) for branch in branches(trees)])


def find_path(tree, value):
        if root(tree) == value:
                return [root(tree)]
        else:
                for branch in branches(tree):
                        if find_path(branch, value):
                                return [root(tree)] + find_path(branch, value)

def hailstone_tree(n, hight):
        if hight == 0:
                return tree(n)
        else:
                branches = [hailstone_tree(2*n, hight-1)]                           
//all hailstone numbers come from last number/ 2
                if (n-1) % 3 == 0 and ((n-1) // 3 )% 2 != 0 and ((n-1) // 3 ) != 1:   
                        branches += [hailstone_tree((n-1)//3, hight-1)]    // if last number comes from (a odd number * 3 +1), then there is other branch
                return tree(n, branches)

question and solution: http://cs61a.org/disc/disc03_sol.pdf
回复

使用道具 举报

🔗
 楼主| elyn 2015-12-17 23:46:12 | 只看该作者
全局:
Week 5 hw04
Q8:
Write a function polynomial that takes an interval x and a list of coefficients c, and returns the interval containing all values of f(t) for t in interval x, where:

f(t) = c[k-1] * pow(t, k-1) + c[k-2] * pow(t, k-2) + ... + c[0] * 1
Like quadratic, your polynomial function should return the smallest such interval, one that does not suffer from the multiple references problem.

Hint: You can approximate this result. Try using Newton's method.

貌似涉及很多数学知识,已忘光。。先留着以后做吧。。
回复

使用道具 举报

🔗
PeaceJoy88 2015-12-28 20:36:11 | 只看该作者
全局:
赞一下楼主,这个和15 Spring的是类似的课程内容吗?http://cs61b.ug/sp15/
回复

使用道具 举报

🔗
 楼主| elyn 2015-12-29 12:57:39 | 只看该作者
全局:
PeaceJoy88 发表于 2015-12-28 20:36
赞一下楼主,这个和15 Spring的是类似的课程内容吗?http://cs61b.ug/sp15/

有的视频是15spring有的是15fall新录的
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表