Day 15
This commit is contained in:
100
2021/15.input
Normal file
100
2021/15.input
Normal file
@@ -0,0 +1,100 @@
|
||||
4395194575929822238989941988598994946581953236424841813955769288219282998336161199274582725132193662
|
||||
1715719228759138638397684864996679719167258159599658826174926447916886499139963731181569842792979836
|
||||
5641957947399279962631596818774779918898868615738299911674929785663922472189972649893918935926989965
|
||||
2585497851318911812329521892518876883669883794214786673934129871993567882759933254875129861732949942
|
||||
6326121293629918828545199576444799485199997872984968987116189717399321966789925619859799917896971919
|
||||
1197891193163157699998465137799499428622885997715629793728799611991922169771186415959393796833328797
|
||||
9971941176236517711968176833694122359799994332972933319744917758263654615939671218999722759897946883
|
||||
8999294422711677672138234871949951867361994331595339178487499997983949131794946775549222972399289896
|
||||
3349291493887252933563637858998292429461181979119894978282958316785791165839546981395193797183659157
|
||||
7189439835616936936452916284895714389978973983979946899115361688238479929831181859649911588342717174
|
||||
9919687931991844963923118455824186376858799159986659568599889942949751127924998243532126861192227813
|
||||
8556752119948211196297781958736978151712384292658126551391659754132796214991112228251319499881769877
|
||||
1979947819698244184997611639891169294112917898297946132711657818979459522579998285949272941189651219
|
||||
8526183359487314556663171586821716949298464911898919115161199393481771956882329857552411954641939441
|
||||
1781919896684119688349391339192196799588645991242746996794955718159288456491121922268271789679196351
|
||||
1197567977371916661139687299725917634957272938365923151889699976438687129398228799597921729929992714
|
||||
4612932372899778339369954694952999219672973397661799332114944198582981641791452579999989699742756964
|
||||
6999162799681597281641651777891979395397835152949992426916756338121612297639319849519239816897924832
|
||||
2929523873329969919578959424699989299758674993329912629488597872529465316591581194999996221889681928
|
||||
8228656689838938962979299798868965176111786181396381619674278311396838891887432267914997982584599249
|
||||
3291189727977984366996998628998999313854947791298837533988923314799893553121114286295795551978824232
|
||||
1969899739799949932911885277583879342673999999696225694755379718993111283179891261733382476218558941
|
||||
4139678172235724118199726211119671191998665963518891164122317193835651793851195981494569791148964119
|
||||
8491859444877458918921985959989568279219722914284989216186773895898218317795329987999133881714858193
|
||||
2771894559749588998196893858679239272818243739928684589924781981773791798991892831999869587961311167
|
||||
8698775892993989977451194464865721268484216875311866222111987933418291995941958137194897996649415669
|
||||
9815831789813838789211849713941639192861814785979938811825669343313889446468439829866799197356199957
|
||||
8391217969784868593822994733189558658223987532137877169778153978669662784849729448991221591737912928
|
||||
1286923398138799667979629228969771916586553188988688124597199878412159468838995398755911831124947458
|
||||
1114829212648462813962865127721383493959596596219921932831948169799141594693396881528179473168999246
|
||||
8229274989319485131759119628887993878981894123939971871579472951958128273735938172877719459979616966
|
||||
9499516139937388199431887411757519697113346973918231323926539878654177977781846978129796428916386862
|
||||
4976998292388572314456265734789687366686748398788899297684913137779698579739992995231592719964862978
|
||||
2298177775583527949898397959425767832825991552239939999392925878819892226485971811999876289184259875
|
||||
3598947472448691635139959991352673979496318718231961399989962929352899269143994934946299795998128783
|
||||
7112174898192377964819299748639161162263488897467958394886818188981289197818113459389985525596199819
|
||||
9987787819769819287382267885519776534891123996871992292115788186562861498191537481789591841846186882
|
||||
4932928968769839163293479931958989358947715254682158299764179952675896919281473293998826971956719781
|
||||
9992216325832365211598714373826949876761198899344963795899592692291996816722739297999357184959969777
|
||||
8299492186897712559157176181191385891631253997468944991976578985988414979191999779899999718894199893
|
||||
9599634119932298479281989351167939998231691111219295175188529818284912884666292812879581588751975666
|
||||
9893411889151989895121929229639869648431989868714855378743883971235628399646641369715828182779286514
|
||||
8939515728674611191619883917891998789585382765378965697452669997798898499199181191539751395986113886
|
||||
9985666981399318453128358762184119989474811319212718761249919671981988848392275694674398146181416198
|
||||
8193892754125669889688695711759861961188261942984936153189888489199611811681269985959959968811384341
|
||||
8299917437379188117917628771687562449889987984991225519931596159725913681979787939969976651741749698
|
||||
8285297977988918992157859998969934917144295338397889967636236876746919995248975499929976279814914931
|
||||
9129499129593186731916693856178488768855292651679735946159317969489119952269991769981967997489693511
|
||||
7186637914671953873792124571983949693887419197239989992917386832793799278886872648567913786197639677
|
||||
9667487981719871696217751899991188952177479933799965849967487849683858162517919957637748993181344613
|
||||
4798696188279263112441176132921127173319858683256972916675925279917946959468161918992879929186429996
|
||||
1875628214911419676889344457796569819463131975985822779517679476958819822619947289779578492991712138
|
||||
9729987223699868162597477587276969892989969399943929635225993221991199187491492967948629623789668744
|
||||
9916111911755127191948896779129983784992661981998299971599989198761289123181443629292169995715974949
|
||||
1291917878889332658369889135368111113759781552671763529821597651871398558593277892399994199844188899
|
||||
8857659891128611558849143993177991511814858869793389498556946631129988799922937638978992359857839357
|
||||
9498927473319717382175369484488993971151116118963956979372884748999382475159478948297342397888172486
|
||||
8838311993693897959989699851182958819758515849648216159982472145775919486496793748386329827875114795
|
||||
2646323635456985931835993825299725819616464197571881778646919914938572377378887919941193912366189981
|
||||
4192777568853894179559191115999836896832987112829422358328999616261299876112799681459689496973841216
|
||||
4182522211326928934549829947681273461197958221628297222967289879895821718559188491763567998193425175
|
||||
9941452899981779489899453416943116824565113896695891691999972969869313999989231351588275691638731173
|
||||
4279199328962391513117193251941896142249199541185874189116658753849872967489875833815972485753775799
|
||||
2692166517168484891439119972374885161996829937192277189246449949998287236914964598317589854294191818
|
||||
9691899795175315938351268169518149836746199789392955191246577759192964575629739479919199793594669346
|
||||
4928854341918568913973278223498427458884195453535861967991191927617293996995778496126372492999583688
|
||||
1869735122593925853281477159999674511464912381748647211595414615939131393112325927225913832758726989
|
||||
8673156999937894893938221988172251959669284384873549417558434149199712793826799147878341238872169799
|
||||
3786244397665631994388328169996499172551393184212436839161983999116249888235795513969896377319987648
|
||||
3299841254618376148274689819516491144697712179196959898422484829331951929556251191292922792943475111
|
||||
8979685787892899891511168966657683893794989939899716589793811126757987574288699799754629917678927199
|
||||
5291969299298572611431791117595444556315389932888323856938713114932929293397712995429591559999339269
|
||||
5571919139695338299758473188558593632658195263118579497481394132986981877919799978847911917349971951
|
||||
9447171299311825169951839995999391971743173914736767913282767941796338297879485196369168312316114619
|
||||
8965937476731877998867589955999781971348978541526728915989299973637949395212351839999632681871119852
|
||||
7154818129168364927991293583982982964961899491189199159915998987259614876919693993277919976424821339
|
||||
5863889995599382179127198593932798869731787297368813494929776247986339942885147596969931861841289387
|
||||
8291299218914728523912933158961272669279911995972979992183926289243118311811961558131192613197929186
|
||||
8961913468988371188879695178682994979962878269287243998918854923819591848296141587688276923892888765
|
||||
5496139281898589971291971391186884911787687869879279111147189911627194976288937484497924811159764722
|
||||
9875395289318577859812192389977827241588661341589921792229379945659193616899945199691585158611997752
|
||||
9897872534836989139768375684846127999667957297219249999952812149314798361868111441889987449192925623
|
||||
9138263544984999193841859937147586599945426897796171621827994461911885818295944939999799882269659399
|
||||
6914856489683269528879792799877759191976961973971938559173939387419513299922889959976555221521424697
|
||||
1715191986151162997669282366919988483318991958172785998996643612786988727959277619145619891677993797
|
||||
9942283447167676428491385853611565159691399722133269739927118911631657887991431834279716429273499866
|
||||
4799972923699768188516165542947747617263791192642512198299894199889995551779128118616736724861699788
|
||||
4958919625759529361425491889628879199991912868912939317496198948944989139197771291619455967185949537
|
||||
2223977898998997958945226793679996855922957491361985987152262111657894546195945683493497719917994917
|
||||
2169115388563391991925213886793982979499187969173993849967129291479453796965869487632218484794186428
|
||||
8181979148789991463199414217818677797879614992639757619958818656897787992873919194129981917198598753
|
||||
7298898662149861558411999137899133141939277162229327197891618169842134976193137994322715445297289799
|
||||
3295636966178697931489122998118891198718116639897914658911799996899497168942241323161993721164174647
|
||||
1198816571471558697411816978791898982893995992519493175459877178916533784561911924112689959897991892
|
||||
5618962846185938989183714393155171999657459292691693826899689462277599981997875426218165946485993981
|
||||
9347291669523992969899819288568678793199991148799181869131292289712895996712494789999957779656718174
|
||||
1211541591292966678912459115993944851245448935997663676619889855226196181522818261837465192373166996
|
||||
1797339189173753393939899772787971418172195729879466938989599928482964996915184691991154998224136189
|
||||
3421551897114792849579376681776925441448992599913934985689149424792976946888488111919491919499858968
|
||||
1971473988843177925911719936118862197889673997928889139314775919195258317837961344298715732432565457
|
||||
60
2021/15.py
Normal file
60
2021/15.py
Normal file
@@ -0,0 +1,60 @@
|
||||
import sys
|
||||
inf = sys.argv[1] if len(sys.argv) > 1 else './2021/15.input'
|
||||
|
||||
ll = [[int(y) for y in x] for x in open(inf).read().strip().split('\n')]
|
||||
|
||||
def inr(pos, arr):
|
||||
return pos[0] in range(len(arr)) and pos[1] in range(len(arr[0]))
|
||||
|
||||
q = [(0, 0, 0)]
|
||||
costs = {}
|
||||
while True:
|
||||
cost,x,y = q[0]
|
||||
if x==len(ll)-1 and y==len(ll[0])-1:
|
||||
print(cost)
|
||||
break
|
||||
q=q[1:]
|
||||
for xx,yy in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
|
||||
if inr((xx,yy),ll):
|
||||
nc = cost + ll[xx][yy]
|
||||
if (xx,yy) in costs and costs[(xx,yy)]<=nc:
|
||||
continue
|
||||
costs[(xx,yy)]=nc
|
||||
q.append((nc,xx,yy))
|
||||
q = sorted(q)
|
||||
|
||||
ll = [[int(y) for y in x] for x in open(inf).read().strip().split('\n')]
|
||||
|
||||
def inr(pos, arr):
|
||||
return pos[0] in range(len(arr)) and pos[1] in range(len(arr[0]))
|
||||
|
||||
expanded = [[0 for x in range(5*len(ll[0]))] for y in range(5*len(ll))]
|
||||
|
||||
for x in range(len(expanded)):
|
||||
for y in range(len(expanded[0])):
|
||||
dist = x//len(ll) + y//len(ll[0])
|
||||
newval = ll[x%len(ll)][y%len(ll[0])]
|
||||
for i in range(dist):
|
||||
newval+=1
|
||||
if newval==10:
|
||||
newval=1
|
||||
expanded[x][y] = newval
|
||||
|
||||
ll = expanded
|
||||
|
||||
q = [(0, 0, 0)]
|
||||
costs = {}
|
||||
while True:
|
||||
cost,x,y = q[0]
|
||||
if x==len(ll)-1 and y==len(ll[0])-1:
|
||||
print(cost)
|
||||
break
|
||||
q=q[1:]
|
||||
for xx,yy in [(x+1,y),(x-1,y),(x,y-1),(x,y+1)]:
|
||||
if inr((xx,yy),ll):
|
||||
nc = cost + ll[xx][yy]
|
||||
if (xx,yy) in costs and costs[(xx,yy)]<=nc:
|
||||
continue
|
||||
costs[(xx,yy)]=nc
|
||||
q.append((nc,xx,yy))
|
||||
q = sorted(q)
|
||||
10
2021/15.test
Normal file
10
2021/15.test
Normal file
@@ -0,0 +1,10 @@
|
||||
1163751742
|
||||
1381373672
|
||||
2136511328
|
||||
3694931569
|
||||
7463417111
|
||||
1319128137
|
||||
1359912421
|
||||
3125421639
|
||||
1293138521
|
||||
2311944581
|
||||
Reference in New Issue
Block a user