Create Git repo
This commit is contained in:
commit
7298e6d87b
|
|
@ -0,0 +1,25 @@
|
|||
CC=gcc
|
||||
CFLAGS=-Wall
|
||||
|
||||
run1: bin/part01
|
||||
cat data/p01data.txt | bin/part01
|
||||
|
||||
run2: bin/part02
|
||||
cat data/p02data.txt | bin/part02
|
||||
|
||||
test1: bin/part01
|
||||
cat data/p01test.txt | bin/part01
|
||||
|
||||
test2: bin/part02
|
||||
cat data/p02test.txt | bin/part02
|
||||
|
||||
bin/part01:
|
||||
$(CC) src/part01.c -o bin/part01
|
||||
|
||||
bin/part02:
|
||||
$(CC) src/part02.c -o bin/part02
|
||||
|
||||
.PHONY: clean
|
||||
|
||||
clean:
|
||||
rm -f bin/*
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,5 @@
|
|||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,7 @@
|
|||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define debug_printf(...) do{ fprintf( stderr, __VA_ARGS__ ); } while( 0 )
|
||||
#else
|
||||
#define debug_printf(...) do{ } while ( 0 )
|
||||
#endif
|
||||
|
||||
#define LINE_MAX 90
|
||||
#define ASCII_0 48
|
||||
#define ASCII_9 57
|
||||
|
||||
|
||||
int isNum(char character){
|
||||
return (character >=ASCII_0 && character <= ASCII_9);
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
int linesProcessed = 0;
|
||||
char line[LINE_MAX];
|
||||
int sum = 0;
|
||||
while (fgets(line, LINE_MAX, stdin) != NULL) {
|
||||
linesProcessed++;
|
||||
char firstNum = ' ';
|
||||
char lastNum = ' ';
|
||||
for (int i = 0; i < strlen(line); i++){
|
||||
if (!isNum(line[i])) continue;
|
||||
if (firstNum == ' ') firstNum=line[i];
|
||||
lastNum = line[i];
|
||||
}
|
||||
char fullNum[3] = {firstNum, lastNum, '\0' };
|
||||
debug_printf("fN: %c%c\n", firstNum, lastNum);
|
||||
sum+=atoi(fullNum);
|
||||
}
|
||||
printf("\n Processed %d Lines\n", linesProcessed);
|
||||
printf("===================================\n");
|
||||
printf("Answer: \n%d\n", sum);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define LINE_MAX 90
|
||||
|
||||
int isNum(char character){
|
||||
return (character >=48 && character <= 57);
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
char line[LINE_MAX];
|
||||
int sum = 0;
|
||||
while (fgets(line, LINE_MAX, stdin) != NULL) {
|
||||
char firstNum = ' ';
|
||||
char lastNum = ' ';
|
||||
for (int i = 0; i < strlen(line); i++){
|
||||
if (!isNum(line[i])) continue;
|
||||
if (firstNum == ' ') firstNum=line[i];
|
||||
lastNum = line[i];
|
||||
}
|
||||
char fullNum[3] = {firstNum, lastNum, '\0' };
|
||||
printf("fN: %c%c\n", firstNum, lastNum);
|
||||
sum+=atoi(fullNum);
|
||||
}
|
||||
printf("answer sum: %d\n", sum);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef DEBUG
|
||||
#define debug_printf(...) do{ fprintf( stderr, __VA_ARGS__ ); } while( 0 )
|
||||
#else
|
||||
#define debug_printf(...) do{ } while ( 0 )
|
||||
#endif
|
||||
|
||||
#define LINE_MAX 90
|
||||
#define ASCII_0 48
|
||||
#define ASCII_9 57
|
||||
|
||||
|
||||
char *numberStrings[] = {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
|
||||
|
||||
int isNum(char character){
|
||||
return (character >=ASCII_0 && character <= ASCII_9);
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
int linesProcessed = 0;
|
||||
char line[LINE_MAX];
|
||||
int sum = 0;
|
||||
while (fgets(line, LINE_MAX, stdin) != NULL) {
|
||||
linesProcessed++;
|
||||
char firstNum = ' ';
|
||||
char lastNum = ' ';
|
||||
for(int i = 0; i< strlen(line); i++){
|
||||
for (int repi=0; repi<9; repi++ ){
|
||||
char *cNS = numberStrings[repi];
|
||||
debug_printf("cNS=%s; strlen(cNS)=%d\n", cNS, strlen(cNS));
|
||||
if (strncmp( &line[i], cNS, strlen(cNS) ) == 0) line[i] = ASCII_0+repi+1;
|
||||
}
|
||||
}
|
||||
debug_printf("mutatedInputLine: %s", line);
|
||||
for (int i = 0; i < strlen(line); i++){
|
||||
if (!isNum(line[i])) continue;
|
||||
if (firstNum == ' ') firstNum=line[i];
|
||||
lastNum = line[i];
|
||||
}
|
||||
char fullNum[3] = {firstNum, lastNum, '\0' };
|
||||
debug_printf("fN: %c%c\n", firstNum, lastNum);
|
||||
sum+=atoi(fullNum);
|
||||
}
|
||||
printf("\n Processed %d Lines\n", linesProcessed);
|
||||
printf("===================================\n");
|
||||
printf("Answer: \n%d\n", sum);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue