update libflint, 2021-02
This commit is contained in:
parent
6cbdd7b20c
commit
b5caa4dfa4
@ -1,7 +0,0 @@
|
|||||||
#ifndef ADVENT_MATH_H_
|
|
||||||
#define ADVENT_MATH_H_
|
|
||||||
|
|
||||||
int int_max(int, int);
|
|
||||||
int int_min(int, int);
|
|
||||||
|
|
||||||
#endif // ADVENT_MATH_H_
|
|
@ -3,7 +3,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include "advent_math.h"
|
#include "math.h"
|
||||||
|
|
||||||
void advent2015day02(void) {
|
void advent2015day02(void) {
|
||||||
size_t sz = 0;
|
size_t sz = 0;
|
||||||
@ -18,8 +18,8 @@ void advent2015day02(void) {
|
|||||||
t = strtok(NULL, "x");
|
t = strtok(NULL, "x");
|
||||||
int h = atoi(t);
|
int h = atoi(t);
|
||||||
|
|
||||||
paper += 2 * l * w + 2 * w * h + 2 * h * l + int_min(w * l, int_min(l * h, h * w));
|
paper += 2 * l * w + 2 * w * h + 2 * h * l + min_int(w * l, min_int(l * h, h * w));
|
||||||
ribbon += l * w * h + int_min(w + w + h + h, int_min(h + h + l + l, l + l + w + w));
|
ribbon += l * w * h + min_int(w + w + h + h, min_int(h + h + l + l, l + l + w + w));
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%d\n%d\n", paper, ribbon);
|
printf("%d\n%d\n", paper, ribbon);
|
||||||
|
@ -1,10 +1,55 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
void advent2021day02(void) {
|
static void solution(long p2) {
|
||||||
char *input = get_input("input/2021/02");
|
size_t sz = 0;
|
||||||
printf("Solution for Day 02 of 2021 is not completed yet\n");
|
char **input = get_lines("input/2021/02", &sz);
|
||||||
free(input);
|
long h = 0, d = 0, a = 0;
|
||||||
|
|
||||||
|
for (size_t i = 0; i < sz; ++i) {
|
||||||
|
size_t sp_sz = 0;
|
||||||
|
char **sp = split(input[i], &sp_sz, " ");
|
||||||
|
if (sp == NULL) {
|
||||||
|
printf("Failed to split\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
const char *errstr;
|
||||||
|
long n = 0;
|
||||||
|
n = (long)strtonum(sp[1], LONG_MIN, LONG_MAX, &errstr);
|
||||||
|
if (errstr) {
|
||||||
|
printf("Failed to convert %s to long\n", sp[i]);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p2) {
|
||||||
|
if (strcmp("forward", sp[0]) == 0) {
|
||||||
|
h += n;
|
||||||
|
} else if (strcmp("down", sp[0]) == 0) {
|
||||||
|
d += n;
|
||||||
|
} else {
|
||||||
|
d -= n;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (strcmp("forward", sp[0]) == 0) {
|
||||||
|
h += n;
|
||||||
|
d += a * n;
|
||||||
|
} else if (strcmp("down", sp[0]) == 0) {
|
||||||
|
a += n;
|
||||||
|
} else {
|
||||||
|
a -= n;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(sp);
|
||||||
|
}
|
||||||
|
printf("%ld\n", h * d);
|
||||||
|
del_lines(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
void advent2021day02(void) {
|
||||||
|
solution(0);
|
||||||
|
solution(1);
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "input.h"
|
#include "input.h"
|
||||||
|
|
||||||
void advent2021day03(void) {
|
void advent2021day03(void) {
|
||||||
char *input = get_input("input/2021/03");
|
size_t sz;
|
||||||
printf("Solution for Day 03 of 2021 is not completed yet\n");
|
char **input = get_lines("input/2021/03", &sz);
|
||||||
free(input);
|
|
||||||
|
|
||||||
|
del_lines(input);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
#include "advent_math.h"
|
|
||||||
|
|
||||||
int int_max(int a, int b) {
|
|
||||||
return a > b ? a : b;
|
|
||||||
}
|
|
||||||
|
|
||||||
int int_min(int a, int b) {
|
|
||||||
return a < b ? a : b;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user