aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Manring <michael@manring>2023-11-27 21:51:47 +1100
committerMichael Manring <michael@manring>2023-11-28 13:26:06 +1100
commit7a0976d301a1090cbf3a9ae302e45b9a612d29b3 (patch)
tree61b845d8443780012708822d64a439a080f08b5a
parenta91d49494a545d745c5c622afa3a9646bf1ac774 (diff)
downloadperlweeklychallenge-club-7a0976d301a1090cbf3a9ae302e45b9a612d29b3.tar.gz
perlweeklychallenge-club-7a0976d301a1090cbf3a9ae302e45b9a612d29b3.tar.bz2
perlweeklychallenge-club-7a0976d301a1090cbf3a9ae302e45b9a612d29b3.zip
pwc245 solution in python
-rw-r--r--challenge-245/pokgopun/python/ch-1.py42
-rw-r--r--challenge-245/pokgopun/python/ch-2.py59
2 files changed, 101 insertions, 0 deletions
diff --git a/challenge-245/pokgopun/python/ch-1.py b/challenge-245/pokgopun/python/ch-1.py
new file mode 100644
index 0000000000..566c3310b1
--- /dev/null
+++ b/challenge-245/pokgopun/python/ch-1.py
@@ -0,0 +1,42 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-245/
+"""
+
+Task 1: Sort Language
+
+Submitted by: [45]Mohammad S Anwar
+ __________________________________________________________________
+
+ You are given two array of languages and its popularity.
+
+ Write a script to sort the language based on popularity.
+
+Example 1
+
+Input: @lang = ('perl', 'c', 'python')
+ @popularity = (2, 1, 3)
+Output: ('c', 'perl', 'python')
+
+Example 2
+
+Input: @lang = ('c++', 'haskell', 'java')
+ @popularity = (1, 3, 2)
+Output: ('c++', 'java', 'haskell')
+
+Task 2: Largest of Three
+"""
+### solution by pokgopun@gmail.com
+
+def sortL(tup1,tup2: tuple):
+ return tuple(
+ tup[0] for tup in
+ sorted(
+ map(lambda e1,e2: (e1,e2), tup1, tup2),
+ key=lambda tup: tup[1]
+ )
+ )
+
+for (inpt1,inpt2), otpt in {
+ (('perl', 'c', 'python'), (2, 1, 3)): ('c', 'perl', 'python'),
+ (('c++', 'haskell', 'java'), (1, 3, 2)): ('c++', 'java', 'haskell'),
+ }.items():
+ print(otpt==sortL(inpt1, inpt2))
diff --git a/challenge-245/pokgopun/python/ch-2.py b/challenge-245/pokgopun/python/ch-2.py
new file mode 100644
index 0000000000..d689e65c04
--- /dev/null
+++ b/challenge-245/pokgopun/python/ch-2.py
@@ -0,0 +1,59 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-245/
+"""
+
+Task 2: Largest of Three
+
+Submitted by: [46]Mohammad S Anwar
+ __________________________________________________________________
+
+ You are given an array of integers >= 0.
+
+ Write a script to return the largest number formed by concatenating
+ some of the given integers in any order which is also multiple of 3.
+ Return -1 if none found.
+
+Example 1
+
+Input: @digits = (8, 1, 9)
+Output: 981
+
+981 % 3 == 0
+
+Example 2
+
+Input: @digits = (8, 6, 7, 1, 0)
+Output: 8760
+
+Example 3
+
+Input: @digits = (1)
+Output: -1
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 3rd December
+ 2023.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+"""
+### solution by pokgopun@gmail.com
+
+from itertools import permutations
+
+def lot(tup: tuple):
+ for n in range(len(tup),0,-1):
+ for x in permutations(
+ sorted(tup,reverse=True), n
+ ):
+ y = int(
+ "".join( str(e) for e in x )
+ )
+ if y % 3 == 0: return y
+ return -1
+
+for inpt, otpt in {
+ (8, 1, 9): 981,
+ (8, 6, 7, 1, 0): 8760,
+ (1,): -1,
+ }.items():
+ print(otpt==lot(inpt))