diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-03-09 23:37:54 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-09 23:37:54 +0000 |
| commit | 0a9c33f24cb817475c7f6dc26c811763b95f8bdf (patch) | |
| tree | 8ec5878b412a74307afa4f2f9d232a70c75c00f0 /challenge-102 | |
| parent | 7ff04a014c9cb952772a4531d62f01e3c80e8353 (diff) | |
| parent | 3654bd7723a2df65ee7147eefbd2aad1f57e6d3d (diff) | |
| download | perlweeklychallenge-club-0a9c33f24cb817475c7f6dc26c811763b95f8bdf.tar.gz perlweeklychallenge-club-0a9c33f24cb817475c7f6dc26c811763b95f8bdf.tar.bz2 perlweeklychallenge-club-0a9c33f24cb817475c7f6dc26c811763b95f8bdf.zip | |
Merge pull request #3691 from Doomtrain14/master
Added perl solution ch102-2
Diffstat (limited to 'challenge-102')
| -rw-r--r-- | challenge-102/yet-ebreo/perl/ch-2.pl | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/challenge-102/yet-ebreo/perl/ch-2.pl b/challenge-102/yet-ebreo/perl/ch-2.pl new file mode 100644 index 0000000000..4197f1d406 --- /dev/null +++ b/challenge-102/yet-ebreo/perl/ch-2.pl @@ -0,0 +1,37 @@ +#! /usr/bin/perl + +use strict; +use warnings; +use feature qw(say); + + +# You are given a positive integer $N. + +# Write a script to produce Hash-counting string of that length. + +# The definition of a hash-counting string is as follows: + +# - the string consists only of digits 0-9 and hashes, ‘#’ +# - there are no two consecutive hashes: ‘##’ does not appear in your string +# - the last character is a hash +# - the number immediately preceding each hash (if it exists) is the position of that hash in the string, with the position being counted up from 1 +# It can be shown that for every positive integer N there is exactly one such length-N string. + +# Examples: +# (a) "#" is the counting string of length 1 +# (b) "2#" is the counting string of length 2 +# (c) "#3#" is the string of length 3 +# (d) "#3#5#7#10#" is the string of length 10 +# (e) "2#4#6#8#11#14#" is the string of length 14 + +my $N = $ARGV[0] || 2; +my $out = ""; + +while ($N) { + $out = ($N>1?"$N":"")."#$out"; + $N = $ARGV[0] - length $out; +} + + +say $out; + |
