一键导入
pass-function-as-arg
For generic algorithms: strategy pattern, callbacks, configurable behavior. Pass functions as parameters to customize algorithm behavior.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
For generic algorithms: strategy pattern, callbacks, configurable behavior. Pass functions as parameters to customize algorithm behavior.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Conducts iterative deep research on any topic using web search, progressive exploration, and structured synthesis. Use when asked for comprehensive research, deep investigation, thorough analysis, or multi-source exploration of any topic. Triggers: research, investigate, deep dive, comprehensive analysis, explore thoroughly, find everything about.
For cross-cutting concerns: add behavior without modifying functions, caching, timing, logging, validation wrappers.
For performance work: measure before changing, profile to find bottlenecks, compare before and after.
For symbolic computation: ASTs, mathematical expressions, code that manipulates code structure, expression transformations.
For ordered processing: A* search, Dijkstra, event simulation, task scheduling. Efficient min/max extraction with heap-based queue.
For dynamic programming: overlapping subproblems, recursive solutions with repeated computations, memoization to avoid redundant work.
| name | pass-function-as-arg |
| description | For generic algorithms: strategy pattern, callbacks, configurable behavior. Pass functions as parameters to customize algorithm behavior. |
Accept a function as a parameter to customize behavior.
def generic_algorithm(data, key=lambda x: x, filter_fn=lambda x: True):
"""Process data with customizable key and filter."""
filtered = [x for x in data if filter_fn(x)]
return sorted(filtered, key=key)
# Use with different strategies
result1 = generic_algorithm(items, key=lambda x: x.priority)
result2 = generic_algorithm(items, key=lambda x: -x.size, filter_fn=lambda x: x.active)
# Hill climbing with configurable objective (ngrams.py)
def hillclimb(x, objective_fn, neighbors_fn, steps=10000):
"""Search for x that maximizes objective_fn, using neighbors_fn to explore."""
best = x
best_score = objective_fn(x)
for _ in range(steps):
for neighbor in neighbors_fn(best):
score = neighbor_score = objective_fn(neighbor)
if score > best_score:
best, best_score = neighbor, score
break
return best
# Use with specific objective and neighbor functions
decoded = hillclimb(initial_guess,
objective_fn=log_probability,
neighbors_fn=swap_adjacent_chars)
# Priority queue with custom key (AdventUtils.ipynb)
class PriorityQueue:
def __init__(self, items=(), key=lambda x: x):
self.key = key
self.items = []
for item in items:
self.add(item)
def add(self, item):
heapq.heappush(self.items, (self.key(item), item))
# A* search with custom heuristic
frontier = PriorityQueue(initial_nodes, key=lambda n: n.cost + h(n))
# Tree generation with configurable pop strategy (Maze.ipynb)
def random_tree(nodes, neighbors, pop=deque.pop):
"""Pop strategy determines tree shape."""
...
current = pop(frontier) # DFS, BFS, or random based on pop function
key=lambda x: x as sensible defaultobjective_fn, neighbors_fn, key