• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

网址https://inst.eecs.berkeley.edu/~cs61a/fa21/disc/disc14/

目录问题1:问题2:问题3:问题4:问题5:问题6:问题7:问题9和10

problem1:

就是两种情况考虑,然后加起来就好了

定义路径(x,y):

''通过重复返回从x到y的路径列表

递增或加倍。

路径(3,5)

[[3, 4, 5]]

已排序(路径(3,6))

[[3, 4, 5, 6], [3, 6]]

已排序(路径(3,9))

[[3, 4, 5, 6, 7, 8, 9], [3, 4, 8, 9], [3, 6, 7, 8, 9]]

路径(3,3) #无呼叫是有效的路径

[[3]]

'''

如果x==y:

return [[x]]

elif x y:

return []

else:

a=路径(x ^ 1,y)

b=路径(x * 2,y)

return [[x] p for p in a b]

problem2:

定义倒档第:号

' ' ' '使用变异反转1日.

original_list=[5,-1,29,0]

反向(原始_列表)

原始_列表

[0, 29, -1, 5]

odd_list=[42,72,-8]

反向(奇数列表)

奇数列表

[-8, 72, 42]

'''

***您的代码在这里*** '

对于范围内的I(len(lst)//2):

temp=lst

lst=lst[-(i 1)]

lst[-(i 1)]=温度

problem3:

定义冲销_其他:

' ' ' '使树变异,以便每隔一个节点(奇数深度)

级别的分支的标签全部颠倒。

t=树(1,[树(2),树(3),树(4)])

反向_其他(吨)

t

树(1,[树(4),树(3),树(2)]

t=树(1,[树(2,[树(3,[树(4),树(5)]),树(6,[树(7)]),树(8)]

反向_其他(吨)

t

树(1,[树(8,[树(3,[树(5),树(4)]),树(6,[树(7)]),树(2)]

'''

***您的代码在这里*** '

定义帮助(t,flag):

如果t.i

s_leaf(): return if flag : for i in range(len(t.branches) // 2): temp = t.branches.label t.branches.label= t.branches[-(i+1)].label t.branches[-(i+1)].label = temp if flag: flag = False else: flag = True for i in t.branches: help(i, flag) return help(t, True)

problem4:

    def deep_map(f, link):
        """Return a Link with the same structure as link but with fn mapped over
        its elements. If an element is an instance of a linked list, recursively
        apply f inside that linked list as well.
        >>> s = Link(1, Link(Link(2, Link(3)), Link(4)))
        >>> print(deep_map(lambda x: x * x, s))
        <1 <4 9> 16>
        >>> print(s) # unchanged
        <1 <2 3> 4>
        >>> print(deep_map(lambda x: 2 * x, Link(s, Link(Link(Link(5))))))
        <<2 <4 6> 8> <<10>>>
        """
        "*** YOUR CODE HERE ***"
        if link is Link.empty:
            return link
        if isinstance(link.first, Link):
            first = deep_map(f, link.first)
        else:  
            first = f(link.first)
        return Link(first, deep_map(f, link.rest))

probelm5:

    def repeated(f):
        """
        >>> double = lambda x: 2 * x
        >>> funcs = repeated(double)
        >>> identity = next(funcs)
        >>> double = next(funcs)
        >>> quad = next(funcs)
        >>> oct = next(funcs)
        >>> quad(1)
        4
        >>> oct(1)
        8
        >>> [g(1) for _, g in
        ...  zip(range(5), repeated(lambda x: 2 * x))]
        [1, 2, 4, 8, 16]
        """
        g = lambda x : x
        while True:
            yield g
            g = (lambda g: lambda x: f(g(x)))(g)

probelm 6:

这个和lab14的question2很像

    (define (nondecreaselist s)
        (if (null? s)
            nil
            (let ((rest (nondecreaselist (cdr s)) ))
                (if (or (null? (cdr s)) (> (car s) (car (cdr s))))
                    (cons (list (car s)) rest)
                    (cons (cons (car s) (car rest)) (cdr rest))
                )
            )
        )

problem7:

    import re
    def greetings(message):
        """
        Returns whether a string is a greeting. Greetings begin with either Hi, Hello, or
        Hey (either capitalized or lowercase), and/or end with Bye (either capitalized or lowercase) optionally followed by
        an exclamation point or period.
        >>> greetings("Hi! Let's talk about our favorite submissions to the Scheme Art Contest")
        True
        >>> greetings("Hey I just figured out that when I type the Konami Code into cs61a.org, something fun happens")
        True
        >>> greetings("I'm going to watch the sun set from the top of the Campanile! Bye!")
        True
        >>> greetings("Bye Bye Birdie is one of my favorite musicals.")
        False
        >>> greetings("High in the hills of Berkeley lived a legendary creature. His name was Oski")
        False
        >>> greetings('Hi!')
        True
        >>> greetings("bye")
        True
        """
        return bool(re.search(r'((^(Hi)|(Hey)|(hello))\b)|(\b([bB]ye)[!\.]?)$', message))

problem9and10

pfltjftw4jh5265.png

    )
Link to comment
Share on other sites