From a82c0c8a3e188cc1d9b4c6d4379d072a902948c1 Mon Sep 17 00:00:00 2001 From: Nuno Vieira Date: Thu, 21 Jan 2021 23:05:32 +0000 Subject: Add nunovieira220 perl solution to challenge 096 --- challenge-096/nunovieira220/perl/ch-1.pl | 17 +++++++++++++++++ challenge-096/nunovieira220/perl/ch-2.pl | 28 ++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 challenge-096/nunovieira220/perl/ch-1.pl create mode 100644 challenge-096/nunovieira220/perl/ch-2.pl diff --git a/challenge-096/nunovieira220/perl/ch-1.pl b/challenge-096/nunovieira220/perl/ch-1.pl new file mode 100644 index 0000000000..87cf5afacb --- /dev/null +++ b/challenge-096/nunovieira220/perl/ch-1.pl @@ -0,0 +1,17 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature qw(say); + +# Input +my $S = " Perl and Raku are part of the same family "; + +# Reverse Words +$S =~ s/^\s+|\s+$//g; +$S =~ s/\s+/ /g; + +my $res = join(" ", reverse(split(" ", $S))); + +# Output +say($res); \ No newline at end of file diff --git a/challenge-096/nunovieira220/perl/ch-2.pl b/challenge-096/nunovieira220/perl/ch-2.pl new file mode 100644 index 0000000000..7603957e12 --- /dev/null +++ b/challenge-096/nunovieira220/perl/ch-2.pl @@ -0,0 +1,28 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature qw(say); +use List::Util qw[max]; + +# Input +my $S1 = "kitten"; +my $S2 = "sitting"; + +# Edit Distance +my $maxLength = max(length($S1), length($S2)); + +for(my $i = 0; $i < $maxLength; $i++) { + my $char1 = substr($S1, $i, 1); + my $char2 = substr($S2, $i, 1); + + if(notEmpty($char1) && notEmpty($char2)) { + say("Replace '$char1' with '$char2'"); + } elsif (notEmpty($char1)) { + say("Remove '$char1' at position ".($i + 1)); + } else { + say("Insert '$char2' at the end"); + } +} + +sub notEmpty { return defined $_[0] && !$_[0] eq '' ? 1 : 0 } -- cgit