2022 day 8

This commit is contained in:
2022-12-08 21:44:04 +00:00
parent afcbbaea49
commit 4de4e05050
4 changed files with 186 additions and 2 deletions

99
2022/08/input Normal file
View File

@@ -0,0 +1,99 @@
230302102312303431324124303141114045300001501242156105363242032123135210143324224140132332112100221
322200120140130323143433402101444233512140224062422011111403231052521053542252401012232443102111032
220300201042003221454531141345330151415344324656555610153343240503352304331551230452141112120303320
131301034134041313145104311104431531104002136262204021050462633364005504230105333250310334430012231
021000431324243205221240551231546346005546113055526350502461501303260444304552521404504240012202100
130032042140100501120530551053341401664420533042546256013026351632616214431331333233341222140143402
102213021202104044154525451632332223320015014365014110000262152226451306654102512123512023131343201
331321033401405043214153225511265312435604105124767542760400104362304616510410004451235001241134031
234010022341252215202325124644011146300614531262461555623242615510132104506502155353245030411321214
304102101231325220244422554336626240225366453655233535214545356712401516453566460554521045401410034
124222310241022025221634021203456261377536264451547554432421672616632511164231351545110100421124041
231432431351552412035636562534314116212363155763515352233177566413166344310511112324524355103343213
103031123324141030040550165506212465546735652123674755314542271633361443500442335114204031255241224
320113443131100311503426244335257671411253247761166615472155473411374661621210160254602143000503002
003031503150544521324165216521624371212157515435232724117746343274255223574322040541222535240125320
431234101124435354234422257673575575175341283683836588272273446224536761435621240216142511140302323
123130200251405600130545412766211145442246588283778878426386645127335561311156623533260243441410122
432402514341626355125037245134531317588423262388855625822687585244364351651321623121561560010312113
312341305215255100304471152277172523637784345263433358277226635245516164123212336452605424200110430
001434330142034560665237211325533756327872855833882354736845633764265764254723135136216531341302425
345110412256633232261137637156368637757634446735753883783375577533786454271246611655350133245255344
130515311233246602623742771612278266785844368233445235428485736334867477631346361563230603123034134
330040046512436325746335744443684727248746257893478978476233834562664674872164576161101306065422041
222154026412500467311716243862854643768585738339383839693837627262625554423155651645532206206134414
542550455123342216235327358832483365754856794969568679863575688486863754828773355515541016335040545
404234533623052522751165344644483278684968464647937735374953694986883822877673474565215510426220344
314254353400344713147333655472357537587356967673598874457668767889935746887521663427411521635661241
250301522140303127537224263455464893375697787574446387685355687386368545878447447117247625662212301
531245634640354662654558667774728435789865389774334746464789766764944468568554351264634206163162541
254210565205047575772722425336239545866857335764867899689375964484886366575237326255114412442436305
254440240052645344117878758858477694934868449869846797495773435673485582766622343237654674230614650
302350056253421457757382352837655457348549979584868566587675763536549455773244366226575120110432202
524251410101643732555863746673768898357598988876769465556757759865678788677845447537546514520246465
412424366507365464723435562846447777556788564867748886999988659539789863738827284322243654235650222
302260630341726247764652638469957786688964699758599945666799457875988357894464748565724572166261234
215150213244237121847528247786444449998976749466844877974565875546766745893426378444445742710223525
424160233533557213425484474439489658786978977985856797555685676569553489768586885887425626363046446
153322066741372433344452464455559968984567799888687677756697744545783483874576867684647332571001005
145420124453223247785888737894569596698676567955697655669665679864796955354676474465373675660155614
033506450161333145373824444348436889577445897969987595896979686466678689467597644746532527513131131
225012522655144432763537973395798658496758867787886779885975689947696977368784268458336146373115143
216342537614133655675625959443677654855666875698895757965779667678777945996749485327555574145424460
166106344353256563624325443477776845578965867968867569996565856754694668864655545773383227234335414
150522031675635233237668486584959896545865765899786958699768689485564988376498275457676373151605464
412336103615667832572493349365459748765865988788966796676798558958658889874394465442751254315016610
352326617457732528434753466738454444568858687988678798897989789856878957499594873552874152661460523
062415331267566426437243673895878674897896558788889897878987955994767455333837536424584567627336053
411350266636525852438469567638886987958577976996868967687585597767547999698594634538245463464543005
052464462614766832722735867947598567878869668679877788879769878876988899643845375267672315514353000
543545564473648376567477376798669977686956967668898889969875757785956549649485643782434576251353131
634033674455736672452884665689654778778759896979877869977686568577555776433947564287374612267436364
620541245674573376723897469464969646966776677799787978979857977798869788359344972235473531452736105
602620347126374653254296764775476547797557857869988876878957998886476566934646536357683276776151421
453313013613244386884696349435758974966876787969887886879899685595858499393337785854825724737215563
633162016753461244685737989459664898569667899679799786798979988797998958559548885735471347141136630
000101426742225562735894769979656676989556887676998666978968879767489645833678358457422477754521142
620262606411662643533249376858748847498879757666997687879595676878844467633967768755461265735510400
360023137544654575733228376896988578467698566656988978959969695576685749457685864437734765717026064
453004005155344764583728835857979544659758957678779579869558958494954483997436423583442547122611144
542364512554772785834745874957646879945679759867877799887755596454644564849589474263221373377352410
002404034225236156254239388474876685554666797767767967895789558759867549659597464467365225556245635
245410135477125426663788797639838547747878866579559887665897566567957973945395387477415314463463430
134134265157751574644752634743354666668958565798799857969998998868959355953856752485414215452524346
134233063522723113742886693543696949958945798696986777765986578999899884698774475872617234240653423
244361001066345154366465584498936779955869489578987799745999756687935697875536775754117227145563503
424615513054521426726444456756894679964484855474988695686689467459399699543485425832215323565610231
010511022361177421578425884488933866869996559974758675556944646898573447548734866775441423552334113
455000614233131572534883424588896457684489858997764475858957676964979965647378323342574224433221410
554234433657562455545554335673953366894875796478846544767476975987878676385863745315342113644542314
334234343615275457652768335759749448996379787584585465788795884334949898848654742611353314261636503
333304555356366151638427333872998755488366686597689567687856687846596683534345663212543346305030250
221202454261633375664542356764698437549939857548989949987335436749598666277762261737227146546505534
240412550420563537276688628732843367868467736695759997434973759746799657483248636225432651522613045
234101415413036337546543888388563596433499988836578844689689497975764628525732325317653041241353030
431410263125326725415234754275746658476797893535668937455785755994425345326575247342241464251000421
235305105630506142127546572374764553754685586586673543349859396362874755756655416517334460144522501
053230360255455453432625173284836864837934635996948769536785973725832747476731215716516416145320150
220341023145561653434447455522778482225563875986777563368797985846552555226462623761223514365411344
555505021215644010564473315638562438843876455985785666379866472746877227331266714741141010601131000
453335252144616255521312353556677472322787423527747647554222386736627248134362414253412412531431213
042151015320560413551651234262565787675225582872838475557456742335545484137617276444245016450453552
014404334344615462565743465273746656366752555484464325685467246827267515345457117051354205241444340
213041551013263163616741653367152326275633684378845888827238722532735171772265542620411543050510551
224455113205603560061536164734146772822552432636277537568582283454552565546556622004610432104440414
120034300413036442405642132721761733145582724757284464865848374626544672733422446132110450322334043
321102323253550034451665134657546626247721386824348475375862731112516436572563504423615532222151203
423413023253053651012440232734663275166577433646527244777525111735773767313620631626060044333201413
310311122105544263022025236566616265144255413423733523634375771573412213343520014446112203251501244
242112304444105230054262221514232727536351532732445557376642241447573270443566533260102401044113312
300401122201443130504625604224103567247721576334262357161547725313757534624304442441502400005401420
312140241542522534423315456561105236441214136262754317657256235334116150340065011324403154142414212
144233324321121441233255150514400352347655162673141155544742475145632635002103305025150134340421444
111103103110050242122311312046534446626061741554364774752533752234163656421540312341011215100222430
303431234002202314522440214134041163045124514037641775350115015005306206502562310105314100032000400
022101131200322543535350013343206260166164021153334624135541245000601615213233143310354543221432032
233233001110344441512334010360062644015111403065346201116113310635016323603102000435213440203331333
221234200414024043305553013402501300310163441031202131631042043410330561032554522352320341422042103
321123401142123425525550311314256215506650120142506242614512364236453401432552531430304012423410223
122333244113420243051112411113522042223653563261365250113056645225530145055223432541231304233333203

40
2022/08/part1 Executable file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env python
TGRID = [] # heights
VGRID = [] # visibility
def check_visible(x, y, xr, yr):
target = TGRID[y][x]
for y in yr:
for x in xr:
if TGRID[y][x] >= target:
return False
return True
with open('input') as f:
for line in f:
l = []
for tree in line.rstrip():
l.append(int(tree))
TGRID.append(l)
max_y = len(TGRID)
for y in range(0, max_y):
max_x = len(TGRID[y])
l = []
for x in range(0, max_x):
l.append(
check_visible(x, y, range(0, x), range(y, y+1)) or # left to right
check_visible(x, y, range(x, x+1), range(0, y)) or # top to bottom
check_visible(x, y, range(max_x-1, x, -1), range(y, y+1)) or # right to left
check_visible(x, y, range(x, x+1), range(max_y-1, y, -1)) # bottom to top
)
VGRID.append(l)
count = 0
for row in VGRID:
for col in row:
if col:
count = count + 1
print(count)

45
2022/08/part2 Executable file
View File

@@ -0,0 +1,45 @@
#!/usr/bin/env python
TGRID = [] # heights
VGRID = [] # scenic score
def count_visible(x, y, xr, yr):
target = TGRID[y][x]
count = 0
for y in yr:
for x in xr:
if TGRID[y][x] >= target:
if x > 0 and y > 0:
count += 1
return count
count+=1
return count
with open('input') as f:
for line in f:
l = []
for tree in line.rstrip():
l.append(int(tree))
TGRID.append(l)
max_y = len(TGRID)
for y in range(0, max_y):
max_x = len(TGRID[y])
l = []
for x in range(0, max_x):
l.append(
count_visible(x, y, range(x, x+1), range(y-1, -1, -1)) * # north
count_visible(x, y, range(x+1, max_x), range(y, y+1)) * # east
count_visible(x, y, range(x, x+1), range(y+1, max_y)) * # south
count_visible(x, y, range(x-1, -1, -1), range(y, y+1)) # west
)
VGRID.append(l)
best_seen = 0
for y in range(0, len(VGRID)):
for x in range(0, len(VGRID[y])):
if VGRID[y][x] > best_seen:
best_seen = VGRID[y][x]
print(best_seen)

View File

@@ -9,7 +9,7 @@ a programming language I'm interested in learning more about.
2018, 2019, and 2020 were in their own separate repositories, but have been 2018, 2019, and 2020 were in their own separate repositories, but have been
`git subtree`'d into this one - no point creating a new repository every year. `git subtree`'d into this one - no point creating a new repository every year.
* [2022](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2022) 🌟 `14` - Python * [2022](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2022) 🌟 `16` - Python
* [2021](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2021) 🌟 ` 5` - Python * [2021](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2021) 🌟 ` 5` - Python
* [2020](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2020) 🌟 `20` - Javascript * [2020](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2020) 🌟 `20` - Javascript
* [2019](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2019) 🌟 `22` - Zig * [2019](https://code.ur.gs/lupine/advent-of-code/src/branch/main/2019) 🌟 `22` - Zig
@@ -18,6 +18,6 @@ a programming language I'm interested in learning more about.
* 2016 🌟 `16` - LISP? * 2016 🌟 `16` - LISP?
* 2015 🌟 ` 9` - Ruby? * 2015 🌟 ` 9` - Ruby?
Total: 🌟 `92` Total: 🌟 `94`
Maybe I'll backfill some of the old years one day. Maybe I'll backfill some of the old years one day.