aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-03-18 04:20:06 +0000
committerGitHub <noreply@github.com>2024-03-18 04:20:06 +0000
commit178c0bd245547d42152bb2e1cf22777728c4a762 (patch)
tree7d59888c40b6a38fadbf29ec8876a8caff247643
parent688b3b570509026b86bbc68d5055cba9117d11af (diff)
parent7c47c6b67bbce297462f1b82d79c61e9b307ba23 (diff)
downloadperlweeklychallenge-club-178c0bd245547d42152bb2e1cf22777728c4a762.tar.gz
perlweeklychallenge-club-178c0bd245547d42152bb2e1cf22777728c4a762.tar.bz2
perlweeklychallenge-club-178c0bd245547d42152bb2e1cf22777728c4a762.zip
Merge pull request #9762 from Hiranyaloka/ch-260
challenge-260 rick-bychowski ch-1.raku
-rw-r--r--challenge-260/rick-bychowski/raku/ch-1.raku58
1 files changed, 58 insertions, 0 deletions
diff --git a/challenge-260/rick-bychowski/raku/ch-1.raku b/challenge-260/rick-bychowski/raku/ch-1.raku
new file mode 100644
index 0000000000..ef1cfc1268
--- /dev/null
+++ b/challenge-260/rick-bychowski/raku/ch-1.raku
@@ -0,0 +1,58 @@
+#!/usr/bin/env raku
+# Unique Occurrences
+# https://theweeklychallenge.org/blog/perl-weekly-challenge-260/
+# This script takes input from the terminal.
+
+my %IntCount;
+
+sub MAIN( *@ints where .all ~~ Int ){
+ for @ints.sort -> $int {
+ if %IntCount{$int}:!exists { # start of a new integer
+ say 0 and exit unless &uniqueSoFar(%IntCount.values);
+ }
+ %IntCount{"$int"}++;
+
+ LAST { say 0 and exit unless &uniqueSoFar(%IntCount.values); }
+ }
+
+say 1;
+
+}
+
+sub uniqueSoFar(@counts where .all ~~ Int ){
+ if @counts.unique.elems !== @counts.elems {
+ False;
+ } else {
+ True;
+ }
+}
+
+=begin comment
+
+Task 1: Unique Occurrences
+Submitted by: Mohammad Sajid Anwar
+
+You are given an array of integers, @ints.
+
+Write a script to return 1 if the number of occurrences of each value in the given array is unique or 0 otherwise.
+Example 1
+
+Input: @ints = (1,2,2,1,1,3)
+Output: 1
+
+The number 1 occurred 3 times.
+The number 2 occurred 2 times.
+The number 3 occurred 1 time.
+
+All occurrences are unique, therefore the output is 1.
+
+Example 2
+
+Input: @ints = (1,2,3)
+Output: 0
+
+Example 3
+
+Input: @ints = (-2,0,1,-2,1,1,0,1,-2,9)
+Output: 1
+=end comment