diff options
| author | Bond_009 <bond.009@outlook.com> | 2020-12-02 20:22:31 +0100 |
|---|---|---|
| committer | Bond_009 <bond.009@outlook.com> | 2020-12-02 20:22:31 +0100 |
| commit | d4019c536df8c2abc411825b4501c7a80a83fe0c (patch) | |
| tree | 596c665dcc364122e357def188110b6c3a641735 | |
| parent | 928092a7b82bc6dd16926a378b91e24510b9ec0f (diff) | |
Add day 1
| -rw-r--r-- | 1/input | 200 | ||||
| -rw-r--r-- | 1/part1.c | 33 | ||||
| -rw-r--r-- | 1/part2.c | 35 |
3 files changed, 268 insertions, 0 deletions
@@ -0,0 +1,200 @@ +1779 +1737 +1537 +1167 +1804 +1873 +1894 +1446 +1262 +1608 +1430 +1421 +1826 +1718 +1888 +1314 +1844 +248 +1812 +1627 +1605 +1641 +1126 +1051 +1839 +1067 +1685 +1800 +1383 +1415 +1781 +1372 +1711 +1687 +1357 +1603 +1899 +1856 +1240 +1872 +1483 +1624 +1358 +1168 +1238 +1585 +1159 +1409 +1615 +1258 +1412 +1468 +1912 +1840 +1681 +1700 +1031 +1757 +1911 +1096 +1239 +1331 +1881 +1304 +1694 +1705 +1680 +820 +1744 +1245 +1922 +1545 +1335 +1852 +1318 +1565 +1505 +1535 +1536 +1758 +1508 +1453 +1957 +1375 +1647 +1531 +1261 +1202 +1701 +1562 +1933 +1293 +1828 +334 +1714 +1931 +1385 +1294 +1469 +1629 +1842 +1730 +1534 +1544 +1946 +1805 +1188 +1684 +1875 +1623 +1248 +1347 +2006 +1191 +1037 +1387 +1903 +1746 +16 +952 +1246 +384 +1518 +1738 +1269 +1747 +1423 +1764 +1666 +1999 +1776 +1673 +1350 +1698 +2004 +1235 +1719 +1131 +1671 +1334 +1556 +1299 +1569 +1523 +1655 +1189 +1023 +1264 +1821 +1639 +1114 +1391 +1154 +1225 +1906 +1481 +1728 +1309 +1682 +1662 +1017 +1952 +1948 +2010 +1809 +1394 +1039 +1493 +1509 +1628 +1401 +1515 +1497 +1164 +1829 +1452 +1706 +1919 +1831 +1643 +1849 +1558 +1162 +1328 +1432 +680 +1169 +1393 +1646 +1161 +1104 +1678 +1477 +1824 +1353 +1260 +1736 +1777 +1658 +1715 diff --git a/1/part1.c b/1/part1.c new file mode 100644 index 0000000..85cbfd7 --- /dev/null +++ b/1/part1.c @@ -0,0 +1,33 @@ +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define INPUT_LEN 200 + +int repair(int * arr) +{ + for (int i = 0; i < INPUT_LEN; i++) { + for (int j = 0; j < INPUT_LEN; j++) { + if (arr[i] + arr[j] == 2020) { + return arr[i] * arr[j]; + } + } + } + + return 0; +} + +int main() +{ + FILE * file = fopen("input", "r"); + + char buffer[8] = { 0 }; + int input[INPUT_LEN] = { 0 }; + for (int i = 0; i < 200; i++) { + fgets(buffer, 8, file); + input[i] = atoi(buffer); + } + + printf("%i", repair(input)); +} diff --git a/1/part2.c b/1/part2.c new file mode 100644 index 0000000..5842205 --- /dev/null +++ b/1/part2.c @@ -0,0 +1,35 @@ +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#define INPUT_LEN 200 + +int repair(int * arr) +{ + for (int i = 0; i < INPUT_LEN; i++) { + for (int j = 0; j < INPUT_LEN; j++) { + for (int k = 0; k < INPUT_LEN; k++) { + if (arr[i] + arr[j] + arr[k] == 2020) { + return arr[i] * arr[j] * arr[k]; + } + } + } + } + + return 0; +} + +int main() +{ + FILE * file = fopen("input", "r"); + + char buffer[8] = { 0 }; + int input[INPUT_LEN] = { 0 }; + for (int i = 0; i < 200; i++) { + fgets(buffer, 8, file); + input[i] = atoi(buffer); + } + + printf("%i", repair(input)); +} |
