This commit is contained in:
Moritz Hölting 2023-12-24 13:35:07 +01:00
parent 8d0c9f6379
commit a95dffbf5c
5 changed files with 811 additions and 0 deletions

193
Cargo.lock generated
View File

@ -2,18 +2,91 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "aho-corasick"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0"
dependencies = [
"memchr",
]
[[package]]
name = "autocfg"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bindgen"
version = "0.66.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7"
dependencies = [
"bitflags",
"cexpr",
"clang-sys",
"lazy_static",
"lazycell",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex",
"syn",
]
[[package]]
name = "bitflags"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "cc"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
]
[[package]]
name = "cexpr"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
dependencies = [
"nom",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clang-sys"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f"
dependencies = [
"glob",
"libc",
"libloading",
]
[[package]]
name = "cmake"
version = "0.1.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130"
dependencies = [
"cc",
]
[[package]]
name = "console"
version = "0.15.7"
@ -229,6 +302,15 @@ dependencies = [
"indoc",
]
[[package]]
name = "day-24"
version = "0.0.0"
dependencies = [
"indoc",
"itertools",
"z3",
]
[[package]]
name = "deprecate-until"
version = "0.1.1"
@ -265,6 +347,12 @@ version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "glob"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "hashbrown"
version = "0.12.3"
@ -350,12 +438,34 @@ version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "lazycell"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "libc"
version = "0.2.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
[[package]]
name = "libloading"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
"cfg-if",
"winapi",
]
[[package]]
name = "log"
version = "0.4.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
[[package]]
name = "memchr"
version = "2.6.4"
@ -484,6 +594,12 @@ dependencies = [
"thiserror",
]
[[package]]
name = "peeking_take_while"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
[[package]]
name = "portable-atomic"
version = "1.6.0"
@ -544,6 +660,35 @@ dependencies = [
"crossbeam-utils",
]
[[package]]
name = "regex"
version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "rustc-hash"
version = "1.1.0"
@ -562,6 +707,12 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "shlex"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380"
[[package]]
name = "syn"
version = "2.0.40"
@ -605,6 +756,28 @@ version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.45.0"
@ -670,3 +843,23 @@ name = "windows_x86_64_msvc"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0"
[[package]]
name = "z3"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a7ff5718c079e7b813378d67a5bed32ccc2086f151d6185074a7e24f4a565e8"
dependencies = [
"log",
"z3-sys",
]
[[package]]
name = "z3-sys"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7cf70fdbc0de3f42b404f49b0d4686a82562254ea29ff0a155eef2f5430f4b0"
dependencies = [
"bindgen",
"cmake",
]

13
day-24/Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "day-24"
version = "0.0.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
itertools.workspace = true
z3 = { version = "0.12.1", features = ["static-link-z3"] }
[dev-dependencies]
indoc.workspace = true

300
day-24/src/bin/input.txt Normal file
View File

@ -0,0 +1,300 @@
184964585341884, 113631924395348, 401845630841620 @ 61, 469, -390
331877282121819, 365938348079363, 314507465806130 @ 46, -106, 24
263775277465044, 418701236136888, 52607746821705 @ 105, -170, 307
208356602267478, 274354112299498, 294235176347885 @ 46, 8, -49
215069209934964, 263266623283188, 304961521854129 @ -28, 48, -120
218821711924084, 386143011380798, 415191763621655 @ 101, -181, -189
451773868335257, 516705765114825, 478982876413032 @ -54, -246, -128
160266893683207, 318090322227659, 233527333051300 @ -106, -238, 26
133382790359204, 248866187487128, 271295536804269 @ 117, 233, -203
126081027693345, 357221115260331, 166079877492738 @ 180, -398, 420
412552579106310, 238682026521804, 213182511307125 @ -130, 41, 131
213009943077568, 188071566233378, 189159097538284 @ 81, 163, 180
366495890008028, 365288029612049, 443509928183922 @ -67, -128, -176
384782259204993, 344542120191675, 467426129680761 @ -180, -118, -287
348749863928109, 148865902367784, 367750792926300 @ -58, 169, -84
211395081228450, 222394239720422, 270482520554253 @ -182, 272, -101
343177001344294, 240270201959713, 339571651319800 @ -33, 38, -36
340020595292155, 558364836389057, 259798360146916 @ -84, -446, 60
252064135849544, 235489727727348, 246970174964945 @ -138, 129, 45
140358912743560, 373357926049956, 320906099428877 @ 158, -339, -252
188443931780591, 269549626545306, 232934981929617 @ -36, 51, 73
154926237032900, 289502736377988, 292505912751361 @ 93, -27, -163
301528564942018, 447808448611077, 300306817931185 @ 83, -186, 41
158273993341950, 397498609178670, 156936237513441 @ 64, -488, 393
389360056957012, 271466577261286, 310836940693015 @ -19, -8, 26
523606165049724, 311160441358758, 382715523758715 @ -279, -56, -96
124541310468344, 263384391070213, 181388147891580 @ 9, 406, 772
367981615695219, 124849946602263, 493393895044755 @ 20, 136, -149
282069200225727, 366811411519455, 433506003940557 @ 104, -104, -91
475019452646862, 292986287630220, 339967775498451 @ -144, -31, -16
310337090337168, 149828492293020, 146414880235513 @ -44, 195, 239
121070348836600, 314126009952213, 212886134337194 @ 161, -252, 192
250324788521500, 474348549156984, 369234741457179 @ -87, -501, -260
189260213696946, 274226723382576, 194804430809577 @ -136, 51, 253
245010531114496, 350352263722748, 310270903562697 @ -217, -247, -203
364526329577550, 287576791669506, 107988379663308 @ 11, -25, 238
169589466467844, 234818423458884, 219295838817985 @ 52, 174, 126
308250314562334, 287517226796403, 337801210423020 @ -25, -24, -56
206414999340108, 257481830752005, 293394992457417 @ 29, 54, -63
195321122092581, 371225304242562, 375806132972700 @ -6, -293, -384
131305889163174, 215343095136510, 256785201098943 @ 72, 636, -202
160393711161926, 179942642401256, 197178982114491 @ 51, 449, 223
382386631217010, 192405763860352, 392632986263623 @ -56, 91, -88
342050658842647, 386589691572720, 342014839102920 @ -214, -231, -134
129256076607662, 256707215664942, 258772984880047 @ -84, 540, -538
276468059357704, 264288879976749, 262679239111570 @ 57, 6, 66
142942471076538, 304200425647776, 233448578362839 @ 23, -135, 27
471079154426244, 315697987066868, 113860123070225 @ -83, -53, 227
289498131207561, 376422088031079, 286209846076920 @ -96, -206, -14
474902657117445, 238766305641606, 404357015017095 @ -142, 31, -89
336918796133476, 317679284529444, 319274063639601 @ -15, -63, -5
204667760809768, 289046375821304, 242561451830337 @ 66, -26, 73
313666343836136, 437408999642022, 511619285956785 @ 23, -210, -239
150214488661956, 292444527376524, 227847189772593 @ 21, -45, 77
266399759675388, 332797003864548, 186020731120257 @ 58, -87, 169
334319890566109, 284268507639378, 250316774628295 @ 18, -21, 87
119671750003904, 305649874601848, 225576517701325 @ 114, -260, 50
152092651117364, 264317961468208, 223507251703065 @ 185, 26, 115
191994714264194, 252105280340738, 280744192450255 @ -121, 151, -165
176296292857804, 487497720699528, 397506034018065 @ 65, -645, -431
351126679842792, 394834346925389, 445968133234078 @ -71, -178, -202
400751927677326, 167249697187992, 278100344246973 @ -120, 139, 43
143570208306518, 317610309210600, 337650914079437 @ -16, -261, -853
174533080468696, 263082050627488, 251092775094081 @ -36, 98, -23
326143431565034, 216365643581054, 307763244395741 @ 12, 62, 15
205666491035516, 190316653217512, 163166122385917 @ 123, 130, 212
163214020667229, 323481000284694, 256139775138660 @ 22, -185, -44
147341160785210, 300395103269254, 238510643415807 @ -70, -124, -38
255079503729126, 353635554030308, 345715139531529 @ 94, -107, -35
378641483407764, 150274899984308, 314020694220561 @ -53, 143, 7
183094666413783, 290647854892384, 249570387598004 @ 16, -31, 20
330134494207119, 285278759028318, 313583646802245 @ -38, -21, -11
243555407077101, 335932246351317, 202166517244020 @ -52, -140, 166
114882672025599, 270455005889607, 183862081867974 @ 222, 134, 432
154605415821338, 271346043866368, 267304878177821 @ -54, 103, -213
324633800141281, 242122975432271, 533550209968844 @ -184, 74, -546
167352109980324, 236593843351108, 267982907220705 @ 34, 191, -74
180693911601672, 312760860036996, 223018298293623 @ -121, -155, 108
221423333710774, 484993977058078, 222842149398260 @ -85, -653, 114
264160477263684, 380868412808772, 338968380487617 @ -93, -244, -160
145268355570996, 291229240743036, 274904729632329 @ -129, -46, -476
169632434434110, 295479004776492, 147446857227831 @ 154, -39, 268
382309611883178, 282293948784995, 193880648335531 @ 11, -20, 147
359338860474380, 290837646894610, 486303337917283 @ -99, -29, -277
357337175171495, 322114305594295, 117253608569995 @ -36, -68, 251
264708880893114, 209357236371423, 248360762395725 @ 119, 54, 93
396127672485124, 151022091606442, 383415863964374 @ -43, 127, -60
341024766384930, 265816743761253, 301188520006404 @ -165, 18, -32
213611994410577, 224405458386627, 228375189930615 @ -132, 226, 91
284764305813837, 3708512638212, 219167633527527 @ 40, 357, 123
282937888234536, 353040703673328, 266135953278801 @ 16, -122, 53
209426621486360, 330872583534712, 257956826972125 @ -21, -149, 11
290948208762924, 281895547819093, 301650329177740 @ -131, -10, -60
323761626400404, 235365188530044, 319617254078865 @ -93, 66, -49
167572968083239, 316088343294363, 268864712317865 @ 110, -102, -15
387204653812714, 487381360577728, 324992146960277 @ -33, -247, 5
142729798922121, 258427229345442, 247597754417538 @ 36, 191, -68
124797856428873, 257965627877194, 236424699359902 @ 76, 359, -72
239391417673888, 301716067543826, 356668242183610 @ 41, -49, -124
395773779995976, 448067203493316, 209920009315238 @ -71, -219, 134
121331024690484, 286911668109780, 249157896059793 @ 207, -13, -33
206285273962778, 250041076282880, 314842937600659 @ 14, 79, -132
159325907176100, 253605987772844, 169044230064321 @ -31, 190, 433
148479399713988, 409813885471620, 217144759805697 @ 60, -678, 140
142279848269394, 95052378748863, 144870364700205 @ 175, 558, 349
119950770113517, 217296242754485, 218451366678253 @ 256, 104, 125
118958595434864, 241026171341548, 221168221500735 @ 215, 257, 118
206976226804044, 271068721732128, 207366506643885 @ 47, 16, 152
197588878150347, 355192053942832, 336500144328588 @ 76, -175, -140
493964085515464, 227888094794758, 464133357817430 @ -111, 35, -124
442585900077221, 515365501298755, 429850071290732 @ -124, -298, -130
100056309704324, 212907123852228, 159838655014145 @ 306, 240, 333
338667740833092, 275909107984856, 334202923452137 @ -11, -10, -21
283199190888372, 389769159819432, 296070207185121 @ 73, -144, 33
153543161284359, 333764600720223, 294690056311095 @ -122, -418, -533
465000253913832, 306899056893324, 447774774059725 @ -92, -45, -114
227938543212651, 368314267799073, 281398691277951 @ -34, -232, -37
292385579024940, 126834194582382, 159003345012045 @ -111, 316, 251
121099499189976, 279592226552448, 207165063992157 @ 78, 128, 332
450023615098580, 286946766813780, 166980784261137 @ -124, -24, 184
356414060795058, 198120176266446, 384771763269009 @ 11, 71, -55
284292253406481, 227464525681545, 218956468104123 @ 70, 46, 123
201063341146812, 260265689958684, 333871941882129 @ -21, 67, -243
320339817058074, 361660739342628, 304539823555899 @ 42, -107, 28
144796336397908, 226569990301598, 320812940992781 @ 141, 208, -253
152390619422409, 288059623719858, 230613622450602 @ -28, -17, 52
197784871445154, 238161325846838, 289027877182695 @ -80, 178, -152
392528959104867, 318163729609803, 145318677185877 @ -70, -62, 213
124975751600790, 312460277576658, 216888753733313 @ 136, -222, 153
177257709183444, 106276547659548, 243387213634725 @ 177, 239, 88
400945813502889, 376937487918098, 410322298450359 @ -158, -157, -161
154563776058084, 313955256047268, 101714259310785 @ 124, -108, 515
285525237519732, 173792333943060, 166896887341065 @ -69, 199, 226
155967420648823, 126331065637260, 68467182976326 @ 186, 285, 412
178480150935156, 305375446020036, 207617847903537 @ -94, -111, 190
449784431920584, 418774010108808, 304848205436757 @ -238, -222, -6
208427726338586, 432348123055257, 301421047281463 @ 111, -264, -13
307991611925752, 285083195523900, 272954045216213 @ 6, -21, 50
284259394981781, 342378006680820, 390664826708194 @ -202, -171, -342
390534769909485, 268664640164971, 452127970610856 @ -224, 10, -290
248566771695947, 256770896367571, 286737407017328 @ 50, 26, 14
324797249726889, 88383704996928, 230129142964410 @ -20, 249, 108
183588717993153, 397995874846347, 129468660629964 @ -62, -516, 532
314767748388235, 228952382912349, 359987065987427 @ -40, 66, -93
379035713057055, 79665185256357, 221669853085938 @ 10, 180, 120
163563614880774, 292928194197174, 190207631161185 @ 132, -36, 201
149247398649436, 283240134840086, 236477454257889 @ 29, 11, 25
322187014104468, 288512869105974, 313703668678821 @ -155, -25, -67
436194401455500, 119522660322996, 560616297219489 @ -47, 141, -215
318244698737196, 312171515043564, 284274975558057 @ -10, -58, 34
218549125817763, 21096654315252, 328562644317159 @ 34, 565, -117
225868642074420, 249663169913772, 168324511194645 @ -71, 91, 276
304680377888406, 317144686205670, 181770012301071 @ -142, -86, 204
243246025938711, 240235031322548, 271771389104524 @ 58, 53, 38
447650797024081, 328890876224120, 205438000168954 @ -102, -71, 138
283840453432166, 295632510005332, 415276457777677 @ 48, -35, -133
387963720893616, 279041959463070, 360450163881591 @ -17, -16, -26
321941295718884, 277044742323104, 301633106466251 @ 37, -13, 30
192366160775836, 286062853343460, 253335033937521 @ -16, -15, 7
185918883086276, 295863701981400, 234589688812217 @ 21, -48, 75
270953466705778, 288773688022130, 289186690560157 @ 54, -26, 27
278383849769784, 138712884422556, 193553393941045 @ -68, 279, 176
122893514160444, 271597411711088, 278001576812955 @ 157, 121, -353
176345811927809, 315369910816718, 271564945866580 @ 30, -121, -64
227162627755431, 238781038353393, 290684812059591 @ -86, 128, -93
256026292948414, 312953127314295, 245843602041094 @ 107, -54, 92
329787773506278, 132539235844270, 355790284641845 @ 64, 124, -9
153055563375504, 247390665548828, 278175071120065 @ 190, 55, 9
205338294571383, 206636011368930, 276185393826915 @ 50, 167, -9
166139619393314, 245767184801915, 298224859225559 @ 207, 26, 27
184578922721808, 378808795189944, 299100656228115 @ -165, -545, -334
232276788838913, 249534637832998, 277338175773309 @ -64, 83, -35
140281527306384, 277203155310618, 215785023894705 @ 15, 74, 161
125895940497717, 289148791789134, 219122385224471 @ -20, -21, 147
222155415164452, 279343831751648, 313610122440516 @ 53, -7, -62
268297572830532, 392785623334524, 149024465446101 @ 85, -151, 207
225844552430008, 297000749298024, 338125014190069 @ 89, -39, -67
195111276358279, 291442510023553, 250306970834570 @ -36, -34, 14
302574497621359, 280161527590225, 200990442398425 @ -118, -8, 161
351074137433244, 2931869440578, 47966860472955 @ 17, 280, 306
255674684941908, 203779546926636, 357692511345117 @ 33, 115, -106
372818488317164, 160016949117932, 387528673761549 @ -13, 115, -62
181217048415774, 222596593650396, 287832070670676 @ 7, 221, -128
402092593050376, 247922330486591, 225079592544760 @ -55, 20, 116
281560368230596, 360962436450308, 263111613976001 @ -135, -197, 20
301052051780046, 299333163338733, 213447165338292 @ -17, -42, 132
132876663294574, 295057614422228, 237419973493015 @ 30, -83, -48
121823183063444, 86262115700488, 280558643835505 @ 233, 638, -75
223674498499072, 406097043832668, 238145291227707 @ 99, -207, 94
525570159274532, 278366128191076, 460521552212225 @ -210, -14, -159
351050888894319, 415122842777688, 283466198309355 @ 22, -159, 55
200946715416074, 197528936776304, 347269427678057 @ 122, 127, -91
319677905840812, 504595133263820, 440012488189109 @ -169, -481, -342
327181907573547, 317772274391438, 382923293306708 @ -110, -77, -166
297042895570646, 164164378608658, 418558815271605 @ -9, 163, -179
183538004584866, 302454435799911, 237854303358288 @ -77, -88, 40
219347195013932, 298489865843774, 290208712279501 @ -7, -50, -57
119237614879054, 285841411143288, 225293823740125 @ 99, 33, 45
174842456729360, 251300903172920, 269898970570373 @ -24, 146, -102
438201419228916, 357562015210260, 331906889354565 @ -227, -131, -49
249738204491524, 223870137276308, 433331009506295 @ 53, 77, -216
127451203617054, 264642017340693, 197984420201280 @ 155, 132, 266
248527785189316, 313786516399748, 302527174897153 @ -127, -97, -115
173612714838078, 376895740825026, 253479808751585 @ 118, -240, 41
389168192299914, 285087759822163, 293944755936200 @ -41, -22, 38
184231782453369, 258394556934738, 122067145643205 @ -40, 103, 533
381786860663880, 334750360792701, 198513690608688 @ -7, -74, 144
368289321181923, 107662016373516, 44745013800831 @ 14, 157, 299
328803870456894, 244787304136191, 266001372171609 @ -73, 44, 49
144760749843651, 297182629305831, 281969388648186 @ -12, -88, -366
170175091313724, 301514452292172, 223963719056889 @ -78, -96, 102
270855370146153, 550201655064669, 370074763835739 @ -34, -526, -165
336004962312988, 311907192968888, 298623654045837 @ 23, -52, 34
316492880180318, 438684089858526, 345894812228969 @ 51, -189, -15
138999631921164, 278049877562548, 187915907408845 @ 31, 65, 384
286261975493264, 403076292131350, 399910793346739 @ 17, -193, -141
274275045092004, 104939696439390, 169849465575846 @ 117, 151, 170
274478365375402, 314171451530358, 228056759655216 @ 75, -57, 112
169490235293208, 205912171529286, 228989947647291 @ 35, 304, 88
301313091597347, 342782522756070, 503200466811455 @ 38, -93, -229
343523942106892, 326065422953079, 269406393876293 @ -51, -78, 53
228121890663791, 97824178380111, 280740814503983 @ -6, 426, -21
399208991276364, 44590477071108, 109425160674297 @ -8, 213, 230
173169125181118, 337353723455090, 232561653855961 @ -6, -236, 69
414653839181904, 469623461355649, 343167407442489 @ -143, -274, -47
457692755849724, 221158091758368, 271534936104111 @ -183, 63, 54
243667545719964, 246118004141028, 297150278264145 @ 40, 49, -13
153547449132644, 285267883335813, 220938468645650 @ 117, -12, 120
227522832774198, 66854022806478, 346422580613412 @ 79, 343, -88
123318720653261, 306766121089230, 226874676161404 @ 116, -213, 54
306964005010657, 470477903124681, 219775487363779 @ -174, -438, 123
241525309223094, 272735746453158, 241039544625965 @ -128, 24, 59
111512132847122, 301536460981324, 240370970523481 @ 228, -215, -187
251572324598542, 396565645723108, 292254465734054 @ 63, -187, 14
253994448218356, 367797757215040, 45614410626669 @ -15, -184, 472
123564561345906, 230822207724990, 208123245779091 @ 94, 680, 272
289224141978585, 148002059542635, 169201353533013 @ 38, 160, 189
364194300019070, 191175059612464, 378147085013607 @ -30, 91, -68
412814215902576, 383502681688218, 313443187899603 @ -225, -182, -32
405842438080899, 192594303533463, 261104882296785 @ -76, 88, 73
352645969593595, 319085643016553, 328845060816257 @ -12, -62, -7
403071969419431, 366884693332908, 316093892020573 @ -180, -147, -27
270992879754009, 265261663622028, 264088067130600 @ -206, 45, -8
280096576419597, 179726822999808, 327295603819737 @ 58, 113, -15
331472103984276, 211347939340308, 236287104517041 @ -37, 83, 99
127956705836266, 51650904405709, 12175846867459 @ 243, 386, 483
441415784591754, 177047637257208, 243147164933661 @ -108, 103, 95
111872617053224, 254008859284621, 259122415851085 @ 257, 176, -99
163731108603690, 172516776933792, 186815379063387 @ 30, 495, 272
285852984067832, 321064421299557, 188179628740934 @ -111, -96, 192
219899708094225, 297255743445807, 317866926036774 @ 90, -40, -42
294972746749235, 191976174540635, 529584213819733 @ -54, 146, -427
131745985334201, 74334783621777, 28052621855818 @ 248, 240, 360
290285085394220, 281149753631034, 245715093350367 @ 81, -18, 94
297407296572712, 247050721543949, 242282643232506 @ 41, 26, 94
375830447894126, 371394423241832, 315615654345239 @ -30, -121, 12
212427764005155, 408482119743801, 147775784819007 @ 40, -298, 287
216000528893572, 328639043848580, 301374779267601 @ -75, -155, -143
299417908940219, 241010617847288, 280017186759155 @ -180, 89, -21
239630632178868, 284976703659732, 284774941951465 @ -71, -15, -49
428791978611744, 203617956204588, 361870543279230 @ -111, 77, -50
172359881927082, 321669655881500, 364708002016537 @ -89, -211, -703
298986261980274, 129020926627515, 461071423318068 @ -33, 234, -270
447200382093752, 376250023707103, 465589662274065 @ -55, -112, -119
141986993932810, 140699264280756, 298973762002785 @ 174, 429, -119
180255631633068, 285816585183956, 273644568523715 @ -35, -11, -109
325782178400430, 135704255162880, 24135863556867 @ 48, 135, 328
349016188316904, 332077594949154, 314135725885326 @ 17, -73, 20
205153853136414, 288581039522874, 157980758961753 @ 172, -26, 189
210775702318890, 455042687992626, 404004795675351 @ 24, -436, -332
279951860197256, 255404000916120, 332153597572121 @ -40, 36, -85
200996337792004, 187369690398084, 458966585729281 @ 92, 177, -355
136307446534557, 272199874227918, 279238692674742 @ 164, 43, -116
550909316773830, 337117114657827, 232793143494562 @ -197, -78, 108
382310025001419, 270517187946663, 169123942224480 @ -26, -6, 178
275388687381974, 226152976227718, 269032325587893 @ -13, 83, 37
209673803260266, 266275142003532, 266466122903571 @ -37, 45, -21
164934656833122, 282006968807862, 229287635038741 @ 28, 6, 83
379580768562877, 317176724665073, 130518011831571 @ -66, -62, 235
290459365430094, 342765310047838, 303646666874155 @ -17, -113, -13
163447265626818, 443656097026193, 222303585604982 @ 43, -682, 114
405313858272379, 204010646455121, 257202382023097 @ -178, 104, 65
422659058170132, 401746798813948, 460377392740591 @ -115, -167, -178
133444165348728, 201763049380494, 288604925265459 @ 239, 106, 18
106473419377620, 50451563918772, 246653752724433 @ 280, 350, 80
174121409676891, 270674148087029, 278685236891477 @ 64, 34, -67
171823955955694, 316694853209238, 231791964383255 @ 32, -132, 78
260440517718208, 293039127874936, 237454004720008 @ 105, -31, 102
477479812815169, 295719226979516, 484856995674445 @ -198, -35, -219
210885150412920, 265959892267716, 277060875790365 @ 68, 21, 6
247691524224231, 206017588288228, 354754164228682 @ 10, 133, -136
349531458052309, 279152703128938, 304491414426810 @ 44, -17, 40
258699283396533, 244044053202236, 479977269589363 @ -14, 61, -381
368419720280954, 213077580485903, 375491525877885 @ 15, 50, -35
368359482108805, 276938463575491, 319237362482943 @ 8, -14, 19
231773269756038, 323018130216816, 296319685745647 @ 34, -93, -28
387341264732292, 289502736377988, 203220796273077 @ 5, -27, 138
236067436014778, 62693609266136, 349240847094177 @ 134, 227, -23
424411221646508, 230847941181580, 269681048557249 @ -84, 40, 65
157391625464718, 273639971939388, 153080768601069 @ -32, 73, 547

164
day-24/src/bin/part1.rs Normal file
View File

@ -0,0 +1,164 @@
use itertools::Itertools;
fn main() {
println!(
"{}",
part1(
include_str!("./input.txt"),
200_000_000_000_000,
400_000_000_000_000
)
);
}
fn part1(input: &str, min: i128, max: i128) -> usize {
let hailstones = input.lines().map(Hailstone::from).collect::<Vec<_>>();
let combinations = hailstones
.into_iter()
.combinations(2)
.map(|v| (v[0], v[1]))
.collect::<Vec<_>>();
let intersections = combinations
.into_iter()
.filter_map(|(a, b)| {
if let Some((x, y)) = a.intersection(&b) {
// intersection is in past
if i128::signum(x - a.x) != i128::signum(a.dx)
|| i128::signum(x - b.x) != i128::signum(b.dx)
|| i128::signum(y - a.y) != i128::signum(a.dy)
|| i128::signum(y - b.y) != i128::signum(b.dy)
{
None
} else if x >= min && x <= max && y >= min && y <= max {
// intersection is in the specified area
Some((x, y))
} else {
// intersection is not in the specified area
None
}
} else {
// no intersection
None
}
})
.collect::<Vec<_>>();
intersections.len()
}
#[derive(Debug, PartialEq, Clone, Copy)]
struct Hailstone {
x: i128,
y: i128,
z: i128,
dx: i128,
dy: i128,
dz: i128,
}
impl Hailstone {
fn new(x: i128, y: i128, z: i128, dx: i128, dy: i128, dz: i128) -> Self {
Self {
x,
y,
z,
dx,
dy,
dz,
}
}
fn to_line(self) -> (i128, i128, i128) {
let a = self.dy;
let b = -self.dx;
let c = self.dx * self.y - self.dy * self.x;
(a, b, c)
}
fn intersection(&self, other: &Self) -> Option<(i128, i128)> {
let (a1, b1, c1) = self.to_line();
let (a2, b2, c2) = other.to_line();
if (a1 * b2 - a2 * b1) == 0 {
return None;
}
let x = (b1 * c2 - b2 * c1) / (a1 * b2 - a2 * b1);
let y = (c1 * a2 - c2 * a1) / (a1 * b2 - a2 * b1);
Some((x, y))
}
}
impl From<&str> for Hailstone {
fn from(value: &str) -> Self {
let (pos, vel) = value.split_once(" @ ").expect("no @ symbol");
let mut pos = pos.split(", ");
let mut vel = vel.split(", ");
let x = pos
.next()
.expect("no x")
.trim()
.parse::<i128>()
.expect("x not a number");
let y = pos
.next()
.expect("no y")
.trim()
.parse::<i128>()
.expect("y not a number");
let z = pos
.next()
.expect("no z")
.trim()
.parse::<i128>()
.expect("z not a number");
let dx = vel
.next()
.expect("no dx")
.trim()
.parse::<i128>()
.expect("dx not a number");
let dy = vel
.next()
.expect("no dy")
.trim()
.parse::<i128>()
.expect("dy not a number");
let dz = vel
.next()
.expect("no dz")
.trim()
.parse::<i128>()
.expect("dz not a number");
Hailstone::new(x, y, z, dx, dy, dz)
}
}
#[cfg(test)]
mod tests {
use super::*;
use indoc::indoc;
#[test]
fn test_part1() {
assert_eq!(
part1(
indoc!(
"
19, 13, 30 @ -2, 1, -2
18, 19, 22 @ -1, -1, -2
20, 25, 34 @ -2, -2, -4
12, 31, 28 @ -1, -2, -1
20, 19, 15 @ 1, -5, -3
"
),
7,
27
),
2
);
}
}

141
day-24/src/bin/part2.rs Normal file
View File

@ -0,0 +1,141 @@
use z3::{
ast::{Ast, Int},
Config, Context, SatResult, Solver,
};
fn main() {
println!("{}", part2(include_str!("./input.txt"),));
}
fn part2(input: &str) -> i64 {
let hailstones = input.lines().map(Hailstone::from).collect::<Vec<_>>();
let cfg = Config::new();
let context = Context::new(&cfg);
let solver = Solver::new(&context);
let x = Int::new_const(&context, "x");
let y = Int::new_const(&context, "y");
let z = Int::new_const(&context, "z");
let dx = Int::new_const(&context, "dx");
let dy = Int::new_const(&context, "dy");
let dz = Int::new_const(&context, "dz");
// add assertions for every hailstone
for (i, hailstone) in hailstones.iter().take(3).enumerate() {
let a = Int::from_i64(&context, hailstone.x.try_into().unwrap());
let da = Int::from_i64(&context, hailstone.dx.try_into().unwrap());
let b = Int::from_i64(&context, hailstone.y.try_into().unwrap());
let db = Int::from_i64(&context, hailstone.dy.try_into().unwrap());
let c = Int::from_i64(&context, hailstone.z.try_into().unwrap());
let dc = Int::from_i64(&context, hailstone.dz.try_into().unwrap());
// add assertions that the hailstone is at the given position at time t
let t = Int::new_const(&context, "t".to_string() + &i.to_string());
solver.assert(&t.gt(&z3::ast::Int::from_i64(&context, 0)));
solver.assert(&(x.clone() + dx.clone() * t.clone())._eq(&(a + da * t.clone())));
solver.assert(&(y.clone() + dy.clone() * t.clone())._eq(&(b + db * t.clone())));
solver.assert(&(z.clone() + dz.clone() * t.clone())._eq(&(c + dc * t.clone())));
}
if solver.check() == SatResult::Sat {
if let Some(m) = solver.get_model() {
// get the sum of the x,y,z coordinates of the starting position
m.eval(&(x + y + z), true).unwrap().as_i64().unwrap()
} else {
panic!("Failed to solve!");
}
} else {
panic!("Failed to check")
}
}
#[derive(Debug, PartialEq, Clone, Copy)]
struct Hailstone {
x: i128,
y: i128,
z: i128,
dx: i128,
dy: i128,
dz: i128,
}
impl Hailstone {
fn new(x: i128, y: i128, z: i128, dx: i128, dy: i128, dz: i128) -> Self {
Self {
x,
y,
z,
dx,
dy,
dz,
}
}
}
impl From<&str> for Hailstone {
fn from(value: &str) -> Self {
let (pos, vel) = value.split_once(" @ ").expect("no @ symbol");
let mut pos = pos.split(", ");
let mut vel = vel.split(", ");
let x = pos
.next()
.expect("no x")
.trim()
.parse::<i128>()
.expect("x not a number");
let y = pos
.next()
.expect("no y")
.trim()
.parse::<i128>()
.expect("y not a number");
let z = pos
.next()
.expect("no z")
.trim()
.parse::<i128>()
.expect("z not a number");
let dx = vel
.next()
.expect("no dx")
.trim()
.parse::<i128>()
.expect("dx not a number");
let dy = vel
.next()
.expect("no dy")
.trim()
.parse::<i128>()
.expect("dy not a number");
let dz = vel
.next()
.expect("no dz")
.trim()
.parse::<i128>()
.expect("dz not a number");
Hailstone::new(x, y, z, dx, dy, dz)
}
}
#[cfg(test)]
mod tests {
use super::*;
use indoc::indoc;
#[test]
fn test_part2() {
assert_eq!(
part2(indoc!(
"
19, 13, 30 @ -2, 1, -2
18, 19, 22 @ -1, -1, -2
20, 25, 34 @ -2, -2, -4
12, 31, 28 @ -1, -2, -1
20, 19, 15 @ 1, -5, -3
"
)),
47
);
}
}