2 Commits dbf8970590 ... 3c3b196075

Author SHA1 Message Date
  hvincent 3c3b196075 moved directory parent out of the class and now have an external PWD log but that doesn't solve the problem either 1 year ago
  hvincent e4e39dfcfe doing a little shuffle that still works on examples but not on input 1 year ago
1 changed files with 29 additions and 10 deletions
  1. 29 10
      2022/solver.py

+ 29 - 10
2022/solver.py

@@ -467,7 +467,9 @@ $ ls
 
     p1, p2 = "",""
 
-    p1, root = day_seven_processor_a(data)
+    root = day_seven_parser(data)
+
+    p1 = day_seven_processor_a(root)
     p2 = day_seven_processor_b(root)
 
     return p1, p2
@@ -524,14 +526,14 @@ class Directory:
 
         return subdirs
 
-def day_seven_processor_a(input):
-
-    ans = 0
+def day_seven_parser(input):
     home = Directory("root", "")
     here = home
+    last = []
 
     for i in range(len(input) - 1):
         line = input[i]
+        print(line)
 
         if line[0] == "$":
             cmd = line.split(" ")[1:]
@@ -553,22 +555,40 @@ def day_seven_processor_a(input):
                         here.add_file(filename, int(filesize))
 
             elif cmd[0] == "cd":
+                #print(last)
+                print("{}: {}".format(here.get_name(),id(here)))
                 if cmd[1] == "..":
-                    here = here.get_parent()
+                    #print("{}: {}".format(here.get_name(),id(here)))
+                    #here = here.get_parent()
+                    pwd = []
+                    for x in last:
+                        pwd.append(x.get_name())
+                    print("/".join(pwd))
+
+                    here = last.pop()
                 elif cmd[1] == "/":
                     here = home
+                    last = []
                 else:
+                    last.append(here)
                     here = here.get_dir(cmd[1])
+                print("->{}: {}".format(here.get_name(),id(here)))
 
 
     home.calc_subdirs()
 
+    return home
+
+def day_seven_processor_a(home):
+
+    ans = 0
+
     for x in home.list_subdirs():
         a = x.get_size()
         if x.get_size() <= 100000:
             ans += x.get_size()
 
-    return ans, home
+    return ans
 
 def day_seven_processor_b(root):
 
@@ -586,11 +606,10 @@ def day_seven_processor_b(root):
 
     for x in root.list_subdirs():
         a = x.get_size()
+        here = x.get_name()
+        print("{}: {}".format(here, a))
 
         if a >= delta:
-            here = x.get_name()
-            print(here)
-            print(a)
             if a < curr_x:
                 print("!")
                 curr = here
@@ -632,4 +651,4 @@ if __name__ == '__main__':
     day7 = day_seven_solver()
     print("day 07: {}".format(day7))
     #submit(day7[0], part="a", day=7, year=2022)
-    submit(day7[1], part="b", day=7, year=2022)
+    #submit(day7[1], part="b", day=7, year=2022)