Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Solving problem07

  • Loading branch information...
commit a89601c155f005dda8ba1568765f0b64d79e5663 1 parent 6db2da0
Charles Leifer authored

Showing 1 changed file with 37 additions and 0 deletions. Show diff stats Hide diff stats

  1. +37 0 go/problem07.go
37 go/problem07.go
... ... @@ -0,0 +1,37 @@
  1 +package main
  2 +
  3 +import (
  4 + "fmt"
  5 + "math"
  6 +)
  7 +
  8 +func is_prime(i int64) bool {
  9 + var j int64 = 0;
  10 + if i < 2 {
  11 + return false
  12 + } else if i == 2 {
  13 + return true
  14 + }
  15 + for j = 3; j <= sqrt(i); j+=2 {
  16 + if i % j == 0 {
  17 + return false
  18 + }
  19 + }
  20 + return true
  21 +}
  22 +
  23 +func sqrt(i int64) int64 {
  24 + return int64(math.Sqrt(float64(i)))
  25 +}
  26 +
  27 +func main() {
  28 + var i, j int64
  29 + i = 1 // since we're starting with 3, count two
  30 + for j = 3; i < 10001; j += 2 {
  31 + if is_prime(j) {
  32 + i += 1
  33 + }
  34 + }
  35 + // go adds 2 even if the check fails so subtract here
  36 + fmt.Printf("%v\n", j-2)
  37 +}

0 comments on commit a89601c

Please sign in to comment.
Something went wrong with that request. Please try again.