Skip to content

Commit 4bbc767

Browse files
committed
initial commit
0 parents  commit 4bbc767

5 files changed

Lines changed: 88 additions & 0 deletions

File tree

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Staff Services Software Engineer Coding Exercise
2+
3+
## The Sieve of Eratosthenes
4+
5+
Prime numbers have many modern day applications and a long history in mathematics. Utilizing your own resources research the sieve of Eratosthenes, an algorithm for generating prime numbers. Based on your research, implement an API in `pkg/sieve/sieve.go` that allows the caller to retrieve the Nth prime number.
6+
Some stub code and a test suite have been provided as a convenience, however, you are encouraged to deviate from Eratosthenes's algorithm, modify the existing functions/methods or anything else that might showcase your ability provided the following requirements are satisfied.
7+
8+
### Requirements
9+
10+
- A url to a publically accessible `git` repository (GitHub, GitLab, self-hosted, etc) of the completed exercise must be given to your coordinator at least 24 hours in advance of the technical interview
11+
- Interviewers must be able to clone the repository via `git clone`
12+
- Interviewers must be able to execute a suite of tests via `go test ./...`
13+
- The go library package provides an API for retrieving the Nth prime number using 0-based indexing where the 0th prime number is 2
14+
15+
### Considerations
16+
17+
During the technical interview, your submission will be discussed and you will be evaluated in the following areas:
18+
19+
- Technical ability
20+
- Communication skills
21+
- Work habits and complementary skills

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module ssse-exercise-sieve
2+
3+
go 1.19
4+
5+
require github.com/stretchr/testify v1.8.1
6+
7+
require (
8+
github.com/davecgh/go-spew v1.1.1 // indirect
9+
github.com/pmezard/go-difflib v1.0.0 // indirect
10+
gopkg.in/yaml.v3 v3.0.1 // indirect
11+
)

go.sum

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
6+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
7+
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
8+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
9+
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
10+
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
11+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
12+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
13+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
14+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
15+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
16+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
17+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

pkg/sieve/sieve.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package sieve
2+
3+
type Sieve interface {
4+
NthPrime(n int64) int64
5+
}
6+
7+
func NewSieve() Sieve {
8+
panic("unimplemented")
9+
}

pkg/sieve/sieve_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package sieve
2+
3+
import (
4+
"math/big"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestNthPrime(t *testing.T) {
11+
sieve := NewSieve()
12+
13+
assert.Equal(t, 2, sieve.NthPrime(0))
14+
assert.Equal(t, 71, sieve.NthPrime(19))
15+
assert.Equal(t, 541, sieve.NthPrime(99))
16+
assert.Equal(t, 3581, sieve.NthPrime(500))
17+
assert.Equal(t, 7793, sieve.NthPrime(986))
18+
assert.Equal(t, 17393, sieve.NthPrime(2000))
19+
assert.Equal(t, 15485867, sieve.NthPrime(1000000))
20+
}
21+
22+
func FuzzNthPrime(f *testing.F) {
23+
sieve := NewSieve()
24+
25+
f.Fuzz(func(t *testing.T, n int64) {
26+
if !big.NewInt(sieve.NthPrime(n)).ProbablyPrime(0) {
27+
t.Errorf("the sieve produced a non-prime number at index %d", n)
28+
}
29+
})
30+
}

0 commit comments

Comments
 (0)