j2 fertig
This commit is contained in:
@ -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)
|
||||
|
||||
BIN
j2-Baulwuerfe/j2
Executable file
BIN
j2-Baulwuerfe/j2
Executable file
Binary file not shown.
@ -1,4 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <acl/file.h>
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user