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

sieve source realm

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

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

Constants 1

const MaxN

1const MaxN = 10000
source

MaxN bounds the sieve so gas stays predictable.

Functions 4

func IsPrime

Action
1func IsPrime(x int) bool
source

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

func NthPrime

Action
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

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

func Render

1func Render(path string) string
source

Render renders the sieve for gnoweb.

Example
1Render("")      / Render("/") -> first 100 primes + total count up to MaxN
2Render("/<n>")               -> every prime <= n, laid out as a grid

Imports 2

  • strconv stdlib
  • strings stdlib

Source Files 2