cleanup day 10 a bit
This commit is contained in:
parent
5094014b93
commit
7789002a2e
@ -13,11 +13,7 @@ function check_line(l, dict, scores)
|
|||||||
end
|
end
|
||||||
if length(braces) != 0 && b == dict[braces[end]]
|
if length(braces) != 0 && b == dict[braces[end]]
|
||||||
pop!(braces)
|
pop!(braces)
|
||||||
continue
|
|
||||||
else
|
else
|
||||||
@info "found $b"
|
|
||||||
t = braces[end]
|
|
||||||
@info "should be $t"
|
|
||||||
return scores[b]
|
return scores[b]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -25,39 +21,9 @@ function check_line(l, dict, scores)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function p1(input::Vector{String})
|
function p1(input::Vector{String})
|
||||||
dict = Dict(
|
dict = Dict('(' => ')', '[' => ']', '<' => '>', '{' => '}')
|
||||||
'(' => ')',
|
scores = Dict(')' => 3, ']' => 57, '>' => 25137, '}' => 1197)
|
||||||
'[' => ']',
|
return sum([ check_line(l, dict, scores) for l in input ])
|
||||||
'<' => '>',
|
|
||||||
'{' => '}'
|
|
||||||
)
|
|
||||||
scores = Dict(
|
|
||||||
')' => 3,
|
|
||||||
']' => 57,
|
|
||||||
'>' => 25137,
|
|
||||||
'}' => 1197)
|
|
||||||
sum = 0
|
|
||||||
for l in input
|
|
||||||
sum += check_line(l, dict, scores)
|
|
||||||
end
|
|
||||||
return sum
|
|
||||||
end
|
|
||||||
|
|
||||||
function corrupted(l, dict)
|
|
||||||
braces = []
|
|
||||||
for b in l
|
|
||||||
if b in keys(dict)
|
|
||||||
push!(braces, b)
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
if length(braces) != 0 && b == dict[braces[end]]
|
|
||||||
pop!(braces)
|
|
||||||
continue
|
|
||||||
else
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function complete(l, dict)
|
function complete(l, dict)
|
||||||
@ -69,7 +35,6 @@ function complete(l, dict)
|
|||||||
end
|
end
|
||||||
if length(braces) != 0 && b == dict[braces[end]]
|
if length(braces) != 0 && b == dict[braces[end]]
|
||||||
pop!(braces)
|
pop!(braces)
|
||||||
continue
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
out = []
|
out = []
|
||||||
@ -80,19 +45,9 @@ function complete(l, dict)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function p2(input::Vector{String})
|
function p2(input::Vector{String})
|
||||||
dict = Dict(
|
dict = Dict('(' => ')','[' => ']', '<' => '>', '{' => '}')
|
||||||
'(' => ')',
|
scores = Dict(')' => 1,']' => 2,'}' => 3,'>' => 4)
|
||||||
'[' => ']',
|
remaining = filter(x -> check_line(x, dict, scores) == 0, input)
|
||||||
'<' => '>',
|
|
||||||
'{' => '}'
|
|
||||||
)
|
|
||||||
scores = Dict(
|
|
||||||
')' => 1,
|
|
||||||
']' => 2,
|
|
||||||
'}' => 3,
|
|
||||||
'>' => 4)
|
|
||||||
line_scores = []
|
|
||||||
remaining = filter(x -> !corrupted(x, dict), input)
|
|
||||||
a = [complete(x, dict) for x in remaining]
|
a = [complete(x, dict) for x in remaining]
|
||||||
out = []
|
out = []
|
||||||
for e in a
|
for e in a
|
||||||
|
Loading…
x
Reference in New Issue
Block a user