Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const magic = (entries, start, end) => {
- let value = entries[start]
- for (let i = start + 1; i <= end; i++) {
- value = value ^ entries[i]
- }
- return value
- }
- const contestResponse = input => {
- const entries = input[1].split(' ').map(Number)
- const instructions = input
- .slice(2)
- .map(x => {
- const s = x.split(' ')
- return { start: Number(s[0]), end: Number(s[1]) }
- })
- const result = instructions.map(i => magic(entries, i.start, i.end))
- const counts = {}
- result.forEach(element => {
- if (!counts[element]) counts[element] = 0
- counts[element]++
- })
- let binary = '' + (counts[0] || 0).toString()
- for (let i = 1; i < 256; i++) {
- binary += ' ' + (counts[i] || 0).toString()
- }
- return binary
- }
- module.exports = contestResponse
RAW Paste Data