aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-07-29 21:05:27 +0100
committerGitHub <noreply@github.com>2022-07-29 21:05:27 +0100
commitc549a7288ca66b1b48e8518454806b538fd97568 (patch)
tree2ebcf9f392c154f77ccd3aec462848f2d54a90d7
parent1a12e75e82c23f90cbdc3fda2c649f05e0d3ad06 (diff)
parent9d8f405bf4752d438c907566967489fb5785be9f (diff)
downloadperlweeklychallenge-club-c549a7288ca66b1b48e8518454806b538fd97568.tar.gz
perlweeklychallenge-club-c549a7288ca66b1b48e8518454806b538fd97568.tar.bz2
perlweeklychallenge-club-c549a7288ca66b1b48e8518454806b538fd97568.zip
Merge pull request #6520 from pokgopun/pwc175
pwc175 solution in go - simplified task#2
-rw-r--r--challenge-175/pokgopun/go/ch-2.go16
1 files 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")
}