Week 1¶
约 777 个字 11 行代码 3 张图片 预计阅读时间 3 分钟
Summary¶
大致需要3.5h完成
- 建议先看Videos再看Reading,这样对Reading的内容有一个粗略的把握看书会更快
- 一定要写Lab和HW
- 可以先写Lab 00再写HW01
Disc 00(5min)¶
- Part 0 没有Group pass
- Part 1 没有Discord账号 pass
- Part 2 破冰小游戏 pass
- Part 3 唯一的问题(30 min)
Imagine you can call only the following three functions: - f(x): Subtracts one from an integer x - g(x): Doubles an integer x - h(x, y): Concatenates the digits of two different positive integers x and y. For example, h(789, 12) evaluates to 78912 and h(12, 789) evaluates to 12789.
Definition: A small expression is a call expression that contains only f, g, h, the number 5, and parentheses. All of these can be repeated. For example, h(g(5), f(f(5))) is a small expression that evaluates to 103.
Q:What’s the shortest small expression you can find that evaluates to 2024?
A:h(g(g(5)),g(g(g(f(f(5))))))?
- Part 4 拍合照/考勤/讨论Part 3的计算机实现
Reading(2h)¶
Chapter 1: Building Abstractions with Functions
- 1.1 Getting Started
- 1.2 Elements of Programming
- 1.3 Defining New Functions
Ch. 1.1¶
Computers are very powerful, looking at volumes of data very quickly. Computers can perform billions of operations per second, where each operation is pretty simple.
Computers are also shockingly stupid and fragile. The operations that they can do are extremely rigid, simple, and mechanical. The computer lacks anything like real insight ... it's nothing like the HAL 9000 from the movies. If nothing else, you should not be intimidated by the computer as if it's some sort of brain. It's very mechanical underneath it all.
Programming is about a person using their real insight to build something useful, constructed out of these teeny, simple little operations that the computer can do.
Ch. 1.2¶
As videos and some addition
The possibility of binding names to values and later retrieving those values by name means that the interpreter must maintain some sort of memory that keeps track of the names, values, and bindings. This memory is called an environment.
pure function:
Pure functions have the property that applying them has no effects beyond returning a value. Moreover, a pure function must always return the same value when called twice with the same arguments.
Non-pure function:
In addition to returning a value, applying a non-pure function can generate side effects, which make some change to the state of the interpreter or computer. A common side effect is to generate additional output beyond the return value, using the print function.
Remark: The value that print returns is always None, a special Python value that represents nothing. The interactive Python interpreter does not automatically print the value None. In the case of print, the function itself is printing output as a side effect of being called.
Ch. 1.3¶
Defining New Functions
Function Signatures. Functions differ in the number of arguments that they are allowed to take. A description of the formal parameters of a function is called the function's signature.
Videos(1h)¶
Functions¶
Call expression¶
- expresstion tree
- recursion
Names, Assignment, and User-Defined Functions¶
Discussion Qustion 1
Answer: 3
Environment Diagrams¶
给出了Environment Diagrams的概念,目前粗略感觉就是一个简单的可视化过程(类似单纯形表的东西)
Defining Functions¶
assignment is binding name to values and function can be more powerful to bind names to expressions.
Execution procedure for def statements:
- create a function with signature
- set the body
- bind name to that function in the current frame
Print and None¶
Interesting case
- Pure function
- Non-pure function
Lab 00(10min)¶
纪念一下第一次使用ok的Lab
HW01(15min)¶
还是比较简单的,比较有趣的是Q4是冰雹猜想,不过确实也是很多OJ上的老题了
Remark:
+ Q1注意返回的是f(a,b)
,所以你需要输入的是函数
+ Q4冰雹猜想需要注意初始的数和迭代后的1也都需要print
+ 61A的AIdebug真的好玩,玩过头了