Browse Source

Day 6 js

master
boB Rudis 4 months ago
parent
commit
b9e8c4920a
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
3 changed files with 51 additions and 0 deletions
  1. +4
    -0
      R/.Rproj.user/CBF2E10B/sources/prop/INDEX
  2. +1
    -0
      R/.Rproj.user/shared/notebooks/paths
  3. +46
    -0
      js/06.js

+ 4
- 0
R/.Rproj.user/CBF2E10B/sources/prop/INDEX View File

@ -6,6 +6,7 @@
~%2FDevelopment%2F2020-code-advent%2FR%2F05.R="3147CB9C"
~%2FDevelopment%2F2020-code-advent%2FR%2F05.py="C22F3766"
~%2FDevelopment%2F2020-code-advent%2FR%2F06.R="2E0DCDD0"
~%2FDevelopment%2F2020-code-advent%2FR%2F06.js="6AE95C9F"
~%2FDevelopment%2F2020-code-advent%2FR%2F06.py="A53BEE38"
~%2FDevelopment%2F2020-code-advent%2FREADME.md="87542FC2"
~%2FDevelopment%2F2020-code-advent%2FSwift%2F2020-code-advent.playground%2FSources%2F05-01.swift="A5C6F3F2"
@ -13,4 +14,7 @@
~%2FDevelopment%2F2020-code-advent%2Finput%2F06-01.txt="488B7FA9"
~%2FDevelopment%2F2020-code-advent%2Fjs%2F01.js="BCBA9F87"
~%2FDevelopment%2F2020-code-advent%2Fjs%2F02.js="823FD9BF"
~%2FDevelopment%2F2020-code-advent%2Fjs%2F03.js="8D76FAB7"
~%2FDevelopment%2F2020-code-advent%2Fjs%2F04.js="48608747"
~%2FDevelopment%2F2020-code-advent%2Fjs%2F05.js="28BC66DE"
~%2FDevelopment%2F2020-code-advent%2Fjs%2F06.js="60A0ABC4"

+ 1
- 0
R/.Rproj.user/shared/notebooks/paths View File

@ -9,6 +9,7 @@
/Users/hrbrmstr/Development/2020-code-advent/R/05.R="A949D345"
/Users/hrbrmstr/Development/2020-code-advent/R/05.py="89270E3A"
/Users/hrbrmstr/Development/2020-code-advent/R/06.R="E6CEEABC"
/Users/hrbrmstr/Development/2020-code-advent/R/06.js="14D95124"
/Users/hrbrmstr/Development/2020-code-advent/R/06.py="6D546EAC"
/Users/hrbrmstr/Development/2020-code-advent/README.md="74DC8DCF"
/Users/hrbrmstr/Development/2020-code-advent/Swift/2020-code-advent.playground/Sources/05-01.swift="8E24EF14"


+ 46
- 0
js/06.js View File

@ -0,0 +1,46 @@
var fs = require("fs")
Array.prototype.prepend = function() {
this.unshift(arguments["0"])
return(this)
}
// 06-01
res = input = fs.readFileSync("../input/06-01.txt", "utf-8")
.split("\n")
.prepend("")
.reduce((recs, line) => {
(line == "") ? recs.push([line]) : recs[recs.length - 1].push(line)
return(recs)
}, [])
.filter((x) => x.length > 1)
.map((x) => x.filter((y) => y != "")
.map((y) => y.split(""))
.flat()
)
.map((x) => (new Set(x)).size)
.reduce((a, b) => a + b)
console.log(res)
// 06-02
res = input = fs.readFileSync("../input/06-01.txt", "utf-8")
.split("\n")
.prepend("")
.reduce((recs, line) => {
(line == "") ? recs.push([line]) : recs[recs.length - 1].push(line)
return(recs)
}, [])
.filter((x) => x.length > 1)
.map((x) => x.filter((y) => y != "")
.map((y) => y.split(""))
)
.map((x) => {
map = x.flat().reduce((acc, e) => acc.set(e, (acc.get(e) || 0) + 1), new Map())
return([...map.values()].filter((v) => v == x.length).length)
})
.reduce((a, b) => a + b)
console.log(res)

Loading…
Cancel
Save