From 64a31b5a052514d210c53a84b8425483e092bc2a Mon Sep 17 00:00:00 2001 From: Akumatic Date: Wed, 7 Dec 2022 19:51:29 +0100 Subject: [PATCH] 2022 Day 07 --- 2022/07/README.md | 109 ++++ 2022/07/code.py | 71 +++ 2022/07/input.txt | 1105 ++++++++++++++++++++++++++++++++++++++++ 2022/07/solution.txt | 2 + 2022/07/test_code.py | 19 + 2022/07/test_input.txt | 23 + 2022/README.md | 2 +- 7 files changed, 1330 insertions(+), 1 deletion(-) create mode 100644 2022/07/README.md create mode 100644 2022/07/code.py create mode 100644 2022/07/input.txt create mode 100644 2022/07/solution.txt create mode 100644 2022/07/test_code.py create mode 100644 2022/07/test_input.txt diff --git a/2022/07/README.md b/2022/07/README.md new file mode 100644 index 0000000..d132524 --- /dev/null +++ b/2022/07/README.md @@ -0,0 +1,109 @@ +# 2022 Day 07: No Space Left On Device +Copyright (c) Eric Wastl +#### [Direct Link](https://adventofcode.com/2022/day/7) + +## Part 1 + +You can hear birds chirping and raindrops hitting leaves as the expedition proceeds. Occasionally, you can even hear much louder sounds in the distance; how big do the animals get out here, anyway? + +The device the Elves gave you has problems with more than just its communication system. You try to run a system update: + +``` +$ system-update --please --pretty-please-with-sugar-on-top +Error: No space left on device +``` + +Perhaps you can delete some files to make space for the update? + +You browse around the filesystem to assess the situation and save the resulting terminal output (your puzzle input). For example: + +``` +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k +``` + +The filesystem consists of a tree of files (plain data) and directories (which can contain other directories or files). The outermost directory is called `/`. You can navigate around the filesystem, moving into or out of directories and listing the contents of the directory you're currently in. + +Within the terminal output, lines that begin with `$` are **commands you executed**, very much like some modern computers: + +- `cd` means **change directory**. This changes which directory is the current directory, but the specific result depends on the argument: + - `cd x` moves **in** one level: it looks in the current directory for the directory named `x` and makes it the current directory. + - `cd ..` moves **out** one level: it finds the directory that contains the current directory, then makes that directory the current directory. + - `cd /` switches the current directory to the outermost directory, `/`. +- `ls` means **list**. It prints out all of the files and directories immediately contained by the current directory: + - `123 abc` means that the current directory contains a file named `abc` with size `123`. + - `dir xyz` means that the current directory contains a directory named `xyz`. + +Given the commands and output in the example above, you can determine that the filesystem looks visually like this: + +``` +- / (dir) + - a (dir) + - e (dir) + - i (file, size=584) + - f (file, size=29116) + - g (file, size=2557) + - h.lst (file, size=62596) + - b.txt (file, size=14848514) + - c.dat (file, size=8504156) + - d (dir) + - j (file, size=4060174) + - d.log (file, size=8033020) + - d.ext (file, size=5626152) + - k (file, size=7214296) +``` + +Here, there are four directories: `/` (the outermost directory), `a` and `d` (which are in `/`), and `e` (which is in `a`). These directories also contain files of various sizes. + +Since the disk is full, your first step should probably be to find directories that are good candidates for deletion. To do this, you need to determine the **total size** of each directory. The total size of a directory is the sum of the sizes of the files it contains, directly or indirectly. (Directories themselves do not count as having any intrinsic size.) + +The total sizes of the directories above can be found as follows: + +- The total size of directory `e` is **584** because it contains a single file `i` of size 584 and no other directories. +- The directory `a` has total size **94853** because it contains files `f` (size 29116), `g` (size 2557), and `h.lst` (size 62596), plus file `i` indirectly (`a` contains `e` which contains `i`). +- Directory `d` has total size **24933642**. +- As the outermost directory, `/` contains every file. Its total size is **48381165**, the sum of the size of every file. + +To begin, find all of the directories with a total size of **at most 100000**, then calculate the sum of their total sizes. In the example above, these directories are `a` and `e`; the sum of their total sizes is **`95437`** (94853 + 584). (As in this example, this process can count files more than once!) + +Find all of the directories with a total size of at most 100000. **What is the sum of the total sizes of those directories?** + +## Part 2 + +Now, you're ready to choose a directory to delete. + +The total disk space available to the filesystem is **`70000000`**. To run the update, you need unused space of at least **`30000000`**. You need to find a directory you can delete that will **free up enough space** to run the update. + +In the example above, the total size of the outermost directory (and thus the total amount of used space) is `48381165`; this means that the size of the **unused** space must currently be `21618835`, which isn't quite the `30000000` required by the update. Therefore, the update still requires a directory with total size of at least `8381165` to be deleted before it can run. + +To achieve this, you have the following options: + +- Delete directory `e`, which would increase unused space by `584`. +- Delete directory `a`, which would increase unused space by `94853`. +- Delete directory `d`, which would increase unused space by `24933642`. +- Delete directory `/`, which would increase unused space by `48381165`. + +Directories `e` and `a` are both too small; deleting them would not free up enough space. However, directories `d` and `/` are both big enough! Between these, choose the **smallest**: d, increasing unused space by **`24933642`**. + +Find the smallest directory that, if deleted, would free up enough space on the filesystem to run the update. **What is the total size of that directory?** diff --git a/2022/07/code.py b/2022/07/code.py new file mode 100644 index 0000000..d46e0f2 --- /dev/null +++ b/2022/07/code.py @@ -0,0 +1,71 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2022 Akumatic +# +# https://adventofcode.com/2022/day/7 + +class Node: + def __init__(self, name, parent = None, size = None) -> None: + self.name = name + self.parent = parent + if parent: + parent.children[name] = self + self.size = size + self.children = dict() + + def get_size(self) -> int: + if self.size: + return self.size + return sum(self.children[child].get_size() for child in self.children) + +def build_dir_tree(terminal_output: list) -> Node: + root = Node("/") + cur_dir = root + for line in terminal_output: + if line.startswith("$ ls"): + continue # 'else' will deal with output + elif line.startswith("$ cd"): + dir = line[5:] + match dir: + case "/": + cur_dir = root + case "..": + cur_dir = cur_dir.parent + case _: + cur_dir = cur_dir.children[dir] + else: # line not starting with "$" => output of ls + type, name = line.split(" ") + match type: + case "dir": + new_node = Node(name=name, parent=cur_dir) + case _: + new_node = Node(name=name, parent=cur_dir, size=int(type)) + return root + +def read_file(filename: str = "input.txt") -> Node: + with open(f"{__file__.rstrip('code.py')}{filename}", "r") as f: + lines = [line.strip() for line in f.readlines()] + return build_dir_tree(lines) + +def get_possible_folder_sizes(node: Node, target_size: int, size_up_to: bool, sizes: list) -> None: + if len(node.children) == 0: + return + size = node.get_size() + if not size_up_to and size >= target_size or size_up_to and size <= target_size: + sizes.append(size) + for child in node.children: + get_possible_folder_sizes(node.children[child], target_size, size_up_to, sizes) + +def part1(node: Node) -> int: + sizes = [] + get_possible_folder_sizes(node, 100000, True, sizes) + return sum(sizes) + +def part2(node: Node) -> int: + sizes = [] + get_possible_folder_sizes(node, node.get_size() - 40000000, False, sizes) + return min(sizes) + +if __name__ == "__main__": + vals = read_file() + print(f"Part 1: {part1(vals)}") + print(f"Part 2: {part2(vals)}") diff --git a/2022/07/input.txt b/2022/07/input.txt new file mode 100644 index 0000000..1033235 --- /dev/null +++ b/2022/07/input.txt @@ -0,0 +1,1105 @@ +$ cd / +$ ls +dir hdwsmn +dir lmlsvqsw +dir rlfgcqz +dir sjq +dir tpnspw +$ cd hdwsmn +$ ls +dir mrrqnc +dir qst +dir rlfgcqz +$ cd mrrqnc +$ ls +227398 rwhw +$ cd .. +$ cd qst +$ ls +152795 bblss.hnl +dir lvs +$ cd lvs +$ ls +81813 jwvtjgjb.sss +$ cd .. +$ cd .. +$ cd rlfgcqz +$ ls +dir hlltch +dir jqpnnmwc +$ cd hlltch +$ ls +219753 rtgdsbz.qlg +$ cd .. +$ cd jqpnnmwc +$ ls +164333 dmvchsd.ncw +141721 njsfs.pmd +dir rlfgcqz +$ cd rlfgcqz +$ ls +278398 vhh.jtr +dir wfnpcnr +$ cd wfnpcnr +$ ls +dir njsfs +$ cd njsfs +$ ls +46895 twfg.gzb +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd lmlsvqsw +$ ls +81577 bblss +12519 dlghs.dcz +260260 gphgq.ztw +dir mldg +6570 qgbg +61210 twfg.gzb +$ cd mldg +$ ls +152240 bgddpvj.cgb +dir rlfgcqz +$ cd rlfgcqz +$ ls +dir dbvjfgff +dir dnnd +112649 qwhmdlf +dir wcqpzpp +$ cd dbvjfgff +$ ls +dir rlfgcqz +$ cd rlfgcqz +$ ls +278899 wmclvlvq.fbf +$ cd .. +$ cd .. +$ cd dnnd +$ ls +17486 zhqjt.dwq +$ cd .. +$ cd wcqpzpp +$ ls +195207 cvqtfn +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rlfgcqz +$ ls +63895 gbwqg +35085 lllv.jpl +155195 nhrbwg.dcf +84099 wsh.sps +$ cd .. +$ cd sjq +$ ls +48652 dmvchsd.ncw +$ cd .. +$ cd tpnspw +$ ls +81312 ftjrpmr.mfd +dir gcwq +dir lvvztw +dir msrdg +dir ncgljn +dir njsfs +dir ptncs +263168 rwglhrm +192446 twfg.gzb +$ cd gcwq +$ ls +dir bblss +dir hlmm +$ cd bblss +$ ls +120988 qgbg.tcm +326021 tbvgfdnc.cvl +$ cd .. +$ cd hlmm +$ ls +287707 dmvchsd.ncw +319996 gpvfhpnr.jjl +$ cd .. +$ cd .. +$ cd lvvztw +$ ls +dir bdsvzhbm +155345 ftjrpmr.mfd +112094 qwhmdlf +9917 vnmtgsq.gcj +$ cd bdsvzhbm +$ ls +dir jmmltt +dir zgcjl +$ cd jmmltt +$ ls +130686 zsp.dcc +$ cd .. +$ cd zgcjl +$ ls +318547 dmvchsd.ncw +$ cd .. +$ cd .. +$ cd .. +$ cd msrdg +$ ls +dir wjp +$ cd wjp +$ ls +301898 bjccpf +97684 mcnqbl.bwn +160132 qwhmdlf +315893 twfg.gzb +$ cd .. +$ cd .. +$ cd ncgljn +$ ls +dir bblss +119737 gdc.mrs +196706 ggljwvgj.blh +162440 mlgnvbhj.gbw +163186 qwqlfwfw.mfj +167447 twfg.gzb +$ cd bblss +$ ls +dir bblss +dir njsfs +137986 nlmbnm +dir qgbg +229544 zhqjt.dwq +$ cd bblss +$ ls +186733 wcqpzpp.mmr +$ cd .. +$ cd njsfs +$ ls +dir tjbrtt +$ cd tjbrtt +$ ls +284955 rlfgcqz.ltq +$ cd .. +$ cd .. +$ cd qgbg +$ ls +dir dmcmw +15196 ftjrpmr.mfd +dir gbpqj +236891 ghlm.wlm +156863 qgbg +dir wfvqv +$ cd dmcmw +$ ls +116526 dhzhmj.qpw +251858 dmvchsd.ncw +dir ffqghmp +dir njsfs +148820 njsfs.zvm +290169 twfg.gzb +186117 wcqpzpp.vsd +$ cd ffqghmp +$ ls +dir wcqpzpp +$ cd wcqpzpp +$ ls +dir rfmsdjr +$ cd rfmsdjr +$ ls +291669 psmg.ldm +$ cd .. +$ cd .. +$ cd .. +$ cd njsfs +$ ls +35762 dmvchsd.ncw +97427 njsfs +261675 twfg.gzb +15426 wcqpzpp +dir zvnjrnrw +$ cd zvnjrnrw +$ ls +18370 dmvchsd.ncw +10620 wsgd.fjt +$ cd .. +$ cd .. +$ cd .. +$ cd gbpqj +$ ls +10204 fdlpjd.tgr +117954 rlfgcqz +$ cd .. +$ cd wfvqv +$ ls +dir fsq +133485 twfg.gzb +$ cd fsq +$ ls +156862 qwhmdlf +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd njsfs +$ ls +dir bblss +dir bzlpqv +dir cvm +dir dbbngm +dir gbtmsjgl +224200 nrffnj +$ cd bblss +$ ls +dir dhmwcmf +280202 hmp +66351 ndnr.wjh +85218 qhrhjb +dir tcqnf +dir wjv +dir zwlpqrb +$ cd dhmwcmf +$ ls +dir qtdf +dir scsllc +$ cd qtdf +$ ls +dir fmbsgvr +$ cd fmbsgvr +$ ls +1641 jdtcd.qhw +109819 qwhmdlf +$ cd .. +$ cd .. +$ cd scsllc +$ ls +dir brthfcm +dir qqgh +81391 rlfgcqz.pcj +192835 rlfgcqz.rnf +$ cd brthfcm +$ ls +135591 qwhmdlf +$ cd .. +$ cd qqgh +$ ls +270614 djjq +dir njsfs +$ cd njsfs +$ ls +18629 fngbfvr +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd tcqnf +$ ls +25594 gvqjrdlr.fps +314758 rlfgcqz.ndb +269846 wcqpzpp.gvz +$ cd .. +$ cd wjv +$ ls +dir dtddhqbj +dir njsfs +dir pgfrd +95552 pjzgwggg.hpc +29427 rlfgcqz +dir shhzzrf +$ cd dtddhqbj +$ ls +dir fmzhtfd +36982 ftjrpmr.mfd +dir gqsg +dir wcqpzpp +$ cd fmzhtfd +$ ls +dir psqnghl +226561 rttdhnnm +220713 tsfcpzzv +$ cd psqnghl +$ ls +136028 qwhmdlf +280539 rlfgcqz.nzf +129468 zhqjt.dwq +dir zlb +$ cd zlb +$ ls +dir qgbg +$ cd qgbg +$ ls +188576 ftjrpmr.mfd +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd gqsg +$ ls +302134 dmvchsd.ncw +161569 drzt.pmq +$ cd .. +$ cd wcqpzpp +$ ls +254804 bblss.sqp +280941 dbvw.mdw +dir gfs +317925 njsfs.wpr +dir qgbg +$ cd gfs +$ ls +dir jrctzlg +dir lrnzq +233927 njsfs.bmd +45942 twfg.gzb +125290 vbtr.wvj +dir wcqpzpp +$ cd jrctzlg +$ ls +88635 qwhmdlf +204938 vlnwcv +$ cd .. +$ cd lrnzq +$ ls +253736 bblss.ddj +272769 vsrvgsc.cwl +$ cd .. +$ cd wcqpzpp +$ ls +301739 ftjrpmr.mfd +63733 qwhmdlf +$ cd .. +$ cd .. +$ cd qgbg +$ ls +dir cpr +196886 hgj +188348 lqvq +132024 twfg.gzb +213866 zhqjt.dwq +$ cd cpr +$ ls +dir wznlzpzj +115532 zhqjt.dwq +$ cd wznlzpzj +$ ls +dir bcwnrc +$ cd bcwnrc +$ ls +289013 dmvchsd.ncw +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd njsfs +$ ls +296178 mpprqbgc +128104 zhqjt.dwq +$ cd .. +$ cd pgfrd +$ ls +dir slgztr +$ cd slgztr +$ ls +dir htjd +dir rlfgcqz +243751 twfg.gzb +dir wcqpzpp +$ cd htjd +$ ls +216650 ftjrpmr.mfd +$ cd .. +$ cd rlfgcqz +$ ls +144834 qwchd.qtn +$ cd .. +$ cd wcqpzpp +$ ls +133476 qwhmdlf +$ cd .. +$ cd .. +$ cd .. +$ cd shhzzrf +$ ls +dir hbp +dir jqfhdn +dir qgbg +dir tftrnfpd +dir zppjlf +$ cd hbp +$ ls +158562 fbwsrbbg +297036 zph.mbd +$ cd .. +$ cd jqfhdn +$ ls +166463 bblss.sgd +125240 dmq +48389 ftjrpmr.mfd +dir njsfs +dir rlfgcqz +$ cd njsfs +$ ls +dir tbjp +307427 zhqjt.dwq +$ cd tbjp +$ ls +76200 rcfv.bgh +$ cd .. +$ cd .. +$ cd rlfgcqz +$ ls +294331 bblss.vwj +$ cd .. +$ cd .. +$ cd qgbg +$ ls +dir qnpdnjdl +dir rdmj +$ cd qnpdnjdl +$ ls +dir sblj +$ cd sblj +$ ls +39051 twfg.gzb +2405 zhqjt.dwq +$ cd .. +$ cd .. +$ cd rdmj +$ ls +213965 zhqjt.dwq +$ cd .. +$ cd .. +$ cd tftrnfpd +$ ls +294450 chbgd.vjv +318594 hvwbj +dir nznzzw +96252 twfg.gzb +dir vlfdtwj +dir vsvj +dir wvnjtmt +dir zlj +dir zwqff +$ cd nznzzw +$ ls +115971 nndbd.rhl +$ cd .. +$ cd vlfdtwj +$ ls +167648 ddvqzlh.cpw +$ cd .. +$ cd vsvj +$ ls +dir dfzcrmt +dir ffpvbczr +110196 njsfs.zsh +257204 qrgnw.mhw +dir rptmp +131871 zhqjt.dwq +$ cd dfzcrmt +$ ls +dir hqbthjc +dir hztrwjr +11874 rsd +252800 zhqjt.dwq +$ cd hqbthjc +$ ls +135533 bblss.clm +231343 rlfgcqz.zfh +176061 rrzqhdp +$ cd .. +$ cd hztrwjr +$ ls +dir zmpm +$ cd zmpm +$ ls +297930 rpb +$ cd .. +$ cd .. +$ cd .. +$ cd ffpvbczr +$ ls +dir qdvppt +dir qgbg +$ cd qdvppt +$ ls +323419 bblss.lnl +$ cd .. +$ cd qgbg +$ ls +158408 dmvchsd.ncw +$ cd .. +$ cd .. +$ cd rptmp +$ ls +280342 rqlbtpw +$ cd .. +$ cd .. +$ cd wvnjtmt +$ ls +dir bblss +249330 fgc.ftp +dir gtbbfzzn +dir wcqpzpp +$ cd bblss +$ ls +1570 zhqjt.dwq +$ cd .. +$ cd gtbbfzzn +$ ls +65850 lmbrdhc.jbz +$ cd .. +$ cd wcqpzpp +$ ls +62362 qwhmdlf +$ cd .. +$ cd .. +$ cd zlj +$ ls +103758 lrhflmsw.qhq +163919 qwhmdlf +$ cd .. +$ cd zwqff +$ ls +dir ghfc +dir njsfs +$ cd ghfc +$ ls +131979 hpcgrvms +$ cd .. +$ cd njsfs +$ ls +126387 wcqpzpp +$ cd .. +$ cd .. +$ cd .. +$ cd zppjlf +$ ls +241176 rlfgcqz.ctz +$ cd .. +$ cd .. +$ cd .. +$ cd zwlpqrb +$ ls +272627 bblss.gpv +261635 blczb.srs +dir lnhzzl +153210 njsfs +55633 twfg.gzb +$ cd lnhzzl +$ ls +dir dtwcsvzf +$ cd dtwcsvzf +$ ls +74858 dtz.rpc +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd bzlpqv +$ ls +157801 gdqhdd +318418 nmq +266938 qwhmdlf +$ cd .. +$ cd cvm +$ ls +1145 dmvchsd.ncw +233344 ftjrpmr.mfd +263393 njsfs.hvb +74436 twfg.gzb +dir wcqpzpp +96596 whq +$ cd wcqpzpp +$ ls +dir rlfgcqz +$ cd rlfgcqz +$ ls +244048 gspw +324759 qgbg.wrf +190410 qwhmdlf +$ cd .. +$ cd .. +$ cd .. +$ cd dbbngm +$ ls +dir bblss +184222 bcfzt.grj +dir rlfgcqz +41851 sshb.nzv +113784 wgjc.mrr +13594 zhqjt.dwq +$ cd bblss +$ ls +102201 qwhmdlf +$ cd .. +$ cd rlfgcqz +$ ls +91063 bblss.msn +2918 dqhbnt +74771 nbprqmbs.jwj +$ cd .. +$ cd .. +$ cd gbtmsjgl +$ ls +207664 cnfpq.wbl +$ cd .. +$ cd .. +$ cd ptncs +$ ls +dir bmpts +dir bpmf +dir brhp +dir gzjppjfr +dir jrd +321627 jss.jsh +130602 lfmrp.csp +dir prfz +dir qgbg +dir qjgchtwb +dir rvqrjms +174888 ttmwlrs.wbc +dir vwgsmc +55854 zhqjt.dwq +$ cd bmpts +$ ls +124846 dmvchsd.ncw +283278 mlcmzqdf.pfj +dir plbpr +312240 qwhmdlf +74910 rlfgcqz.jqp +dir tvrvwv +$ cd plbpr +$ ls +37432 dmvchsd.ncw +dir wcqpzpp +$ cd wcqpzpp +$ ls +18638 bsfsc.gfs +$ cd .. +$ cd .. +$ cd tvrvwv +$ ls +dir tsgp +$ cd tsgp +$ ls +141689 wcqpzpp.jdc +$ cd .. +$ cd .. +$ cd .. +$ cd bpmf +$ ls +201372 ftjrpmr.mfd +dir nhtjhsp +dir qgbg +dir sbqfdzh +dir wcqpzpp +178078 zhqjt.dwq +$ cd nhtjhsp +$ ls +225213 ftjrpmr.mfd +$ cd .. +$ cd qgbg +$ ls +214193 cwnphff +296165 ftjrpmr.mfd +260246 zhqjt.dwq +$ cd .. +$ cd sbqfdzh +$ ls +281546 njsfs.rjz +dir qgbg +246263 qqbsjtp.nbn +10231 srllsw +$ cd qgbg +$ ls +92801 dmvchsd.ncw +66784 pbz +226132 wcqpzpp.vjs +242775 wgt.bbw +$ cd .. +$ cd .. +$ cd wcqpzpp +$ ls +55886 bblss.vzh +313619 rlfgcqz +$ cd .. +$ cd .. +$ cd brhp +$ ls +321184 nnfzrm.mgz +190867 rlfgcqz.qbs +$ cd .. +$ cd gzjppjfr +$ ls +67036 ftjrpmr.mfd +$ cd .. +$ cd jrd +$ ls +293867 dmvchsd.ncw +dir drjbp +dir njsfs +10759 pcpvd.hsg +dir qfghvhsr +dir thf +268195 tmwvbl +$ cd drjbp +$ ls +dir ccdmcgvz +276381 gbhhwlv.rlt +252224 zqt.wpc +$ cd ccdmcgvz +$ ls +4082 cffmcz +31006 mws.tvb +dir njsfs +$ cd njsfs +$ ls +dir bblss +$ cd bblss +$ ls +180561 lfd +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd njsfs +$ ls +115688 qgbg +34653 qwhmdlf +$ cd .. +$ cd qfghvhsr +$ ls +3280 ssg.ctr +$ cd .. +$ cd thf +$ ls +dir bzhbrlh +dir qgbg +$ cd bzhbrlh +$ ls +148423 wjtlhwq +$ cd .. +$ cd qgbg +$ ls +dir rrtb +dir slhbmldf +$ cd rrtb +$ ls +30387 rlfgcqz +$ cd .. +$ cd slhbmldf +$ ls +dir vszhrc +$ cd vszhrc +$ ls +235629 qwhmdlf +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd prfz +$ ls +254587 bblss +dir bmfg +dir bsw +dir cfjdjcmt +321761 dmvchsd.ncw +35369 ftjrpmr.mfd +dir nqrbhdcn +237737 rlfgcqz.wsp +dir smdsrzlc +25049 tbwfsp +$ cd bmfg +$ ls +dir bblss +275693 wcqpzpp.zvw +$ cd bblss +$ ls +dir lddn +$ cd lddn +$ ls +dir mqlpwvcg +$ cd mqlpwvcg +$ ls +34635 zztv +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd bsw +$ ls +dir ljqv +dir vhpqbw +$ cd ljqv +$ ls +119525 ftjrpmr.mfd +$ cd .. +$ cd vhpqbw +$ ls +154199 twfg.gzb +$ cd .. +$ cd .. +$ cd cfjdjcmt +$ ls +22258 zhqjt.dwq +$ cd .. +$ cd nqrbhdcn +$ ls +dir bblss +84121 fbgqdsn +232625 hrjft +201822 ltfpl.lsq +194572 pgbqncwc.vqq +43024 qfgrmw +dir wcqpzpp +dir wvtnznjn +$ cd bblss +$ ls +326048 jctnwzn.zcq +$ cd .. +$ cd wcqpzpp +$ ls +265643 bzjmjng.vhr +dir lwt +dir qgbg +164876 twfg.gzb +dir vswqzjc +264349 wcqpzpp.lzp +$ cd lwt +$ ls +156024 ftjrpmr.mfd +287930 lmjwqw +dir qvr +56184 qwhmdlf +203952 twfg.gzb +95508 wcqpzpp +$ cd qvr +$ ls +dir ndqmn +$ cd ndqmn +$ ls +153880 njsfs.fvr +$ cd .. +$ cd .. +$ cd .. +$ cd qgbg +$ ls +244154 ftjrpmr.mfd +dir pztf +dir qgbg +dir rlfgcqz +dir zpvcn +$ cd pztf +$ ls +dir njsfs +dir sfrbvhp +$ cd njsfs +$ ls +268512 dmvchsd.ncw +$ cd .. +$ cd sfrbvhp +$ ls +dir wcqpzpp +$ cd wcqpzpp +$ ls +2126 dmvchsd.ncw +$ cd .. +$ cd .. +$ cd .. +$ cd qgbg +$ ls +123331 zhqjt.dwq +$ cd .. +$ cd rlfgcqz +$ ls +4261 lflphd.cfn +144504 twfg.gzb +110656 wcqpzpp.cjr +$ cd .. +$ cd zpvcn +$ ls +259119 qgbg +$ cd .. +$ cd .. +$ cd vswqzjc +$ ls +dir qgbg +dir rlfgcqz +$ cd qgbg +$ ls +76795 qwhmdlf +dir wcqpzpp +293923 zfcwvpz.vrn +$ cd wcqpzpp +$ ls +296986 qwhmdlf +$ cd .. +$ cd .. +$ cd rlfgcqz +$ ls +dir dtwv +dir rfbrzf +200095 rlqrlh +$ cd dtwv +$ ls +306977 bblss.dzm +139644 njsfs +$ cd .. +$ cd rfbrzf +$ ls +96622 cnb.wdl +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd wvtnznjn +$ ls +320558 lvtrqjnv.twq +$ cd .. +$ cd .. +$ cd smdsrzlc +$ ls +dir mbfqdbl +$ cd mbfqdbl +$ ls +dir hrhc +$ cd hrhc +$ ls +110162 hgbng +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd qgbg +$ ls +41978 mrfvnb.zbh +172912 rlfgcqz.qlf +$ cd .. +$ cd qjgchtwb +$ ls +243299 dmvchsd.ncw +91104 jbwss +207317 llqnrd.czw +145298 znzb.lsj +$ cd .. +$ cd rvqrjms +$ ls +40049 twfg.gzb +$ cd .. +$ cd vwgsmc +$ ls +dir qzl +dir rlfgcqz +dir tmpjd +dir vqt +$ cd qzl +$ ls +324024 cspbrpgv.fcc +8468 hfdwz.bjq +dir nvrpj +46755 qgbg.lhn +247926 qwhmdlf +dir thtq +17180 wcqpzpp +$ cd nvrpj +$ ls +dir vpscvbj +$ cd vpscvbj +$ ls +225620 bvrzrw +$ cd .. +$ cd .. +$ cd thtq +$ ls +dir pqqhcl +276922 qwhmdlf +59145 sshgg.bcf +dir wclbp +$ cd pqqhcl +$ ls +123067 vvhlq.bbg +$ cd .. +$ cd wclbp +$ ls +dir djbbpzjz +$ cd djbbpzjz +$ ls +5446 wtn.gnz +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rlfgcqz +$ ls +dir njsfs +$ cd njsfs +$ ls +178834 flrr +$ cd .. +$ cd .. +$ cd tmpjd +$ ls +1973 fnlwgc.rbq +240728 njsfs.sgm +dir qgbg +51532 qgbg.vdc +330859 rdvzpf.lld +dir sjlq +259561 twfdn.vnm +dir zlbmf +$ cd qgbg +$ ls +273408 bznqvg +45710 dmvchsd.ncw +306311 jcvn.brh +269315 rlfgcqz.crg +51046 rnqb.wlt +dir wqfprrd +dir zjscb +$ cd wqfprrd +$ ls +276417 zhqjt.dwq +$ cd .. +$ cd zjscb +$ ls +276541 bblss.dhl +dir mlsdv +dir njsfs +$ cd mlsdv +$ ls +251030 qwhmdlf +$ cd .. +$ cd njsfs +$ ls +dir cfmfsbc +$ cd cfmfsbc +$ ls +234880 zhqjt.dwq +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd sjlq +$ ls +25547 nqvnpgs.zhl +$ cd .. +$ cd zlbmf +$ ls +21812 pjn.hbf +dir rcgvwrg +$ cd rcgvwrg +$ ls +19512 qwhmdlf +$ cd .. +$ cd .. +$ cd .. +$ cd vqt +$ ls +80263 njsfs.zmr diff --git a/2022/07/solution.txt b/2022/07/solution.txt new file mode 100644 index 0000000..e6c36cc --- /dev/null +++ b/2022/07/solution.txt @@ -0,0 +1,2 @@ +Part 1: 1348005 +Part 2: 12785886 diff --git a/2022/07/test_code.py b/2022/07/test_code.py new file mode 100644 index 0000000..3dd83bf --- /dev/null +++ b/2022/07/test_code.py @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: MIT +# Copyright (c) 2022 Akumatic + +from code import read_file, part1, part2 + +def test(): + root = read_file("test_input.txt") + assert root.get_size() == 48381165 + assert root.children["d"].get_size() == 24933642 + assert root.children["a"].get_size() == 94853 + assert root.children["a"].children["e"].get_size() == 584 + print("Passed Tree Bulding") + assert part1(root) == 95437 + print("Passed Part 1") + assert part2(root) == 24933642 + print("Passed Part 2") + +if __name__ == "__main__": + test() diff --git a/2022/07/test_input.txt b/2022/07/test_input.txt new file mode 100644 index 0000000..09a921e --- /dev/null +++ b/2022/07/test_input.txt @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +14848514 b.txt +8504156 c.dat +dir d +$ cd a +$ ls +dir e +29116 f +2557 g +62596 h.lst +$ cd e +$ ls +584 i +$ cd .. +$ cd .. +$ cd d +$ ls +4060174 j +8033020 d.log +5626152 d.ext +7214296 k diff --git a/2022/README.md b/2022/README.md index 18fb882..c766e2e 100644 --- a/2022/README.md +++ b/2022/README.md @@ -21,7 +21,7 @@ Collect stars by solving puzzles. Two puzzles will be made available on each day | 04 | :white_check_mark: | :white_check_mark: | [Solution](04/code.py) | [Day 04](https://adventofcode.com/2022/day/4) | | 05 | :white_check_mark: | :white_check_mark: | [Solution](05/code.py) | [Day 05](https://adventofcode.com/2022/day/5) | | 06 | :white_check_mark: | :white_check_mark: | [Solution](06/code.py) | [Day 06](https://adventofcode.com/2022/day/6) | -| 07 | | | | [Day 07](https://adventofcode.com/2022/day/7) | +| 07 | :white_check_mark: | :white_check_mark: | [Solution](07/code.py) | [Day 07](https://adventofcode.com/2022/day/7) | | 08 | | | | [Day 08](https://adventofcode.com/2022/day/8) | | 09 | | | | [Day 09](https://adventofcode.com/2022/day/9) | | 10 | | | | [Day 10](https://adventofcode.com/2022/day/10) |