2015-03. Add advent_utility and libflint
This commit is contained in:
@ -1,10 +1,74 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "set.h"
|
||||
#include "input.h"
|
||||
#include "advent_utility.h"
|
||||
|
||||
static int part_two(char *input) {
|
||||
int sx = 0, sy = 0, rx = 0, ry = 0, is_santa = 1;
|
||||
int *x, *y;
|
||||
char *c = input;
|
||||
|
||||
Set* houses = malloc(sizeof(Set));
|
||||
set_init(houses, same_Point_v, free);
|
||||
|
||||
while (*c != '\0') {
|
||||
if (is_santa) {
|
||||
x = &sx;
|
||||
y = &sy;
|
||||
} else {
|
||||
x = ℞
|
||||
y = &ry;
|
||||
}
|
||||
is_santa = is_santa == 1 ? 0 : 1;
|
||||
|
||||
switch (*c) {
|
||||
case '^': ++(*y); break;
|
||||
case 'v': --(*y); break;
|
||||
case '>': ++(*x); break;
|
||||
case '<': --(*x); break;
|
||||
}
|
||||
set_insert(houses, (void *) new_Point_p(*x, *y));
|
||||
++c;
|
||||
}
|
||||
|
||||
int sz = (int)houses->size;
|
||||
set_destroy(houses);
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
||||
static int part_one(char *input) {
|
||||
int x = 0, y = 0;
|
||||
char *c = input;
|
||||
|
||||
Set* houses = malloc(sizeof(Set));
|
||||
set_init(houses, same_Point_v, free);
|
||||
|
||||
while (*c != '\0') {
|
||||
switch (*c) {
|
||||
case '^': ++y; break;
|
||||
case 'v': --y; break;
|
||||
case '>': ++x; break;
|
||||
case '<': --x; break;
|
||||
}
|
||||
set_insert(houses, (void *) new_Point_p(x, y));
|
||||
++c;
|
||||
}
|
||||
|
||||
int sz = (int)houses->size;
|
||||
set_destroy(houses);
|
||||
|
||||
return sz;
|
||||
}
|
||||
|
||||
void advent2015day03(void) {
|
||||
char *input = get_input("input/2015/03");
|
||||
printf("Solution for Day 03 of 2015 is not completed yet\n");
|
||||
|
||||
printf("%d\n", part_one(input));
|
||||
printf("%d\n", part_two(input));
|
||||
|
||||
free(input);
|
||||
}
|
||||
|
Reference in New Issue
Block a user