aboutsummaryrefslogtreecommitdiff
path: root/challenge-102/arne-sommer/perl/hash-counting-string-perl
blob: f2f84f78a8c36d95854d90e288bb0c94b16bdadd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#! /usr/bin/env perl

use strict;
use feature 'say';

my $N = shift(@ARGV) // die 'Please specify $N';

die '$N is not a positive integer' unless $N =~ /^[1-9][0-9]*$/;

my $position = $N;
my $string   = "";

while ($position > 1)
{
  my $prefix = $position . '#';

  $string = $prefix . $string;
  $position -= length($prefix);
}

length($string) == $N
    ? say $string
    : say "#$string";