commit 3a5c7cf1411e4fd9def7de63c832458a7e132fb7
parent 362de4cf2cc8d77ca48705ec134e9c724a1ce81b
Author: bsandro <brian.drosan@gmail.com>
Date: Thu, 23 Dec 2021 01:13:46 +0200
Day 22, puzzle 1 (dumb)
Diffstat:
A | day22/Makefile | | | 27 | +++++++++++++++++++++++++++ |
A | day22/input.txt | | | 420 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | day22/main.c | | | 29 | +++++++++++++++++++++++++++++ |
A | day22/puzzle.c | | | 143 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | day22/test.txt | | | 60 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 files changed, 679 insertions(+), 0 deletions(-)
diff --git a/day22/Makefile b/day22/Makefile
@@ -0,0 +1,27 @@
+NAME=$(shell basename ${PWD})
+SRC=$(wildcard *.c ../common/*.c)
+DEPS:=$(wildcard *.h ../common/*.h)
+OBJ:=$(SRC:.c=.o)
+CFLAGS=-O0 -g -fsanitize=address -fno-omit-frame-pointer -std=c99 -Werror -Wall -Wextra -I. -I../common
+LDFLAGS=-g -lc -lm -fsanitize=address
+#CFLAGS=-O2 -std=c99 -Werror -Wall -Wextra -I. -I../common
+#LDFLAGS=-lc -lm
+
+all: $(NAME)
+
+.PHONY: clean run
+
+clean:
+ rm -f $(OBJ) $(NAME)
+
+%.o : %.c $(DEPS)
+ @$(CC) $(CFLAGS) -c $< -o $@
+
+$(NAME): $(OBJ)
+ @$(CC) $(OBJ) -o $@ $(LDFLAGS)
+
+run: $(NAME)
+ @./$(NAME) input.txt
+
+test: $(NAME)
+ @./$(NAME) test.txt
diff --git a/day22/input.txt b/day22/input.txt
@@ -0,0 +1,420 @@
+on x=-16..31,y=1..46,z=-4..43
+on x=-25..20,y=-25..28,z=-48..-3
+on x=-1..48,y=-8..36,z=-12..41
+on x=-14..38,y=-46..0,z=-33..15
+on x=-36..14,y=-35..14,z=-24..28
+on x=-13..37,y=-36..8,z=-24..21
+on x=-43..11,y=-48..6,z=-12..39
+on x=-20..29,y=-45..5,z=-42..11
+on x=-32..21,y=-9..45,z=-26..18
+on x=-3..43,y=-38..14,z=-10..36
+off x=-13..1,y=9..26,z=18..33
+on x=-5..43,y=-2..49,z=-41..9
+off x=-15..-1,y=-46..-32,z=-43..-29
+on x=-3..46,y=-10..34,z=-35..19
+off x=-44..-25,y=10..27,z=-46..-29
+on x=-33..20,y=-35..14,z=-32..18
+off x=-10..4,y=-33..-21,z=16..35
+on x=-6..44,y=-11..39,z=-9..43
+off x=-40..-30,y=-35..-25,z=-42..-27
+on x=-45..7,y=-12..41,z=-19..35
+on x=-16626..-5358,y=65839..74495,z=29415..38920
+on x=11538..27407,y=-83170..-62776,z=-39346..-27107
+on x=-30148..-7832,y=19050..44636,z=-78637..-67274
+on x=-42884..-16251,y=-90039..-71861,z=-5240..8756
+on x=-74438..-63179,y=39217..44062,z=-39956..-7545
+on x=-86334..-69841,y=3354..16304,z=-31270..-3793
+on x=-1236..-311,y=41066..80091,z=-64115..-48420
+on x=-79806..-53833,y=-61996..-36600,z=-4523..13558
+on x=75813..85464,y=-2925..22451,z=422..17494
+on x=-46893..-33468,y=-16111..-8063,z=54555..76734
+on x=-8758..18245,y=55024..83027,z=-59650..-35022
+on x=-27699..-5940,y=-83756..-56570,z=-42866..-21950
+on x=73920..81095,y=-25253..-8409,z=2743..14735
+on x=35818..41904,y=-57650..-41233,z=27973..61207
+on x=29959..59740,y=-38895..-21398,z=-65078..-60454
+on x=40127..64417,y=-64447..-52833,z=-8592..14482
+on x=64969..96459,y=-23166..1188,z=-25001..2693
+on x=-143..29601,y=-83445..-67771,z=-9638..-7783
+on x=-60213..-45765,y=-53615..-19163,z=-52850..-39718
+on x=19768..47655,y=69461..74219,z=-4463..16237
+on x=46138..61661,y=-63285..-51050,z=9780..21893
+on x=-27642..-12656,y=25894..46430,z=61246..76823
+on x=-65790..-39877,y=40195..63446,z=-2899..11490
+on x=49291..72263,y=-50811..-26583,z=-20941..-5171
+on x=43500..64276,y=12863..21473,z=54519..73780
+on x=46844..73861,y=-16675..-2479,z=-47642..-25535
+on x=-38804..-29011,y=-67818..-52416,z=-61006..-43171
+on x=1476..21276,y=-9840..-6534,z=-85982..-60406
+on x=-49568..-20033,y=-68783..-52200,z=31854..65658
+on x=-76725..-67570,y=-4561..14897,z=-38772..-8804
+on x=-55244..-26894,y=-36916..-934,z=48540..70261
+on x=-41119..-16974,y=16600..40627,z=58244..70088
+on x=3316..25661,y=-12050..-1558,z=-99062..-70346
+on x=45001..70541,y=-33078..-2030,z=52228..72036
+on x=-67378..-51926,y=-72562..-47073,z=6195..26804
+on x=55900..80560,y=-57308..-33974,z=-17793..-9736
+on x=-29945..-7557,y=-95561..-58463,z=-9932..7238
+on x=8449..36405,y=-76928..-68845,z=-23326..757
+on x=-34111..-8335,y=-19697..-3799,z=66119..83203
+on x=-36514..-4829,y=49252..76336,z=29521..56642
+on x=11206..38344,y=47029..70722,z=30062..49138
+on x=-55423..-33064,y=-70039..-63720,z=538..17442
+on x=-14042..9000,y=78992..82671,z=939..18684
+on x=-64272..-55953,y=-62880..-46525,z=-20251..-12223
+on x=56784..83081,y=-53146..-23655,z=-22242..-376
+on x=-72515..-54296,y=20329..32675,z=-48741..-36672
+on x=-37591..-14405,y=-78283..-60946,z=-27261..-13754
+on x=-7827..4332,y=59740..82815,z=6353..26827
+on x=32544..39071,y=37014..61832,z=-58551..-43422
+on x=-17870..1502,y=40727..57792,z=-67559..-56495
+on x=-89322..-54056,y=-30501..-9285,z=19617..43415
+on x=-51038..-20752,y=64717..81878,z=-43867..-12998
+on x=47396..69956,y=-33858..113,z=-63348..-43854
+on x=7217..23792,y=-74758..-64728,z=-42951..-23023
+on x=66415..85414,y=-14449..19269,z=7812..13458
+on x=26596..51516,y=63127..86109,z=-17075..8711
+on x=27887..44175,y=51326..76134,z=-17583..12578
+on x=-26245..-4662,y=-87359..-53408,z=29011..44615
+on x=50041..68185,y=-72545..-50449,z=771..26455
+on x=-53882..-23346,y=61979..69412,z=-14830..403
+on x=-92395..-71742,y=8500..31184,z=-30948..3326
+on x=-84689..-61365,y=-5903..-5045,z=-16904..4053
+on x=2428..14437,y=-34803..-23153,z=-87517..-69099
+on x=-32827..-8995,y=-87108..-49977,z=15664..50808
+on x=49790..61799,y=-66565..-55646,z=-13400..9149
+on x=65152..90550,y=6393..32550,z=-26986..2769
+on x=-17765..4636,y=68602..99811,z=-21823..4508
+on x=16493..40766,y=-60273..-32161,z=-64629..-34942
+on x=2763..10738,y=-84795..-68975,z=-36158..-21112
+on x=47015..72584,y=-43148..-36236,z=-41625..-21182
+on x=-34469..-16168,y=-18103..-3805,z=-90141..-63881
+on x=-5626..21545,y=-52157..-28783,z=-79195..-67791
+on x=9088..41761,y=49408..67441,z=-51281..-29791
+on x=-83591..-46808,y=1450..17985,z=39684..58556
+on x=7209..43400,y=-84613..-70397,z=8338..27012
+on x=63618..91669,y=-2593..20510,z=14081..35656
+on x=-67238..-58196,y=-47018..-38371,z=-41182..-25445
+on x=13678..24060,y=71418..94729,z=-28691..2217
+on x=3387..21883,y=64793..81377,z=20775..42439
+on x=-82175..-63317,y=-29428..-5086,z=-13144..-2955
+on x=47731..83696,y=-17540..-6608,z=-46538..-22647
+on x=-84279..-64526,y=-33480..-26072,z=-16658..7353
+on x=-64883..-38001,y=-47465..-21473,z=-65978..-36673
+on x=-63796..-48066,y=-37473..-6219,z=47505..61163
+on x=-33926..-18593,y=44590..72508,z=36548..64115
+on x=-81609..-53863,y=-8671..9973,z=22066..39557
+on x=-88013..-53644,y=-15369..-6524,z=13986..47932
+on x=5047..23891,y=36753..52877,z=-78487..-45244
+on x=-66398..-44245,y=-49816..-34494,z=-40477..-19878
+on x=-67893..-53853,y=38596..54419,z=-22278..456
+on x=-88257..-55664,y=-40627..-9932,z=1099..13966
+on x=-59525..-35831,y=46383..76442,z=-4614..7577
+on x=41818..66402,y=40030..79040,z=16461..36668
+on x=-79970..-55362,y=-45789..-20849,z=12043..44443
+on x=-64665..-48265,y=-35597..-4744,z=51281..69945
+on x=-76472..-52314,y=39753..65367,z=-6014..25019
+on x=11290..39892,y=4014..24015,z=58832..91425
+on x=-31215..-7336,y=19452..38703,z=-87464..-68675
+on x=63267..88137,y=-19484..-9070,z=-47370..-32263
+on x=-50518..-23309,y=60603..88733,z=791..25241
+on x=-1078..29251,y=-67190..-44967,z=41638..74339
+on x=-47895..-20668,y=33083..51786,z=-73207..-52212
+on x=3176..23061,y=-55638..-38880,z=-71587..-55883
+on x=54115..93604,y=-44801..-25806,z=-7741..7069
+on x=46384..81130,y=22680..31065,z=30537..48351
+on x=28034..44298,y=-47439..-16795,z=-76136..-53822
+on x=9523..29645,y=-57882..-33834,z=55659..63229
+on x=-20187..5555,y=-93716..-65405,z=14830..41338
+on x=-25151..-3749,y=50580..69807,z=-60241..-24729
+on x=3542..18582,y=16727..47510,z=54771..90607
+on x=46673..59564,y=35983..44196,z=49775..68560
+on x=-58557..-40339,y=9808..28894,z=-64449..-45036
+on x=-84213..-67910,y=244..20118,z=-29610..-2857
+on x=-13227..15428,y=-43619..-39287,z=-79240..-59131
+on x=-57724..-35823,y=-15708..1729,z=64748..75596
+on x=-71650..-52829,y=-20464..176,z=-63601..-43029
+on x=24621..55801,y=55911..66270,z=-39645..-18207
+on x=-579..22805,y=-58911..-51405,z=40712..63582
+on x=-33137..-20573,y=5394..24614,z=-80518..-66374
+on x=-42485..-30060,y=53121..86748,z=-18756..-2445
+on x=2524..31875,y=48593..70768,z=-45430..-35645
+on x=-35030..-27015,y=56962..87451,z=-14112..1442
+on x=-34897..-2060,y=59422..80969,z=-20283..8499
+on x=48896..80551,y=4835..29904,z=-53060..-30399
+on x=-62041..-44374,y=-51140..-30372,z=-53710..-26830
+on x=65216..82599,y=-9284..10775,z=34125..49701
+on x=57796..90183,y=16788..27230,z=-33817..-4659
+on x=-45986..-31576,y=56558..69975,z=-32799..2823
+on x=52929..78672,y=-16621..15755,z=-60872..-28415
+on x=23766..41795,y=24357..46468,z=-68419..-49642
+on x=39212..56024,y=-22869..-562,z=-81770..-49370
+on x=55290..86573,y=-1420..3401,z=-59855..-39428
+on x=4988..37148,y=70767..88373,z=169..23908
+on x=-24288..-9725,y=19858..45959,z=73017..73771
+on x=16463..35944,y=-34992..-22225,z=63605..75415
+on x=59981..87070,y=-12490..6924,z=-50883..-31427
+on x=-31696..-14917,y=-80331..-71170,z=13660..36778
+on x=50890..69328,y=-64313..-35420,z=10931..37792
+on x=-18277..12031,y=-30989..-11500,z=63994..77515
+on x=-54741..-22937,y=-50360..-21842,z=-73236..-52694
+on x=11255..30975,y=-84766..-48678,z=25978..46263
+on x=-25133..-6698,y=44481..63935,z=-57957..-44787
+on x=6835..27609,y=63969..85980,z=-13784..4839
+on x=-28332..-3402,y=59221..80886,z=12704..36232
+on x=14352..42281,y=-71402..-37811,z=30897..58907
+on x=-95510..-63057,y=-31980..-8260,z=-36401..-2477
+on x=26648..32121,y=39897..55842,z=-70416..-42005
+on x=53848..84281,y=26417..50749,z=14345..40770
+on x=-56910..-29275,y=26413..43384,z=46029..58793
+on x=14326..36045,y=-6103..4525,z=-93728..-72484
+on x=-15173..5626,y=-29458..-6475,z=-80989..-66470
+on x=54405..58848,y=-7066..-368,z=-59003..-48198
+on x=14360..38053,y=22013..44227,z=-69567..-50967
+on x=-73788..-48192,y=-29910..-12391,z=-43054..-31730
+on x=-601..20162,y=-58316..-41530,z=-65908..-53349
+on x=25669..38881,y=66371..68180,z=-38085..-12167
+on x=-34694..-8890,y=-79602..-47486,z=32345..58909
+on x=-81839..-62323,y=7805..25102,z=19298..40989
+on x=36228..64481,y=34189..57670,z=-56377..-35424
+on x=-20882..3842,y=-60435..-45168,z=36672..69888
+on x=-49916..-28386,y=-31202..-23856,z=-81647..-54377
+on x=-26929..-13521,y=-87676..-62810,z=-37804..-20570
+on x=-62129..-37808,y=-65166..-46544,z=16404..39757
+on x=-34366..-23888,y=68996..74027,z=9849..38569
+on x=-14711..976,y=-37284..-14813,z=-86822..-58807
+on x=-16581..-4037,y=-42760..-17834,z=67353..72170
+on x=-40967..-27659,y=42525..61193,z=37870..53152
+on x=-56733..-37605,y=-70355..-39518,z=38723..44119
+on x=26431..43156,y=-75476..-66088,z=-19376..-5034
+on x=33930..53828,y=-51162..-31527,z=-74973..-37419
+on x=-2306..22702,y=-64265..-35624,z=-77488..-42536
+on x=-34183..-11208,y=-32051..3881,z=64410..78673
+on x=-20578..-10681,y=62323..66053,z=34829..60085
+on x=-429..19875,y=16343..53290,z=-72639..-63281
+on x=-24462..-10401,y=-86602..-61532,z=-28182..-8995
+on x=-19769..15057,y=78579..95903,z=-4288..1519
+on x=10663..27371,y=49806..68401,z=-47121..-23445
+on x=68309..74448,y=16971..36971,z=11771..27647
+on x=66195..80982,y=2656..16698,z=-31180..-9431
+on x=-83972..-66358,y=14622..22080,z=-42322..-33379
+on x=-74214..-52465,y=-70178..-46958,z=-41784..-2035
+on x=-49046..-24438,y=-72059..-56568,z=20498..28669
+on x=-38824..-24674,y=-59190..-34157,z=-62245..-44297
+on x=-77769..-53191,y=16428..42919,z=-47804..-17226
+on x=46116..51837,y=-65835..-59134,z=-35666..-5868
+on x=34121..61853,y=-45227..-21033,z=-69337..-36629
+on x=44863..65321,y=-54680..-34053,z=20013..31978
+on x=27750..60445,y=-2084..23012,z=-77586..-63487
+on x=-41968..-17023,y=57245..64595,z=30346..58376
+on x=43476..66037,y=12833..23996,z=40813..63592
+on x=-80085..-70681,y=17109..37749,z=-24174..4791
+on x=-13618..12965,y=-79679..-62900,z=-28948..-12942
+on x=-83372..-64426,y=-42695..-14603,z=-3458..10425
+on x=-55278..-31190,y=46809..62709,z=27387..64320
+on x=62079..88113,y=20443..23267,z=1628..13526
+on x=-78952..-64492,y=11312..32930,z=-38733..-35097
+on x=48948..71682,y=19378..36384,z=31232..43658
+on x=29001..58779,y=-48676..-24503,z=38433..67387
+on x=58147..63001,y=-32793..5075,z=34059..55086
+on x=40107..56067,y=-5729..14676,z=-68681..-38450
+on x=7875..35440,y=-15987..-3470,z=58258..88059
+off x=51958..77157,y=-45848..-34019,z=-45965..-14397
+off x=-86500..-64620,y=-40730..-21013,z=8977..27364
+on x=36600..57995,y=43848..56744,z=-55747..-38177
+on x=-19750..2967,y=-49416..-28586,z=-76313..-62346
+off x=-75162..-73773,y=26429..45476,z=-3374..5164
+on x=-7641..-149,y=47286..72177,z=37778..59677
+off x=-38471..-17837,y=35136..54980,z=33162..62964
+off x=14197..27015,y=-23589..1868,z=66503..77836
+on x=21832..40266,y=22135..50108,z=-75513..-55839
+on x=-34944..-14485,y=-82842..-74366,z=-14291..1057
+off x=56693..70278,y=10943..21670,z=24742..47647
+off x=19971..29459,y=-82505..-65074,z=-37816..-23149
+off x=17036..36058,y=-29409..-11370,z=-83929..-61137
+off x=45616..60300,y=-68946..-58338,z=-8158..12965
+off x=-28662..-9085,y=-40046..-15105,z=62947..82701
+off x=-68712..-50215,y=-54223..-34857,z=11101..35300
+off x=-88678..-71561,y=-14184..5969,z=10679..14896
+on x=-95320..-65801,y=-21337..-4497,z=-4599..12837
+off x=-35879..-9726,y=43567..71900,z=-55585..-43092
+off x=-13337..-672,y=-91559..-70282,z=15426..47750
+on x=61339..77214,y=-29785..-19418,z=-16859..7599
+off x=-6261..16649,y=-74127..-61175,z=-46194..-24546
+on x=22251..45206,y=53117..82021,z=-9760..7833
+on x=-90076..-60813,y=-6625..26632,z=-39106..-17298
+off x=-22745..6369,y=-16502..-8195,z=-87636..-60625
+off x=3348..9565,y=-59871..-40258,z=-60078..-38207
+off x=-90837..-70775,y=-20228..3601,z=-30483..-574
+off x=66695..76890,y=-5403..9319,z=33227..50438
+on x=7291..20105,y=33289..66821,z=59030..64968
+on x=40327..47796,y=16749..48112,z=-76173..-44901
+off x=64078..81457,y=4654..14203,z=31828..55639
+off x=-92698..-74388,y=-2205..12393,z=-11688..9765
+off x=-26801..2614,y=-91444..-59132,z=-964..22837
+off x=-33467..-21903,y=1915..17346,z=-76591..-72233
+off x=47233..67200,y=-16874..-13192,z=58091..76860
+on x=-32577..-12069,y=-70699..-59054,z=36614..61215
+on x=-28041..-15568,y=65989..82844,z=30495..46234
+off x=41050..57876,y=45972..71928,z=-34752..-14763
+off x=-64481..-43271,y=7232..28511,z=-79472..-50301
+off x=62226..71717,y=-47218..-20868,z=-33751..-12145
+on x=-76166..-73836,y=-46351..-25058,z=-9950..12887
+on x=51569..68895,y=-25534..6325,z=-49599..-29670
+on x=21667..37723,y=-20572..5217,z=-76647..-73577
+on x=17483..48658,y=58197..74602,z=-60549..-36898
+on x=-10384..6333,y=-40935..-27349,z=-77251..-63349
+on x=-68984..-65983,y=22525..50962,z=-19771..12138
+off x=-58919..-28689,y=-75440..-47994,z=16871..33411
+off x=-44023..-28664,y=56859..70596,z=656..35844
+off x=35433..56357,y=7023..14208,z=-66848..-46258
+on x=19690..44341,y=-43825..-35801,z=45666..66021
+off x=-6242..-2477,y=69188..86491,z=-31190..-15901
+on x=-69460..-35858,y=-37475..-31116,z=43385..60481
+on x=50832..86946,y=244..30423,z=-57431..-29634
+off x=-65756..-45475,y=-70591..-55686,z=-23643..2664
+on x=31319..51746,y=19239..43761,z=-78757..-53954
+on x=-55240..-34527,y=-17893..7258,z=56872..75539
+on x=50059..79978,y=-13376..9044,z=41401..51629
+off x=-30249..-16222,y=43512..62505,z=36928..58564
+off x=-54885..-37507,y=-57837..-55055,z=-44955..-21044
+off x=31490..45226,y=-56247..-34966,z=-61957..-44432
+off x=24374..50207,y=63753..79036,z=20456..36392
+on x=66918..68950,y=-22992..-19780,z=-54258..-20636
+on x=42542..63202,y=30163..54372,z=7183..18442
+off x=-76872..-63748,y=-4691..26359,z=17102..29213
+off x=-48139..-21270,y=60968..77342,z=-18627..5990
+off x=1226..11824,y=-25474..-7551,z=76683..88050
+on x=-95165..-64563,y=-19270..-13804,z=-12736..21255
+off x=-80601..-60260,y=-8765..-5952,z=29707..42600
+on x=-26876..-8092,y=-66644..-53813,z=-57475..-38397
+off x=-13715..8380,y=-5774..13178,z=76259..91419
+on x=8150..33762,y=-63730..-51855,z=41629..57627
+off x=17839..44732,y=-76378..-54837,z=-33798..-12901
+on x=-49645..-14239,y=55252..89300,z=3910..21542
+off x=47194..70686,y=43841..46414,z=27690..42199
+off x=50914..71896,y=49240..67373,z=2871..10096
+on x=-6340..14780,y=-81439..-77819,z=4573..22232
+off x=-57375..-30239,y=48994..82581,z=-14542..5302
+on x=3372..9130,y=60107..83088,z=-13516..16450
+on x=30299..52580,y=-10357..22818,z=-79602..-62627
+on x=-53844..-27717,y=-18339..-1532,z=61313..72349
+on x=-58398..-46645,y=-44700..-22765,z=42201..47374
+on x=-81276..-69690,y=5411..18580,z=15378..32709
+off x=-35829..-3851,y=-57319..-37095,z=58187..81413
+off x=402..14047,y=-24272..-6449,z=59010..83646
+on x=27550..42843,y=47820..79720,z=11309..32935
+off x=56333..73493,y=28215..45737,z=-1074..22185
+off x=44308..63449,y=34730..50699,z=23484..50544
+off x=-40897..-18763,y=-23057..11408,z=70802..81924
+on x=-73403..-38679,y=37674..62706,z=-4373..26508
+off x=-80125..-52482,y=23077..55062,z=24748..32575
+off x=-55875..-45659,y=-175..14543,z=49667..66476
+off x=-27555..-11161,y=44425..70896,z=-59356..-37374
+on x=56308..79171,y=7988..29473,z=-40276..-24792
+off x=-65029..-47567,y=-8374..834,z=42147..53892
+on x=22996..32697,y=-64709..-44331,z=46589..72898
+off x=-1238..9147,y=-69906..-55988,z=39844..48229
+off x=9782..33340,y=62225..83321,z=-6522..10654
+on x=60924..80234,y=-16599..-1949,z=-368..17555
+off x=39425..62851,y=29136..43243,z=37333..52106
+on x=-88732..-77798,y=-13797..14749,z=-9445..-3764
+on x=-6312..25336,y=27697..47402,z=-64807..-51196
+off x=47059..65193,y=-67865..-50769,z=-2356..17889
+off x=-66466..-33918,y=-80857..-53128,z=7909..32981
+on x=-50170..-21632,y=-12227..3468,z=66380..75960
+on x=56305..82812,y=5802..20625,z=-54917..-18215
+on x=-51859..-45511,y=49027..67695,z=-41308..-19520
+on x=-54017..-21370,y=-3939..14574,z=-79661..-69882
+off x=2954..30305,y=37879..61246,z=-62511..-46512
+off x=-41951..-23637,y=-5145..24954,z=69321..90039
+off x=-59695..-34510,y=-10696..10590,z=-73096..-57771
+on x=49418..81941,y=-17985..1622,z=32347..43274
+on x=3712..17409,y=-82677..-60783,z=-5630..15337
+on x=55607..75339,y=1814..13578,z=-46767..-24371
+on x=49271..60093,y=8087..12615,z=51662..66525
+off x=17156..30964,y=11217..33411,z=-84837..-68845
+on x=-54176..-31024,y=-29615..-19726,z=55908..75563
+off x=-65875..-37896,y=19679..45285,z=-65011..-41402
+on x=55107..68679,y=-40911..-14782,z=-53940..-32483
+off x=13181..25962,y=-78407..-47316,z=-55027..-41623
+off x=-95851..-75879,y=-27897..-3759,z=-7561..6687
+off x=35198..66921,y=47071..77078,z=-16288..2101
+on x=-87291..-60306,y=32721..53513,z=-4810..12624
+on x=-51778..-23602,y=-70905..-34218,z=40619..58631
+off x=-63295..-32341,y=-3721..8840,z=57300..80069
+off x=53615..67373,y=-49382..-14872,z=32122..40382
+off x=54226..77357,y=-14052..13464,z=-64908..-33611
+on x=-9021..1020,y=-82050..-74394,z=-21567..-6418
+on x=-55257..-30186,y=38085..59501,z=-57168..-24352
+on x=-12966..6085,y=-93996..-55367,z=-29085..-11854
+on x=44282..61594,y=17339..24686,z=-58914..-33533
+on x=-21999..5391,y=49345..79259,z=21711..55399
+off x=35181..53502,y=57123..68754,z=-26015..-2750
+on x=-75391..-44186,y=20744..42977,z=-41415..-20250
+on x=-32020..-27201,y=61437..80740,z=-32945..-7748
+off x=33537..62364,y=-75710..-59061,z=-42883..-6765
+on x=55095..77318,y=-24162..-1764,z=-39890..-22660
+off x=56578..72878,y=4204..32996,z=-46746..-33829
+off x=-1808..20827,y=-54031..-41635,z=-68043..-53956
+on x=-36979..-26462,y=-25931..2234,z=65257..79327
+off x=72240..86512,y=-6210..-754,z=-10857..11101
+off x=-54747..-24658,y=-47386..-31322,z=-78190..-58931
+off x=32335..52343,y=3136..18926,z=-76016..-48328
+off x=-35889..-29752,y=54999..69658,z=21294..31774
+on x=-73504..-46004,y=45731..51425,z=-29171..-10342
+on x=22812..32347,y=-81087..-48713,z=-60741..-26688
+off x=-49392..-27098,y=23448..33161,z=53162..82741
+off x=-33426..-12545,y=-25829..-6848,z=60349..89608
+off x=-16755..15751,y=12212..41700,z=-89455..-69171
+off x=11535..35448,y=-87544..-56623,z=-19765..-5850
+on x=17726..42834,y=-91258..-69081,z=-9379..14367
+on x=45699..66936,y=-62411..-36101,z=-15619..14059
+on x=-89802..-56796,y=1436..13897,z=31360..38206
+on x=-9105..8407,y=66795..85218,z=-2333..8108
+off x=-31177..-5615,y=-54354..-42492,z=58082..72236
+off x=53112..74169,y=-41196..-24997,z=42601..55051
+on x=-59952..-37873,y=52545..67703,z=-28529..-15215
+off x=38721..67531,y=-64468..-38349,z=4668..27809
+on x=11517..23917,y=-6065..26686,z=-80262..-66693
+off x=45122..67892,y=-397..18680,z=-57958..-38325
+on x=18823..30836,y=8992..23124,z=69257..78968
+off x=-34237..-6539,y=-74485..-54254,z=31491..62360
+off x=-44469..-11507,y=-1285..29902,z=-78681..-54757
+on x=-77537..-52674,y=-14827..2356,z=33026..45741
+on x=8691..43126,y=31360..62618,z=-58661..-37392
+on x=15955..38219,y=-85135..-57493,z=18722..43935
+on x=-26552..-12096,y=-45538..-26088,z=-66777..-57793
+off x=-28372..-9794,y=62019..74411,z=32555..38193
+off x=-47450..-35133,y=51176..74603,z=-27962..-13567
+on x=36668..45427,y=-65444..-42135,z=22873..47270
+on x=61636..82231,y=23446..45113,z=-16012..5844
+off x=-60633..-40309,y=-61223..-36894,z=-24595..7035
+off x=1018..32130,y=-71177..-47333,z=-70756..-38503
+on x=71193..85927,y=-26871..-20940,z=2184..10815
+on x=-14903..-4211,y=-71273..-62439,z=27816..46954
+on x=46003..58146,y=42520..65257,z=-57140..-23606
+on x=-66695..-47305,y=-40061..-25526,z=-51905..-38531
+off x=51804..70223,y=-23812..-21346,z=-51759..-19411
+off x=44625..66317,y=53194..65497,z=-7..24591
+on x=-23697..9411,y=66212..73784,z=15710..31146
+on x=-56955..-41267,y=47766..79338,z=-26808..2798
+off x=-63489..-54075,y=3690..19760,z=45498..59804
+off x=-94144..-63196,y=-22144..-5253,z=-11443..11383
+on x=22283..45634,y=-83292..-62326,z=20994..44101
+on x=-4502..19949,y=6666..38000,z=-81401..-65692
+on x=55099..77629,y=-30121..-20671,z=-17243..-3631
+on x=44050..69909,y=41113..58559,z=-36248..-21714
+on x=38643..50380,y=-63757..-39070,z=-66637..-36706
+off x=-49088..-30686,y=57749..74120,z=-13646..1118
+on x=-77908..-55175,y=-18321..4702,z=-53372..-28652
+on x=-58978..-42937,y=44889..57631,z=4246..21878
+off x=66453..68159,y=7285..41875,z=-35853..-24935
+off x=55700..82868,y=-3230..24114,z=-46638..-30761
+off x=-2093..8023,y=-83963..-70642,z=6834..26401
+off x=24653..46398,y=-37527..-26070,z=46964..80592
+on x=-29351..-436,y=69055..89354,z=-4117..5812
+off x=-50278..-18285,y=-15337..3834,z=72134..78000
+off x=73213..91064,y=-8689..18918,z=-11794..18175
+on x=60620..75875,y=24894..44737,z=12585..26731
+off x=10079..23835,y=68428..73664,z=21838..38598
diff --git a/day22/main.c b/day22/main.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+
+void puzzle(const char *filename, long long *res1, long long *res2);
+
+int main(int argc, char *argv[]) {
+ printf("Advent of Code: day 22\n");
+ double time_start = clock();
+
+ if (argc <= 1) {
+ printf("Usage: %s inputfile.txt\n", argv[0]);
+ return -1;
+ }
+
+ const char *filename = argv[1];
+ long long counter1 = -1;
+ long long counter2 = -1;
+
+ puzzle(filename, &counter1, &counter2);
+
+ printf("Puzzle #1: %lld\n", counter1);
+ printf("Puzzle #2: %lld\n", counter2);
+
+ double elapsed = clock() - time_start;
+ printf("Elapsed: %f\n", elapsed / CLOCKS_PER_SEC);
+
+ return 0;
+}
diff --git a/day22/puzzle.c b/day22/puzzle.c
@@ -0,0 +1,143 @@
+#define _DEFAULT_SOURCE
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <strings.h>
+#include <assert.h>
+#include <ctype.h>
+#include <stdbool.h>
+#include <math.h>
+
+#include "util.h"
+
+#define STR_LEN 1024
+
+struct cuboid_t {
+ int x1, y1, x2, y2, z1, z2;
+ bool on;
+};
+
+void parse_cuboid(struct array_t *array, const char *str);
+void init_cubes(bool (*cubes)[101][101][101], struct array_t *cuboids);
+long long count_cubes(bool (*cubes)[101][101][101]);
+
+void puzzle(const char *filename, long long *result1, long long *result2) {
+ FILE *infile = fopen(filename, "r");
+ if (infile == NULL) {
+ fprintf(stderr, "fopen() error: %s\n", strerror(errno));
+ return;
+ }
+
+ char buf[STR_LEN] = {0};
+
+ struct array_t cuboids = { .data = NULL };
+ array_init(&cuboids, sizeof(struct cuboid_t), 10);
+
+ while (fgets(buf, STR_LEN, infile) != NULL) {
+ parse_cuboid(&cuboids, buf);
+ bzero(buf, STR_LEN);
+ }
+
+ bool cubes[101][101][101] = {0};
+
+ init_cubes(&cubes, &cuboids);
+ *result1 = count_cubes(&cubes);
+
+ *result2 = 0;
+
+ free(cuboids.data);
+ // mutiny! ignoring feof/ferror.
+ fclose(infile);
+}
+
+void init_cubes(bool (*cubes)[101][101][101], struct array_t *cuboids) {
+ assert(cubes != NULL);
+ assert(cuboids != NULL);
+ assert(cuboids->data != NULL);
+
+ struct cuboid_t *cuboids_data = cuboids->data;
+ for (size_t i = 0; i < cuboids->count; ++i) {
+ struct cuboid_t *cuboid = &cuboids_data[i];
+ if (cuboid->x1 >= -50 && cuboid->x2 <= 50 &&
+ cuboid->y1 >= -50 && cuboid->y2 <= 50 &&
+ cuboid->z1 >= -50 && cuboid->z2 <= 50) {
+
+ for (int x = cuboid->x1; x <= cuboid->x2; ++x) {
+ for (int y = cuboid->y1; y <= cuboid->y2; ++y) {
+ for (int z = cuboid->z1; z <= cuboid->z2; ++z) {
+ (*cubes)[x+50][y+50][z+50] = cuboid->on;
+ }
+ }
+ }
+ }
+ }
+}
+
+long long count_cubes(bool (*cubes)[101][101][101]) {
+ long long count = 0;
+ for (int x = 0; x <= 100; ++x) {
+ for (int y = 0; y <= 100; ++y) {
+ for (int z = 0; z <= 100; ++z) {
+ count += (*cubes)[x][y][z];
+ }
+ }
+ }
+ return count;
+}
+
+void parse_cuboid(struct array_t *array, const char *str) {
+ assert(str != NULL);
+ assert(array != NULL);
+ assert(strlen(str) > 5);
+ struct cuboid_t cuboid = {0};
+ int offset = 0;
+ if (strncmp(str, "on", 2) == 0) {
+ cuboid.on = true;
+ offset = 3;
+ } else if (strncmp(str, "off", 3) == 0) {
+ cuboid.on = false;
+ offset = 4;
+ } else {
+ printf("invalid string %s", str);
+ return;
+ }
+
+ char *tmp = strndup(str+offset, STR_LEN);
+ assert(tmp != NULL);
+ char *token = NULL;
+
+ while ((token = strsep(&tmp, ",")) != NULL) {
+ if (*token == '\n' || *token == '\0') break;
+
+ char *tmp2 = strndup(token + 2, STR_LEN);
+ assert(tmp2 != NULL);
+ char *t = NULL;
+ int nums[2] = {0};
+ int cnt = 0;
+ while ((t = strsep(&tmp2, ".")) != NULL) {
+ if (*t != '\n' && *t != '\0') {
+ nums[cnt++] = atoi(t);
+ }
+ }
+ if (token[0] == 'x') {
+ cuboid.x1 = nums[0];
+ cuboid.x2 = nums[1];
+ } else if (token[0] == 'y') {
+ cuboid.y1 = nums[0];
+ cuboid.y2 = nums[1];
+ } else if (token[0] == 'z') {
+ cuboid.z1 = nums[0];
+ cuboid.z2 = nums[1];
+ } else {
+ printf("invalid string %s\n", tmp);
+ }
+ free(tmp2);
+ }
+ free(tmp);
+
+ if (array->count >= array->cap) array_expand(array);
+ struct cuboid_t *cuboids = array->data;
+ cuboids[array->count++] = cuboid;
+}
diff --git a/day22/test.txt b/day22/test.txt
@@ -0,0 +1,60 @@
+on x=-5..47,y=-31..22,z=-19..33
+on x=-44..5,y=-27..21,z=-14..35
+on x=-49..-1,y=-11..42,z=-10..38
+on x=-20..34,y=-40..6,z=-44..1
+off x=26..39,y=40..50,z=-2..11
+on x=-41..5,y=-41..6,z=-36..8
+off x=-43..-33,y=-45..-28,z=7..25
+on x=-33..15,y=-32..19,z=-34..11
+off x=35..47,y=-46..-34,z=-11..5
+on x=-14..36,y=-6..44,z=-16..29
+on x=-57795..-6158,y=29564..72030,z=20435..90618
+on x=36731..105352,y=-21140..28532,z=16094..90401
+on x=30999..107136,y=-53464..15513,z=8553..71215
+on x=13528..83982,y=-99403..-27377,z=-24141..23996
+on x=-72682..-12347,y=18159..111354,z=7391..80950
+on x=-1060..80757,y=-65301..-20884,z=-103788..-16709
+on x=-83015..-9461,y=-72160..-8347,z=-81239..-26856
+on x=-52752..22273,y=-49450..9096,z=54442..119054
+on x=-29982..40483,y=-108474..-28371,z=-24328..38471
+on x=-4958..62750,y=40422..118853,z=-7672..65583
+on x=55694..108686,y=-43367..46958,z=-26781..48729
+on x=-98497..-18186,y=-63569..3412,z=1232..88485
+on x=-726..56291,y=-62629..13224,z=18033..85226
+on x=-110886..-34664,y=-81338..-8658,z=8914..63723
+on x=-55829..24974,y=-16897..54165,z=-121762..-28058
+on x=-65152..-11147,y=22489..91432,z=-58782..1780
+on x=-120100..-32970,y=-46592..27473,z=-11695..61039
+on x=-18631..37533,y=-124565..-50804,z=-35667..28308
+on x=-57817..18248,y=49321..117703,z=5745..55881
+on x=14781..98692,y=-1341..70827,z=15753..70151
+on x=-34419..55919,y=-19626..40991,z=39015..114138
+on x=-60785..11593,y=-56135..2999,z=-95368..-26915
+on x=-32178..58085,y=17647..101866,z=-91405..-8878
+on x=-53655..12091,y=50097..105568,z=-75335..-4862
+on x=-111166..-40997,y=-71714..2688,z=5609..50954
+on x=-16602..70118,y=-98693..-44401,z=5197..76897
+on x=16383..101554,y=4615..83635,z=-44907..18747
+off x=-95822..-15171,y=-19987..48940,z=10804..104439
+on x=-89813..-14614,y=16069..88491,z=-3297..45228
+on x=41075..99376,y=-20427..49978,z=-52012..13762
+on x=-21330..50085,y=-17944..62733,z=-112280..-30197
+on x=-16478..35915,y=36008..118594,z=-7885..47086
+off x=-98156..-27851,y=-49952..43171,z=-99005..-8456
+off x=2032..69770,y=-71013..4824,z=7471..94418
+on x=43670..120875,y=-42068..12382,z=-24787..38892
+off x=37514..111226,y=-45862..25743,z=-16714..54663
+off x=25699..97951,y=-30668..59918,z=-15349..69697
+off x=-44271..17935,y=-9516..60759,z=49131..112598
+on x=-61695..-5813,y=40978..94975,z=8655..80240
+off x=-101086..-9439,y=-7088..67543,z=33935..83858
+off x=18020..114017,y=-48931..32606,z=21474..89843
+off x=-77139..10506,y=-89994..-18797,z=-80..59318
+off x=8476..79288,y=-75520..11602,z=-96624..-24783
+on x=-47488..-1262,y=24338..100707,z=16292..72967
+off x=-84341..13987,y=2429..92914,z=-90671..-1318
+off x=-37810..49457,y=-71013..-7894,z=-105357..-13188
+off x=-27365..46395,y=31009..98017,z=15428..76570
+off x=-70369..-16548,y=22648..78696,z=-1892..86821
+on x=-53470..21291,y=-120233..-33476,z=-44150..38147
+off x=-93533..-4276,y=-16170..68771,z=-104985..-24507