aboutsummaryrefslogtreecommitdiff
path: root/challenge-252
diff options
context:
space:
mode:
author冯昶 <fengchang@novel-supertv.com>2024-02-20 10:00:29 +0800
committer冯昶 <fengchang@novel-supertv.com>2024-02-20 10:00:29 +0800
commit01a6f15175138e75c911587cbe12f04022bbf7e4 (patch)
tree943bc32e8ddc1eeb96b0812c081cb2cd845d4970 /challenge-252
parente5957b34dcceeec35cfab30af3dc01e4411c64ed (diff)
parentd56f5846adcf3864f7b9dd2426d85ae68579729e (diff)
downloadperlweeklychallenge-club-01a6f15175138e75c911587cbe12f04022bbf7e4.tar.gz
perlweeklychallenge-club-01a6f15175138e75c911587cbe12f04022bbf7e4.tar.bz2
perlweeklychallenge-club-01a6f15175138e75c911587cbe12f04022bbf7e4.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-252')
-rw-r--r--challenge-252/zapwai/javascript/ch-1.js25
-rw-r--r--challenge-252/zapwai/javascript/ch-2.js17
-rw-r--r--challenge-252/zapwai/python/ch-1.py14
-rw-r--r--challenge-252/zapwai/python/ch-2.py13
4 files changed, 69 insertions, 0 deletions
diff --git a/challenge-252/zapwai/javascript/ch-1.js b/challenge-252/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..8b95a0d51c
--- /dev/null
+++ b/challenge-252/zapwai/javascript/ch-1.js
@@ -0,0 +1,25 @@
+let ints = [1, 2, 3, 4];
+let ints2 = [2, 7, 1, 19, 18, 3];
+
+proc(ints);
+proc(ints2);
+
+function total( list ) {
+ let sum = 0;
+ for (let i of list) {
+ sum += i*i;
+ }
+ return sum;
+}
+
+function proc( ints ) {
+ let n = ints.length;
+ let spec = [];
+ for (let i = 0; i < n; i++) {
+ if (n % (i + 1) == 0) {
+ spec.push(ints[i]);
+ }
+ }
+ console.log("Input:", ints);
+ console.log("Output:", total( spec ));
+}
diff --git a/challenge-252/zapwai/javascript/ch-2.js b/challenge-252/zapwai/javascript/ch-2.js
new file mode 100644
index 0000000000..1fe5b40823
--- /dev/null
+++ b/challenge-252/zapwai/javascript/ch-2.js
@@ -0,0 +1,17 @@
+let inputs = [5, 3, 1];
+for (let inp of inputs) {
+ proc(inp);
+}
+function proc(n) {
+ let list = [];
+ if (n % 2 == 1) {
+ list.push(0);
+ }
+ let k = parseInt(n / 2);
+ for (let i = 0; i < k; i++) {
+ list.push(-1 * (i+1));
+ list.push(i+1);
+ }
+ console.log("Input:", n);
+ console.log("Output:", list);
+}
diff --git a/challenge-252/zapwai/python/ch-1.py b/challenge-252/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..541d927568
--- /dev/null
+++ b/challenge-252/zapwai/python/ch-1.py
@@ -0,0 +1,14 @@
+def proc(ints):
+ spec = []
+ for i in range(len(ints)):
+ if len(ints) % (i+1) == 0:
+ spec.append(ints[i])
+ sum = 0
+ for v in spec:
+ sum += v*v
+ print("Input: ints =", ints)
+ print(f"Output: {sum}")
+ints = [1,2,3,4]
+proc(ints)
+ints = [2, 7, 1, 19, 18, 3]
+proc(ints)
diff --git a/challenge-252/zapwai/python/ch-2.py b/challenge-252/zapwai/python/ch-2.py
new file mode 100644
index 0000000000..998cba13e9
--- /dev/null
+++ b/challenge-252/zapwai/python/ch-2.py
@@ -0,0 +1,13 @@
+def proc(n):
+ print(f"Input : n = {n}")
+ l = []
+ if n % 2 == 1:
+ l.append(0)
+ k = int( (n - 1) / 2 )
+ val = 1
+ for i in range(k):
+ l.append(val); l.append(-1*val)
+ val += 1
+ print("Output:", l)
+for n in [5, 3, 1]:
+ proc(n)