diff --git a/7.py b/7.py new file mode 100644 index 0000000..964293e --- /dev/null +++ b/7.py @@ -0,0 +1,45 @@ +import string + +import aoclib + +from pathlib import PurePath + + +inp = aoclib.get_input(7, parser=aoclib.parse_lines) + + +class FileSystem: + def __init__(self, shell_log: list[str]): + fs = {"/": {}} + cwd = PurePath() + for line in shell_log: + if line.startswith("$"): + _, cmd = line.split(" ", maxsplit=1) + if cmd.startswith("cd"): + _, to = cmd.split(" ") + if to == "..": + cwd = cwd.parent + else: + cwd /= to + else: # is ls output + if line.startswith("dir"): + _, dirname = line.split(" ") + else: + size, name = line.split(" ") + + +def part1(): + total = 0 + for line in inp: + if line[0] in string.digits: + size, _ = line.split(" ") + total += int(size) + + return "haha fuck this day, im not doing it" + + +def part2(): + ... + + +aoclib.main(part1, part2) diff --git a/8.py b/8.py new file mode 100644 index 0000000..be7095d --- /dev/null +++ b/8.py @@ -0,0 +1,101 @@ +import aoclib + + +inp = aoclib.get_input(8, parser=aoclib.parse_lines_with_func(lambda line: [int(c) for c in line])) + + +class Forest: + class Directions: + UP = (-1, 0) + DOWN = (1, 0) + LEFT = (0, -1) + RIGHT = (0, 1) + ALL = (UP, DOWN, LEFT, RIGHT) + + def __init__(self, grid): # assumes rect grid + self.grid = grid + self.max = (len(grid[0]), len(grid)) + + def is_tree_visible(self, x: int, y: int): + return any([self._tree_visible_from(direction, x, y) for direction in self.Directions.ALL]) + + def _tree_visible_from(self, direction, x, y): + main = self._get_tree(x, y) + others = self._get_all_trees_in_dir(direction, x, y) + return all([o < main for o in others]) + + def _get_all_trees_in_dir(self, direction, x, y): + trees = [] + dx, dy = direction + while True: + x += dx + y += dy + tree = self._get_tree(x, y) + if tree is not None: + trees.append(tree) + else: + return trees + + def scenic_score_for_pos(self, x, y): + prod = 1 + for d in self.Directions.ALL: + prod *= self._get_scenic_score_in_dir(d, x, y) + if prod == 0: + break + return prod + + def _get_scenic_score_in_dir(self, direction, x, y): + house = self._get_tree(x, y) + count = 0 + for tree in self._get_trees_in_dir_iter(direction, x, y): + count += 1 + if tree >= house: + break + + return count + + def _get_trees_in_dir_iter(self, direction, x, y): + dx, dy = direction + while True: + x += dx + y += dy + tree = self._get_tree(x, y) + if tree is not None: + yield tree + else: + break + + def _get_tree(self, x, y): + if x < 0 or y < 0: + return None + try: + return self.grid[y][x] + except IndexError: + return None + + +def part1(): + f = Forest(inp) + xmax, ymax = f.max + count = 0 + for x in range(xmax): + for y in range(ymax): + if f.is_tree_visible(x, y): + count += 1 + + return count + + +def part2(): + f = Forest(inp) + xmax, ymax = f.max + highest = 0 + for x in range(xmax): + for y in range(ymax): + if (current := f.scenic_score_for_pos(x, y)) > highest: + highest = current + + return highest + + +aoclib.main(part1, part2) diff --git a/inputs/7 b/inputs/7 new file mode 100644 index 0000000..e60b95e --- /dev/null +++ b/inputs/7 @@ -0,0 +1,1087 @@ +$ cd / +$ ls +dir fwbjchs +dir hmnpr +dir jtrbrcjl +dir lcgv +dir ldqc +dir vrvl +$ cd fwbjchs +$ ls +154619 wqdlv.mdw +21648 wvbnz +$ cd .. +$ cd hmnpr +$ ls +178623 rftqqsrp.bfm +$ cd .. +$ cd jtrbrcjl +$ ls +dir nmbfwc +dir whqb +$ cd nmbfwc +$ ls +242645 lcgv +256365 wdzw.drg +$ cd .. +$ cd whqb +$ ls +161522 mrqgpv.gsm +48062 vpsgcl.gfh +$ cd .. +$ cd .. +$ cd lcgv +$ ls +dir cthtlwds +dir grldv +dir lnztfr +dir vwhf +dir znmzg +$ cd cthtlwds +$ ls +dir dghvw +dir tfwgg +$ cd dghvw +$ ls +107090 jmj.lzh +$ cd .. +$ cd tfwgg +$ ls +dir ddnfmsjc +252616 fvj +dir gng +dir lcgv +234528 mpb +181198 pzqgf.cjd +dir svvz +$ cd ddnfmsjc +$ ls +dir hwmcsdvt +dir lcgv +$ cd hwmcsdvt +$ ls +208912 wdzw.drg +$ cd .. +$ cd lcgv +$ ls +47252 tnd.ztd +$ cd .. +$ cd .. +$ cd gng +$ ls +44313 pzqgf.cjd +$ cd .. +$ cd lcgv +$ ls +182616 wdzw.drg +$ cd .. +$ cd svvz +$ ls +86968 sqtggfv +33927 vfmltgs +$ cd .. +$ cd .. +$ cd .. +$ cd grldv +$ ls +145761 mrqgpv.gsm +dir wqdlv +$ cd wqdlv +$ ls +96902 jhmsp +157064 mrqgpv.gsm +$ cd .. +$ cd .. +$ cd lnztfr +$ ls +137978 bpq +180941 fvpfmwn +148685 hsg.qgj +865 mrqgpv.gsm +$ cd .. +$ cd vwhf +$ ls +dir bgtgqzz +dir fcwzw +dir lcgv +dir mrlvtb +116134 mrqgpv.gsm +dir wszvqd +$ cd bgtgqzz +$ ls +dir dzpjg +283411 nmbfwc +dir smhhzq +240602 ttlbcssq +$ cd dzpjg +$ ls +75545 cmfw.gsj +189219 lcgv.chq +255580 lqndrsh.szf +175733 mrqgpv.gsm +$ cd .. +$ cd smhhzq +$ ls +137259 thjwcz.qhn +$ cd .. +$ cd .. +$ cd fcwzw +$ ls +59717 tpljg +$ cd .. +$ cd lcgv +$ ls +148881 mrzcdzd.gjt +68671 pzqgf.cjd +242866 slpftp +89945 vpsgcl.gfh +196497 wdzw.drg +$ cd .. +$ cd mrlvtb +$ ls +40003 rfzrwc.zjn +$ cd .. +$ cd wszvqd +$ ls +dir bhhtbv +dir lcpvwdq +$ cd bhhtbv +$ ls +dir fbh +248604 ldscpjmp +dir nmbfwc +$ cd fbh +$ ls +256295 vpsgcl.gfh +$ cd .. +$ cd nmbfwc +$ ls +83799 lcgv.vfc +$ cd .. +$ cd .. +$ cd lcpvwdq +$ ls +dir lwhq +212569 rfzrwc.clp +23957 wdzw.drg +$ cd lwhq +$ ls +240867 fzrwpl.hqd +68771 mzsqgswh +88777 pqtqv.qwz +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd znmzg +$ ls +30277 gltpwzg.gjd +211983 wdzw.drg +$ cd .. +$ cd .. +$ cd ldqc +$ ls +dir dnzfqzwv +dir dvshtm +97119 gdnlwmbf +dir gqb +dir jclb +dir jgbsw +115989 lcgv.hlf +255836 lchqqdh.wrn +dir qtdlb +dir rmljszcj +dir tqwpmw +dir vhdgcsw +$ cd dnzfqzwv +$ ls +dir tqv +$ cd tqv +$ ls +139984 dwhz.nhz +240411 pzqgf.cjd +129386 rnnr +190691 svgwt.mql +$ cd .. +$ cd .. +$ cd dvshtm +$ ls +dir lcgv +96767 mrqgpv.gsm +dir qdmmpq +$ cd lcgv +$ ls +82949 bldf.hwn +$ cd .. +$ cd qdmmpq +$ ls +dir lzgwflt +dir vgrdpbg +$ cd lzgwflt +$ ls +148651 tndbwbh +$ cd .. +$ cd vgrdpbg +$ ls +dir wqdlv +$ cd wqdlv +$ ls +130393 rqjc.dnr +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd gqb +$ ls +dir jtf +dir lvwpqs +212592 mrzcdzd.gjt +70051 tqpwdwm.nzz +dir vznbng +52226 wbsdrsfh.tfw +$ cd jtf +$ ls +232635 lvpccb.dmm +105086 wdzw.drg +$ cd .. +$ cd lvwpqs +$ ls +124821 dmhqlt +265915 mrqgpv.gsm +45481 pzqgf.cjd +$ cd .. +$ cd vznbng +$ ls +42179 nrzcpgvl.jft +17752 tld.ghn +174859 zvqglbw.ppl +$ cd .. +$ cd .. +$ cd jclb +$ ls +dir bnz +dir dtmtvbw +dir hnlrtpbz +dir pbb +dir vhjwtq +dir vpfggv +dir zmflq +$ cd bnz +$ ls +199447 mrzcdzd.gjt +$ cd .. +$ cd dtmtvbw +$ ls +dir bjthn +dir hzlhz +dir zmflq +$ cd bjthn +$ ls +272777 pgqfn.tdd +$ cd .. +$ cd hzlhz +$ ls +50958 lcgv.gvq +$ cd .. +$ cd zmflq +$ ls +207442 rrnwns.zpf +15759 wdzw.drg +$ cd .. +$ cd .. +$ cd hnlrtpbz +$ ls +69788 jhqjs.sdj +219666 jljzp.mhf +137518 jqnfg +108183 shfjz.vnr +130164 vpsgcl.gfh +$ cd .. +$ cd pbb +$ ls +dir wqdlv +dir zmflq +$ cd wqdlv +$ ls +dir fgggwt +dir hrghbhj +dir nmbfwc +dir tgmqnq +146479 vpsgcl.gfh +dir wqdlv +$ cd fgggwt +$ ls +264892 wqdlv.zsp +$ cd .. +$ cd hrghbhj +$ ls +116698 bfwtbg +dir lcgv +92758 pzqgf.cjd +dir tsdjgt +284427 vpsgcl.gfh +229621 wqdlv.pml +dir zfjjncvd +$ cd lcgv +$ ls +30459 mrzcdzd.gjt +dir wqdlv +$ cd wqdlv +$ ls +78475 wdzw.drg +$ cd .. +$ cd .. +$ cd tsdjgt +$ ls +166330 jpfms +16410 tjswm.bqv +$ cd .. +$ cd zfjjncvd +$ ls +59841 mrqgpv.gsm +$ cd .. +$ cd .. +$ cd nmbfwc +$ ls +dir jtn +151403 mmjm +240129 mmsb +206021 nmbfwc.sds +84439 vpsgcl.gfh +dir wqdlv +dir zvnrwfhn +$ cd jtn +$ ls +23555 hmmt.gbb +$ cd .. +$ cd wqdlv +$ ls +69742 jppj.vvg +$ cd .. +$ cd zvnrwfhn +$ ls +242009 lcgv.bds +$ cd .. +$ cd .. +$ cd tgmqnq +$ ls +259985 bzqjt +46410 flsm.szr +dir lcgv +89561 npfmc.vqs +17503 vpsgcl.gfh +73719 wqdlv.gjn +$ cd lcgv +$ ls +dir dzfglmz +177553 ffvzsgz +dir ljt +216443 mrzcdzd.gjt +255381 nmbfwc +dir rplqnt +84061 zmflq.vlw +$ cd dzfglmz +$ ls +220883 dqbcfgfd +$ cd .. +$ cd ljt +$ ls +11842 rfzrwc.hpn +$ cd .. +$ cd rplqnt +$ ls +119893 lszmvzst.zng +$ cd .. +$ cd .. +$ cd .. +$ cd wqdlv +$ ls +dir chnpddzn +272999 hbhwqt.fsl +144546 jvhjnsz +dir ppsm +102615 pzqgf.cjd +dir swdnss +$ cd chnpddzn +$ ls +256977 pzqgf.cjd +dir wqdlv +$ cd wqdlv +$ ls +6565 hlcqgmj +$ cd .. +$ cd .. +$ cd ppsm +$ ls +238358 fvw.bzw +dir ggjnl +265010 mrzcdzd.gjt +201818 rfzrwc +dir ssggblm +$ cd ggjnl +$ ls +45841 nlnrrqf.fwn +$ cd .. +$ cd ssggblm +$ ls +276584 djqb.ngq +18926 lcgv +$ cd .. +$ cd .. +$ cd swdnss +$ ls +dir bmrzhjs +$ cd bmrzhjs +$ ls +269825 mrqgpv.gsm +3162 rdmbdwq.bmv +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd zmflq +$ ls +dir hnrnldw +dir lcgv +dir mpmcghz +dir nbbv +dir qsnfzp +dir tntnjg +dir wqdlv +$ cd hnrnldw +$ ls +102631 wjbbjwtm.vvz +$ cd .. +$ cd lcgv +$ ls +dir dzz +dir hbzzf +dir jncrbhc +205204 lqnrp +dir mzzpfnr +dir nmbfwc +dir rfzrwc +dir rnrmhfz +dir zmflq +$ cd dzz +$ ls +dir cvvdv +226221 nggtqdzn +94641 npmpjnjm.bzg +dir rsdw +dir sjrb +41983 vfdz.ngz +271561 zmflq.zsc +$ cd cvvdv +$ ls +64260 hhqv.tsg +31245 pzqgf.cjd +280268 znjjp +$ cd .. +$ cd rsdw +$ ls +dir lcgv +$ cd lcgv +$ ls +37080 nmbfwc +$ cd .. +$ cd .. +$ cd sjrb +$ ls +233530 mrqgpv.gsm +$ cd .. +$ cd .. +$ cd hbzzf +$ ls +36018 mrqgpv.gsm +$ cd .. +$ cd jncrbhc +$ ls +205345 mrqgpv.gsm +244683 nqpcpt +$ cd .. +$ cd mzzpfnr +$ ls +dir hmjzlr +dir lcgv +dir mczs +dir wqdlv +90391 wqdlv.pdr +144119 zmflq +$ cd hmjzlr +$ ls +268342 svsd.jcd +$ cd .. +$ cd lcgv +$ ls +dir pwhl +dir rfzrwc +$ cd pwhl +$ ls +42795 gvmt +82576 wdzw.drg +$ cd .. +$ cd rfzrwc +$ ls +dir jjl +dir mqp +156985 mrqgpv.gsm +dir wptr +dir wqdlv +$ cd jjl +$ ls +dir jrjjr +104785 nmbfwc +20108 wdzw.drg +$ cd jrjjr +$ ls +243753 hgndlcrv.wbc +$ cd .. +$ cd .. +$ cd mqp +$ ls +142621 cljnbs +$ cd .. +$ cd wptr +$ ls +46279 vjqlvhrh.njr +$ cd .. +$ cd wqdlv +$ ls +104474 vpsgcl.gfh +$ cd .. +$ cd .. +$ cd .. +$ cd mczs +$ ls +186843 mrqgpv.gsm +dir pjm +dir thbwb +$ cd pjm +$ ls +dir wqdlv +$ cd wqdlv +$ ls +201647 sgtt +$ cd .. +$ cd .. +$ cd thbwb +$ ls +146494 mrqgpv.gsm +$ cd .. +$ cd .. +$ cd wqdlv +$ ls +103876 mrqgpv.gsm +$ cd .. +$ cd .. +$ cd nmbfwc +$ ls +dir fgctdds +dir rwgscjbv +$ cd fgctdds +$ ls +205015 bwvshdcz.dpp +$ cd .. +$ cd rwgscjbv +$ ls +242899 rbmtfdhp +$ cd .. +$ cd .. +$ cd rfzrwc +$ ls +dir bnsgzwhn +228624 ffj +dir lcgv +dir rcvwcbfd +268775 vbhsh.nnz +129373 vpsgcl.gfh +68919 wqdlv +dir wqmdw +dir zmflq +153277 zmflq.frv +$ cd bnsgzwhn +$ ls +9892 ltcrrzhb.njc +dir wpwmflr +dir zmflq +$ cd wpwmflr +$ ls +274142 bfj.fbw +dir rfzrwc +dir srnm +$ cd rfzrwc +$ ls +161517 mrqgpv.gsm +dir zbhgwsd +$ cd zbhgwsd +$ ls +43750 vbqmpbcr.zwz +$ cd .. +$ cd .. +$ cd srnm +$ ls +dir rvvtgr +$ cd rvvtgr +$ ls +164604 wzgbzbn +$ cd .. +$ cd .. +$ cd .. +$ cd zmflq +$ ls +184482 mrqgpv.gsm +80280 pzqgf.cjd +183303 zln.tbm +$ cd .. +$ cd .. +$ cd lcgv +$ ls +dir lcgv +dir pqttlp +$ cd lcgv +$ ls +dir bpjzg +$ cd bpjzg +$ ls +99853 wdzw.drg +$ cd .. +$ cd .. +$ cd pqttlp +$ ls +dir bgvhcgfn +45115 mrzcdzd.gjt +248058 qnvhgpw.ddw +112129 rfzrwc +$ cd bgvhcgfn +$ ls +228291 nmbfwc.gqj +$ cd .. +$ cd .. +$ cd .. +$ cd rcvwcbfd +$ ls +dir vtrtt +dir wgp +$ cd vtrtt +$ ls +138009 pzqgf.cjd +dir ztsvzpn +$ cd ztsvzpn +$ ls +51632 vpsgcl.gfh +$ cd .. +$ cd .. +$ cd wgp +$ ls +81030 lcgv.zhv +$ cd .. +$ cd .. +$ cd wqmdw +$ ls +dir zmrdf +$ cd zmrdf +$ ls +dir qqgw +$ cd qqgw +$ ls +58554 gqpqvplc.zvr +$ cd .. +$ cd .. +$ cd .. +$ cd zmflq +$ ls +224544 mrzcdzd.gjt +254976 pzqgf.cjd +$ cd .. +$ cd .. +$ cd rnrmhfz +$ ls +19759 lcgv.stz +$ cd .. +$ cd zmflq +$ ls +22390 nftzlqg.qmp +80148 wqdlv +$ cd .. +$ cd .. +$ cd mpmcghz +$ ls +169324 mrqgpv.gsm +65924 wdzw.drg +$ cd .. +$ cd nbbv +$ ls +115297 bqcrc.prw +58148 pvzv.qwf +dir wqdlv +$ cd wqdlv +$ ls +145268 mrzcdzd.gjt +35745 nmbfwc.hgv +112142 wqdlv +$ cd .. +$ cd .. +$ cd qsnfzp +$ ls +241308 nmbfwc.hmg +$ cd .. +$ cd tntnjg +$ ls +19543 mrqgpv.gsm +667 wqdlv +$ cd .. +$ cd wqdlv +$ ls +dir dqpgtmdl +dir jrqsqrv +189727 mrzcdzd.gjt +dir rfzrwc +208280 vpsgcl.gfh +281557 vwsljgn.mwd +119829 zmflq.hgd +$ cd dqpgtmdl +$ ls +268413 qcw.slb +$ cd .. +$ cd jrqsqrv +$ ls +238387 mvllmjc.wvm +213020 nqp.gdr +157257 nzdmplg.zqh +dir ppwcgc +24914 pzqgf.cjd +dir zjr +dir zmflq +$ cd ppwcgc +$ ls +249714 bsrnnhrr.spq +dir cvnd +$ cd cvnd +$ ls +248610 pzqgf.cjd +$ cd .. +$ cd .. +$ cd zjr +$ ls +224145 smwb.mmz +$ cd .. +$ cd zmflq +$ ls +250519 ftggp +147304 vpsgcl.gfh +238706 wdzw.drg +258323 wqdlv.bjp +dir wqgngf +$ cd wqgngf +$ ls +14302 bdz.jdw +dir jpgfsgd +dir ldwgr +22718 nwfh.nzf +$ cd jpgfsgd +$ ls +dir lcgv +dir qbrwz +$ cd lcgv +$ ls +284229 qhwc.zpq +dir wsjs +$ cd wsjs +$ ls +111635 lcgv +$ cd .. +$ cd .. +$ cd qbrwz +$ ls +199057 gpssftw.wdb +$ cd .. +$ cd .. +$ cd ldwgr +$ ls +260404 gdnpg.vjb +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rfzrwc +$ ls +dir lmcg +$ cd lmcg +$ ls +32819 sjjztgr.rfj +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd vhjwtq +$ ls +dir qgqbrv +$ cd qgqbrv +$ ls +176900 gwbnqtn.rnj +$ cd .. +$ cd .. +$ cd vpfggv +$ ls +144809 cmc.srv +117565 nhddq.bqn +dir scw +dir tpmnhdc +dir vvp +71774 wqdlv.gdm +61647 zmflq +174026 zmflq.wzn +$ cd scw +$ ls +2295 bqbsrj.gnc +243386 mfmdqhh.mzl +$ cd .. +$ cd tpmnhdc +$ ls +dir fjwr +dir lcllz +dir nmbfwc +$ cd fjwr +$ ls +133256 pwgtqz.dpm +159987 vpsgcl.gfh +$ cd .. +$ cd lcllz +$ ls +dir flwws +210654 qmbfw.bsv +dir zmflq +$ cd flwws +$ ls +222222 nmbfwc.vhj +$ cd .. +$ cd zmflq +$ ls +235011 jlzfbt.wlb +49525 rfzrwc.fnc +$ cd .. +$ cd .. +$ cd nmbfwc +$ ls +133730 dqdqhvm +dir lcgv +188291 nmbfwc.qhv +110039 wdzw.drg +249996 wqdlv +dir zmflq +dir zppcvq +$ cd lcgv +$ ls +dir wths +$ cd wths +$ ls +120313 jdbtlf.rrn +$ cd .. +$ cd .. +$ cd zmflq +$ ls +124906 dqdcpzh +$ cd .. +$ cd zppcvq +$ ls +112537 mrzcdzd.gjt +$ cd .. +$ cd .. +$ cd .. +$ cd vvp +$ ls +dir fsw +194927 hvlm.pbd +dir nmbfwc +230376 pgsq +$ cd fsw +$ ls +111889 nmbfwc.smt +dir rfzrwc +$ cd rfzrwc +$ ls +282718 gbvss +$ cd .. +$ cd .. +$ cd nmbfwc +$ ls +dir fvh +160971 ngqvztv.hfg +dir rfzrwc +$ cd fvh +$ ls +256956 mrqgpv.gsm +14363 vbvsncs.jjw +172959 wdzw.drg +$ cd .. +$ cd rfzrwc +$ ls +257264 vpsgcl.gfh +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd zmflq +$ ls +10486 lbdtpnps.jhq +118145 rlgjvn.nvf +176390 wdzw.drg +$ cd .. +$ cd .. +$ cd jgbsw +$ ls +dir cfdljgh +214846 dwqdqv.ftq +dir rfzrwc +147094 vpsgcl.gfh +$ cd cfdljgh +$ ls +261471 mrqgpv.gsm +$ cd .. +$ cd rfzrwc +$ ls +dir fcvfw +dir gvqrwgrs +57417 zfqrqv.fvp +$ cd fcvfw +$ ls +279614 wdzw.drg +$ cd .. +$ cd gvqrwgrs +$ ls +dir sgfltf +$ cd sgfltf +$ ls +204207 mstlc.wtj +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd qtdlb +$ ls +dir gjpmcvwp +dir nsjlcmfz +dir wqdlv +$ cd gjpmcvwp +$ ls +dir cjjdzcwm +$ cd cjjdzcwm +$ ls +233873 pdnsrz.vfp +$ cd .. +$ cd .. +$ cd nsjlcmfz +$ ls +53472 nmbfwc +dir qvpj +$ cd qvpj +$ ls +150929 mrzcdzd.gjt +$ cd .. +$ cd .. +$ cd wqdlv +$ ls +dir qccsnjd +$ cd qccsnjd +$ ls +65908 hsrqhn.hjr +267802 zmflq.jdt +$ cd .. +$ cd .. +$ cd .. +$ cd rmljszcj +$ ls +dir jnstrbj +172566 nbtszsgl +dir wqdlv +$ cd jnstrbj +$ ls +232158 fgccmchh.wqg +236339 mrqgpv.gsm +281875 rfzrwc.sfd +$ cd .. +$ cd wqdlv +$ ls +58492 wdzw.drg +213853 wqdlv.zlz +$ cd .. +$ cd .. +$ cd tqwpmw +$ ls +92747 pzqgf.cjd +$ cd .. +$ cd vhdgcsw +$ ls +125104 crfw.sfv +dir flhbhzlt +139949 mrqgpv.gsm +dir rfzrwc +dir rnz +97174 zmflq.vpn +$ cd flhbhzlt +$ ls +282258 mrzcdzd.gjt +$ cd .. +$ cd rfzrwc +$ ls +dir lcgv +$ cd lcgv +$ ls +dir dlpng +dir glqrj +178245 lcgv +106863 nmbfwc.fgr +$ cd dlpng +$ ls +195950 rfzrwc +$ cd .. +$ cd glqrj +$ ls +248909 pzqgf.cjd +34214 vpsgcl.gfh +$ cd .. +$ cd .. +$ cd .. +$ cd rnz +$ ls +dir chfccv +dir cmsccq +dir zmflq +$ cd chfccv +$ ls +13688 mrqgpv.gsm +162142 vpsgcl.gfh +$ cd .. +$ cd cmsccq +$ ls +94122 dzpsltth +190025 rfzrwc +dir twqt +12230 wgghbcz.tph +60111 wqdlv +$ cd twqt +$ ls +109250 wdzw.drg +$ cd .. +$ cd .. +$ cd zmflq +$ ls +174075 wdzw.drg +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd vrvl +$ ls +dir pnfv +210089 rfzrwc +dir stcfmz +$ cd pnfv +$ ls +183315 rhmztnnh +$ cd .. +$ cd stcfmz +$ ls +115637 lcgv \ No newline at end of file diff --git a/inputs/8 b/inputs/8 new file mode 100644 index 0000000..eb781ab --- /dev/null +++ b/inputs/8 @@ -0,0 +1,99 @@ +002220021312231312222033343421330303240001434141231331323404031022114013434333010230221020221020022 +121122120202012020121043013102221221435521112422443242343123513341010302410221342010223030013102200 +000102113102200232304033323331230042243225545423222145155353323244444103030341114102200110230210210 +210000210011313230124421403131035424212553341224354235111554525424232312243334330011232213102110221 +011221213013233101202214421014211444113354135545433143234341354155455431402040121341332111001213200 +102011200323032042010300400433425523314114545134123354514144125244221425322110331241203233303212321 +102333112233124011310312033433351241332441511153434514142551252434413454525133430430232301313012101 +211211123303442031043123115213455152541435522242266645543311341343514541312331003041323121132333230 +001321210013322412003145152352533215251266535255436246225646232235155455213434510131104234003003222 +223300223021202423423443531414132551356424245326334266655533565213421321535315422410221142133031312 +222100212043241001125454253523452134533223365232264243252423323432612224141255512031323011313003103 +021121103403121443434132421553436423352664246453242666446362544432226535142445142544021324240001211 +133332012412432333133345415214366446545565543462332546664335363355632655443241344522421402100130202 +203311422144324333445534552346564665545464453356346434642563543262655253451122554135410444243311311 +322001144142332343512222522324564232262466666644733543366455434326365635422423142542532442322034233 +101313214102402432135211163436536554325523756753777636774442234646434532462532323552412110323232323 +001234101142053124341452526452436566623744636336343435367647546635623353553555534224231314214100212 +011340142113121313424442565642324364776443464557637463364534454646665424552553413532212514302012341 +131222200221422152343654426266433667545366347373774775466374344436764353332356464535514434324340110 +111003023342553555436244262523625335453474533637454347543437747544744452225334642442335223143444444 +321342121452254343244365542366665534457746575473573344454777777733474472444242626215251353540020101 +112143303315213335256234665554477437377636773577545734476555474364535534426563254464121321342443010 +234221035235112225663223532437466537576546445657685585555367446553357466742263556432335535233141333 +222423221324421313653564633554665443633556667677566864675574576677657463472426635262534215124024221 +324331152222354262443463537535377475436657674545875474876844577557734435563264343363652233415524410 +213342122353141336533663276453775344477647556654774756865757686866756357447742256452564542442334022 +031310253121515643256663543343774374464475868668856447745665786466775333667666543356266334544230111 +003414153141543253444633475333643566678746567545465484644456865746567655663777455623456224131310102 +330142523253452632255556734446376546656754857454455688868674648457646443377555553462454615251453442 +133235545322333532564577755447648846778644645755887995696448544647577553657663736532335515233432204 +334335524535365552354756376746487575645445659755695765666787544578886583475443775453346362431143131 +341031551123323343266454736348684858484889599858696567585876875856777548475375347666344435552535130 +330124132352653624374474564584845574667585775689557998777788587447485878554574675446242255332135430 +022332341314322336445375435566746866478875855558865695755978785575785875787557756366564323334355421 +422512114322233253336344454648844756687768565958568995898568666686676864785573463376463556254314532 +103452142442634255644464378667858765668577695986766569979865855566666464448666555466453356541352555 +241112442533463566644466384475785778588865998998987687878685758585665474766754566466245444341351111 +242331514626445247647536577786867686956757887867997868868565789798577586688475374636425346525131421 +243314253655642337357775774485658855797598667666899989967796597576898668686444477753324232232351154 +141212322533446654653434488448555885596757899977797669696788657787555457687585673655426445422433424 +342122455562335353366637887665858986966688896796677969888697689675958786488564747444335354224244114 +312551335256534266765767457478789957996778878677968997797796765897866875565887677747646635544512542 +211534134626623545346577744877677876857796986969678796966776968959655984565744445456734645346232512 +032231543234465677337374577887787968857667678778778977789989896785756795858858774466662336446214512 +324534154425536743565446458446858967886787686879898778778766688758858698485648874353672463266531234 +435134112333555443375367474578758968688997879997977798878668997879689696565868444476554256336155424 +415141242653322635673376487876767958867777897899878989988966688858578595645554834563765634653311443 +333153263566332363556565647675776889997977998798979989789779878767599668677764763567736353533453222 +324533443324323546474686475757577689889799697979879899988679887776859589545565675357363456543514214 +541212526226223464775746748666766598968767978778799799798889796767886998655687843577354334262542222 +254152122622335364377555764858997897878877898777778878987979889696555579776547754776646635325242443 +233322465646563366564454647465965779689999699998999997777987688766899995784766835357675264423235125 +535451544662624547343458788846585555988689797879987987777878766896757589544864553377356554234332115 +244155565332636373565485774649696779997697667779778999898989987886985757674786675646374345632323155 +541445123454425766545765876866698666699986888787877988888968997758669898748856774455664363534535245 +455333345362435745575658765456987788888989966788777799798897779657686755844678835677774462453432523 +221534413542463536734757867768888675877686879688897878998879669688977768885557754643352225526224333 +221234516433463336765777686785786979666796878779797869789769666688997978844648636667643543232444133 +332215426646234434537648668445869988799778678686878967687668768657879955656846347743656535222133422 +031553553463354667655574475474488786777686996886779777887886867775767548458866434657666522253512145 +331532316364356445453744448764666787785586687678778969697798769655779847465578374664546445324424334 +231442532632664337564767657644566986698596889799897977969897769799988688455757473356424325365512353 +411553532344436334565736755688777565758689667688779789696666578858657666568855774576363253255223545 +142243141626243333657765468644745995798775976978979869767759758699574774455763666347225335254143154 +434542532345526233743743645456757487695765886898969876785665857797756868557564677455336336551245453 +242111213336234342634744347655654759597665895975786988997859879785674785466364664476642426523334413 +240432541545646555637655375878747648689956699797668787668987857785877748855353544573343263423351451 +233353541126663465447637576756467765799985779857685597778958855944587564657567344425653566513324251 +202133125415524635556354365368576748667886559966988689898777998784678575655573455765246634331111323 +214241132111456463244677753468567888865459986568778556756857554488444844574373477643253433514113414 +404043331523632565246656343354566578548867897777799576599855576486586885647776646654645643421251434 +321431341441524644343774675764678486487885575766685789987548644455655465455574763334325643223532112 +312044135522435234264466734356344664746887668755765684564685544655877565747654532452656321312254240 +221443411432246553232444575537753577667488768677578665484847677754883754573376245624364553144524310 +333011355143132662522563635437666768647485448557477746476767655566765543476573262345334242422532040 +130221313353423632635345377635457345475858877766844478544578458753453567556654264564563111241221424 +420000412311333223455353344535675346674758458678588744648777864536643447536366432335235213533510131 +033211203422344216654546246576546347545346767685845774858574755653734736666352442234431433312122020 +420112221555544554533234236234734667465467566545488844644654555366376734646542254343325451511102040 +120131424153254535662246332535575674733567577374535555633745576736633645534235222461444514331311422 +213413130454123421355422255452563464655444643735457443555675634373377635255435222352513552212031020 +003020114244244432233353656455567667744454636765475774754663376447476625234623436352314413331402042 +324044223442544345113455525643466577777675355766774773637445365463522332325642562435514442142404141 +210441410124444533445153545634656623447563677736473335673574337754666335462353221213524122021303233 +220001402334314112552325546465543662455673446333744466773363533553456364646542224332314211402042433 +023121402021311422535432445424233646345224547753633435644474236362532444465321253221141144332413310 +323020230034123314134444533446535564436335465334366443566523243354226225646253351453120014034104303 +312321342442214055412542111145545344545643544554353232456465256462323445343525123442530123340220021 +123101342024104423223521423214332556563335635536633462555625643665222463242344244522332431230422020 +300202224124443140142225324453536234525546225346366434644466234244662333545341335424243412214111222 +230103311300324320142422532144424144356464635656343323243433326662623345523535351332140310322302320 +102213121041413130343312325141341341255366646363663225633336454234535134543235451400033131103312302 +220010012323010223213414114534555442121353366562642344263362424334153543414344531223433101022121003 +111303131132410340323210521254433532435211213444624335211322534254443353121223030123212013112122222 +221300032203340322340214302442511523252243154411411131132224142542512334245223323243012130220310111 +210202131021310312212042132343151311311552432124522351251323142332524114321412240003424203112223000 +120001230322001230123443443202113524332314432515141344214224414354425231021342403441230201112313220 +000101310102010302144343300032331251425155511533145124553435221424141440223210230440103301210001022 +111021010130123300013234210112002104312354542225421421441334253132031032244142134422332001101011222 \ No newline at end of file diff --git a/prompts/8 b/prompts/8 new file mode 100644 index 0000000..8bb3d2b --- /dev/null +++ b/prompts/8 @@ -0,0 +1,76 @@ +--- 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? + +Your puzzle answer was [full of wild kittens!]. + +--- Part Two --- + +Content with the amount of tree cover available, the Elves just need to know the best spot to build their tree house: they would like to be able to see a lot of trees. + +To measure the viewing distance from a given tree, look up, down, left, and right from that tree; stop if you reach an edge or at the first tree that is the same height or taller than the tree under consideration. (If a tree is right on the edge, at least one of its viewing distances will be zero.) + +The Elves don't care about distant trees taller than those found by the rules above; the proposed tree house has large eaves to keep it dry, so they wouldn't be able to see higher than the tree house anyway. + +In the example above, consider the middle 5 in the second row: + +30373 +25512 +65332 +33549 +35390 + + Looking up, its view is not blocked; it can see 1 tree (of height 3). + Looking left, its view is blocked immediately; it can see only 1 tree (of height 5, right next to it). + Looking right, its view is not blocked; it can see 2 trees. + Looking down, its view is blocked eventually; it can see 2 trees (one of height 3, then the tree of height 5 that blocks its view). + +A tree's scenic score is found by multiplying together its viewing distance in each of the four directions. For this tree, this is 4 (found by multiplying 1 * 1 * 2 * 2). + +However, you can do even better: consider the tree of height 5 in the middle of the fourth row: + +30373 +25512 +65332 +33549 +35390 + + Looking up, its view is blocked at 2 trees (by another tree with a height of 5). + Looking left, its view is not blocked; it can see 2 trees. + Looking down, its view is also not blocked; it can see 1 tree. + Looking right, its view is blocked at 2 trees (by a massive tree of height 9). + +This tree's scenic score is 8 (2 * 2 * 1 * 2); this is the ideal spot for the tree house. + +Consider each tree on your map. What is the highest scenic score possible for any tree? + +Your puzzle answer was [actually fun this time]. +