update for macOS, 2015-08
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user