fix Point usage
This commit is contained in:
parent
aa4946f17f
commit
8b61f739bc
@ -1,19 +1,6 @@
|
||||
#ifndef ADVENT_H_UTILITY_
|
||||
#define ADVENT_H_UTILITY_
|
||||
|
||||
struct Point {
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
struct Point new_Point(int, int);
|
||||
|
||||
struct Point *new_Point_p(int, int);
|
||||
|
||||
int same_Point(const struct Point *, const struct Point *);
|
||||
|
||||
int same_Point_v(const void *, const void *);
|
||||
|
||||
char *md5_str(const char *);
|
||||
|
||||
char *capture_system(const char *);
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 85536a351dd16df24835283c139aacf91961ab8a
|
||||
Subproject commit 0b5e8b999a7ae03ac015ce433af13dd4226f5ef4
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "lfset.h"
|
||||
#include "lfinput.h"
|
||||
#include "advent_utility.h"
|
||||
#include "lfutility.h"
|
||||
|
||||
static int part_two(char *input) {
|
||||
int sx = 0, sy = 0, rx = 0, ry = 0, is_santa = 1;
|
||||
@ -11,7 +11,7 @@ static int part_two(char *input) {
|
||||
char *c = input;
|
||||
|
||||
Set *houses = malloc(sizeof(Set));
|
||||
set_init(houses, same_Point_v, free);
|
||||
set_init(houses, Point_cmp_v, free);
|
||||
|
||||
while (*c != '\0') {
|
||||
if (is_santa) {
|
||||
@ -37,11 +37,11 @@ static int part_two(char *input) {
|
||||
--(*x);
|
||||
break;
|
||||
}
|
||||
set_insert(houses, (void *) new_Point_p(*x, *y));
|
||||
set_insert(houses, Point_new_p(*x, *y));
|
||||
++c;
|
||||
}
|
||||
|
||||
int sz = (int) houses->size;
|
||||
int sz = houses->size;
|
||||
set_destroy(houses);
|
||||
|
||||
return sz;
|
||||
@ -52,7 +52,7 @@ static int part_one(char *input) {
|
||||
char *c = input;
|
||||
|
||||
Set *houses = malloc(sizeof(Set));
|
||||
set_init(houses, same_Point_v, free);
|
||||
set_init(houses, Point_cmp_v, free);
|
||||
|
||||
while (*c != '\0') {
|
||||
switch (*c) {
|
||||
@ -69,11 +69,11 @@ static int part_one(char *input) {
|
||||
--x;
|
||||
break;
|
||||
}
|
||||
set_insert(houses, (void *) new_Point_p(x, y));
|
||||
set_insert(houses, Point_new_p(x, y));
|
||||
++c;
|
||||
}
|
||||
|
||||
int sz = (int) houses->size;
|
||||
int sz = houses->size;
|
||||
set_destroy(houses);
|
||||
|
||||
return sz;
|
||||
|
@ -4,7 +4,12 @@
|
||||
#include "lfinput.h"
|
||||
|
||||
void advent2017day02(void) {
|
||||
char *input = get_input("input/2017/02");
|
||||
printf("Solution for Day 02 of 2017 is not completed yet\n");
|
||||
size_t sz = 0;
|
||||
char **input = get_lines("input/2017/02", &sz);
|
||||
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
|
||||
}
|
||||
|
||||
free(input);
|
||||
}
|
||||
|
@ -3,13 +3,13 @@
|
||||
#include <limits.h>
|
||||
|
||||
#include "lfinput.h"
|
||||
#include "advent_utility.h"
|
||||
#include "lfutility.h"
|
||||
|
||||
struct Point parse_floors(char *input) {
|
||||
Point parse_floors(char *input) {
|
||||
size_t sz = 0;
|
||||
char **sp = split(input, &sz, "-");
|
||||
const char *errstr;
|
||||
struct Point p;
|
||||
Point p;
|
||||
p.x = strtonum(sp[0], INT_MIN, INT_MAX, &errstr);
|
||||
p.y = strtonum(sp[1], INT_MIN, INT_MAX, &errstr);
|
||||
free(sp);
|
||||
@ -24,8 +24,8 @@ void advent2022day04(void) {
|
||||
for (size_t i = 0; i < sz; ++i) {
|
||||
size_t sp_sz = 0;
|
||||
char **sp = split(lines[i], &sp_sz, ",");
|
||||
struct Point e1 = parse_floors(sp[0]);
|
||||
struct Point e2 = parse_floors(sp[1]);
|
||||
Point e1 = parse_floors(sp[0]);
|
||||
Point e2 = parse_floors(sp[1]);
|
||||
|
||||
if (e1.x <= e2.x && e1.y >= e2.y) {
|
||||
++p1;
|
||||
|
@ -12,31 +12,6 @@
|
||||
|
||||
#include "advent_utility.h"
|
||||
|
||||
struct Point new_Point(int x, int y) {
|
||||
struct Point p;
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
return p;
|
||||
}
|
||||
|
||||
struct Point *new_Point_p(int x, int y) {
|
||||
struct Point *p = malloc(sizeof(struct Point));
|
||||
p->x = x;
|
||||
p->y = y;
|
||||
return p;
|
||||
}
|
||||
|
||||
int same_Point(const struct Point *a, const struct Point *b) {
|
||||
if (a->x == b->x && a->y == b->y) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int same_Point_v(const void *a, const void *b) {
|
||||
return same_Point((const struct Point *) a, (const struct Point *) b);
|
||||
}
|
||||
|
||||
char *md5_str(const char *input) {
|
||||
unsigned char digest[16];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user