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