Skip to content

Commit

Permalink
Solving problem07
Browse files Browse the repository at this point in the history
  • Loading branch information
coleifer committed Apr 20, 2012
1 parent 6db2da0 commit a89601c
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions go/problem07.go
@@ -0,0 +1,37 @@
package main

import (
"fmt"
"math"
)

func is_prime(i int64) bool {
var j int64 = 0;
if i < 2 {
return false
} else if i == 2 {
return true
}
for j = 3; j <= sqrt(i); j+=2 {
if i % j == 0 {
return false
}
}
return true
}

func sqrt(i int64) int64 {
return int64(math.Sqrt(float64(i)))
}

func main() {
var i, j int64
i = 1 // since we're starting with 3, count two
for j = 3; i < 10001; j += 2 {
if is_prime(j) {
i += 1
}
}
// go adds 2 even if the check fails so subtract here
fmt.Printf("%v\n", j-2)
}

0 comments on commit a89601c

Please sign in to comment.