C: 2015 Day 3 part 1 done

This commit is contained in:
Brian Buller 2018-03-16 14:11:13 -05:00
parent 7241b745b2
commit 8fbefb2a3c
2 changed files with 73 additions and 1 deletions

71
2015/day03/day03.c Normal file
View File

@ -0,0 +1,71 @@
#include <stdio.h>
void part1() {
printf("Part 1\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 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; }
switch(ch) {
case '>':
x++;
break;
case 'v':
y--;
break;
case '<':
x--;
break;
case '^':
y++;
break;
}
if(x > maxx) {
maxx = x;
}
if(x < minx) {
minx = x;
}
if(y > maxy) {
maxy = y;
}
if(y < miny) {
miny = y;
}
ch = getchar();
}
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);
}
void part2() {
printf("Part 2\n");
}
int main(int argc, char **argv) {
int doPart = 1;
if(argc > 1) { doPart = argv[1][0] - '0'; }
if(doPart == 1) {
part1();
} else {
part2();
}
return 0;
}

File diff suppressed because one or more lines are too long