move to lib

This commit is contained in:
filifa
2025-09-29 21:52:52 -04:00
parent d2275cd69f
commit b55fe61820
16 changed files with 452 additions and 296 deletions

View File

@@ -20,39 +20,13 @@ import (
"fmt"
"github.com/spf13/cobra"
"scm.dairydemon.net/filifa/mathtools/internal/lib"
)
var totientN uint
func totientSieve(n uint) chan uint {
totients := make([]uint, n)
totients[0] = 0
totients[1] = 1
for i := uint(2); i < n; i++ {
totients[i] = i - 1
}
ch := make(chan uint)
go func() {
for i := uint(0); i < n; i++ {
ch <- totients[i]
if i == 0 || i == 1 || totients[i] != i-1 {
continue
}
for j := uint(2 * i); j < n; j += i {
totients[j] -= totients[j] / i
}
}
close(ch)
}()
return ch
}
func totient(cmd *cobra.Command, args []string) {
for v := range totientSieve(totientN) {
for v := range lib.TotientSieve(totientN) {
if v == 0 {
continue
}