C: 2015 day 03 complete

This commit is contained in:
Brian Buller 2018-03-22 07:46:02 -05:00
parent 8fbefb2a3c
commit de5c4ac25c
2 changed files with 71 additions and 3 deletions

View File

@ -37,7 +37,6 @@ int getBoxArea(int l, int w, int h) {
void part1() {
printf("Part 1\n");
char str[100];
int l, w, h, result = 0;
while(scanf("%dx%dx%d", &l, &w, &h) > 0) {
result += getBoxSidesArea(l, w, h) + getSmallestSideArea(l, w, h);
@ -47,7 +46,6 @@ void part1() {
void part2() {
printf("Part 2\n");
char str[100];
int l, w, h, result = 0;
while(scanf("%dx%dx%d", &l, &w, &h) > 0) {
result += getSmallestPerimeter(l, w, h) + getBoxArea(l, w, h);

View File

@ -2,6 +2,7 @@
void part1() {
printf("Part 1\n");
char ch = getchar();
int visits[1000][1000];
for(int i = 0; i < 1000; i++) {
@ -11,7 +12,6 @@ void part1() {
}
int x = 0, y = 0, minx = 0, maxx = 0, miny = 0, maxy = 0;
int inc = 0;
printf("(%4d,%4d) (%4d:%4d,%4d:%4d)", x, y, minx, maxx, miny, maxy);
while(ch) {
visits[x+500][y+500]++;
if(ch == '\n') { break; }
@ -56,6 +56,76 @@ void part1() {
void part2() {
printf("Part 2\n");
char ch = getchar();
int visits[1000][1000];
for(int i = 0; i < 1000; i++) {
for(int j = 0; j < 1000; j++) {
visits[i][j] = 0;
}
}
int x1 = 0, y1 = 0, x2 = 0, y2 = 0, minx = 0, maxx = 0, miny = 0, maxy = 0;
int inc = 0;
int robo = -1;
int lastOutLngth = 0;
while(ch) {
robo++;
int usex = x1, usey = y1;
if(robo % 2 == 1) {
usex = x2;
usey = y2;
}
visits[usex+500][usey+500]++;
if(ch == '\n') { break; }
switch(ch) {
case '>':
usex++;
break;
case 'v':
usey--;
break;
case '<':
usex--;
break;
case '^':
usey++;
break;
}
if(usex > maxx) {
maxx = usex;
}
if(usex < minx) {
minx = usex;
}
if(usey > maxy) {
maxy = usey;
}
if(usey < miny) {
miny = usey;
}
// Get the next char
if(robo % 2 == 1) {
x2 = usex;
y2 = usey;
} else {
x1 = usex;
y1 = usey;
}
ch = getchar();
}
// Now find how many houses got presents
int result = 0;
for(int i = 0; i < 1000; i++) {
for(int j = 0; j < 1000; j++) {
if(visits[i][j] > 0) {
result++;
}
}
}
printf("%d houses\n", result);
}
int main(int argc, char **argv) {