Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ProcessFile(fileName, part) {
- FileRead, data, % fileName
- arrDirs := []
- dictSize := {}
- For k, v in StrSplit(data, "`n") {
- if RegExMatch(v, "^\$ cd +(.*)", m) {
- if (m1 = "/") {
- arrDirs.push("/")
- } else if (m1 = "..") {
- arrDirs.pop()
- } else {
- arrDirs.push(arrDirs[arrDirs.count()] "/" m1)
- }
- } else if RegExMatch(v, "^(\d+)", m) {
- For j, w in arrDirs {
- if !dictSize.hasKey(w)
- dictSize[w] := 0
- dictSize[w] += m
- }
- }
- }
- if (part = 1) {
- totalSize := 0
- For k, v in dictSize {
- if (v <= 100000)
- totalSize += v
- }
- } else if (part = 2) {
- totalSize := 70000000
- threshold := 30000000 - (totalSize - dictSize["/"])
- for k, v in dictSize {
- if (v >= threshold) && (v < totalSize)
- totalSize := v
- }
- } else
- return "Invalid parameter value"
- return totalSize
- }
- MsgBox, % ProcessFile(A_ScriptDir "\aoc7.txt", 1)
- MsgBox, % ProcessFile(A_ScriptDir "\aoc7.txt", 2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement