From 9f7b0cd76272068588d0a7220408f91390c5b583 Mon Sep 17 00:00:00 2001 From: jacopograndi Date: Thu, 6 Jan 2022 18:42:22 +0100 Subject: moved --- 2021/day01/day01 | Bin 0 -> 79296 bytes 2021/day01/day01.cpp | 52 ++ 2021/day01/day01_input.txt | 2000 +++++++++++++++++++++++++++++++++++++++++ 2021/day01/day01_input_ez.txt | 10 + 2021/day01/makefile | 2 + 2021/day02/day02 | Bin 0 -> 47672 bytes 2021/day02/day02.cpp | 50 ++ 2021/day02/day02_input.txt | 1000 +++++++++++++++++++++ 2021/day02/makefile | 2 + 2021/day03/day03 | Bin 0 -> 83112 bytes 2021/day03/day03.cpp | 96 ++ 2021/day03/day03_input.txt | 1000 +++++++++++++++++++++ 2021/day03/day03_input_ez.txt | 12 + 2021/day03/makefile | 2 + 2021/day04/day04 | Bin 0 -> 116280 bytes 2021/day04/day04.cpp | 134 +++ 2021/day04/day04_input.txt | 601 +++++++++++++ 2021/day04/day04_input_ez.txt | 19 + 2021/day04/makefile | 2 + 2021/day05/day05 | Bin 0 -> 104096 bytes 2021/day05/day05.cpp | 100 +++ 2021/day05/day05_input.txt | 500 +++++++++++ 2021/day05/day05_input_ez.txt | 10 + 2021/day05/makefile | 2 + 2021/day06/day06 | Bin 0 -> 76512 bytes 2021/day06/day06.cpp | 47 + 2021/day06/day06_input.txt | 1 + 2021/day06/day06_input_ez.txt | 1 + 2021/day06/makefile | 2 + 2021/day07/day07 | Bin 0 -> 76312 bytes 2021/day07/day07.cpp | 40 + 2021/day07/day07_input.txt | 1 + 2021/day07/day07_input_ez.txt | 1 + 2021/day07/makefile | 2 + 2021/day08/day08 | Bin 0 -> 84872 bytes 2021/day08/day08.cpp | 72 ++ 2021/day08/day08_input.txt | 200 +++++ 2021/day08/day08_input_ez.txt | 10 + 2021/day08/makefile | 2 + 2021/utils.h | 26 + 40 files changed, 5999 insertions(+) create mode 100755 2021/day01/day01 create mode 100644 2021/day01/day01.cpp create mode 100644 2021/day01/day01_input.txt create mode 100644 2021/day01/day01_input_ez.txt create mode 100644 2021/day01/makefile create mode 100755 2021/day02/day02 create mode 100644 2021/day02/day02.cpp create mode 100644 2021/day02/day02_input.txt create mode 100644 2021/day02/makefile create mode 100755 2021/day03/day03 create mode 100644 2021/day03/day03.cpp create mode 100644 2021/day03/day03_input.txt create mode 100644 2021/day03/day03_input_ez.txt create mode 100644 2021/day03/makefile create mode 100755 2021/day04/day04 create mode 100644 2021/day04/day04.cpp create mode 100644 2021/day04/day04_input.txt create mode 100644 2021/day04/day04_input_ez.txt create mode 100644 2021/day04/makefile create mode 100755 2021/day05/day05 create mode 100644 2021/day05/day05.cpp create mode 100644 2021/day05/day05_input.txt create mode 100644 2021/day05/day05_input_ez.txt create mode 100644 2021/day05/makefile create mode 100755 2021/day06/day06 create mode 100644 2021/day06/day06.cpp create mode 100644 2021/day06/day06_input.txt create mode 100644 2021/day06/day06_input_ez.txt create mode 100644 2021/day06/makefile create mode 100755 2021/day07/day07 create mode 100644 2021/day07/day07.cpp create mode 100644 2021/day07/day07_input.txt create mode 100644 2021/day07/day07_input_ez.txt create mode 100644 2021/day07/makefile create mode 100755 2021/day08/day08 create mode 100644 2021/day08/day08.cpp create mode 100644 2021/day08/day08_input.txt create mode 100644 2021/day08/day08_input_ez.txt create mode 100644 2021/day08/makefile create mode 100644 2021/utils.h diff --git a/2021/day01/day01 b/2021/day01/day01 new file mode 100755 index 0000000..8fb500a Binary files /dev/null and b/2021/day01/day01 differ diff --git a/2021/day01/day01.cpp b/2021/day01/day01.cpp new file mode 100644 index 0000000..113f86d --- /dev/null +++ b/2021/day01/day01.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include + +std::string read (char* name) { + FILE *f = fopen(name, "r"); + char c = fgetc(f); std::string txt; + while (c != EOF) { txt += c; c = fgetc(f); } + fclose(f); + return txt; +} + +std::vector split (std::vector vec, std::string name) { + auto token = name.find("\n"); + if (token != std::string::npos) { + vec.push_back(name.substr(0, token)); + return split(vec, name.substr(token+1)); + } else if (name.size() > 1) { + vec.push_back(name); + } + return vec; +} + +int main (int argc, char* argv[]) { + if (argc < 2 && argc > 3) return 1; + std::string txt = read(argv[1]); + + std::vector vec; + vec = split(vec, txt); + std::vector depths; + for (auto v : vec) { + depths.push_back(std::stoi(v)); + } + + int window = 1; + if (argc == 3) { window = atoi(argv[2]); } + + int inc = 0; + for (std::size_t i=0; i= window) { + int sum0 = 0, sum1 = 0; + for (int j=0; j sum0) inc ++; + } + } + + std::cout << "The number of depth increases is " << inc << std::endl; + + return 0; +} diff --git a/2021/day01/day01_input.txt b/2021/day01/day01_input.txt new file mode 100644 index 0000000..b3ee114 --- /dev/null +++ b/2021/day01/day01_input.txt @@ -0,0 +1,2000 @@ +198 +208 +209 +212 +213 +217 +218 +223 +222 +224 +216 +233 +238 +239 +240 +250 +263 +264 +267 +274 +288 +316 +319 +330 +340 +347 +349 +354 +350 +349 +351 +352 +353 +371 +383 +385 +405 +413 +455 +451 +459 +458 +459 +461 +463 +475 +480 +486 +489 +497 +502 +512 +513 +516 +517 +528 +559 +560 +558 +565 +566 +567 +571 +573 +574 +582 +583 +585 +589 +597 +608 +607 +614 +619 +608 +624 +665 +666 +675 +695 +698 +703 +711 +733 +738 +739 +742 +743 +763 +775 +778 +804 +806 +810 +812 +818 +819 +828 +867 +866 +876 +878 +881 +875 +881 +858 +859 +868 +869 +860 +888 +890 +891 +893 +894 +919 +924 +925 +933 +937 +950 +955 +966 +984 +989 +993 +996 +997 +1015 +1031 +1035 +1039 +1055 +1057 +1058 +1059 +1060 +1061 +1067 +1069 +1070 +1059 +1060 +1077 +1079 +1078 +1080 +1087 +1088 +1090 +1097 +1082 +1102 +1105 +1106 +1120 +1125 +1130 +1132 +1154 +1141 +1135 +1131 +1133 +1134 +1137 +1138 +1141 +1142 +1143 +1166 +1175 +1193 +1201 +1236 +1238 +1234 +1240 +1242 +1243 +1271 +1276 +1277 +1272 +1286 +1288 +1290 +1292 +1317 +1341 +1361 +1363 +1375 +1376 +1377 +1383 +1387 +1390 +1402 +1404 +1412 +1418 +1426 +1429 +1466 +1480 +1483 +1478 +1484 +1486 +1488 +1491 +1486 +1489 +1492 +1517 +1520 +1523 +1539 +1546 +1551 +1521 +1517 +1518 +1522 +1525 +1526 +1539 +1540 +1544 +1545 +1561 +1571 +1572 +1574 +1575 +1568 +1573 +1587 +1588 +1600 +1603 +1627 +1629 +1633 +1645 +1670 +1671 +1685 +1690 +1696 +1698 +1703 +1698 +1699 +1702 +1714 +1716 +1709 +1738 +1753 +1761 +1766 +1769 +1772 +1761 +1763 +1774 +1781 +1782 +1799 +1802 +1816 +1818 +1819 +1805 +1810 +1817 +1819 +1831 +1834 +1835 +1852 +1855 +1858 +1859 +1856 +1857 +1868 +1885 +1891 +1893 +1890 +1891 +1892 +1893 +1896 +1911 +1912 +1914 +1916 +1914 +1918 +1930 +1932 +1958 +1966 +1976 +1982 +1985 +1986 +1987 +1992 +1997 +2031 +2041 +2042 +2044 +2058 +2060 +2075 +2073 +2084 +2087 +2090 +2125 +2128 +2129 +2130 +2131 +2136 +2137 +2145 +2150 +2152 +2155 +2161 +2162 +2165 +2167 +2189 +2197 +2199 +2214 +2226 +2233 +2234 +2241 +2242 +2256 +2259 +2263 +2257 +2267 +2270 +2269 +2272 +2273 +2275 +2279 +2284 +2285 +2266 +2271 +2287 +2291 +2310 +2313 +2314 +2317 +2311 +2312 +2311 +2312 +2326 +2331 +2332 +2338 +2340 +2352 +2355 +2360 +2361 +2357 +2371 +2384 +2380 +2392 +2393 +2396 +2397 +2400 +2417 +2420 +2421 +2422 +2444 +2457 +2458 +2464 +2467 +2494 +2495 +2498 +2510 +2514 +2521 +2526 +2525 +2533 +2536 +2547 +2544 +2547 +2556 +2557 +2558 +2561 +2570 +2571 +2573 +2575 +2583 +2584 +2585 +2572 +2574 +2575 +2587 +2589 +2590 +2602 +2603 +2604 +2605 +2589 +2603 +2608 +2611 +2616 +2613 +2617 +2618 +2619 +2628 +2629 +2630 +2631 +2639 +2645 +2649 +2657 +2665 +2673 +2680 +2679 +2680 +2702 +2703 +2709 +2711 +2714 +2715 +2716 +2715 +2721 +2720 +2739 +2745 +2748 +2752 +2749 +2748 +2749 +2751 +2752 +2750 +2760 +2777 +2778 +2779 +2780 +2787 +2800 +2805 +2810 +2812 +2820 +2821 +2843 +2846 +2853 +2862 +2861 +2867 +2880 +2890 +2891 +2892 +2885 +2887 +2890 +2894 +2897 +2925 +2926 +2931 +2933 +2940 +2943 +2941 +2959 +2971 +2982 +2984 +3002 +3006 +3008 +3012 +3013 +3034 +3043 +3059 +3063 +3064 +3060 +3075 +3090 +3091 +3104 +3108 +3114 +3117 +3106 +3104 +3110 +3113 +3114 +3126 +3119 +3138 +3140 +3141 +3143 +3139 +3145 +3147 +3153 +3161 +3170 +3168 +3180 +3181 +3177 +3196 +3210 +3216 +3232 +3233 +3234 +3235 +3239 +3240 +3242 +3243 +3244 +3243 +3248 +3249 +3275 +3276 +3278 +3280 +3286 +3291 +3293 +3294 +3301 +3310 +3319 +3326 +3338 +3339 +3348 +3366 +3376 +3371 +3372 +3404 +3407 +3408 +3425 +3444 +3451 +3457 +3452 +3459 +3468 +3491 +3475 +3476 +3481 +3505 +3516 +3519 +3542 +3543 +3541 +3542 +3541 +3551 +3553 +3552 +3533 +3542 +3543 +3561 +3562 +3563 +3566 +3571 +3572 +3596 +3600 +3603 +3607 +3608 +3609 +3613 +3654 +3665 +3672 +3661 +3662 +3663 +3670 +3676 +3683 +3707 +3709 +3714 +3717 +3709 +3710 +3713 +3714 +3715 +3716 +3735 +3749 +3763 +3770 +3784 +3782 +3786 +3790 +3792 +3794 +3803 +3805 +3819 +3823 +3826 +3828 +3838 +3839 +3843 +3870 +3877 +3888 +3889 +3891 +3892 +3893 +3894 +3880 +3860 +3878 +3880 +3888 +3893 +3898 +3904 +3906 +3907 +3910 +3918 +3927 +3946 +3973 +3982 +3979 +3980 +3993 +3984 +3988 +3986 +3987 +3988 +3989 +3997 +4000 +4001 +4025 +4030 +4034 +4038 +4040 +4044 +4046 +4048 +4057 +4067 +4079 +4092 +4094 +4122 +4124 +4128 +4127 +4128 +4132 +4136 +4141 +4146 +4151 +4153 +4163 +4167 +4168 +4170 +4172 +4176 +4177 +4178 +4194 +4198 +4199 +4201 +4203 +4204 +4205 +4204 +4209 +4211 +4213 +4224 +4240 +4242 +4255 +4266 +4280 +4284 +4295 +4310 +4323 +4343 +4351 +4359 +4383 +4387 +4388 +4397 +4401 +4403 +4404 +4405 +4425 +4431 +4435 +4439 +4444 +4452 +4461 +4470 +4466 +4467 +4469 +4481 +4482 +4498 +4496 +4504 +4505 +4512 +4518 +4520 +4521 +4523 +4534 +4516 +4527 +4525 +4534 +4535 +4551 +4565 +4570 +4571 +4578 +4584 +4595 +4609 +4610 +4618 +4628 +4629 +4630 +4634 +4636 +4637 +4640 +4659 +4664 +4669 +4665 +4673 +4687 +4688 +4693 +4694 +4697 +4667 +4678 +4679 +4702 +4707 +4706 +4709 +4711 +4718 +4725 +4716 +4718 +4723 +4724 +4726 +4727 +4729 +4735 +4736 +4738 +4739 +4758 +4763 +4773 +4774 +4776 +4777 +4778 +4777 +4785 +4786 +4771 +4773 +4774 +4777 +4781 +4783 +4788 +4791 +4794 +4807 +4816 +4818 +4825 +4828 +4838 +4822 +4831 +4837 +4841 +4851 +4854 +4870 +4876 +4888 +4889 +4900 +4906 +4909 +4910 +4917 +4919 +4920 +4926 +4928 +4934 +4941 +4943 +4945 +4948 +4950 +4956 +4951 +4948 +4954 +4958 +4960 +4959 +4962 +4969 +4982 +4986 +4994 +5000 +5009 +5027 +5025 +5029 +5033 +5037 +5036 +5037 +5040 +5032 +5033 +5034 +5039 +5045 +5050 +5045 +5076 +5077 +5082 +5083 +5106 +5107 +5114 +5117 +5137 +5138 +5143 +5147 +5153 +5156 +5171 +5182 +5183 +5184 +5185 +5189 +5182 +5189 +5194 +5201 +5205 +5213 +5218 +5221 +5223 +5230 +5231 +5243 +5255 +5230 +5228 +5237 +5245 +5248 +5259 +5260 +5272 +5278 +5281 +5287 +5286 +5287 +5298 +5328 +5329 +5333 +5335 +5337 +5339 +5341 +5346 +5349 +5350 +5351 +5358 +5359 +5360 +5374 +5376 +5359 +5360 +5388 +5401 +5406 +5410 +5412 +5413 +5414 +5415 +5435 +5436 +5441 +5443 +5448 +5446 +5448 +5449 +5464 +5465 +5466 +5469 +5470 +5492 +5493 +5494 +5509 +5520 +5528 +5530 +5537 +5541 +5542 +5559 +5562 +5563 +5588 +5595 +5596 +5601 +5618 +5626 +5627 +5641 +5667 +5679 +5685 +5693 +5695 +5717 +5733 +5734 +5754 +5755 +5757 +5758 +5759 +5760 +5761 +5771 +5774 +5780 +5784 +5785 +5787 +5788 +5790 +5800 +5811 +5814 +5810 +5811 +5794 +5792 +5803 +5804 +5812 +5814 +5815 +5836 +5852 +5853 +5855 +5878 +5879 +5880 +5883 +5889 +5897 +5911 +5932 +5934 +5935 +5936 +5938 +5939 +5941 +5951 +5955 +5950 +5951 +5954 +5970 +5971 +5974 +5977 +5978 +5985 +5986 +6013 +6024 +6031 +6037 +6043 +6052 +6051 +6053 +6076 +6096 +6101 +6106 +6108 +6115 +6125 +6106 +6107 +6104 +6114 +6142 +6143 +6162 +6169 +6170 +6171 +6181 +6198 +6199 +6202 +6206 +6207 +6244 +6246 +6249 +6250 +6254 +6264 +6271 +6276 +6277 +6268 +6271 +6288 +6293 +6308 +6309 +6326 +6341 +6345 +6344 +6341 +6364 +6365 +6366 +6370 +6371 +6373 +6376 +6377 +6378 +6377 +6379 +6386 +6396 +6397 +6420 +6422 +6429 +6433 +6463 +6472 +6473 +6490 +6491 +6492 +6497 +6522 +6523 +6524 +6519 +6520 +6521 +6525 +6530 +6531 +6534 +6535 +6543 +6552 +6558 +6584 +6586 +6587 +6588 +6606 +6614 +6618 +6646 +6650 +6651 +6654 +6677 +6663 +6665 +6676 +6655 +6653 +6655 +6665 +6667 +6682 +6692 +6703 +6704 +6707 +6715 +6719 +6730 +6731 +6733 +6743 +6747 +6748 +6750 +6759 +6771 +6772 +6776 +6775 +6776 +6782 +6785 +6812 +6841 +6858 +6860 +6859 +6877 +6886 +6895 +6914 +6919 +6922 +6924 +6933 +6935 +6936 +6937 +6938 +6952 +6962 +6965 +6984 +6987 +6986 +6985 +6977 +6967 +6968 +6966 +6980 +6997 +6994 +7002 +7008 +7000 +6975 +7009 +7014 +7015 +7026 +7027 +7034 +7036 +7041 +7040 +7041 +7045 +7048 +7065 +7074 +7075 +7082 +7087 +7092 +7098 +7097 +7111 +7127 +7124 +7135 +7136 +7137 +7140 +7153 +7156 +7158 +7174 +7176 +7177 +7163 +7166 +7159 +7157 +7158 +7164 +7165 +7172 +7190 +7194 +7199 +7200 +7205 +7208 +7207 +7222 +7227 +7244 +7249 +7271 +7272 +7273 +7274 +7281 +7286 +7288 +7314 +7315 +7317 +7318 +7319 +7304 +7307 +7308 +7309 +7312 +7319 +7322 +7337 +7338 +7345 +7346 +7350 +7360 +7361 +7362 +7360 +7395 +7400 +7404 +7405 +7407 +7406 +7411 +7420 +7435 +7440 +7442 +7446 +7453 +7446 +7448 +7467 +7471 +7469 +7470 +7482 +7485 +7492 +7488 +7489 +7492 +7493 +7494 +7497 +7504 +7520 +7525 +7547 +7554 +7543 +7553 +7560 +7561 +7577 +7589 +7591 +7593 +7587 +7596 +7597 +7584 +7590 +7591 +7599 +7626 +7627 +7628 +7630 +7645 +7639 +7645 +7652 +7657 +7662 +7664 +7674 +7680 +7681 +7694 +7698 +7716 +7704 +7705 +7706 +7708 +7712 +7716 +7715 +7717 +7722 +7723 +7728 +7721 +7722 +7724 +7727 +7735 +7737 +7725 +7746 +7747 +7750 +7761 +7762 +7765 +7777 +7780 +7776 +7777 +7778 +7759 +7769 +7770 +7787 +7797 +7798 +7804 +7803 +7804 +7805 +7811 +7825 +7824 +7826 +7827 +7828 +7851 +7867 +7887 +7889 +7890 +7900 +7904 +7917 +7918 +7935 +7941 +7942 +7946 +7947 +7948 +7949 +7976 +7979 +7981 +7983 +7988 +7999 +8000 +8009 +8011 +8012 +8019 +8021 +8025 +8027 +8006 +8011 +8034 +8036 +8037 +8038 +8013 +8024 +8029 +8032 +8033 +8034 +8032 +8034 +8036 +8059 +8060 +8063 +8064 +8081 +8090 +8097 +8122 +8135 +8147 +8149 +8150 +8151 +8162 +8174 +8154 +8158 +8162 +8170 +8171 +8188 +8189 +8190 +8191 +8196 +8205 +8216 +8217 +8222 +8233 +8239 +8240 +8242 +8257 +8249 +8262 +8264 +8274 +8309 +8311 +8328 +8333 +8335 +8338 +8344 +8350 +8349 +8350 +8363 +8366 +8370 +8371 +8395 +8398 +8401 +8410 +8425 +8429 +8430 +8441 +8443 +8445 +8451 +8452 +8455 +8458 +8431 +8443 +8453 +8459 +8477 +8474 +8479 +8476 +8487 +8488 +8489 +8500 +8501 +8503 +8504 +8538 +8523 +8529 +8530 +8556 +8573 +8576 +8589 +8595 +8624 +8632 +8634 +8628 +8636 +8635 +8636 +8644 +8659 +8661 +8641 +8652 +8659 +8650 +8664 +8667 +8674 +8676 +8678 +8686 +8696 +8697 +8735 +8740 +8749 +8767 +8769 +8747 +8751 +8760 +8755 +8766 +8768 +8777 +8782 +8788 +8796 +8799 +8801 +8809 +8807 +8816 +8827 +8831 +8835 +8836 +8843 +8844 +8845 +8851 +8858 +8860 +8862 +8863 +8889 +8891 +8912 +8913 +8924 +8928 +8929 +8939 +8955 +8957 +8958 +8963 +8988 +8989 +8997 +8995 +8999 +8968 +8990 +8991 +8992 +8994 +8996 +9013 +9024 +9026 +9035 +9046 +9047 +9083 +9084 +9089 +9096 +9108 +9107 +9116 +9123 +9122 +9128 +9132 +9151 +9155 +9163 +9174 +9178 +9183 +9199 +9209 +9217 +9219 +9232 +9233 +9232 +9237 +9241 +9244 +9245 +9247 +9251 +9252 +9266 +9285 +9284 +9291 +9294 +9295 +9296 +9300 +9322 +9328 +9333 +9337 +9345 +9346 +9347 +9371 +9375 +9394 +9397 +9404 +9406 +9422 +9425 +9438 +9440 +9435 +9442 +9455 +9473 +9475 +9496 +9499 +9500 +9511 +9512 +9513 +9539 +9540 +9543 +9547 +9550 +9557 +9571 +9577 +9593 +9600 +9609 +9615 +9620 +9621 +9616 +9625 +9626 +9637 +9638 +9642 +9648 +9656 +9654 +9661 +9665 +9696 +9705 +9710 +9719 +9720 +9717 +9718 +9717 +9719 +9724 +9725 +9738 +9741 +9743 +9744 +9745 +9765 +9778 +9779 +9789 +9791 +9773 +9778 +9780 +9782 +9783 +9782 +9797 +9799 +9800 +9801 +9823 +9824 +9834 +9836 +9841 +9845 +9847 +9865 +9868 +9883 +9884 +9887 +9890 +9892 +9899 +9908 +9910 +9911 +9915 +9918 +9922 +9926 +9923 +9944 +9947 +9948 +9949 +9958 +9959 +9961 +9973 +9954 +9976 +9978 +10001 +10000 +9992 +9997 +9985 +9995 +9996 +10005 +9999 +10001 +10002 +10009 +10041 +10045 +10051 +10070 +10071 +10073 +10100 +10099 +10100 +10101 +10102 +10105 +10082 +10083 +10082 +10086 +10112 +10113 +10114 +10122 +10124 +10127 +10140 +10156 +10157 +10158 +10159 +10162 +10163 +10166 +10177 +10178 +10180 +10178 +10179 +10191 +10186 +10198 +10201 +10204 +10227 +10229 +10232 +10234 +10246 +10247 +10248 +10249 +10250 +10269 +10277 +10278 +10279 +10289 +10291 +10294 +10292 +10304 +10324 +10339 +10342 +10343 +10349 +10354 +10371 +10370 +10374 +10376 +10379 +10405 +10406 +10405 +10403 +10411 +10412 +10411 +10419 +10422 +10435 +10437 +10438 +10437 +10440 +10427 +10421 +10432 +10434 +10439 +10449 +10442 +10469 +10471 +10476 +10480 +10481 +10485 +10507 +10508 +10511 +10512 +10513 +10523 +10524 +10529 +10536 +10552 +10563 +10569 +10573 +10575 +10576 +10578 +10596 +10602 +10630 +10647 +10657 +10659 +10684 +10687 +10692 +10693 +10700 +10702 +10703 +10709 +10714 +10716 +10727 +10746 +10744 +10754 +10753 +10754 +10755 +10759 +10763 +10764 +10765 +10769 +10770 +10771 +10777 +10796 +10807 +10813 +10818 +10825 +10830 +10835 +10836 +10849 +10858 +10873 +10882 +10879 +10882 +10886 +10902 +10903 +10931 +10930 diff --git a/2021/day01/day01_input_ez.txt b/2021/day01/day01_input_ez.txt new file mode 100644 index 0000000..167e291 --- /dev/null +++ b/2021/day01/day01_input_ez.txt @@ -0,0 +1,10 @@ +199 +200 +208 +210 +200 +207 +240 +269 +260 +263 diff --git a/2021/day01/makefile b/2021/day01/makefile new file mode 100644 index 0000000..92fb064 --- /dev/null +++ b/2021/day01/makefile @@ -0,0 +1,2 @@ +all day01.cpp: + g++ -std=c++20 -o day01 day01.cpp diff --git a/2021/day02/day02 b/2021/day02/day02 new file mode 100755 index 0000000..8755c57 Binary files /dev/null and b/2021/day02/day02 differ diff --git a/2021/day02/day02.cpp b/2021/day02/day02.cpp new file mode 100644 index 0000000..dccb44a --- /dev/null +++ b/2021/day02/day02.cpp @@ -0,0 +1,50 @@ +#include + +int main (int argc, char *argv[]) { + if (argc != 2) return 1; + + int depth = 0; + int forward = 0; + + int aim = 0; + int aim_depth = 0; + + FILE *f = fopen(argv[1], "r"); + char c = fgetc(f); + std::string command; + while (c != EOF) { + if (c == '\n') { + auto token_space = command.find(" "); + if (token_space != std::string::npos) { + std::string op = command.substr(0, token_space); + int amt = std::stoi(command.substr(token_space+1)); + if (op == "forward") { + forward += amt; + aim_depth += aim * amt; + } + if (op == "down") { + depth += amt; + aim += amt; + } + if (op == "up") { + depth -= amt; + aim -= amt; + } + } + command = ""; + } + else command += c; + c = fgetc(f); + } + + std::cout << "depth " << depth << ", " + << "forward " << forward << ", " + << "product " << depth * forward << std::endl; + + std::cout << "using aim: depth " << aim_depth << ", " + << "forward " << forward << ", " + << "aim " << aim << ", " + << "product " << aim_depth * forward << std::endl; + + return 0; +} diff --git a/2021/day02/day02_input.txt b/2021/day02/day02_input.txt new file mode 100644 index 0000000..7834464 --- /dev/null +++ b/2021/day02/day02_input.txt @@ -0,0 +1,1000 @@ +forward 8 +forward 9 +forward 9 +down 3 +forward 9 +down 1 +down 7 +down 7 +down 4 +down 2 +down 6 +down 6 +down 2 +forward 6 +forward 6 +forward 2 +forward 2 +forward 7 +forward 6 +up 6 +up 8 +forward 5 +forward 4 +down 6 +forward 7 +down 5 +forward 5 +down 8 +down 8 +down 7 +forward 4 +down 2 +forward 7 +up 8 +forward 3 +down 2 +forward 1 +up 3 +forward 3 +up 1 +down 3 +up 7 +up 2 +down 4 +down 2 +forward 9 +forward 3 +down 8 +forward 5 +up 9 +up 4 +forward 9 +down 1 +forward 6 +down 3 +forward 8 +up 2 +forward 3 +up 7 +down 4 +forward 2 +forward 7 +forward 3 +down 1 +down 3 +up 5 +forward 6 +down 5 +down 4 +down 8 +down 2 +up 5 +forward 7 +up 8 +forward 2 +down 5 +forward 3 +up 1 +up 5 +down 8 +down 3 +forward 4 +forward 4 +forward 1 +up 8 +down 9 +forward 7 +forward 9 +down 5 +up 3 +down 9 +up 6 +forward 1 +forward 3 +forward 5 +down 5 +forward 6 +down 3 +down 8 +forward 3 +forward 5 +forward 7 +forward 6 +down 9 +down 5 +down 6 +down 5 +down 1 +down 8 +forward 3 +down 9 +down 5 +down 5 +forward 9 +forward 2 +down 7 +forward 9 +forward 9 +up 1 +forward 3 +up 9 +forward 5 +forward 7 +down 7 +forward 2 +up 8 +up 6 +down 7 +down 3 +down 5 +down 2 +forward 6 +forward 6 +up 6 +up 2 +forward 4 +forward 7 +forward 1 +down 4 +up 8 +down 3 +up 1 +down 2 +forward 4 +forward 7 +up 1 +down 7 +forward 8 +up 2 +down 8 +up 4 +up 4 +up 2 +down 8 +up 4 +down 6 +up 8 +down 5 +up 5 +down 8 +forward 9 +down 1 +down 5 +forward 3 +forward 3 +up 9 +down 2 +forward 3 +down 6 +forward 1 +forward 9 +forward 3 +down 8 +up 4 +down 1 +down 8 +up 1 +forward 2 +down 7 +up 3 +up 8 +down 2 +up 6 +forward 6 +down 9 +forward 4 +forward 7 +up 9 +forward 3 +forward 2 +down 8 +down 2 +down 5 +down 5 +down 1 +up 7 +down 4 +forward 5 +down 9 +down 5 +down 1 +down 6 +forward 9 +down 6 +forward 3 +down 3 +up 6 +forward 2 +forward 6 +down 2 +down 9 +down 6 +down 1 +down 7 +down 6 +down 6 +up 1 +forward 8 +down 9 +down 6 +down 8 +down 8 +down 6 +down 3 +forward 9 +forward 6 +down 9 +forward 5 +down 6 +down 6 +down 9 +down 7 +down 3 +forward 1 +up 9 +forward 9 +down 7 +forward 4 +down 1 +forward 9 +up 9 +down 7 +forward 5 +down 3 +up 7 +forward 9 +forward 6 +forward 3 +forward 8 +down 4 +down 1 +down 7 +down 7 +up 4 +down 9 +forward 6 +forward 7 +down 8 +forward 2 +forward 2 +forward 9 +forward 6 +forward 9 +up 6 +up 8 +forward 2 +up 3 +forward 9 +forward 1 +down 4 +forward 8 +down 4 +forward 5 +forward 7 +up 2 +forward 5 +down 4 +forward 3 +down 5 +forward 9 +up 3 +forward 8 +down 7 +down 7 +down 9 +forward 2 +down 1 +down 6 +up 8 +down 2 +down 1 +up 3 +down 3 +forward 2 +forward 6 +up 6 +down 3 +up 9 +up 3 +down 8 +up 6 +down 2 +forward 4 +up 1 +down 5 +down 4 +up 9 +up 7 +forward 7 +down 9 +forward 9 +forward 5 +forward 3 +down 4 +up 6 +up 7 +down 7 +down 6 +up 9 +up 4 +down 7 +forward 7 +forward 8 +down 9 +forward 5 +forward 4 +down 5 +forward 8 +forward 5 +up 3 +down 9 +forward 1 +forward 2 +up 3 +down 2 +down 1 +forward 5 +forward 5 +forward 6 +up 2 +forward 3 +down 7 +down 6 +up 3 +down 4 +down 4 +forward 5 +down 3 +up 6 +forward 1 +up 8 +forward 7 +forward 1 +forward 9 +down 2 +up 8 +up 1 +up 4 +forward 9 +forward 3 +forward 5 +down 1 +up 9 +down 1 +forward 3 +down 6 +down 8 +up 4 +forward 6 +up 7 +down 8 +forward 9 +up 2 +down 7 +down 1 +forward 9 +up 7 +forward 3 +forward 9 +forward 1 +forward 1 +down 9 +forward 1 +up 4 +down 5 +forward 4 +down 1 +forward 4 +forward 9 +up 4 +down 3 +down 6 +up 2 +down 6 +down 5 +forward 5 +up 1 +up 9 +forward 8 +up 3 +down 1 +forward 3 +forward 7 +up 6 +up 3 +down 6 +forward 7 +up 6 +down 7 +forward 8 +up 4 +down 8 +up 9 +up 3 +down 3 +forward 8 +down 4 +down 9 +forward 2 +down 7 +up 1 +forward 9 +forward 5 +up 8 +forward 9 +forward 4 +forward 9 +forward 7 +down 4 +up 4 +down 7 +down 4 +down 4 +down 1 +forward 5 +forward 4 +down 1 +down 4 +down 8 +down 3 +forward 7 +forward 4 +down 1 +down 9 +up 3 +forward 2 +down 8 +down 9 +down 2 +down 5 +up 9 +down 9 +up 9 +forward 5 +forward 8 +forward 9 +down 5 +forward 6 +down 8 +down 9 +forward 8 +up 5 +up 9 +up 7 +up 8 +forward 9 +forward 1 +up 6 +down 8 +down 8 +forward 1 +up 1 +forward 8 +forward 6 +down 4 +forward 1 +down 7 +forward 8 +forward 3 +up 3 +down 4 +down 2 +forward 2 +forward 3 +up 4 +down 3 +forward 2 +down 8 +forward 7 +up 3 +down 2 +forward 2 +down 5 +up 6 +up 6 +forward 4 +up 4 +down 8 +forward 8 +down 9 +down 9 +down 6 +down 2 +forward 2 +up 6 +up 5 +forward 3 +forward 3 +up 9 +down 3 +forward 8 +down 5 +forward 5 +forward 7 +down 3 +down 4 +down 1 +down 8 +down 1 +down 1 +forward 9 +forward 3 +down 8 +down 6 +up 9 +forward 1 +forward 5 +up 9 +up 8 +forward 2 +up 8 +down 9 +up 2 +forward 5 +forward 1 +forward 8 +down 3 +forward 4 +down 5 +up 6 +forward 8 +forward 9 +forward 3 +down 1 +down 3 +down 3 +up 4 +forward 9 +down 3 +down 6 +forward 3 +forward 2 +down 6 +down 8 +forward 6 +up 8 +up 3 +up 4 +forward 2 +forward 4 +forward 4 +forward 7 +down 6 +up 8 +down 3 +forward 8 +forward 4 +down 7 +down 5 +forward 6 +forward 4 +forward 6 +down 3 +forward 3 +down 1 +down 7 +forward 3 +forward 2 +forward 7 +down 5 +up 4 +down 6 +down 9 +forward 3 +forward 5 +forward 3 +down 1 +forward 2 +up 5 +up 6 +forward 2 +down 4 +forward 3 +down 4 +down 1 +forward 8 +up 2 +down 3 +down 6 +up 5 +forward 3 +forward 6 +down 3 +forward 1 +down 7 +forward 2 +forward 1 +forward 6 +forward 5 +forward 3 +down 4 +down 8 +forward 1 +up 2 +up 8 +down 4 +forward 9 +up 6 +forward 5 +forward 7 +down 5 +forward 5 +down 1 +forward 4 +forward 5 +up 2 +forward 5 +up 8 +up 1 +forward 2 +down 4 +down 6 +forward 4 +down 2 +down 3 +forward 2 +up 3 +up 4 +forward 2 +down 6 +forward 1 +forward 4 +down 6 +forward 7 +up 2 +forward 7 +forward 6 +up 2 +forward 8 +forward 4 +forward 9 +down 1 +down 8 +forward 3 +forward 2 +down 8 +up 1 +forward 4 +down 8 +forward 2 +forward 8 +up 2 +down 1 +forward 4 +forward 2 +up 4 +up 2 +down 3 +up 8 +forward 3 +up 8 +forward 9 +up 1 +up 5 +down 5 +down 6 +forward 1 +up 5 +up 8 +forward 7 +down 5 +up 4 +forward 2 +up 4 +up 4 +down 2 +forward 6 +forward 2 +down 7 +down 5 +forward 1 +down 2 +down 5 +down 7 +up 8 +down 8 +up 5 +down 1 +forward 5 +down 2 +forward 5 +down 1 +up 7 +up 2 +forward 2 +forward 3 +forward 6 +forward 3 +down 8 +up 8 +forward 8 +forward 1 +forward 7 +up 2 +forward 9 +down 1 +forward 5 +up 9 +forward 3 +forward 7 +forward 8 +up 1 +down 3 +forward 5 +down 2 +forward 6 +forward 3 +down 9 +up 5 +forward 2 +down 4 +up 1 +forward 4 +up 4 +down 8 +down 8 +forward 3 +forward 8 +down 7 +up 3 +forward 1 +up 3 +forward 9 +forward 7 +forward 1 +down 6 +forward 3 +down 1 +down 8 +forward 5 +forward 3 +up 6 +forward 5 +forward 4 +forward 3 +forward 9 +forward 8 +down 6 +down 2 +forward 7 +forward 6 +up 6 +down 6 +down 4 +down 3 +forward 8 +down 9 +up 5 +forward 3 +forward 2 +down 5 +up 4 +down 6 +down 3 +forward 9 +down 2 +forward 9 +forward 8 +up 1 +down 2 +forward 7 +up 5 +up 6 +down 8 +up 9 +up 8 +forward 1 +forward 5 +down 9 +forward 8 +down 8 +up 1 +down 7 +forward 7 +up 3 +down 3 +down 1 +forward 2 +down 3 +forward 9 +forward 2 +down 8 +down 2 +forward 5 +down 9 +down 1 +down 5 +down 6 +up 4 +up 3 +down 1 +up 7 +forward 6 +down 3 +down 6 +up 5 +forward 8 +up 8 +down 1 +down 2 +up 8 +down 7 +forward 7 +forward 4 +down 8 +down 3 +forward 3 +down 4 +forward 3 +down 6 +forward 4 +forward 7 +forward 9 +up 7 +forward 1 +down 7 +down 8 +down 8 +up 6 +down 3 +forward 5 +forward 5 +forward 9 +forward 4 +down 4 +down 8 +down 7 +down 1 +forward 2 +forward 4 +down 3 +down 6 +down 7 +forward 5 +down 8 +down 1 +forward 4 +forward 3 +forward 1 +down 6 +down 7 +down 1 +forward 6 +down 4 +up 2 +forward 4 +down 2 +up 5 +down 2 +down 6 +up 7 +forward 4 +forward 7 +forward 9 +up 5 +down 9 +up 5 +forward 6 +down 2 +up 8 +up 9 +up 9 +forward 5 +down 2 +forward 2 +down 7 +forward 5 +forward 9 +up 8 +down 8 +forward 1 +down 2 +up 3 +forward 3 +down 5 +forward 4 +down 3 +forward 4 +forward 9 +forward 3 +down 5 +forward 4 +down 2 +forward 5 +forward 8 +up 6 +up 2 +down 3 +forward 6 +down 5 +down 4 +down 4 +down 4 +up 2 +up 2 +forward 6 +forward 2 +forward 9 +down 2 +down 9 +down 8 +forward 2 +down 3 +up 3 +forward 5 +down 4 +up 3 +forward 3 +down 1 +forward 7 +forward 5 +forward 6 +down 8 +down 5 +down 5 +down 9 +up 2 +forward 3 +down 4 +down 9 +forward 3 +forward 9 +forward 2 +forward 4 +up 6 +down 6 +up 9 +forward 8 +down 7 +forward 1 +forward 4 +up 1 +up 2 +down 9 +forward 6 +down 6 +down 1 +down 4 +down 7 +down 6 +forward 5 +up 1 +up 7 +down 2 +down 8 +down 2 +down 7 +down 3 +up 9 +down 7 +down 5 +down 6 +forward 9 +up 3 +forward 2 +down 8 +forward 4 +down 6 +forward 3 +up 3 +down 5 +up 4 +forward 6 +forward 7 +forward 9 +down 3 +forward 7 +forward 3 +down 4 +up 4 +down 8 +forward 6 +forward 7 +forward 9 +forward 4 +down 3 +up 5 +down 7 +down 7 +forward 9 diff --git a/2021/day02/makefile b/2021/day02/makefile new file mode 100644 index 0000000..61ca2f4 --- /dev/null +++ b/2021/day02/makefile @@ -0,0 +1,2 @@ +all day02.cpp: + g++ -std=c++20 -o day02 day02.cpp diff --git a/2021/day03/day03 b/2021/day03/day03 new file mode 100755 index 0000000..ccb1732 Binary files /dev/null and b/2021/day03/day03 differ diff --git a/2021/day03/day03.cpp b/2021/day03/day03.cpp new file mode 100644 index 0000000..036cd07 --- /dev/null +++ b/2021/day03/day03.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include + +int bin_to_dec (std::string bin) { + int dec = 0, pow = 1; + for (std::size_t i=bin.size(); i > 0; i--) { + dec += pow * (bin[i-1] == '0' ? 0 : 1); + pow *= 2; + } + return dec; +} + +std::vector get_freq (std::vector bits) { + std::vector freq; + for (std::size_t i=0; i filter (std::vector bits, int inv, int sel) { + std::vector res; + auto freq = get_freq(bits); + + for (auto b : bits) { + int f = freq[sel] * inv; + if (f == 0) f += inv; + if ((f > 0 ? '0' : '1') == b[sel]) { + res.push_back(b); + } + } + + return res; +} + +int main (int argc, char *argv[]) { + if (argc != 2) return 1; + + std::string raw; + std::getline(std::ifstream(argv[1]), raw, '\0'); + + std::vector bits; + + while (1) { + auto token = raw.find("\n"); + if (token != std::string::npos) { + bits.push_back(raw.substr(0, token)); + raw = raw.substr(token+1); + } else { + if (raw.size() > 0) bits.push_back(raw); + break; + } + } + + auto freq = get_freq(bits); + + std::string gamma = "", epsilon = ""; + for (std::size_t i=0; i 0 ? "1" : "0"; + epsilon += freq[i] > 0 ? "0" : "1"; + } + + int g = bin_to_dec(gamma); + int e = bin_to_dec(epsilon); + std::cout << "power level " << e*g << ", " + << "epsilon " << e << " (" << epsilon << "), " + << "gamma " << g << " (" << gamma << ")" << std::endl; + + std::vector o2 = bits; + for (std::size_t i=0; i co2 = bits; + for (std::size_t i=0; i +#include +#include + +void split (std::vector &vec, std::string str, std::string del) { + auto token = str.find(del); + if (token != std::string::npos) { + vec.push_back(str.substr(0, token)); + split(vec, str.substr(token+del.size()), del); + } else { vec.push_back(str); } +} + +class Board { + public: + Board(std::string repr) { + std::vector lines; + split(lines, repr, "\n"); + for (auto line : lines) { + std::vector strcells; + split(strcells, line, " "); + size = 0; + for (auto strcell : strcells) { + if (strcell.size() == 0) continue; + cells.push_back(std::stoi(strcell)); + state.push_back(0); + size++; + } + } + + } + + int size; + std::vector cells; + std::vector state; + + void mark (int ex) { + for (int y=0; y extract; + auto token = raw.find("\n"); + if (token != std::string::npos) { + std::string ex = raw.substr(0, token); + std::vector vec; + split(vec, ex, ","); + for (auto v : vec) { extract.push_back(std::stoi(v)); } + + raw = raw.substr(token+2); + if (raw[raw.size()-1] == '\n') raw = raw.substr(0, raw.size()-1); + } else return 1; + + std::vector boards; + + std::vector str_boards; + split(str_boards, raw, "\n\n"); + for (auto s : str_boards) { + boards.emplace_back(s); + } + + bool flag = false; + std::vector filtered = boards; + for (int ex : extract) { + std::cout << ex << " " << filtered.size() << std::endl; + std::vector next; + int size = filtered.size(), seen = 0;; + for (auto& board : filtered) { + board.mark(ex); + if (board.win() && filtered.size() != 1) { + if (!flag) { + std::cout << "first winner product: " << ex * board.score() << ", " + << "ex: " << ex << ", score: " << board.score() << std::endl; + flag = true; + } + } else { + next.push_back(board); + } + } + if (next.size() == 1 && next[0].win()) { + int score = next[0].score(); + std::cout << "last winner product: " << ex * score << ", " + << "ex: " << ex << ", score: " << score << std::endl; + break; + } + filtered = next; + } + + return 0; +} diff --git a/2021/day04/day04_input.txt b/2021/day04/day04_input.txt new file mode 100644 index 0000000..033baa2 --- /dev/null +++ b/2021/day04/day04_input.txt @@ -0,0 +1,601 @@ +38,54,68,93,72,12,33,8,98,88,21,91,53,61,26,36,18,80,73,47,3,5,55,92,67,52,25,40,56,95,9,62,30,31,85,65,14,2,78,75,15,39,87,27,58,42,60,32,41,83,51,77,10,66,70,4,37,6,89,23,16,49,48,63,94,97,86,64,74,82,7,0,11,71,44,43,50,69,45,81,20,28,46,79,90,34,35,96,99,59,1,76,22,24,17,57,13,19,84,29 + +57 7 8 38 31 +17 96 5 12 18 +58 45 81 89 4 +73 51 93 32 10 +74 50 26 0 24 + +79 67 21 84 71 +25 22 19 80 13 +10 63 90 78 33 +93 50 89 58 87 +91 7 45 6 41 + +66 85 4 91 41 +59 69 16 0 90 +35 13 64 61 93 +11 20 29 67 77 +92 75 58 3 34 + +19 1 34 50 76 +26 75 8 28 20 +96 64 49 77 2 +18 58 62 53 60 +82 99 38 10 83 + +89 69 97 16 48 +32 3 83 17 33 +82 53 15 50 94 +52 0 86 25 81 +42 38 84 73 76 + +68 18 44 61 66 +24 21 22 6 41 +48 29 4 64 78 +93 25 88 95 96 +72 49 51 2 5 + +35 41 59 23 21 + 0 66 34 12 85 +61 26 29 68 5 +28 69 90 2 96 + 1 16 32 24 44 + +98 73 33 82 18 +51 62 88 67 6 +99 44 53 39 36 +34 90 50 72 43 +64 40 11 26 5 + +88 8 81 57 99 +61 16 22 50 5 +26 84 85 7 15 +97 27 47 18 21 + 3 78 66 94 58 + +56 40 68 20 24 +26 98 6 76 89 +61 63 22 99 83 +31 5 32 54 82 +18 23 17 46 13 + +35 95 67 73 13 +86 33 7 9 43 +44 28 55 32 52 +54 91 84 97 98 +17 49 93 23 56 + +22 90 61 12 13 +87 4 46 25 88 +70 38 53 80 11 +75 56 96 49 32 + 3 55 43 19 67 + +40 17 70 76 61 +82 86 37 8 28 +60 48 24 83 53 +57 87 44 92 63 +10 49 88 15 55 + +36 80 47 46 84 +25 70 2 79 75 +55 5 13 99 45 +54 73 83 59 67 +57 0 69 33 68 + +51 52 21 44 36 +17 30 15 42 18 + 6 3 47 94 2 +57 77 45 70 90 +29 60 19 9 84 + +16 12 37 6 27 +86 87 21 70 71 +84 0 11 67 83 + 5 68 33 23 26 +51 43 28 79 49 + +22 5 53 12 42 +29 81 46 13 88 +80 65 8 62 33 +72 67 34 21 35 +38 77 90 52 44 + +63 57 52 82 96 +46 11 32 20 58 +35 15 83 1 55 +18 16 73 19 17 +22 88 45 95 47 + +43 15 7 97 88 +96 52 84 86 49 +80 13 21 28 29 +16 36 98 82 41 +32 10 62 68 24 + +46 69 8 55 50 +28 21 92 79 73 +19 71 74 53 44 +24 27 10 14 85 + 2 39 58 81 72 + +68 74 43 62 61 +82 73 37 40 93 +16 7 41 54 96 +10 3 85 70 65 +69 71 94 5 81 + +17 53 87 80 98 +76 41 30 25 58 +29 14 73 74 43 +20 91 24 70 39 +46 48 51 9 18 + +20 41 36 81 93 +46 75 33 73 78 +26 16 80 54 90 +87 17 12 67 1 +51 10 39 91 45 + +76 21 31 3 69 +27 42 97 32 87 +26 22 4 63 38 +46 77 67 80 43 +37 50 59 88 96 + +17 16 10 68 76 + 2 45 94 29 40 + 1 54 60 66 93 + 0 13 42 39 70 + 6 82 46 74 43 + +87 95 31 22 94 +86 30 39 56 18 +89 74 23 11 64 +63 48 85 20 49 +27 15 40 83 50 + +81 48 47 73 95 +40 65 89 69 5 +38 76 85 30 11 +31 61 8 67 62 +41 68 42 78 20 + +46 85 96 83 20 +94 52 7 97 31 +29 95 99 34 62 + 8 69 6 51 54 +38 59 5 56 55 + +18 15 10 35 96 +44 66 58 91 9 +12 2 45 98 80 +22 69 37 67 79 +46 36 23 51 75 + +11 58 64 85 26 +21 43 32 36 65 +94 61 40 68 67 +14 23 6 53 2 +93 9 74 3 90 + +73 82 46 37 20 +47 75 38 45 54 +76 34 65 44 58 +93 89 27 13 33 +85 67 40 42 17 + +13 66 2 65 10 +98 4 83 79 92 +22 48 93 6 23 +24 39 17 60 9 +77 49 16 19 35 + +96 37 88 4 32 +80 89 59 39 63 +67 19 35 10 40 +91 66 47 9 79 +45 21 86 92 30 + +76 85 37 32 29 +59 41 44 23 93 +86 24 83 81 57 +22 21 82 53 16 +38 99 79 49 30 + +54 29 64 65 62 +44 59 83 75 56 +11 13 34 12 24 +96 39 31 95 16 +41 38 21 25 60 + +49 8 3 67 2 +30 81 39 26 33 +83 73 47 32 65 +48 20 75 24 40 +74 28 11 19 96 + +87 25 49 81 7 +99 34 35 50 86 +18 24 68 4 78 +59 8 71 0 41 +92 54 64 75 46 + + 2 19 73 29 10 +55 6 43 48 22 +64 14 62 39 97 +99 26 68 25 12 +98 72 45 38 40 + +59 76 40 37 9 +42 23 1 12 54 +49 51 17 11 34 +74 95 26 78 67 +65 32 98 80 45 + +50 86 95 29 38 + 6 11 24 10 73 +63 28 30 46 68 +34 9 20 58 77 +88 52 79 89 98 + +32 20 93 39 80 +67 98 99 4 26 +22 89 97 13 73 +88 11 72 31 78 +76 95 64 43 75 + +75 23 81 89 90 +98 86 88 38 99 +51 7 65 2 3 +16 59 49 41 87 +57 20 58 72 83 + +21 81 24 43 12 +55 74 2 90 5 +13 89 59 42 3 +47 66 38 20 62 +61 56 72 84 41 + +83 68 73 77 66 +96 48 24 7 98 +57 4 86 10 34 +22 46 80 75 49 +89 35 60 79 37 + +27 50 90 37 28 +81 74 58 39 61 + 8 72 31 85 57 +52 43 9 5 91 +68 86 0 4 89 + +14 41 70 67 59 +13 94 31 69 65 +76 19 9 79 1 +33 20 53 91 36 +80 50 21 37 85 + +16 47 62 33 12 +11 74 44 63 60 + 2 23 84 80 42 +14 58 67 81 24 + 8 29 31 91 43 + +62 86 26 57 74 + 9 46 47 81 39 + 4 99 59 89 3 +20 76 51 70 84 +95 72 43 67 61 + +75 93 56 15 30 +11 49 97 16 45 +52 91 21 92 62 + 0 74 85 48 63 +28 76 59 79 60 + +36 18 0 69 10 +34 33 21 5 23 +73 42 50 14 11 +75 26 95 79 51 +76 93 1 43 22 + +86 64 25 9 54 +67 79 49 1 8 +63 47 60 4 46 +94 97 57 38 30 +91 87 0 68 15 + +94 46 6 69 9 +18 49 43 30 31 +79 35 76 45 92 +67 89 82 2 57 +65 21 24 81 52 + + 5 58 43 37 61 +65 67 54 15 50 +69 75 14 17 96 +23 95 71 33 9 +68 82 10 3 29 + +56 43 88 35 82 +44 14 64 60 23 +33 5 96 86 47 +70 74 27 4 1 +51 71 95 59 11 + +46 14 44 6 19 +54 81 59 31 28 + 7 67 73 23 86 +25 91 57 43 92 +65 76 80 47 77 + + 3 39 70 90 23 +64 77 33 83 22 + 6 36 81 80 68 +85 45 72 53 42 + 7 19 88 13 9 + +88 3 72 6 29 +33 13 1 85 68 +28 32 78 8 63 +15 99 35 80 41 +61 50 43 53 39 + +22 88 19 86 54 +78 3 70 65 85 +18 12 21 14 17 + 5 48 64 81 71 +89 91 55 30 87 + +35 82 37 42 25 +44 53 12 2 73 +18 24 0 75 51 +34 26 54 52 86 +56 64 31 57 80 + +45 97 83 15 5 +40 77 1 53 84 +67 44 52 37 20 +36 64 33 82 90 +49 22 6 65 99 + +18 69 23 78 55 +45 4 31 54 44 +16 97 13 81 86 +77 87 91 53 33 + 1 84 83 75 40 + +95 46 89 7 38 +83 32 99 44 20 + 6 57 37 34 48 +69 5 84 29 54 +62 27 13 80 53 + +45 92 59 71 83 +52 75 42 46 86 +76 33 50 80 69 +36 89 90 3 31 + 7 5 48 38 53 + +86 80 77 18 87 +79 93 52 17 20 +30 68 48 12 91 +25 98 13 9 47 +45 73 97 15 59 + +93 60 34 18 25 +38 80 81 91 40 +43 87 20 79 7 +70 68 6 24 23 +46 97 32 78 67 + + 9 6 28 17 42 + 2 86 84 90 13 +91 58 16 37 76 +15 3 45 51 4 +64 99 41 59 39 + +44 3 85 80 93 + 0 43 90 40 89 +82 91 55 79 75 +30 5 68 50 1 +37 24 59 62 66 + +38 55 21 45 1 +23 14 95 25 22 +84 10 39 9 0 +17 15 58 70 49 +62 44 77 65 88 + + 8 62 25 75 39 +20 95 65 11 32 + 5 92 15 86 66 +64 34 60 7 85 +10 76 6 53 61 + +71 61 62 25 35 +23 30 37 14 9 +99 98 52 51 19 +77 57 17 72 85 +33 91 31 43 67 + +76 66 39 36 44 +49 97 93 33 52 +13 70 21 17 32 +71 98 80 19 60 +73 15 99 74 9 + +41 8 33 29 87 +42 86 66 31 50 +45 60 83 81 21 +36 4 98 43 0 +49 76 18 90 16 + +83 53 34 39 58 +91 68 17 62 4 + 2 76 44 31 35 +14 61 49 84 92 +73 6 86 27 65 + +56 70 47 60 97 +35 89 26 99 59 +67 23 27 74 65 +61 62 15 18 45 +54 93 0 9 71 + +11 24 97 15 30 +46 74 17 48 43 +16 64 72 60 37 +63 90 41 91 66 +25 95 1 54 49 + +87 67 27 26 38 +63 44 65 25 81 + 1 66 96 62 17 +82 2 58 4 86 +61 64 54 24 90 + +72 94 69 85 43 +38 11 93 39 13 +86 92 12 42 75 + 6 89 58 88 52 +79 19 20 55 14 + +77 93 58 6 52 +27 48 29 60 71 +87 24 25 54 49 +53 38 90 51 80 +57 50 18 1 13 + +85 84 54 2 51 +33 41 0 38 80 + 5 62 1 28 96 +17 88 64 26 90 +78 91 56 34 74 + +83 14 82 6 55 +30 13 99 57 39 +93 73 37 19 8 +29 49 76 22 92 +69 66 9 60 53 + +51 78 52 72 79 +42 55 74 88 44 +90 75 65 87 69 +22 35 64 36 86 +63 41 19 59 49 + +49 86 81 23 12 +93 16 9 8 95 +68 33 4 82 61 +45 28 85 87 38 +35 70 63 18 52 + +63 93 38 34 61 +75 21 86 42 25 +52 85 99 24 36 +41 11 79 54 47 +44 84 65 28 89 + +91 37 30 39 59 + 7 94 90 38 40 +72 21 75 31 61 +68 42 34 20 8 + 3 16 76 44 57 + +32 55 36 81 42 +21 75 68 28 65 +46 70 29 54 64 +66 89 96 25 43 +79 76 41 77 71 + +41 29 60 74 34 +84 49 83 72 92 +22 6 21 17 94 +15 44 62 28 2 +25 93 64 1 42 + +68 76 23 62 10 +36 87 15 12 57 +79 46 18 83 11 +48 81 58 52 28 +72 40 64 55 21 + +25 51 42 63 41 + 0 72 92 23 13 +65 1 69 33 2 +78 27 95 61 55 +30 54 48 3 57 + +50 40 58 66 59 +84 79 64 75 44 +88 93 41 25 97 +19 86 37 91 81 +10 26 94 77 34 + +76 44 11 16 60 +19 92 91 58 50 +97 5 46 4 52 +87 42 65 75 15 +12 2 54 27 86 + +77 38 51 29 89 + 7 76 54 48 44 +88 50 2 5 53 +12 70 26 57 74 +31 19 18 34 47 + +35 99 86 96 62 +61 97 71 70 66 +49 55 36 76 3 +94 23 31 91 26 +80 8 20 95 15 + + 4 96 40 36 12 +87 75 38 30 11 +69 29 23 85 91 +49 5 14 57 24 +88 20 99 78 65 + +34 65 71 79 67 +28 1 33 47 11 +15 86 84 83 55 +35 10 19 63 23 +58 66 45 77 26 + +74 13 25 39 8 +46 47 77 37 0 +60 1 81 42 18 + 5 51 78 30 4 +36 12 10 32 82 + +51 83 58 10 56 +28 18 43 99 14 + 3 57 30 49 88 +20 68 76 73 82 + 1 85 77 22 47 + +50 12 11 97 83 +40 10 49 81 63 +43 15 91 3 2 +52 20 53 89 33 +42 94 59 78 46 + +19 63 86 82 9 +69 13 27 88 37 +45 51 79 11 8 + 2 29 41 84 73 +76 24 78 96 38 + +15 19 88 95 54 +28 94 96 27 26 + 8 82 68 6 71 +33 9 99 62 63 +38 83 41 14 79 + +67 57 2 21 19 +11 79 74 45 95 +42 90 68 47 62 +80 61 1 0 39 +43 76 40 27 66 diff --git a/2021/day04/day04_input_ez.txt b/2021/day04/day04_input_ez.txt new file mode 100644 index 0000000..669a51d --- /dev/null +++ b/2021/day04/day04_input_ez.txt @@ -0,0 +1,19 @@ +7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1 + +22 13 17 11 0 + 8 2 23 4 24 +21 9 14 16 7 + 6 10 3 18 5 + 1 12 20 15 19 + + 3 15 0 2 22 + 9 18 13 17 5 +19 8 7 25 23 +20 11 10 24 4 +14 21 16 12 6 + +14 21 17 24 4 +10 16 15 9 19 +18 8 23 26 20 +22 11 13 6 5 + 2 0 12 3 7 diff --git a/2021/day04/makefile b/2021/day04/makefile new file mode 100644 index 0000000..ef809af --- /dev/null +++ b/2021/day04/makefile @@ -0,0 +1,2 @@ +all day04.cpp: + g++ -std=c++20 -o day04 day04.cpp diff --git a/2021/day05/day05 b/2021/day05/day05 new file mode 100755 index 0000000..78ac4fc Binary files /dev/null and b/2021/day05/day05 differ diff --git a/2021/day05/day05.cpp b/2021/day05/day05.cpp new file mode 100644 index 0000000..895dba0 --- /dev/null +++ b/2021/day05/day05.cpp @@ -0,0 +1,100 @@ +#include +#include +#include +#include +#include + +#include "../utils.h" + +class Line { + public: + Line (int a, int b, int c, int d) : a(a), b(b), c(c), d(d) { } + Line (std::string line) { + std::vector parts, start, end; + split(parts, line, "->"); + split(start, parts[0], ","); + split(end, parts[1], ","); + a = std::stoi(start[0]); + b = std::stoi(start[1]); + c = std::stoi(end[0]); + d = std::stoi(end[1]); + if (c-a == 0) xdir = 0; + else { xdir = (c-a) > 0 ? 1 : -1; } + if (d-b == 0) ydir = 0; + else { ydir = (d-b) > 0 ? 1 : -1; } + } + int a, b, c, d, xdir, ydir; + + int length () { return abs(a-c) + abs(b-d); } + + bool operator==(Line& oth) { + return a == oth.a && b == oth.b && c == oth.c && d == oth.d; + } +}; + +int main (int argc, char *argv[]) { + std::string raw; + std::getline(std::ifstream(argv[1]), raw, '\0'); + + std::vector lines; + std::vector strlines; + split(strlines, raw, "\n"); + for (auto strline : strlines) { + if (strline.size() == 0) continue; + Line line { strline }; + if (line.xdir != 0 && line.ydir != 0 + && std::stoi(argv[2]) == 0) continue; + lines.push_back(line); + } + + int intersections = 0; + std::map, int> overlaps; + for (auto& line : lines) { + int dist = 0; + bool straight = true; + if (line.xdir != 0 && line.ydir != 0) straight = false; + for (int i=0; dist 9) amt = 9; + if (amt > 0) std::cout << amt; + else std::cout << "."; + + } + std::cout << std::endl; + } + */ + + std::cout << "intersections: " << intersections << std::endl; + + return 0; +} diff --git a/2021/day05/day05_input.txt b/2021/day05/day05_input.txt new file mode 100644 index 0000000..58fb409 --- /dev/null +++ b/2021/day05/day05_input.txt @@ -0,0 +1,500 @@ +682,519 -> 682,729 +852,131 -> 25,958 +303,481 -> 206,481 +199,682 -> 183,666 +363,190 -> 571,190 +930,290 -> 221,290 +364,627 -> 952,39 +234,309 -> 234,821 +130,864 -> 130,886 +462,347 -> 699,110 +375,969 -> 481,969 +989,859 -> 275,145 +221,748 -> 212,748 +870,173 -> 106,937 +604,33 -> 604,142 +780,35 -> 780,206 +636,808 -> 721,808 +944,989 -> 334,989 +477,113 -> 192,113 +879,265 -> 879,358 +754,974 -> 17,974 +10,989 -> 989,10 +337,320 -> 674,657 +225,96 -> 557,428 +129,354 -> 299,354 +717,695 -> 695,695 +94,255 -> 317,478 +90,87 -> 90,187 +77,942 -> 952,67 +804,315 -> 989,315 +619,470 -> 491,342 +466,90 -> 466,755 +840,121 -> 840,469 +638,127 -> 638,77 +844,40 -> 151,40 +653,987 -> 653,631 +195,583 -> 195,623 +88,985 -> 570,503 +921,897 -> 165,141 +230,27 -> 171,27 +737,771 -> 832,771 +563,365 -> 665,467 +942,940 -> 776,774 +12,903 -> 644,903 +308,390 -> 308,971 +572,943 -> 572,15 +104,389 -> 104,73 +346,721 -> 974,93 +30,53 -> 562,53 +804,682 -> 804,120 +952,45 -> 15,982 +475,456 -> 475,348 +409,247 -> 664,247 +345,18 -> 816,489 +571,158 -> 505,158 +59,195 -> 27,195 +230,681 -> 23,681 +258,711 -> 921,711 +658,112 -> 366,404 +842,220 -> 842,825 +815,744 -> 540,744 +192,314 -> 703,825 +869,573 -> 869,888 +603,268 -> 603,301 +816,668 -> 816,189 +148,606 -> 948,606 +117,461 -> 506,461 +986,955 -> 986,315 +131,250 -> 192,189 +988,148 -> 518,618 +682,900 -> 31,900 +652,839 -> 652,236 +466,812 -> 466,611 +881,346 -> 401,346 +229,639 -> 731,639 +104,476 -> 840,476 +10,988 -> 988,10 +29,15 -> 987,973 +825,348 -> 825,240 +989,989 -> 10,10 +430,796 -> 926,796 +49,293 -> 610,854 +325,288 -> 918,288 +625,309 -> 439,495 +536,150 -> 356,150 +834,558 -> 822,558 +315,408 -> 315,635 +257,973 -> 813,973 +713,52 -> 122,52 +323,970 -> 578,970 +447,49 -> 829,49 +941,709 -> 941,390 +148,323 -> 391,80 +23,171 -> 23,49 +475,265 -> 322,112 +506,407 -> 69,844 +567,284 -> 483,368 +114,745 -> 114,765 +392,252 -> 109,535 +65,188 -> 455,188 +732,779 -> 732,52 +233,214 -> 759,214 +232,969 -> 957,244 +20,669 -> 20,308 +49,972 -> 285,972 +501,383 -> 433,383 +918,15 -> 32,901 +255,268 -> 935,948 +757,588 -> 757,919 +530,803 -> 284,557 +688,926 -> 48,286 +331,245 -> 331,777 +448,544 -> 209,544 +10,970 -> 951,29 +233,11 -> 897,11 +145,392 -> 628,392 +935,971 -> 935,280 +169,632 -> 54,632 +155,244 -> 155,334 +56,284 -> 205,284 +553,428 -> 553,520 +977,176 -> 497,656 +323,339 -> 971,987 +616,355 -> 616,248 +72,660 -> 72,334 +644,822 -> 510,956 +356,841 -> 587,841 +413,468 -> 605,468 +85,22 -> 645,582 +924,850 -> 522,850 +448,45 -> 345,148 +102,566 -> 551,566 +80,39 -> 847,806 +936,436 -> 934,436 +53,24 -> 495,466 +234,173 -> 282,173 +145,680 -> 456,680 +960,759 -> 960,282 +984,814 -> 308,138 +398,808 -> 716,808 +509,536 -> 25,52 +289,777 -> 803,263 +766,892 -> 257,892 +301,733 -> 688,733 +24,109 -> 887,972 +180,32 -> 577,429 +985,801 -> 687,503 +901,582 -> 586,582 +50,56 -> 50,267 +344,373 -> 437,373 +542,133 -> 905,496 +420,624 -> 420,716 +645,106 -> 645,574 +356,37 -> 114,37 +324,919 -> 357,919 +126,797 -> 120,797 +288,689 -> 435,836 +93,915 -> 639,369 +106,391 -> 478,19 +277,501 -> 714,64 +253,277 -> 643,277 +568,972 -> 350,972 +213,235 -> 213,406 +595,888 -> 595,233 +577,63 -> 37,603 +649,732 -> 931,732 +469,892 -> 549,892 +953,895 -> 953,457 +222,213 -> 290,213 +841,800 -> 841,336 +685,143 -> 25,143 +441,127 -> 441,146 +646,586 -> 56,586 +698,122 -> 465,122 +641,502 -> 641,240 +111,91 -> 185,91 +927,755 -> 874,808 +108,151 -> 108,567 +309,453 -> 309,210 +890,657 -> 491,657 +404,244 -> 404,123 +939,28 -> 26,941 +596,970 -> 596,870 +489,556 -> 489,589 +607,621 -> 903,325 +912,284 -> 571,284 +921,702 -> 743,524 +719,36 -> 719,394 +100,905 -> 798,207 +316,260 -> 316,887 +799,940 -> 885,940 +835,287 -> 199,923 +422,760 -> 64,760 +727,113 -> 727,679 +733,56 -> 59,730 +141,399 -> 485,743 +769,629 -> 769,797 +62,486 -> 62,205 +192,332 -> 800,332 +15,931 -> 727,931 +854,915 -> 988,915 +349,610 -> 886,610 +72,110 -> 72,903 +955,110 -> 78,987 +591,553 -> 591,428 +708,467 -> 516,467 +397,589 -> 353,589 +930,336 -> 930,532 +639,50 -> 228,50 +472,17 -> 472,244 +420,825 -> 420,562 +203,197 -> 203,35 +984,964 -> 223,203 +944,269 -> 935,260 +933,119 -> 87,965 +696,290 -> 696,580 +925,960 -> 52,87 +451,470 -> 235,254 +562,71 -> 562,149 +405,126 -> 405,67 +356,424 -> 356,673 +859,649 -> 859,291 +210,651 -> 210,544 +403,783 -> 403,122 +672,87 -> 586,87 +409,668 -> 984,668 +917,352 -> 511,758 +395,953 -> 141,953 +152,795 -> 152,313 +839,344 -> 811,372 +114,649 -> 650,649 +60,517 -> 60,27 +448,392 -> 845,392 +33,849 -> 719,163 +151,988 -> 876,988 +805,556 -> 124,556 +361,538 -> 706,193 +974,941 -> 141,108 +271,813 -> 968,116 +500,697 -> 80,277 +586,731 -> 586,480 +128,147 -> 174,101 +882,681 -> 882,745 +531,730 -> 677,730 +989,11 -> 11,989 +74,332 -> 234,492 +360,326 -> 932,898 +136,288 -> 113,311 +666,645 -> 916,895 +977,478 -> 561,62 +20,83 -> 566,83 +331,942 -> 331,646 +180,291 -> 405,291 +637,763 -> 637,941 +120,138 -> 120,820 +951,24 -> 14,961 +204,304 -> 204,51 +84,168 -> 880,168 +955,145 -> 955,903 +437,427 -> 437,354 +875,67 -> 189,753 +46,767 -> 802,11 +52,59 -> 889,896 +926,56 -> 102,880 +500,30 -> 964,30 +329,488 -> 329,972 +63,11 -> 889,837 +707,168 -> 707,584 +580,10 -> 735,10 +105,620 -> 105,110 +187,531 -> 323,531 +82,947 -> 82,941 +737,199 -> 737,851 +612,650 -> 217,650 +971,15 -> 82,904 +16,590 -> 506,100 +950,877 -> 832,759 +570,470 -> 570,276 +213,411 -> 213,195 +670,755 -> 89,755 +906,963 -> 906,984 +458,463 -> 442,463 +956,969 -> 10,23 +87,215 -> 195,107 +819,454 -> 819,467 +594,793 -> 686,793 +395,724 -> 787,332 +315,461 -> 644,461 +448,247 -> 249,48 +620,302 -> 247,675 +607,134 -> 932,134 +312,776 -> 312,289 +850,942 -> 54,146 +31,538 -> 851,538 +729,126 -> 640,126 +702,199 -> 702,706 +402,783 -> 254,783 +110,59 -> 203,59 +27,10 -> 965,948 +747,261 -> 47,261 +628,742 -> 972,742 +712,742 -> 657,797 +877,871 -> 877,758 +665,313 -> 449,529 +498,157 -> 498,68 +870,922 -> 27,79 +856,697 -> 856,429 +447,271 -> 963,787 +495,302 -> 495,520 +526,47 -> 721,47 +826,179 -> 826,741 +565,461 -> 893,461 +512,328 -> 127,328 +487,920 -> 522,920 +614,452 -> 614,146 +331,574 -> 331,840 +985,79 -> 285,779 +812,320 -> 985,320 +118,69 -> 429,69 +644,525 -> 644,878 +271,132 -> 156,132 +955,782 -> 565,392 +630,939 -> 630,372 +51,203 -> 840,203 +202,490 -> 202,479 +579,868 -> 579,92 +979,336 -> 979,623 +843,865 -> 260,282 +685,872 -> 685,503 +721,193 -> 721,510 +908,661 -> 908,955 +19,950 -> 715,254 +233,730 -> 233,101 +922,954 -> 27,954 +399,444 -> 399,403 +380,712 -> 380,718 +238,264 -> 849,875 +458,577 -> 458,139 +418,244 -> 469,295 +460,375 -> 964,879 +276,445 -> 815,445 +463,910 -> 648,725 +26,384 -> 968,384 +955,385 -> 955,143 +942,775 -> 733,566 +425,326 -> 531,326 +364,545 -> 364,873 +182,759 -> 182,819 +390,757 -> 390,475 +217,417 -> 217,157 +669,286 -> 65,890 +257,11 -> 257,858 +557,397 -> 557,20 +888,946 -> 32,90 +971,938 -> 971,578 +874,248 -> 874,485 +87,268 -> 87,135 +756,679 -> 103,26 +771,250 -> 771,107 +320,711 -> 967,711 +293,219 -> 293,706 +103,565 -> 103,538 +388,256 -> 388,261 +468,953 -> 503,953 +424,142 -> 287,142 +24,930 -> 850,930 +316,167 -> 316,161 +481,421 -> 208,148 +938,926 -> 938,933 +701,653 -> 701,780 +536,390 -> 536,559 +40,954 -> 829,165 +404,985 -> 247,985 +94,628 -> 94,500 +441,637 -> 441,271 +766,946 -> 97,277 +428,363 -> 428,37 +542,694 -> 542,347 +11,16 -> 979,984 +938,651 -> 632,957 +779,127 -> 243,663 +636,294 -> 636,787 +533,744 -> 636,641 +521,950 -> 458,950 +988,12 -> 18,982 +954,621 -> 954,271 +638,951 -> 813,951 +822,911 -> 632,911 +714,849 -> 512,849 +696,88 -> 385,88 +65,451 -> 65,687 +976,973 -> 976,907 +368,489 -> 368,571 +358,831 -> 690,499 +436,704 -> 178,704 +690,619 -> 606,535 +96,701 -> 358,701 +885,562 -> 420,562 +581,480 -> 613,512 +44,970 -> 970,44 +216,796 -> 892,120 +72,623 -> 72,72 +896,283 -> 896,326 +794,195 -> 22,967 +134,326 -> 134,889 +420,141 -> 944,665 +941,194 -> 941,421 +940,525 -> 298,525 +653,300 -> 769,300 +227,424 -> 406,603 +275,850 -> 113,850 +648,850 -> 92,850 +638,389 -> 638,10 +379,404 -> 584,609 +833,931 -> 833,520 +772,286 -> 500,558 +372,262 -> 333,262 +689,18 -> 131,576 +687,499 -> 687,188 +344,499 -> 37,806 +778,496 -> 134,496 +938,87 -> 344,681 +788,401 -> 479,401 +828,903 -> 756,903 +423,625 -> 285,763 +218,489 -> 218,819 +488,384 -> 891,787 +817,532 -> 788,532 +512,27 -> 512,149 +369,794 -> 54,794 +534,590 -> 827,883 +84,310 -> 39,265 +357,545 -> 665,545 +539,807 -> 539,781 +378,683 -> 22,327 +71,909 -> 943,37 +740,552 -> 348,552 +698,315 -> 45,968 +516,835 -> 360,835 +629,141 -> 629,385 +695,908 -> 303,908 +795,707 -> 386,707 +211,397 -> 291,397 +64,620 -> 236,620 +97,638 -> 97,445 +46,103 -> 893,950 +468,122 -> 979,122 +810,486 -> 433,486 +532,899 -> 461,970 +232,60 -> 235,60 +549,708 -> 549,90 +294,978 -> 294,124 +865,406 -> 640,406 +755,305 -> 664,305 +12,989 -> 987,14 +275,249 -> 260,234 +502,783 -> 67,783 +863,938 -> 297,372 +516,961 -> 516,272 +67,510 -> 611,510 +980,951 -> 312,283 +325,512 -> 325,169 +142,429 -> 542,29 +273,964 -> 822,964 +370,217 -> 508,217 +131,131 -> 331,331 +734,824 -> 734,817 +75,89 -> 687,701 +155,255 -> 702,802 +577,395 -> 130,395 +684,94 -> 555,94 +393,881 -> 173,881 +894,750 -> 773,750 +380,269 -> 380,338 +427,36 -> 427,77 +637,107 -> 637,846 +53,437 -> 53,221 +128,979 -> 960,147 +838,211 -> 838,645 +898,39 -> 849,39 +862,495 -> 951,495 +754,406 -> 76,406 +951,960 -> 113,122 +830,125 -> 15,940 +190,117 -> 190,973 +192,956 -> 718,430 +895,162 -> 88,969 +135,196 -> 70,131 +578,642 -> 578,789 +713,268 -> 625,268 +938,719 -> 938,604 +30,863 -> 99,863 +844,309 -> 287,309 +131,837 -> 459,509 +61,206 -> 722,867 +95,974 -> 283,974 +746,672 -> 558,672 +552,32 -> 352,32 +21,637 -> 21,781 +945,847 -> 945,303 diff --git a/2021/day05/day05_input_ez.txt b/2021/day05/day05_input_ez.txt new file mode 100644 index 0000000..b258f68 --- /dev/null +++ b/2021/day05/day05_input_ez.txt @@ -0,0 +1,10 @@ +0,9 -> 5,9 +8,0 -> 0,8 +9,4 -> 3,4 +2,2 -> 2,1 +7,0 -> 7,4 +6,4 -> 2,0 +0,9 -> 2,9 +3,4 -> 1,4 +0,0 -> 8,8 +5,5 -> 8,2 diff --git a/2021/day05/makefile b/2021/day05/makefile new file mode 100644 index 0000000..a197e7d --- /dev/null +++ b/2021/day05/makefile @@ -0,0 +1,2 @@ +all day05.cpp: + g++ -std=c++20 -o day05 day05.cpp diff --git a/2021/day06/day06 b/2021/day06/day06 new file mode 100755 index 0000000..ccf553a Binary files /dev/null and b/2021/day06/day06 differ diff --git a/2021/day06/day06.cpp b/2021/day06/day06.cpp new file mode 100644 index 0000000..38d602b --- /dev/null +++ b/2021/day06/day06.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include + +#include "../utils.h" + +long sum (std::vector vec) { + long s = 0; for (long v : vec) s += v; return s; +} + +int main (int argc, char *argv[]) { + std::string raw; + std::getline(std::ifstream(argv[1]), raw, '\0'); + std::vector strfish; + split(strfish, raw, ","); + + std::vector fish; + for (int i=0; i<9; i++) { fish.push_back(0); } + for (std::string str : strfish) fish[std::stoi(str)] += 1; + + int days = 80; + if (argc > 2) days = std::stoi(std::string(argv[2])); + for (int i=0; i 3 && std::string(argv[3]) == "-w") { + std::cout << "day " << i+1 << "/" << days + << " current fish: " << sum(fish) << std::endl; + } + if (argc > 3 && std::string(argv[3]) == "-v") { + std::cout << "day " << i+1 << ": "; + for (auto f : fish) std::cout << f << ","; + std::cout << std::endl; + } + } + + std::cout << "fish: " << sum(fish) << std::endl; + return 0; +} diff --git a/2021/day06/day06_input.txt b/2021/day06/day06_input.txt new file mode 100644 index 0000000..5b38bce --- /dev/null +++ b/2021/day06/day06_input.txt @@ -0,0 +1 @@ +4,1,1,4,1,1,1,1,1,1,1,1,3,4,1,1,1,3,1,3,1,1,1,1,1,1,1,1,1,3,1,3,1,1,1,5,1,2,1,1,5,3,4,2,1,1,4,1,1,5,1,1,5,5,1,1,5,2,1,4,1,2,1,4,5,4,1,1,1,1,3,1,1,1,4,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,5,1,1,2,1,1,1,1,1,1,1,2,4,4,1,1,3,1,3,2,4,3,1,1,1,1,1,2,1,1,1,1,2,5,1,1,1,1,2,1,1,1,1,1,1,1,2,1,1,4,1,5,1,3,1,1,1,1,1,5,1,1,1,3,1,2,1,2,1,3,4,5,1,1,1,1,1,1,5,1,1,1,1,1,1,1,1,3,1,1,3,1,1,4,1,1,1,1,1,2,1,1,1,1,3,2,1,1,1,4,2,1,1,1,4,1,1,2,3,1,4,1,5,1,1,1,2,1,5,3,3,3,1,5,3,1,1,1,1,1,1,1,1,4,5,3,1,1,5,1,1,1,4,1,1,5,1,2,3,4,2,1,5,2,1,2,5,1,1,1,1,4,1,2,1,1,1,2,5,1,1,5,1,1,1,3,2,4,1,3,1,1,2,1,5,1,3,4,4,2,2,1,1,1,1,5,1,5,2 diff --git a/2021/day06/day06_input_ez.txt b/2021/day06/day06_input_ez.txt new file mode 100644 index 0000000..55129f1 --- /dev/null +++ b/2021/day06/day06_input_ez.txt @@ -0,0 +1 @@ +3,4,3,1,2 diff --git a/2021/day06/makefile b/2021/day06/makefile new file mode 100644 index 0000000..2bc132f --- /dev/null +++ b/2021/day06/makefile @@ -0,0 +1,2 @@ +all day06.cpp: + g++ -std=c++20 -o day06 day06.cpp diff --git a/2021/day07/day07 b/2021/day07/day07 new file mode 100755 index 0000000..4cbc735 Binary files /dev/null and b/2021/day07/day07 differ diff --git a/2021/day07/day07.cpp b/2021/day07/day07.cpp new file mode 100644 index 0000000..f9bbd1a --- /dev/null +++ b/2021/day07/day07.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include + +#include "../utils.h" + +long sumdist (std::vector pos, int pole, int inc) { + long sd = 0; + for (auto p : pos) { + int n = abs(p-pole); + if (inc == 1) n = (n * (n+1)) / 2; + sd += n; + } + return sd; +} + +int main (int argc, char *argv[]) { + std::string raw; + std::getline(std::ifstream(argv[1]), raw, '\0'); + std::vector vec; + split(vec, raw, ","); + std::vector pos; + for (auto s : vec) pos.push_back(std::stoi(s)); + + int minp = 10000, maxp = -10000; + for (auto p : pos) { + minp = std::min(minp, p); + maxp = std::max(maxp, p); + } + int inc = argc > 2 ? atoi(argv[2]) : 0; + long fuel = 100000000000; + for (int i=minp; i +#include +#include +#include + +#include "../utils.h" + +int distance (std::string a, std::string b) { + int d = 0; + for (auto k : b) { + if (a.find(k) == std::string::npos) d++; + } return d; +} + +int map (std::vector tries, std::string dig) { + if (dig.size() == 2) return 1; + if (dig.size() == 3) return 7; + if (dig.size() == 4) return 4; + if (dig.size() == 7) return 8; + if (dig.size() == 4) return 8; + + std::string one = *std::find_if(std::begin(tries), std::end(tries), + [](std::string &str){ return str.size() == 2; }); + std::string four = *std::find_if(std::begin(tries), std::end(tries), + [](std::string &str){ return str.size() == 4; }); + if (dig.size() == 5) { + if (distance(dig, one) == 0) return 3; + if (distance(dig, four) == 1) return 5; + return 2; + } + if (dig.size() == 6) { + if (distance(dig, one) == 1) return 6; + if (distance(dig, four) == 0) return 9; + } + return 0; +} + +int main (int argc, char *argv[]) { + std::string raw; + std::getline(std::ifstream(argv[1]), raw, '\0'); + std::vector lines, parts; + split(lines, raw, "\n"); + + std::vector count; + for (int i=0; i<8; i++) count.push_back(0); + + int sum = 0; + for (auto line : lines) { + if (line.size() == 0) continue; + parts.clear(); + split(parts, line, " | "); + + std::vector tries, digits; + split(tries, parts[0], " "); + split(digits, parts[1], " "); + + int i = 1000; + int num = 0; + for (auto dig : digits) { + count[dig.size()]++; + num += i*map(tries, dig); + i/=10; + } + sum += num; + } + + std::cout << "digits: " << count[2] + count[3] + count[4] + count[7] + << std::endl; + std::cout << "sum: " << sum << std::endl; + + return 0; +} diff --git a/2021/day08/day08_input.txt b/2021/day08/day08_input.txt new file mode 100644 index 0000000..cf25f77 --- /dev/null +++ b/2021/day08/day08_input.txt @@ -0,0 +1,200 @@ +bfdcga cgdfe egfda cbfeda ec efc gcfbd ebcg gdfbec adcgfeb | bgdfc ec dfgae gefcd +cafgbd bc gfdbae eacfb cbf debaf cdgefba fecag fbcdae ecbd | cdfabg cb adgfcb bface +afg daecgf aefbgdc fbge fg dabfg efabgd cbadge abcfd gbaed | acbdf egbda adbge fg +cbeafg fadce cdeabfg gbdefc ged ebcgf bfgd dg ecdgf bgedac | fgdb afcbeg gcfeba edg +efd aegdb efgdcb bafcd acef dfaeb ef fgbadec cadfgb bfecda | fedgcb begcfd def gfdbac +badce gbcda gad fgdc acbgf cfbage gcfbad gd dbafeg afcbged | ebdfag dfcbag gd fdeagb +gdbcaf da dcbeg cad edcbfg gdea baedc afbec baegdc gbfaedc | gbdcaf dbgec da gaed +bedga agbefd dbgfca gcafdbe begcdf gdabf abegc deb ed adef | bgade gacbe ebd cbefdg +eg edfcab gfde abedf fbgdea bgcad gefcba agbed ebg eafbcgd | ge fbdeca bdcfega cgadb +dgbaecf fegbd de fbgade fde gecfb ebda dbgfa dfegca dfagbc | afcegd fgdabce de efgdac +dgafe deafbg gdecbfa fgcad beagd gfbcae efa dbfe ef dcgeba | gafedb debacg ef dfbe +gbadcf bcade efdgbac bcf acebf bf egcfa ebdf acbgde cdabfe | fbcea eafcg fcbea dcbafge +dcfbge ecdabg gfbdae afecb cbg cbgae gacedbf gadc cg bedag | bgdae becga bdcgfe ebcgda +bde eb cgbfade cdgbef beag gabdf dafeb cadfe agdfcb eadgfb | begfdc dfbcga abfdg edagbf +dcbgea fced cgeaf cfaged gdeac dgbfca fc badgfce cfg egbfa | fbcdag feagb cdef fcg +gfdbc adebcg cbg dfcaeb cg bcaefdg bdgfec bdagf dcfeb egcf | fbgda aedfcb cfgbde defgcb +daf cagfeb adeg dcbef cdgbaf da efcag fbdegca ecafd dcaegf | da bgeafc bgdfac ecgdaf +gfdaeb gfde agebf bgf fg bgcfad afbde fdaecb dbeacfg eabcg | gecab baedf eadfb gcbdfa +bagcfed eafb acfgd cebdfg ead agbdef baedcg egfbd agefd ea | gacfd bgfed fgdae bfdeg +cgfab adcfebg cgdef eabc feagbd ebcfg feb eb bdfcga gbcfae | defgc bdcafg fgdec cegbf +cdfab gdf cfebg decbaf gd dcgbaf gcbfd cgad egdbaf badcfeg | gfcbd gd cbgfe ecbafd +faebd ba efacgd baedcf adcef abf dcfbgae dbac gdbfe begcaf | dcab dafec fecadg ebdfa +dfceab egbadcf ba fdcbg feba cgdfae dbegac abdfc cba ecfad | defacg dgbcf gbdcf efcdbga +cadgb bedg fgaceb eacbgd egbac cefadg gd cafdb eabgdfc gad | afgdce adcgb gbacd adg +acb adcgf adcfeb baedg cb becagd bfcadge abcdg ebgc gfdeba | gdafc acfdeb cb aebgd +fabcgd fcdgae facde bcafeg da geda gcebadf befcd eagfc adf | cfage fgeac fgdbaec fgeac +bafeg fabcdg efdgabc fgdbea gdae ae dgafb bae ebgcf fcadbe | begcf abgfe aegbf efbadc +fdeca cadegbf gce bafdge abcdeg dcgb ebcfga cg deagb dagce | bdeag aebdgf gce dbage +fcgbde cdgaebf dgbaef fed bade ed adfgb efdag fdabcg agefc | gfdab adbcfg gcfae dfagb +ebdgfc febad adbfc fc bdfcea badfge cfb eafc acdgb egcfdba | acbgd bgfead dfabc fcea +eb ebaf cbdgef gaedb afgebdc febdag dgefac agbcd beg deagf | dgfcea efabdg egabd geafd +cedfba efgbd gfbdac gfaecd bfa gdfba bcag ab cgdfa begdafc | dfbace dfgeb eafcdbg dfcag +cfdbge gdbefac dabf dgbcfa gacdf gebca fb agefdc bcgaf fbc | afbd gbcafed acgeb ebgfdc +fgbec fbgcd fdbaceg gafedc bfacge fge eafb agbced cbgea fe | abgce fadegc ebacg fagecd +bdgec bgecfa fcbed debfcg acebfd gcb adbecgf gb aegcd gbdf | ebgfdc geacbfd gcb gb +fbea bdfcag dceabg egfcd edcfbga abdge af adf dfbage egfad | fa deacgb agfdbce ebdag +abdecfg gbacf fdbcge gfd dg gdafbc adgb acfde fadgc fbeagc | dcgebf dacgf agfbc cdagbf +agcefd ged bdfagc ed ebdgf fcdbge dgfbc abegf cdfegab debc | cagdfe ged cgdafb bafdcg +cebgad fdgea abgf fdbcae af baedg dgfeba dfbagce edgfc fea | dabegcf agdbe afe acfedb +agdfe fedbcga gfedbc agcbe edb db fdba edbgaf gedafc abdeg | cdgabfe afegbd fegbcd eafgd +dea abgdfe edgfbac egdab de cadbef adfbg gbcea gfde dabgfc | cdafeb ed bafgde ed +adgfb cdgefa ea fea bcdef cfagbd fgecabd febda agbe fgabed | cdefb gbea bdacfg dcbef +cadbg ea fdgeab afcedg dae ebcfdga cdfge afec dbfgce ceagd | fbeacdg dgcab bgdca dae +ecdbfg caebd fcgde fgda aefbcg afedc fcabegd aef gcdaef af | ecdfa bdecfg fea dgcfbea +dbcagf afgec fcadb ead daefc dbcgae edfb cagbdfe fcdbae de | egdabc fdagbc cgafbd afdec +dgfabe egdcbfa beacdg dbcfg aefc cdbaf fbadec fa aedbc fab | eacf bcdfg efca ecbad +defbgc gbdef cg edgc egbadfc cbgef gafdeb gcf eacbf gbfdca | fbedg decg cgf egfcb +cfdgae abdgf gbcd cfdaeb afebcgd cafgd bdf bcfgad db gefba | egfba decgfa abfeg eafdcg +dfagb gdbface adefbc gbfae gae begc acebgf fdgeca ge cefba | cgefab dfgace fecagd beadfc +fedacgb ed cabdfg bfgade dbaefc gdfba def gead bgcfe bdfeg | adcefb gdbaf egad caebdf +agfbed ecfbg cdge cgb fcgbde ebcaf adfbcg dcegabf cg efdgb | bdfcga bfeadg ecgfb cg +bec becfdag bgcaf eb debf adcef cefba fbcade acbged fcadge | edacfb fdeca fgabc cgafb +bfcae gabc fegcdb adefgbc bcgfae gfb fbgea fdabec adgfe bg | dfcgeb fgbae fgb bedgfc +afedcbg ed dfagc gefcd dec agbdec bfecg gfedca efad dfabcg | edaf dec begadc dfagbc +cgebd befcadg ecg ec fcde dbfgc fgdabc becfga aegbd bfcged | cbgafd bcgfd fedc gfdbec +dfabeg acfebd bgfcde begfd bcagd cdafgbe gabed aeb fgae ea | gbedf gdebfa bfegcd bgefd +gdf dagec gf cfdbega cfdba edbcga ceadfg fcdag aegf cdbfge | eafg fgd dfg bdegcf +bcfae fabge cdegabf cdae ebc dfcba ecbdfg ce dagcfb fbedca | fdagcb bcedfa fceabdg adce +cgbaf ad fgcadeb cbfdae fbgdac bgda egdfc cefbag adc fcadg | cfdgbae adc ecafgb dgabfc +bafdc cfb cf abcfged acdbge dbgca aefdb afcg afcdgb gbefdc | dabfc cagf efbcgd abecdgf +de abgefdc fbed adbcgf gaecf eda aebdgf adbecg fegda bfagd | feagbd dbgfac ade adgfe +gacefb faebcgd decfgb fa abdgfe afb fdbge dacbg adfgb edfa | dgbac abcgd gbadc adbgf +fbadg fgbde fagebd agbcf gad gfcbed abde da cbdfaeg afegdc | ecfbdg agd efdgcba aefbdg +cbdge gfecd cfe cafgd dbfe fe bgefdca gedfcb gebfac dgbcea | dgecb bagcfde gecbaf gacbef +dfgecb agbfe dbeacf ebcdf cbad cadfbeg ca cfa abcef edfcga | afgdbce cabd fcbdae becaf +abcd fbade befdcag da fecdag ecfdab bgfced bfedc dae gbaef | da ebfdc cabd cfedbg +ecdab cfaged cbfd cfebad begda agbfce fecba cd acd fedcbga | cfdage daecb febca ebacf +fcdageb beadf dag dacfbg bacge deabg dfcabe gdbaef degf gd | bafcdg dgafbc bdaef gd +febcg cefbagd fegdbc bfeac ab gcba bfa fdbega cedfa cgfeab | eagbcf cbgef afb fcgbae +egfac acbdge fadcbg bgcedfa bdcafe bf ecadb fdeb fecba bfc | fgdcabe dcbfga aegcf fbcadeg +gcfebd acdgb faedcb gcdfb fd gdfe fcgbe fgacdeb baefcg dbf | cgfdb bgdcf gabcd edcbgf +aced fbacg adbcf cd fbade cdb decfbg faegdcb gedabf ecdfba | bdfae fdgcbae fdbgec fdecgb +gdbeac dfcaeb afbgecd dbcgf af fbacg cegbfa fba cagbe geaf | fgbdcae eabcg caebg afeg +ebfda dgfbe ae fcbgead deafgc fdbac eaf gaeb ecdbgf ebfgad | baedf debgfca efcbdg ea +dgcfe acbef cgaef fbdgace ecafbd gcebfa ga age gdfeba bgac | adfbce ga cegfa abcg +abcgd facd fag eacfbg gafdb fa bgfacd dcgeba befgd efgacbd | bdcegfa gbdaf cbgda egabcfd +bdefcga aecbg cgde agbed ecabfg dgb befda gcadbe gdbcfa dg | acgdeb dgb bfaed adbeg +cefgb bde adgceb dafgebc aefd debgaf gfedb agfdb de cgdfba | defa edbgf afbdg bgfad +fa caefg egcab fca gdbcea abef bceagdf dcfge acgfdb afbgec | abfe faebcg acgef geacf +cbfed egacdb eabfgd gdbac deacgfb aeb eacdb gacfbd ea cage | dbegacf aecdbg cage dcgbae +efgad agedcbf bcea ba ebdcfg efbcag bgaef gfabcd bga gfbce | fgdae ba fedgbc egfba +dbcfa bcagd gdbfae cdfg fecab bcfadg dcbgae dfb fd bcadfeg | daegbc befca cbfae dbgcae +egfa bcgdafe dcfea dcfeba cafgbd gf edgbc gfd egfdc edcgaf | gf dgafce fdg efcbda +fgecd afgcde gfcadeb dbcg dcfbeg facbe gbf gfbec gdeafb gb | abdgfe cegdf bgf ecgfbad +gdcbafe gaf agcfe bafc gfdcbe gbfdea cfegb gaedc gfbace fa | bfeacg acgfe bcaf gcade +egbcf fgcea decbf dgabef gb fabedc fbecdag fgdbec bcdg beg | bgdfaec acgdbfe defbca fcdeb +bdeafc cabegd acdbe fdba cfb bf edcfagb fecag cbafe bcfgde | bfda fdgaebc dbaec fb +bc ebdcg agcfebd cadeg ecb fdbaec befgd cbdgfe gabfed bgfc | dagbef bcgdfe bgedaf gdace +eb ebf gaedfc fagdb cabe fabecg bagef bdgafce cgdefb efcga | beacfgd efgbca efbgca ebfgac +cagdf gdacef fcdbga cb gcadb bgc fcab dbfcage baged gbdecf | aefcdg cb agdfc bdgfec +dfbaec abegdf daf edbgcaf bgfd eafgc gafed fd bedag gebdca | ecfgbda beafdgc facebd bdeag +bfaegd dbecga fcadbg dcfg dabcg gf acbfe fgbca fga aegdfcb | cegbda ecabdgf egcafdb fgcd +dbgcea agc aegbc fgceda abdfce cbdg begaf adbcefg cbade gc | dfecba gbedac cdfeab abecg +cfdeab fgbec eadg bga ga dcebagf beadgc gaebc bgfdca bcead | bgaced bdeacg cbgea beacgdf +bagfce ebcdfg fa cgade cfa bfcgeda ecbdf adfb fecbad efadc | ecdbf cfa bfceag bdfeac +af egdaf aef eacdg fdgeca cafg cdgfabe baedgc edfbg acbdef | edfga decagb bdecfa dacfge +dab gfbed bfdage ebdcgf baecg da dfacbeg eagbd beacfd gadf | egbda cbdfae cfadeb egabfd +bcgfaed bfgade bd gfcda acgedb bacefg caebg cbed abdcg bdg | cebag fcebag dbcaeg gbd +dgcfb begdf def fbaegd fegab ed cebagf cefdgab cebdfa gade | ebgdacf aefbgd de gfdbae +ab abdf agbcde aegfb eafgc fgcdeb fbged bea bgafced efdbga | gbafe gbafed gaefdcb gdfbec +eafbg abgdf eg aceg gabfce fge fcbedg ecfabd bafdceg caebf | cedbfa gbface eg fagbe +face bfe adgfeb acebg cdbfg fe gacbdfe gcaedb cgebf cgaefb | aefc gdbcf gecab gfcbd +agfecd fa gbfa fbdce gdfeacb dabfe fbadeg bgdaec begad afd | fda bdefc egadbf fa +ab bfedcg gfdcb deacg abdfce gcabd adcgfb eabfcdg abc abgf | decga debfac fcbdg gecdbaf +gfadcb dcgab abfgde fdcega acd adbgf cgdeb ac acfb befdcag | dbagf ca gdcfab gaebcdf +efcagd dbcef bgda gbf dfaegb cfegab bfged bg agcfbde afegd | bfagce cefdb fgeda aegfcd +cedafgb cbfeda bcegf gdbe gb fcgbad cedbgf gcaef bgf cefdb | ceagf dbfcge afdcbe ebdfgc +cgfed acfge bdecaf fdag fecgad fedgbc bacge af efa afegcbd | cgadbef gbdecf fgced fa +abegf fagcde ceb feabc ecfda cb acdb efcgdab cbgdfe ecadbf | eafcb ceb cadb bdeafc +fbgae begd abcfegd bfeda efd eagfdb de fgaecb acgdef dacbf | dagfce adefb bdfac dfegab +fd fed fgad dfecag gaedbfc gecafb bdceg cbdafe efcgd fcega | agfd dgaf gdafce eafcdb +befagd dfeb bf caebdg ebgda egfcba bgf gcadf gafbd fabgdec | agdefb eagcfb edacbg badfg +eagcd bdacgf gfeb fdgba be deb cefagdb afcdbe bdgae aegbfd | cfbgad dbage eb bgeadf +eacbfg debgac dbfcage dc eagbc cda cabdfe dfgea bgdc adegc | becag efbacg caebg cdgae +fed fcbagd acdebf gaef ef fgdec fecbagd dcegaf cbdeg agcfd | bdeacfg ef cadgf dcbeg +efc becdag afedc edgaf fc badgcfe fcdbge adfcbe cafb eabdc | dfebca acbed fc efacd +abfed dc fdcegb cgbfe cagfeb fdecb gbcadfe bgadcf gcde cdf | gecafb fbegdc febcdg cegafb +feagc daecfbg gdca dg fgd fdgec cebdf eagcfb efcgda fbdeag | defagb aedbfg gfd faegbc +cagdf ce bcegdf dbafeg cbeadf gbdaefc caeb cfe feadb efadc | ecba dcfae ec ce +fgabd abgdc dbcae cfadge cag cbge cg ebcadg cgfdeba fcbeda | dgabce dacegf baecd cfabed +efagc fdcgea geb bfdgec cgba fdcbgae adbfe bg bfcaeg fgeba | afegb daebf ceagdf agbc +ecgfbad ceg deca gbfed bagfdc cegfba cabdg ec agcdbe bdegc | agbcd ecbdg bcadg dcagb +aedbg bedca efbdag dgcb bfeac efgadc abegdc bfdegca cd edc | cbdae edcgfba ecd fdagbe +cfeagbd cfab bgc fbgdae fgdce gfadb bc ecadgb bcdfga gdbcf | cbfa cbadgf bfcdg abcf +edacg cdfbag fbeagdc cdgaef fc bagfe fac edabgc defc gcefa | dagcfb aegcf fc fegac +gfdabc dbgaef agbe cegadfb bdgaf gedafc fbced ge gfe befdg | dfcbga adbfge bdfeg cfadge +bcafge gbcd bc bfgdea cafdb fabdg acfdbg acefdgb acfde bfc | bfdac cbf fdabc edfca +gdcab cegd ebdcfga egb eg afceb cdgbfa acbge gdebaf bgcdea | agbce fceab dagfbe acebg +bagc cgf bacfd begfdc afdge bcagdf bcedfa cg becgafd dgfac | bdacf cfedab abcefd cafbd +ca cag gbfdc cadfbg eafcdg afcb edgab dgcbef cbgad abfdgce | cdbga bacf fgdace dcfgb +dcebf aefcbd gdcf fcbgde cbgef beacg gfebda gf fcdbgae feg | bfcadge cfbeg fg becgf +dcabfeg fbc cfgba dfabgc becadg fc dgebcf cfad cbagd gbeaf | ecadbg degabc aecbgd cf +cba efabd ebdcga cgeafbd cdabf fbce dbfcae bc cgdfa egbafd | abedf facdg ebcf cb +db efdcag dabf cagfdbe caegb decba bfcdeg fcabed fedca bde | edfacb adefc dbe dbe +fdabg efca bac ca fdacb becafdg fcdbe bcegad begdfc afbdce | gecdbf faec fadcb dbcaf +eg egad egfbadc bdecf feg agfcbe decfag dfceg cfgda cfbadg | fcabdg gef eg fecadg +fgad bgfde afe acebd dgfcbe af beadf ecabgf fbcedga abefgd | cbdegf edfab fegacb fa +efcgb beacfg gbecfda bfac afg dbfgce bfgdea fagce caedg af | gcebf aedfbg eafcbg fabecgd +bfdecga gaedfc ecga begcfd cfdab gbfade efa caedf ae defcg | daecf egca afcdeg caefd +decab efa dagefbc dagbce fcadg abdegf fe eafdc ebcf dcfabe | ebcf fe ebcf fae +begfd agedfc dabfce eadgf adf eacgfb afecbdg da feacg dcag | abcdfe daf debgf dbfeac +gbdfca gbefca cba cb ebcfagd gbafd fdacb fdgeab bcdg cadef | afbdc efdgabc dbagf gfdab +efdagb dae fcabedg caedb fdaecb ad ebdfc cdgfeb dfca eacbg | bedfgc fecdb edgfba cedfab +cd afdc cdg cbdgaf eagbd gacfb befdcga bdacg cbeafg ecfbgd | bdgacf dcfbeg dacgbf dagcb +begdaf gedbcfa dafc fea dfgce dgacfe gbedfc cfeag cbgea af | gecba agfbedc cbage egfdc +dc fgcd baefcg afbgecd bgeda ced baedfc cdeag gdafec efgca | bacfge bgdae abegfc afgbced +fc afcbgd bcf afebcgd bgdcf acdf bdfeg ecbagf cbdega adcgb | ceagbf befdcga edfagcb acdf +dbcgf degc bfgad bcfed gcb fceabdg gbfcde gc fbdaec afgebc | fecbdag fadgecb afbdg dgecfb +abcfg cfb eafgb bc cgbfda adfcge afdcg cfbgde cadb efgbcda | acgfb cb dfcag gdecfb +cdefb cfga edcgbfa cab abfge acfbe ca bcgaed bcaefg bdegaf | dbfce gdfcaeb fedabg fbcea +fgcae gafd eacdfgb baceg cadebf cfbged daefcg fge fg fceda | gceadbf dcbfage cafed ebacdf +fabdceg abcgde acebdf cfaeb fa egfcb dbfa fac abecd agefcd | cfeab edcbag acf dcabefg +dgbecfa abdfe acegd fdgabc gadef gfce ecbagd edagcf fg dfg | gdf fcegbda agcde fgd +dagf bcdaef ad acd cbeag febagdc dgbfac dgcab fcdbge bdgcf | fdbeac gcbda bcfdg bfcgd +fgdc gc gefdcab bdgec dbcefa gce bfgdec gcefab degab cebfd | bdfce gbecfd gadbe ebcadgf +fagc bdcfag fdacb agbedf daf aedgbc dbcga ebdgcfa cbdfe fa | febdc cfag af cadbg +bcd bfec dagbcf egcbfd bc edfgc bdecg edabg dcgeabf gdefca | bedag dbc fgcdbe ebdfcg +gedafcb dbagcf bcadeg fc gfc cebf edgfc cgdbe bcfdge egdfa | fc dabgec bdcge ebfc +gafbd ef becga ebgcaf agbef gfe gebcda gbfdce afce dbcgefa | ef gfe cabfeg gabecf +deab fbedgc eb bdacg dagcfbe abecg cfdagb beg baedcg gacfe | gacdb dbfgace dbea cadbg +badceg ced fecba fbdc adfec ebfcgad gecafb faedcb gfeda cd | fcead fbcaged adebgc ceabgd +bd bdcg fgcab abd cfaebd baecgf fecbgad agdfb efdga gfdacb | afebcd bfadg egbfca cgbfea +da decbf afdec begcad dcgefb gcafe edbfca dca fdab begdfca | efadc abdf ebcdfa fegac +gcbeaf geadbc fdbeagc bfdec cdbae ea agfdcb dabcg eac adeg | gcdba cebdf abecd gedcab +bcdae abedg ebg bfadec eg dbgaf egafcb gcadeb egdc abedfcg | dagfb ebg gebcaf eg +afb abgfed caegfd cfbd becag dcbgfea bf decaf faecb bedfac | daegfb dbaefc gacedf bfa +bgecf becfad ea adebgc cfdbgea dabcg eca eagd acbeg adfcgb | agdbc bagcd bgcda aedg +bf fagcde cfdb acfgd gfdaeb acdfegb gfacb bfg bgeca bcgafd | gfb gfacd agfdeb abcge +aegfd efcd bedfagc bacdgf gecadf aed egbdac fcagd ed afbeg | daefg dagfc acdbfg gbacfd +decga efbcd badcgf cfgdbe agefcbd fa ebcdaf fcdea eafb fda | dcfea fad ebadgfc afedcb +bf gebfcd bagfed bdagcfe cegbd fgbdc gfb ecgbad gdafc befc | fadbeg bcgde gbf bfg +df cbfged fgbca fbd bcafge bdeac agbfecd adcbf gdaf dabgfc | bcdea cafbd afdg gacfb +ecdbfa fadgce aceb fgebd bfcgad cdfae afgbced dfebc cfb cb | cfead fcb bc bedcf +fdbega cfegd cdbgae cdfebga fecadb aeg cbag ag adceb dcage | ebcagd gcead egdfc dagecb +cdbfeag gfdeba edfgca cead geadf gac fcbdg afgcd cabegf ca | fecgad gefda dafcg fdgca +cfgbae cgefb egdbfc dcg dfcbg ecbgfda badcf gfed edcgba gd | gd cbefdg adbceg badcf +bf bgf debfg bgade egbfcd cebdafg agdfce fgced dcbfag fcbe | adcgfe fdgeac fb ebfc +gefdc fdagcb gfdac bdafce caf ac daegcbf febgda cbga dbafg | dagbf ac faedcgb dfagb +ecfgadb dbgacf abfegc gd cefad fcgde cefdgb fcbge gdeb dgf | efacd bcegdaf bdgacf gd +cdfgb bdf fdcag bd cdba gbecf dfecga cfgebda gdefab dcbagf | begfc bcgfd gfbce afbgcd +fbe facb decgaf afdce fb bcdeaf bagdfe ecdbg dfbce bgedcfa | abdgfe eafdc efdbca acfgde +bgdcf cbaegd eabfdcg ceg eg aedcb deabfc dgea gfcaeb gecdb | eacgdb ge daebcf eg +egbdcaf gd cefabg dfge bcfagd afdegc caedg baecd gad caefg | gcedaf efgabc dag deagc +cdabf bgcfde afedgc fcb gcba gfacd bdaef bdegfac cb bdfagc | bcf bcedfg gaecdf cdgeabf +gf dcbfeg fcgdbea fge gedacb aefbg bgead gfad dfegba aebfc | aedgfb gf egf dfag +gbeacfd gacbd dcgfbe fg fgd dbacge bdagcf dfcea gafb fgadc | deagcb gf degfbc edcgbaf +ce gdbcae debcf cfdabe eacfbdg acef fgdbc begadf ecd afdbe | dbefa abegdc cbdfg acfbed +begdfc gbdc gedaf dc edgfc cdf fgbec ecdafb ebgafc degcbfa | egdfa edgbfca cbefg fagcbe +efcab dgbfc ag agdc cfagbde fbgeda fag acgdfb fcbga gbefcd | gacd gdac dcag gdac +bdage bdaefg gbe eb edfb bgafec dgbecaf egadf fdaecg dbacg | geb afgdbe dfbegac efgcba +ecgfa bec be ebfgc dgbcea adefgc egafbc egbafcd bafe gbfdc | aefb bce befa gfecab +ebgdc cbe ecdgab gacb gfced dbgea edbcfa fagcdeb gabfde bc | dgfec aebdgf abcdfeg fbaedc +daegbf adef dgcabe cafdgbe adcgfb dbegf ebgcf dbf ebadg fd | fcbge bgcef acfgdb efbgd +cdbge cfe adbcef fedgcb gfebcda cedgf edagf gdbcae cf gcfb | cdbeg gcdfe fabgdce aecbfd +beacg dafge gbeadc fcba bgdeafc begfa bf eabcfg ebgcdf bfg | gaefb bcfged degcab egdaf +acgefbd feb bf cdaef beadf gbaed abgced gabdef abfg gbfedc | begfda efcda bfe dgacbe +eacfgd fbdgce abfcge bcfea cafeg cagdbfe ebf debca bf fgba | fb fb acdbe cfdage +bfec cedagf aef ef degba bagcef dgcfab fgeab fecdgba bacfg | cbgaef efacgd aegfb aef +dbacfe edfc ec caebd agfebc cbe cbdag gfcbead bgfead bafde | deabc dfagbe cgbfea ec +ed dfgbec dfabg fbaec feacbg edafb aedc eadfcgb ebdacf dbe | deac bgeafc cebfdg fcdegb diff --git a/2021/day08/day08_input_ez.txt b/2021/day08/day08_input_ez.txt new file mode 100644 index 0000000..c9f629b --- /dev/null +++ b/2021/day08/day08_input_ez.txt @@ -0,0 +1,10 @@ +be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe +edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc +fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg +fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb +aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea +fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb +dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe +bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef +egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb +gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce diff --git a/2021/day08/makefile b/2021/day08/makefile new file mode 100644 index 0000000..5c81ee3 --- /dev/null +++ b/2021/day08/makefile @@ -0,0 +1,2 @@ +all day08.cpp: + g++ -std=c++20 -o day08 day08.cpp diff --git a/2021/utils.h b/2021/utils.h new file mode 100644 index 0000000..b96f570 --- /dev/null +++ b/2021/utils.h @@ -0,0 +1,26 @@ +#ifndef UTILS_H +#define UTILS_H + +void split (std::vector &vec, std::string str, std::string del) { + auto token = str.find(del); + if (token != std::string::npos) { + vec.push_back(str.substr(0, token)); + split(vec, str.substr(token+del.size()), del); + } else { vec.push_back(str); } +} + +// trim +static inline void ltrim(std::string &s) { + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { + return !std::isspace(ch); + })); +} +static inline void rtrim(std::string &s) { + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { + return !std::isspace(ch); + }).base(), s.end()); +} +static inline void trim(std::string &s) { ltrim(s); rtrim(s); } + + +#endif -- cgit v1.2.3-54-g00ecf