diff --git a/src/Day01.kt b/src/Day01.kt index 35b4e09..8a1a919 100644 --- a/src/Day01.kt +++ b/src/Day01.kt @@ -1,17 +1,18 @@ fun main() { - fun part1(input: List): Int { - return input.size + fun part1(input: List): Int { + return input.windowed(2).count { it[0] < it[1] } } - fun part2(input: List): Int { - return input.size + fun part2(input: List): Int { + return part1(input.windowed(3).map { it.sum() }.toList()) } - // test if implementation meets criteria from the description, like: - val testInput = readInput("Day01_test") - check(part1(testInput) == 1) + val testInput = readInputAsInts("Day01_test") + val input = readInputAsInts("Day01") - val input = readInput("Day01") + check(part1(testInput) == 7) println(part1(input)) + + check(part2(testInput) == 5) println(part2(input)) } diff --git a/src/Day01.txt b/src/Day01.txt new file mode 100644 index 0000000..b6b18e5 --- /dev/null +++ b/src/Day01.txt @@ -0,0 +1,2000 @@ +176 +184 +196 +199 +204 +206 +219 +215 +216 +217 +218 +230 +231 +214 +210 +189 +174 +170 +162 +167 +173 +182 +177 +179 +180 +182 +198 +201 +200 +207 +203 +213 +231 +222 +223 +224 +209 +217 +228 +236 +243 +241 +260 +262 +258 +260 +254 +270 +271 +278 +264 +263 +262 +260 +261 +234 +229 +233 +208 +210 +211 +210 +206 +207 +209 +199 +201 +218 +210 +206 +207 +218 +221 +229 +233 +234 +235 +246 +253 +254 +260 +259 +253 +254 +275 +277 +295 +296 +299 +333 +334 +336 +337 +339 +347 +374 +369 +371 +376 +371 +374 +375 +371 +374 +381 +383 +384 +395 +396 +400 +395 +397 +399 +389 +396 +390 +404 +411 +412 +428 +424 +433 +431 +437 +473 +489 +486 +488 +479 +480 +484 +474 +475 +471 +492 +493 +501 +512 +509 +506 +519 +523 +522 +521 +535 +548 +531 +519 +523 +522 +516 +512 +522 +547 +581 +582 +580 +579 +580 +600 +595 +592 +587 +588 +591 +592 +583 +586 +584 +597 +610 +592 +581 +583 +578 +575 +582 +579 +587 +594 +592 +593 +599 +605 +609 +610 +609 +601 +604 +608 +609 +613 +614 +612 +614 +626 +627 +636 +656 +652 +655 +656 +678 +680 +686 +687 +654 +663 +669 +664 +668 +647 +652 +659 +653 +654 +656 +637 +638 +621 +620 +621 +609 +604 +612 +616 +612 +617 +614 +610 +607 +608 +613 +617 +624 +625 +622 +604 +606 +610 +609 +607 +605 +618 +622 +635 +636 +640 +667 +668 +664 +674 +675 +682 +694 +698 +704 +717 +723 +724 +699 +695 +693 +674 +670 +683 +685 +683 +676 +675 +678 +677 +675 +657 +670 +675 +673 +658 +660 +673 +685 +675 +676 +677 +671 +689 +688 +690 +691 +692 +709 +713 +712 +715 +739 +731 +734 +762 +764 +746 +728 +729 +727 +730 +745 +773 +781 +787 +806 +807 +808 +815 +822 +837 +844 +842 +841 +850 +853 +838 +841 +845 +846 +844 +849 +846 +847 +859 +851 +854 +857 +873 +882 +892 +896 +883 +896 +895 +886 +879 +878 +877 +878 +881 +891 +898 +913 +914 +920 +922 +928 +929 +915 +917 +918 +913 +926 +929 +937 +939 +940 +936 +938 +939 +948 +946 +951 +950 +918 +917 +924 +917 +918 +921 +919 +917 +929 +950 +985 +988 +991 +996 +1002 +995 +990 +999 +989 +990 +991 +992 +991 +992 +993 +991 +994 +996 +997 +989 +993 +975 +973 +972 +973 +971 +969 +976 +983 +980 +987 +1003 +1002 +1000 +993 +994 +993 +972 +970 +991 +988 +989 +993 +996 +1002 +1003 +1008 +1007 +1014 +1015 +1022 +1012 +1029 +1030 +1029 +1030 +1025 +1026 +1010 +1006 +1008 +1006 +1012 +1015 +1029 +1067 +1102 +1107 +1108 +1103 +1108 +1103 +1120 +1119 +1118 +1119 +1118 +1119 +1132 +1137 +1148 +1150 +1153 +1166 +1169 +1199 +1205 +1208 +1216 +1210 +1217 +1216 +1217 +1218 +1198 +1199 +1197 +1198 +1193 +1202 +1241 +1242 +1239 +1241 +1238 +1233 +1234 +1235 +1237 +1228 +1229 +1235 +1218 +1236 +1237 +1208 +1246 +1251 +1246 +1248 +1242 +1241 +1243 +1231 +1226 +1224 +1221 +1220 +1224 +1219 +1227 +1214 +1237 +1261 +1271 +1268 +1292 +1304 +1303 +1312 +1287 +1286 +1292 +1295 +1297 +1304 +1311 +1312 +1309 +1314 +1307 +1316 +1320 +1319 +1316 +1333 +1332 +1316 +1315 +1320 +1321 +1335 +1355 +1353 +1356 +1325 +1333 +1335 +1339 +1360 +1361 +1362 +1364 +1361 +1363 +1362 +1363 +1364 +1392 +1397 +1398 +1405 +1406 +1408 +1406 +1394 +1391 +1407 +1413 +1415 +1413 +1419 +1422 +1416 +1422 +1421 +1431 +1433 +1437 +1439 +1443 +1446 +1449 +1439 +1444 +1452 +1460 +1468 +1469 +1486 +1500 +1507 +1513 +1512 +1511 +1531 +1532 +1541 +1550 +1557 +1561 +1557 +1560 +1563 +1564 +1565 +1588 +1589 +1592 +1591 +1593 +1598 +1603 +1590 +1604 +1608 +1610 +1623 +1598 +1592 +1601 +1598 +1600 +1601 +1599 +1609 +1607 +1608 +1613 +1605 +1601 +1605 +1610 +1611 +1609 +1608 +1615 +1620 +1629 +1628 +1641 +1632 +1630 +1635 +1634 +1629 +1630 +1632 +1630 +1641 +1661 +1655 +1657 +1653 +1619 +1629 +1607 +1600 +1603 +1591 +1596 +1599 +1601 +1582 +1591 +1593 +1596 +1597 +1600 +1596 +1597 +1603 +1624 +1630 +1628 +1626 +1628 +1631 +1628 +1629 +1625 +1627 +1620 +1613 +1614 +1638 +1637 +1626 +1624 +1623 +1621 +1620 +1621 +1598 +1610 +1611 +1622 +1629 +1646 +1655 +1677 +1678 +1679 +1699 +1702 +1715 +1710 +1722 +1719 +1715 +1716 +1724 +1735 +1734 +1727 +1743 +1748 +1745 +1742 +1755 +1754 +1734 +1738 +1729 +1732 +1733 +1726 +1723 +1744 +1745 +1746 +1748 +1778 +1777 +1780 +1792 +1798 +1799 +1800 +1793 +1794 +1797 +1802 +1796 +1800 +1820 +1823 +1824 +1823 +1828 +1827 +1824 +1847 +1842 +1846 +1847 +1844 +1833 +1826 +1834 +1839 +1846 +1854 +1842 +1845 +1860 +1874 +1869 +1871 +1869 +1870 +1874 +1875 +1891 +1893 +1894 +1886 +1885 +1853 +1871 +1868 +1866 +1875 +1885 +1882 +1883 +1879 +1884 +1893 +1918 +1919 +1932 +1933 +1930 +1949 +1952 +1949 +1945 +1944 +1930 +1950 +1952 +1951 +1981 +1980 +1992 +1993 +1981 +1979 +2007 +1989 +1987 +1996 +2006 +2012 +2028 +2037 +2041 +2039 +2046 +2047 +2055 +2058 +2079 +2086 +2087 +2088 +2079 +2080 +2079 +2082 +2089 +2092 +2097 +2113 +2115 +2119 +2109 +2111 +2110 +2108 +2100 +2099 +2107 +2103 +2104 +2115 +2110 +2116 +2117 +2113 +2120 +2128 +2129 +2115 +2114 +2125 +2148 +2145 +2147 +2160 +2159 +2162 +2155 +2161 +2162 +2160 +2162 +2149 +2150 +2152 +2170 +2171 +2172 +2171 +2186 +2187 +2186 +2188 +2196 +2185 +2195 +2196 +2200 +2197 +2195 +2190 +2191 +2189 +2199 +2200 +2208 +2204 +2203 +2209 +2231 +2234 +2247 +2245 +2277 +2279 +2281 +2282 +2279 +2294 +2296 +2304 +2287 +2294 +2293 +2297 +2311 +2339 +2343 +2344 +2323 +2360 +2369 +2371 +2372 +2373 +2372 +2384 +2383 +2390 +2412 +2419 +2421 +2432 +2428 +2427 +2449 +2459 +2456 +2457 +2459 +2469 +2472 +2474 +2472 +2475 +2487 +2479 +2481 +2482 +2481 +2502 +2492 +2493 +2496 +2522 +2529 +2550 +2551 +2549 +2547 +2546 +2551 +2553 +2555 +2552 +2547 +2536 +2534 +2518 +2517 +2513 +2511 +2495 +2508 +2500 +2501 +2514 +2524 +2551 +2552 +2561 +2563 +2571 +2573 +2565 +2559 +2564 +2565 +2568 +2570 +2556 +2546 +2552 +2554 +2581 +2574 +2573 +2572 +2575 +2577 +2578 +2579 +2580 +2579 +2589 +2586 +2587 +2611 +2615 +2614 +2618 +2619 +2618 +2626 +2630 +2623 +2627 +2628 +2627 +2628 +2657 +2658 +2672 +2673 +2685 +2668 +2658 +2660 +2668 +2669 +2671 +2673 +2669 +2668 +2675 +2668 +2669 +2652 +2672 +2675 +2678 +2677 +2699 +2700 +2701 +2712 +2710 +2712 +2711 +2710 +2721 +2722 +2727 +2731 +2733 +2731 +2734 +2738 +2751 +2745 +2744 +2750 +2765 +2767 +2773 +2771 +2770 +2773 +2778 +2782 +2792 +2796 +2794 +2806 +2807 +2820 +2823 +2836 +2834 +2827 +2826 +2830 +2828 +2829 +2831 +2838 +2845 +2846 +2863 +2860 +2862 +2861 +2862 +2863 +2864 +2871 +2873 +2874 +2875 +2893 +2892 +2893 +2898 +2924 +2942 +2956 +2950 +2952 +2990 +2993 +2994 +3001 +3017 +3022 +3017 +3016 +3017 +3012 +3018 +3019 +3018 +3048 +3058 +3059 +3062 +3072 +3073 +3071 +3072 +3065 +3093 +3094 +3095 +3094 +3100 +3101 +3084 +3085 +3079 +3077 +3099 +3100 +3117 +3118 +3121 +3122 +3137 +3108 +3110 +3109 +3108 +3113 +3102 +3103 +3119 +3122 +3126 +3132 +3137 +3132 +3152 +3153 +3163 +3164 +3176 +3175 +3181 +3190 +3191 +3198 +3195 +3177 +3178 +3177 +3183 +3202 +3203 +3192 +3184 +3185 +3191 +3196 +3195 +3173 +3183 +3182 +3184 +3185 +3193 +3210 +3208 +3207 +3214 +3221 +3234 +3233 +3263 +3284 +3283 +3284 +3270 +3259 +3268 +3253 +3259 +3246 +3251 +3246 +3251 +3256 +3249 +3251 +3261 +3260 +3259 +3267 +3277 +3273 +3282 +3286 +3284 +3285 +3288 +3295 +3270 +3269 +3277 +3276 +3281 +3280 +3292 +3293 +3301 +3306 +3335 +3336 +3310 +3309 +3312 +3318 +3324 +3340 +3368 +3371 +3369 +3370 +3368 +3367 +3386 +3388 +3416 +3420 +3423 +3433 +3427 +3438 +3457 +3469 +3474 +3479 +3489 +3507 +3471 +3468 +3480 +3486 +3490 +3493 +3495 +3496 +3495 +3479 +3480 +3485 +3490 +3489 +3491 +3488 +3494 +3493 +3515 +3517 +3526 +3519 +3520 +3525 +3515 +3516 +3517 +3508 +3510 +3512 +3515 +3536 +3535 +3530 +3540 +3542 +3550 +3530 +3550 +3553 +3537 +3536 +3542 +3547 +3544 +3562 +3561 +3551 +3546 +3547 +3562 +3561 +3586 +3593 +3582 +3586 +3589 +3600 +3604 +3605 +3607 +3608 +3613 +3624 +3626 +3652 +3668 +3669 +3666 +3674 +3677 +3668 +3671 +3673 +3675 +3657 +3666 +3655 +3658 +3662 +3659 +3660 +3657 +3655 +3662 +3657 +3660 +3661 +3664 +3675 +3677 +3661 +3663 +3669 +3645 +3646 +3644 +3645 +3666 +3677 +3685 +3686 +3689 +3697 +3694 +3703 +3672 +3676 +3675 +3706 +3726 +3742 +3744 +3765 +3792 +3793 +3802 +3805 +3813 +3816 +3817 +3826 +3827 +3828 +3830 +3826 +3825 +3824 +3816 +3821 +3820 +3821 +3825 +3846 +3848 +3847 +3846 +3849 +3854 +3844 +3860 +3859 +3861 +3863 +3848 +3845 +3846 +3853 +3851 +3850 +3863 +3865 +3885 +3912 +3913 +3914 +3913 +3901 +3897 +3927 +3928 +3927 +3929 +3931 +3925 +3912 +3915 +3919 +3920 +3896 +3900 +3904 +3909 +3919 +3922 +3923 +3925 +3944 +3938 +3937 +3936 +3944 +3943 +3942 +3955 +3944 +3945 +3948 +3946 +3939 +3955 +3957 +3951 +3950 +3954 +3966 +3974 +3987 +3991 +3987 +3985 +3981 +3983 +3986 +3996 +4002 +4012 +4031 +4030 +4031 +4034 +4018 +4020 +4007 +4009 +4019 +4006 +4011 +4018 +4022 +4012 +4014 +4012 +4013 +4031 +4046 +4051 +4054 +4065 +4070 +4074 +4080 +4081 +4080 +4051 +4058 +4056 +4054 +4049 +4054 +4048 +4065 +4078 +4082 +4086 +4099 +4100 +4106 +4126 +4118 +4145 +4141 +4142 +4153 +4168 +4176 +4168 +4167 +4171 +4172 +4173 +4137 +4154 +4150 +4134 +4137 +4138 +4137 +4148 +4151 +4129 +4131 +4130 +4132 +4129 +4155 +4156 +4157 +4162 +4179 +4185 +4187 +4186 +4177 +4167 +4174 +4178 +4176 +4174 +4177 +4180 +4192 +4206 +4212 +4192 +4201 +4193 +4213 +4194 +4201 +4181 +4184 +4181 +4192 +4195 +4205 +4209 +4199 +4201 +4200 +4201 +4219 +4218 +4220 +4221 +4235 +4236 +4229 +4235 +4233 +4234 +4240 +4239 +4211 +4216 +4223 +4210 +4224 +4225 +4223 +4224 +4223 +4233 +4232 +4240 +4248 +4240 +4241 +4246 +4247 +4244 +4245 +4246 +4256 +4261 +4274 +4268 +4288 +4289 +4290 +4301 +4299 +4303 +4304 +4303 +4297 +4299 +4288 +4296 +4293 +4296 +4295 +4302 +4303 +4319 +4313 +4315 +4320 +4322 +4326 +4328 +4337 +4338 +4351 +4370 +4381 +4388 +4413 +4418 +4417 +4416 +4415 +4436 +4440 +4441 +4464 +4461 +4468 +4469 +4471 +4480 +4496 +4495 +4496 +4497 +4494 +4461 +4462 +4461 +4462 +4461 +4457 +4466 +4467 +4468 +4469 +4491 +4497 +4510 +4500 +4485 +4497 +4508 +4506 +4500 +4501 +4514 +4516 +4517 +4516 +4543 +4549 +4529 +4523 +4522 +4540 +4539 +4540 +4543 +4545 +4530 +4532 +4531 +4533 +4535 +4511 +4517 +4520 +4521 +4523 +4517 +4525 +4526 +4538 +4566 +4567 +4564 +4575 +4577 +4576 +4574 +4580 +4594 +4595 +4596 +4621 +4622 +4629 +4632 +4641 +4642 +4658 +4659 +4660 +4685 +4687 +4708 +4727 +4735 +4739 +4745 +4744 +4753 +4755 +4757 +4759 +4782 +4785 +4777 +4783 +4786 +4789 +4794 +4802 +4803 +4833 +4849 +4857 +4865 +4866 +4872 +4869 +4876 +4874 +4877 +4899 +4900 +4901 +4893 +4892 +4904 +4907 +4900 +4907 +4908 +4903 +4890 +4895 +4896 +4876 +4880 +4888 +4889 +4894 +4893 +4924 +4927 +4922 +4893 +4901 +4891 +4908 +4916 +4915 +4920 +4931 +4954 +4943 +4953 +4954 +4959 +4949 +4952 +4936 +4935 +4916 +4922 +4923 +4922 +4928 +4929 +4930 +4927 +4923 +4926 +4924 +4931 +4935 +4955 +4966 +4987 +4988 +4990 +4992 +4991 +4999 +5001 +5006 +5007 +5021 +5034 +5047 +5050 +5055 +5091 +5096 +5101 +5100 +5105 +5108 +5117 +5114 +5127 +5129 +5127 +5153 +5152 +5154 +5155 +5156 +5142 +5154 +5180 +5177 +5183 +5184 +5201 +5204 +5205 +5222 +5212 +5217 +5222 +5251 +5278 +5277 +5302 +5319 +5326 +5333 +5327 +5321 +5337 +5361 +5362 +5368 +5369 +5366 +5368 +5385 +5383 +5384 +5393 +5403 +5427 +5428 +5429 +5428 +5459 +5442 +5441 +5433 +5436 +5428 +5429 +5428 +5427 +5433 +5418 +5419 +5421 +5425 +5426 +5435 +5441 +5445 +5442 +5446 +5454 +5458 +5454 +5456 +5452 +5423 +5426 +5425 +5418 +5417 +5420 +5425 +5420 +5438 +5447 +5450 +5451 +5453 +5450 +5453 +5449 +5457 +5464 +5455 +5460 +5443 +5439 +5425 +5423 +5434 +5438 +5437 +5412 +5408 +5405 +5407 +5420 +5426 +5452 +5459 +5460 +5490 +5498 +5508 +5528 +5531 +5516 +5517 +5512 +5524 +5529 +5511 +5525 +5527 +5538 +5539 +5546 +5550 +5549 +5552 +5554 +5559 +5551 +5552 +5556 +5559 +5579 +5584 +5590 +5593 +5592 +5595 +5604 +5600 +5586 +5591 +5572 +5571 +5583 +5584 +5578 +5579 +5580 +5579 +5570 +5571 +5574 +5577 +5583 +5584 +5569 +5586 +5582 +5561 +5550 +5554 +5544 +5550 +5529 +5538 +5551 +5569 +5570 +5584 +5588 +5596 \ No newline at end of file diff --git a/src/Day01_test.txt b/src/Day01_test.txt new file mode 100644 index 0000000..59dad67 --- /dev/null +++ b/src/Day01_test.txt @@ -0,0 +1,10 @@ +199 +200 +208 +210 +200 +207 +240 +269 +260 +263 \ No newline at end of file diff --git a/src/Utils.kt b/src/Utils.kt index acfb72a..e229fbc 100644 --- a/src/Utils.kt +++ b/src/Utils.kt @@ -7,6 +7,8 @@ import java.security.MessageDigest */ fun readInput(name: String) = File("src", "$name.txt").readLines() +fun readInputAsInts(name: String) = readInput(name).map { it.toInt() } + /** * Converts string to md5 hash. */