This commit is contained in:
Preston Baxter 2024-08-22 16:50:21 -05:00
parent d9f34743c2
commit 3349d09c74
1 changed files with 61 additions and 0 deletions

61
cmd/21/main.go Normal file
View File

@ -0,0 +1,61 @@
package main
import (
"fmt"
"math"
)
const maxLen = 10000
func main() {
divList := make([]int, maxLen)
numList := make([]int, 0, 100)
for i := 0; i < maxLen; i+=1 {
if divList[i] > 0 {
continue
}
sum := sumDiv(findDiv(i))
divList[i] = sum
if sum >= maxLen {
continue
}
if divList[sum] == 0 {
divList[sum] = sumDiv(findDiv(sum))
}
if divList[sum] == i && sum != i {
numList = append(numList, i, sum)
}
}
fmt.Printf("List: %v\n", numList)
fmt.Printf("Sum: %d\n", sumDiv(numList))
}
func findDiv(num int) []int {
out := []int{1}
minDiv2 := num
for i := 2; i < int(math.Sqrt(float64(num))); i+=1 {
if i == minDiv2 {
break
}
if num % i == 0 {
div2 := num / i
out = append(out, i, div2)
minDiv2 = div2
}
}
return out
}
func sumDiv(list []int) int {
sum := 0
for _, i := range list {
sum += i
}
return sum
}