aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-12-07 15:45:52 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-12-07 15:45:52 +0800
commit152c1b1d68c9b9805c25a6c35f702e1d8d78e126 (patch)
tree0c37f05b699094f3ec475fb570656599d1abfd0d /src
parent3703e1e4aff85020af522e748d8b5e5feb33679f (diff)
downloadadvent-of-code-152c1b1d68c9b9805c25a6c35f702e1d8d78e126.tar.gz
advent-of-code-152c1b1d68c9b9805c25a6c35f702e1d8d78e126.zip
2022 day7
Diffstat (limited to 'src')
-rw-r--r--src/2015/day22/aoc.cpp19
-rw-r--r--src/2015/day22/aoc.h119
-rw-r--r--src/2022/day7/README.md91
-rw-r--r--src/2022/day7/aoc.cpp101
-rw-r--r--src/2022/day7/aoc.h45
-rw-r--r--src/2022/day7/input1090
-rw-r--r--src/2022/day7/input023
7 files changed, 1378 insertions, 110 deletions
diff --git a/src/2015/day22/aoc.cpp b/src/2015/day22/aoc.cpp
index 1c33c66..1e6ae41 100644
--- a/src/2015/day22/aoc.cpp
+++ b/src/2015/day22/aoc.cpp
@@ -2,4 +2,23 @@
namespace aoc2015 {
+static spell bosskill = {0, 1, 8, 0, 0, 0, 0};
+static spell spells[5] = {
+ {53, 1, 4, 0, 0, 0, 0},
+ {73, 1, 2, 2, 0, 0, 0},
+ {113, 6, 0, 0, 0, 7, 0},
+ {173, 6, 3, 0, 0, 0, 0},
+ {229, 5, 0, 0, 101, 0, 0},
+};
+
+bool effects(wizard&);
+
+std::pair<int, int> day22(wizard me, wizard boss) {
+ me.spells[0] = & bosskill;
+ for (int i = 0; i < 5; i++) {
+ boss.spells[i] = spells + i;
+ }
+ return {0, 0};
+}
+
}
diff --git a/src/2015/day22/aoc.h b/src/2015/day22/aoc.h
index 44b7e93..1c53c20 100644
--- a/src/2015/day22/aoc.h
+++ b/src/2015/day22/aoc.h
@@ -1,126 +1,27 @@
#pragma once
#include "common.h"
-#include <set>
-#include <stack>
-#include <vector>
namespace aoc2015 {
-enum class stype {
- magic_missile = 0,
- drain,
- shield,
- poison,
- recharge,
-};
-
struct spell;
struct wizard {
- int hitpoints;
+ int points;
int armor;
int mana;
- std::stack<spell*> spells[5];
-
- bool alive() const noexcept { return mana > 0 && hitpoints > 0; }
+ spell* spells[5] = {nullptr, nullptr, nullptr, nullptr, nullptr};
};
struct spell {
- wizard* w;
- spell(wizard* wp) : w(wp) {}
- virtual int cost() = 0;
- virtual void apply(wizard&) = 0;
- virtual void unapply(wizard&) = 0;
-};
-
-struct magic_missile : public spell {
- magic_missile(wizard* w) : spell(w) {}
- virtual int cost() override { return 53; };
- virtual void apply(wizard& w) override { w.hitpoints -= 4; }
- virtual void unapply(wizard& w) override { w.hitpoints += 4; }
-};
-
-struct drain : public spell {
- drain(wizard* w) : spell(w) {}
- virtual int cost() override { return 73; };
- virtual void apply(wizard& w) override {
- w.hitpoints -= 2;
- this->w->hitpoints += 2;
- }
- virtual void unapply(wizard& w) override {
- w.hitpoints += 2;
- this->w->hitpoints -= 2;
- }
-};
-
-struct shield : public spell {
- int armor;
- shield(wizard* w) : spell(w) {}
- virtual int cost() override { return 113; };
- virtual void apply(wizard& w) override {
- armor = w.armor;
- w.armor = 7;
- }
- virtual void unapply(wizard& w) override { w.armor = armor; }
-};
-
-struct poison : public spell {
- poison(wizard* w) : spell(w) {}
- virtual int cost() override { return 173; };
- virtual void apply(wizard& w) override { w.hitpoints -= 3; }
- virtual void unapply(wizard& w) override { w.hitpoints += 3; }
-};
-
-struct recharge : public spell {
- recharge(wizard* w) : spell(w) {}
- virtual int cost() override { return 229; };
- virtual void apply(wizard& w) override { w.mana += 101; }
- virtual void unapply(wizard& w) override { w.mana -= 101; }
-};
+ int costs;
+ int turns;
-struct arena {
- void apply(wizard* w) {
- for (int i = 0; i < 5; i++) {
- if (!w->spells[i].empty()) {
- spell* s = w->spells[i].top();
- s->apply(*w);
- w->spells[i].pop();
- }
- }
- }
+ int damage;
+ int heals;
+ int payback;
+ int protect;
- // before cast needs to check
- // 1 spell s is not active, stack is empty
- // 2 w2 has enough mana
- void cast(int s, wizard* w1, wizard* w2) {
- switch (stype(s)) {
- case stype::magic_missile:
- w1->spells[s].emplace(new magic_missile{w2});
- w2->mana -= w1->spells[s].top()->cost();
- break;
- case stype::drain:
- w1->spells[s].emplace(new drain{w2});
- w2->mana -= w1->spells[s].top()->cost();
- break;
- case stype::shield:
- for (int i = 0; i < 6; i++) {
- w2->spells[s].emplace(new shield{w2});
- }
- w2->mana -= w2->spells[s].top()->cost();
- break;
- case stype::poison:
- for (int i = 0; i < 6; i++) {
- w1->spells[s].emplace(new poison{w2});
- }
- w2->mana -= w1->spells[s].top()->cost();
- break;
- case stype::recharge:
- for (int i = 0; i < 5; i++) {
- w1->spells[s].emplace(new recharge{w2});
- }
- w2->mana -= w1->spells[s].top()->cost();
- break;
- }
- }
+ int tick;
};
+std::pair<int, int> day22(wizard me, wizard boss);
} // namespace aoc2015
diff --git a/src/2022/day7/README.md b/src/2022/day7/README.md
index e69de29..322ae81 100644
--- a/src/2022/day7/README.md
+++ b/src/2022/day7/README.md
@@ -0,0 +1,91 @@
+--- Day 7: No Space Left On Device ---
+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 Two ---
+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/src/2022/day7/aoc.cpp b/src/2022/day7/aoc.cpp
index 857e87b..940d9be 100644
--- a/src/2022/day7/aoc.cpp
+++ b/src/2022/day7/aoc.cpp
@@ -1,9 +1,108 @@
#include "aoc.h"
+#include <iostream>
+#include <algorithm>
namespace aoc2022 {
+static dir root{"/"};
+
+// ls
+void load(dir* d, line_view lv) {
+ per_line(lv, [&d](line_view l) {
+ dir* n = new dir(l);
+ n->parent = d;
+ d->dirs.push_back(n);
+ return true;
+ });
+}
+
+// cd /
+void get_root(dir** current) {
+ *current = &root;
+}
+
+// cd ..
+void get_parent(dir** current) {
+ dir* parent = (*current)->parent;
+ *current = parent;
+}
+
+// cd xxxx
+void get_dir(dir** current, line_view n) {
+ dir* d = *current;
+ for(auto& s : d->dirs) {
+ if (s->name == n) {
+ *current = s;
+ break;
+ }
+ }
+}
+
+struct dst {
+ dir* d;
+ int s;
+};
+
+void get_size(dir* d, std::vector<dir*> & dirs, std::vector<dst>& ds, int target) {
+ int s = d->get_size();
+ if (d->size == 0) {
+ ds.push_back({d, s});
+ }
+ if (s <= target && d->size == 0) {
+ // std::cout << d->name << " size is " << s << std::endl;
+ dirs.push_back(d);
+ }
+ for (auto& x: d->dirs) {
+ get_size(x, dirs, ds, target);
+ }
+}
std::pair<int,int> day7(line_view file) {
- return {0, 0};
+ dir* current = nullptr;
+ const char* p = file.line;
+ while(p < file.line + file.length) {
+ if (p[0] == '$') {
+ if (p[2] == 'c' && p[3] == 'd') {
+ if (p[5] == '/') get_root(&current);
+ else if (p[5] == '.') get_parent(&current);
+ else {
+ const char *p0 = p + 5;
+ while(*p0 != '\n') p0++;
+ get_dir(&current, line_view{p + 5, p0});
+ }
+ while(*p != '\n') p++;
+ }
+ if (p[2] == 'l' && p[3] == 's') {
+ const char* p0 = p + 5;
+ while (*p0 != '$') p0++;
+ load(current, line_view{p + 5, p0});
+ p = p0 - 1;
+ }
+ }
+ p++;
+ }
+
+ int rootsize = root.get_size();
+ // printf("root size is %d\n", rootsize);
+ std::vector<dir*> dirs;
+ std::vector<dst> ds;
+ get_size(&root, dirs, ds, 100000);
+ int total{0};
+ for(auto& d : dirs) {
+ total += d->get_size();
+ }
+ std::sort(ds.begin(), ds.end(), [](const dst&d1, const dst&d2) {
+ return d1.s < d2.s;
+ });
+ int smallest{0};
+ for (auto& d: ds) {
+ int x = 70000000 - rootsize + d.s;
+ // std::cout << d.d->name << ": " << d.s << " avail: " << x << std::endl;
+ if ( x >= 30000000) {
+ smallest = d.s;
+ break;
+ }
+ }
+ return {total, smallest};
}
}
diff --git a/src/2022/day7/aoc.h b/src/2022/day7/aoc.h
index a0cc427..ffb381f 100644
--- a/src/2022/day7/aoc.h
+++ b/src/2022/day7/aoc.h
@@ -1,7 +1,52 @@
#include "common.h"
+#include <vector>
namespace aoc2022 {
+struct dir {
+ line_view name;
+ int size = 0;
+ dir* parent = nullptr;
+ std::vector<dir*> dirs = {};
+
+ int get_number(const char** pp) {
+ int d{0};
+ const char* p = *pp;
+ while(*p != ' ') {
+ d = 10 * d + *p - '0';
+ p++;
+ }
+ *pp = p + 1;
+ return d;
+ }
+
+ dir(line_view lv) {
+ const char* p = lv.line;
+ if (p[0] == '/') {
+ size = 0;
+ name = lv;
+ }
+ if (p[0] == 'd') {
+ size = 0;
+ name = line_view{p+4, lv.line + lv.length - 1};
+ }
+ else if (p[0] >= '0' && p[0] <= '9') {
+ size = get_number(&p);
+ name = line_view{p, lv.line + lv.length - 1};
+ }
+ }
+
+ int get_size() const noexcept {
+ int s{0};
+ s += size;
+ for (auto& d: dirs) {
+ s += d->get_size();
+ }
+ return s;
+ }
+
+};
+
std::pair<int,int> day7(line_view file);
}
diff --git a/src/2022/day7/input b/src/2022/day7/input
index e69de29..a90e822 100644
--- a/src/2022/day7/input
+++ b/src/2022/day7/input
@@ -0,0 +1,1090 @@
+$ cd /
+$ ls
+dir fnsvfbzt
+dir hqdssf
+dir jwphbz
+dir lncqsmj
+dir mhqs
+dir trwqgzsb
+132067 vjw
+dir wbsph
+$ cd fnsvfbzt
+$ ls
+62158 sfwnts.hbj
+$ cd ..
+$ cd hqdssf
+$ ls
+45626 cvcbmcm
+dir dlsmjsbz
+dir hqdssf
+dir mhqs
+dir mtw
+dir sfccfsrd
+dir shzgg
+$ cd dlsmjsbz
+$ ls
+9205 qcqbgd.lzd
+$ cd ..
+$ cd hqdssf
+$ ls
+105963 mhqs.zrn
+87909 slwshm.nwr
+$ cd ..
+$ cd mhqs
+$ ls
+dir ctfl
+45923 jvvl.rcs
+dir jzjm
+dir lncqsmj
+dir mhqs
+dir wfbvtfmr
+$ cd ctfl
+$ ls
+dir shzgg
+$ cd shzgg
+$ ls
+18097 cvcbmcm
+289064 mhqs
+208557 slwshm.nwr
+283449 vjw
+dir wfbvtfmr
+$ cd wfbvtfmr
+$ ls
+263560 dssbpgnl.szh
+dir hnqjmq
+76551 jvvl.rcs
+195911 lncqsmj
+185776 slwshm.nwr
+$ cd hnqjmq
+$ ls
+3307 rjd.lgh
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jzjm
+$ ls
+31719 rjjrg.pjq
+$ cd ..
+$ cd lncqsmj
+$ ls
+dir mhqs
+$ cd mhqs
+$ ls
+138296 wfbvtfmr
+$ cd ..
+$ cd ..
+$ cd mhqs
+$ ls
+175499 jvvl.rcs
+dir rqznrr
+108476 slwshm.nwr
+199853 vjw
+$ cd rqznrr
+$ ls
+105075 shslmlt.spg
+$ cd ..
+$ cd ..
+$ cd wfbvtfmr
+$ ls
+131522 rjjrg.pjq
+$ cd ..
+$ cd ..
+$ cd mtw
+$ ls
+dir dcgpfrsf
+dir gwqm
+188911 hqdssf
+34693 jvvl.rcs
+dir shzgg
+$ cd dcgpfrsf
+$ ls
+47863 dfwthflp.jwq
+203815 dqbqbps.prq
+dir mhqs
+183653 rqjqpm.bbr
+220694 vjw
+$ cd mhqs
+$ ls
+74450 tjpn
+$ cd ..
+$ cd ..
+$ cd gwqm
+$ ls
+dir trghjhvs
+$ cd trghjhvs
+$ ls
+dir shzgg
+2620 slwshm.nwr
+$ cd shzgg
+$ ls
+73435 shzgg.bbf
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd shzgg
+$ ls
+184378 rjjrg.pjq
+$ cd ..
+$ cd ..
+$ cd sfccfsrd
+$ ls
+87317 ccvs.phq
+dir cqmgf
+dir cssmfv
+dir hhhqdmz
+17971 mhqs
+dir mvjttqr
+264394 slwshm.nwr
+dir stdzptb
+dir tcddd
+dir zmrt
+dir zqqtb
+$ cd cqmgf
+$ ls
+202804 tcrqqlgs
+$ cd ..
+$ cd cssmfv
+$ ls
+13440 jnhzrtfd
+$ cd ..
+$ cd hhhqdmz
+$ ls
+dir fdbpld
+272827 jftd.lml
+dir prqbhbv
+dir wbzvmz
+$ cd fdbpld
+$ ls
+dir bgrnz
+dir dcdj
+78284 jqqfc.tzz
+147731 lbdsh.plp
+269235 ntf.gmq
+$ cd bgrnz
+$ ls
+dir qzs
+dir rcv
+dir wmrmhdd
+$ cd qzs
+$ ls
+156779 lncqsmj.gnf
+$ cd ..
+$ cd rcv
+$ ls
+224927 dvbw.svf
+dir hqdssf
+dir jjmsqft
+255189 mhqs.pcl
+dir mvgqtlm
+dir pjs
+dir sljw
+$ cd hqdssf
+$ ls
+63099 blpdwd
+96035 jvvl.rcs
+40533 lvpsmzw
+205031 rjjrg.pjq
+59874 shzgg.ldg
+dir zdnfpwlw
+$ cd zdnfpwlw
+$ ls
+109325 hqdssf.fmj
+41775 jfqhq.tdn
+203744 nprghch.zjb
+dir qfs
+dir rzctqrgm
+dir shzgg
+$ cd qfs
+$ ls
+234449 vjw
+$ cd ..
+$ cd rzctqrgm
+$ ls
+99041 cvcbmcm
+$ cd ..
+$ cd shzgg
+$ ls
+149752 mhqs.bds
+126331 rjjrg.pjq
+75464 vbcjqdjv
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jjmsqft
+$ ls
+47522 shzgg
+$ cd ..
+$ cd mvgqtlm
+$ ls
+dir tgtbj
+dir tmrsn
+dir vpv
+$ cd tgtbj
+$ ls
+86585 lbmv.jcr
+202755 rjjrg.pjq
+$ cd ..
+$ cd tmrsn
+$ ls
+150980 hqdssf.hmh
+$ cd ..
+$ cd vpv
+$ ls
+197783 jvvl.rcs
+$ cd ..
+$ cd ..
+$ cd pjs
+$ ls
+216539 cvcbmcm
+159509 jgfphj
+195297 pdgnb.qjd
+162974 rjjrg.pjq
+$ cd ..
+$ cd sljw
+$ ls
+61689 hqdssf.bbn
+$ cd ..
+$ cd ..
+$ cd wmrmhdd
+$ ls
+92888 msgcqfbf
+$ cd ..
+$ cd ..
+$ cd dcdj
+$ ls
+99280 mclcnw
+$ cd ..
+$ cd ..
+$ cd prqbhbv
+$ ls
+102589 bqlcds.pqp
+107625 mhqs
+281871 mvwvdtd.dzf
+$ cd ..
+$ cd wbzvmz
+$ ls
+287371 tnwgfw
+$ cd ..
+$ cd ..
+$ cd mvjttqr
+$ ls
+dir dtf
+dir frcqdb
+dir hqdssf
+55645 slwshm.nwr
+dir zdzchmtq
+$ cd dtf
+$ ls
+121764 cvcbmcm
+279094 lncqsmj
+68484 slwshm.nwr
+278387 vjw
+$ cd ..
+$ cd frcqdb
+$ ls
+233216 lncqsmj.mbd
+217901 slwshm.nwr
+$ cd ..
+$ cd hqdssf
+$ ls
+dir dgdtm
+260973 qnt
+231311 thdrddd.zmj
+160399 vjw
+dir vpqjmmf
+197241 vqvzsv.nzg
+$ cd dgdtm
+$ ls
+dir cnshbf
+173312 vjw
+$ cd cnshbf
+$ ls
+72788 hqdssf.mhc
+122945 rjjrg.pjq
+$ cd ..
+$ cd ..
+$ cd vpqjmmf
+$ ls
+127969 hqdssf.stc
+267724 lncqsmj
+55890 mhqs.mql
+dir tsbtz
+$ cd tsbtz
+$ ls
+244065 qqfnbd.nqv
+59649 qttbcgd.vtj
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd zdzchmtq
+$ ls
+271886 lmphsmv
+dir nncghrr
+$ cd nncghrr
+$ ls
+180468 rjjrg.pjq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd stdzptb
+$ ls
+19398 frsztqqz.mnc
+$ cd ..
+$ cd tcddd
+$ ls
+dir hqdssf
+71084 jvvl.rcs
+dir wnzhld
+$ cd hqdssf
+$ ls
+178907 gcslqrn
+$ cd ..
+$ cd wnzhld
+$ ls
+206073 hpdnj
+$ cd ..
+$ cd ..
+$ cd zmrt
+$ ls
+dir bmfgjr
+dir bpztq
+dir chsh
+dir dpjhn
+288144 mhqs.zvb
+$ cd bmfgjr
+$ ls
+189592 jhmgm
+$ cd ..
+$ cd bpztq
+$ ls
+184906 rjjrg.pjq
+$ cd ..
+$ cd chsh
+$ ls
+110753 jvvl.rcs
+dir lncqsmj
+dir njdgplj
+dir qhpplfnd
+190460 rjjrg.pjq
+144668 wfbvtfmr.flv
+$ cd lncqsmj
+$ ls
+dir pzd
+$ cd pzd
+$ ls
+287833 vhfjdg.jrz
+$ cd ..
+$ cd ..
+$ cd njdgplj
+$ ls
+dir cbvz
+dir vfhj
+$ cd cbvz
+$ ls
+dir rtpcsrf
+$ cd rtpcsrf
+$ ls
+240018 wfbvtfmr
+$ cd ..
+$ cd ..
+$ cd vfhj
+$ ls
+152840 cbbrgc.wnq
+243656 hqdssf
+36325 hqdssf.fhn
+$ cd ..
+$ cd ..
+$ cd qhpplfnd
+$ ls
+206490 dfththnq.vnm
+$ cd ..
+$ cd ..
+$ cd dpjhn
+$ ls
+127322 rjjrg.pjq
+dir shzgg
+$ cd shzgg
+$ ls
+165774 cvcbmcm
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd zqqtb
+$ ls
+dir ljnmbqvd
+60485 pcz.snl
+274930 slwshm.nwr
+131928 vqm
+51341 wfbvtfmr.stc
+$ cd ljnmbqvd
+$ ls
+268048 bdbjn
+dir fjh
+dir qpclpbz
+dir rqpljw
+dir tzjftf
+255809 vjw
+243604 wfbvtfmr.rzb
+$ cd fjh
+$ ls
+180021 hqdssf.rqs
+$ cd ..
+$ cd qpclpbz
+$ ls
+109952 blmm.nsv
+dir dltbt
+dir htbzp
+287761 mfbd
+dir mhqs
+dir vgbvrwvn
+dir wmhd
+$ cd dltbt
+$ ls
+205121 dfzlcv.hjf
+56409 hpqhhmb.sss
+233277 hqdssf.qcb
+187838 mbmcfhf.fnj
+dir rrqjn
+dir swrgj
+151306 tqjzq.dmg
+$ cd rrqjn
+$ ls
+240447 lncqsmj
+$ cd ..
+$ cd swrgj
+$ ls
+dir lnnwdbt
+dir sgjsn
+dir wfbvtfmr
+$ cd lnnwdbt
+$ ls
+213111 tnn.bhq
+$ cd ..
+$ cd sgjsn
+$ ls
+dir wpprqhs
+$ cd wpprqhs
+$ ls
+dir hqdssf
+$ cd hqdssf
+$ ls
+209286 qbdfzdzw.sgp
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd wfbvtfmr
+$ ls
+199298 hqdssf.chs
+123953 rjjrg.pjq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd htbzp
+$ ls
+dir bmfr
+68162 bzwcswr.mlv
+284074 dtzwf
+270421 jpsvh.ncc
+dir mwbvz
+95631 shzgg.tbf
+44434 vjw
+$ cd bmfr
+$ ls
+19937 shzgg
+$ cd ..
+$ cd mwbvz
+$ ls
+156668 rjjrg.pjq
+$ cd ..
+$ cd ..
+$ cd mhqs
+$ ls
+111821 ftrv.zcw
+dir jsnlcn
+dir mhqs
+dir rjdwmb
+dir sfmrwgd
+$ cd jsnlcn
+$ ls
+7527 smqts.cnc
+dir svdw
+$ cd svdw
+$ ls
+173846 vjtrp
+$ cd ..
+$ cd ..
+$ cd mhqs
+$ ls
+dir hswdjgg
+30326 rjjrg.pjq
+$ cd hswdjgg
+$ ls
+285037 jvvl.rcs
+$ cd ..
+$ cd ..
+$ cd rjdwmb
+$ ls
+219498 twl.lmw
+$ cd ..
+$ cd sfmrwgd
+$ ls
+168290 ltwpm.fjl
+$ cd ..
+$ cd ..
+$ cd vgbvrwvn
+$ ls
+dir bswv
+dir hqdssf
+dir mhqs
+$ cd bswv
+$ ls
+121032 cncdt
+dir jrbmlg
+dir lncqsmj
+dir mhmgn
+65380 rjjrg.pjq
+dir wfbvtfmr
+$ cd jrbmlg
+$ ls
+37975 shzgg.bnq
+$ cd ..
+$ cd lncqsmj
+$ ls
+114558 jvvl.rcs
+dir mhqs
+dir nfn
+dir nhlbfq
+141816 phtt.phj
+181530 vjw
+224510 zmzp.jwg
+$ cd mhqs
+$ ls
+dir wpnw
+$ cd wpnw
+$ ls
+286077 lncqsmj.cld
+$ cd ..
+$ cd ..
+$ cd nfn
+$ ls
+269740 cvcbmcm
+87123 mhqs.nst
+61029 mhqs.vhb
+211712 slwshm.nwr
+$ cd ..
+$ cd nhlbfq
+$ ls
+247458 lncqsmj
+$ cd ..
+$ cd ..
+$ cd mhmgn
+$ ls
+85806 vjw
+$ cd ..
+$ cd wfbvtfmr
+$ ls
+275888 cvvhvg.pwv
+151703 gnbm
+61419 grcfbwdp
+150382 gzdmzj.wpc
+dir mtrqcwrd
+112827 nbtjlnt.srg
+$ cd mtrqcwrd
+$ ls
+273564 shzgg.tbm
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd hqdssf
+$ ls
+72227 ccvwdrs.dsf
+141028 dctbz.spr
+dir shzgg
+277461 slwshm.nwr
+94390 stgp.trm
+24297 vgdzsrrl.dhg
+$ cd shzgg
+$ ls
+143437 lncqsmj.vpl
+78418 pbdwbmtd.nlp
+28173 vlfj.tps
+$ cd ..
+$ cd ..
+$ cd mhqs
+$ ls
+97312 jvvl.rcs
+dir qqfbsz
+42472 rjjrg.pjq
+dir wfbvtfmr
+$ cd qqfbsz
+$ ls
+dir lncqsmj
+dir mhqs
+$ cd lncqsmj
+$ ls
+186873 wfbvtfmr.lfh
+$ cd ..
+$ cd mhqs
+$ ls
+dir wfbvtfmr
+$ cd wfbvtfmr
+$ ls
+234441 gsjwsn
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd wfbvtfmr
+$ ls
+55214 dgf
+dir fdtz
+6756 jvvl.rcs
+226995 rpsjvr.wpb
+68993 vjw
+$ cd fdtz
+$ ls
+dir rdzsjm
+$ cd rdzsjm
+$ ls
+dir mjgfpvc
+$ cd mjgfpvc
+$ ls
+dir vfcq
+$ cd vfcq
+$ ls
+dir fmtfm
+$ cd fmtfm
+$ ls
+200137 dvbqjq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd wmhd
+$ ls
+dir hnn
+dir rzt
+$ cd hnn
+$ ls
+16335 wfbvtfmr.vhw
+262909 zgtln.dwc
+$ cd ..
+$ cd rzt
+$ ls
+285086 mhqs.vsg
+dir qnr
+$ cd qnr
+$ ls
+290611 llnp.hsh
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd rqpljw
+$ ls
+267152 jbv
+$ cd ..
+$ cd tzjftf
+$ ls
+258707 cnfb.dgv
+17087 hqdssf.dtd
+92075 nwvtww
+dir qblrnn
+dir tdg
+$ cd qblrnn
+$ ls
+dir brrqp
+dir frqcc
+25504 jvvl.rcs
+dir lncqsmj
+dir mhqs
+107908 rjjrg.pjq
+286918 rngbhp.ntg
+dir shzgg
+dir wcnh
+dir wfbvtfmr
+$ cd brrqp
+$ ls
+270783 wfbvtfmr
+$ cd ..
+$ cd frqcc
+$ ls
+dir clj
+7502 lncqsmj
+dir mnsbr
+73859 scwltjwh.cqd
+29920 vjw
+dir wpplgrc
+$ cd clj
+$ ls
+31407 grm.pwv
+$ cd ..
+$ cd mnsbr
+$ ls
+dir wfbvtfmr
+99467 whsrtf.gff
+$ cd wfbvtfmr
+$ ls
+81283 cvcbmcm
+$ cd ..
+$ cd ..
+$ cd wpplgrc
+$ ls
+285496 lncqsmj.hwq
+$ cd ..
+$ cd ..
+$ cd lncqsmj
+$ ls
+8972 jvvl.rcs
+$ cd ..
+$ cd mhqs
+$ ls
+119520 hqdssf.tbn
+$ cd ..
+$ cd shzgg
+$ ls
+180825 lncqsmj.rsg
+23507 wfbvtfmr
+$ cd ..
+$ cd wcnh
+$ ls
+98662 tmwrh
+220468 wml.sht
+$ cd ..
+$ cd wfbvtfmr
+$ ls
+283178 hqdssf.ctf
+$ cd ..
+$ cd ..
+$ cd tdg
+$ ls
+283636 cvcbmcm
+117742 gsqzjfn.pmp
+176660 lncqsmj
+dir pbdgbsts
+dir znvv
+$ cd pbdgbsts
+$ ls
+92092 vjw
+$ cd ..
+$ cd znvv
+$ ls
+41213 hqdssf.rnn
+dir pcttrtd
+$ cd pcttrtd
+$ ls
+16759 mhqs.gpb
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd shzgg
+$ ls
+19544 bcn.rws
+dir fqwpwcq
+dir hngpzst
+dir hqdssf
+dir shzgg
+dir vgjr
+dir wfbvtfmr
+$ cd fqwpwcq
+$ ls
+269576 mhqs
+dir pmfv
+$ cd pmfv
+$ ls
+175725 jvvl.rcs
+29161 pnbm.mlr
+$ cd ..
+$ cd ..
+$ cd hngpzst
+$ ls
+18430 cvcbmcm
+dir fgzlgbm
+dir hqdssf
+378 rjjrg.pjq
+dir zjlnsztt
+$ cd fgzlgbm
+$ ls
+134751 dwlfbfjp
+dir hqdssf
+227313 jvvl.rcs
+dir lncqsmj
+dir mhqs
+dir qfjmtvpv
+dir qzm
+114934 shzgg.jdf
+187091 zpgbdnl.twq
+$ cd hqdssf
+$ ls
+87131 bdmdpdf.cqg
+dir fdc
+dir gwgp
+$ cd fdc
+$ ls
+116738 cvcbmcm
+$ cd ..
+$ cd gwgp
+$ ls
+dir qdvss
+dir rpwzw
+dir wfbvtfmr
+$ cd qdvss
+$ ls
+111546 wqnsrnh
+$ cd ..
+$ cd rpwzw
+$ ls
+183614 lfjqvff
+129803 rdwd
+$ cd ..
+$ cd wfbvtfmr
+$ ls
+266779 mhqs
+189793 slwshm.nwr
+279894 sncqtvwp.mff
+40520 vjw
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd lncqsmj
+$ ls
+257714 dtcjv.lsd
+69877 shzgg
+267645 vjw
+$ cd ..
+$ cd mhqs
+$ ls
+257031 stsfrb.gvs
+$ cd ..
+$ cd qfjmtvpv
+$ ls
+dir mhqs
+$ cd mhqs
+$ ls
+91378 wldhvhl
+$ cd ..
+$ cd ..
+$ cd qzm
+$ ls
+dir shn
+$ cd shn
+$ ls
+dir jmmlsvdg
+$ cd jmmlsvdg
+$ ls
+41383 rnlgl.vjv
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd hqdssf
+$ ls
+dir mzj
+$ cd mzj
+$ ls
+169639 sgdn
+$ cd ..
+$ cd ..
+$ cd zjlnsztt
+$ ls
+78315 jfj.sgg
+$ cd ..
+$ cd ..
+$ cd hqdssf
+$ ls
+906 rjjrg.pjq
+$ cd ..
+$ cd shzgg
+$ ls
+163015 mhqs.cnb
+$ cd ..
+$ cd vgjr
+$ ls
+129546 hclg.vbl
+286437 hqdssf
+dir lncqsmj
+1552 nhgwff
+279693 qmpdlw
+83645 slwshm.nwr
+$ cd lncqsmj
+$ ls
+233355 fhpjbpjl.tbh
+$ cd ..
+$ cd ..
+$ cd wfbvtfmr
+$ ls
+218452 jvvl.rcs
+47525 rjjrg.pjq
+109880 tctz.rnd
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd jwphbz
+$ ls
+dir bqbwds
+dir mwnzw
+113414 qgdsgfg.ngj
+141013 qtp
+10795 slwshm.nwr
+$ cd bqbwds
+$ ls
+18049 shzgg
+$ cd ..
+$ cd mwnzw
+$ ls
+169353 dtqlr
+dir hlrgzlph
+dir mhqs
+238527 vjw
+$ cd hlrgzlph
+$ ls
+249097 hqdssf
+86490 pwdmzwb
+$ cd ..
+$ cd mhqs
+$ ls
+176337 rjjrg.pjq
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd lncqsmj
+$ ls
+dir jmsw
+dir mcgm
+dir mpc
+233050 rjjrg.pjq
+30757 shzgg
+250575 slwshm.nwr
+$ cd jmsw
+$ ls
+dir hqdssf
+dir nmsbdqhm
+dir wfbvtfmr
+$ cd hqdssf
+$ ls
+44806 lvzm
+$ cd ..
+$ cd nmsbdqhm
+$ ls
+dir czzp
+dir gcp
+dir gsrnmq
+dir rmngvc
+dir vpfq
+dir vpzvb
+dir wccgblsq
+43981 wfbvtfmr
+$ cd czzp
+$ ls
+95330 slwshm.nwr
+82000 wfbvtfmr
+$ cd ..
+$ cd gcp
+$ ls
+229303 ddsppspd.fcn
+$ cd ..
+$ cd gsrnmq
+$ ls
+dir hrsstlt
+dir rzc
+40890 sfpt
+$ cd hrsstlt
+$ ls
+18477 mnpc.tmh
+$ cd ..
+$ cd rzc
+$ ls
+33078 dmfwf
+149792 wfbvtfmr.jnz
+dir zsnmz
+$ cd zsnmz
+$ ls
+dir gzsnl
+69834 lplszs.rvg
+213489 slwshm.nwr
+dir vrnqh
+$ cd gzsnl
+$ ls
+109060 jvvl.rcs
+122307 svtppnvt.wrz
+$ cd ..
+$ cd vrnqh
+$ ls
+94389 jvvl.rcs
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd rmngvc
+$ ls
+dir jljbrrgg
+$ cd jljbrrgg
+$ ls
+128554 cvcbmcm
+$ cd ..
+$ cd ..
+$ cd vpfq
+$ ls
+73628 rjjrg.pjq
+$ cd ..
+$ cd vpzvb
+$ ls
+265609 rjjrg.pjq
+$ cd ..
+$ cd wccgblsq
+$ ls
+110134 hffzwm.zfr
+$ cd ..
+$ cd ..
+$ cd wfbvtfmr
+$ ls
+209356 jvvl.rcs
+286105 mtsb.bwd
+234687 vcgnlc.cft
+$ cd ..
+$ cd ..
+$ cd mcgm
+$ ls
+203407 cvcbmcm
+$ cd ..
+$ cd mpc
+$ ls
+dir shzgg
+$ cd shzgg
+$ ls
+dir bnb
+$ cd bnb
+$ ls
+232449 lncqsmj.czs
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd ..
+$ cd mhqs
+$ ls
+116955 jvvl.rcs
+$ cd ..
+$ cd trwqgzsb
+$ ls
+88439 jgphdrnq
+$ cd ..
+$ cd wbsph
+$ ls
+dir mhqs
+dir vgh
+$ cd mhqs
+$ ls
+133965 rfh.zdb
+$ cd ..
+$ cd vgh
+$ ls
+36092 rjjrg.pjq
+$
diff --git a/src/2022/day7/input0 b/src/2022/day7/input0
index e69de29..09a921e 100644
--- a/src/2022/day7/input0
+++ b/src/2022/day7/input0
@@ -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