diff options
| -rw-r--r-- | challenge-272/dave-jacoby/perl/ch-1.pl | 24 | ||||
| -rw-r--r-- | challenge-272/dave-jacoby/perl/ch-2.pl | 25 |
2 files changed, 49 insertions, 0 deletions
diff --git a/challenge-272/dave-jacoby/perl/ch-1.pl b/challenge-272/dave-jacoby/perl/ch-1.pl new file mode 100644 index 0000000000..abaa466aae --- /dev/null +++ b/challenge-272/dave-jacoby/perl/ch-1.pl @@ -0,0 +1,24 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ bitwise fc postderef say signatures state }; + +use List::Util qw{max}; + +my @examples = ( + + "1.1.1.1", "255.101.1.0" +); +for my $example (@examples) { + my $output = defang_ipv4($example); + say <<"END"; + Input: \$ip = "$example" + Output: "$output" +END +} + +sub defang_ipv4 ( $address ) { + $address =~ s/\./[.]/gmx; + return $address; +} diff --git a/challenge-272/dave-jacoby/perl/ch-2.pl b/challenge-272/dave-jacoby/perl/ch-2.pl new file mode 100644 index 0000000000..79650b52d9 --- /dev/null +++ b/challenge-272/dave-jacoby/perl/ch-2.pl @@ -0,0 +1,25 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use experimental qw{ fc say postderef signatures state }; + +use List::Util qw{ sum0 }; + +my @examples = (qw{ hello perl raku weekly linux Perl PERL }); + +for my $example (@examples) { + my $output = string_score($example); + + say <<"END"; + Input: \$str = "$example" + Output: $output +END +} + +sub string_score ($str) { + my @str = split //, $str; + return sum0 + map { abs ord( $str[$_] ) - ord( $str[ 1 + $_ ] ) } + 0 .. -2 + scalar @str; +} |
