From 9d8f405bf4752d438c907566967489fb5785be9f Mon Sep 17 00:00:00 2001 From: Michael Manring Date: Sat, 30 Jul 2022 00:38:14 +0700 Subject: pwc175 solution in go - simplified task#2 --- challenge-175/pokgopun/go/ch-2.go | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/challenge-175/pokgopun/go/ch-2.go b/challenge-175/pokgopun/go/ch-2.go index 51106c56a2..a94463d9b3 100644 --- a/challenge-175/pokgopun/go/ch-2.go +++ b/challenge-175/pokgopun/go/ch-2.go @@ -12,6 +12,7 @@ Output package main import ( + "fmt" "io" "os" "strconv" @@ -21,18 +22,11 @@ import ( ) func main() { - var cntdwn uint = 20 - p := totient.New(cntdwn) + var count, start uint64 = 20, 3 + fmt.Sscanf(strings.Join(os.Args[1:], " "), "%d %d", &count, &start) var b strings.Builder - for i := uint(3); i < 200_000; i += 2 { - if p.IsPerfect(i) { - b.WriteString(", " + strconv.FormatUint(uint64(i), 10)) - //fmt.Println(i) - cntdwn-- - } - if cntdwn == 0 { - break - } + for _, v := range totient.New().ListPerfect(start, count) { + b.WriteString(", " + strconv.FormatUint(v, 10)) } io.WriteString(os.Stdout, (b.String()[2:])+"\n") } -- cgit