aboutsummaryrefslogtreecommitdiff
path: root/2020/01
diff options
context:
space:
mode:
Diffstat (limited to '2020/01')
-rw-r--r--2020/01/.gitignore1
-rw-r--r--2020/01/Makefile7
-rw-r--r--2020/01/input200
-rw-r--r--2020/01/puzzles.c39
4 files changed, 247 insertions, 0 deletions
diff --git a/2020/01/.gitignore b/2020/01/.gitignore
new file mode 100644
index 0000000..60d075d
--- /dev/null
+++ b/2020/01/.gitignore
@@ -0,0 +1 @@
+puzzle-[12]
diff --git a/2020/01/Makefile b/2020/01/Makefile
new file mode 100644
index 0000000..c32dafa
--- /dev/null
+++ b/2020/01/Makefile
@@ -0,0 +1,7 @@
+all:
+ ${CC} ${CFLAGS} -o puzzle-1 puzzles.c
+ ${CC} ${CFLAGS} -DPART2 -o puzzle-2 puzzles.c
+
+.PHONY: clean
+clean:
+ rm -f puzzle-[12]
diff --git a/2020/01/input b/2020/01/input
new file mode 100644
index 0000000..127b7a7
--- /dev/null
+++ b/2020/01/input
@@ -0,0 +1,200 @@
+1293
+1207
+1623
+1675
+1842
+1410
+85
+1108
+557
+1217
+1506
+1956
+1579
+1614
+1360
+1544
+1946
+1666
+1972
+1814
+1699
+1778
+1529
+2002
+1768
+1173
+1407
+1201
+1264
+1739
+1774
+1951
+1980
+1428
+1381
+1714
+884
+1939
+1295
+1694
+1168
+1971
+1352
+1462
+1828
+1402
+1433
+1542
+1144
+1331
+1427
+1261
+1663
+1820
+1570
+1874
+1486
+1613
+1769
+1721
+1753
+1142
+1677
+2010
+1640
+1465
+1171
+534
+1790
+2005
+1604
+1891
+1247
+1281
+1867
+1403
+2004
+1668
+1416
+2001
+1359
+686
+1965
+1728
+1551
+1565
+1128
+1832
+1757
+1350
+1808
+1711
+1799
+1590
+1989
+1547
+1140
+1905
+1368
+1179
+1902
+1473
+1908
+1859
+1257
+1394
+1244
+1800
+1695
+1731
+1474
+1781
+1885
+1154
+1990
+1929
+1193
+1302
+1831
+1226
+1418
+1400
+1435
+1645
+1655
+1843
+1227
+1481
+1754
+1290
+1685
+1498
+71
+1286
+1137
+1288
+1758
+1987
+1471
+1839
+1545
+1682
+1615
+1475
+1849
+1985
+1568
+1795
+1184
+1863
+1362
+1271
+1802
+1944
+1821
+1880
+1788
+1733
+1150
+1314
+1727
+1434
+1833
+1312
+1457
+160
+1629
+1967
+1505
+1239
+1266
+1838
+1687
+1630
+1591
+1893
+1450
+1234
+1755
+1523
+1533
+1499
+1865
+1725
+1444
+1517
+1167
+1738
+1519
+1263
+1901
+1627
+1644
+1771
+1812
+1270
+1497
+1707
+1708
+1396
diff --git a/2020/01/puzzles.c b/2020/01/puzzles.c
new file mode 100644
index 0000000..29384e0
--- /dev/null
+++ b/2020/01/puzzles.c
@@ -0,0 +1,39 @@
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define BUFFER 200
+
+int
+main(void)
+{
+ int nums[BUFFER];
+ FILE *fp;
+
+ if (!(fp = fopen("input", "r")))
+ err(EXIT_FAILURE, "fopen");
+
+ for (int i = 0; i < BUFFER; i++)
+ fscanf(fp, "%d", &nums[i]);
+
+ fclose(fp);
+
+ /* Inefficient, but small sample size so it's fine */
+ for (int i = 0; i < BUFFER - 1; i++) {
+ for (int j = i + 1; j < BUFFER; j++) {
+#ifdef PART2
+ for (int k = j + 1; k < BUFFER; k++) {
+ if (nums[i] + nums[j] + nums[k] == 2020) {
+ printf("%d\n", nums[i] * nums[j] * nums[k]);
+ return EXIT_SUCCESS;
+ }
+ }
+#else
+ if (nums[i] + nums[j] == 2020) {
+ printf("%d\n", nums[i] * nums[j]);
+ return EXIT_SUCCESS;
+ }
+#endif
+ }
+ }
+}