aboutsummaryrefslogtreecommitdiff
path: root/challenge-043
diff options
context:
space:
mode:
authorCris-HD <59669732+Cris-HD@users.noreply.github.com>2020-01-19 21:36:57 +0100
committerCris-HD <59669732+Cris-HD@users.noreply.github.com>2020-01-19 21:36:57 +0100
commitcbf2a21bc9cae15d4f251de0acb8ebf30b34ba65 (patch)
treed54d43a32e2fffde9c01a01502bd062b3bb93ebd /challenge-043
parentf63d9c21b9020921adfb6187bafd52ff8f72ca1b (diff)
downloadperlweeklychallenge-club-cbf2a21bc9cae15d4f251de0acb8ebf30b34ba65.tar.gz
perlweeklychallenge-club-cbf2a21bc9cae15d4f251de0acb8ebf30b34ba65.tar.bz2
perlweeklychallenge-club-cbf2a21bc9cae15d4f251de0acb8ebf30b34ba65.zip
Added new challenges
Diffstat (limited to 'challenge-043')
-rw-r--r--challenge-043/cristian-heredia/perl/ch-1.pl90
-rw-r--r--challenge-043/cristian-heredia/perl/ch-2.pl18
2 files changed, 108 insertions, 0 deletions
diff --git a/challenge-043/cristian-heredia/perl/ch-1.pl b/challenge-043/cristian-heredia/perl/ch-1.pl
new file mode 100644
index 0000000000..f39b954826
--- /dev/null
+++ b/challenge-043/cristian-heredia/perl/ch-1.pl
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+
+#Array with posibles values
+my @values = (1, 2, 3, 4, 6);
+my @red = (9, $a);
+my @green = ($a, 5, $b);
+my @black = ($b, $q, $c);
+my @yellow = ($c, 7, $d);
+my @blue = ($d, 8);
+
+#others variables
+my $a;
+my $b;
+my $c;
+my $d;
+my $q;
+my @total = (11);
+
+$a = @total[0] - @red[0];
+@red[1] = $a;
+validate($a);
+print "\nValors of red:\n";
+for (my $j = 0; $j < @red; $j++) {
+ print "@red[$j],";
+}
+print "\n";
+
+@green[0] = $a;
+$b = @total[0] - @red[1] - @green[1];
+validate($b);
+@green[2] = $b;
+print "\nValors of green:\n";
+for (my $j = 0; $j < @green; $j++) {
+ print "@green[$j],";
+}
+print "\n";
+
+$d = @total[0] - @blue[1];
+validate($d);
+@blue[0] = $d;
+print "\nValors of blue:\n";
+for (my $j = 0; $j < @blue; $j++) {
+ print "@blue[$j],";
+}
+print "\n";
+
+@yellow[2] = $d;
+$c = @total[0] - @yellow[1] - @yellow[2];
+validate($c);
+@yellow[0] = $c;
+print "\nValors of yellow:\n";
+for (my $j = 0; $j < @yellow; $j++) {
+ print "@yellow[$j],";
+}
+print "\n";
+
+@black[0] = $b;
+@black[2] = $c;
+$q = @total[0] - @black[0] - @black[2];
+@black[1] = $q;
+validate($q);
+print "\nValors of black:\n";
+for (my $j = 0; $j < @black; $j++) {
+ print "@black[$j],";
+}
+print "\n";
+
+
+sub validate {
+ $valor = shift;
+ my $valide;
+ for (my $j = 0; $j < @values; $j++) {
+ if (@values[$j] == $valor) {
+ $valide = "KO";
+
+ }
+ else {
+ $valide = "OK";
+ last;
+ }
+ }
+
+ if ($validate == KO) {
+ print "The number $valor is one of the given.";
+ }
+ else {
+ print "The number $valor isn't one of the given.";
+ }
+
+}
diff --git a/challenge-043/cristian-heredia/perl/ch-2.pl b/challenge-043/cristian-heredia/perl/ch-2.pl
new file mode 100644
index 0000000000..7bf375c5e1
--- /dev/null
+++ b/challenge-043/cristian-heredia/perl/ch-2.pl
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use strict;
+use Math::Base::Convert;
+use Math::Base::Convert qw(:base);
+
+my $valor;
+
+for (my $b = 7; $b <= 10; $b++) {
+
+ $valor = ($b - 4) * $b**($b - 1) + 2 * $b ** ($b-2) + $b**($b-3) + $b**3;
+
+ $converted = cnv($valor,10 => $b);
+ print "Base is $b, and the result is $converted\n";
+
+}
+
+