Created
October 18, 2012 21:09
-
-
Save ZachMassia/3914754 to your computer and use it in GitHub Desktop.
Golang Perfect Numbers
This file contains 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 characters
package main | |
import ( | |
"fmt" | |
) | |
func isPerfect(num uint64) { | |
sum := calcDiv(num) | |
if sum == num { | |
fmt.Println(num) | |
} | |
} | |
func calcDiv(num uint64) (sum uint64) { | |
var i uint64 | |
for i = 1; i <= num / 2; i++ { | |
if num % i == 0 { | |
sum += i | |
} | |
} | |
return | |
} | |
func main() { | |
var start, end uint64 | |
start = 1 | |
end = 999999999 | |
for ; start <= end; start++ { | |
isPerfect(start) | |
// go isPerfect(start) // concurrent execution | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment