diff options
| author | David Ferrone <zapwai@gmail.com> | 2025-06-30 08:59:38 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-30 08:59:38 -0400 |
| commit | f19da3a6aa52ccf7a1607de4054e55fbe5b07b93 (patch) | |
| tree | 8a0d45863f42ae85840b2f40ff4a68c4f4a456a8 | |
| parent | 7daf92e1dd4a2726fc578e87b6364ba4db3d5ad9 (diff) | |
| download | perlweeklychallenge-club-f19da3a6aa52ccf7a1607de4054e55fbe5b07b93.tar.gz perlweeklychallenge-club-f19da3a6aa52ccf7a1607de4054e55fbe5b07b93.tar.bz2 perlweeklychallenge-club-f19da3a6aa52ccf7a1607de4054e55fbe5b07b93.zip | |
Week 328
| -rw-r--r-- | challenge-328/zapwai/perl/ch-1.pl | 31 | ||||
| -rw-r--r-- | challenge-328/zapwai/perl/ch-2.pl | 46 |
2 files changed, 77 insertions, 0 deletions
diff --git a/challenge-328/zapwai/perl/ch-1.pl b/challenge-328/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..cd98146861 --- /dev/null +++ b/challenge-328/zapwai/perl/ch-1.pl @@ -0,0 +1,31 @@ +use v5.38; + +sub proc($str) { + say "Input: $str"; + my @letter = ('a' .. 'z'); + my $index = index $str, '?'; + my ($a, $b) = (substr($str, $index - 1, 1), substr($str, $index + 1, 1)); + my $current_ind = 0; + my $next_letter = $letter[$current_ind]; + my $end_flag = 0; + do { + if ($next_letter eq $a || $next_letter eq $b) { + $current_ind++; + $next_letter = $letter[$current_ind]; + } else { + $end_flag = 1; + } + } while ($end_flag == 0); + my ($pre, $post) = split '\?', $str; + say "Output: ".$pre.$next_letter.$post; +} + + +my $str = "a?z"; +proc($str); + +$str = "pe?k"; +proc($str); + +$str = "gra?te"; +proc($str); diff --git a/challenge-328/zapwai/perl/ch-2.pl b/challenge-328/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..793a875276 --- /dev/null +++ b/challenge-328/zapwai/perl/ch-2.pl @@ -0,0 +1,46 @@ +use v5.38; + +sub where_badspot($s) { + my @l = split '', $s; + for my $i (0 .. $#l - 1) { + my $let = $l[$i]; + my $next_let = $l[$i+1]; + if ($let eq uc($let)) { + return $i if (lc($let) eq $next_let) + } else { + return $i if (uc($let) eq $next_let); + } + } + return -1; +} + +sub strip_it($s, $badspot) { + my $out = substr $s, 0, $badspot; + $out .= substr $s, $badspot + 2; + return $out; +} + +sub proc($str) { + say " Input: $str"; + my $out = $str; + my $clear_flag = 0; + while ($clear_flag == 0) { + my $badspot = where_badspot($out); + + if ($badspot != -1) { + $out = strip_it($out, $badspot); + } else { + $clear_flag = 1; + } + } + say "Output: $out"; +} + +my $str = "WeEeekly"; +proc($str); + +$str = "abBAdD"; +proc($str); + +$str = "abc"; +proc($str); |
