Blacad Docs
L10 1
正在初始化搜索引擎
    Blacad/blog
    • 首页
    • CS
    Blacad/blog
    • 首页
      • CS61A
        • L1 Welcome
        • L2 Functions
        • L3 Control
        • L4 Higher Order Function
        • L5 Environments
        • L6 Sounds
        • L7 Function Abstract
        • L8 Function Example
        • L9 Recursion
        • L10 Tree Recursion
        • L11 Sequences
        • L12 Containers
        • L13 Data Abstraction
        • L14 Trees
        • L15 Mutability
        • L16 Iterators
        • L17 Generators
        • L18 Objects
        • L19 Class Attributes
        • L20 Inheritance
        • L21 Representations
        • L22 Composition
        • L23 Efficiency
        • L24 Decomposition
        • L25 Data Example
        • L28 Scheme
        • L29 Scheme Lists
        • L30 Calculator
        • L31 Interpreters
        • L32 Tail Calls
        • L33 Programs as Data
        • L34 Macros
        • L35 SQL
        • L36 Tables
        • L37 Aggregation
        • L38 Database
        • L39 思考解决问题
        • Hog
        • Cats
        • Ants
        • Scheme
        • Note
      • CS70
        • Note10 Counting
        • Note11 Countability
        • Note12 Computability
        • Note13 Discrete Probability
        • Note14 Conditional Probability
        • Note15 RV
        • Note16 RV
        • Note17 Concentration Inequalities and the Laws of Large Numbers
        • Note18 Hashing and Load Balance
        • Note19 Geometric and Poisson Distributions
        • Note20 Continuous Probability Distribution
        • Note21 Markov Chains
        • 不完备补充
        • 限与界

    L10 1

    def cascade(n):
        if n<10:
            print(n)
        else:
            print(n)
            cascade(n//10)
            print(n)
    
    def inverse_cascade(n):
        grow(n)
        print(n)
        shrink(n)
    
    def fg(f,g,n):
        if n:
            f(n)
            g(n)
    
    
    grow = lambda n: fg(grow, print, n//10)
    shrink = lambda n: fg(print,shrink, n//10)
    
    cascade(12345)
    print()
    inverse_cascade(12345)