diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2025-10-20 16:58:24 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-20 16:58:24 +0100 |
| commit | 825716d3c81ed9d4659931c741b83b03717e5d47 (patch) | |
| tree | 53a2ba3adb459869e73eefb03655875d333c7cee | |
| parent | d821c7cb2589513d6504f298c6ce1e1c696d0f8e (diff) | |
| parent | a64aee4cd23cb17869af853b1140418150b9916c (diff) | |
| download | perlweeklychallenge-club-825716d3c81ed9d4659931c741b83b03717e5d47.tar.gz perlweeklychallenge-club-825716d3c81ed9d4659931c741b83b03717e5d47.tar.bz2 perlweeklychallenge-club-825716d3c81ed9d4659931c741b83b03717e5d47.zip | |
Merge pull request #12884 from zapwai/branch-for-344
Week 344
| -rw-r--r-- | challenge-344/zapwai/perl/ch-1.pl | 25 | ||||
| -rw-r--r-- | challenge-344/zapwai/perl/ch-2.pl | 41 |
2 files changed, 66 insertions, 0 deletions
diff --git a/challenge-344/zapwai/perl/ch-1.pl b/challenge-344/zapwai/perl/ch-1.pl new file mode 100644 index 0000000000..d846bcf00e --- /dev/null +++ b/challenge-344/zapwai/perl/ch-1.pl @@ -0,0 +1,25 @@ +use v5.38; + +sub proc($x, @ints) { + say "Input: \@ints = @ints, \$x = $x"; + my $num = join '', @ints; + my $sum = $x + $num; + my @o = split "", $sum; + say "Output: @o"; +} + +my $x = 12; +my @ints = (1,2,3,4); +proc($x, @ints); +$x = 181; +@ints = (2,7,4); +proc($x, @ints); +$x = 1; +@ints = (9,9,9); +proc($x, @ints); +$x = 9999; +@ints = (1,0,0,0,0); +proc($x, @ints); +$x = 1000; +@ints = (0); +proc($x, @ints); diff --git a/challenge-344/zapwai/perl/ch-2.pl b/challenge-344/zapwai/perl/ch-2.pl new file mode 100644 index 0000000000..5cf860cad6 --- /dev/null +++ b/challenge-344/zapwai/perl/ch-2.pl @@ -0,0 +1,41 @@ +use v5.38; +use Algorithm::Permute; + +sub proc($r, $s) { + my @source = @$r; + my @target = @$s; + print "Input: \@source = "; + print "[@$_]\t" for (@source); + say "\n\t\@target = @target"; + my $t = join '', @target; + + my @piece; + push @piece, join '', @$_ for (@source); + my $o = "false"; + my @ind = (0 .. $#piece); + my $p = Algorithm::Permute->new(\@ind); + while (my @perm = $p->next) { + my $permutation = ""; + for my $i (@perm) { + $permutation .= $piece[$i]; + } + $o = "true" if ($permutation eq $t); + } + say "Output: $o\n"; +} + +my @source = ([2,3], [1], [4]); +my @target = (1, 2, 3, 4); +proc(\@source, \@target); +@source = ([1,3], [2,4]); +@target = (1, 2, 3, 4); +proc(\@source, \@target); +@source = ([9,1], [5,8], [2]); +@target = (5, 8, 2, 9, 1); +proc(\@source, \@target); +@source = ([1], [3]); +@target = (1, 2, 3); +proc(\@source, \@target); +@source = ([7,4,6]); +@target = (7, 4, 6); +proc(\@source, \@target); |
