From 14ad32df3ca719eab1f4a9b1498818c9aca04505 Mon Sep 17 00:00:00 2001 From: robbie-hatley Date: Mon, 19 Aug 2024 13:32:49 -0700 Subject: Robbie Hatley's solutions, in Perl, for The Weekly Challenge #283. --- challenge-283/robbie-hatley/blog.txt | 1 + challenge-283/robbie-hatley/perl/ch-1.pl | 20 ++++++++++++++++++++ challenge-283/robbie-hatley/perl/ch-2.pl | 30 ++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 challenge-283/robbie-hatley/blog.txt create mode 100755 challenge-283/robbie-hatley/perl/ch-1.pl create mode 100755 challenge-283/robbie-hatley/perl/ch-2.pl 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'; +} -- cgit