Sha256: 08dfcb7a7b4fc7001a2a616f213c300d6c014c5337ebec1251f24de939ac261f

Contents?: true

Size: 387 Bytes

Versions: 219

Compression:

Stored size: 387 Bytes

Contents

package prime

func Nth(n int) (p int, ok bool) {
	switch {
	case n < 1:
		return 0, false
	case n == 1:
		return 2, true
	}
	n--
	p = 3
	inc := 1
	sqr := 1
	sqrt := 1
	for {
		for f := 3; ; f += 2 {
			if f > sqrt {
				n--
				if n == 0 {
					return p, true
				}
				break
			}
			if p%f == 0 {
				break
			}
		}
		p += 2
		if p > sqr {
			inc += 2
			sqr += inc
			sqrt++
		}
	}
}

Version data entries

219 entries across 219 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.158 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.157 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.156 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.155 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.154 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.153 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.152 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.151 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.150 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.149 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.148 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.147 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.146 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.145 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.144 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.143 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.142 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.141 tracks/go/exercises/nth-prime/example.go
trackler-2.2.1.140 tracks/go/exercises/nth-prime/example.go