diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2020-01-26 21:19:49 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-26 21:19:49 +0000 |
| commit | 7c00becec6b51b9ae1344ea47846cdf8f06614c9 (patch) | |
| tree | 6a66f307654f476f3f0d5ab47ffa1747bea4712f /challenge-044 | |
| parent | e09ed014ad1a6d10ca87189965ced44dd77a0ebe (diff) | |
| parent | e155835c99727c1b5e51e089f0e45b842fdd0780 (diff) | |
| download | perlweeklychallenge-club-7c00becec6b51b9ae1344ea47846cdf8f06614c9.tar.gz perlweeklychallenge-club-7c00becec6b51b9ae1344ea47846cdf8f06614c9.tar.bz2 perlweeklychallenge-club-7c00becec6b51b9ae1344ea47846cdf8f06614c9.zip | |
Merge pull request #1172 from Cris-HD/branch-for-challenge-044a
Create ch-2.pl
Diffstat (limited to 'challenge-044')
| -rw-r--r-- | challenge-044/cristian-heredia/perl/ch-2.pl | 32 |
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 |
