Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with open("input.txt") as readFile:
- lineLst = []
- for lines in readFile:
- lineLst.append(lines.strip())
- readFile.close()
- fileSystem = {}
- for line in lineLst:
- if line.startswith('$'):
- if line.startswith('$ cd'):
- if line[5:] == '..':
- continue
- else:
- recentDir = line[5:]
- fileSystem[recentDir] = []
- else:
- continue
- else:
- if line.startswith('dir'):
- fileSystem[recentDir].append(line)
- else:
- fileSystem[recentDir].append(line.split(' ')[0])
- sums = []
- for key in fileSystem:
- while any(file.startswith('dir') for file in fileSystem[key]):
- for i,files in enumerate(fileSystem[key]):
- if files.startswith('dir'):
- fileSystem[key].extend(fileSystem[files[4:]])
- fileSystem[key].pop(i)
- sums.append(sum(list(map(int,fileSystem[key]))))
- sumsLess = []
- for dirSums in sums:
- if dirSums <= 100000:
- sumsLess.append(dirSums)
- print(sum(sumsLess))
Advertisement
Add Comment
Please, Sign In to add comment