From 49fbe1677bf2959599861c89b89bd97ed75cde34 Mon Sep 17 00:00:00 2001 From: Zenn Date: Tue, 12 Sep 2023 10:07:47 +0200 Subject: [PATCH] added day 8 of 2022 --- .gitignore | 1 + 2022/day8/Cargo.lock | 7 +++ 2022/day8/Cargo.toml | 8 ++++ 2022/day8/data | 99 +++++++++++++++++++++++++++++++++++++++++++ 2022/day8/src/main.rs | 3 ++ 2022/day8/task.txt | 33 +++++++++++++++ 6 files changed, 151 insertions(+) create mode 100644 .gitignore create mode 100644 2022/day8/Cargo.lock create mode 100644 2022/day8/Cargo.toml create mode 100644 2022/day8/data create mode 100644 2022/day8/src/main.rs create mode 100644 2022/day8/task.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53f7426 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +**/target/ \ No newline at end of file diff --git a/2022/day8/Cargo.lock b/2022/day8/Cargo.lock new file mode 100644 index 0000000..0a523ad --- /dev/null +++ b/2022/day8/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "day8" +version = "0.1.0" diff --git a/2022/day8/Cargo.toml b/2022/day8/Cargo.toml new file mode 100644 index 0000000..4879259 --- /dev/null +++ b/2022/day8/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "day8" +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/2022/day8/data b/2022/day8/data new file mode 100644 index 0000000..59841ff --- /dev/null +++ b/2022/day8/data @@ -0,0 +1,99 @@ +222100000013112132123310430431410000421233203434334433324302430012114211021123030010201312000120201 +101021021033011112103044112003343322403423454241342342345211525113333240020143443122030210310022011 +220101001133100310002411002043420103515231215523212315435342111245041142130232312400222030320100112 +200122221230321133044100332034021325535145544344545253525534243453412331214043304401230010020110000 +000011200031133111412421443430224551211135242142233535513155431423245220314304114203010112113003022 +200110301031330240043404212112151455211214554251222423224121251245551231544200332324141021101302320 +211313310001120421114110031311134411225441423121215412315242313455445215433103243003331323232021210 +113023232323114232323200154111555445211221521564442455324451241134422414442353242422024301202303200 +033103132121042304342321133113123442114234244262244362254636514423544554241131340043413001103230111 +222130001131222313011514241155115431453566353362523635234523544443331545242212110302120041131331000 +122003333203421424243423241241145242362425662245243454434463245655424513432355342413342304140323132 +200132001433233414535423533545455356266563252323664634454642325452632535414233213444024120224001312 +103022000024242042232345311151252366645245625425252254664223635666456554424455255314414201023100202 +011123314401132331522443121124243332365536553533653266524244535435555642241321424311440431140002313 +112211332222044342251223514432453246552433654362667575535222222434424332333535551325510210012402111 +012034031201422433433544333435332354236525757766675753775672443526635625666411211315313431001211021 +222131010444144222113122265646535633254344346447355664747364675464264442356435454343134203131301320 +130204300400253551553414543245455464767455566634465767776436634753554635546252415422554253212302111 +003420010011545433455324656653655336363754663777466766534773337737564264622226622152541532444043422 +222443443245214511144624625533466765654637646677673764377774656447545424634555552322232123102200221 +131401122122541311136443466423774374674674644356633456444637564653463756534425365511222235542400434 +020304120343231311655625465655375336347635537637356474737537736475747664453654642435444421312003441 +330343204414214144663432532273356366677365344448485644668544447556754747333244226622353444432431203 +013032001213332124643646542366473765434545644448468456647846863656675334773653446336233442425343443 +032304344311244225545253365465763653568645444468586475857554557364567345453456433425434524425320340 +404422443241453445422422553656467636467787445444464844587867767885464476337762322652643443152400310 +423240415535414656342334546645767686856678584786777647846875755758745674346466423542354114134214444 +011030431533245543654555435345765747564477644667658776568874577764754567666746242522425334235523011 +304141431155466443263644746373647747866875877747665747457575464455646775674543326443642441231224201 +131114441112334443562775355733455774775467784987985795575544877666455543676676766355422441315441324 +430314423542533443234733353445778486466878667959585558576994644485858886644666446446534452214325144 +234043255111363462227473347477688468584489685978769565888875968868778767543673677363352531435143524 +332514411423345463663744673467787665769687998556765798696889899888747474874533436436252246354342354 +343351353455545565635555344675547864877967899959657795679897665768887566875734464464265463133152220 +304315235446623534567454757568755564666595669996877688899968576566787884766634473546655234425154332 +102434355126466525455775354887868447559596877755866959597666867668558485674655477534335455431433112 +122435322353564665545357554686754498985569558877879689779956877758645856774754544465455555411345432 +205343122436524456576336444487867565768865559989677777796577669975668468746773345355325355462321544 +244421231222553435356653847788488675876678988776997676698897689969586845444476467776346464255425235 +011141212323222656564355748565568698959878768999769698979687856698985667477447735736764436662535445 +341532114624343674454664747878669755789998777768669876776979978586767967487477444333746325646435514 +332225232253533547565768678777599889889986786676898889796886795899776746658866733634625566222131221 +452115152353553475665558585658666677868888996889998779787687898769796898574684366444335464566131241 +222451343363565554437346767558895565959796776666688967696988666679956757766466653747344422662412441 +352312532554653753433645874848668779969867679887889979966988777858759985688847467477436644343221314 +253453523324622576773348855746776868699997976897788898798988697688759757656674457764653663435535551 +255215136645533637445568746577666855796996998878787787989997666766965555455644774737474254653535431 +224553242555543337334785854657996797787699767987987877987767789767987655676757876444754463423354514 +123154243466644666546775557579585989696788969989777778898979998897985697866556637766477643365644322 +554211453455627676754574468848856965688687898898898987897889687869558659748577474654465642432212231 +121545355642566434543444766876559558799969877778988788897996978967956568566568437553533324624643533 +343533523352453757643688556467889769997789877997988888888997869785799657747877636573466342443313343 +514522335642537537375788876657768698786777789799788789989868878986986599667677637644366254666343342 +445132523635445577344646447787655657998679778899778887789986767685689896766667567376634235626522255 +531432262653342445554787675779556895668677679888998898998979898688885658645488775453563263324444521 +244354252355562565357375758886677896998668697778978777786868797957956585645446465464342453536315311 +331332542346565453565468588687898988998899678777778888987879896766957964458684767674732342255112134 +323222553252555764467548647586787989698798867966879898766777967895559878445748535555772564352323121 +222112256556444766665645575857868775966987669678797778989996976999597964558764436354464354454115511 +231521425424626436644777445867799777875677879667696879686889969989898845765485563646336643234131352 +355133253664246535564564876446795699978678666879799996766969886966786964656655463556453424246325411 +032153423465433637445644746455668795767666979897978979967667987866677885867645774566445534632451125 +023153145454343367456365744778545786785687966678788897768987767885867756448666544363445625242522531 +433143232524343347377744757586847855967999597666986986999686668885676754478777454637243455342311532 +041445134126223465774744566767745475776968756578667896988697555595776655546733433735653653432132233 +221512433144443536474554676654665445558779696796579879876998998776465745558346764543545453644144545 +331424235262424426737544466746485788568786659757689559959759667768655887786744476475525364623425533 +320451531315362426576743675876464666456576667575695897756879976656668566874643454335445262114444554 +433151555354653533355456563775468744778576966965557755996597568885868445653464345446225342143132550 +214125323355543252463774664575887864646475575755776587586666976564488546433557465425532665321234540 +200323512352523254535467534457646558758856986957578658768964788848786647657766457454556542424151320 +321332134211123223226667643735764455548668485865685588886847485767774746455657633463665254121412001 +012234315531464554245247467735667568768477464845687764665675656887448367475433732636565224541321012 +301234542341223435424426747367366544565566848548747578766588788767885775664437356522235353533143014 +334003331234445455322432564335463367457486487588666685866765755644646453645643652462624434432442422 +042143134435444325324432335637663775578547578854666475667787688784544634336532242223445252453531242 +310411334152432163553225536747773333656667455878457766657566745435666777454323262242612514451104020 +240402042351343515263253256753473577367758467858666457875545437655464455452535563554421221153321201 +140230434512144443255324466566375735664375475557548858557333643346544766626556653552352331343211204 +103332424311424141626635455553663773455334335637373374565743454773345777455425656462325511551200242 +300034243213121311233252524644436354656563557344777363377675636366463362642532235453325525444412244 +212242021025345333222565653434654746356455755667665757547556664465433533346662654353424311001014101 +131101234311553242452666635432665533633753765643655666636643433754534354353642634345311333033143214 +230232130130231122325124444645225546335344735745337356445573656773545235424533233332544531130001441 +203302312432313112332152223225462333636474337343366375747734333244655463653321433443325513101324303 +220234041400202455245214462454254525365333654447453545675644632235454662344232215321554320103020310 +200010034012032125113513354322342432455256556433373774556434252645545426455143411452141404444030212 +100330134044341121214144343523422253634565324653336633436226523634446353531514354335531412332131232 +130332044322000001512111255442345646456454345262564366666436346533225534443132355523003421120002002 +113132210324301312214421141434544636364655266265645646422544566424244551313122432513114113023320010 +112132020021120122422112434111115365555664632265464656245333363252541131215331552444402413142001121 +203112202340410440414115311114515245122424246432322362425453662652145112443553123122131302001031212 +230300331323432142203321123243444245342565365466665664464243251544455253512331101201042041220200212 +023003202312212103443344553251225314354244313342234634552312313531432211135354024130442013121321330 +202322100120313004402231123343531111133245451514414545333322414215353123341412440243322310212031021 +221023032132103304434414013211335214155422221314144114325152225215522555512120322411330301131003022 +201103233233322020210340012040333235122454154134514325421433512223435543144431413040233113023112011 +221021131310123213123044244400331522512444434344354343132442132331145324334003431424001200033011112 +102201030320220211144211104323434023533353133112145253453525542112011403201223032223120103003122001 diff --git a/2022/day8/src/main.rs b/2022/day8/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/2022/day8/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/2022/day8/task.txt b/2022/day8/task.txt new file mode 100644 index 0000000..89ef5fb --- /dev/null +++ b/2022/day8/task.txt @@ -0,0 +1,33 @@ +--- Day 8: Treetop Tree House --- + +The expedition comes across a peculiar patch of tall trees all planted carefully in a grid. The Elves explain that a previous expedition planted these trees as a reforestation effort. Now, they're curious if this would be a good location for a tree house. + +First, determine whether there is enough tree cover here to keep a tree house hidden. To do this, you need to count the number of trees that are visible from outside the grid when looking directly along a row or column. + +The Elves have already launched a quadcopter to generate a map with the height of each tree (your puzzle input). For example: + +30373 +25512 +65332 +33549 +35390 + +Each tree is represented as a single digit whose value is its height, where 0 is the shortest and 9 is the tallest. + +A tree is visible if all of the other trees between it and an edge of the grid are shorter than it. Only consider trees in the same row or column; that is, only look up, down, left, or right from any given tree. + +All of the trees around the edge of the grid are visible - since they are already on the edge, there are no trees to block the view. In this example, that only leaves the interior nine trees to consider: + + The top-left 5 is visible from the left and top. (It isn't visible from the right or bottom since other trees of height 5 are in the way.) + The top-middle 5 is visible from the top and right. + The top-right 1 is not visible from any direction; for it to be visible, there would need to only be trees of height 0 between it and an edge. + The left-middle 5 is visible, but only from the right. + The center 3 is not visible from any direction; for it to be visible, there would need to be only trees of at most height 2 between it and an edge. + The right-middle 3 is visible from the right. + In the bottom row, the middle 5 is visible, but the 3 and 4 are not. + +With 16 trees visible on the edge and another 5 visible in the interior, a total of 21 trees are visible in this arrangement. + +Consider your map; how many trees are visible from outside the grid? + +Awnser Part 1: \ No newline at end of file