lemmaly
它能做什么
Lemmaly 是一个帮助你在动手写代码之前,先想清楚代码效率的工具。它会要求你在开始编程前,先明确复杂度(代码运行得有多快)、数据结构(数据如何组织)以及算法类型(所采用的解题策略)。
适用场景
- ✓在编写涉及列表、搜索或重复操作的新代码时。
- ✓在审查看起来运行缓慢或效率低下的代码时。
- ✓当你不确定该如何组织数据和选择算法时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/lemmaly/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我需要写一个函数,在一个包含 100 万个数字的列表中找出出现次数最多的元素。在开始之前,我应该使用什么复杂度、数据结构和算法?”
每周 5 个新技能,1 分钟读完。
工作原理
Lemmaly 的工作方式是要求你先写明时间和空间复杂度、选定的数据结构及其理由,以及所属的算法家族。这样可以强制你提前分析,避免写出低效的方案。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
lemmaly — Algorithm-First Proof
The model already knows Big-O, hash tables, divide-and-conquer, dynamic programming, sorting, graph algorithms, and amortized analysis. It just does not apply them spontaneously. lemmaly fixes the behavior, not the knowledge.
This skill is the gateway for an algorithm-discipline suite of four skills (lemmaly, mathguard, invariant-guard, complexity-cuts). It enforces the hard rules that every other guard in the suite assumes.
Violating the letter of these rules is violating the spirit of the skill. "Just this once" is how O(n²) ships to production.
When to Use This Skill
Use lemmaly when:
- Writing, editing, or reviewing code that involves loops, collections, lookups, searches, joins, recursion, graphs, queries, or any computation over more than a handful of items.
- About to write a
forinside afor,.find/.includes/.indexOfinside a loop,awaitinsidefor/map/forEachover independent items, or one query per item in a collection. - Auditing a codebase / PR for known anti-patterns (await-in-loop,
.includesinside.filter, string-concat in loop,SELECT *, N+1, etc.). - Reviewing AI-generated code that "looks idiomatic" but might hide O(n²) or N+1.
When in doubt, start at lemmaly — it is the gateway and will tell you when to escalate to its three sibling skills.
| If you are about to… | Use | Why |
|---|---|---|
| Write new code that loops, queries, joins, recurses, or processes a collection | lemmaly | Forces complexity + data structure + algorithm family before code is written. |
| Refactor existing code that is already slow, OOMs, times out, or has nested loops / N+1 / repeated work | complexity-cuts | Corrective playbook for code that already shipped with bad Big-O. |
| Implement an algorithm where the obvious version is subtly wrong (binary search variants, in-place dedup, Boyer–Moore, QuickSelect partition, recursion with accumulators, fixed-point / termination concerns) | invariant-guard | Forces writing the function contract + loop invariant before code. The trap is in the contract, not the loop body. |
| Work with n ≥ 10⁶, similarity search, dedup at scale, top-K, streaming analytics, cardinality estimation, embeddings, FFT/NTT, dimensionality reduction, computational geometry, randomized algorithms | mathguard | Classical algorithms have hit their lower bound; an approximate or math-heavy technique (Bloom, HLL, Count-Min, MinHash/LSH, FFT, JL projection, sweep line, kd-tree) gives the asymptotic win. |
Routing flow
Are you writing new code?
├── yes → lemmaly (state complexity, structure, family BEFORE coding)
│ ├── classical algorithm at its lower bound AND n is large? → mathguard
│ └── subtle correctness trap (invariant, base case, off-by-one)? → invariant-guard
└── no, refactoring existing slow / OOM / timed-out code → complexity-cuts
└── still slow after classical fixes? → mathguard
One-line mental model
- lemmaly = think first (prevention).
- complexity-cuts = clean up bad Big-O (correction).
- invariant-guard = prove it's correct (verification).
- mathguard = beat the classical floor (acceleration).
The Iron Law
NO NON-TRIVIAL CODE WITHOUT STATED COMPLEXITY, DATA STRUCTURE, AND ALGORITHM FAMILY
Before you write a loop, a recursion, a query, or any computation over more than a handful of items, three things must appear in your message — in this order:
time = O(?),space = O(?), with the dominant input dimension named.- The data structure you will use, with a one-phrase reason.
- The algorithm family (one of: linear scan, two-pointer, sliding window, binary search, sort+sweep, hash join, BFS/DFS, topo sort, Dijkstra/A*, union-find, DP, greedy, recursion+memo, prefix sum, segment tree, monoid reduction).
If you cannot state all three, you do not understand the problem yet. Ask, or read more code. Do not write code.
Non-negotiable rules
- State complexity before writing any non-trivial code. In one line:
time = O(?),space = O(?)- Dominant input dimension:
n = what, with realistic magnitude (e.g.n ~ 10^6 rows) - If you cannot state these, you do not yet understand the problem. Ask, or read more code.
…
常见问题
什么是“Big-O”?
Big-O(也叫复杂度)用来描述随着输入数据规模增长,算法运行速度会如何变化。例如,O(n) 表示运行时间与数据规模呈线性增长。
为什么要先确定数据结构?
数据结构(比如列表、映射或集合)的选择会直接影响效率。提前确定它,有助于你为任务选对工具,比如用映射来实现快速查找。
什么是“算法家族”?
这是解决问题的策略大类,比如二分查找、排序或动态规划。识别算法家族,有助于你联想到已知的高效解法。
详情
作者的原始描述
Algorithm-first discipline: state Big-O, data structure, and algorithm family BEFORE writing loops, queries, or recursion. Catches O(n^2), N+1, and brute-force defaults.
热度
- GitHub 星标
- 48k
- 排名
- #5047
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。