···12121313# MSVC Windows builds of rustc generate these, which store debugging information
1414*.pdb
1515+1616+1717+dist/
1818+build/
1919+2020+node_modules/
2121+2222+.vscode/
2323+.idea/
2424+2525+.env
2626+.env.local
2727+.env.*.local
2828+2929+*.tsbuildinfo
3030+3131+# Log files
3232+*.log
3333+3434+# Runtime data
3535+pids
3636+*.pid
3737+*.seed
3838+*.pid.lock
3939+4040+# Directory for instrumented libs generated by jscoverage/JSCover
4141+lib-cov
4242+4343+# Coverage directory used by tools like istanbul
4444+coverage
···11+--- Day 1: Trebuchet?! ---
22+--------------------------
33+44+Something is wrong with global snow production, and you've been selected to take a look. The Elves have even given you a map; on it, they've used stars to mark the top fifty locations that are likely to be having problems.
55+66+You've been doing this long enough to know that to restore snow operations, you need to check all fifty stars by December 25th.
77+88+Collect stars by solving puzzles. Two puzzles will be made available on each day in the Advent calendar; the second puzzle is unlocked when you complete the first. Each puzzle grants one star. Good luck!
99+1010+You try to ask why they can't just use a [weather machine](https://adventofcode.com/2015/day/1) ("not powerful enough") and where they're even sending you ("the sky") and why your map looks mostly blank ("you sure ask a lot of questions") and hang on did you just say the sky ("of course, where do you think snow comes from") when you realize that the Elves are already loading you into a [trebuchet](https://en.wikipedia.org/wiki/Trebuchet) ("please hold still, we need to strap you in").
1111+1212+As they're making the final adjustments, they discover that their calibration document (your puzzle input) has been amended by a very young Elf who was apparently just excited to show off her art skills. Consequently, the Elves are having trouble reading the values on the document.
1313+1414+The newly-improved calibration document consists of lines of text; each line originally contained a specific calibration value that the Elves now need to recover. On each line, the calibration value can be found by combining the first digit and the last digit (in that order) to form a single two-digit number.
1515+1616+For example:
1717+1818+```
1919+1abc2
2020+pqr3stu8vwx
2121+a1b2c3d4e5f
2222+treb7uchet
2323+2424+```
2525+2626+In this example, the calibration values of these four lines are `12`, `38`, `15`, and `77`. Adding these together produces `142`.
2727+2828+Consider your entire calibration document. What is the sum of all of the calibration values?
+21
src/day1/prompt_b.md
···11+--- Part Two ---
22+----------------
33+44+Your calculation isn't quite right. It looks like some of the digits are actually spelled out with letters: `one`, `two`, `three`, `four`, `five`, `six`, `seven`, `eight`, and `nine` also count as valid "digits".
55+66+Equipped with this new information, you now need to find the real first and last digit on each line. For example:
77+88+```
99+two1nine
1010+eightwothree
1111+abcone2threexyz
1212+xtwone3four
1313+4nineeightseven2
1414+zoneight234
1515+7pqrstsixteen
1616+1717+```
1818+1919+In this example, the calibration values are `29`, `83`, `13`, `24`, `42`, `14`, and `76`. Adding these together produces `281`.
2020+2121+What is the sum of all of the calibration values?
+114
src/day1/typescript/main.ts
···11+// In our parent folder, we have a text file, input.txt, with lines of strings we want to store in an array.
22+import {readFileSync} from 'node:fs';
33+44+// Read the file and split it into an array of strings
55+const input: string[] = readFileSync('src/day1/input.txt', 'utf8').split('\n');
66+77+(() => { // Part A
88+ const calibrationValue = (line: string) => {
99+ // Slice the first and last digits from the string and combine them into a number
1010+ // The first digit might be anywhere in the string, so we need to find it
1111+ const firstDigit = (/\d/.exec(line))?.[0];
1212+ // Reverse the string and find the first digit again
1313+ const lastDigit = (/\d/.exec([...line].reverse().join('')))?.[0];
1414+ // Combine the two digits into a number
1515+ return Number((Number(firstDigit) * 10) + Number(lastDigit));
1616+ };
1717+1818+ let sum = 0;
1919+ for (const line of input) {
2020+ sum += calibrationValue(line);
2121+ }
2222+2323+ console.log(sum);
2424+ // Answer: 55029
2525+})();
2626+2727+(() => { // Part B
2828+ const calibrationValue = (line: string): number => {
2929+ // Let's find all possible numbers in the string.
3030+ // For each character, if it's a digit, we'll add it to our ordered list of digits.
3131+ // If it's a letter, we'll check if the next few characters spell out a number.
3232+ // If they do, we'll add that number to our list of digits.
3333+ const digits: number[] = [];
3434+ for (let i = 0; i < line.length; i++) {
3535+ const char = line[i];
3636+ if (/\d/.test(char)) {
3737+ digits.push(Number(char));
3838+ } else {
3939+ switch (char) {
4040+ case 'o': {
4141+ if (line.slice(i, i + 3) === 'one') {
4242+ digits.push(1);
4343+ }
4444+4545+ break;
4646+ }
4747+4848+ case 't': {
4949+ if (line.slice(i, i + 3) === 'two') {
5050+ digits.push(2);
5151+ } else if (line.slice(i, i + 5) === 'three') {
5252+ digits.push(3);
5353+ }
5454+5555+ break;
5656+ }
5757+5858+ case 'f': {
5959+ if (line.slice(i, i + 4) === 'four') {
6060+ digits.push(4);
6161+ } else if (line.slice(i, i + 4) === 'five') {
6262+ digits.push(5);
6363+ }
6464+6565+ break;
6666+ }
6767+6868+ case 's': {
6969+ if (line.slice(i, i + 3) === 'six') {
7070+ digits.push(6);
7171+ } else if (line.slice(i, i + 5) === 'seven') {
7272+ digits.push(7);
7373+ }
7474+7575+ break;
7676+ }
7777+7878+ case 'e': {
7979+ if (line.slice(i, i + 5) === 'eight') {
8080+ digits.push(8);
8181+ }
8282+8383+ break;
8484+ }
8585+8686+ case 'n': {
8787+ if (line.slice(i, i + 4) === 'nine') {
8888+ digits.push(9);
8989+ }
9090+9191+ break;
9292+ }
9393+9494+ default: {
9595+ break;
9696+ }
9797+ }
9898+ }
9999+ }
100100+101101+ const firstDigit = digits[0];
102102+ const lastDigit = digits.at(-1) ?? firstDigit;
103103+ return (firstDigit * 10) + lastDigit;
104104+ };
105105+106106+ let sum = 0;
107107+ for (const line of input) {
108108+ const getValue = calibrationValue(line);
109109+ sum += getValue;
110110+ }
111111+112112+ console.log(sum);
113113+ // Answer: 55686
114114+})();