Created
March 6, 2022 16:52
-
-
Save genghisjahn/4ef5bd289d7c11e349e77c17922cbf82 to your computer and use it in GitHub Desktop.
FindFactors
This 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 characters
package main | |
import "fmt" | |
func main() { | |
for i := 1; i <= 10000; i++ { | |
f := getFactors(i) | |
if len(f) == 1 { | |
fmt.Println(i, "is prime.") | |
continue | |
} | |
if len(f) > 0 { | |
fmt.Println(i, "factors:", f) | |
} | |
} | |
} | |
func getFactors(num int) []int { | |
var result []int | |
a := num / 2 | |
for i := a; i > 0; i-- { | |
if num%i == 0 { | |
result = append(result, i) | |
} | |
} | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment