diff --git a/j2-Baulwuerfe/CMakeLists.txt b/j2-Baulwuerfe/CMakeLists.txt index 53e3424..2f591d3 100644 --- a/j2-Baulwuerfe/CMakeLists.txt +++ b/j2-Baulwuerfe/CMakeLists.txt @@ -1,4 +1,4 @@ file(GLOB J2SOURCES "src/*.c") file(GLOB ACLSOURCES "../lib/acl/src/*.c") -add_executable(j2 ${J1SOURCES} ${ACLSOURCES}) +add_executable(j2 ${J2SOURCES} ${ACLSOURCES}) target_link_libraries(j2 PRIVATE m) diff --git a/j2-Baulwuerfe/j2 b/j2-Baulwuerfe/j2 new file mode 100755 index 0000000..8a248fb Binary files /dev/null and b/j2-Baulwuerfe/j2 differ diff --git a/j2-Baulwuerfe/src/main.c b/j2-Baulwuerfe/src/main.c index 9dd7a9e..b7e7c95 100644 --- a/j2-Baulwuerfe/src/main.c +++ b/j2-Baulwuerfe/src/main.c @@ -1,4 +1,13 @@ #include +#include +#include +#include +#include +#include + +enum baulwurfhuegel{baulwurfhuegel = 'X', keinBaulwurfhuegel = ' '}; + +int width, height; void pointerCheck(void *pointer) { if(pointer == NULL) { @@ -7,8 +16,33 @@ void pointerCheck(void *pointer) { } } +bool checkRow(char *row) { + for(uint8_t i = 0; i < 4; ++i) { + if(row[i * (width + 1)] == keinBaulwurfhuegel) return false; + } + return true; +} + int main(int argc, char *argv[]) { if(argc != 2) printf("file argument required"); bool sucess; FILE *fp = fopen(argv[1], "rb"); char *input = acl_ReadTextFile(fp, &sucess); + fclose(fp); + pointerCheck(input); + char *heightText; + char *textRest; + width = strtol(input, &heightText, 10); + ++heightText; // height points does not point to \n anymore + height = strtol(heightText, &textRest, 10); + ++textRest; + printf("height: %d width: %d\n", height, width); + unsigned baulwurfhuegelCounter = 0; + for(char *i = textRest; (uintptr_t)i <= (uintptr_t)textRest + ((height - 4) * (width + 1)); i += width + 1) { + for(char *j = i; (uintptr_t)j < (uintptr_t)i + width - 1; ++j) { + baulwurfhuegelCounter += checkRow(j) && checkRow(j + 2) && j[1] == baulwurfhuegel && j[1 + 3 * (width + 1)]; + } + } + free(input); + printf("Baulwurfhuegel: %u", baulwurfhuegelCounter); +}