diff options
| -rw-r--r-- | challenge-058/yet-ebreo/perl/ch-1.pl | 36 | ||||
| -rw-r--r-- | challenge-058/yet-ebreo/perl/ch-2.pl | 28 |
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-058/yet-ebreo/perl/ch-1.pl b/challenge-058/yet-ebreo/perl/ch-1.pl new file mode 100644 index 0000000000..4b9d6eaad8 --- /dev/null +++ b/challenge-058/yet-ebreo/perl/ch-1.pl @@ -0,0 +1,36 @@ +#!/usr/bin/perl +use strict; +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; +} + +my @num_set = ( + [qw(0.1 1.1)], + [qw(2.0 1.2)], + [qw(1.2 1.2_5)], + [qw(1.2.1 1.2_1)], + [qw(1.2.1 1.2.1)], +); + +#leading 0's are ignored such that 1.002 is eq 1.2 +for my $num (@num_set) { + my $c = compare(@{$num}); + printf "%10s %s %-10s %2s\n", $num->[0], qw(< 0 >)[$c+1], $num->[1], $c ; +} + +=begin +perl .\ch-1.pl + 0.1 < 1.1 -1 + 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 +=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 new file mode 100644 index 0000000000..f65e5b319d --- /dev/null +++ b/challenge-058/yet-ebreo/perl/ch-2.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl +use strict; +use warnings; +use feature 'say'; + +my %hash; + +my @heights = qw(2 6 4 5 1 3); +my @taller = qw(1 0 2 0 1 2); +@heights = eval "qw($ARGV[0])" if $ARGV[0]; +@taller = eval "qw($ARGV[1])" if $ARGV[1]; + +@hash{@heights} = @taller; +my @sorted = sort {$b-$a} keys %hash; + +for my $i (0..$#sorted) { + splice @sorted, $hash{$sorted[$i]}, 0, splice @sorted, $i, 1; +} + +say "@sorted"; + +=begin +perl .\ch-2.pl +5 1 2 6 3 4 + +perl .\ch-2.pl "1 2 3 4 5 6" "2 1 1 1 1 0" +6 2 1 3 4 5 +=cut |
