diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-09-09 10:45:17 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-09 10:45:17 +0100 |
| commit | e83f7e4d7285a22af4a40efa15e28272d79749e2 (patch) | |
| tree | 124fdf69a104887540e90d38d3cec69028c29f12 | |
| parent | 2b81a279baeac47b1316c8c88dca9048e5d76457 (diff) | |
| parent | 8ad15997e58619bf0370d85c92d0cd1367543e9b (diff) | |
| download | perlweeklychallenge-club-e83f7e4d7285a22af4a40efa15e28272d79749e2.tar.gz perlweeklychallenge-club-e83f7e4d7285a22af4a40efa15e28272d79749e2.tar.bz2 perlweeklychallenge-club-e83f7e4d7285a22af4a40efa15e28272d79749e2.zip | |
Merge pull request #10803 from pokgopun/pwc286
pwc286 ch-2.go - add test case and fix bug
| -rw-r--r-- | challenge-286/pokgopun/go/ch-1.go | 33 | ||||
| -rw-r--r-- | challenge-286/pokgopun/go/ch-2.go | 5 |
2 files changed, 37 insertions, 1 deletions
diff --git a/challenge-286/pokgopun/go/ch-1.go b/challenge-286/pokgopun/go/ch-1.go new file mode 100644 index 0000000000..8e3672b95e --- /dev/null +++ b/challenge-286/pokgopun/go/ch-1.go @@ -0,0 +1,33 @@ +//# https://theweeklychallenge.org/blog/perl-weekly-challenge-286/ +/*# + +Task 1: Self Spammer + +Submitted by: [56]David Ferrone + __________________________________________________________________ + + Write a program which outputs one word of its own script / source code + at random. A word is anything between whitespace, including symbols. + +Example 1 + +If the source code contains a line such as: 'open my $fh, "<", "ch-1.pl" or die; +' +then the program would output each of the words { open, my, $fh,, "<",, "ch-1.pl +", or, die; } +(along with other words in the source) with some positive probability. + +Example 2 + +Technically 'print(" hello ");' is *not* an example program, because it does not +assign positive probability to the other two words in the script. +It will never display print(" or "); + +Example 3 + +An empty script is one trivial solution, and here is another: +echo "42" > ch-1.pl && perl -p -e '' ch-1.pl + +Task 2: Order Game +#*/ +//# solution by pokgopun@gmail.com diff --git a/challenge-286/pokgopun/go/ch-2.go b/challenge-286/pokgopun/go/ch-2.go index 58fd8dbb01..3c0ade7d7e 100644 --- a/challenge-286/pokgopun/go/ch-2.go +++ b/challenge-286/pokgopun/go/ch-2.go @@ -102,7 +102,7 @@ type ints []int func (is ints) play() int { for { l := len(is) - if l > 2 { + if l == 2 { break } var j int @@ -115,6 +115,7 @@ func (is ints) play() int { j++ } is = is[:j] + //fmt.Println(is) } return min(is[0], is[1]) } @@ -127,7 +128,9 @@ func main() { {ints{2, 1, 4, 5, 6, 3, 0, 2}, 1}, {ints{0, 5, 3, 2}, 0}, {ints{9, 2, 1, 4, 5, 6, 0, 7, 3, 1, 3, 5, 7, 9, 0, 8}, 2}, + {ints{22, 11, 4, 5, 6, 3, 0, 2}, 3}, } { io.WriteString(os.Stdout, gcmp.Diff(data.input.play(), data.output)) // blank if ok, otherwise, show the difference + //fmt.Println("###") } } |
