aboutsummaryrefslogtreecommitdiff
path: root/challenge-258/eric-cheung/python
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-03-04 16:39:31 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-03-04 16:39:31 +0800
commit8edd4508d3af07ed272eec6ceeca1a9789b5e68a (patch)
tree2db742aea75a7a3005575c04a7e44da6d5c88a1f /challenge-258/eric-cheung/python
parentd64db60d9dcf17d59060a03f5b1fbc5e82fc1953 (diff)
parentad381c1123e47114d3d98f1749f9f354eebafcdd (diff)
downloadperlweeklychallenge-club-8edd4508d3af07ed272eec6ceeca1a9789b5e68a.tar.gz
perlweeklychallenge-club-8edd4508d3af07ed272eec6ceeca1a9789b5e68a.tar.bz2
perlweeklychallenge-club-8edd4508d3af07ed272eec6ceeca1a9789b5e68a.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-258/eric-cheung/python')
-rwxr-xr-xchallenge-258/eric-cheung/python/ch-1.py7
-rwxr-xr-xchallenge-258/eric-cheung/python/ch-2.py15
2 files changed, 22 insertions, 0 deletions
diff --git a/challenge-258/eric-cheung/python/ch-1.py b/challenge-258/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..ece02350ec
--- /dev/null
+++ b/challenge-258/eric-cheung/python/ch-1.py
@@ -0,0 +1,7 @@
+
+## arrInt = [10, 1, 111, 24, 1000] ## Example 1
+## arrInt = [111, 1, 11111] ## Example 2
+arrInt = [2, 8, 1024, 256] ## Example 3
+
+arrOutput = [elemLoop for elemLoop in arrInt if len(str(elemLoop)) % 2 == 0]
+print (len(arrOutput))
diff --git a/challenge-258/eric-cheung/python/ch-2.py b/challenge-258/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..a6088a474b
--- /dev/null
+++ b/challenge-258/eric-cheung/python/ch-2.py
@@ -0,0 +1,15 @@
+
+## Example 1
+## arrInt = [2, 5, 9, 11, 3]
+## nInput = 1
+
+## Example 2
+## arrInt = [2, 5, 9, 11, 3]
+## nInput = 2
+
+## Example 3
+arrInt = [2, 5, 9, 11, 3]
+nInput = 0
+
+arrOutput = [elemLoop for nIndx, elemLoop in enumerate(arrInt) if bin(nIndx)[2:].count("1") == nInput]
+print (sum(arrOutput))