committing everything squashed

This commit is contained in:
2023-12-03 01:12:13 -08:00
commit 92caa0f5c4
15 changed files with 1587 additions and 0 deletions

1000
01/input.txt Normal file

File diff suppressed because it is too large Load Diff

63
01/main.c Normal file
View File

@@ -0,0 +1,63 @@
#include <stdio.h>
#define MAX_LENGTH 52
int convert(char* c) {
switch (*c) {
case 'z':
return (c[1] == 'e' && c[2] == 'r' && c[3] == 'o') ? 0 : -1;
case 'o':
return (c[1] == 'n' && c[2] == 'e') ? 1 : -1;
case 't':
if (c[1] == 'w' && c[2] == 'o')
return 2;
else if (c[1] == 'h' && c[2] == 'r' && c[3] == 'e' && c[4] == 'e')
return 3;
else
return -1;
case 'f':
if (c[1] == 'o' && c[2] == 'u' && c[3] == 'r')
return 4;
else if (c[1] == 'i' && c[2] == 'v' && c[3] == 'e')
return 5;
else
return -1;
case 's':
if (c[1] == 'i' && c[2] == 'x')
return 6;
else if (c[1] == 'e' && c[2] == 'v' && c[3] == 'e' && c[4] == 'n')
return 7;
else
return -1;
case 'e':
return (c[1] == 'i' && c[2] == 'g' && c[3] == 'h' && c[4] == 't') ? 8 : -1;
case 'n':
return (c[1] == 'i' && c[2] == 'n' && c[3] == 'e') ? 9 : -1;
}
return -1;
}
int main(void) {
int num1, num2, sum, word_num;
char buf[MAX_LENGTH];
num1 = 0;
num2 = 0;
sum = 0;
while (fgets(buf, MAX_LENGTH, stdin)) {
for (char* c = buf; *c != '\n'; c++) {
if (*c >= '0' && *c <= '9') {
num1 = num1 == 0 ? *c - '0' : num1;
num2 = *c - '0';
} else if ((word_num = convert(c)) >= 0) {
num1 = num1 == 0 ? word_num : num1;
num2 = word_num;
}
}
sum += num1*10 + num2;
num1 = 0;
}
printf("%d\n", sum);
return 0;
}

20
01/main1.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdio.h>
int main(void) {
int c, num1, num2, sum;
num1 = 0;
num2 = 0;
sum = 0;
while ((c = fgetc(stdin)) != EOF) {
if (c >= '0' && c <= '9') {
num1 = num1 == 0 ? c - '0' : num1;
num2 = c - '0';
} else if (c == '\n') {
sum += num1*10 + num2;
num1 = 0;
}
}
printf("%d\n", sum);
return 0;
}

12
01/part1.sed Normal file
View File

@@ -0,0 +1,12 @@
s/one/o1e/g
s/two/t2o/g
s/three/t3e/g
s/four/4/g
s/five/5e/g
s/six/6/g
s/seven/7n/g
s/eight/e8t/g
s/nine/n9e/g
s/[^0-9]//g
s/^(.).*(.)$/\1\2/g
s/^(.)$/\1\1/g

7
01/test.txt Normal file
View File

@@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen