Transaction
DE1640082EE3FD…73191BAE521A
Block 25,953 · index 0 · indexed
Summary
- Hash
- DE1640082EE3FD8CD4A08AA0D4C811A87E805B0B93E49961314F73191BAE521A
- Block
- 25,953
- Size
- 3369 bytes
- Gas used
- 7,826,662 / 9,392,054
- Fee
- 1000000ugnot
- Memo
- gnopublish
- Status
- success
Messages
Arguments · 9
- #1sieve
- #2README.md
- #3# `gno.land/p/moul/x/daily/sieve/v0` **Sieve 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. ```go import "gno.land/p/moul/x/daily/sieve/v0" primes := sieve.PrimesUpTo(30) // [2 3 5 7 11 13 17 19 23 29] p := sieve.NthPrime(10) // 29 (1-indexed; 0 beyond MaxN) ok := sieve.IsPrime(9973) // true ``` **Live demo:** [`r/moul/x/daily/sievedemo`](https://github.com/moul/gno-contracts/tree/main/r/moul/x/daily/sievedemo/v0) · render it at [`/r/moul/x/daily/sievedemo/v0`](https://gno.land/r/moul/x/daily/sievedemo/v0). <!-- BEGIN GNOCONTRACTS FOOTER (generated by `make readmes`; do not edit below) --> --- Part of **[moul/gno-contracts](https://github.com/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](https://github.com/moul/gno-contracts/blob/main/DISCLAIMER.md). <!-- END GNOCONTRACTS FOOTER -->
- #4gnomod.toml
- #5module = "gno.land/p/moul/x/daily/sieve/v0" gno = "0.9"
- #6sieve.gno
- #7// 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). package sieve // MaxN bounds the sieve so gas stays predictable. const MaxN = 10000 // 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 PrimesUpTo(n int) []int { if n < 2 { return []int{} } if n > MaxN { n = MaxN } // composite[i] == true once i is known to be non-prime. composite := make([]bool, n+1) for p := 2; p*p <= n; p++ { if composite[p] { continue } for m := p * p; m <= n; m += p { composite[m] = true } } primes := []int{} for i := 2; i <= n; i++ { if !composite[i] { primes = append(primes, i) } } return primes } // NthPrime returns the k-th prime (1-indexed), or 0 if it lies beyond MaxN. // Pure helper handy for callers and tests. func NthPrime(k int) int { if k < 1 { return 0 } primes := PrimesUpTo(MaxN) if k > len(primes) { return 0 } return primes[k-1] } // IsPrime reports whether x is prime (trial division). Pure. func IsPrime(x int) bool { if x < 2 { return false } for d := 2; d*d <= x; d++ { if x%d == 0 { return false } } return true }
- #8/gno.MemPackageType
- #9 MPUserProd
Result log
msg:0,success:true,log:,events:[]