aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-286/pokgopun/go/ch-1.go33
-rw-r--r--challenge-286/pokgopun/go/ch-2.go5
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("###")
}
}