-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path7_part1.lua
68 lines (61 loc) · 1.31 KB
/
7_part1.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
require "luarocks.loader"
local inspect = require('inspect')
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
function string.split(inputstr, sep)
if sep == nil then
sep = "%s"
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, str)
end
return t
end
function noop()
return 0
end
local tot = 0
local hirarchy = {}
local cwd = {}
local cwdfor = {}
local lines = {}
local size = {}
for line in io.lines() do
table.insert(lines, line)
end
for idx, line in ipairs(lines) do
if (string.starts(line, "$ cd"))
then
local dumb = string.split(line, " ")[3]
if (dumb == "..")
then
table.remove(cwd)
else
table.insert(cwd, dumb)
table.insert(cwdfor, table.concat(cwd, "+"))
end
elseif (string.starts(line, "$ ls"))
then
noop()
else
local tot = ""
for idx, dir in ipairs(cwd) do
if idx ~= 1 then tot = tot .. '+' end
tot = tot .. dir
if (string.starts(line, "dir") == false) then
if (size[tot] == nil) then
size[tot] = 0
end
size[tot] = size[tot] + tonumber(string.split(line, " ")[1])
end
end
end
end
for idx, cnt in pairs(size) do
if (cnt <= 100000) then
tot = tot + cnt
end
end
print(tot)