aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-04-10 12:20:51 +0100
committerGitHub <noreply@github.com>2024-04-10 12:20:51 +0100
commitfc1a26a24e1e2484bb472c14705d0e55068d4530 (patch)
tree9f61fbd8943830997374a8ecbb72e7166c5c4261
parent7508921b1d25a45066b61c68ae00fe2a31002692 (diff)
parent50386d1884b49f7268d6aa6662872be9ff4a2538 (diff)
downloadperlweeklychallenge-club-fc1a26a24e1e2484bb472c14705d0e55068d4530.tar.gz
perlweeklychallenge-club-fc1a26a24e1e2484bb472c14705d0e55068d4530.tar.bz2
perlweeklychallenge-club-fc1a26a24e1e2484bb472c14705d0e55068d4530.zip
Merge pull request #9909 from pokgopun/pwc264
Pwc264
-rw-r--r--challenge-264/pokgopun/go/ch-1.go80
-rw-r--r--challenge-264/pokgopun/go/ch-2.go90
-rw-r--r--challenge-264/pokgopun/python/ch-1.py57
-rw-r--r--challenge-264/pokgopun/python/ch-2.py73
4 files changed, 300 insertions, 0 deletions
diff --git a/challenge-264/pokgopun/go/ch-1.go b/challenge-264/pokgopun/go/ch-1.go
new file mode 100644
index 0000000000..d5e7f029f3
--- /dev/null
+++ b/challenge-264/pokgopun/go/ch-1.go
@@ -0,0 +1,80 @@
+//# https://theweeklychallenge.org/blog/perl-weekly-challenge-264/
+/*#
+
+Task 1: Greatest English Letter
+
+Submitted by: [47]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given a string, $str, made up of only alphabetic characters
+ [a..zA..Z].
+
+ Write a script to return the greatest english letter in the given
+ string.
+
+ A letter is greatest if it occurs as lower and upper case. Also
+ letter ‘b’ is greater than ‘a’ if ‘b’ appears after ‘a’ in the
+ English alphabet.
+
+Example 1
+
+Input: $str = 'PeRlwEeKLy'
+Output: L
+
+There are two letters E and L that appears as lower and upper.
+The letter L appears after E, so the L is the greatest english letter.
+
+Example 2
+
+Input: $str = 'ChaLlenge'
+Output: L
+
+Example 3
+
+Input: $str = 'The'
+Output: ''
+
+Task 2: Target Array
+#*/
+//# solution by pokgopun@gmail.com
+
+package main
+
+import (
+ "io"
+ "os"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+func gel(s string) string {
+ seen := make(map[byte]bool)
+ var mx byte
+ for _, v := range []byte(s) {
+ if v > 96 {
+ v -= 32
+ }
+ if seen[v] {
+ mx = max(mx, v)
+ continue
+ }
+ seen[v] = true
+ }
+ var res string
+ if mx > 0 {
+ res = string([]byte{mx})
+ }
+ return res
+}
+
+func main() {
+ for _, data := range []struct {
+ input, output string
+ }{
+ {"PeRlwEeKLy", "L"},
+ {"ChaLlenge", "L"},
+ {"The", ""},
+ } {
+ io.WriteString(os.Stdout, cmp.Diff(gel(data.input), data.output)) // blank if ok, otherwise show the difference
+ }
+}
diff --git a/challenge-264/pokgopun/go/ch-2.go b/challenge-264/pokgopun/go/ch-2.go
new file mode 100644
index 0000000000..b5275f9323
--- /dev/null
+++ b/challenge-264/pokgopun/go/ch-2.go
@@ -0,0 +1,90 @@
+//# https://theweeklychallenge.org/blog/perl-weekly-challenge-264/
+/*#
+
+Task 2: Target Array
+
+Submitted by: [48]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given two arrays of integers, @source and @indices. The
+ @indices can only contains integers 0 <= i < size of @source.
+
+ Write a script to create target array by insert at index $indices[i]
+ the value $source[i].
+
+Example 1
+
+Input: @source = (0, 1, 2, 3, 4)
+ @indices = (0, 1, 2, 2, 1)
+Output: (0, 4, 1, 3, 2)
+
+@source @indices @target
+0 0 (0)
+1 1 (0, 1)
+2 2 (0, 1, 2)
+3 2 (0, 1, 3, 2)
+4 1 (0, 4, 1, 3, 2)
+
+Example 2
+
+Input: @source = (1, 2, 3, 4, 0)
+ @indices = (0, 1, 2, 3, 0)
+Output: (0, 1, 2, 3, 4)
+
+@source @indices @target
+1 0 (1)
+2 1 (1, 2)
+3 2 (1, 2, 3)
+4 3 (1, 2, 3, 4)
+0 0 (0, 1, 2, 3, 4)
+
+Example 3
+
+Input: @source = (1)
+ @indices = (0)
+Output: (1)
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 14th April
+ 2024.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+#*/
+//# solution by pokgopun@gmail.com
+
+package main
+
+import (
+ "io"
+ "os"
+
+ "github.com/google/go-cmp/cmp"
+)
+
+type ints []int
+
+func target(source, indices ints) ints {
+ res := make(ints, len(source))
+ var i, j, v int
+ for i, v = range source {
+ j = indices[i]
+ if j < i {
+ copy(res[j+1:], res[j:])
+ }
+ res[j] = v
+ }
+ return res
+}
+
+func main() {
+ for _, data := range []struct {
+ source, indices, target ints
+ }{
+ {ints{0, 1, 2, 3, 4}, ints{0, 1, 2, 2, 1}, ints{0, 4, 1, 3, 2}},
+ {ints{1, 2, 3, 4, 0}, ints{0, 1, 2, 3, 0}, ints{0, 1, 2, 3, 4}},
+ {ints{1}, ints{0}, ints{1}},
+ } {
+ io.WriteString(os.Stdout, cmp.Diff(target(data.source, data.indices), data.target)) // blank if ok, otherwise show the difference
+ }
+}
diff --git a/challenge-264/pokgopun/python/ch-1.py b/challenge-264/pokgopun/python/ch-1.py
new file mode 100644
index 0000000000..2969fd1bd8
--- /dev/null
+++ b/challenge-264/pokgopun/python/ch-1.py
@@ -0,0 +1,57 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-264/
+"""
+
+Task 1: Greatest English Letter
+
+Submitted by: [47]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given a string, $str, made up of only alphabetic characters
+ [a..zA..Z].
+
+ Write a script to return the greatest english letter in the given
+ string.
+
+ A letter is greatest if it occurs as lower and upper case. Also
+ letter ‘b’ is greater than ‘a’ if ‘b’ appears after ‘a’ in the
+ English alphabet.
+
+Example 1
+
+Input: $str = 'PeRlwEeKLy'
+Output: L
+
+There are two letters E and L that appears as lower and upper.
+The letter L appears after E, so the L is the greatest english letter.
+
+Example 2
+
+Input: $str = 'ChaLlenge'
+Output: L
+
+Example 3
+
+Input: $str = 'The'
+Output: ''
+
+Task 2: Target Array
+"""
+### solution by pokgopun@gmail.com
+
+def gel(word: str):
+ word = word.upper() + chr(0)*2
+ c = max(e for e in set(word) if word.count(e) > 1)
+ return "" if c==chr(0) else c
+
+import unittest
+
+class TestGel(unittest.TestCase):
+ def test(self):
+ for inpt,otpt in {
+ 'PeRlwEeKLy': "L",
+ 'ChaLlenge': "L",
+ 'The': ''
+ }.items():
+ self.assertEqual(gel(inpt),otpt)
+
+unittest.main()
diff --git a/challenge-264/pokgopun/python/ch-2.py b/challenge-264/pokgopun/python/ch-2.py
new file mode 100644
index 0000000000..5829642ca4
--- /dev/null
+++ b/challenge-264/pokgopun/python/ch-2.py
@@ -0,0 +1,73 @@
+### https://theweeklychallenge.org/blog/perl-weekly-challenge-264/
+"""
+
+Task 2: Target Array
+
+Submitted by: [48]Mohammad Sajid Anwar
+ __________________________________________________________________
+
+ You are given two arrays of integers, @source and @indices. The
+ @indices can only contains integers 0 <= i < size of @source.
+
+ Write a script to create target array by insert at index $indices[i]
+ the value $source[i].
+
+Example 1
+
+Input: @source = (0, 1, 2, 3, 4)
+ @indices = (0, 1, 2, 2, 1)
+Output: (0, 4, 1, 3, 2)
+
+@source @indices @target
+0 0 (0)
+1 1 (0, 1)
+2 2 (0, 1, 2)
+3 2 (0, 1, 3, 2)
+4 1 (0, 4, 1, 3, 2)
+
+Example 2
+
+Input: @source = (1, 2, 3, 4, 0)
+ @indices = (0, 1, 2, 3, 0)
+Output: (0, 1, 2, 3, 4)
+
+@source @indices @target
+1 0 (1)
+2 1 (1, 2)
+3 2 (1, 2, 3)
+4 3 (1, 2, 3, 4)
+0 0 (0, 1, 2, 3, 4)
+
+Example 3
+
+Input: @source = (1)
+ @indices = (0)
+Output: (1)
+ __________________________________________________________________
+
+ Last date to submit the solution 23:59 (UK Time) Sunday 14th April
+ 2024.
+ __________________________________________________________________
+
+SO WHAT DO YOU THINK ?
+"""
+### solution by pokgopun@gmail.com
+
+def target(source,indices):
+ result = list()
+ for i in range(len(source)):
+ result.insert(indices[i],source[i])
+ return tuple(result)
+
+import unittest
+
+class TestTarget(unittest.TestCase):
+ def test(self):
+ for (source,indices), result in {
+ ((0, 1, 2, 3, 4), (0, 1, 2, 2, 1)): (0, 4, 1, 3, 2),
+ ((1, 2, 3, 4, 0), (0, 1, 2, 3, 0)): (0, 1, 2, 3, 4),
+ ((1,), (0,)): (1,),
+ }.items():
+ self.assertEqual(target(source,indices),result)
+
+unittest.main()