diff options
| author | Michael Manring <michael@manring> | 2022-06-06 11:54:42 +0700 |
|---|---|---|
| committer | Michael Manring <michael@manring> | 2022-06-08 14:41:06 +0700 |
| commit | 471b056ad154010f4c8a1f5bc830b20a3390c665 (patch) | |
| tree | 86a9028db59c396b9b4072bb98680382a749de3f /challenge-146 | |
| parent | 4b569aef972ae1d1b9b6811ca336cd77a03b4998 (diff) | |
| download | perlweeklychallenge-club-471b056ad154010f4c8a1f5bc830b20a3390c665.tar.gz perlweeklychallenge-club-471b056ad154010f4c8a1f5bc830b20a3390c665.tar.bz2 perlweeklychallenge-club-471b056ad154010f4c8a1f5bc830b20a3390c665.zip | |
pwc145 solution in go
Diffstat (limited to 'challenge-146')
| -rw-r--r-- | challenge-146/pokgopun/go/ch-2.go | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/challenge-146/pokgopun/go/ch-2.go b/challenge-146/pokgopun/go/ch-2.go index b8aea49f0f..a8545314f3 100644 --- a/challenge-146/pokgopun/go/ch-2.go +++ b/challenge-146/pokgopun/go/ch-2.go @@ -2,35 +2,22 @@ package main import ( "fmt" - "log" "os" ) func main() { - samples := [][2]uint{ - [2]uint{3, 5}, - [2]uint{4, 3}, - } + var sample []string if len(os.Args) > 1 { - var sample [2]uint - _, err := fmt.Sscanf(os.Args[1], "%d/%d", &sample[0], &sample[1]) - if err != nil { - log.Fatal(err) + sample = os.Args[1:] + } else { + sample = []string{ + "redivider", + "deific", + "rotors", + "challenge", + "champion", + "christmas", } - samples = [][2]uint{sample} - } - for _, v := range samples { - p := parent(v) - gp := parent(p) - fmt.Printf("Input: member = '%d/%d'\nOutput: parent ='%d/%d' and grandparent = '%d/%d'\n", v[0], v[1], p[0], p[1], gp[0], gp[1]) - } -} - -func parent(s [2]uint) [2]uint { - if s[0] > s[1] { - return [2]uint{s[0] - s[1], s[1]} - } else if s[0] < s[1] { - return [2]uint{s[0], s[1] - s[0]} } - return [2]uint{1, 1} + fmt.Println(sample) } |
