Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

v0 source pure

Package sieve is an on-chain port of Go's classic concurrent prime sieve (the "prime sieve" example from the Go tour ...

Readme View source

gno.land/p/moul/x/daily/sieve/v0

Sieve of EratosthenesPrimesUpTo, 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.

Overview

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).

Constants 1

const MaxN

1const MaxN = 10000
source

MaxN bounds the sieve so gas stays predictable.

Functions 3

func IsPrime

1func IsPrime(x int) bool
source

IsPrime reports whether x is prime (trial division). Pure.

func NthPrime

1func NthPrime(k int) int
source

NthPrime returns the k-th prime (1-indexed), or 0 if it lies beyond MaxN. Pure helper handy for callers and tests.

func PrimesUpTo

1func PrimesUpTo(n int) []int
source

PrimesUpTo returns every prime p with 2 <= p <= n, in ascending order, using the Sieve of Eratosthenes. n is clamped to [0, MaxN]. Pure.

Source Files 3