From 7443fc80ae11a5859972fd5e9b8b38f43bf2168c Mon Sep 17 00:00:00 2001 From: efim Date: Wed, 7 Dec 2022 20:37:14 +0000 Subject: [PATCH] wow, filesystem stats was HARD --- day7-directories-cleanup.lisp | 284 ++++++++++ day7-input.txt | 1008 +++++++++++++++++++++++++++++++++ day7-test-input.txt | 23 + 3 files changed, 1315 insertions(+) create mode 100644 day7-directories-cleanup.lisp create mode 100644 day7-input.txt create mode 100644 day7-test-input.txt diff --git a/day7-directories-cleanup.lisp b/day7-directories-cleanup.lisp new file mode 100644 index 0000000..7f4acf0 --- /dev/null +++ b/day7-directories-cleanup.lisp @@ -0,0 +1,284 @@ +;; https://adventofcode.com/2022/day/7 + +;; so, right now if i need to calculate sum of the size of files. +;; but, there could be duplicates. +;; so, i suppose i'll need to maintain the full filename? +;; so, track the current directory? and on $ ls read lines until next $ +;; and put them into hashtable, under full name. ok. ugh +;; +;; so types of commands: +;; cd / - drop current path +;; cd - add to current path +;; cd .. - drop head of current path +;; ls - read in filenames, and add them with current path and size into hashmap +;; +;; then what? go through the hashmap and do calculation +;; with current task, i don't really need to process +;; dir d - names of the directories after $ ls +;; but, how to do pleasant parsing of the lines? +;; and how to store the state, if I'm reading things one line at a time? +;; possibly with DO macro again + +;; i guess is could be one function that takes in line and returns new state +;; so state would be +;; - list of directories +;; - hashtable of (filename -> size) + +;; i could split string, and try to do case pattern match +(ql:quickload 'alexandria) + +(require 'cl-ppcre) + +(let* ((line "dir a") + (line-list (cl-ppcre:split " " line))) + (cond ((equal '("$" "cd" "/") line-list) 'ROOT) + ((equal '("$" "cd") (subseq line-list 0 2)) 'CD) + ((equal '("$" "ls") (subseq line-list 0 2)) 'LS) + ((equal '("dir") (subseq line-list 0 1)) 'DIR) + ((integerp (parse-integer (first line-list))) 'FILE) + (t 'OTHER))) + + +;; CASE or COND + +(subseq '(1 2 3) 0 2) +(integerp (parse-integer (first (cl-ppcre:split " " "14848514 b.txt")))) +(integerp "1") +(parse-integer "1") +(parse-integer "r") + +(defun what (n) + (format t "~S~%" n)) + +(defun my-parse-line (line) + (let ((line-list (cl-ppcre:split " " line))) + (cond ((equal '("$" "cd" "/") line-list) 'ROOT) + ((equal '("$" "cd") (subseq line-list 0 2)) 'CD) + ((equal '("$" "ls") (subseq line-list 0 2)) 'LS) + ((equal '("dir") (subseq line-list 0 1)) 'DIR) + ((integerp (parse-integer (first line-list))) 'FILE) + (t 'OTHER)))) + +;; (integerp (parse-integer (first (cl-ppcre:split " " "$ cd /")))) + +(mapcar #'my-parse-line '( + "$ cd /" + "$ ls" + "dir a" + "14848514 b.txt" + "8504156 c.dat" + "dir d" + "$ cd a" + )) + +;; next step is to utilize parse line to change state, i guess + +(ql:quickload 'fset) + +(defparameter *test-dir-list* ()) +(defparameter *test-dir-set* (fset:empty-set)) +(defparameter *test-file-sizes* (make-hash-table)) + +(let ((current-path-dirs '()) + (file-sizes (make-hash-table)) + (dirset (fset:empty-set))) + (labels ((my-full-file-name (dirs lastName) + (let* ((all-dirs (reverse (concatenate 'list (list lastName) + dirs)))) + (format nil "~{~a~^/~}" all-dirs))) + (ingest-line (line) + (let ((line-list (cl-ppcre:split " " line))) + (cond ((equal '("$" "cd" "/") + line-list) + (setf current-path-dirs '())) + ((equal '("$" "cd" "..") + line-list) + (pop current-path-dirs)) + ((equal '("$" "cd") + (subseq line-list 0 2)) + (push (third line-list) current-path-dirs)) + ((equal '("$" "ls") + (subseq line-list 0 2)) + ;; do i need to do anything if just act on the file? + ) + ((equal '("dir") + (subseq line-list 0 1)) + (setf dirset (fset:with dirset (my-full-file-name current-path-dirs (second line-list))))) + ((integerp (parse-integer (first line-list))) + (let ((file-name (my-full-file-name current-path-dirs (second line-list))) + (file-size (parse-integer (first line-list)))) + (setf (gethash file-name file-sizes) file-size))))))) + (with-open-file (in "day7-input.txt") + ;; with-open-file (in "day7-test-input.txt") + (loop + for line = (read-line in nil nil) + while line + do (ingest-line line)))) + (setf *test-dir-list* current-path-dirs) + (setf *test-file-sizes* file-sizes) + (setf *test-dir-set* dirset)) + +*test-dir-list* +*test-dir-set* +*test-file-sizes* +;; now let's iterate over keys in the sizes +(print (loop + for k being each hash-key of *test-file-sizes* using (hash-value v) + do (format t "~a => ~a~%" k v))) +;; ok, popping doesn't happen i think +;; fixed +;; now i want / in the beginning + +;; now let's loop over dirs in set. and loop over keys in the hashtable +;; and sum values, and collect sum if it's < 100000 +;; +;; well. it's for sure! should be different value +;; hmw/tsrqvpbq/dqbnbl/mbc/nqrdmvjm +;; is also a file +;; hmw/tsrqvpbq/dqbnbl/mbc/nqrdmvjm.vtq => 137158 +;; but if all such directories are above 100k then they wouldn't matter. +;; ugh. let's sort lines + +(fset:do-set (dirname *test-dir-set*) + (print dirname)) +;; but I guess i'll need to just map with fset:image +;; and put sum of all files there +;; let's first return all files for which dir is prefix +(fset:image (lambda (dir) `(,dir imagined)) *test-dir-set*) + +(print (fset:reduce #'+ + (fset:filter (lambda (sumed) + (>= 100000 sumed)) + (fset:image (lambda (dir) + (loop + for filename being each hash-key of *test-file-sizes* using (hash-value filesize) + when (alexandria:starts-with-subseq (concatenate 'string dir "/") filename ) + summing filesize)) *test-dir-set*)))) +;; oh, shit. it's set, so duplicates of the freaking same sizes get dropped. +;; so, i need to calculate differently +(print (let ((total-sum 0)) + (fset:do-set (dirname *test-dir-set*) + (let ((dir-size (loop + for filename being each hash-key of *test-file-sizes* using (hash-value filesize) + when (alexandria:starts-with-subseq (concatenate 'string dirname "/") + filename ) + summing filesize))) + (if (> 100000 dir-size) + (incf total-sum dir-size)))) + total-sum)) + +;; crap +;; with / 159935456 +;; without / 160367201 +;; but if i'm not filtering, then they should be same? wtf +;; or like i'm not counting top level? + +;; wow. summing instead of collect +;; now filter those that less than 10000 and sum again +;; ok, i guess. +;; now with a different file? +;; +;; wrong answer 1265478 +;; +;; oh, you tricky people +;; there's dir.file that matches as prefix. ugh +;; but then my value should be more that required? ugh twice + +(fset:image (lambda (dir) + (loop + for filename being each hash-key of *test-file-sizes* using (hash-value filesize) + when (alexandria:starts-with-subseq (concatenate 'string dir "/") + filename ) + collect (list filename filesize))) + *test-dir-set*) + +(string-prefix-p "a" "aab") +(alexandria:starts-with "a" "aab") +(alexandria:starts-with-subseq "a/" "a/ab") +(alexandria:starts-with-subseq "" "aab") +;; ok. hello + +;; error - tried to use FLET* for allowing recursion, again went to stackoverflow. + +;; oh. i need to sum over dirs, ugh. +;; now that's more complicated now. +;; so. then maybe i'd want to register DIRs in another hashtable? +;; and then for each dir collect all files that start with that prefix and sum? +;; would be O(n^2) but ok, i guess + +(defparameter *test-set* (fset:empty-set)) +(fset:with *test-set* "hello") ; already uses #'EQUAL , cool + +(concatenate 'string "hello" "another" "yay") +;; yay! +;; thank you https://stackoverflow.com/questions/5457346/lisp-function-to-concatenate-a-list-of-strings +(format nil "~{~a~^/~}" '("hello" "this" "one")) + +(concatenate 'list '("name") '("efim" "home")) +(defun my-full-file-name (dirs lastName) + (let* ((all-dirs (reverse (concatenate 'list (list lastName) dirs)))) + (format nil "/~{~a~^/~}" all-dirs))) + +(my-full-file-name '("eifm" "home") "Documents") + + +;; well. ok. now what? maybe i don't need to count root anyway? + +;; ugh. can i build a tree then? +;; have pointer? ugh/ + +;;; so, just start anew? ugh + +;;; TO THE PART 2 +;; need to find /smallest/ directory to delete, so that free space would be 30000000 our of 70000000 +;; so I need "total sum of all" + +;; copying over code to calculate sum +;; oh, shit. it's set, so duplicates of the freaking same sizes get dropped. +;; so, i need to calculate differently +(print (let ((total-sum 0)) + (fset:do-set (dirname *test-dir-set*) + (let ((dir-size (loop + for filename being each hash-key of *test-file-sizes* using (hash-value filesize) + when (alexandria:starts-with-subseq (concatenate 'string dirname "/") + filename ) + summing filesize))) + (incf total-sum dir-size))) + total-sum)) +;; 166378694 ; oh that's sum with the duplicates. ugh + +;; (- 70000000 166378694) +;; i need direct sum, just over the lines. +;; luckily this should be easier? or no? well, sum over the file-hashtable, there are all unique + +(print (loop + for filename being each hash-key of *test-file-sizes* using (hash-value filesize) + summing filesize)) + +(print (- 70000000 44795677)) +;; wait, no. I need 30000000 +;; so, that's my free memory right now: 25204323 +;; to free is +(print (- 30000000 25204323)) +;; to free 4795677 +;; now i need for all dir sizes find one that is more than than, but the smallest + +(fset:filter (lambda (item) + (< 4795677 (first item))) (fset:image (lambda (dir) + (list (loop + for filename being each hash-key of *test-file-sizes* using (hash-value filesize) + when (alexandria:starts-with-subseq (concatenate 'string dir "/") + filename ) + summing filesize) dir)) + *test-dir-set*)) +;; and it shows sorted, and the first one - is the dir to be deleted. +;; cooooool. it was very hard. +;; +;; what are lessons: +;; image (mapping) on set discards duplicates. lot's of time spent debugging this +;; also - i need to learn threading. +;; maybe that's the way to make code simpler. +;; but then i won't be able to call it iteratevly? i really still should. +;; +;; so, go to Alexandria for threading, and for string things. +;; and maybe read about functions for hashmaps and such. ugh. diff --git a/day7-input.txt b/day7-input.txt new file mode 100644 index 0000000..5be5f9f --- /dev/null +++ b/day7-input.txt @@ -0,0 +1,1008 @@ +$ cd / +$ ls +dir cdnhnmcb +dir dmccnsqv +290229 dsm +dir gsszlj +dir hmw +dir jhmrn +dir ncb +dir npclt +dir rvvjbz +$ cd cdnhnmcb +$ ls +170937 fsjwz.css +281758 jmfcfs.gsq +109017 jwwv.zlz +295735 tsrqvpbq +$ cd .. +$ cd dmccnsqv +$ ls +273438 fsjwz.css +dir jtntzqfd +dir tqmbq +211769 vmgpwrbz.nbp +205895 wqz.qcg +$ cd jtntzqfd +$ ls +4635 wqfvvzth.vdz +$ cd .. +$ cd tqmbq +$ ls +dir bnvspstf +22264 bqcvlnw.pmq +dir hwv +200690 jlwjsbw.bzf +dir npclt +243708 qvnbwvt.sbv +157861 tsrqvpbq.mtf +$ cd bnvspstf +$ ls +46133 mwvz.vwh +289236 rjcp.gqj +$ cd .. +$ cd hwv +$ ls +dir tsrqvpbq +$ cd tsrqvpbq +$ ls +292872 rvvjbz.mgh +$ cd .. +$ cd .. +$ cd npclt +$ ls +191646 bhllwpr +26548 jlwjsbw.bzf +214302 nnqz +74637 szdjtbt.tmw +$ cd .. +$ cd .. +$ cd .. +$ cd gsszlj +$ ls +dir bjvqcfwc +dir dfzhdhs +179837 dsm.hzf +112354 gnrzhsw.jcf +175236 jlwjsbw.bzf +dir mfnllhfw +dir nwvcgb +dir rvvjbz +dir vcvmq +$ cd bjvqcfwc +$ ls +125387 rvvjbz +$ cd .. +$ cd dfzhdhs +$ ls +218291 jlwjsbw.bzf +dir jsmjbfg +dir rvvjbz +272548 zdrtjvzj.rlt +196309 ztdcrnl.hjj +$ cd jsmjbfg +$ ls +72259 bmszdt +242641 fsjwz.css +109294 mwtlz +149525 sgngzrnn.mww +$ cd .. +$ cd rvvjbz +$ ls +175613 rqjmjhrb +$ cd .. +$ cd .. +$ cd mfnllhfw +$ ls +119986 fcjrv.dvh +dir gwjgjljj +157962 jjjbv.fdp +dir mwttp +30246 vhzdjv.fqh +197554 zdrtjvzj.rlt +288875 zhdn.dtj +$ cd gwjgjljj +$ ls +237890 mlmmfh +dir ncjzqll +10935 zdrtjvzj.rlt +$ cd ncjzqll +$ ls +152092 gwwh.ttt +$ cd .. +$ cd .. +$ cd mwttp +$ ls +217929 fsjwz.css +$ cd .. +$ cd .. +$ cd nwvcgb +$ ls +131410 fsjwz.css +dir nqrdmvjm +82487 qwbg.hcb +dir tsrqvpbq +123617 tsrqvpbq.wqw +$ cd nqrdmvjm +$ ls +dir btjwzz +dir dsm +dir fcrsj +141465 fsjwz.css +133916 ztdcrnl.hjj +$ cd btjwzz +$ ls +dir nqrdmvjm +dir tsrqvpbq +150003 zdrtjvzj.rlt +$ cd nqrdmvjm +$ ls +dir dsm +160109 gzv.wzw +33187 mcgmjn.ftg +dir pbgdcwd +167821 ztdcrnl.hjj +$ cd dsm +$ ls +84979 gwwh.ttt +dir rvvjbz +$ cd rvvjbz +$ ls +189309 btvjmhp.dwm +$ cd .. +$ cd .. +$ cd pbgdcwd +$ ls +240743 rzgbfcg.dzg +$ cd .. +$ cd .. +$ cd tsrqvpbq +$ ls +284223 mmhvjn +188341 tnv.rcs +271396 zdrtjvzj.rlt +$ cd .. +$ cd .. +$ cd dsm +$ ls +128966 ptf +$ cd .. +$ cd fcrsj +$ ls +261786 qljq.nrv +$ cd .. +$ cd .. +$ cd tsrqvpbq +$ ls +57089 fsjwz.css +208087 ttfhpzll +$ cd .. +$ cd .. +$ cd rvvjbz +$ ls +dir ldglv +$ cd ldglv +$ ls +39389 wjwzdg.ldb +$ cd .. +$ cd .. +$ cd vcvmq +$ ls +dir jzgd +246541 lmfdrnnz.dcc +169613 npclt +264902 npclt.jsl +dir pwzbvvwz +82651 rch.bsc +223282 vddwtwz.pqf +dir wnb +$ cd jzgd +$ ls +91717 dqmhdw.mjr +69771 ztdcrnl.hjj +$ cd .. +$ cd pwzbvvwz +$ ls +dir cdmfv +dir fvqjbd +dir nhvhhs +dir npclt +dir rgdb +$ cd cdmfv +$ ls +172054 dsm.qjw +$ cd .. +$ cd fvqjbd +$ ls +212067 hclqv +dir tcjsbn +$ cd tcjsbn +$ ls +40576 wbzwnc.pqf +13447 wlrjhcf.jtg +$ cd .. +$ cd .. +$ cd nhvhhs +$ ls +92810 bgfgrzs +$ cd .. +$ cd npclt +$ ls +dir dcs +dir tsrqvpbq +$ cd dcs +$ ls +274856 nrqwg +$ cd .. +$ cd tsrqvpbq +$ ls +144678 jlwjsbw.bzf +dir nqrdmvjm +163728 qwddbflc.gjp +$ cd nqrdmvjm +$ ls +122069 btpm.vhg +105752 psrmw +149744 rvvjbz.bnn +126434 ztdcrnl.hjj +$ cd .. +$ cd .. +$ cd .. +$ cd rgdb +$ ls +75645 blzt +dir clz +dir ddmbzz +dir hrl +280472 jgmd.htc +217770 nqwgl.qqb +dir qjcrf +$ cd clz +$ ls +dir fshcptjq +125496 lhgsdhl.gss +291857 pfbjptg.lqh +78923 rdhmmqml.lrw +$ cd fshcptjq +$ ls +157704 btf +66314 qcpjsfr +225592 rsftvgr +$ cd .. +$ cd .. +$ cd ddmbzz +$ ls +217731 cbc.dmn +16389 cdwwz +256395 gwwh.ttt +233481 rvsslvbh +dir rvvjbz +dir zgc +$ cd rvvjbz +$ ls +dir zrwtdlzz +$ cd zrwtdlzz +$ ls +21488 gdgl.vbc +$ cd .. +$ cd .. +$ cd zgc +$ ls +222107 gwwh.ttt +35382 npclt.fpp +$ cd .. +$ cd .. +$ cd hrl +$ ls +dir rvvjbz +$ cd rvvjbz +$ ls +65335 dgn.mgd +$ cd .. +$ cd .. +$ cd qjcrf +$ ls +dir fjrdgbwh +$ cd fjrdgbwh +$ ls +143960 wvnzt.wvq +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd wnb +$ ls +66543 jlwjsbw.bzf +dir nqrdmvjm +dir pfwptjtl +3047 sbdlzbt.hlj +$ cd nqrdmvjm +$ ls +dir cqn +dir mnmbmb +182573 pmw.pdl +dir rvvjbz +92911 ztdcrnl.hjj +$ cd cqn +$ ls +38563 npclt.pcl +14353 sdlmtzzv +52230 ztdcrnl.hjj +$ cd .. +$ cd mnmbmb +$ ls +212337 fsjwz.css +24700 gwwh.ttt +10243 npclt +dir nqrdmvjm +238617 rvvjbz +$ cd nqrdmvjm +$ ls +19026 plrvst.bpd +$ cd .. +$ cd .. +$ cd rvvjbz +$ ls +23115 fsjwz.css +260656 jlwjsbw.bzf +113097 zdrtjvzj.rlt +$ cd .. +$ cd .. +$ cd pfwptjtl +$ ls +134817 jlwjsbw.bzf +80522 npclt +254529 nqrdmvjm.mbc +35322 ztdcrnl.hjj +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd hmw +$ ls +dir cfc +dir cmbtwjqm +dir dsm +81077 dzsj.bsl +dir gzgr +dir jrdhssrz +dir npclt +dir tsrqvpbq +dir vssgzdw +dir wngccwdr +5928 wrpd.zwq +113540 ztdcrnl.hjj +$ cd cfc +$ ls +159334 npclt +212665 ztdcrnl.hjj +$ cd .. +$ cd cmbtwjqm +$ ls +dir vzftvhhc +$ cd vzftvhhc +$ ls +86763 jlwjsbw.bzf +dir nbj +dir qzbf +$ cd nbj +$ ls +63776 jlwjsbw.bzf +$ cd .. +$ cd qzbf +$ ls +189850 rtszjp.zhq +$ cd .. +$ cd .. +$ cd .. +$ cd dsm +$ ls +dir bddwfjhv +258304 fltv +4285 jlwjsbw.bzf +dir nqrdmvjm +dir rvvjbz +258902 zdrtjvzj.rlt +$ cd bddwfjhv +$ ls +201408 zdrtjvzj.rlt +$ cd .. +$ cd nqrdmvjm +$ ls +250981 npclt.dnd +$ cd .. +$ cd rvvjbz +$ ls +181444 npclt.msj +146533 thzv.jbn +$ cd .. +$ cd .. +$ cd gzgr +$ ls +dir brmzzz +dir dsm +$ cd brmzzz +$ ls +40671 jlwjsbw.bzf +$ cd .. +$ cd dsm +$ ls +53299 bmdpw +dir npclt +223542 qdrlng +dir thjnrtq +$ cd npclt +$ ls +30938 bdldl +36847 gfwbhj.nvh +159051 qjpggrst.czp +233569 vwpr.drg +dir wwln +$ cd wwln +$ ls +153489 fsjwz.css +196950 lzcrjs +$ cd .. +$ cd .. +$ cd thjnrtq +$ ls +30861 fsjwz.css +$ cd .. +$ cd .. +$ cd .. +$ cd jrdhssrz +$ ls +194556 bqcn.ctq +dir gnhc +148157 gwwh.ttt +dir jcqcjbj +245407 jlwjsbw.bzf +248457 lmvh +$ cd gnhc +$ ls +183841 fsjwz.css +128648 hzcpmz +154895 mvznln +193794 ztdcrnl.hjj +$ cd .. +$ cd jcqcjbj +$ ls +266176 cbbfjsp +dir dsm +195555 sfq +$ cd dsm +$ ls +13098 bjhsqfpp.rvw +dir grpp +dir nqb +$ cd grpp +$ ls +259797 jvw.psl +32317 sfm.twr +$ cd .. +$ cd nqb +$ ls +82426 rvvjbz.fdm +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd npclt +$ ls +dir tqzmprzr +$ cd tqzmprzr +$ ls +278120 dsm.hqd +$ cd .. +$ cd .. +$ cd tsrqvpbq +$ ls +dir dqbnbl +dir dsm +dir lsglr +213028 rvvjbz.rvh +112991 tsrqvpbq.ptw +$ cd dqbnbl +$ ls +dir dhzs +281375 dsm +121452 gwwh.ttt +dir mbc +dir npclt +211213 tsrqvpbq.zsz +125518 zdrtjvzj.rlt +$ cd dhzs +$ ls +110840 gwwh.ttt +197645 tsrqvpbq +$ cd .. +$ cd mbc +$ ls +224503 drsrlls.ctp +dir dzm +65461 jlwjsbw.bzf +dir nqrdmvjm +137158 nqrdmvjm.vtq +dir rvvjbz +126868 rwrzljq +$ cd dzm +$ ls +279593 fsjwz.css +13111 gwwh.ttt +205453 hchlb.bdn +277556 jlwjsbw.bzf +dir jvd +dir nqrdmvjm +dir prqlqh +dir rhdhhfs +dir rvvjbz +$ cd jvd +$ ls +76776 fsjwz.css +85847 wqdzvs.vwf +$ cd .. +$ cd nqrdmvjm +$ ls +40200 npclt.fcq +$ cd .. +$ cd prqlqh +$ ls +267371 fsjwz.css +$ cd .. +$ cd rhdhhfs +$ ls +51224 dsm.qln +$ cd .. +$ cd rvvjbz +$ ls +dir npclt +dir wdhgmfb +60599 wjwgrq +$ cd npclt +$ ls +138588 bdqtq.slq +221322 rjmbd.pdj +279540 ztdcrnl.hjj +$ cd .. +$ cd wdhgmfb +$ ls +98271 jcg.pwz +$ cd .. +$ cd .. +$ cd .. +$ cd nqrdmvjm +$ ls +221950 swnsstls.zcl +7947 tqwhs +$ cd .. +$ cd rvvjbz +$ ls +272797 zdrtjvzj.rlt +$ cd .. +$ cd .. +$ cd npclt +$ ls +294537 bqlgnwwf.qqf +285887 flzmnmft +3041 fsjwz.css +dir npclt +dir rvvjbz +235966 zhwvl +$ cd npclt +$ ls +96669 sjcr.qmc +$ cd .. +$ cd rvvjbz +$ ls +240351 fsjwz.css +112539 rvvjbz.tlc +$ cd .. +$ cd .. +$ cd .. +$ cd dsm +$ ls +dir dpbsq +dir lmvjnd +dir vjnb +$ cd dpbsq +$ ls +dir vczm +$ cd vczm +$ ls +252709 jfzq.fvc +$ cd .. +$ cd .. +$ cd lmvjnd +$ ls +20118 rsp.njm +$ cd .. +$ cd vjnb +$ ls +192558 vvggw.ljj +$ cd .. +$ cd .. +$ cd lsglr +$ ls +222728 qvp +296718 ztdcrnl.hjj +$ cd .. +$ cd .. +$ cd vssgzdw +$ ls +dir smfhgcv +$ cd smfhgcv +$ ls +16174 dtpgsvfv.csm +43403 lhbqdpv +dir ndh +52985 pcj.csh +81157 vwsrt +278111 zdrtjvzj.rlt +$ cd ndh +$ ls +80287 jlwjsbw.bzf +$ cd .. +$ cd .. +$ cd .. +$ cd wngccwdr +$ ls +6088 ppjnslg +$ cd .. +$ cd .. +$ cd jhmrn +$ ls +dir qwqhhbth +$ cd qwqhhbth +$ ls +dir ggfmlp +dir qgflbldg +$ cd ggfmlp +$ ls +35739 dsm +38351 jlwjsbw.bzf +$ cd .. +$ cd qgflbldg +$ ls +dir pbw +dir rvvjbz +dir tqppnqmv +$ cd pbw +$ ls +dir nqrdmvjm +5912 nqrdmvjm.qvj +$ cd nqrdmvjm +$ ls +dir tnd +$ cd tnd +$ ls +dir lwsvwsl +$ cd lwsvwsl +$ ls +150503 jlwjsbw.bzf +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd rvvjbz +$ ls +dir dmrff +dir ssnbl +dir zgrgt +$ cd dmrff +$ ls +dir vmmzmf +$ cd vmmzmf +$ ls +211105 tsrqvpbq +$ cd .. +$ cd .. +$ cd ssnbl +$ ls +246210 mlj.qbv +$ cd .. +$ cd zgrgt +$ ls +207409 lnvqlhsj +$ cd .. +$ cd .. +$ cd tqppnqmv +$ ls +59007 gwwh.ttt +123705 jlwjsbw.bzf +277423 rvvjbz.hbn +170157 tbs +dir ztg +$ cd ztg +$ ls +8432 fsjwz.css +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd ncb +$ ls +30859 dsm +74337 jvp.jwl +dir lgvwz +150310 lhl.rtq +$ cd lgvwz +$ ls +105307 fftbgl.tnh +69432 npclt.sdq +49765 zdrtjvzj.rlt +214149 ztdcrnl.hjj +$ cd .. +$ cd .. +$ cd npclt +$ ls +dir dsm +dir rvvjbz +dir trr +$ cd dsm +$ ls +dir bcccgpl +dir cvddqch +210401 fsjwz.css +96482 nqrdmvjm.tgr +dir nwctzch +29453 zdrtjvzj.rlt +$ cd bcccgpl +$ ls +237918 dshtjdcs +dir mtrcfbf +dir tgt +dir tsrqvpbq +99779 wpfsbnh.nbh +257112 ztdcrnl.hjj +$ cd mtrcfbf +$ ls +dir hms +49756 tsrqvpbq +$ cd hms +$ ls +185755 zdrtjvzj.rlt +$ cd .. +$ cd .. +$ cd tgt +$ ls +dir dsm +dir jmfdpdf +256858 zdrtjvzj.rlt +$ cd dsm +$ ls +71528 dsm.rvc +$ cd .. +$ cd jmfdpdf +$ ls +231263 hgsvvrqt.vbp +$ cd .. +$ cd .. +$ cd tsrqvpbq +$ ls +218774 clhqvp +$ cd .. +$ cd .. +$ cd cvddqch +$ ls +144164 fsjwz.css +dir gfszp +60880 nqrdmvjm +222198 vhhtgj +$ cd gfszp +$ ls +127091 fsjwz.css +$ cd .. +$ cd .. +$ cd nwctzch +$ ls +258292 rfvvc +$ cd .. +$ cd .. +$ cd rvvjbz +$ ls +dir cnv +dir dtpswgq +dir ggdhw +97538 jsjlq +218535 nqrdmvjm.fhj +134022 tsrqvpbq.mbs +51273 zdrtjvzj.rlt +$ cd cnv +$ ls +208016 gzvmv.dfg +$ cd .. +$ cd dtpswgq +$ ls +dir jfbgfts +$ cd jfbgfts +$ ls +273657 bbtbqv +77349 dsm.rnc +dir nqrdmvjm +208448 zdrtjvzj.rlt +$ cd nqrdmvjm +$ ls +dir bjdrqnt +dir msqc +dir npclt +dir rsms +dir vzhdtv +$ cd bjdrqnt +$ ls +103077 tph.bpz +264222 wmvzc +$ cd .. +$ cd msqc +$ ls +72288 ztdcrnl.hjj +$ cd .. +$ cd npclt +$ ls +dir tfbzdm +$ cd tfbzdm +$ ls +dir nqrdmvjm +35970 nqrdmvjm.gwj +54275 rvvjbz.pvs +dir wwrsrmn +179618 ztdcrnl.hjj +$ cd nqrdmvjm +$ ls +dir gljgj +$ cd gljgj +$ ls +135000 gwwh.ttt +$ cd .. +$ cd .. +$ cd wwrsrmn +$ ls +17120 npclt.vhz +$ cd .. +$ cd .. +$ cd .. +$ cd rsms +$ ls +198169 fsjwz.css +$ cd .. +$ cd vzhdtv +$ ls +234619 gwwh.ttt +$ cd .. +$ cd .. +$ cd .. +$ cd .. +$ cd ggdhw +$ ls +dir dsm +dir fmljfpfb +dir nqrdmvjm +dir qrhnjrn +dir vpsqmmp +$ cd dsm +$ ls +185390 rvvjbz.ljl +70843 scrzhct.shj +dir zqd +$ cd zqd +$ ls +197478 lrpnc.pqp +dir nljssvvw +228126 rfsnv +dir wzvvggdp +$ cd nljssvvw +$ ls +248489 dwdcnzb.ztq +$ cd .. +$ cd wzvvggdp +$ ls +40266 jlwjsbw.bzf +$ cd .. +$ cd .. +$ cd .. +$ cd fmljfpfb +$ ls +dir chc +232964 gwwh.ttt +283351 jlwjsbw.bzf +$ cd chc +$ ls +273399 cjtznvrq.jcd +250531 dsm.djs +dir lgqz +173885 pmlw.hcb +273356 swwzbpdm +7329 wtvs.qrr +$ cd lgqz +$ ls +9432 fst.nlb +$ cd .. +$ cd .. +$ cd .. +$ cd nqrdmvjm +$ ls +129926 zdrtjvzj.rlt +$ cd .. +$ cd qrhnjrn +$ ls +dir vnvchpr +dir zchcq +271220 ztdcrnl.hjj +$ cd vnvchpr +$ ls +257931 rvvjbz +132252 wtgs.btb +$ cd .. +$ cd zchcq +$ ls +dir hmf +215104 sshml +$ cd hmf +$ ls +253334 gbvbmwbf.lhs +$ cd .. +$ cd .. +$ cd .. +$ cd vpsqmmp +$ ls +32455 gwwh.ttt +170338 rfsvs.dfq +$ cd .. +$ cd .. +$ cd .. +$ cd trr +$ ls +dir bfjwfd +dir bhrvh +dir ggfc +187910 gwwh.ttt +dir mtqftj +$ cd bfjwfd +$ ls +dir npclt +dir wqqfszn +$ cd npclt +$ ls +269520 trrcw.jmq +$ cd .. +$ cd wqqfszn +$ ls +151594 rvvjbz.gvt +$ cd .. +$ cd .. +$ cd bhrvh +$ ls +251782 cpbvqrjj +$ cd .. +$ cd ggfc +$ ls +65357 gwwh.ttt +dir jqjtwf +$ cd jqjtwf +$ ls +65025 wzrp.pbp +$ cd .. +$ cd .. +$ cd mtqftj +$ ls +294942 vtjhwjr.qgc +88168 wvbnjp.blf +$ cd .. +$ cd .. +$ cd .. +$ cd rvvjbz +$ ls +dir csfp +141875 dsm +294580 jlwjsbw.bzf +dir jqlm +25928 lqhpn.jrh +224295 zdrtjvzj.rlt +113314 zww.ftt +$ cd csfp +$ ls +153717 ztdcrnl.hjj +$ cd .. +$ cd jqlm +$ ls +163455 jlwjsbw.bzf diff --git a/day7-test-input.txt b/day7-test-input.txt new file mode 100644 index 0000000..9d4eaba --- /dev/null +++ b/day7-test-input.txt @@ -0,0 +1,23 @@ +$ cd / +$ ls +dir a +1 b.txt +1 c.dat +dir d +$ cd a +$ ls +dir e +1 f +1 g +1 h.lst +$ cd e +$ ls +1 i +$ cd .. +$ cd .. +$ cd d +$ ls +1 j +1 d.log +1 d.ext +1 k