update for macOS, 2015-08

This commit is contained in:
2022-09-09 11:13:53 -07:00
parent 597db66495
commit b0b6773395
4 changed files with 62 additions and 13 deletions

View File

@ -1,10 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lfinput.h"
void advent2015day08(void) {
char *input = get_input("input/2015/08");
printf("Solution for Day 08 of 2015 is not completed yet\n");
free(input);
static size_t part_one(char** input, size_t sz) {
size_t code = 0, mem = 0;
for (size_t i = 0; i < sz; ++i) {
code += strlen(input[i]);
for (size_t j = 1; j < strlen(input[i]) - 1; ++j) {
if (input[i][j] == '\\') {
if (input[i][j + 1] == '\"' || input[i][j + 1] == '\\') {
++j;
} else {
j += 3;
}
}
++mem;
}
}
return code - mem;
}
static size_t part_two(char** input, size_t sz) {
size_t code = 0, encoded = 0;
for (size_t i = 0; i < sz; ++i) {
code += strlen(input[i]);
encoded += 6;
for (size_t j = 1; j < strlen(input[i]) - 1; ++j) {
if (input[i][j] == '\\' || input[i][j] == '\"') {
++encoded;
}
++encoded;
}
}
return encoded - code;
}
void advent2015day08(void) {
size_t sz = 0;
char **input = get_lines("input/2015/08", &sz);
printf("%zu\n", part_one(input, sz));
printf("%zu\n", part_two(input, sz));
del_lines(input);
}