aboutsummaryrefslogtreecommitdiff
path: root/2020/6/solve.js
diff options
context:
space:
mode:
authorMarvin Borner2020-12-06 12:57:15 +0100
committerMarvin Borner2020-12-06 12:57:15 +0100
commit9dd43be0c0671303b97d1e4a2dc1727a633a5187 (patch)
treec088117ed547a3ff54491d07ae48bebabe22cb61 /2020/6/solve.js
parentaac336b3596b1eb5e6819fec70302858cda3c683 (diff)
6th in JS
Diffstat (limited to '2020/6/solve.js')
-rw-r--r--2020/6/solve.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/2020/6/solve.js b/2020/6/solve.js
new file mode 100644
index 0000000..e82242a
--- /dev/null
+++ b/2020/6/solve.js
@@ -0,0 +1,26 @@
+const fs = require("fs");
+const data = fs.readFileSync("input", "utf8");
+
+function part_one()
+{
+ return data.split("\n\n").map(e => [...new Set(e.replace(/\n/g, ''))].join('').length).reduce((a, b) => a + b);
+}
+
+function part_two()
+{
+ let res = 0;
+
+ data.split("\n\n").forEach(elem => {
+ const line = elem.replace(/\n/g, '');
+ const chars = line.split('');
+ const cnt = elem.split('\n').length;
+ for (const c of new Set(line))
+ if (chars.filter(x => x == c).length == cnt)
+ res++;
+ });
+
+ return res;
+}
+
+console.log(part_one());
+console.log(part_two());