diff options
| -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 |
