aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-08-19 12:12:46 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-08-19 12:28:12 +0100
commitde4d41bd5196fc44f5548c8303c93a6f62db32d8 (patch)
tree2f9abdba0f30706ee1b5445f621b81056e9575bd
parent774f46dff430c3ac4d85635e184465702b69f1f4 (diff)
downloadperlweeklychallenge-club-de4d41bd5196fc44f5548c8303c93a6f62db32d8.tar.gz
perlweeklychallenge-club-de4d41bd5196fc44f5548c8303c93a6f62db32d8.tar.bz2
perlweeklychallenge-club-de4d41bd5196fc44f5548c8303c93a6f62db32d8.zip
Add Perl solution to challenge 283
-rw-r--r--challenge-283/paulo-custodio/Makefile2
-rw-r--r--challenge-283/paulo-custodio/README1
-rw-r--r--challenge-283/paulo-custodio/perl/ch-1.pl39
-rw-r--r--challenge-283/paulo-custodio/perl/ch-2.pl47
-rw-r--r--challenge-283/paulo-custodio/t/test-1.yaml20
-rw-r--r--challenge-283/paulo-custodio/t/test-2.yaml10
6 files changed, 119 insertions, 0 deletions
diff --git a/challenge-283/paulo-custodio/Makefile b/challenge-283/paulo-custodio/Makefile
new file mode 100644
index 0000000000..c3c762d746
--- /dev/null
+++ b/challenge-283/paulo-custodio/Makefile
@@ -0,0 +1,2 @@
+all:
+ perl ../../challenge-001/paulo-custodio/test.pl
diff --git a/challenge-283/paulo-custodio/README b/challenge-283/paulo-custodio/README
new file mode 100644
index 0000000000..87dc0b2fbd
--- /dev/null
+++ b/challenge-283/paulo-custodio/README
@@ -0,0 +1 @@
+Solution by Paulo Custodio
diff --git a/challenge-283/paulo-custodio/perl/ch-1.pl b/challenge-283/paulo-custodio/perl/ch-1.pl
new file mode 100644
index 0000000000..a1d4008c9c
--- /dev/null
+++ b/challenge-283/paulo-custodio/perl/ch-1.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+
+# Challenge 283
+#
+# Task 1: Unique Number
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given an array of integers, @ints, where every elements appears more than once except one element.
+#
+# Write a script to find the one element that appears exactly one time.
+# Example 1
+#
+# Input: @ints = (3, 3, 1)
+# Output: 1
+#
+# Example 2
+#
+# Input: @ints = (3, 2, 4, 2, 4)
+# Output: 3
+#
+# Example 3
+#
+# Input: @ints = (1)
+# Output: 1
+#
+# Example 4
+#
+# Input: @ints = (4, 3, 1, 1, 1, 4)
+# Output: 3
+
+use Modern::Perl;
+
+my @ints = @ARGV;
+my %count;
+for (@ints) {
+ $count{$_}++;
+}
+my($unique) = map {$_->[0]} grep {$count{$_->[0]}==1} map {[$_, $count{$_}]} @ints;
+say $unique;
diff --git a/challenge-283/paulo-custodio/perl/ch-2.pl b/challenge-283/paulo-custodio/perl/ch-2.pl
new file mode 100644
index 0000000000..716d644f92
--- /dev/null
+++ b/challenge-283/paulo-custodio/perl/ch-2.pl
@@ -0,0 +1,47 @@
+#!/usr/bin/env perl
+
+# Challenge 283
+#
+# Task 2: Digit Count Value
+# Submitted by: Mohammad Sajid Anwar
+#
+# You are given an array of positive integers, @ints.
+#
+# Write a script to return true if for every index i in the range 0 <= i < size
+# of array, the digit i occurs exactly the $ints[$i] times in the given array
+# otherwise return false.
+# Example 1
+#
+# Input: @ints = (1, 2, 1, 0)
+# Ouput: true
+#
+# $ints[0] = 1, the digit 0 occurs exactly 1 time.
+# $ints[1] = 2, the digit 1 occurs exactly 2 times.
+# $ints[2] = 1, the digit 2 occurs exactly 1 time.
+# $ints[3] = 0, the digit 3 occurs 0 time.
+#
+# Example 2
+#
+# Input: @ints = (0, 3, 0)
+# Ouput: false
+#
+# $ints[0] = 0, the digit 0 occurs 2 times rather than 0 time.
+# $ints[1] = 3, the digit 1 occurs 0 time rather than 3 times.
+# $ints[2] = 0, the digit 2 occurs exactly 0 time.
+
+use Modern::Perl;
+
+my @ints = @ARGV;
+say digit_count_true(@ints) ? "true" : "false";
+
+sub digit_count_true {
+ my(@ints) = @_;
+ my %count;
+ for (@ints) {
+ $count{$_}++;
+ }
+ for (0 .. $#ints) {
+ return 0 if ($count{$_}//0) != $ints[$_];
+ }
+ return 1;
+}
diff --git a/challenge-283/paulo-custodio/t/test-1.yaml b/challenge-283/paulo-custodio/t/test-1.yaml
new file mode 100644
index 0000000000..bca16fb292
--- /dev/null
+++ b/challenge-283/paulo-custodio/t/test-1.yaml
@@ -0,0 +1,20 @@
+- setup:
+ cleanup:
+ args: 3 3 1
+ input:
+ output: 1
+- setup:
+ cleanup:
+ args: 3 2 4 2 4
+ input:
+ output: 3
+- setup:
+ cleanup:
+ args: 1
+ input:
+ output: 1
+- setup:
+ cleanup:
+ args: 4 3 1 1 1 4
+ input:
+ output: 3
diff --git a/challenge-283/paulo-custodio/t/test-2.yaml b/challenge-283/paulo-custodio/t/test-2.yaml
new file mode 100644
index 0000000000..8a8cf09983
--- /dev/null
+++ b/challenge-283/paulo-custodio/t/test-2.yaml
@@ -0,0 +1,10 @@
+- setup:
+ cleanup:
+ args: 1 2 1 0
+ input:
+ output: true
+- setup:
+ cleanup:
+ args: 0 3 0
+ input:
+ output: false