From 1cfc6e940e5e14061fb605c569f457a1c7b13a5c Mon Sep 17 00:00:00 2001 From: Louis Vallat Date: Sun, 9 Jan 2022 17:35:58 +0100 Subject: [PATCH] Added day 22 code for part 1 and 2 Signed-off-by: Louis Vallat --- .gitlab-ci.yml | 5 + day22/Cargo.toml | 8 + day22/input | 420 ++++++++++++++++++++++++++++++++++++++++++++++ day22/src/main.rs | 78 +++++++++ 4 files changed, 511 insertions(+) create mode 100644 day22/Cargo.toml create mode 100644 day22/input create mode 100644 day22/src/main.rs diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cdc0b41..d3d4b22 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -108,3 +108,8 @@ day-21: stage: build script: - cd day21; cargo run --release ./input + +day-22: + stage: build + script: + - cd day22; cargo run --release ./input diff --git a/day22/Cargo.toml b/day22/Cargo.toml new file mode 100644 index 0000000..06b2e41 --- /dev/null +++ b/day22/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day22" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day22/input b/day22/input new file mode 100644 index 0000000..fa4849e --- /dev/null +++ b/day22/input @@ -0,0 +1,420 @@ +on x=-3..43,y=-22..22,z=-15..34 +on x=-9..42,y=-40..12,z=-30..19 +on x=-5..46,y=-9..38,z=-31..21 +on x=-27..25,y=-30..22,z=-9..42 +on x=-25..27,y=-43..3,z=-22..31 +on x=-39..9,y=-45..8,z=-17..29 +on x=-10..36,y=-2..44,z=-9..35 +on x=-45..4,y=-41..5,z=-3..49 +on x=-24..26,y=-34..12,z=-6..44 +on x=-35..17,y=-36..11,z=-42..10 +off x=5..19,y=6..21,z=-21..-3 +on x=-45..1,y=-40..11,z=-31..20 +off x=16..30,y=-16..-4,z=21..33 +on x=-38..7,y=-30..15,z=-46..3 +off x=36..48,y=-39..-22,z=-47..-34 +on x=-23..22,y=-22..29,z=-27..24 +off x=-39..-29,y=-47..-34,z=-13..-1 +on x=-18..28,y=-3..44,z=-8..38 +off x=-38..-24,y=-48..-39,z=14..28 +on x=-32..21,y=-36..9,z=-38..16 +on x=-40114..-18236,y=44675..56621,z=-62989..-35133 +on x=-47063..-26565,y=34232..54684,z=-70517..-34320 +on x=-56151..-43929,y=48563..58124,z=36908..41850 +on x=-77794..-42408,y=-69580..-49841,z=1311..11416 +on x=-55821..-38492,y=49499..69556,z=17469..29122 +on x=63143..77824,y=-46210..-33353,z=9878..30392 +on x=39342..53117,y=-50110..-40820,z=-62170..-40938 +on x=-73484..-48152,y=-65736..-42700,z=-18262..-13156 +on x=37366..54383,y=19405..43152,z=47195..68515 +on x=-58204..-27378,y=-43155..-25521,z=-62841..-54391 +on x=-74420..-47151,y=37359..62719,z=-25475..-3046 +on x=-45598..-17555,y=-26089..-5704,z=-70074..-64019 +on x=-60861..-28014,y=-73554..-54991,z=-31524..-9823 +on x=-24856..-677,y=-30123..-15884,z=63853..91090 +on x=-70612..-48898,y=-58794..-27838,z=31988..51431 +on x=-39272..-20927,y=-20393..-13252,z=-85528..-72953 +on x=-25668..-4103,y=-18215..-1734,z=-91736..-74972 +on x=-58040..-34891,y=-68034..-41896,z=22484..48325 +on x=-83077..-63382,y=17005..35646,z=-28949..3129 +on x=-75533..-63223,y=-47132..-32953,z=18181..35552 +on x=-12005..9792,y=19338..25243,z=-92843..-67825 +on x=56387..84965,y=-35767..-23866,z=-7517..29845 +on x=41294..42717,y=62107..77449,z=-6076..18165 +on x=68909..88527,y=12129..33752,z=-14973..1514 +on x=70106..89265,y=-44616..-27968,z=-11036..-1697 +on x=23822..38056,y=40195..55684,z=-65662..-33478 +on x=57501..81938,y=-18907..-5701,z=5821..28274 +on x=-25260..-17668,y=-48592..-46210,z=-69961..-51155 +on x=-40924..-23866,y=59810..71028,z=1641..21630 +on x=34547..43160,y=-74622..-56131,z=-36907..-17782 +on x=-21350..276,y=14485..29856,z=-77890..-58230 +on x=-75736..-39641,y=-2847..32980,z=-57010..-42061 +on x=-25041..-10364,y=-77922..-57550,z=18525..31966 +on x=-11867..7378,y=17836..49462,z=-90609..-54269 +on x=-73484..-39680,y=-39303..-21793,z=31847..54382 +on x=-16778..-10708,y=-66044..-52096,z=-44957..-39847 +on x=-6352..5197,y=-48264..-42773,z=-69346..-65566 +on x=-70366..-51952,y=-45555..-37939,z=-60527..-28534 +on x=21301..42400,y=-20291..4389,z=66067..89444 +on x=45669..82341,y=-56204..-41535,z=-21028..-14812 +on x=-12687..6121,y=-75650..-50731,z=40334..49677 +on x=62454..72648,y=-56206..-23070,z=-36904..-4173 +on x=-14045..15260,y=74607..78556,z=3616..39536 +on x=3027..21243,y=58402..67345,z=32845..51345 +on x=36180..53611,y=3808..31420,z=-75144..-41742 +on x=62333..81915,y=22152..45857,z=-19764..3026 +on x=16840..31474,y=51862..63491,z=41052..56975 +on x=34291..46927,y=-64612..-48527,z=-43496..-32299 +on x=-15540..7128,y=28606..58975,z=61419..80612 +on x=-41973..-18320,y=-77313..-61240,z=15692..47003 +on x=-53801..-30362,y=39541..57030,z=-60083..-35312 +on x=68377..77233,y=20169..50880,z=-27441..-20458 +on x=-48517..-32670,y=27681..29643,z=43402..61515 +on x=-27916..-4199,y=26661..49908,z=52384..82183 +on x=49989..60432,y=-53633..-30668,z=-41268..-22103 +on x=27313..55472,y=56100..75902,z=19430..45734 +on x=-6356..15818,y=-68706..-57263,z=36276..50109 +on x=-86603..-47010,y=-10414..18891,z=-47053..-29175 +on x=-55452..-23629,y=-70516..-54860,z=1793..24906 +on x=50625..72911,y=-12487..-2707,z=-71603..-40651 +on x=39137..55253,y=19930..23696,z=45922..65211 +on x=-9884..16104,y=-37553..-13090,z=-80288..-61586 +on x=15247..32364,y=58299..77121,z=12794..38315 +on x=-66919..-64795,y=27710..52508,z=-5853..20204 +on x=55575..68137,y=-44413..-25743,z=-53783..-25185 +on x=-28440..950,y=-58170..-37455,z=42708..66553 +on x=-62883..-47411,y=41864..58827,z=-14578..6700 +on x=-77452..-58620,y=-27879..-12335,z=28389..50389 +on x=16287..41670,y=-20720..-3731,z=58921..81851 +on x=-39948..-11682,y=62858..90995,z=-33475..-6506 +on x=-56395..-35664,y=27367..43557,z=-61199..-44459 +on x=-52933..-35603,y=-11996..5380,z=-73054..-57610 +on x=-13683..-926,y=-79150..-68241,z=13231..23670 +on x=-2283..11495,y=-47635..-35881,z=65101..72052 +on x=68775..80912,y=-16331..4168,z=9807..29318 +on x=-82722..-62858,y=28101..48460,z=-20008..-10603 +on x=2241..10548,y=76361..96934,z=-22674..-2056 +on x=54720..67218,y=-55890..-27903,z=-24408..-4708 +on x=-29992..1612,y=7330..30747,z=-89965..-57543 +on x=-26063..-23251,y=-14766..-5848,z=56200..88720 +on x=25688..45780,y=48319..64535,z=29487..42809 +on x=-10623..723,y=21921..25266,z=59433..79964 +on x=9630..28513,y=-55849..-40790,z=59817..71724 +on x=11397..35361,y=-80067..-68146,z=-50677..-32416 +on x=50224..86037,y=-20267..-15219,z=-58574..-37744 +on x=-46674..-23145,y=25112..36216,z=62513..76632 +on x=-57137..-35534,y=26364..30930,z=47504..77090 +on x=-41608..-18461,y=-42765..-18900,z=59370..81028 +on x=-79954..-65176,y=-48791..-24716,z=-18848..6604 +on x=-34241..-17350,y=-56143..-45006,z=44227..58857 +on x=-5530..18391,y=42342..80378,z=44220..64341 +on x=30538..43170,y=-48953..-12974,z=-64060..-46708 +on x=18461..24438,y=-27505..-8539,z=-92027..-61631 +on x=7320..30402,y=2065..30085,z=63426..78441 +on x=-83260..-52652,y=-51533..-38598,z=-14357..16445 +on x=-62617..-42138,y=42994..61052,z=-44270..-29008 +on x=41132..55256,y=17301..44161,z=47335..72698 +on x=-38586..-28967,y=15440..46541,z=54083..79262 +on x=4995..13584,y=-83385..-58047,z=8179..45684 +on x=-9417..16240,y=-364..29729,z=63018..79305 +on x=-12093..-408,y=69909..76313,z=17279..43292 +on x=22311..54594,y=-61374..-47340,z=38721..58551 +on x=17514..41718,y=19397..55401,z=52361..75918 +on x=-50215..-25999,y=-31832..-5898,z=-76682..-69666 +on x=-88531..-51323,y=20056..51515,z=-25044..3011 +on x=31693..42788,y=58122..73210,z=10170..25065 +on x=-53730..-34736,y=-81115..-51623,z=-18858..-15751 +on x=-8074..19450,y=56979..82537,z=21384..34758 +on x=-9034..12679,y=-88632..-76023,z=-5255..10049 +on x=-86158..-60722,y=-29277..-10774,z=-8108..5698 +on x=51152..71206,y=-60178..-30734,z=-35299..-26419 +on x=-53802..-21439,y=-81913..-62752,z=-48874..-14789 +on x=-73416..-53624,y=-34880..-13729,z=-53059..-31384 +on x=56542..90289,y=-39884..-24348,z=-33572..-10907 +on x=6068..14850,y=-24184..-14322,z=60362..84796 +on x=-65456..-62775,y=-39784..-18820,z=29946..43097 +on x=-20508..-10931,y=21416..42909,z=-92770..-64543 +on x=-78252..-45498,y=-42625..-36372,z=-37489..-22616 +on x=-57749..-32551,y=33364..54148,z=39122..59239 +on x=42486..64700,y=53697..67728,z=6295..16867 +on x=-49857..-32057,y=8944..15961,z=66948..80602 +on x=5331..24738,y=60035..81743,z=-9594..14754 +on x=-37717..-27443,y=-26773..4070,z=-92232..-59205 +on x=65813..86768,y=-40687..-15775,z=-29939..-15873 +on x=3652..16387,y=-11856..10121,z=74824..93756 +on x=-79835..-45711,y=-53126..-25959,z=-44777..-15785 +on x=29228..52342,y=-42363..-18344,z=-83369..-51120 +on x=-77918..-47225,y=-64364..-34769,z=-23149..-14421 +on x=53783..76513,y=-54253..-24629,z=-1497..25601 +on x=-4117..22514,y=-68600..-43788,z=39330..61783 +on x=56356..73410,y=29059..61247,z=23522..30743 +on x=-53663..-19354,y=9252..18430,z=55428..81436 +on x=-77447..-54826,y=-13321..11273,z=37758..54142 +on x=-33225..-11181,y=-88722..-71114,z=-17425..-1981 +on x=34224..64644,y=-2807..21051,z=-76498..-56029 +on x=-84451..-58720,y=-8709..7250,z=28349..41147 +on x=32736..58563,y=-56724..-25395,z=38575..66087 +on x=-70967..-60938,y=-14558..-1120,z=31180..57527 +on x=57978..73770,y=37063..64257,z=-6069..-220 +on x=20034..21990,y=-73943..-62810,z=16616..34791 +on x=-86125..-62182,y=-46075..-37645,z=-22559..-16252 +on x=64441..79235,y=44123..53922,z=-15543..5734 +on x=58533..82768,y=-2754..6990,z=26452..35254 +on x=34809..61230,y=-73095..-41773,z=16468..37593 +on x=27000..39601,y=-35268..-18100,z=-72724..-54029 +on x=-84967..-77387,y=-19101..-328,z=-9397..13132 +on x=-19461..8572,y=13497..45738,z=-86131..-73254 +on x=-86433..-60998,y=-56901..-29700,z=-18913..-2693 +on x=-18094..5939,y=-84753..-47530,z=33605..55713 +on x=-52752..-32887,y=-76293..-43540,z=20582..47775 +on x=38804..57591,y=28533..48342,z=23227..52409 +on x=-33372..-19183,y=60151..91114,z=-5895..13014 +on x=8399..15500,y=-46061..-19393,z=-88136..-58963 +on x=-70207..-50729,y=-27195..3250,z=49944..64484 +on x=-83322..-60694,y=-4859..1403,z=-55073..-24265 +on x=51507..67511,y=22011..37789,z=27870..58092 +on x=2315..14851,y=70777..97981,z=-4391..22434 +on x=63322..90550,y=13247..36385,z=-20220..2069 +on x=-7013..25559,y=40439..56120,z=-72584..-61716 +on x=-40699..-27549,y=4164..28551,z=53800..74409 +on x=-51494..-24862,y=-80402..-64283,z=5411..14489 +on x=-72139..-55806,y=7820..29650,z=25222..38356 +on x=12742..29953,y=56665..75761,z=-11802..13027 +on x=44039..72762,y=26530..56028,z=-42832..-10426 +on x=-37796..-27142,y=-30810..-8406,z=-70974..-66926 +on x=43717..56286,y=-26329..-1604,z=43116..72171 +on x=19995..45643,y=-81477..-55528,z=-50320..-32192 +on x=-49680..-28498,y=62214..65820,z=4605..27403 +on x=59518..86037,y=25183..54580,z=-18246..17254 +on x=-47268..-30247,y=57888..82990,z=-12900..3592 +on x=-37656..-27114,y=-74361..-62506,z=-7732..28378 +on x=5240..14690,y=72411..91552,z=-4756..19683 +on x=-13372..17477,y=34586..56772,z=-82117..-63141 +on x=-73452..-63296,y=-30094..-10448,z=22254..41160 +on x=20735..26850,y=8049..29008,z=-87764..-67519 +on x=-76309..-65638,y=1432..22127,z=24850..31614 +on x=-56517..-42480,y=-29032..-8499,z=-76299..-46050 +on x=-36653..-19363,y=11175..28415,z=66897..87189 +on x=62824..67201,y=13766..38734,z=35946..42497 +on x=-19952..-10429,y=74606..80317,z=-5904..9244 +on x=63120..89695,y=-7158..10597,z=20219..31044 +on x=-19027..-2451,y=60517..68949,z=33513..50296 +on x=-26923..178,y=60741..97131,z=-20073..-10265 +on x=-34849..-16047,y=-51895..-35335,z=-70945..-60177 +on x=-41721..-28645,y=55366..79906,z=27747..32753 +on x=-80144..-52339,y=-59029..-24157,z=-22364..-4544 +on x=-4504..10906,y=32503..70662,z=46415..77796 +on x=17183..29538,y=-18225..5416,z=66301..94405 +on x=75285..86468,y=-9980..8717,z=20674..33762 +on x=4311..28111,y=-83354..-62962,z=25674..42363 +on x=-71564..-37032,y=-3279..4967,z=45245..76671 +on x=-72811..-43922,y=36116..54013,z=-9748..23400 +on x=-1220..17639,y=21306..41079,z=63317..81228 +on x=37556..60204,y=-62343..-41856,z=10087..40031 +on x=14130..31680,y=30041..49421,z=51511..76214 +on x=-63039..-54227,y=-33537..-19281,z=34615..54260 +on x=-91314..-63751,y=-3032..6841,z=-23321..2232 +on x=-3127..19287,y=32794..47325,z=-76096..-49513 +on x=-71132..-47802,y=4545..20375,z=48670..70063 +on x=-61151..-40280,y=30652..36424,z=-62946..-37982 +on x=14119..36433,y=-95152..-75989,z=6144..26828 +on x=22834..51857,y=38327..58265,z=-65978..-49040 +off x=66244..89751,y=-24261..7534,z=15888..42514 +on x=-89728..-64157,y=-24044..4131,z=19969..28747 +off x=-35080..-19430,y=56612..91727,z=8626..23420 +off x=-47718..-31733,y=-43188..-28331,z=-67776..-45597 +on x=-74294..-57200,y=-36792..-5040,z=-54121..-41055 +off x=-24382..-20518,y=44282..50318,z=-68960..-42650 +off x=-28521..-11994,y=-8661..4706,z=-88439..-56964 +on x=52049..74171,y=-44537..-30138,z=-47237..-27418 +on x=-1707..15178,y=34753..55182,z=-74195..-46652 +off x=31059..42725,y=43145..70092,z=-38459..-30046 +on x=40446..59879,y=-59586..-36260,z=-33512..-11076 +off x=-79707..-50997,y=33225..51747,z=14860..47325 +on x=-19465..-7616,y=10119..31262,z=-87813..-71548 +on x=-83962..-64896,y=-20394..-7180,z=-61988..-32043 +off x=57772..82725,y=-8053..15222,z=973..22968 +off x=12596..37443,y=48270..79255,z=-49385..-33356 +on x=-1003..8848,y=3538..36480,z=67569..78791 +on x=-82583..-61600,y=-56407..-35035,z=-26389..-4025 +off x=-441..23101,y=-65805..-48288,z=-52691..-32101 +off x=60604..90029,y=-19348..-12737,z=-42042..-27174 +off x=17436..39271,y=72348..90756,z=-25418..-8051 +off x=26847..53845,y=46859..73289,z=23426..31266 +off x=16841..27203,y=23421..55101,z=49100..83605 +off x=25714..42561,y=-8143..13044,z=64035..91107 +on x=29558..48710,y=-57841..-33714,z=33263..67264 +off x=11715..35392,y=39866..51678,z=60099..69063 +on x=23402..48483,y=37984..59658,z=48734..59709 +on x=75216..93398,y=-37876..-11754,z=-1464..22273 +off x=38528..43781,y=5542..42957,z=52809..77368 +on x=72051..74887,y=-3880..3267,z=26293..34756 +off x=-6816..4852,y=1566..29804,z=-80492..-65423 +on x=49708..81155,y=32161..56409,z=-32648..-13317 +on x=38909..68249,y=37014..67847,z=13517..42846 +on x=-54894..-16193,y=-67206..-56964,z=-57382..-33779 +on x=-81586..-61862,y=-24449..-420,z=-43066..-15910 +on x=29328..40904,y=60475..81198,z=-31636..-14673 +off x=-5756..14438,y=-80552..-71779,z=-14292..-6865 +on x=-61722..-56718,y=23303..45126,z=-62045..-39044 +off x=29463..53594,y=-69311..-47154,z=-65164..-43563 +on x=-29305..-7147,y=-56581..-39066,z=-71283..-49802 +off x=26856..50097,y=-61266..-31296,z=-66719..-39032 +on x=46464..63140,y=-64133..-42261,z=-11759..5149 +off x=-83817..-61709,y=-37291..-21874,z=-519..9751 +off x=55841..74697,y=40336..59356,z=11147..34426 +on x=34828..69659,y=-20348..-3038,z=-58724..-55121 +off x=21197..38486,y=-72990..-45057,z=-53372..-35381 +off x=-73182..-49019,y=28385..50982,z=-42019..-21521 +off x=-76884..-61701,y=18507..39972,z=1310..29815 +on x=55547..71247,y=4141..26473,z=-56178..-52622 +on x=13772..43566,y=55179..85749,z=-13447..14016 +on x=-55863..-32769,y=38694..59920,z=-33084..-7650 +off x=-71553..-51565,y=-7760..1771,z=44677..67548 +on x=15461..31815,y=-68075..-55208,z=33755..38037 +off x=-757..36383,y=-21000..466,z=-82460..-62406 +on x=31348..41123,y=-55197..-29777,z=42323..69200 +off x=-5382..9760,y=-59558..-41324,z=-73937..-45324 +on x=-6236..21866,y=-82614..-52320,z=33120..35911 +off x=4099..31840,y=-71104..-64545,z=-49523..-23826 +off x=29700..42212,y=48414..79717,z=13133..39395 +on x=30163..49570,y=-32012..-6858,z=-82363..-58792 +on x=-46359..-40371,y=-69671..-55358,z=6944..32266 +off x=35348..60233,y=-59451..-46944,z=-50174..-21191 +on x=-59278..-40919,y=48706..74528,z=-32748..-24764 +on x=-57659..-37141,y=-74346..-56091,z=-17851..-3011 +off x=-68343..-39351,y=-17836..3402,z=-70369..-50558 +on x=-17324..10446,y=27985..43066,z=-84705..-64368 +off x=-2280..7517,y=61082..89231,z=-19465..-2882 +on x=5543..33886,y=77122..80758,z=-10232..26039 +off x=19644..31561,y=42033..74969,z=45658..57072 +on x=28283..49889,y=49674..76561,z=13613..37459 +on x=45096..53724,y=18463..39530,z=38390..74144 +off x=41400..61615,y=55595..76548,z=-25393..-1387 +off x=16748..34122,y=29923..56425,z=-75021..-51740 +on x=-15179..5656,y=-95572..-69068,z=11214..25476 +off x=-58988..-47130,y=30229..46889,z=-44974..-35744 +off x=-38977..-14492,y=-36334..-3133,z=-87758..-60247 +off x=-67544..-49093,y=58841..65953,z=-34695..2783 +on x=-44817..-12547,y=-69513..-42436,z=39463..67412 +off x=-44782..-35211,y=63582..79211,z=-35165..-9576 +off x=-51917..-19062,y=-70443..-39929,z=-56733..-29318 +off x=-32721..-9720,y=-70269..-48267,z=39356..68334 +on x=-89499..-64841,y=-7134..14311,z=10526..42888 +off x=-15686..10883,y=-68334..-64832,z=40994..55889 +off x=15665..28627,y=66455..83258,z=-19131..2585 +on x=-36618..-12260,y=-1197..23827,z=-84792..-62643 +on x=-63442..-42432,y=31128..47260,z=-58742..-50931 +off x=59788..75917,y=-43859..-30744,z=-37530..-27877 +on x=-97459..-75879,y=-2528..12488,z=-25702..8626 +off x=4312..20664,y=43578..62639,z=45490..65994 +off x=-42832..-21422,y=-36295..-10208,z=64453..78449 +on x=45985..62219,y=41630..64002,z=-35004..-28441 +off x=30577..58921,y=60165..62928,z=2996..24752 +on x=-63410..-43768,y=18828..35057,z=-54580..-27363 +on x=-37744..-7907,y=57733..80242,z=-9272..25957 +off x=37094..69910,y=-11677..3264,z=57810..73004 +off x=-58324..-35044,y=-65535..-55260,z=-14769..16228 +on x=29859..52630,y=-10518..7762,z=-70264..-49235 +on x=57003..84333,y=-43825..-36782,z=-2738..13139 +on x=71783..92840,y=-12502..2933,z=-27092..1613 +on x=40360..50398,y=-23637..-8074,z=-66669..-60640 +on x=43892..72948,y=-1818..13786,z=-66670..-46862 +off x=-77329..-51638,y=5621..37354,z=-38107..-25102 +on x=-16374..13066,y=-43732..-18415,z=-82490..-64333 +off x=-13344..-10566,y=-39722..-23766,z=-88355..-56712 +on x=-1142..4694,y=56137..86923,z=-53607..-22509 +off x=-57266..-32196,y=3936..11070,z=66725..88936 +on x=46021..63903,y=35240..49664,z=15607..37579 +on x=57444..70046,y=3467..37797,z=41207..53935 +on x=-70116..-53894,y=34009..53610,z=5772..25407 +on x=1370..17649,y=-45129..-26001,z=-71085..-60208 +on x=27244..51676,y=16417..41941,z=50284..75127 +off x=-7215..16100,y=13132..33300,z=52638..88374 +on x=-67708..-56526,y=28446..49266,z=-54764..-36982 +off x=36565..53117,y=-69659..-48686,z=-56660..-30523 +on x=-34438..-14244,y=-45433..-35154,z=-66685..-45700 +off x=-91754..-62736,y=6030..27794,z=-36516..-23095 +on x=-20638..-13653,y=-9532..17224,z=63461..84278 +on x=-59626..-50588,y=-32678..-6316,z=46959..59720 +off x=-20225..749,y=-69753..-43037,z=-70716..-40645 +off x=-56667..-40496,y=11366..43347,z=46773..65399 +off x=-58207..-36567,y=42530..65883,z=-24484..-7023 +off x=-34762..-20011,y=42739..59302,z=-49523..-35094 +on x=-61220..-42210,y=-66752..-48262,z=8014..23734 +off x=-49232..-41437,y=-63307..-37354,z=24865..47979 +on x=26703..52532,y=-78499..-46465,z=-25018..-8738 +off x=21105..43246,y=38644..70375,z=42805..60720 +on x=-29375..-9597,y=-86639..-63948,z=-642..25463 +on x=56583..64693,y=22117..52883,z=-40318..-24339 +on x=-35643..-27958,y=47024..56238,z=36245..52842 +off x=-33039..-14225,y=64997..87100,z=-41179..-4967 +off x=59162..83173,y=25323..44364,z=2725..23248 +off x=52877..68876,y=-45091..-16834,z=-42624..-16917 +on x=38829..70185,y=8104..18659,z=45852..67774 +off x=-27424..-2771,y=-93872..-68133,z=-3046..23499 +off x=39387..48068,y=-14087..2670,z=-70270..-50908 +off x=-67568..-31653,y=-63342..-45027,z=-44056..-28022 +off x=73339..75776,y=19469..34170,z=9060..24104 +on x=18259..51005,y=48630..76031,z=7479..26749 +on x=14513..37579,y=-33597..-15184,z=63582..76318 +on x=-41275..-31697,y=-24246..-37,z=57091..73485 +off x=-31890..-16118,y=-76794..-49970,z=29480..57799 +on x=71419..87971,y=15207..25964,z=-19283..7832 +on x=-41791..-24849,y=59031..75550,z=-18258..9027 +on x=-38199..-24871,y=42794..71254,z=-42870..-21798 +on x=-25039..-8806,y=-76747..-56020,z=-57258..-29947 +off x=-22405..10912,y=-55580..-41017,z=-75320..-53817 +on x=-49793..-22756,y=-27786..-9284,z=58862..86007 +off x=25510..36784,y=-35757..-20885,z=-75794..-46116 +on x=-3712..14342,y=65221..88505,z=-9736..11415 +off x=-17899..7630,y=-87586..-63559,z=-18626..2791 +off x=-14610..11209,y=24694..36426,z=-89209..-72203 +on x=-41903..-27211,y=-37226..-32667,z=-61406..-49458 +on x=-29172..-15874,y=-29621..8729,z=-94236..-66936 +off x=-7596..-2397,y=-24666..-3179,z=68145..98782 +off x=-30179..-17490,y=-26796..7612,z=-78764..-61938 +off x=-50707..-22641,y=-62067..-42787,z=-61450..-36116 +on x=-2926..22736,y=-56652..-31989,z=54504..85199 +on x=-12251..16818,y=-45483..-39539,z=-85412..-54335 +off x=-30871..-10215,y=25326..41186,z=65924..74927 +off x=-27548..-2218,y=-90837..-53885,z=24861..40128 +off x=-15719..-8624,y=-24279..7866,z=-78569..-62304 +on x=5300..29443,y=-60482..-32603,z=53463..77364 +off x=-36883..-4698,y=-11779..15251,z=-85176..-63993 +off x=77136..95419,y=-991..22518,z=-30101..-5527 +off x=-77467..-49063,y=-3059..21180,z=-69555..-36161 +off x=43217..54077,y=56300..68390,z=-17902..7166 +off x=-27450..-5699,y=-85434..-62891,z=12577..21069 +on x=-34456..-17300,y=-38896..-25828,z=-88087..-66157 +off x=-6542..22866,y=48683..62179,z=51476..66042 +off x=-85081..-63427,y=24901..39908,z=-22256..-2736 +on x=-84263..-51335,y=-43993..-23210,z=-50786..-14571 +off x=70496..91875,y=-99..13516,z=-15338..-1176 +on x=-3414..20761,y=-58271..-50023,z=-70568..-58707 +on x=-37366..-24760,y=-40714..-28220,z=-68669..-57693 +on x=55366..69711,y=19336..39334,z=41575..56327 +off x=7756..37863,y=6813..30407,z=-86788..-58086 +on x=64340..71944,y=-58382..-21540,z=-26270..-7157 +off x=-66006..-47470,y=-36577..-20368,z=19166..34254 +on x=-58240..-46662,y=-3017..27043,z=55289..74468 +off x=-39417..-32733,y=-29342..-7099,z=-79724..-67801 +on x=-79339..-46658,y=-7270..19942,z=-50655..-39180 +off x=-60143..-38745,y=-19956..11524,z=-84176..-55543 +off x=-3874..10037,y=-64263..-39967,z=-74772..-50336 +on x=-11752..2774,y=-57741..-44508,z=51849..72929 +on x=-11710..-4855,y=-72067..-49425,z=-62392..-47771 +off x=43931..74857,y=41059..57790,z=-36316..-17211 +off x=3946..34651,y=-53908..-25012,z=52699..70802 +off x=-46656..-15008,y=17844..47261,z=55932..84912 +off x=26684..42064,y=56114..63695,z=14465..39503 +on x=-40489..-22313,y=8243..32746,z=-74516..-48795 +off x=-22851..-6555,y=-82055..-68517,z=-28862..-6378 +off x=-74113..-54822,y=24351..54331,z=7776..25070 +off x=-45651..-16942,y=18572..51284,z=62915..80308 +on x=-70429..-46638,y=-63316..-43477,z=-9658..15603 +on x=10379..47780,y=72033..88868,z=-19821..-11434 +on x=-22601..1937,y=4579..19393,z=-80796..-60988 +on x=54161..77065,y=-58754..-49409,z=338..31784 +on x=28966..60740,y=50370..68031,z=8613..32275 diff --git a/day22/src/main.rs b/day22/src/main.rs new file mode 100644 index 0000000..2fe19ab --- /dev/null +++ b/day22/src/main.rs @@ -0,0 +1,78 @@ +use std::{fs, env, collections::HashMap, hash::Hash}; + +#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)] +struct Cuboid { + pub s: bool, + pub x: (i32, i32), + pub y: (i32, i32), + pub z: (i32, i32) +} + +impl Cuboid { + fn insersects(&self, o: &Cuboid) -> Option { + if (self.x.1 < o.x.0 || self.x.0 > o.x.1) + || (self.y.1 < o.y.0 || self.y.0 > o.y.1) + || (self.z.1 < o.z.0 || self.z.0 > o.z.1) { + return None; + } + return Some(Cuboid { s: self.s && o.s, + x: (std::cmp::max(self.x.0, o.x.0), std::cmp::min(self.x.1, o.x.1)), + y: (std::cmp::max(self.y.0, o.y.0), std::cmp::min(self.y.1, o.y.1)), + z: (std::cmp::max(self.z.0, o.z.0), std::cmp::min(self.z.1, o.z.1)), + }); + } + + fn get_nb_cubes(&self) -> usize { + return (self.x.1 - self.x.0 + 1) as usize + * (self.y.1 - self.y.0 + 1) as usize + * (self.z.1 - self.z.0 + 1) as usize; + } +} + +fn read_input(path: &str) -> String { + return fs::read_to_string(path).expect("Cannot read file."); +} + +fn parse_input(s: &str) -> Vec { + let mut v = vec![]; + for l in s.lines() { + let a = l.split_once(" ").unwrap(); + let c = a.1.split(",") + .map(|e| e.split_once("=").unwrap().1.split_once("..").unwrap()) + .map(|e| (e.0.parse::().unwrap(), e.1.parse::().unwrap())) + .collect::>(); + v.push(Cuboid { s: a.0 == "on", x: c[0], y: c[1], z: c[2] }); + } + return v; +} + +fn compute_reboot(a: &Vec) -> i64 { + let mut c: HashMap = HashMap::new(); + for c1 in a.iter() { + let mut t = HashMap::new(); + for (c2, i) in &c { + let n = c1.insersects(c2); + if n.is_some() { + t.insert(n.unwrap(), *t.get(&n.unwrap()).unwrap_or(&0) - i); + } + } + if c1.s { t.insert(*c1, *t.get(&c1).unwrap_or(&0) + 1); } + for e in t { + c.insert(e.0, *c.get(&e.0).unwrap_or(&0) + e.1); + } + } + return c.iter() + .fold(0, |acc, e| acc + e.0.get_nb_cubes() as i64 * *e.1 as i64); +} + +fn main() { + let args: Vec = env::args().collect(); + for arg in args.iter().skip(1) { + let input = read_input(&arg); + let vec_in = parse_input(&input); + println!("[{}]", &arg); + println!("\t[Part 1] => Answer is '{}'.", compute_reboot(&vec_in[0..20].to_vec())); + println!("\t[Part 2] => Answer is '{}'.", compute_reboot(&vec_in)); + } +} +