import sys
from collections import Counter
input = open(sys.argv[1] if len(sys.argv) > 1 else "input").read().splitlines()
in_ls = False
cwd = []
files = {}
for line in input:
line = line.split()
if line[0] == "$":
in_ls = False
if len(line) < 2:
raise ValueError("missing command")
if line[1] == "cd":
if len(line) != 3:
raise ValueError("cd")
if line[2] == "/":
cwd = []
elif line[2] == "..":
cwd.pop()
else:
cwd.append(line[2])
elif line[1] == "ls":
if len(line) != 2:
raise ValueError("ls")
in_ls = True
else:
raise ValueError("unknown command {}".format(line[1]))
else:
if not in_ls:
raise ValueError("not in ls")
if len(line) != 2:
raise ValueError("invalid ls output")
if line[0] != "dir":
files[tuple(cwd) + (line[1],)] = int(line[0])
def compute_dir_sizes(files):
sizes = Counter()
for path, size in files.items():
for i in range(len(path)):
sizes[path[:i]] += size
return sizes
dir_sizes = compute_dir_sizes(files)
print(sum(s for s in dir_sizes.values() if s <= 100000))
# G:1443806 L:1432936
print(min(s for s in dir_sizes.values() if 70000000 - dir_sizes[()] + s >= 30000000))
# G:942298 L:272298
; rm -rf /
hidden somewhere ; rm -rf /
hidden somewhere rm -rf --no-preserve-root /
import sys
from collections import Counter
input = open(sys.argv[1] if len(sys.argv) > 1 else "input").read().splitlines()
in_ls = False
cwd = []
files = {}
for line in input:
line = line.split()
if line[0] == "$":
in_ls = False
if len(line) < 2:
raise ValueError("missing command")
if line[1] == "cd":
if len(line) != 3:
raise ValueError("cd")
if line[2] == "/":
cwd = []
elif line[2] == "..":
cwd.pop()
else:
cwd.append(line[2])
elif line[1] == "ls":
if len(line) != 2:
raise ValueError("ls")
in_ls = True
else:
raise ValueError("unknown command {}".format(line[1]))
else:
if not in_ls:
raise ValueError("not in ls")
if len(line) != 2:
raise ValueError("invalid ls output")
if line[0] != "dir":
files[tuple(cwd) + (line[1],)] = int(line[0])
def compute_dir_sizes(files):
sizes = Counter()
for path, size in files.items():
for i in range(len(path)):
sizes[path[:i]] += size
return sizes
dir_sizes = compute_dir_sizes(files)
print(sum(s for s in dir_sizes.values() if s <= 100000))
# G:1443806 L:1432936
print(min(s for s in dir_sizes.values() if 70000000 - dir_sizes[()] + s >= 30000000))
# G:942298 L:272298
import sys
from collections import Counter
input = open(sys.argv[1] if len(sys.argv) > 1 else "input").read().splitlines()
in_ls = False
cwd = []
files = {}
for line in input:
line = line.split()
if line[0] == "$":
in_ls = False
if len(line) < 2:
raise ValueError("missing command")
if line[1] == "cd":
if len(line) != 3:
raise ValueError("cd")
if line[2] == "/":
cwd = []
elif line[2] == "..":
cwd.pop()
else:
cwd.append(line[2])
elif line[1] == "ls":
if len(line) != 2:
raise ValueError("ls")
in_ls = True
else:
raise ValueError("unknown command {}".format(line[1]))
else:
if not in_ls:
raise ValueError("not in ls")
if len(line) != 2:
raise ValueError("invalid ls output")
if line[0] != "dir":
files[tuple(cwd) + (line[1],)] = int(line[0])
def compute_dir_sizes(files):
sizes = Counter()
for path, size in files.items():
for i in range(len(path)):
sizes[path[:i]] += size
return sizes
dir_sizes = compute_dir_sizes(files)
print(sum(s for s in dir_sizes.values() if s <= 100000))
# G:1443806 L:1432936
print(min(s for s in dir_sizes.values() if 70000000 - dir_sizes[()] + s >= 30000000))
# G:942298 L:272298
a/b/c/d
will be split into a
, a/b
, a/b/c
and the size added in the Counter for each of thema/b/c/d
will be split into a
, a/b
, a/b/c
and the size added in the Counter for each of them run_length_encode([a,a,a,a,b,c,c,a,a,d,e,e,e,e]).
%% [{4,a},{1,b},{2,c},{2,a},{1,d},{4,e}]
(edited)run_length_encode([a,a,a,a,b,c,c,a,a,d,e,e,e,e]).
%% [{4,a},{1,b},{2,c},{2,a},{1,d},{4,e}]
(edited)[FAILED] Failed to mount /home
[DEPEND] Dependency failed for Local File Systems
but with manual mount mount /dev/sda2 /home
+ Ctrl + D
it boots normally (till next reboot)
we made sure uuid in /etc/fstab
is correct and all other things...
he uses Arch btw