28 lines
623 B
C
28 lines
623 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include "input.h"
|
|
#include "advent_math.h"
|
|
|
|
void advent2015day02(void) {
|
|
size_t sz = 0;
|
|
char **lines = get_lines("input/2015/02", &sz);
|
|
int paper = 0, ribbon = 0;
|
|
|
|
for (size_t i = 0; i < sz; i++) {
|
|
char *t = strtok(lines[i], "x");
|
|
int w = atoi(t);
|
|
t = strtok(NULL, "x");
|
|
int l = atoi(t);
|
|
t = strtok(NULL, "x");
|
|
int h = atoi(t);
|
|
|
|
paper += 2*l*w + 2*w*h + 2*h*l + int_min(w*l, int_min(l*h, h*w));
|
|
ribbon += l*w*h + int_min(w+w+h+h, int_min(h+h+l+l, l+l+w+w));
|
|
}
|
|
|
|
printf("%d\n%d\n", paper, ribbon);
|
|
del_lines(lines);
|
|
}
|