This commit is contained in:
xenia 2022-12-08 00:23:58 -05:00
parent 459e836026
commit bbb31f624c
3 changed files with 170 additions and 0 deletions

66
8.rkt Normal file
View File

@ -0,0 +1,66 @@
#lang curly-fn racket
(require "scripts/aoc.rkt")
;; solution for day 8
(define (visible? grid y x)
(define h (vector-length grid))
(define w (vector-length (vector-ref grid 0)))
(define v (vector-ref (vector-ref grid y) x))
(cond
[(= 0 y) #t]
[(= 0 x) #t]
[(= (sub1 h) y) #t]
[(= (sub1 w) x) #t]
[else
(or
(for/and ([x* (in-range 0 x)])
(< (vector-ref (vector-ref grid y) x*) v))
(for/and ([x* (in-range (add1 x) w)])
(< (vector-ref (vector-ref grid y) x*) v))
(for/and ([y* (in-range 0 y)])
(< (vector-ref (vector-ref grid y*) x) v))
(for/and ([y* (in-range (add1 y) h)])
(< (vector-ref (vector-ref grid y*) x) v)))]))
(define (part1 input)
(define h (vector-length input))
(define w (vector-length (vector-ref input 0)))
(for*/sum ([x (in-range w)] [y (in-range h)]
#:when (visible? input y x))
1))
(define (part2 input)
(define h (vector-length input))
(define w (vector-length (vector-ref input 0)))
(define (scenic-score y x)
(define v (vector-ref (vector-ref input y) x))
(*
(for/sum ([x* (in-range (sub1 x) -1 -1)] #:final (>= (vector-ref (vector-ref input y) x*) v))
1)
(for/sum ([x* (in-range (add1 x) w)] #:final (>= (vector-ref (vector-ref input y) x*) v))
1)
(for/sum ([y* (in-range (sub1 y) -1 -1)] #:final (>= (vector-ref (vector-ref input y*) x) v))
1)
(for/sum ([y* (in-range (add1 y) h)] #:final (>= (vector-ref (vector-ref input y*) x) v))
1)))
(apply max
(for*/list ([y (in-range h)] [x (in-range w)])
(scenic-score y x))))
(define (parse fname)
(for/vector ([line (in-list (file->lines fname))])
(for/vector ([chr (in-list (string->list (string-trim line)))])
(- (char->integer chr) (char->integer #\0)))))
(module+ main
(define input (parse "inputs/8"))
(answer 8 1 (time (part1 input)))
(answer 8 2 (time (part2 input)))
(displayln "meow"))

99
inputs/8 Normal file
View File

@ -0,0 +1,99 @@
300030213213113240234210203330153124541151003015456312312442524531405533542450111443312103110220211
133000004421300341005340432514034555543556261543410250030436135103304323425502113341331442032311030
213121312230422241205230130541010120012561656126511652636160154566425231221254515542342023142010133
210020103232311410025023513110540633654032560666266266442224400244155120504322112255323444432301210
300221311013444150512444105105055122104524660253365233115442634642236455351502043504233200041232000
000000011130235121555143014441555205423003555504400645452656322632050035240315440035451003103431431
012142333141321404105321351332544222551046221101044054031533500165110422142125530252401331243211232
020213033022012453014033014405001564353352011316633456214232621532251606161624054400501054130430422
042314012030233125141141244243333123002627374716422264424361631360462131201236611502353523210122300
211224020402441314100154352420322456122364263545772174674761655261311042611615130513350241030243433
314424032332214322125462603406635133652272743472434161773175755665106156425610245350415311352303020
430442043211531134103213404455524724321332213636522224572442553173311265220261503235505013340341232
001001325232413003110430361654232165433226632435251776357256175725724566400520111500101504331132114
334412500412200403511523220032572737752127755542727442166375451622531763242464326501020110104340144
121243523444032105062316052754715461676111661333423221122752355145371142754413605365235134243015313
242330445052105423412660066474767425155231852584272588286671442475372464535465114141632114402431330
122050043214212560234014261446673143437367834853285853825877263146536255554162263165412530555001012
310254352155555362305652565245733333847537568334443567664745527772362543753627625001150411055105112
025031121433111201225651315747477674878824738825265832254676344282526441156537710545602456542112210
105541425514161020436715372516214235452255778656548556525666534284848751622646711602335633004210430
120403544243300210571653423576358224736356674473762873838666826244548367625153434754030101342121403
432020535536321653451132344347283847864642562823856582222257783373625252524642355422611066341041555
105515504230051446254242173357243344432244287653558393463636636527332375861462227252610460111541451
424315140455252444231317616735826624757676779939449898765575452676252735247362276562636111623005500
021423534431553132473112715725478325366953865554356694548876447733778524336511267122410032353204044
445423066641156261422146768782747848378447486547353679545953363787428372464325267535533614266344140
152411666100126757726562222726546749954446865366696449877979478486373233467373175176717065434502141
140202601300054474441768586442348397689388764774948539945648798559996563788746555346275261454103223
544203021060377313252177225245274373949438556349734495443338667684563463227487637566451205231151234
225400103300571274173335762334287864949875576664869759876374397685438976626326425644665160321405114
230314645445261324544678872478778643594945995976689844475579675835534645236636838337776723535345500
150534014520772265552634657365463588877484555578696496798458453663473396824266754637171242001256124
501401625205514213726356888877344586367477569695884664945598775858874867554835685452612772106263532
003545414654644264168635752867577699868859699658765954768468556893987864886348334776371465025135140
251042560617345355567763755683459686855588797756945758776799955744646686687652842535676751665034401
302210131663435613688532374877833645976757884777578755957476749797784636464388672831672655516160250
111065246313516415337376337787538574959786899487589688777994584659853384389926247746333354700561235
110414613452245538424336745356686988599756856889899665657755876955474687659467286778227144340035665
412353204671232672374342364957877787589988865788855789958795889895469566379993753537827253655122163
220455060636641757662657656485887468555667756998687885558888697575769544353438542486665473665353031
061302402574166188357244985755358964658897589996959669756655586556668978665737857647731571412663614
451215265723364666667225569887469777655996787798658577588667964644965767693668287254634774752440436
301215542714677435434258733978685986666878695679857768798658676786669569956767732852857361576404432
154623106155526744253836847466987985777579987895579899887867686679478588489549787628542237217621402
016326557476722738858767965394776546697557589788987986685897875855497888993584977357781252535652100
516434443771523825524465875344974794885887577968879977777596685889766469448884476765464722367346613
663333275643147748552476447559494596988869978768877866788776955886649886647734953675545514515635060
564446265661363787884698458539864897955876879789888686667667695889588654946548558665552464445515100
444635271445544486468235896595657574556796676868879879878987585894795697656985562654886247765264633
462165473462113357828755539386966448779857797769787979697957598754959785656563752733766632117233453
324114033531125766355764993645548777979758996876999867877675777569547846779389355565826361114230641
224200317716278667488649555774497597689687678896896677969958769969794969974689727365357612457234644
402622076242363764226695388365948877677669866868687967866668896555954488854868827247567131532732161
351431525533425423868437845597564857555568597698676776879667799897879746844566636356646565257121003
225616611661632445584357877765956764697568598699686698997669677996868665573893357436745717575725454
464505117521646733487884876599599666866788675666888876875979598579854747435497874323277332541546013
052114137625735662285578885579794999468569858977677679667685665987955489696478687578266127111546664
316613323223637567683247984347647849968985558977789767985598956679896995585799768687622276617221641
150200045167123286782287837679577787677797988695867797789687586558667574856533357756471257515363540
252244417323233175887456579833456748749996686798597998557665769755856789834546748233733443273254100
356160635747716144466869844679547594648877886665966889699566759455979998476485752287252722716164416
425166022644275152644747799869954648746958878589556668589768447767896344585634858425817452170565306
345366062117166733576545864397534485854779888658678987596689784695568398698547735888734716543316365
533535636242332164847587898599999846566885656697676699688759667965889473655654364846464567176441222
145156433556112342733574868953399368585597766648768658747699944777476969449428537232155673534436334
054406066337214353545756523343684448899669455797588778689784798466937584849358665356646637313111401
254230005511427461268747424696354657897679767675549867458844878496487636435757334231367213603232112
555355424332316775464478853457754765559478879676449464477968898464959946683563372221445526535034024
414023123606577152476576548378794456898548667574545479875668799757679333543655778735436732625602102
103425425660432324255388475439558538899897884857688985496679573943943844375486647275716474356544432
452130224302617716756636522262934655383939784956995477695867446373399748438345254577364313526363420
000042112640363475341785644528248693738497465445788948789539367488865954668672787612122734016622455
023111166642052271313457755228576545698943896555698897675589438943493564742233477111247522056555041
204431055441351336464513762857847353357853376696786639733989764484974246522527515321225331245432343
411113064641332752327456644465236399895559367589866764738365755795443834767856231524273551544613205
002003415151314635554646457575673343677789786935595493666738344866563385573637543752334431304230033
232000241320312557743676572825328454583544756367648459896978649838474485587354722365706253422641104
140032334604361016614454563867878852473268539588353455546354984764388862653617247612502644151343100
230313534421421354553535613177284354853423658747835975969372246355755687417111117262662010635050245
455442045443411622436616447216784738377874843272575735853775463446344736154635424345111430260111355
015553515233634200652274644243776752756254628443363283782332853857876372453144557606024162435425502
414231425344640401425671247313254225752325627774572863823427628435276621555353276003524346445135344
444014215230466136522431711445473522537227372726657772534226483275376766662531115626523414452105414
433450111244440640533563144151113117278453728882746574687858827886235133216737041020563315330400051
043413224423155241164263423653444422516645633847447523577743865447652437564632624466116150042552500
034343233153545155011601574561726663612576786744276243622471222711311674626123164654601253202230221
334424544214152026360221522751357747561434577416644336551153665531545226246342213505320031201441042
444213310102503010334251632366652423612713524641262137252252513732611325223401240210534434334020134
113234310313013130034263432336443446455536236436221526156612252522132633100613031453230501112202424
142402332004051013660101510101263126711727662153761423762243333777317301206400030653210431512111444
411034340051512350022551420314334411275415543216224154457677376654154362121625361111251523342230021
401212212311255150514520514410354360022337233263271545513775531712533425164554033545254524043033243
040034023233143153232242654250224010246422671266544421771125320425056106225340103411544104041430023
202210233034441525003330614323226104160433060432454154126634040116105426512145204401511210203422322
011431432013322542545215145526600364414641235513425454443064214552663664101101323545031512031302333
020023210301103025401200032420642652143243335333016204055261530250106466135400230513140242434444003
310203111441432251152455421244135150164323516554016042002411655305545265404525521215102013341240121
012320311100031143153052200224256541012135453345356532252242115324133425054343145333123421144111230
311310344433212432240252542030050542510636225454204032233645040015025321421052152330422440232330022

5
inputs/8-test1 Normal file
View File

@ -0,0 +1,5 @@
30373
25512
65332
33549
35390