diff options
| author | Michael Firkins <michael@firkins> | 2023-08-06 05:33:14 +1000 |
|---|---|---|
| committer | Michael Firkins <michael@firkins> | 2023-08-06 05:44:52 +1000 |
| commit | 68a2994eabcc7d36509d89fac95795466a20a296 (patch) | |
| tree | 6c9f1cec9af288bd84dadb9e306d699f576bafe4 | |
| parent | 10ec616c81e28fa2bdd7230718941fc16f28d49a (diff) | |
| download | perlweeklychallenge-club-68a2994eabcc7d36509d89fac95795466a20a296.tar.gz perlweeklychallenge-club-68a2994eabcc7d36509d89fac95795466a20a296.tar.bz2 perlweeklychallenge-club-68a2994eabcc7d36509d89fac95795466a20a296.zip | |
pwc228 solution in python
| -rw-r--r-- | challenge-228/pokgopun/python/ch-1.py | 25 | ||||
| -rw-r--r-- | challenge-228/pokgopun/python/ch-2.py | 39 |
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-228/pokgopun/python/ch-1.py b/challenge-228/pokgopun/python/ch-1.py new file mode 100644 index 0000000000..c9f2c99c32 --- /dev/null +++ b/challenge-228/pokgopun/python/ch-1.py @@ -0,0 +1,25 @@ +### Task 1: Unique Sum +### Submitted by: Mohammad S Anwar +### You are given an array of integers. +### +### Write a script to find out the sum of unique elements in the given array. +### +### Example 1 +### Input: @int = (2, 1, 3, 2) +### Output: 4 +### +### In the given array we have 2 unique elements (1, 3). +### Example 2 +### Input: @int = (1, 1, 1, 1) +### Output: 0 +### +### In the given array no unique element found. +### Example 3 +### Input: @int = (2, 1, 3, 4) +### Output: 10 +### +### In the given array every element is unique. + +def sumOfUniqElem(tup): return sum(tuple(filter(lambda x: tup.count(x)==1, tup))) + +for tup, s in ((2,1,3,2), 4), ((1,1,1,1), 0), ((2,1,3,4), 10): assert sumOfUniqElem(tup)==s diff --git a/challenge-228/pokgopun/python/ch-2.py b/challenge-228/pokgopun/python/ch-2.py new file mode 100644 index 0000000000..d4f65de3ba --- /dev/null +++ b/challenge-228/pokgopun/python/ch-2.py @@ -0,0 +1,39 @@ +### Task 2: Empty Array +### Submitted by: Mohammad S Anwar +### You are given an array of integers in which all elements are unique. +### +### Write a script to perform the following operations until the array is empty and return the total count of operations. +### +### +### If the first element is the smallest then remove it otherwise move it to the end. +### +### Example 1 +### Input: @int = (3, 4, 2) +### Ouput: 5 +### +### Operation 1: move 3 to the end: (4, 2, 3) +### Operation 2: move 4 to the end: (2, 3, 4) +### Operation 3: remove element 2: (3, 4) +### Operation 4: remove element 3: (4) +### Operation 5: remove element 4: () +### Example 2 +### Input: @int = (1, 2, 3) +### Ouput: 3 +### +### Operation 1: remove element 1: (2, 3) +### Operation 2: remove element 2: (3) +### Operation 3: remove element 3: () + +def cntEmptyOp(lst): + #print(lst,end=" ") + cnt = 0 + while len(lst)!=0: + cnt += 1 + if lst[0]!=min(lst): + lst.append(lst[0]) + lst.pop(0) + #print(cnt) + return cnt + +for lst, cnt in ([3,4,2], 5), ([1,2,3], 3): assert cntEmptyOp(lst)==cnt + |
