blob: 05fa9eb2f241d85dbb14b1ee1f2fe2c1f7889e4f [file] [log] [blame]
import { readFileSync } from 'fs'
const input = readFileSync('./input.txt').toString().split('\n');
const firstLast = (str: string) => {
const newStr = str
.replaceAll('one', 'o1e')
.replaceAll('two', 't2o')
.replaceAll('three', 't3e')
.replaceAll('four', 'f4r')
.replaceAll('five', 'f5e')
.replaceAll('six', 's6x')
.replaceAll('seven', 's7n')
.replaceAll('eight', 'e8t')
.replaceAll('nine', 'n9e')
console.log(newStr)
const matches = newStr.match(/[\d]/g)
return matches ? [matches[0], matches[matches.length-1]].join('') : null
}
let int: number = 0;
for(const line of input) {
int += parseInt(firstLast(line) ?? "0")
}
console.log(int)