| name | sieve |
| description | Demonstrates cyclic skill invocation — runs the Sieve of Eratosthenes by invoking a private "strike" subskill once per prime, re-rendering a visual grid after each pass. Takes an upper limit n. Use to show one skill invoking another skill N times in a loop. |
| argument-hint | [n] |
Sieve of Eratosthenes (demo) — cyclic skill invocation
This skill demonstrates cyclic invocation: a controller skill that invokes a
subskill N times in a loop, where N depends on the input. It runs the Sieve of
Eratosthenes over the numbers 2..n and shows the grid after every pass.
It uses two private subskills (user-invocable: false):
sieve-strike — strikes out the multiples of one prime p
sieve-render — draws the current grid (remaining primes vs. struck numbers)
You are the controller. You repeatedly pick the next prime and invoke
sieve-strike for it — that is the loop. State lives in sieve.state so the
subskills share it between calls.
What to do
-
Parse n from the argument: n = $1. If absent, use n = 30. Require an
integer n ≥ 2; otherwise ask the user for a valid limit and stop.
-
Initialize sieve.state in the current directory, overwriting it, with a
single header line:
n=<n>
-
Invoke sieve-render once to show the starting grid (every number from
2..n is still a candidate).
-
Loop — this is the cyclic invocation:
a. Read sieve.state. Build the struck set = the union of every number on
the right-hand side of all strike p=... -> ... lines.
b. The unmarked numbers are 2..n minus the struck set.
c. Choose the next pivot p = the smallest unmarked number that is greater
than the previous pivot (start from 1) and satisfies p*p ≤ n.
d. If no such p exists, exit the loop.
e. Invoke sieve-strike, passing p as its argument.
f. Invoke sieve-render to show the grid after this pass.
g. Repeat from (a).
-
When the loop ends, every remaining unmarked number is prime. Invoke
sieve-render one final time, then report to the user:
- the list of primes
≤ n,
- how many strike passes ran (the number of times you invoked
sieve-strike).
Do not strike or render the grid yourself — always go through the subskills.
That is the point of the demo: the controller only orchestrates the loop.