aboutsummaryrefslogtreecommitdiff
path: root/challenge-270/zapwai/javascript
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2024-05-20 13:26:47 -0400
committerDavid Ferrone <zapwai@gmail.com>2024-05-20 13:26:47 -0400
commit7543ffc033b251b55c32ce83133b789e520995d6 (patch)
tree7abe14ec31968b78c0d6d05b0c892355020ade3b /challenge-270/zapwai/javascript
parented462bf99ed6fda013ab14d58855951ef13b05fa (diff)
downloadperlweeklychallenge-club-7543ffc033b251b55c32ce83133b789e520995d6.tar.gz
perlweeklychallenge-club-7543ffc033b251b55c32ce83133b789e520995d6.tar.bz2
perlweeklychallenge-club-7543ffc033b251b55c32ce83133b789e520995d6.zip
Week 270
Diffstat (limited to 'challenge-270/zapwai/javascript')
-rw-r--r--challenge-270/zapwai/javascript/ch-1.js50
1 files changed, 50 insertions, 0 deletions
diff --git a/challenge-270/zapwai/javascript/ch-1.js b/challenge-270/zapwai/javascript/ch-1.js
new file mode 100644
index 0000000000..d8b130e799
--- /dev/null
+++ b/challenge-270/zapwai/javascript/ch-1.js
@@ -0,0 +1,50 @@
+let matrix = [ [1, 0, 0],
+ [0, 0, 1],
+ [1, 0, 0],
+ ];
+
+let matrix2 = [ [1, 0, 0],
+ [0, 1, 0],
+ [0, 0, 1],
+ ];
+
+proc(matrix);
+proc(matrix2);
+
+function is_special(m, M, N, i, j) {
+ if (m[i][j] != 1) {
+ return 0;
+ }
+ for (let k = 0; k < M; k++) {
+ if (k == i) {
+ continue;
+ }
+ if (m[k][j] != 0) {
+ return 0;
+ }
+ }
+ for (let k = 0; k < N; k++) {
+ if (k == j) {
+ continue;
+ }
+ if (m[i][k] != 0) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+function proc(m) {
+ let M = m.length;
+ let N = m[0].length;
+ console.log("Input: m = ", m);
+ let cnt = 0;
+ for (let i = 0; i < M; i++) {
+ for (let j = 0; j < N; j++) {
+ if (is_special(m, M, N, i, j)) {
+ cnt++;
+ }
+ }
+ }
+ console.log("Output: ", cnt);
+}