Hw04 题解 (UCB CS61A@2021 Fall)


Implement the planet data abstraction by completing the planet constructor and the size selector so that a planet is represented using a two-element list where the first element is the string 'planet' and the second element is its size.

从问题的描述中我们可以知道什么是 planet. 就是一个长度为 2 的 list, 内容是 ['planet', size]. 可以参考 mobile 函数, 这两个函数的代码是很类似的

Lab05 题解 (UCB CS61A@2021 Fall)


Write factors_list, which takes a number n and returns a list of its factors in ascending order.

我们可以知道这么一个基本的数学事实: 一个数字的因子最大仅可能为它的一半(当这个数字是偶数的时候). 所以我们的 for 循环只要遍历到 n // 2 + 1 即可

How to Manage Windows Using Hammerspoon


虽然 macOS 自带窗口管理这个功能, 但是实际上是用下来发现还是很难受的. 功能不足以满足自己的需求. 所以我常常发现自己在用鼠标拖动窗口和重新调整窗口大小. 长此以往, 我觉得这样效率实在太低, 恰好前阵子在看 MIT-Missing-Semester 的课, 里面提到了 hammerspoon 这个工具. 我去稍微了解了一下发现这工具真的不错.

怎么 debug Python 代码

PS. 有兴趣的可以查看我翻译的一个项目 - pdb 教程 🙌

很长一段时间内我写代码都是用最简单的 debug 方法, 手动在程序里面插入 print 代码来看具体的变量的值, 然后自己推断程序到底是在哪里出问题。根据 print 的结果可能还要到别的地方重复这个步骤。debug 完之后还得去把这些 print 语句注释掉,即我是一名 print debugger 😢