/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]>
95 lines
2.2 KiB
Vue
95 lines
2.2 KiB
Vue
<script setup>
|
|
/**
|
|
* A file with line numbers, highlighting and a copy button.
|
|
*/
|
|
import { computed, ref } from "vue";
|
|
import { highlight } from "@/highlight";
|
|
|
|
const props = defineProps({
|
|
content: { type: String, required: true },
|
|
lang: { type: String, default: "" },
|
|
truncated: { type: Boolean, default: false },
|
|
});
|
|
|
|
const html = computed(() => highlight(props.content.replace(/\n$/, ""), props.lang));
|
|
const lines = computed(() => props.content.replace(/\n$/, "").split("\n").length);
|
|
|
|
const copied = ref(false);
|
|
async function copy() {
|
|
try {
|
|
await navigator.clipboard.writeText(props.content);
|
|
copied.value = true;
|
|
setTimeout(() => (copied.value = false), 1500);
|
|
} catch {
|
|
// Clipboard access refused (insecure context or permissions): nothing to do.
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="code">
|
|
<button class="copy" type="button" @click="copy">{{ copied ? "Copied" : "Copy" }}</button>
|
|
<div class="scroll">
|
|
<pre class="gutter" aria-hidden="true">{{ Array.from({ length: lines }, (_, i) => i + 1).join("\n") }}</pre>
|
|
<pre class="hljs src"><code v-html="html"></code></pre>
|
|
</div>
|
|
<p v-if="truncated" class="cut muted">Cut short: the file is larger than the site shows.</p>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.code {
|
|
position: relative;
|
|
background: var(--color-paper);
|
|
border: 1px solid var(--color-line-soft);
|
|
border-radius: 6px;
|
|
}
|
|
.scroll {
|
|
display: flex;
|
|
overflow-x: auto;
|
|
font-family: var(--font-mono);
|
|
font-size: 0.8125rem;
|
|
line-height: 1.55;
|
|
}
|
|
pre {
|
|
margin: 0;
|
|
padding: 12px 0;
|
|
font-family: inherit;
|
|
}
|
|
.gutter {
|
|
padding: 12px 10px 12px 12px;
|
|
text-align: right;
|
|
color: var(--color-ink-faint);
|
|
user-select: none;
|
|
border-right: 1px solid var(--color-line-soft);
|
|
position: sticky;
|
|
left: 0;
|
|
background: var(--color-paper);
|
|
}
|
|
.src {
|
|
padding-left: 12px;
|
|
padding-right: 64px;
|
|
}
|
|
.copy {
|
|
position: absolute;
|
|
top: 8px;
|
|
right: 8px;
|
|
z-index: 1;
|
|
padding: 2px 10px;
|
|
font-size: 0.75rem;
|
|
border: 1px solid var(--color-line);
|
|
border-radius: 4px;
|
|
background: var(--color-paper);
|
|
color: var(--color-ink-muted);
|
|
cursor: pointer;
|
|
}
|
|
.copy:hover {
|
|
color: var(--color-ink);
|
|
}
|
|
.cut {
|
|
padding: 6px 12px;
|
|
font-size: 0.8rem;
|
|
border-top: 1px solid var(--color-line-soft);
|
|
}
|
|
</style>
|