const MaxN
MaxN bounds the sieve so gas stays predictable.
Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.
Package sieve is an on-chain port of Go's classic concurrent prime sieve (the "prime sieve" example from the Go tour ...
gno.land/p/moul/x/daily/sieve/v0Sieve of Eratosthenes — PrimesUpTo, NthPrime, IsPrime, MaxN.
A deterministic, allocation-friendly port of Go's classic concurrent prime-sieve
example — no goroutines, channels, or clocks, so it runs reproducibly on-chain.
MaxN (10000) bounds the sieve so gas stays predictable.
1import "gno.land/p/moul/x/daily/sieve/v0"
2
3primes := sieve.PrimesUpTo(30) // [2 3 5 7 11 13 17 19 23 29]
4p := sieve.NthPrime(10) // 29 (1-indexed; 0 beyond MaxN)
5ok := sieve.IsPrime(9973) // true
Live demo: r/moul/x/daily/sievedemo
· render it at /r/moul/x/daily/sievedemo/v0.
Part of moul/gno-contracts — moul's versioned gno.land contracts. See the repository for the full catalog, build/test tooling, and usage.
🧪 Highly experimental — potentially vibe-coded. Not audited; may break, change, or be removed at any time. Do not use with anything of value. Full disclaimer: DISCLAIMER.
Package sieve is an on-chain port of Go's classic concurrent prime sieve (the "prime sieve" example from the Go tour / Go source docs), implemented as a deterministic, allocation-friendly Sieve of Eratosthenes so it runs reproducibly on-chain (no goroutines, channels, or clocks) — as a reusable pure package.
A live demo of this package (a gnoweb prime explorer) is at r/moul/x/daily/sievedemo(/r/moul/x/daily/sievedemo/v0).
IsPrime reports whether x is prime (trial division). Pure.
NthPrime returns the k-th prime (1-indexed), or 0 if it lies beyond MaxN. Pure helper handy for callers and tests.
PrimesUpTo returns every prime p with 2 <= p <= n, in ascending order, using the Sieve of Eratosthenes. n is clamped to [0, MaxN]. Pure.
Imports nothing.