2 Commits aacfa82704 ... ab73892183

Auteur SHA1 Message Date
  hvincent ab73892183 d7 cleanup il y a 2 ans
  hvincent 5f3bab0aa8 inline comment d7 il y a 2 ans
1 fichiers modifiés avec 42 ajouts et 47 suppressions
  1. 42 47
      2022/solver.py

+ 42 - 47
2022/solver.py

@@ -437,6 +437,12 @@ def day_six_processor(input, length):
 
 def day_seven_solver():
     """
+    oh my god parser hell
+
+    i got stuck on p2 all day because i was returning the name of the directory
+    and not the size. oops.
+
+    did a little cleanup post-star.
     """
 
     s_data = """$ cd /
@@ -472,8 +478,6 @@ $ ls
     p1 = day_seven_processor_a(root, all_dirs)
     p2 = day_seven_processor_b(root, all_dirs)
 
-    print(len(all_dirs))
-
     return p1, p2
 
 class Directory:
@@ -488,33 +492,15 @@ class Directory:
     def add_dir(self, dir_name, dir):
         self.dirs.update({dir_name: dir})
 
-    def calc_subdirs(self):
-        for x in self.dirs.values():
-            x.calc_subdirs()
-            self.size += x.get_size()
-
     def get_size(self):
         return self.size
 
-    def get_dirs(self):
-        return self.dirs
-
     def get_name(self):
         return self.name
 
     def get_dir(self, dir_name):
         return self.dirs.get(dir_name)
 
-    def list_subdirs(self):
-        subdirs = []
-
-        for x in self.dirs.values():
-            subdirs.append(x)
-            if len(x.get_dirs()) > 0:
-                subdirs += x.list_subdirs()
-
-        return subdirs
-
 def day_seven_parser(input):
     home = Directory("root")
     here = home
@@ -523,12 +509,13 @@ def day_seven_parser(input):
 
     for i in range(len(input) - 1):
         line = input[i]
-        print(line)
 
         if line[0] == "$":
             cmd = line.split(" ")[1:]
             if cmd[0] == "ls":
                 ls = []
+
+                ## slurp up all the ls output
                 for j in range(i+1, len(input)):
                     if input[j][0] != "$":
                         ls.append(input[j])
@@ -548,16 +535,7 @@ def day_seven_parser(input):
                             parent.add_file(filesize)
 
             elif cmd[0] == "cd":
-                #print(last)
-                print("{}: {}".format(here.get_name(),id(here)))
                 if cmd[1] == "..":
-                    #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
@@ -565,9 +543,6 @@ def day_seven_parser(input):
                 else:
                     last.append(here)
                     here = here.get_dir(cmd[1])
-                print("->{}: {}".format(here.get_name(),id(here)))
-
-    #home.calc_subdirs()
 
     return home, all_dirs
 
@@ -584,30 +559,45 @@ def day_seven_processor_a(home, all_dirs):
 
 def day_seven_processor_b(root, all_dirs):
 
-    ans = 0
-
     disk   = 70000000
     needed = 30000000
 
     free = disk - root.get_size()
     delta = needed - free
-    print(delta)
-
-    curr = ""
-    curr_x = disk
+    curr = disk
 
     for x in all_dirs:
         a = x.get_size()
-        here = x.get_name()
 
         if a >= delta:
-            print("{}: {}".format(here, a))
-            if a < curr_x:
-                print("!")
-                curr = here
-                curr_x = a
+            if a < curr:
+                curr = a
 
-    return curr_x
+    return curr
+
+def day_eight_solver():
+    """
+    """
+
+    s_data = """
+""".split("\n")
+
+    #data = get_data(day=8, year=2022).split("\n")
+
+    p1, p2 = "",""
+
+    p1 = day_eight_processor_a(s_data)
+    #p2 = day_eight__processor_b(s_data)
+
+    return p1, p2
+
+def day_eight_processor_a(data):
+
+    return 0
+
+def day_eight_processor_b(data):
+
+    return 0
 
 if __name__ == '__main__':
     #day1 = day_one_solver()
@@ -643,4 +633,9 @@ 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)
+
+    day8 = day_eight_solver()
+    print("day 08: {}".format(day8))
+    #submit(day8[0], part="a", day=8, year=2022)
+    #submit(day8[1], part="b", day=8, year=2022)