Last active
September 21, 2019 06:25
-
-
Save kitasuna/3b6cf6a8481507e744b3adeeda2520d3 to your computer and use it in GitHub Desktop.
Advent of Code 2018, Day 5, Part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fs from 'fs' | |
const contents = fs.readFileSync('input', 'utf8') | |
const valuesReact = (x: string) => (y: string) => { | |
const del = Math.abs((x.charCodeAt(0) - y.charCodeAt(0))) | |
return del === 32 | |
} | |
const fin = contents.split('').reduce((acc, curr) => { | |
// Check if current value last char in acc annihilate | |
if(valuesReact(acc.slice(-1))(curr)) { | |
return acc.substring(0, (acc.length - 1)) | |
} | |
return acc.concat(curr) | |
}, '') | |
// Drop carriage return | |
console.log(fin.length - 1) | |
console.log('^^^ fin length') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment