aboutsummaryrefslogtreecommitdiff
path: root/challenge-160
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-160')
-rw-r--r--challenge-160/pokgopun/go/ch-1.go16
-rw-r--r--challenge-160/pokgopun/perl/ch-1.pl24
-rw-r--r--challenge-160/pokgopun/perl/ch-2.pl19
3 files changed, 46 insertions, 13 deletions
diff --git a/challenge-160/pokgopun/go/ch-1.go b/challenge-160/pokgopun/go/ch-1.go
index f4a62114de..4e6506934b 100644
--- a/challenge-160/pokgopun/go/ch-1.go
+++ b/challenge-160/pokgopun/go/ch-1.go
@@ -10,17 +10,7 @@ import (
)
func main() {
- m := map[int]string{
- 1: "one",
- 2: "two",
- 3: "three",
- 4: "four",
- 5: "five",
- 6: "six",
- 7: "seven",
- 8: "eight",
- 9: "nine",
- }
+ m := []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"}
//fmt.Println(m)
re := regexp.MustCompile(`\S+$`)
var num []int
@@ -31,14 +21,14 @@ func main() {
}
for _, n := range num {
fmt.Println("Input: $n =", n)
- str := m[n]
+ str := m[n-1]
for {
r := re.FindString(str)
if r == "four" {
str += " is magic"
break
} else {
- nxt := m[len(r)]
+ nxt := m[len(r)-1]
str += " is " + nxt + ", " + nxt
r = str
diff --git a/challenge-160/pokgopun/perl/ch-1.pl b/challenge-160/pokgopun/perl/ch-1.pl
new file mode 100644
index 0000000000..cf260e0431
--- /dev/null
+++ b/challenge-160/pokgopun/perl/ch-1.pl
@@ -0,0 +1,24 @@
+use strict;
+use warnings;
+
+my @m= qw/one two three four five six seven eight nine/;
+
+my @n = @ARGV && join("",@ARGV) =~ /^\d+$/ ? @ARGV : (5,7,6);
+
+foreach my $n (@n) {
+ printf "Input: \$n = %d\n", $n;
+ my $str = $m[$n-1];
+ {
+ my $prev = $1 if $str =~ /(\S+)$/;
+ if ($prev eq "four") {
+ $str .= " is magic";
+ last;
+ } else {
+ my $next = $m[length($prev)-1];
+ $str .= " is $next, $next";
+ }
+ redo;
+ }
+ $str =~ s/^(.)/\U$1/;
+ printf "Output: %s.\n\n", $str;
+}
diff --git a/challenge-160/pokgopun/perl/ch-2.pl b/challenge-160/pokgopun/perl/ch-2.pl
new file mode 100644
index 0000000000..f4795fc255
--- /dev/null
+++ b/challenge-160/pokgopun/perl/ch-2.pl
@@ -0,0 +1,19 @@
+use strict;
+use warnings;
+use List::Util qw/sum/;
+
+my @samples = @ARGV > 3 && join("",@ARGV) =~ /^\d+$/ ? ([@ARGV]) : ([1,3,5,7,9],[1,2,3,4,5],[2,4,2]);
+
+foreach (@samples) {
+ my @sample = @$_;
+ printf "Input: \@n = (%s)\n", join(", ", @sample);
+ my $o = -1;
+ for (my $i=1; $i < @sample-1; $i++){
+ if ( sum(@sample[0..$i-1]) == sum(@sample[$i+1..@sample-1]) ){
+ $o = $i;
+ last;
+ }
+ }
+ printf "Output: $o\n\n";
+}
+