Progress in c

This commit is contained in:
Brian Buller 2018-03-15 12:00:30 -05:00
parent 2a37946673
commit 5885dced39
5 changed files with 106 additions and 3 deletions

49
2015/day01/day01.c Normal file
View File

@ -0,0 +1,49 @@
#include <stdio.h>
void part1() {
printf("Part 1\n");
int floor = 0;
char ch = getchar();
while(ch) {
if(ch == '\n') { break; }
if(ch == '(') {
floor++;
} else if(ch == ')') {
floor--;
}
ch = getchar();
}
printf("Final Floor: %d\n", floor);
}
void part2() {
printf("Part 2\n");
int floor = 0, step = 0;
char ch = getchar();
while(ch) {
step++;
if(ch == '\n') { break; }
if(ch == '(') {
floor++;
} else if(ch == ')') {
floor--;
}
if(floor < 0) {
break;
}
ch = getchar();
}
printf("Enter basement at: %d\n", step);
}
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

42
2015/day02/day02.c Normal file
View File

@ -0,0 +1,42 @@
#include <stdio.h>
int getBoxArea(int l, int w, int h) {
return (2*l*w + 2*w*h + 2*h*l);
}
int getSmallestSide(int l, int w, int h) {
if(l < w && l < h) {
return l;
}
if(w < l && w < h) {
return w;
}
return h;
}
void part1() {
printf("Part 1\n");
int floor = 0;
char str[100];
int l, w, h, result = 0;
while(scanf("%dx%dx%d", &l, &w, &h) > 0) {
result += getBoxArea(l, w, h) + getSmallestSide(l, w, h);
}
printf("Square Feet Needed: %d\n", result);
}
void part2() {
printf("Part 1\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;
}

View File

@ -997,4 +997,4 @@
29x11x20 29x11x20
3x12x15 3x12x15
24x25x17 24x25x17
14x6x11 14x6x11

View File

@ -1,3 +1,14 @@
# adventofcode # adventofcode
All of my solutions to the Advent of Code All of my solutions to the Advent of Code
## Completion Log
```
+----------+------------+
| Language | Progress |
|----------|------------|
| go | Complete |
| c | 2015/day02 |
+----------+------------+
```