用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/Objective-Arts/lens-dist --skill algorithms命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | algorithms |
| description | Literate programming |
| allowed-tools | [] |
Donald Knuth's core belief: Programs should be written for humans to read, and only incidentally for machines to execute. Code is literature. Treat it as such.
"Premature optimization is the root of all evil."
The full quote: "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%."
Don't optimize until you've measured. But when the 3% matters, optimize with precision.
Knuth invented literate programming with WEB (for Pascal) and CWEB (for C). The idea: write programs as essays that happen to be executable.
Code and documentation are not separate. They are one work, written for a human reader, that happens to also compile.
Traditional approach:
// Calculate factorial
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
Literate approach:
@ The factorial function computes $n!$, the product of all positive
integers up to $n$. We use the recursive definition: $0! = 1$, and
$n! = n \cdot (n-1)!$ for $n > 0$.
This recursive formulation directly mirrors the mathematical definition,
making correctness verification straightforward.
@<Calculate factorial@>=
int factorial(int n) {
if (n <= 1) return 1;
return n * factorial(n - 1);
}
Weaving: Extract the documentation (produces a readable document) Tangling: Extract the code (produces a compilable program)
The source is one file. Two outputs: one for humans, one for machines.
You don't need WEB/CWEB. Apply the principle:
Knuth wrote The Art of Computer Programming to bring mathematical rigor to algorithms.
Don't just know an algorithm works. Know:
For critical code, informal reasoning isn't enough:
Example:
// Precondition: arr is sorted, 0 <= lo <= hi <= len(arr)
// Postcondition: returns index of target, or -1 if not found
// Invariant: if target exists, it's in arr[lo..hi]
int binary_search(int arr[], int lo, int hi, int target) {
while (lo <= hi) {
int mid = lo + (hi - lo) / 2; // Avoids overflow
if (arr[mid] == target) return mid;
if (arr[mid] < target) lo = mid + 1;
else hi = mid - 1;
}
return -1;
}
Knuth famously offers reward checks for errors in TAOCP. Be paranoid about edge cases:
Knuth wrote TeX because existing typesetting was inadequate. Principles from TeX:
TeX development took 10 years. The result: software that's been stable for decades.
"I've spent my whole life trying to get something right. I don't want to waste time getting it almost right."
TeX versions converge to π (3.14159...). Each release adds one digit. The message: asymptotically approaching perfection, never claiming to be there.
TeX has been frozen since 1989. No new features. Bug fixes only. The lesson: done can be better than evolving.
"Beware of bugs in the above code; I have only proved it correct, not tried it."
Even Knuth acknowledges fallibility. Test even when you've proved correctness.
Before committing code, ask:
Apply these checks:
Use a different skill when:
correctness (invariants, weakest preconditions)optimization (profiling, cache behavior)design-patterns (23 classic patterns)java (Effective Java idioms)clarity (readability, naming)Knuth is the algorithmic documentation skill—use it when code should read as literature and algorithms need precise explanation.
"The best programs are written so that computing machines can perform them quickly and so that human beings can understand them clearly." — Donald Knuth