aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels van Dijke <perlboy@cpan.org>2025-10-20 17:26:24 +0000
committerNiels van Dijke <perlboy@cpan.org>2025-10-20 17:26:24 +0000
commitb112e3588e197cd3aeebd2991b3cdb9968ed95a3 (patch)
treefba7ce4eb87feea761f09b9d5b9d5c2715985562
parent5fbd95540e261ce974dfcf7ee37057fa112524ba (diff)
downloadperlweeklychallenge-club-b112e3588e197cd3aeebd2991b3cdb9968ed95a3.tar.gz
perlweeklychallenge-club-b112e3588e197cd3aeebd2991b3cdb9968ed95a3.tar.bz2
perlweeklychallenge-club-b112e3588e197cd3aeebd2991b3cdb9968ed95a3.zip
w344 - Task 1 & 2 (Perl)
-rwxr-xr-xchallenge-344/perlboy1967/perl/ch1.pl35
-rwxr-xr-xchallenge-344/perlboy1967/perl/ch2.pl42
2 files changed, 77 insertions, 0 deletions
diff --git a/challenge-344/perlboy1967/perl/ch1.pl b/challenge-344/perlboy1967/perl/ch1.pl
new file mode 100755
index 0000000000..de180d81b9
--- /dev/null
+++ b/challenge-344/perlboy1967/perl/ch1.pl
@@ -0,0 +1,35 @@
+#!/bin/perl
+
+=pod
+
+L<https://theweeklychallenge.org/blog/perl-weekly-challenge-344#TASK1>
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 1: Array Form Compute
+Submitted by: Mohammad Sajid Anwar
+
+You are given an array of integers, @ints and an integer, $x.
+
+Write a script to add $x to the integer in the array-form.
+
+|| The array form of an integer is a digit-by-digit representation stored
+|| as an array, where the most significant digit is at the 0th index.
+
+=cut
+
+use Test2::V0 qw(-no_srand);
+use exact 'v5.32', -signatures;
+
+sub arrayFormCompute ($x,@ints) {
+ split(//,int(join('',@ints))+$x);
+}
+
+is([arrayFormCompute(12,1,2,3,4)],[1,2,4,6],'Example 1');
+is([arrayFormCompute(181,2,7,4)],[4,5,5],'Example 2');
+is([arrayFormCompute(1,9,9,9)],[1,0,0,0],'Example 3');
+is([arrayFormCompute(9999,1,0,0,0,0)],[1,9,9,9,9],'Example 4');
+is([arrayFormCompute(1000,0)],[1,0,0,0],'Example 5');
+is([arrayFormCompute(123,9,8,7)],[1,1,1,0],'Own example');
+
+done_testing;
diff --git a/challenge-344/perlboy1967/perl/ch2.pl b/challenge-344/perlboy1967/perl/ch2.pl
new file mode 100755
index 0000000000..200aafddbd
--- /dev/null
+++ b/challenge-344/perlboy1967/perl/ch2.pl
@@ -0,0 +1,42 @@
+#!/bin/perl
+
+=pod
+
+L<https://theweeklychallenge.org/blog/perl-weekly-challenge-344#TASK2>
+
+Author: Niels 'PerlBoy' van Dijke
+
+Task 2: Array Formation
+Submitted by: Mohammad Sajid Anwar
+
+You are given two list: @source and @target.
+
+Write a script to see if you can build the exact @target by putting these
+smaller lists from @source together in some order. You cannot break apart
+or change the order inside any of the smaller lists in @source.
+
+=cut
+
+use Test2::V0 qw(-no_srand);
+use exact 'v5.32', -signatures;
+
+use boolean;
+use Algorithm::Combinatorics qw(variations);
+
+sub arrayFormation ($arSrc,$arDst) {
+ my @src = map { join(',',@$_) } @$arSrc;
+ my $dst = join(',',@$arDst);
+ for my $a (variations(\@src,$#src + 1)) {
+ return true if (join(',',@$a) eq $dst);
+ }
+ return false;
+}
+
+is(arrayFormation([[2,3],[1],[4]],[1,2,3,4]),true,'Example 1');
+is(arrayFormation([[1,3],[2,4]],[1,2,3,4]),false,'Example 2');
+is(arrayFormation([[9,1],[5,8],[2]],[5,8,2,9,1]),true,'Example 3');
+is(arrayFormation([[1],[3]],[1,2,3]),false,'Example 4');
+is(arrayFormation([[7,4,6]],[7,4,6]),true,'Example 5');
+is(arrayFormation([[1,1,1],[0,1],[1],[0,0]],[0,1,1,1,1,1,0,0]),true,'Own example');
+
+done_testing;