diff options
author | 2020-12-07 23:16:51 +0100 | |
---|---|---|
committer | 2020-12-07 23:16:51 +0100 | |
commit | 02cfa242c714d25a60151f0629418298432765eb (patch) | |
tree | 183233339eefc23b4d2bca2d8fba1f9921420639 /day5/day5-1.js | |
parent | 1d9e51abbd1de2e31f0526776bd0cd891e72bed5 (diff) | |
download | advent_of_code_2020-02cfa242c714d25a60151f0629418298432765eb.tar.gz advent_of_code_2020-02cfa242c714d25a60151f0629418298432765eb.tar.bz2 advent_of_code_2020-02cfa242c714d25a60151f0629418298432765eb.zip |
day5
Diffstat (limited to 'day5/day5-1.js')
-rw-r--r-- | day5/day5-1.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/day5/day5-1.js b/day5/day5-1.js new file mode 100644 index 0000000..3a308f9 --- /dev/null +++ b/day5/day5-1.js @@ -0,0 +1,24 @@ +const data = require('./data') + +const filterPlaces = (pass, entity, mark, min, max) => ( + pass.forEach((p, i) => { + if (i > min && i <= max) { + p === mark + ? entity.splice(entity.length / 2, entity.length) + : entity.splice(0, entity.length / 2) + } + }) +) + +const checkId = (p) => { + const pass = p.split('') + const row = [...Array(128).keys()] + const column = [...Array(8).keys()] + + filterPlaces(pass, row, 'F', -1, 6) + filterPlaces(pass, column, 'L', 6, 9) + + return ID = row[0] * 8 + column[0] +} + +console.log(Math.max(...data.map(checkId))) |