Skip to content

Instantly share code, notes, and snippets.

@kitasuna
Last active September 21, 2019 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kitasuna/3b6cf6a8481507e744b3adeeda2520d3 to your computer and use it in GitHub Desktop.
Save kitasuna/3b6cf6a8481507e744b3adeeda2520d3 to your computer and use it in GitHub Desktop.
Advent of Code 2018, Day 5, Part 1
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