Skip to content

Commit 94358a7

Browse files
committed
[c] Day01 complete
1 parent 189265e commit 94358a7

File tree

5 files changed

+46
-0
lines changed

5 files changed

+46
-0
lines changed

c/.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
IndentWidth: 4

c/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
a.*
2+

c/compile_flags.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-Wall
2+
-ansi
3+
-std=c89
4+
-pedantic
5+
-pedantic-errors
6+
# Clang on Windows gets confused about -ansi and deprecations
7+
-Wno-deprecated-declarations

c/day01.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <stdio.h>
2+
3+
int main() {
4+
/* input */
5+
unsigned int buf, count = 0, arr[256];
6+
/* solutions */
7+
unsigned int p1, p2;
8+
/* iterations */
9+
unsigned int i, j, k;
10+
11+
while (scanf("%i", &buf) != EOF) {
12+
arr[count++] = buf;
13+
}
14+
15+
for (i = 0; i < count; i++) {
16+
for (j = 0; j < count; j++) {
17+
if (arr[i] + arr[j] == 2020) {
18+
p1 = arr[i] * arr[j];
19+
}
20+
21+
for (k = 0; k < count; k++) {
22+
if (arr[i] + arr[j] + arr[k] == 2020) {
23+
p2 = arr[i] * arr[j] * arr[k];
24+
}
25+
}
26+
}
27+
}
28+
29+
printf("Part 1: %u\nPart 2: %u\n", p1, p2);
30+
31+
return 0;
32+
}

c/make.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
clang -Wall -ansi -std=c89 -pedantic -pedantic-errors -Wno-deprecated-declarations $1
3+

0 commit comments

Comments
 (0)