diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 15:06:53 +0100 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2023-10-17 15:06:53 +0100 |
commit | 31878dd6e8ed95a7abee3a25f2ec850f2ec3df4b (patch) | |
tree | 4b31083ad26b7c6e8f89258108672833ef49530a /2022 | |
parent | 9c1e58152495199eacc44419013f7b9d03914f32 (diff) | |
download | advent-of-code-31878dd6e8ed95a7abee3a25f2ec850f2ec3df4b.tar.gz advent-of-code-31878dd6e8ed95a7abee3a25f2ec850f2ec3df4b.tar.bz2 advent-of-code-31878dd6e8ed95a7abee3a25f2ec850f2ec3df4b.zip |
Made a rough sketch comment of puzzle-7 structure
Diffstat (limited to '2022')
-rw-r--r-- | 2022/puzzle-7.lisp | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/2022/puzzle-7.lisp b/2022/puzzle-7.lisp index 3a4f353..a9b302c 100644 --- a/2022/puzzle-7.lisp +++ b/2022/puzzle-7.lisp @@ -21,6 +21,41 @@ tokens (including command)." if (token-cmdp (car token-set)) return token-set)) +#| What is a directory structure? You have some root directory, with +some entries. Your current working directory (CWD), at the start of +the program, will be at the root but later on could be any descendant +of the root. How do we manage moving around the directory structure +and ensure updates to the root? + +We should maintain a HISTORY stack where +CAR(HISTORY) = (NAME of CWD . State of CWD when entering). + +Firstly a function which updates the HISTORY on our current state. +UPDATE-CURRENT-DIRECTORY(CWD, HISTORY) { +CWD-ENTRY = PEEK(HISTORY); +IF NULL(CWD-ENTRY) +HISTORY = ((NIL . CWD)) +ELSE +SETF((CDR CWD-ENTRY), CWD); +} + +Say CWD = {... a = directory, b = file, ...} +DOWN-DIRECTORY(a, CWD, HISTORY) { +UPDATE-CURRENT-DIRECTORY(CWD, HISTORY); <-- This is so we don't lose information +HISTORY = ACONS(a, CWD@a, HISTORY); +CWD = CWD@a; +} + + +Then UP-DIRECTORY(CWD, HISTORY) { +PAIR = POP(HISTORY); <-- (CWD-NAME . PREVIOUS-CWD-STATE) +PARENT = PEEK(HISTORY); <-- Parent of CWD (PARENT-NAME . PARENT-STATE) +ENTRY = ASSOC(CAR(PAIR) CDR(PARENT)) <-- Gives us the CWD entry in the parent +SETF CDR(ENTRY) CWD <-- Update the parent +CWD = CDR(PARENT) <-- Update CWD +} +|# + (defun parse-ls (tokens) "Converts the following TOKENS till a command (via TOKEN-CMDP) into a directory structure i.e. an alist of string names by their content." |