aboutsummaryrefslogtreecommitdiff
path: root/challenge-044
diff options
context:
space:
mode:
authorCris-HD <59669732+Cris-HD@users.noreply.github.com>2020-01-26 22:06:36 +0100
committerCris-HD <59669732+Cris-HD@users.noreply.github.com>2020-01-26 22:06:36 +0100
commite155835c99727c1b5e51e089f0e45b842fdd0780 (patch)
tree7b6244cb02df1b9edf3a23a1fe7ca6ca196a9f6d /challenge-044
parent87a6af9725acf75343b1d590e224d9cfbd5f0cd8 (diff)
downloadperlweeklychallenge-club-e155835c99727c1b5e51e089f0e45b842fdd0780.tar.gz
perlweeklychallenge-club-e155835c99727c1b5e51e089f0e45b842fdd0780.tar.bz2
perlweeklychallenge-club-e155835c99727c1b5e51e089f0e45b842fdd0780.zip
Create ch-2.pl
added ch2
Diffstat (limited to 'challenge-044')
-rw-r--r--challenge-044/cristian-heredia/perl/ch-2.pl32
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-044/cristian-heredia/perl/ch-2.pl b/challenge-044/cristian-heredia/perl/ch-2.pl
new file mode 100644
index 0000000000..3e1d45e08e
--- /dev/null
+++ b/challenge-044/cristian-heredia/perl/ch-2.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/perl
+
+my $total;
+my $number = 200;
+my @moves;
+
+divide();
+
+sub divide {
+ while (($number %2 )==0) {
+ $number = $number / 2;
+ unshift @moves, 'double ';
+ }
+ remove();
+}
+
+sub remove {
+ $number --;
+ unshift @moves, '+1$ ';
+ if ($number == 1 or $number == 0) {
+ print "The moves that you have to do are: \n";
+ $total = @moves;
+ print "$total\n";
+ print 'And they are: ';
+ foreach (my $i = 0; $i < @moves; $i++) {
+ print "@moves[$i]";
+ }
+ }
+ else {
+ divide();
+ }
+} \ No newline at end of file