diff options
| author | Mohammad S Anwar <Mohammad.Anwar@yahoo.com> | 2021-05-16 22:46:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-16 22:46:33 +0100 |
| commit | e6d4eea188e36a9f45fec5f0a4547f83f65b83be (patch) | |
| tree | 043da56020c7d0c0a7a6b976c6b2319630dc7e4a /challenge-112 | |
| parent | c077f1322724bc9c8e4680ffa627ebfded35ca89 (diff) | |
| parent | c679e15da02f5a668c15fb5bcd7c58096a929df9 (diff) | |
| download | perlweeklychallenge-club-e6d4eea188e36a9f45fec5f0a4547f83f65b83be.tar.gz perlweeklychallenge-club-e6d4eea188e36a9f45fec5f0a4547f83f65b83be.tar.bz2 perlweeklychallenge-club-e6d4eea188e36a9f45fec5f0a4547f83f65b83be.zip | |
Merge pull request #4090 from arnesom/branch-for-challenge-112
Arne Sommer
Diffstat (limited to 'challenge-112')
| -rw-r--r-- | challenge-112/arne-sommer/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-112/arne-sommer/perl/canonical-path-perl | 38 | ||||
| -rwxr-xr-x | challenge-112/arne-sommer/perl/ch-1.pl | 38 | ||||
| -rwxr-xr-x | challenge-112/arne-sommer/perl/ch-2.pl | 44 | ||||
| -rwxr-xr-x | challenge-112/arne-sommer/perl/climb-stairs-perl | 44 | ||||
| -rwxr-xr-x | challenge-112/arne-sommer/raku/canonical-path | 28 | ||||
| -rwxr-xr-x | challenge-112/arne-sommer/raku/ch-1.raku | 28 | ||||
| -rwxr-xr-x | challenge-112/arne-sommer/raku/ch-2.raku | 22 | ||||
| -rwxr-xr-x | challenge-112/arne-sommer/raku/climb-stairs | 22 |
9 files changed, 265 insertions, 0 deletions
diff --git a/challenge-112/arne-sommer/blog.txt b/challenge-112/arne-sommer/blog.txt new file mode 100644 index 0000000000..47a5709921 --- /dev/null +++ b/challenge-112/arne-sommer/blog.txt @@ -0,0 +1 @@ +https://raku-musings.com/canonical-stairs.html diff --git a/challenge-112/arne-sommer/perl/canonical-path-perl b/challenge-112/arne-sommer/perl/canonical-path-perl new file mode 100755 index 0000000000..7da2cb5c80 --- /dev/null +++ b/challenge-112/arne-sommer/perl/canonical-path-perl @@ -0,0 +1,38 @@ +#! /usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use Getopt::Long; + +my $verbose = 0; +GetOptions("verbose" => \$verbose); + +my $path = $ARGV[0] // die "Please specify the path"; + +die 'Path must begin with "/"' unless substr($path, 0, 1) eq '/'; + +my @path = split('/', $path); + +shift(@path); + +my @result; + +for my $current (@path) +{ + say ":: current element $current" if $verbose; + + next unless $current; + next if $current eq '.'; + + if ($current eq '..') + { + pop(@result); + } + else + { + push(@result, $current); + } +} + +say '/' . join('/', @result); diff --git a/challenge-112/arne-sommer/perl/ch-1.pl b/challenge-112/arne-sommer/perl/ch-1.pl new file mode 100755 index 0000000000..7da2cb5c80 --- /dev/null +++ b/challenge-112/arne-sommer/perl/ch-1.pl @@ -0,0 +1,38 @@ +#! /usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use Getopt::Long; + +my $verbose = 0; +GetOptions("verbose" => \$verbose); + +my $path = $ARGV[0] // die "Please specify the path"; + +die 'Path must begin with "/"' unless substr($path, 0, 1) eq '/'; + +my @path = split('/', $path); + +shift(@path); + +my @result; + +for my $current (@path) +{ + say ":: current element $current" if $verbose; + + next unless $current; + next if $current eq '.'; + + if ($current eq '..') + { + pop(@result); + } + else + { + push(@result, $current); + } +} + +say '/' . join('/', @result); diff --git a/challenge-112/arne-sommer/perl/ch-2.pl b/challenge-112/arne-sommer/perl/ch-2.pl new file mode 100755 index 0000000000..448f59a11a --- /dev/null +++ b/challenge-112/arne-sommer/perl/ch-2.pl @@ -0,0 +1,44 @@ +#! /usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use feature 'signatures'; + +no warnings "experimental::signatures"; + +my $n = $ARGV[0] // die "Please specify number of steps"; + +my $matches = 0; + +climb(0); + +sub climb ($sum) +{ + return if $sum > $n; + if ($sum == $n) + { + $matches++; + return; + } + + climb($sum +1); + climb($sum +2); +} + +say $matches; + +__END__ +... 100 +Deep recursion on subroutine "main::climb" at ./climb-stairs-perl line 26. +^C +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ ./climb-stairs-perl 10 +89 +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ ./climb-stairs-perl 15 +987 +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ ./climb-stairs-perl 20 +10946 +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ ./climb-stairs-perl 25 +121393 +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ + diff --git a/challenge-112/arne-sommer/perl/climb-stairs-perl b/challenge-112/arne-sommer/perl/climb-stairs-perl new file mode 100755 index 0000000000..448f59a11a --- /dev/null +++ b/challenge-112/arne-sommer/perl/climb-stairs-perl @@ -0,0 +1,44 @@ +#! /usr/bin/env perl + +use strict; +use warnings; +use feature 'say'; +use feature 'signatures'; + +no warnings "experimental::signatures"; + +my $n = $ARGV[0] // die "Please specify number of steps"; + +my $matches = 0; + +climb(0); + +sub climb ($sum) +{ + return if $sum > $n; + if ($sum == $n) + { + $matches++; + return; + } + + climb($sum +1); + climb($sum +2); +} + +say $matches; + +__END__ +... 100 +Deep recursion on subroutine "main::climb" at ./climb-stairs-perl line 26. +^C +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ ./climb-stairs-perl 10 +89 +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ ./climb-stairs-perl 15 +987 +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ ./climb-stairs-perl 20 +10946 +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ ./climb-stairs-perl 25 +121393 +arne@arne-ThinkPad-T490:~/Desktop/Timeliste/112 $ + diff --git a/challenge-112/arne-sommer/raku/canonical-path b/challenge-112/arne-sommer/raku/canonical-path new file mode 100755 index 0000000000..7af713b045 --- /dev/null +++ b/challenge-112/arne-sommer/raku/canonical-path @@ -0,0 +1,28 @@ +#! /usr/bin/env raku + +unit sub MAIN (Str $path where $path.substr(0,1) eq '/', :v($verbose)); + +my @path = $path.split('/'); + +@path.shift; + +my @result; + +for @path -> $current +{ + say ":: current element $current" if $verbose; + + next unless $current; + next if $current eq '.'; + + if $current eq '..' + { + @result.pop; + } + else + { + @result.push: $current; + } +} + +say "/{ @result.join('/') }"; diff --git a/challenge-112/arne-sommer/raku/ch-1.raku b/challenge-112/arne-sommer/raku/ch-1.raku new file mode 100755 index 0000000000..7af713b045 --- /dev/null +++ b/challenge-112/arne-sommer/raku/ch-1.raku @@ -0,0 +1,28 @@ +#! /usr/bin/env raku + +unit sub MAIN (Str $path where $path.substr(0,1) eq '/', :v($verbose)); + +my @path = $path.split('/'); + +@path.shift; + +my @result; + +for @path -> $current +{ + say ":: current element $current" if $verbose; + + next unless $current; + next if $current eq '.'; + + if $current eq '..' + { + @result.pop; + } + else + { + @result.push: $current; + } +} + +say "/{ @result.join('/') }"; diff --git a/challenge-112/arne-sommer/raku/ch-2.raku b/challenge-112/arne-sommer/raku/ch-2.raku new file mode 100755 index 0000000000..b9a7d9af42 --- /dev/null +++ b/challenge-112/arne-sommer/raku/ch-2.raku @@ -0,0 +1,22 @@ +#! /usr/bin/env raku + +unit sub MAIN (Int $n where $n > 0); + +my $matches = 0; + +climb(0); + +sub climb ($sum) +{ + return if $sum > $n; + if $sum == $n + { + $matches++; + return; + } + + climb($sum +1); + climb($sum +2); +} + +say $matches; diff --git a/challenge-112/arne-sommer/raku/climb-stairs b/challenge-112/arne-sommer/raku/climb-stairs new file mode 100755 index 0000000000..b9a7d9af42 --- /dev/null +++ b/challenge-112/arne-sommer/raku/climb-stairs @@ -0,0 +1,22 @@ +#! /usr/bin/env raku + +unit sub MAIN (Int $n where $n > 0); + +my $matches = 0; + +climb(0); + +sub climb ($sum) +{ + return if $sum > $n; + if $sum == $n + { + $matches++; + return; + } + + climb($sum +1); + climb($sum +2); +} + +say $matches; |
