/usaco/concepts is a library of techniques Claude explained: the admin
asks by topic ("help explain fenwick trees") or pastes code they could
not follow, and gets an intuitive explanation with SVG diagrams plus a
C++ snippet in contest style. Given code, the walkthrough traces that
code and the snippet is a general version of it. Anyone can read the
library; generating, rewriting and deleting are admin-only.
Each concept is committed as concepts/<slug>/: concept.md (tags in a
header comment, then a # title), snippet.cpp (first line
"// concept: <slug>") and request.md (the question, for rewrites). The
slug is Claude's to pick, so a new concept's job is keyed by an id and
returns {slug} as its result; a taken slug gets -2, -3... rather than
overwriting. Rewriting starts from the saved question and version plus
a note on what to change. The index reads concepts into Index.Concepts,
with their date from git.
internal/concept shares explain's math and diagram rules, now split out
as explain.MathRules and explain.DiagramRules; the explain prompt is
byte-for-byte unchanged. Code fences in explanations are highlighted
with the same highlight.js setup as CodeBlock (web/src/highlight.js).
`usaco snippet` lists concepts, prints one's snippet, or pastes it into
a solution above main (or class Solution), keeping a .bak and refusing
a concept the file already has. In interactive mode it pastes into the
selection.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
105 lines
5.6 KiB
Bash
Executable File
105 lines
5.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# usaco - manage USACO problems
|
|
# Usage:
|
|
# usaco i Interactive mode: holds a current problem so commands
|
|
# drop the name (aliases: interactive, repl)
|
|
# s <name> select a problem (bare name works too)
|
|
# s show the current problem
|
|
# none clear the selection
|
|
# r / t / e act on the current problem
|
|
# !cmd run a shell command in the problem dir
|
|
# q quit
|
|
# usaco new <name> [io-name] [--url <link>] [--rust|--cpp]
|
|
# Create solving/<name> from template.cpp or template.rs
|
|
# (io-name sets the file-io name, defaults to <name>;
|
|
# language defaults to 'usaco lang', see below)
|
|
# usaco new <leetcode-url> Import a LeetCode problem (alias: from): statement in
|
|
# problem.md, C++ starter + generated driver.h, the examples
|
|
# as tests/ with expected outputs
|
|
# usaco daily Same, for today's LeetCode daily question
|
|
# usaco lang [cpp|rust] Show or set the default language for 'usaco new'
|
|
# ($USACO_LANG wins for a single shell)
|
|
# usaco run <name> Build the solution and run it (in the problem dir)
|
|
# usaco build <name> Build only
|
|
# usaco done <name> Move solving/<name> -> solved/<name> and git commit
|
|
# usaco undo <name> Move solved/ or skipped/<name> -> solving/<name>
|
|
# usaco skip <name> Move solving/<name> -> skipped/<name>
|
|
# usaco io <name> [io-name] Show the problem's io name, or set it: renames <old>.in/.out
|
|
# and rewires STDIO("...") / stdio("...") in the source
|
|
# usaco cat <name> Print the problem's solution to stdout (pipeable)
|
|
# usaco copy <name> Copy the problem's solution to the clipboard (alias: cp)
|
|
# usaco snippet [concept] [name]
|
|
# List the concepts the website explained; with a concept, print
|
|
# its C++ snippet; with a problem too, paste it into the
|
|
# problem's main.cpp above main (old one saved as .bak)
|
|
# usaco vim <name> Open the problem's solution in $EDITOR (aliases: edit, e)
|
|
# usaco open <name> Open the problem's saved URL in a browser
|
|
# usaco list List problems by status
|
|
# usaco stats Show solve counts and recent activity
|
|
# usaco path <name> Print the problem's directory (used by the ucd shell helper)
|
|
# usaco clean Delete compiled binaries and backups from all problem dirs
|
|
# usaco sync git pull --rebase (picks up edits made on the website), then push
|
|
# usaco lint [name...] Run clippy over the rust solutions (all of them, or just the
|
|
# named ones; "template" lints template.rs) and refresh the
|
|
# Cargo.toml rust-analyzer reads
|
|
# usaco reset <name> [lang] [-y]
|
|
# Reset the solution: fresh source from template (io wired up,
|
|
# old one saved as .bak), delete binary + .out; keeps tests/ and
|
|
# .in. cpp/rust switches the problem's language. Asks first
|
|
# unless -y (aliases: rm, delete, template, tpl)
|
|
# usaco test create <name> Save a test case: uses the current .in (or lets you paste one),
|
|
# then asks for the expected output. Stored in tests/N.in + N.out
|
|
# usaco test <name> [nums...] Build and run every saved test case (or just the given ones),
|
|
# diff against expected output, show pass/fail
|
|
#
|
|
# Short aliases: n=new r=run b=build t=test d=done u=undo sk=skip o=open
|
|
# l/ls=list st=stats p=path e=edit=vim sy=sync sn=snippet
|
|
#
|
|
# Names may be unique prefixes: 'usaco e diam' finds diamond-collector.
|
|
# run/build/test take --debug: build with sanitizers (-fsanitize=address,undefined).
|
|
#
|
|
# Implementation: each command lives in lib/cmd/<name>.sh; shared helpers in lib/common.sh.
|
|
|
|
set -euo pipefail
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
usage() { awk 'NR>1 { if (!/^#/) exit; sub(/^# ?/,""); print }' "$0"; exit 1; }
|
|
|
|
cmd="${1:-}"; shift || true
|
|
case "$cmd" in
|
|
interactive|i|repl) cmd=interactive ;;
|
|
new|n|from) cmd=new ;;
|
|
daily) cmd=new; set -- daily "$@" ;;
|
|
run|r) cmd=run ;;
|
|
build|b) cmd=build ;;
|
|
test|t) cmd=test ;;
|
|
done|d) cmd=done ;;
|
|
undo|u) cmd=undo ;;
|
|
skip|sk) cmd=skip ;;
|
|
io) cmd=io ;;
|
|
cat) cmd=cat ;;
|
|
copy|cp) cmd=copy ;;
|
|
snippet|sn) cmd=snippet ;;
|
|
vim|edit|e) cmd=edit ;;
|
|
open|o) cmd=open ;;
|
|
list|l|ls) cmd=list ;;
|
|
stats|st) cmd=stats ;;
|
|
path|p) cmd=path ;;
|
|
clean) cmd=clean ;;
|
|
sync|sy) cmd=sync ;;
|
|
lang) cmd=lang ;;
|
|
lint) cmd=lint ;;
|
|
reset|rm|delete|template|tpl) cmd=reset ;;
|
|
*) usage ;;
|
|
esac
|
|
|
|
# --debug may appear anywhere in the arguments
|
|
args=()
|
|
for a in "$@"; do
|
|
if [[ "$a" == --debug ]]; then export USACO_DEBUG=1; else args+=("$a"); fi
|
|
done
|
|
set -- "${args[@]+"${args[@]}"}"
|
|
|
|
source "$ROOT/lib/common.sh"
|
|
source "$ROOT/lib/cmd/$cmd.sh"
|