diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-08-19 22:59:13 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-19 22:59:13 +0100 |
| commit | ca2f2ddc03aff6969a0c0f7002b4bf4f5be8b39d (patch) | |
| tree | 7fa920a56fe4a6055708c0b1d8ce17fd850be8ea | |
| parent | 67d8d944ad8182df368110fec1f5dd4847c5efa0 (diff) | |
| parent | 14ad32df3ca719eab1f4a9b1498818c9aca04505 (diff) | |
| download | perlweeklychallenge-club-ca2f2ddc03aff6969a0c0f7002b4bf4f5be8b39d.tar.gz perlweeklychallenge-club-ca2f2ddc03aff6969a0c0f7002b4bf4f5be8b39d.tar.bz2 perlweeklychallenge-club-ca2f2ddc03aff6969a0c0f7002b4bf4f5be8b39d.zip | |
Merge pull request #10666 from robbie-hatley/rh283
Robbie Hatley's solutions, in Perl, for The Weekly Challenge #283.
| -rw-r--r-- | challenge-283/robbie-hatley/blog.txt | 1 | ||||
| -rwxr-xr-x | challenge-283/robbie-hatley/perl/ch-1.pl | 20 | ||||
| -rwxr-xr-x | challenge-283/robbie-hatley/perl/ch-2.pl | 30 |
3 files changed, 51 insertions, 0 deletions
diff --git a/challenge-283/robbie-hatley/blog.txt b/challenge-283/robbie-hatley/blog.txt new file mode 100644 index 0000000000..dfb1cbf6d2 --- /dev/null +++ b/challenge-283/robbie-hatley/blog.txt @@ -0,0 +1 @@ +https://hatley-software.blogspot.com/2024/08/robbie-hatleys-solutions-to-weekly_19.html
\ No newline at end of file diff --git a/challenge-283/robbie-hatley/perl/ch-1.pl b/challenge-283/robbie-hatley/perl/ch-1.pl new file mode 100755 index 0000000000..e759a0a33b --- /dev/null +++ b/challenge-283/robbie-hatley/perl/ch-1.pl @@ -0,0 +1,20 @@ +#!/usr/bin/env perl +# The Weekly Challenge #282, Task 1, "Unique Number" +# Solution in Perl written 2024-08-18 by Robbie Hatley +# ./ch-1.pl '([2, 1, 3, 1, 2],[2,1,3,8,4,6])' +use v5.36; +use List::SomeUtils 'singleton'; +my @arrays = @ARGV ? eval $ARGV[0] : +( + [3, 3, 1], # 1 + [3, 2, 4, 2, 4], # 3 + [1], # 1 + [4, 3, 1, 1, 1, 4] # 3 +); +$"=', '; +foreach my $aref (@arrays) { + say ''; + my @singles = singleton @$aref; + say "Number Array = (@$aref)"; + say "Unique Number(s) = @singles"; +} diff --git a/challenge-283/robbie-hatley/perl/ch-2.pl b/challenge-283/robbie-hatley/perl/ch-2.pl new file mode 100755 index 0000000000..a55794ed9e --- /dev/null +++ b/challenge-283/robbie-hatley/perl/ch-2.pl @@ -0,0 +1,30 @@ +#!/usr/bin/env perl +# The Weekly Challenge #282, Task 2, "Digit Count Value" +# Solution in Perl written 2024-08-19 by Robbie Hatley +# ./ch-2.pl '([2, 1, 2, 0, 0],[2,1,3,0,0])' +use v5.36; +my @arrays = @ARGV ? eval $ARGV[0] : +( + [1, 2, 1, 0], # true + [0, 3, 0], # false +); +$"=', '; +foreach my $aref (@arrays) { + say ''; + my %digit_count = map {$_ => 0} 0..$#$aref; + for my $number (@$aref) { + for my $digit (split '', $number) { + ++$digit_count{$digit}; + } + } + my $truth = 1; + for my $index (0..$#$aref) { + if ($digit_count{$index} != $$aref[$index]) { + $truth = 0; + last; + } + } + say "Array = (@$aref)"; + print 'Digit count = value? '; + $truth and say 'true' or say 'false'; +} |
