aboutsummaryrefslogtreecommitdiff
path: root/challenge-260/pokgopun/python/ch-1.py
diff options
context:
space:
mode:
authorrir <rirans@comcast.net>2024-03-16 20:07:25 -0400
committerGitHub <noreply@github.com>2024-03-16 20:07:25 -0400
commitff5e8ece15a2384fbfb530710f10aa485017d4a5 (patch)
tree6fe268d9ceb2b25a2951ea984c077450feb2efae /challenge-260/pokgopun/python/ch-1.py
parent60f1003122fbada697317d943c238593f86db579 (diff)
parent62e7fc3bb85a74125663f4fbd0a5911f6f30c81f (diff)
downloadperlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.tar.gz
perlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.tar.bz2
perlweeklychallenge-club-ff5e8ece15a2384fbfb530710f10aa485017d4a5.zip
Merge branch 'manwar:master' into work
Diffstat (limited to 'challenge-260/pokgopun/python/ch-1.py')
-rw-r--r--challenge-260/pokgopun/python/ch-1.py56
1 files changed, 56 insertions, 0 deletions
diff --git a/challenge-260/pokgopun/python/ch-1.py b/challenge-260/pokgopun/python/ch-1.py
new file mode 100644
index 0000000000..734382ae7c
--- /dev/null
+++ b/challenge-260/pokgopun/python/ch-1.py
@@ -0,0 +1,56 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-260/
+"""
+
+Task 1: Unique Occurrences
+
+Submitted by: [42]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
+
+Task 2: Dictionary Rank
+"""
+### solution by pokgopun@gmail.com
+
+def UO(tup: tuple):
+ s = set(tup)
+ return len(s)==len(set(tup.count(e) for e in s))
+
+import unittest
+
+class TestUO(unittest.TestCase):
+ def test(self):
+ for inpt, otpt in {
+ (1,2,2,1,1,3): 1,
+ (1,2,3): 0,
+ (-2,0,1,-2,1,1,0,1,-2,9): 1,
+ }.items():
+ self.assertEqual(UO(inpt),otpt)
+
+unittest.main()
+
+