From 1bd06dd5ebbb420d3eba4335a8d2c6b4d4eea520 Mon Sep 17 00:00:00 2001 From: Ysmael Ebreo Date: Mon, 11 May 2020 22:52:44 +0800 Subject: Added perl solution for ch#60 --- challenge-060/yet-ebreo/perl/ch-1.pl | 54 ++++++++++++++++++++++++++++++++++++ challenge-060/yet-ebreo/perl/ch-2.pl | 50 +++++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 challenge-060/yet-ebreo/perl/ch-1.pl create mode 100644 challenge-060/yet-ebreo/perl/ch-2.pl diff --git a/challenge-060/yet-ebreo/perl/ch-1.pl b/challenge-060/yet-ebreo/perl/ch-1.pl new file mode 100644 index 0000000000..556dbc1ba4 --- /dev/null +++ b/challenge-060/yet-ebreo/perl/ch-1.pl @@ -0,0 +1,54 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature 'say'; + +sub to_num { + (ord) - 64 + 26 * (&to_num||0) if $_ = chop @_ +} +sub to_exl { + $% = pop; + while ($%>26) { + $" = chr (64 + $% - 26*($% /= 26)) . $"; + } + chr(64 + $%).$" +} +my $excelcol = uc $ARGV[0]; + +if ($excelcol=~/\D/) { + say to_num($excelcol); +} else { + say to_exl($excelcol); +} +=begin +perl .\ch-1.pl 1 +A + +perl .\ch-1.pl A +1 + +perl .\ch-1.pl 26 +Z + +perl .\ch-1.pl Z +26 + +perl .\ch-1.pl 661 +YK + +perl .\ch-1.pl YK +661 + +perl .\ch-1.pl 16384 +XFD + +perl .\ch-1.pl XFD +16384 + +perl .\ch-1.pl 214358502 +RABBIT + +perl .\ch-1.pl RABBIT +214358502 + +=cut \ No newline at end of file diff --git a/challenge-060/yet-ebreo/perl/ch-2.pl b/challenge-060/yet-ebreo/perl/ch-2.pl new file mode 100644 index 0000000000..79ec00f0a4 --- /dev/null +++ b/challenge-060/yet-ebreo/perl/ch-2.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature 'say'; +use Algorithm::Combinatorics qw(variations); + +my @L = (0, 1, 2, 5); +my $X = 2; +my $Y = 21; +if (@ARGV > 2) { + $Y = pop @ARGV; + $X = pop @ARGV; + @L = @ARGV; +} + +say @{$_} for grep { + (($X == length ($% = join "",@{$_})) && ($% < $Y)) +} variations(\@L,$X); + +=begin +perl .\ch-2.pl +10 +12 +15 +20 + +perl .\ch-2.pl 0 1 3 9 1 5 +0 +1 +3 + +perl .\ch-2.pl 0 1 3 9 2 20 +10 +13 +19 + +perl .\ch-2.pl 0 1 3 9 3 600 +103 +109 +130 +139 +190 +193 +301 +309 +310 +319 +390 +391 +=cut \ No newline at end of file -- cgit