blob: 4fb11be940acfa21f989e83572ecceefbc6ed00e [file] [log] [blame]
Samuel Shuert274a4d62023-12-01 15:04:55 -05001import { readFileSync } from 'fs'
Samuel Shuert274a4d62023-12-01 15:04:55 -05002const input = readFileSync('./input.txt').toString().split('\n');
3
4const firstLast = (str: string) => {
5 const newStr = str
6 .replaceAll('one', 'o1e')
7 .replaceAll('two', 't2o')
8 .replaceAll('three', 't3e')
9 .replaceAll('four', 'f4r')
10 .replaceAll('five', 'f5e')
11 .replaceAll('six', 's6x')
12 .replaceAll('seven', 's7n')
13 .replaceAll('eight', 'e8t')
14 .replaceAll('nine', 'n9e')
Samuel Shuert274a4d62023-12-01 15:04:55 -050015 const matches = newStr.match(/[\d]/g)
16 return matches ? [matches[0], matches[matches.length-1]].join('') : null
17}
18
19let int: number = 0;
20
21for(const line of input) {
22 int += parseInt(firstLast(line) ?? "0")
23}
24console.log(int)