summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Wernick <justin@worthe-it.co.za>2023-12-24 13:53:00 +0200
committerJustin Wernick <justin@worthe-it.co.za>2023-12-24 13:53:00 +0200
commitf3304cff3fc3614a691539c3174980a02f72f19a (patch)
tree3c180792f984829be9bc48e462710d72816abf9b
parentef82c8d175f44a1d8b7cf7f5e0fffe9159fae74b (diff)
Day 24 part 1
-rw-r--r--2023/inputs/day_24.txt300
-rw-r--r--2023/src/bin/day_24.rs95
2 files changed, 387 insertions, 8 deletions
diff --git a/2023/inputs/day_24.txt b/2023/inputs/day_24.txt
new file mode 100644
index 0000000..f02dd0f
--- /dev/null
+++ b/2023/inputs/day_24.txt
@@ -0,0 +1,300 @@
+150191335679733, 257950211885619, 282767497332049 @ 239, 57, 42
+310843966440013, 307550528062309, 305058399233591 @ -42, -26, -8
+240206072440513, 257955942583195, 339853739319015 @ 44, 13, 18
+328079942790643, 130261907815999, 359206049223751 @ -79, 103, 68
+337351249739861, 346613199166195, 166455715168049 @ -117, 180, -22
+382999595831807, 263997929458185, 339398189509755 @ -215, 146, -240
+292215971658941, 304660684415491, 239751607871097 @ 25, 31, 36
+261178320787189, 287724824678835, 503081974721809 @ 23, -19, -244
+293003786105741, 51817612834630, 261778233638086 @ -14, 406, 84
+324292847613041, 239337776311060, 180831151904691 @ -50, 304, 159
+373892219798917, 448206573149333, 494171938903391 @ -174, -316, -506
+291958189750333, 211200561289494, 545387282887706 @ -30, 66, -236
+102766637116733, 328580991181069, 348319849851581 @ 162, -97, 69
+308653288538078, 359626279981411, 327170604352079 @ -51, -127, 43
+170774505741846, 359317723314818, 240337301448910 @ 167, -124, 138
+296280186465071, 297044261027861, 203674632219147 @ 112, 239, -25
+248396036887021, 191015517936307, 136707223922765 @ 6, 49, 295
+227833094847589, 318089240169947, 261826971642057 @ 122, -39, 57
+352695610032885, 336153033721715, 224395399593905 @ -147, -21, 7
+270294479305712, 318237058993306, 438449202167725 @ -17, -86, -27
+238632248166501, 346300590151779, 309004635219439 @ 66, -103, 26
+341194209911093, 353534807020195, 135794093122793 @ -106, -85, 310
+301432759812053, 342060586544947, 222327745155185 @ 59, -15, -57
+371711499291941, 399219161110975, 242683970572882 @ -134, -179, 158
+316271466129173, 364034032826419, 194526193542641 @ 98, -68, -225
+368278994687085, 361265414214411, 295890220941673 @ -147, -124, 8
+310587238911550, 357566571130438, 201579179532636 @ 23, -80, 24
+277239185310903, 224265975853887, 358096476394667 @ -21, 23, 46
+386037425914748, 241960047305104, 448098785319860 @ -151, 22, -100
+315078048368444, 397987070878630, 225531113442221 @ -43, -200, 109
+296524945208531, 365799923335810, 380133277048847 @ 52, -122, -565
+393549222959663, 231005568450907, 526604454053462 @ -156, 25, -170
+343637115842399, 529901670211264, 237925363576607 @ -100, -398, 135
+322371779381428, 245878554603369, 556420394432461 @ -73, -13, -139
+204387183192853, 223442125727539, 425529137843441 @ 62, 25, -32
+326714204756801, 374718574192573, 166924511797313 @ 40, -190, -87
+348865038382197, 400225355062479, 238275811298265 @ -198, -373, -483
+266187173712086, 212326525512415, 191693748167030 @ 261, 661, 40
+472003620323285, 517008364249459, 443754286552817 @ -317, -388, -219
+372042638262818, 275623493933894, 386225368072976 @ -227, 222, -638
+122992776975599, 140149129026023, 88987187791704 @ 196, 165, 360
+273359498615408, 295769201967433, 180783572391983 @ 39, 11, 211
+232426841958251, 318587485962852, 394159844631721 @ 28, -84, 9
+203812800418703, 175428957194703, 353140652762667 @ 49, 59, 72
+226166227152693, 230909778494326, 275610394540285 @ 74, 64, 93
+216550148725297, 357191377108396, 61125096662047 @ 86, -122, 407
+411269718193557, 552313344129718, 367737687952355 @ -214, -446, -89
+313889975950788, 363581990648389, 130523270243237 @ 149, -53, 421
+310564390476236, 336179028313987, 244322390733323 @ -9, -31, -33
+337623537958841, 373111838560921, 162222744206369 @ -128, -166, -23
+269253263840227, 281455069247965, 288774668329102 @ 32, 19, 26
+307310152536265, 236790323193801, 422548879712729 @ -28, 140, -299
+303019263430409, 338535075042883, 238731325313159 @ 22, -31, -37
+303842543732975, 528092293098196, 178947346931561 @ -52, -314, 249
+276751508166609, 134515471577863, 436811993843189 @ -19, 130, -50
+201920035825649, 403415026110451, 406423633751597 @ 48, -175, 23
+263363307326567, 6612657524025, 389600535358843 @ 55, 576, -198
+286155789598472, 206366771696843, 352029275083208 @ 25, 233, -188
+241918030875420, 264230237154371, 426239129935065 @ 11, -31, -7
+263823868465163, 286943886503242, 239986850152598 @ 24, -12, 138
+255140587141973, 327933054889459, 210930723590321 @ 113, -34, 118
+328975587913802, 405284631575062, 251124096310235 @ -67, -250, -57
+333174562801909, 328847768501615, 210542451204191 @ -70, 243, -326
+140577789731557, 225045273708971, 384491896016585 @ 150, 35, -5
+225944837742569, 211715219588521, 420222266544563 @ 36, 36, -22
+334626347118421, 314281645890483, 339263387038513 @ -85, 35, -322
+290893091825943, 372574489851063, 200783506380653 @ 104, -147, 37
+396929006464621, 483731288658147, 307509263349561 @ -253, -445, -156
+299650277924736, 376433221427883, 475592279857012 @ -27, -151, -268
+360604286177275, 203643800521173, 462633928905215 @ -117, 60, -98
+261456679908534, 181373340406312, 426252346265447 @ -13, 46, 7
+296522159354021, 317358452569591, 215853742808165 @ 86, 100, -40
+274207060368995, 185741005899833, 394521481362163 @ -20, 59, 15
+387781188480633, 350356270182319, 438056607504581 @ -153, -116, -86
+278019595731128, 449862540017845, 201261126705674 @ 29, -301, 170
+287320672549637, 303129600514323, 268524251434209 @ 28, 21, -13
+275401221254624, 190495134799033, 198477096504455 @ 175, 651, 43
+253129725996371, 199574270132635, 72341972645963 @ 11, 61, 372
+329683922288507, 272495114876596, 285376365703454 @ -80, -30, 126
+330994134631383, 307979719413504, 243586896391921 @ -76, 18, 33
+267872980108693, 251270179009099, 245360983079121 @ 26, 58, 117
+328376208583163, 369164092306257, 169079782281119 @ -41, -126, 106
+226942232075351, 355739086702617, 241148502824325 @ 172, -105, 53
+280913437772282, 258081527939383, 113960588638322 @ -27, -19, 320
+282074014301388, 108087409918927, 364425320375690 @ -21, 181, 16
+357285316231244, 199178450122798, 289920593979434 @ -147, 328, -114
+334948624416533, 296570749940656, 321341704944761 @ -86, 8, -71
+318531059549597, 351055482917923, 166282645664225 @ 91, 79, 31
+330780224124458, 357474443961364, 179700824509073 @ -61, -58, 65
+337284209474311, 252865822015995, 351553648067339 @ -93, 213, -338
+324482733059534, 340934015364721, 145677568229819 @ 21, 171, 255
+209225206497773, 380959850726179, 265747164367901 @ 130, -159, 77
+298008664299825, 160921323379562, 192724630778501 @ -42, 108, 229
+320644226628801, 320692877923563, 191190049747237 @ 83, 459, -288
+345254176511651, 351035900764183, 332432140979813 @ -104, -107, -43
+335725531057685, 192958477489459, 349786031079665 @ -87, 87, 22
+320616488420262, 353325511515887, 181802270376662 @ 11, -19, 22
+298061267984633, 557559281371195, 498683821024235 @ -36, -395, -194
+295747958884843, 121365832713629, 298853076437828 @ 44, 687, -230
+340821064781909, 264437324437811, 224566123007345 @ -125, 569, -257
+307437117141287, 271450774754449, 362783664332015 @ -5, 152, -360
+158233255899054, 187121012414068, 394244582629703 @ 95, 46, 31
+488833124604261, 345711415035139, 494211461130313 @ -264, -113, -118
+253930730112686, 231327352964251, 331115299259807 @ 11, 25, 63
+335018097230918, 366714435133084, 168195844843301 @ -87, -72, -83
+236138117624129, 307270462650277, 380395451528327 @ 46, -57, -29
+305049599722483, 225045335486819, 426874934819331 @ -55, 9, -6
+272815648722652, 309514029260538, 277476099206929 @ 17, -40, 65
+270670226808105, 341709121136795, 535066551499737 @ -13, -109, -157
+306688972542293, 280391879110519, 443788244550641 @ -38, 12, -223
+89142832207112, 315511426110745, 297150069248879 @ 203, -77, 107
+336460727083291, 363051895059163, 174822373051937 @ -105, -35, -119
+326009005034897, 274056160038226, 417245253877388 @ -74, -12, -80
+253428982982354, 307359157644538, 319309228322372 @ 37, -46, 22
+289045928454333, 312390797439579, 155705469444721 @ -31, -72, 273
+362096466853358, 213586233433349, 413830382260331 @ -131, 119, -161
+317825553661133, 476440197977467, 188241787516553 @ -61, -296, 222
+178265308916008, 131209335349977, 203316011559558 @ 189, 279, 182
+306933408970469, 418399669692331, 234038117533745 @ 68, -400, -215
+313880770598639, 292237402102357, 130737628223242 @ -8, 151, 332
+321235074582496, 324576171740292, 230192804126318 @ -49, -16, 52
+270487792247150, 395888685428375, 77891125722698 @ 31, -187, 406
+354565598691701, 295631229638143, 323808969937385 @ -110, -50, 67
+316345967997305, 121175523881242, 427371229458110 @ -58, 234, -140
+117938432287582, 68508254081682, 339096606787200 @ 171, 216, 56
+312493594691293, 150464962160805, 467949888908061 @ -46, 251, -291
+276779232042824, 216528625291195, 329068526005221 @ -5, 73, 29
+313428526250513, 414460673937343, 307490395397645 @ 9, -332, -440
+342619195039248, 266350990042604, 205908114480291 @ -163, 914, -349
+322741870377841, 356193773777777, 183127710744733 @ 8, -24, -25
+207705091909024, 387476343926645, 161225400512812 @ 123, -169, 258
+305406227427149, 210805065789995, 386897355193093 @ -50, 53, -9
+222875602885909, 226611330032435, 178610876622577 @ 186, 209, 201
+280442099190107, 278706391427308, 331028391368171 @ -8, -10, 19
+231083560006517, 281125716180412, 222053969123378 @ 202, 108, 68
+356945078162486, 256697795056213, 358059117207233 @ -117, 19, -15
+403293408724247, 425065916827115, 437727117658753 @ -173, -211, -87
+309003237210563, 303425898595192, 238960370253134 @ 84, 304, -344
+310945779923888, 299105074932203, 292236386835042 @ -41, -7, 8
+388020127533077, 367961483904659, 540019679161185 @ -230, -133, -790
+241326154621315, 231213300261592, 190192011139088 @ 96, 130, 196
+170216777258017, 186016341365345, 311386502551006 @ 182, 159, 14
+190969092561250, 283079154128614, 33345372260321 @ 231, 52, 529
+340888781757469, 386497398306759, 192157892519929 @ -112, -208, 71
+226629246301718, 215290337414773, 428691879169505 @ 29, 23, -15
+267173816373633, 178972907803889, 197055910098136 @ 54, 255, 176
+223715425126541, 313339279520149, 261658534549895 @ 38, -78, 156
+200581205703653, 473355676063474, 449344185368036 @ 58, -252, -40
+308623249405269, 359306985417889, 140706621953877 @ -22, -113, 293
+319780481265253, 374897321343979, 183522632159841 @ -58, -149, 213
+356396031262869, 174934070285681, 349118364520039 @ -150, 444, -328
+250387248971060, 262176077052140, 366537930003335 @ 43, 24, -53
+151028392805117, 147744114297043, 187332449318786 @ 98, 81, 244
+338332889728541, 397875061122481, 432270686287433 @ -98, -236, -739
+279102561858208, 214418859597904, 401821356239991 @ -21, 40, -13
+342565147194572, 273478489148583, 394543489876039 @ -95, -27, -9
+317176090354349, 406384230621415, 218019868065925 @ 46, -401, -273
+180109237505653, 207130156361609, 30093402381693 @ 74, 27, 405
+21687359882903, 200869089773182, 203993690590634 @ 224, 26, 228
+339534366981203, 509983572321964, 311260142357426 @ -92, -324, 68
+292176454296714, 316356150897092, 427152017470388 @ -45, -90, 16
+323563436748245, 346580457314995, 152302037871089 @ 33, 119, 185
+277344973603847, 241602399331840, 443461950776576 @ -20, 6, -56
+308797883363087, 332699092747159, 524041497523229 @ -39, -73, -397
+298378107633473, 274735135479310, 293510093928729 @ -26, 16, 41
+334948624416533, 351831296246019, 160929184806206 @ -86, 33, 124
+285909478058317, 335512897111523, 349800452025850 @ 66, -31, -354
+241113549514173, 307668544793719, 297606354548713 @ 134, 7, -75
+327792076338904, 362965290893033, 185643207738722 @ -25, -69, -80
+300287627653511, 264362967354589, 361046342230196 @ -44, -13, 24
+287755865544475, 355359238618045, 139010877617953 @ 27, -104, 297
+340876535536183, 278578800375914, 321374873705511 @ -96, 14, -13
+322977728573463, 362356160419499, 210425261119091 @ -19, -91, -92
+278834302906373, 251296552241839, 340228775848961 @ -10, 20, 21
+284686567657813, 158033263729859, 264080376604606 @ -22, 129, 134
+376875184677085, 338296332019889, 150927845218103 @ -130, -108, 280
+204557532007283, 315144198243744, 327507309113216 @ 64, -78, 76
+258663588879493, 168309779948999, 177539773579941 @ 198, 614, 158
+237098506518201, 351696980916895, 294352141035121 @ 17, -122, 129
+340729400214578, 485977904071309, 265032866495036 @ -95, -321, 98
+336159887663095, 449773484357668, 255605071445628 @ -88, -272, 102
+302932573481483, 274895202678169, 172960709884931 @ 5, 132, 202
+339118937383953, 417520447596039, 350033543669597 @ -91, -198, 40
+330268748274753, 346400304715869, 151896442128606 @ -10, 267, 134
+182182888778433, 238510386186019, 423133673115181 @ 93, 13, -40
+281181394871548, 76416035452865, 417053621567368 @ -31, 159, 8
+329296872170939, 325563486644191, 252343751594795 @ -73, -37, 36
+329672986967945, 352776455619085, 184354148348147 @ -34, 43, -125
+165779925874679, 333137057318875, 282638195707277 @ 160, -87, 85
+300216879199261, 385785591503043, 357504361892881 @ 27, -189, -411
+329901187678229, 441049260106099, 296929708002641 @ -78, -253, 44
+318069339669233, 337325792634909, 217464775017566 @ -26, -21, 22
+324342450941923, 370997647394749, 175469193435251 @ 12, -137, -17
+46458147857077, 14979347938899, 54605401564369 @ 371, 422, 428
+370437780101826, 253239261219376, 308189133991581 @ -193, 214, -211
+361350102003941, 316443915453475, 206126955700625 @ -163, 18, 103
+115268529653781, 136621609454563, 334572040809489 @ 186, 148, 51
+249787201791863, 192378632118454, 135195535822781 @ 152, 358, 309
+293548131721253, 342149153909032, 305883904038437 @ -6, -86, -27
+242927595383883, 224413358502179, 405822693648721 @ 9, 9, 17
+302996028818396, 385312265964943, 322411867677809 @ 73, -211, -607
+244232101210118, 188962696152535, 271857615159170 @ 59, 149, 82
+291793800885908, 321251439220669, 413445345977081 @ 63, 31, -647
+350713570266821, 155864308628602, 511842876258206 @ -102, 76, -86
+322559790747293, 178381199714275, 299070703807967 @ -66, 169, 36
+354964158371015, 246095019239941, 394668991984945 @ -119, 64, -127
+376523185763627, 453980940171213, 502664822900229 @ -137, -244, -153
+219799844556538, 345184241881004, 314717522775676 @ 75, -106, 48
+156331750672377, 320847710586815, 57959581765255 @ 132, -81, 392
+319955313134293, 335288225094987, 245805805739537 @ -46, -46, 13
+293737497357583, 438648321205099, 273961686241631 @ 69, -395, -206
+253474666507127, 298933687680433, 250107837707747 @ 7, -60, 166
+251215797245001, 240610567627541, 141808238235123 @ 68, 98, 290
+284014381141233, 283008191981819, 159881275382931 @ 222, 393, 183
+252656976469305, 334079078717641, 323930268036508 @ 6, -101, 86
+248431130504489, 452197775148391, 342734429423999 @ 88, -305, -114
+105901763425541, 173476559047997, 83967463913985 @ 322, 210, 393
+281586692263461, 281953544526915, 325144959522817 @ 8, 15, -33
+241727627095639, 251198092574452, 175579244065865 @ 116, 118, 217
+367457582289400, 440958556645626, 358260508293009 @ -139, -256, -63
+257642146544571, 283832850478501, 368267004877135 @ 17, -26, -12
+199839580529633, 269864858559621, 188289032813627 @ 64, -30, 238
+159699008941637, 211860590844955, 263480368587965 @ 186, 105, 101
+502075668198231, 473576136052048, 541803958139546 @ -268, -254, -146
+311091225457175, 265925982114911, 269591419008657 @ -35, 83, 17
+286054006355617, 164692062171829, 250065349164891 @ 116, 712, -156
+337278499166255, 328932634542849, 396308305611779 @ -89, -88, -38
+182478843910352, 319040472499070, 359911176859965 @ 85, -84, 45
+342512990888358, 373949203445844, 222731573792691 @ -201, -178, -933
+327769328335565, 497869047680275, 215313641319593 @ -43, -899, -148
+226045242421286, 403503096286362, 352009489216264 @ 61, -186, 6
+302437130541695, 386424956715709, 325598559732077 @ -20, -173, -83
+309439661832947, 295464832914250, 331945598716031 @ -12, 78, -261
+330397567907083, 336148764180709, 187498438465825 @ -61, 52, 41
+260822775662048, 245857685855899, 545926023333166 @ 13, 25, -250
+118245364349540, 243346157838943, 315245172602570 @ 191, 21, 68
+293258368866381, 364866059774575, 197855249919693 @ 80, -116, 68
+144573359499861, 181812578858533, 84482204067979 @ 266, 208, 396
+315283085622533, 336686047098419, 204725484976081 @ 13, 33, -25
+277695064761793, 315389159380631, 314112636856301 @ 29, -30, -56
+321096662922635, 359186867342683, 221221977881261 @ 123, 45, -901
+297094316927557, 320344456646991, 296259602814365 @ -10, -40, -20
+275135564926566, 376119009402267, 395020209195493 @ 21, -151, -163
+292793459505047, 269452665775059, 344824492391188 @ -20, 17, -28
+314852351662503, 437416624876699, 183640663732179 @ -31, -323, 176
+346208802895047, 474597208186547, 352273856670092 @ -100, -271, 28
+304351198960908, 382137550824919, 163158207201906 @ 89, -203, 170
+249096678703175, 116692741926871, 291508873676905 @ 13, 151, 117
+278889264698987, 325062466597585, 333427521999773 @ -15, -84, 47
+318522290866375, 352203589731783, 475571867052429 @ -37, -85, -705
+317391495743140, 304445581411432, 533452134547663 @ -57, -32, -357
+337755702829568, 243457090759154, 171358434826776 @ -101, 542, 134
+372262468284729, 409969331089323, 516498878840749 @ -123, -181, -82
+211532629288679, 317274923184805, 295974665114165 @ 200, -17, -67
+318394627733909, 333093617943571, 224032862576081 @ -10, 34, -86
+231171130666631, 236918328858055, 421822927902782 @ 28, 5, -18
+189165505519543, 262464754206035, 344587263255565 @ 149, 33, -37
+288978430450615, 238973533761643, 360564903932831 @ -7, 85, -86
+318579571308413, 429248375621371, 159605824681721 @ 99, -794, 94
+263855261579033, 198740924966919, 256891264685831 @ 76, 251, 28
+221192878937141, 312135897365663, 323518515507409 @ 130, -30, -55
+260570338350698, 345457467607294, 205905235187771 @ 127, -68, 107
+271994052793421, 316494495626479, 227098496615501 @ 148, 62, -26
+247096739208146, 341621677098388, 226497012500958 @ 151, -62, 62
+355170093070033, 293187706578839, 219193538775381 @ -111, -46, 194
+367401014093749, 307861273519891, 262090085321809 @ -144, -29, 75
+329052351180673, 473568299459999, 208685031795506 @ -58, -627, -26
+277804873386167, 45111284780899, 366474202192997 @ -9, 297, -13
+278339050781555, 416436997280995, 182165284404593 @ 5, -215, 225
+282930176609315, 185614928898097, 435065935383545 @ -27, 68, -43
+322306390977149, 373599114529618, 180557531006690 @ 50, -164, -122
+319668156274635, 298695092535035, 279876171169163 @ -55, 5, 10
+151403512810680, 134784161699565, 206050132870976 @ 303, 359, 154
+325717130700208, 327705094864712, 203279816419826 @ -61, -24, 124
+118205392338003, 95443240181779, 284290003678021 @ 140, 145, 141
+333601039654415, 318513662905195, 164555021115549 @ -65, 685, -57
+274776715305543, 284908630311407, 159835871105463 @ 179, 239, 212
+325370278692597, 359603643786823, 176017025951209 @ 50, 28, -189
+301848432284469, 451703283599411, 130805379241361 @ -43, -247, 304
+332006890604087, 373683589901497, 179085916011599 @ -47, -170, -198
+258674693169370, 333027292930539, 456137118086106 @ -7, -103, -36
+176633590581743, 75371727349312, 204924090312498 @ 124, 250, 206
+347016645759060, 407612098262346, 251800547493613 @ -187, -444, -627
+321631459164835, 262186402763633, 201791988161855 @ -45, 194, 106
+295373694794910, 303100954605005, 179654642750740 @ 123, 219, 92
+337475027864399, 264695925661425, 477521481975637 @ -89, -16, -109
+208103462266850, 302567010544263, 298972979701314 @ 127, -27, 26
+221677657105241, 149728375120051, 394322068849853 @ 61, 145, -38
+336426923912942, 244513248263245, 178323912304700 @ -89, 115, 216
+313697433951719, 317893993778713, 240690800042985 @ -35, -14, 53
+333482577531089, 304941871666717, 206858020851617 @ -82, 39, 113
+230297835206615, 202358963585434, 341393655016827 @ 16, 22, 95
+287377479027792, 222459389238249, 219479140356667 @ 83, 387, 15
+170303653115971, 57902939471803, 114086726767521 @ 147, 301, 329
+288019734508483, 228983179633947, 427679608533025 @ -36, 9, -15
+327530044595837, 176291069676091, 328434668394539 @ -74, 173, -12
+178529805017993, 195493100865409, 242489239469651 @ 128, 98, 152
+280749343264517, 310056912736219, 232684093145441 @ 46, 7, 69
+305207571533357, 298697252599459, 311819844132065 @ -33, -13, -13
+278604047935731, 298887079420155, 444483112092287 @ 41, 21, -392
diff --git a/2023/src/bin/day_24.rs b/2023/src/bin/day_24.rs
index b3a610b..325b4cc 100644
--- a/2023/src/bin/day_24.rs
+++ b/2023/src/bin/day_24.rs
@@ -1,19 +1,98 @@
-use nom::IResult;
+use nalgebra::{Matrix2, Point2, Point3, Vector2, Vector3};
+use nom::{
+ bytes::complete::tag,
+ character::complete::{i64, line_ending},
+ combinator::map,
+ multi::separated_list1,
+ sequence::{separated_pair, tuple},
+ IResult,
+};
use std::fs;
fn main() -> Result<(), Box<dyn std::error::Error>> {
- let input = fs::read_to_string("inputs/day_2.txt")?;
- let parsed = Example::parser(&input).unwrap().1;
- dbg!(&parsed);
+ let input = fs::read_to_string("inputs/day_24.txt")?;
+ let parsed = Hailstones::parser(&input).unwrap().1;
+ dbg!(&parsed.count_intersections_2d(200000000000000., 400000000000000.));
Ok(())
}
#[derive(Debug)]
-struct Example;
+struct Hailstones(Vec<Hailstone>);
-impl Example {
- fn parser(_input: &str) -> IResult<&str, Self> {
- todo!()
+#[derive(Debug)]
+struct Hailstone {
+ initial_position: Point3<f64>,
+ velocity: Vector3<f64>,
+}
+
+impl Hailstones {
+ fn parser(input: &str) -> IResult<&str, Self> {
+ map(separated_list1(line_ending, Hailstone::parser), Hailstones)(input)
+ }
+
+ fn count_intersections_2d(&self, min: f64, max: f64) -> usize {
+ self.0
+ .iter()
+ .enumerate()
+ .map(|(i, hailstone)| {
+ self.0
+ .iter()
+ .skip(i + 1)
+ .filter(|other_hailstone| hailstone.intersects_2d(other_hailstone, min, max))
+ .count()
+ })
+ .sum()
+ }
+}
+
+impl Hailstone {
+ fn parser(input: &str) -> IResult<&str, Self> {
+ map(
+ separated_pair(
+ map(
+ tuple((i64, tag(", "), i64, tag(", "), i64)),
+ |(x, _, y, _, z)| Point3::new(x as f64, y as f64, z as f64),
+ ),
+ tag(" @ "),
+ map(
+ tuple((i64, tag(", "), i64, tag(", "), i64)),
+ |(x, _, y, _, z)| Vector3::new(x as f64, y as f64, z as f64),
+ ),
+ ),
+ |(initial_position, velocity)| Hailstone {
+ initial_position,
+ velocity,
+ },
+ )(input)
+ }
+
+ fn intersects_2d(&self, other: &Hailstone, min: f64, max: f64) -> bool {
+ let variables = Matrix2::new(
+ self.velocity.x,
+ -other.velocity.x,
+ self.velocity.y,
+ -other.velocity.y,
+ );
+ let constants = Vector2::new(
+ other.initial_position.x - self.initial_position.x,
+ other.initial_position.y - self.initial_position.y,
+ );
+
+ if let Some(variables_inverse) = variables.try_inverse() {
+ let intersection = variables_inverse * constants;
+ let self_t = intersection.x;
+ let other_t = intersection.y;
+
+ let intersection = self.initial_position.xy() + self.velocity.xy() * self_t;
+ self_t >= 0.
+ && other_t >= 0.
+ && intersection.x >= min
+ && intersection.x <= max
+ && intersection.y >= min
+ && intersection.y <= max
+ } else {
+ false
+ }
}
}