diff options
| author | David Ferrone <zapwai@gmail.com> | 2025-02-10 02:12:23 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-10 02:12:23 -0500 |
| commit | 0060d882a3f85bb546fc58f7a37e4778735c71e4 (patch) | |
| tree | b17d129d950432a8058e5c82dc90779e5dbba2e2 | |
| parent | aa4b8399bdb3da0a50173fcab689bfa80b9b54e1 (diff) | |
| download | perlweeklychallenge-club-0060d882a3f85bb546fc58f7a37e4778735c71e4.tar.gz perlweeklychallenge-club-0060d882a3f85bb546fc58f7a37e4778735c71e4.tar.bz2 perlweeklychallenge-club-0060d882a3f85bb546fc58f7a37e4778735c71e4.zip | |
Week 308
| -rw-r--r-- | challenge-308/zapwai/perl/ch-1.pl | 28 | ||||
| -rw-r--r-- | challenge-308/zapwai/perl/ch-2.pl | 55 |
2 files changed, 83 insertions, 0 deletions
diff --git a/challenge-308/zapwai/perl/ch-1.pl b/challenge-308/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..7939b9d6f0 --- /dev/null +++ b/challenge-308/zapwai/perl/ch-1.pl @@ -0,0 +1,28 @@ +use v5.38; + +sub proc($s1, $s2) { + my @str1 = @$s1; + my @str2 = @$s2; + say "Input: \@str1 = @str1, \@str2 = @str2"; + my $cnt = 0; + for my $w1 (@str1) { + for my $w2 (@str2) { + if ($w1 eq $w2) { + $cnt++; + } + } + } + say "Output: $cnt"; +} + +my @str1 = ("perl", "weekly", "challenge"); +my @str2 = ("raku", "weekly", "challenge"); +proc(\@str1, \@str2); + +@str1 = ("perl", "raku", "python"); +@str2 = ("python", "java"); +proc(\@str1, \@str2); + +@str1 = ("guest", "contribution"); +@str2 = ("fun", "weekly", "challenge"); +proc(\@str1, \@str2); diff --git a/challenge-308/zapwai/perl/ch-2.pl b/challenge-308/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..d378e68b4f --- /dev/null +++ b/challenge-308/zapwai/perl/ch-2.pl @@ -0,0 +1,55 @@ +use v5.38; + +# Only tests values 0 through 9 (larger would require a rewrite) +# Returns an array of refs to arrays with these values. +sub setup($n) { + my @o; + for my $i (0 .. 10**$n - 1) { + my $lab = "%0$n"."d"; + my @a = split "", sprintf($lab, $i); + push @o, \@a; + } + return @o; +} + +sub enc($init, @enc) { + my @orig = ($init); + my @list = setup(scalar @enc); + push @orig, @{$list[0]}; + my $err = 0; + my $lvl = 0; + do { + $err = 0; + my @current; + for my $i (0 .. $#orig - 1) { + push @current, $orig[$i] ^ $orig[$i+1]; + } + say "@orig -> @current"; + for my $i (0 .. $#enc) { + if ($enc[$i] != $current[$i]) { + $err = 1; + $lvl++; + last; + } + } + unless ($err == 0) { + @orig = ($init); + push @orig, @{$list[$lvl]}; + } + } while ($err > 0); + return @orig; +} + +sub proc($init, @enc) { + say "Input: \@encoded = @enc, \$initial = $init"; + say "Output: ", enc($init, @enc); +} + +my $init = 1; +my @enc = (1, 2, 3); +proc($init, @enc); + +$init = 4; +@enc = (6,2,7,3); +proc($init, @enc); + |
