Created
          December 27, 2014 12:32 
        
      - 
      
- 
        Save danackerson/3b3573211a7e79f8705d to your computer and use it in GitHub Desktop. 
Revisions
- 
        danackerson created this gist Dec 27, 2014 .There are no files selected for viewingThis file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ package main import ( "math" "math/big" "fmt" ) // change prime() to main() for execution => can't have 2 main()'s and go test func main(){ index := 0 maxNums := int64(1000000) primes := [][]int64{} perfectSquare := 1 for value := int64(1); value < maxNums; value++ { i := big.NewInt(value) isPrime := i.ProbablyPrime(1) if isPrime { square := int64(math.Pow(float64(value),2)) newPrime := []int64{ value, square, 0 } primes = append(primes, newPrime) if index > 0 { diffPlusOne := primes[index][1] - primes[index - 1][1] + 1 root_of_diff := math.Sqrt(float64(diffPlusOne)) integerPart, decimalPart := math.Modf(root_of_diff) if decimalPart == 0 { primes[index][2] = int64(integerPart) fmt.Printf("%d: squareRoot gives %d with %f remainder\n", value, int(integerPart), decimalPart) perfectSquare++ } else { primes[index][2] = int64(-1) } } index++ } } fmt.Printf("%d/%d are perfect roots\n", perfectSquare, maxNums) }