aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDave Jacoby <jacoby.david@gmail.com>2021-08-18 18:31:07 -0400
committerDave Jacoby <jacoby.david@gmail.com>2021-08-18 18:31:07 -0400
commita54732a97b254d90de1c6eb160beb4f86017e657 (patch)
treee596246e03c4a6fc8a1e8f27bc4f08d2c51dc134
parent90bbb36d90d4f98ba52785b931c75de0304f6839 (diff)
downloadperlweeklychallenge-club-a54732a97b254d90de1c6eb160beb4f86017e657.tar.gz
perlweeklychallenge-club-a54732a97b254d90de1c6eb160beb4f86017e657.tar.bz2
perlweeklychallenge-club-a54732a97b254d90de1c6eb160beb4f86017e657.zip
Did JS too
-rw-r--r--challenge-126/dave-jacoby/node/ch-1.js10
-rw-r--r--challenge-126/dave-jacoby/node/ch-2.js58
2 files changed, 68 insertions, 0 deletions
diff --git a/challenge-126/dave-jacoby/node/ch-1.js b/challenge-126/dave-jacoby/node/ch-1.js
new file mode 100644
index 0000000000..1238a11136
--- /dev/null
+++ b/challenge-126/dave-jacoby/node/ch-1.js
@@ -0,0 +1,10 @@
+"use strict";
+
+let n = 25;
+let list = Array(n)
+ .fill()
+ .map((x, i) => i + 1)
+ .filter((x) => ! x.toString().match(/1/) )
+ ;
+console.log(list.join(", "));
+
diff --git a/challenge-126/dave-jacoby/node/ch-2.js b/challenge-126/dave-jacoby/node/ch-2.js
new file mode 100644
index 0000000000..7157f24e66
--- /dev/null
+++ b/challenge-126/dave-jacoby/node/ch-2.js
@@ -0,0 +1,58 @@
+"use strict";
+
+let minemap = [];
+let field = function () {
+ /*
+x * * * x * x x x x
+* * * * * * * * * x
+* * * * x * x * x *
+* * * x x * * * * *
+x * * * x * * * * x
+*/
+}
+ .toString()
+ .split(/\/\*/)[1]
+ .split(/\*\//)[0]
+ .split(/\n/)
+ .filter((x) => String(x).match(/\w/));
+
+let maxx = 0;
+let maxy = 0;
+
+for (let x in field) {
+ maxx = x;
+ let rowstr = field[x];
+ let row = rowstr.split(/\s+/g);
+ minemap[x] = new Array(row.length);
+ for (let y in row) {
+ maxy = y;
+ minemap[x][y] = "0";
+ if (row[y] === "x") {
+ minemap[x][y] = "x";
+ }
+ }
+}
+for (let x = 0; x <= maxx; x++) {
+ for (let y = 0; y <= maxy; y++) {
+ if (minemap[x][y] === "x") {
+ for (let i = -1; i <= 1; i++) {
+ for (let j = -1; j <= 1; j++) {
+ if (!(i == 0 && i == j)) {
+ let xx = x + i;
+ let yy = y + j;
+ if (xx >= 0 && yy >= 0 && xx <= maxx && yy <= maxy) {
+ if (minemap[xx][yy] != "x") {
+ minemap[xx][yy]++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+for (let x = 0; x <= maxx; x++) {
+ console.log(minemap[x].join(" "));
+}
+
+// console.log([maxx, maxy, minemap]);