aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-08-19 10:35:49 +0100
committerGitHub <noreply@github.com>2024-08-19 10:35:49 +0100
commitad2c688ba2d2473c667228fa3997c8da16ea790d (patch)
tree6aa855809738939d9fa8c1af7a3eca256bacc660
parent093475dc772277b1c2681568982bec7e4bed8cd0 (diff)
parent6255bb8b07d7f7e469fc48fd9c3f98a1d273b961 (diff)
downloadperlweeklychallenge-club-ad2c688ba2d2473c667228fa3997c8da16ea790d.tar.gz
perlweeklychallenge-club-ad2c688ba2d2473c667228fa3997c8da16ea790d.tar.bz2
perlweeklychallenge-club-ad2c688ba2d2473c667228fa3997c8da16ea790d.zip
Merge pull request #10651 from choroba/ech283
Sovle 283: Unique Number & Digit Count Value by E. Choroba
-rwxr-xr-xchallenge-283/e-choroba/perl/ch-1.pl17
-rwxr-xr-xchallenge-283/e-choroba/perl/ch-2.pl19
2 files changed, 36 insertions, 0 deletions
diff --git a/challenge-283/e-choroba/perl/ch-1.pl b/challenge-283/e-choroba/perl/ch-1.pl
new file mode 100755
index 0000000000..7c5520e286
--- /dev/null
+++ b/challenge-283/e-choroba/perl/ch-1.pl
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub unique_number(@ints) {
+ my %seen;
+ ++$seen{$_} for @ints;
+ return (grep 1 == $seen{$_}, keys %seen)[0]
+}
+
+use Test::More tests => 4;
+
+is unique_number(3, 3, 1), 1, 'Example 1';
+is unique_number(3, 2, 4, 2, 4), 3, 'Example 2';
+is unique_number(1), 1, 'Example 3';
+is unique_number(4, 3, 1, 1, 1, 4), 3, 'Example 4';
diff --git a/challenge-283/e-choroba/perl/ch-2.pl b/challenge-283/e-choroba/perl/ch-2.pl
new file mode 100755
index 0000000000..8572fa09ff
--- /dev/null
+++ b/challenge-283/e-choroba/perl/ch-2.pl
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use experimental qw( signatures );
+
+sub digit_count_value(@ints) {
+ my %seen;
+ ++$seen{$_} for @ints;
+ for my $i (0 .. $#ints) {
+ return unless $ints[$i] == ($seen{$i} // 0);
+ }
+ return 1
+}
+
+use Test::More tests => 2 + 1;
+
+ok digit_count_value(1, 2, 1, 0), 'Example 1';
+ok ! digit_count_value(0, 3, 0), 'Example 2';
+ok digit_count_value(10, 2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0), '>9';