17-01
This commit is contained in:
parent
63e10b1a5e
commit
aa4946f17f
@ -1,10 +1,33 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "lfinput.h"
|
||||
|
||||
void advent2017day01(void) {
|
||||
char *input = get_input("input/2017/01");
|
||||
printf("Solution for Day 01 of 2017 is not completed yet\n");
|
||||
const size_t sz = strlen(input);
|
||||
int p1 = 0, p2 = 0;
|
||||
|
||||
for (size_t i = 0; i < sz - 1; ++i) {
|
||||
if (input[i] == input[i + 1]) {
|
||||
p1 += input[i] - '0';
|
||||
}
|
||||
}
|
||||
if (input[sz - 1] == input[0]) {
|
||||
p1 += input[0] - '0';
|
||||
}
|
||||
|
||||
printf("%d\n", p1);
|
||||
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
size_t j = (i + sz / 2) % sz;
|
||||
if (input[i] == input[j]) {
|
||||
p2 += input[i] - '0';
|
||||
}
|
||||
}
|
||||
|
||||
printf("%d\n", p2);
|
||||
|
||||
free(input);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user