Browse Source

Progress in c

master
Brian Buller 4 years ago
parent
commit
5885dced39
  1. 49
      2015/day01/day01.c
  2. 3
      2015/day01/input
  3. 42
      2015/day02/day02.c
  4. 2
      2015/day02/input
  5. 13
      README.md

49
2015/day01/day01.c

@ -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;
}

3
2015/day01/input
File diff suppressed because it is too large
View File

42
2015/day02/day02.c

@ -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;
}

2
2015/day02/input

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

13
README.md

@ -1,3 +1,14 @@
# 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 |
+----------+------------+
```
Loading…
Cancel
Save