aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYsmael Ebreo <Ysmael.Ebreo@latticesemi.com>2020-04-28 11:33:47 +0800
committerYsmael Ebreo <Ysmael.Ebreo@latticesemi.com>2020-04-28 11:33:47 +0800
commitdc465088b9f06e0c95addfe22b548dcd5d2f8545 (patch)
tree6f8e71de5ca579b8aba645c1d8e2809eed360f22
parente6d2ca1282845b4318429b83d12631ab5ff04a50 (diff)
downloadperlweeklychallenge-club-dc465088b9f06e0c95addfe22b548dcd5d2f8545.tar.gz
perlweeklychallenge-club-dc465088b9f06e0c95addfe22b548dcd5d2f8545.tar.bz2
perlweeklychallenge-club-dc465088b9f06e0c95addfe22b548dcd5d2f8545.zip
small update
-rw-r--r--challenge-058/yet-ebreo/perl/ch-1.pl23
-rw-r--r--challenge-058/yet-ebreo/perl/ch-2.pl2
2 files changed, 15 insertions, 10 deletions
diff --git a/challenge-058/yet-ebreo/perl/ch-1.pl b/challenge-058/yet-ebreo/perl/ch-1.pl
index 4b9d6eaad8..7aa7c804ae 100644
--- a/challenge-058/yet-ebreo/perl/ch-1.pl
+++ b/challenge-058/yet-ebreo/perl/ch-1.pl
@@ -4,12 +4,9 @@ use warnings;
use feature 'say';
sub compare {
- my ($n,$m)=@_;
- $n =~ s/_/!/g;
- $m =~ s/_/!/g;
- $n =~ s/\d+/0|$&/ge;
- $m =~ s/\d+/0|$&/ge;
- $n cmp $m;
+ $_[0] =~ s/[._]0+$//r =~s/_/!/gr =~ s/\d+/0|$&/gre
+ cmp
+ $_[1] =~ s/[._]0+$//r =~s/_/!/gr =~ s/\d+/0|$&/gre;
}
my @num_set = (
@@ -18,12 +15,17 @@ my @num_set = (
[qw(1.2 1.2_5)],
[qw(1.2.1 1.2_1)],
[qw(1.2.1 1.2.1)],
+ [qw(3_3 3.3)],
+ [qw(1.01.1 1.1.1)],
+ [qw(2_0 2.0)],
);
-#leading 0's are ignored such that 1.002 is eq 1.2
+#Notes:
+# - leading 0's are ignored such that 1.002 is eq 1.2
+# - 2_00 , 2.0 and 2 are considered equal
for my $num (@num_set) {
my $c = compare(@{$num});
- printf "%10s %s %-10s %2s\n", $num->[0], qw(< 0 >)[$c+1], $num->[1], $c ;
+ printf "%10s %s %-10s %2s\n", $num->[0], qw(< = >)[$c+1], $num->[1], $c ;
}
=begin
@@ -32,5 +34,8 @@ perl .\ch-1.pl
2.0 > 1.2 1
1.2 < 1.2_5 -1
1.2.1 > 1.2_1 1
- 1.2.1 0 1.2.1 0
+ 1.2.1 = 1.2.1 0
+ 3_3 < 3.3 -1
+ 1.01.1 = 1.1.1 0
+ 2_0 = 2.0 0
=cut \ No newline at end of file
diff --git a/challenge-058/yet-ebreo/perl/ch-2.pl b/challenge-058/yet-ebreo/perl/ch-2.pl
index f65e5b319d..994378e255 100644
--- a/challenge-058/yet-ebreo/perl/ch-2.pl
+++ b/challenge-058/yet-ebreo/perl/ch-2.pl
@@ -11,7 +11,7 @@ my @taller = qw(1 0 2 0 1 2);
@taller = eval "qw($ARGV[1])" if $ARGV[1];
@hash{@heights} = @taller;
-my @sorted = sort {$b-$a} keys %hash;
+my @sorted = sort {$b-$a} @heights;
for my $i (0..$#sorted) {
splice @sorted, $hash{$sorted[$i]}, 0, splice @sorted, $i, 1;