summaryrefslogtreecommitdiff
path: root/Advent-of-Code-2020/AOC-1
diff options
context:
space:
mode:
Diffstat (limited to 'Advent-of-Code-2020/AOC-1')
-rwxr-xr-xAdvent-of-Code-2020/AOC-1/aoc-1bin0 -> 16696 bytes
-rw-r--r--Advent-of-Code-2020/AOC-1/aoc-1.c81
-rw-r--r--Advent-of-Code-2020/AOC-1/input.txt200
-rw-r--r--Advent-of-Code-2020/AOC-1/sample.txt6
4 files changed, 287 insertions, 0 deletions
diff --git a/Advent-of-Code-2020/AOC-1/aoc-1 b/Advent-of-Code-2020/AOC-1/aoc-1
new file mode 100755
index 0000000..cc27da9
--- /dev/null
+++ b/Advent-of-Code-2020/AOC-1/aoc-1
Binary files differ
diff --git a/Advent-of-Code-2020/AOC-1/aoc-1.c b/Advent-of-Code-2020/AOC-1/aoc-1.c
new file mode 100644
index 0000000..070642f
--- /dev/null
+++ b/Advent-of-Code-2020/AOC-1/aoc-1.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#if 0
+ #define PFILE "sample.txt"
+ #define A_CAP 6
+#else
+ #define PFILE "input.txt"
+ #define A_CAP 200
+#endif
+
+int ints[A_CAP];
+
+void PrintInts()
+{
+ for(int i=0; i<A_CAP; i++)
+ printf("%d\n", ints[i]);
+}
+
+void Parse()
+{
+ // Parse
+ char ch;
+ FILE *fp;
+ fp = fopen(PFILE, "r");
+
+ int i = 0;
+ int n = 0;
+ char *int_str = malloc(sizeof(char)*5);
+ while((ch = fgetc(fp)) != EOF)
+ {
+ if(ch == '\n')
+ {
+ ints[i] = atoi(int_str);
+ i += 1;
+ n = 0;
+ memset(int_str, 0, sizeof(char)*5);
+ continue;
+ }
+
+ int_str[n] = ch;
+ n += 1;
+ }
+
+ assert(i == A_CAP);
+
+ free(int_str);
+ fclose(fp);
+}
+
+void Part1()
+{
+ Parse();
+
+ // Check
+ for(int i=1; i<A_CAP; i++)
+ for(int j=i; j<A_CAP; j++)
+ if((ints[i-1] + ints[j]) == 2020)
+ printf("RESULT-1: %llu\n", ints[i-1] * ints[j]);
+}
+
+void Part2()
+{
+ Parse();
+
+ // Check
+ for(int i=2; i<A_CAP; i++)
+ for(int j=i; j<A_CAP; j++)
+ for(int k=j; k<A_CAP; k++)
+ if((ints[i-2] + ints[j-1] + ints[k]) == 2020)
+ printf("RESULT-2: %llu\n", ints[i-2] * ints[j-1] * ints[k]);
+}
+
+int main(void)
+{
+ Part1();
+ Part2();
+ return 0;
+}
diff --git a/Advent-of-Code-2020/AOC-1/input.txt b/Advent-of-Code-2020/AOC-1/input.txt
new file mode 100644
index 0000000..6465c03
--- /dev/null
+++ b/Advent-of-Code-2020/AOC-1/input.txt
@@ -0,0 +1,200 @@
+1078
+1109
+1702
+1293
+1541
+1422
+1679
+1891
+1898
+1455
+1540
+1205
+1971
+1582
+1139
+1438
+1457
+1725
+1907
+1872
+1101
+1403
+1557
+1597
+1619
+1974
+1287
+292
+1647
+1444
+1241
+879
+1761
+1067
+1178
+1510
+1110
+1233
+1121
+1299
+1796
+1124
+1768
+1466
+1871
+1279
+1344
+1485
+1258
+1179
+1147
+492
+1234
+1843
+1421
+1819
+1964
+1671
+1793
+1302
+1731
+1886
+1686
+1150
+1806
+1960
+1841
+1936
+1845
+1520
+1779
+1102
+1323
+1892
+1742
+1941
+1395
+1525
+1165
+715
+1829
+1448
+1906
+1191
+1981
+1115
+1716
+1644
+1310
+1836
+1105
+1517
+1790
+1950
+1741
+1256
+1467
+1677
+1372
+1838
+1637
+1143
+1763
+1222
+1291
+1835
+1602
+1927
+1933
+1952
+1692
+1662
+1967
+1791
+1984
+1176
+1324
+1460
+1416
+562
+1862
+1273
+1518
+1535
+1093
+1977
+1923
+1246
+1570
+1674
+1861
+1811
+1431
+47
+1158
+1912
+1322
+1062
+1407
+1528
+1068
+1868
+1997
+1930
+959
+1676
+1759
+2000
+1993
+1722
+1738
+1264
+1361
+1542
+1187
+1735
+1405
+1745
+1753
+1833
+1493
+1311
+1547
+1180
+1553
+1513
+1812
+1951
+1948
+1834
+1925
+1726
+1326
+1931
+1962
+1947
+1173
+1633
+1901
+1781
+1483
+1789
+1417
+1929
+1859
+1760
+1347
+1996
+1328
+1798
+1230
+1298
+1877
+1840
+1607
+1253
+1057
+1650
+1171
+1593
diff --git a/Advent-of-Code-2020/AOC-1/sample.txt b/Advent-of-Code-2020/AOC-1/sample.txt
new file mode 100644
index 0000000..e3fb011
--- /dev/null
+++ b/Advent-of-Code-2020/AOC-1/sample.txt
@@ -0,0 +1,6 @@
+1721
+979
+366
+299
+675
+1456