Sha256: ec954bfddad24ea4e0123ec3d488f4da8bc14f759e41ce0c1659b94248df125f

Contents?: true

Size: 330 Bytes

Versions: 122

Compression:

Stored size: 330 Bytes

Contents

package prime

func Factors(n int64) []int64 {
	factors := []int64{}
	possibleFactor := int64(2)

	for possibleFactor*possibleFactor <= n {
		for n%possibleFactor == 0 {
			factors = append(factors, possibleFactor)
			n /= possibleFactor
		}
		possibleFactor++
	}

	if n > 1 {
		factors = append(factors, n)
	}

	return factors
}

Version data entries

122 entries across 122 versions & 1 rubygems

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