aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-044/paulo-custodio/Makefile2
-rw-r--r--challenge-044/paulo-custodio/README1
-rw-r--r--challenge-044/paulo-custodio/perl/ch-1.pl33
-rw-r--r--challenge-044/paulo-custodio/perl/ch-2.pl32
-rw-r--r--challenge-044/paulo-custodio/t/test-1.yaml16
-rw-r--r--challenge-044/paulo-custodio/t/test-2.yaml5
6 files changed, 89 insertions, 0 deletions
diff --git a/challenge-044/paulo-custodio/Makefile b/challenge-044/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-044/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-044/paulo-custodio/README b/challenge-044/paulo-custodio/README
new file mode 100644
index 0000000000..87dc0b2fbd
--- /dev/null
+++ b/challenge-044/paulo-custodio/README
@@ -0,0 +1 @@
+Solution by Paulo Custodio
diff --git a/challenge-044/paulo-custodio/perl/ch-1.pl b/challenge-044/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..610d74808b
--- /dev/null
+++ b/challenge-044/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,33 @@
+#!/usr/bin/env perl
+
+# Challenge 044
+#
+# TASK #1
+# Only 100, please.
+# You are given a string “123456789”. Write a script that would insert
+# “+” or "-" in between digits so that when you evaluate, the result should
+# be 100.
+
+use Modern::Perl;
+
+for my $a ('', '-', '+') {
+ for my $b ('', '-', '+') {
+ for my $c ('', '-', '+') {
+ for my $d ('', '-', '+') {
+ for my $e ('', '-', '+') {
+ for my $f ('', '-', '+') {
+ for my $g ('', '-', '+') {
+ for my $h ('', '-', '+') {
+ my $test = "1${a}2${b}3${c}4${d}5${e}6${f}7${g}8${h}9";
+ my $res = eval $test;
+ if ($res==100) {
+ say $test;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/challenge-044/paulo-custodio/perl/ch-2.pl b/challenge-044/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..b6afba3e3d
--- /dev/null
+++ b/challenge-044/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+
+# Challenge 044
+#
+# TASK #2
+# Make it $200
+# You have only $1 left at the start of the week. You have been given an
+# opportunity to make it $200. The rule is simple with every move you can either
+# double what you have or add another $1. Write a script to help you get $200
+# with the smallest number of moves.
+
+use Modern::Perl;
+no warnings 'recursion';
+
+my $min = join("+", (1)x200);
+find_min("1", 1);
+say $min;
+
+sub find_min {
+ my($str, $num) = @_;
+ if ($num > 200) {
+ }
+ elsif ($num == 200) {
+ if (length($str) < length($min)) {
+ $min = $str;
+ }
+ }
+ else {
+ find_min("$str*2", $num*2);
+ find_min("$str+1", $num+1);
+ }
+}
diff --git a/challenge-044/paulo-custodio/t/test-1.yaml b/challenge-044/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..aa228c82a0
--- /dev/null
+++ b/challenge-044/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,16 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: |
+ |123-45-67+89
+ |123-4-5-6-7+8-9
+ |123+45-67+8-9
+ |123+4-5+67-89
+ |12-3-4+5-6+7+89
+ |12+3-4+5+67+8+9
+ |12+3+4+5-6-7+89
+ |1+23-4+56+7+8+9
+ |1+23-4+5+6+78-9
+ |1+2+34-5+67-8+9
+ |1+2+3-4+5+6+78+9
diff --git a/challenge-044/paulo-custodio/t/test-2.yaml b/challenge-044/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..2fd9e639c9
--- /dev/null
+++ b/challenge-044/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,5 @@
+- setup:
+ cleanup:
+ args:
+ input:
+ output: 1*2+1*2*2*2+1*2*2*2