added day 10
This commit is contained in:
parent
8936bbfd62
commit
f07db6262d
98
10/input01.txt
Normal file
98
10/input01.txt
Normal file
@ -0,0 +1,98 @@
|
||||
([(<<<{({([{{{{}[]}<[]<>>}<{()()}{{}()}>}{((()()))([[]<>]<{}()>)}]({((<>{})[<>()])<{()<>}<<>(
|
||||
{<{{<[[[(<<<([{}{}](()()))(([][])<()<>>)>>({([[]]<{}<>>)[{[]{}}{[]()}]}[(([]{})){([]<>)}])>((({{<>[]}
|
||||
[[{<<[{{<[(<[<()<>}[{}[]]]((()()))>{[([]<>)([]())]<([])[{}[]]>})<<<[{}[]]((){})>(<<>[]>[[]<>])>
|
||||
({[{[<([{((((<{}()><<>()>))[<{[]<>}<{}()>>({<>[]}(<><>>)])([[<()<>>({}<>)]({[]()}[[]{}])]))}
|
||||
(<<({{{{({[[(<{}{}>{{}<>}){<<>>}]<(<{}()>{(){}}){[{}()]([]<>}}>][([((){})<[]<>>]<<<>{}>{[]}>)(
|
||||
{(((([{([<[[<[(){}]<()()>>{[[]{}]{{}[]}}]([<<><>>{[]{}}]<{[]()}[()()]>)]((({[]}[<><>]))<<[{}[]][<>()]>([{}[]
|
||||
([({[[<{[{{[{<{}{}>[<>[]]}(([]()){<><>})]{<<<>()>(()())>{{<>[]}[<>{}]}}}(([(<><>){[][]}][{[]}[[][]]])<([{
|
||||
<[<{[(([<[([<<()()>{{}{}}>[[<>][{}()]]]({(<>{})}<(<>{}){<><>}>))(<{[{}<>][()()]}<([]())<<>[]>>>)]><
|
||||
<[([<<{{[(((<[(){}}{(){}}>{[()[]]<[]{}>}))){[[[[<>()](<>())]]]}]{<{(<<{}[]>[<>]><[[]()]<{}[]>>)({[()<>]
|
||||
(({[<([<<([{{{()[]}{[]{}}}{{<>[]}{()[]}}}<<(()){<>[]}>[(<><>]{(){}}]>]([[({}{})((){})][[<><>]((){})]][{(
|
||||
{{((<<<{[({[{{()<>}{[][]}}](<([][])[{}{}]>[{(){}}<[]{}>])}<[{{{}{}}(()<>)}[(()<>)[<><>]]]>)(<<[[[][]][{}<>
|
||||
[({[[{[{[{<((([])){<{}()>{[]{}}})>{<[{()<>>({})][{(){}}<()[]>]>{[{<>{}}(<>{})][<()[]><<>()>]}}
|
||||
<<{[(<<{{{(<{{[]()}<<>[]>}>{<<{}{}>{[]{}}><[{}{}]{{}[]}>})}{<{[<{}{}>({}())]}{[([]())[[]<>]]<{<><>}
|
||||
((<[[[([{(({({()()}[{}()])(<{}()>[[][]])}((<[]{}>(<>()))([<><>][<>{}]]))<{([[]{}][[][]])}>
|
||||
<[<<<<{(((<{[{(){}}{<>()}]}{{{{}()}}<<<>()>>}>{({{<>()}}{<[]<>>[()()]}]}){<(<({}<>){[]<>}>({{}()}(<>())))>
|
||||
(([[[{{{{<<{<[[]()]{()[]}><[<>[]]({}<>)>}<<{[]{}}<<>>><[{}[]](<><>)>>>[({<{}[]>[(){}]}[{(){}
|
||||
{[{[({{({<<([({}[])][{()<>}{<>()}])<{<[]()>{()<>}}>>[(<<[]{}>{()()}>)]>})<{[{({<<>[]>{{}()}
|
||||
<([{[[<[([<(<<<>()><[][]>>)[[[<>()]<<>{}>]]>{<(<{}<>><[]()>)<(<>)[[][]]>>}])]{[[((<({}())[[]{}]><<{}
|
||||
[([[([{[<({(<({}{})[<><>]>){{({}{})(()())}[([]<>)<[][]>]}}}[[([[[][]]]<({}{})(<>[])>)(([[]()]{<><>})[[[]()
|
||||
{[[<[<(({<[{<[()[]>{<><>}>([[]<>]{[][]})}([{<><>}<<>{}>][{(){}}[{}<>]])][<(<()<>>(<>()))[{()<>}
|
||||
(<<<<({[{<[[({()<>}(()()))][({()}[<><>])]]<<[(<>[]){{}()}][([]{})({}{})]>{<[[]<>]<<>()>><[{}()][<>
|
||||
[({<<{{(<{<<{<()()>(()<>)}<{<><>}>>(([()<>][()<>])[(()<>)(()<>)])>[<(<()<>>{{}()}){[[]{}]{<>{}}}>]}[(<[({}(
|
||||
({([([[{{[{{{<<><>>{()()}}[[<>[]][()()]]}({{<><>}{<>()}}<({}())>)}<[{[{}()](<>[])}(<(){}>)]
|
||||
(<{[[[{((<([[<[]{}>([]<>)]{{()()}}]({[{}[]](()<>)}{{{}}[<>()]}))>))}([{(([(<{}[]>[<>()])]({<
|
||||
([{{<([<{{<[{(()]([][])}][{([])<{}{}>}<([]<>)<{}[]>>]>{<[[[]{}]<{}[]>]<{()}({}<>)>>}}}{<{<<[(){}](()())
|
||||
{{<<<[{<([<<([{}[]])([()()][()<>>)><({[]()}[()<>])>>]<{[([{}{}]({}[]))]{(({}{}))(<<>()>({}[]))}}{{[[{}{}]<[]<
|
||||
{[([({[[<{{[{[[][]][<>()]}<<[]()>>]{<{[][]}(<>{})>}}{<[[<><>](<>())](<(){}>({}<>))>[<<[]{}><[]()>>[{[]{}
|
||||
[{{{([{([[[<{{{}()}{<>[]}}[{<>{}}[[]<>]]>]<([{{}{}]<[]()>]){{{{}()}[<>[]]}(<{}[]>{[]<>})}>][{{[<<>{}><()[]>]
|
||||
[<[(<(<([(({({{}<>})[{{}<>}{{}[]}]}{[<[]<>><{}[]>][[{}<>)<()<>>]}){{<<(){}>[{}()]><<()>([]<>)>}})
|
||||
<(([<(([([{([({})][<{}[]><[]()>]){{{[]{}}[[]<>]}<(<>())[{}()]>}}])](<[({(({})(<>()))}{{<[]>}{<<>{}>[()()]
|
||||
[<{[[{([<{[<(({}{})(<>()))><{{{}<>}<()()>}(<<>()>(<><>))>][[[[()<>]<[]{}>]]{({{}[]}<()<>>)}]}([<<[()()]
|
||||
([<{{(<(([<{<(<>{})<<>[]>><{{}[]}<[]{}}>}{(((){}){<>()})[<(){}>{<><>}]}>{<([[]()](()<>)){<()>[<><
|
||||
<(<([({<(([[[[<><>]([]{})]({[]()})](({[]}({}[]))[({}<>)(()())])]<{({[]{}}([]())){<()<>>({}<>)}}
|
||||
[<(<{(<<<([{<[()<>][<>{}]>{[<>{}][()<>]}}{{<<>{}>[<>{}]}[{(){}}[[][]]]}][{[<[]()>(<>())][<<>[]
|
||||
[<[[([[[([([[[<><>]({}())][[<>()]]](([[]]({}))[{()[]}({}<>)]))(([{()[]}{{}}][{()[]}[<>[]]])({{<>{}}{
|
||||
[<[([<<{{{[[[({}{})<()[]>]]]<(({(){}}{(){}})<[{}[]][[][]]>)>}({{([[]{}][[][]])<[<>[]][(){}]>}<[
|
||||
<[<[({{<(<<[{{<>[]}}[(()())<[]<>>]][{{{}<>}<<>[]]}]>>)<{<(((<>[]))[([])]){(<[]()>({}()))[{{}<
|
||||
({([<<<<[<{(((<>[])<()()>))<<[<>[]][<>[]]][{[][]}]>}((([[][]])({{}[]}[<><>]))({[[]<>](<>[])
|
||||
{(<{((({[{({<<()[]>(<>())>{<{}{}><<><>>}}(([[]<>][()[]]){[{}()]}))[<<<<>()}[{}[]]>(<{}{}>{<>[]
|
||||
(<<[{[([<[<[{(<>{})[{}[]]}([<>[]]<{}[]>)]>](({<{(){}}{{}{}}>}<<{[][]}<{}()>>[{[]{}}{[][]}]>}[{<([]()){<>
|
||||
{[{{<[[([<{[{([][]){<><>}}[[{}}<<>()>]](<[<><>]({}<>)>[<{}<>><{}{}>])}[<<{()[]}><{{}<>}<<><>>>>([[[]{}]<()<>>
|
||||
{[<{{([[[[{({{()<>}(<>[])})}(((<{}[]>))<[(()[])[{}{}]><<{}()><(){}>>>)][<(<(()[])((){})><[{}()]<[]<>>>
|
||||
{<{[[{<[(({[{<()()><{}<>>}{[[]{}]([]<>)}]([({}[])<[][]>]<[[]{}][()()]>)})<(((<<>{}>[<>()])(
|
||||
[[<{{{(<[{{[[({}<>)<()<>>]]>}{(<[{<>()}]<{{}()}<<>[]>>>{{(<><>){()<>}}[{(){}}<<>{}>]})[{<<()<>>
|
||||
{[{(<({[[{[{{<[]{}>{[]()}}([[][]][{}{}])}[<{<>{}}<[]<>>>({()()}{[]()})]]<(<{()()}([][])>[{<>
|
||||
[[{[[<{{({(<{([]()){()<>}}([()()]{<>})>[[{<>{}}({}<>)][{{}{}}<()[]>]])<<[<[]{}>[{}[]]]{[{}[
|
||||
({({<<{<([[<({[]()}[<>{}]){[{}()][{}<>]}>][<<<{}[]>[{}<>]><<<>>[()()]>><([[]{}]<<>()>>({[]<>}<{}[]>)>]])
|
||||
{<[{[[{<<([({{<>{}}[{}{}]}(({}{})(<>())))<[([]{}){{}()}]>]([[<[][]>]{<{}[]>{{}()}}]{{[()[]
|
||||
{[([[[({([<<(<<><>>[[][]])>([<{}[]>])>({{{<>{}}{{}{}}}{<<>{}>({})}}{[{()<>}]})])>([<[{{([]{}){()()}}[{{
|
||||
<{<(<<{[<([(<<[][]><<>[]>>(<[]{}>(<>[])))])[({(((){}){[]{}})({()()}<{}>)}<<([]())<()<>>>[{<><
|
||||
<[([{{<<[{([[{<>[]}([][])]]([(<><>){{}}]<<<>[]>[{}[]]>))([[[<>{}]{[]()}][({}())>][[[<><>]]{({}())[<>{}]}]
|
||||
{<[[[<[[{[[{((<>{})[()()])[<<>>{()<>}]}]]{{{<(<>{})<[][]>>[{<>{}}{{}[]}]}({{[]<>}(<>())}<<[]{}>>)
|
||||
{<{<<({<<(([([(){}][()<>])[{[][]}(()[])]]{((()())[[]<>])})][[[[<[]{}>[<><>]][[()()][<>]]]({[{}{}]([]()
|
||||
{[<([(({<<[<{<()><[]{}>}><((()[]))<[()][{}{}]>>](([[()[]][<><>]][({}[])[()[]]])<<{{}{}}<[]<>>>{[(
|
||||
{[([{<{[<<[({{[]{}}<<><>>}{{()<>}<[]{}>}){{{[]<>]<{}[]>}[(()[])]}][(<[{}]>{([]<>)[[]{}]}){{[[]<>]}<{()
|
||||
<({{{({[(<<<{<()[]>({}[])}{[()()]{[]<>}}>(<[[]()][<><>]>{([])<<>()>})>({{<{}()>(())}(({}){()<>})}[<<{}{}>{()
|
||||
<({[({[(<[(<[(()())][([])[{}]]>{{{<><>}(<>{})}(([]{})<()()>)})]>[(([{((){})(<>()}}[([][]){[]}]](([{}[]]<
|
||||
[<({([{{(<<<<({}())>>{{<<><>><<><>>}[({}<>){<><>}]}>[<{<[]{}>{[]()}}<[[]][[]()]>><[{{}<>}<()
|
||||
{<<<([<<[[{([<()[]>{[]()}](<<>{}>([]<>))){<<{}{}><{}{}>><<[][]>({}{})>}}{<[<[][]>[<>()]]{[()[]]{[][]}}><<{<>}
|
||||
<({[[<[{<(({{(()<>){{}<>}}[<()<>>({}[])]}<(<<>[]>{()()})[<[]{}>(()<>)]>)[<<{[]<>}(()<>)>[{(){}}<{}()>]>{({
|
||||
(<([{{{<{({[<{()[]}{{}()}>]})}](<{(<<<[]{}>({}{})>[(()<>){[]{}}]>{({{}()}{{}<>})(<()()>[<>{}])})[([[{}<
|
||||
((<(<<[((<{{[<<><>>{()<>}]([<>[]]<()<>>)}}><[(<{[]{}}{<><>}>{<{}{}>(()())})][[{[{}()][<>()]}((<><>)[<>[
|
||||
([[[([<<{((<<({}[])(<>{})><({}())[<>[]]>>){((<[][]>([]<>)){{(){}]<<>[]>}){[{<><>}[{}{}]]}}){{{[{<>()}({}[])]<
|
||||
<{{[{[<<[<{<<(()())(<>())>((<>[]))>[{[()()](<>()}}{({}<>)(<>{})}]}>]>{[<[{[{<>{}}{{}[]}]}{[<<><>>({}())](((
|
||||
{<{[(<[(({<<{[{}[]](<><>)}<<()[]><{}<>>>><(((){})[{}])<[<>()]<()<>>>>>[{<[{}<>]<<>[]>>(<[]()>(<
|
||||
[<<[[{[({(<((({}{})(<>())))[{{[]<>}<(){}>}]>([({{}<>}[[]{}])]((({}())(<>[]))([[]<>](()[])))))}[<(((({}()){<>[
|
||||
{<((((({((<[{[[][]](<><>)}{{{}{}}(()())}]{((<><>)<[]()>)<<()<>>(()<>)>}>[{([{}()]<[]<>>){<[]<>><(){}
|
||||
([{[<[<((<[<<{{}()}<<>{}>>([<><>]([]{}))>}(<{([]()){<>()}}[<[]<>>(<><>)]><(<()[]><()<>>)<[{}[]]
|
||||
<<{[[<{{[({[{{{}{}}(()[])}]})]}([{[{([()]({}{}))[([][])<()[]>]}({{[][]}{[][]>}([()()]))][<(
|
||||
<<{{[[<([{{({[()())(<><>)})}}{(<([<>()][[]<>])[{()[]}{{}{}}]>({{<>()}{{}<>}}))[({<[]><<>>}((<>()
|
||||
{<<<({[<<[{((<{}[]>([][])))[([{}{}]<{}{}>){[()()](()<>)}]}{<{(<>())<{}<>>}([[]()]({}))>{[(<>[]
|
||||
(<<[{[({{{<{[<[][]><[]()>][{()[]}[<>[]]]}><<[(<><>)<[][]>]<<<>{}><[]<>>>>({<{}()>([]<>)}({()[]}
|
||||
[<<[<[[(<{[{[[{}[]]{()<>}]<[{}{}][{}()]>}{(<{}<>>{()[]})<{()[]}[[]()]>}]}{{<((<>{})[{}()])[{<><>}<[][]>]>[<{
|
||||
{<<{([({<(<{(<[]<>>)}[<{[][]}>((<><>)((){}))]>)[(<{([]())[{}()]}<({})>>(<[()<>][[][]]>{([][])<()[]>})){[{<
|
||||
{<(([{<<[[[({{[]{}}({}<>)}[(<>{})[<>[]]])({[()[]]{[]}]<[<><>]<[]{}>>)][(<[[]()]([]<>)>(([]())({}
|
||||
(<[{([<([(<{{{<><>}<<>[]>}{[<><>][()<>]}}[(<[][]><()<>>)]>[{((()<>)<[]()))[(<><>)<()[]>]}])]<([<<{<>()
|
||||
<[(<({{({[<{({<><>}[[][]]){((){})<()[]>}}{[{[]{}}{(){}}][{{}()}{()<>}]}><{[<{}[]>((){})]({<>
|
||||
({<({(([{<{{<[<><>]{[][]}>[{()()}(()[])}}{<<<>{}>[{}{}]><{[]<>}[[][]]>}}[[{{<>{}}}<{<>[]}{(){}}>][{[(
|
||||
<{[<[([<({[[{<<>{}>{<><>}}((()<>)<()()>)]<{[[]()]({}[])}<(<>())<()[]>>>>{{{{[]{}}[{}[]]}}([
|
||||
<[(([{[[({{{{(()())<()()>}(<<>{}>{[]{}})}<{[<><>][<>()]}<{{}{}}>>}{[(<<>{}>((){}))[<[]()>{
|
||||
{<<(<(({[<[{[((){})([][])]}{<(<>{}}(<>{})>[([]<>)([][])]}]{[<((){})<()<>>><<[]<>><{}()>>]({(()<>)}{<{}<
|
||||
[[[(([([[[[[{[[]]}{({})(<>{})}){({{}}[{}[]]){<(){}><[]<>>}}]]]]){(([{(<<{}[]>(<><>)>)<<{{}[]}[<><
|
||||
([(<(((({{[<({[]<>})(([])[{}[]])>[[<<>()>[<>()]][[[][]][[][]]]]]{<<([][]){()[])>(<{}{}>[[]
|
||||
([(([(<<([[{{<{}<>>(<>[])}[[[]<>]<()()>]}[(({}<>){<>{}})[<[][]>[[][]]]]]{[{({}[])}<(<><>)[()<>]
|
||||
{(<<(<[({(<[{[(){}]<<>()>}[[{}<>]{[]{}}]]><<[(()<>){[]{}}]{{[]}{<>}}>[[(<><>)]<(<>{}){{}{}}]]>)}([<{({(
|
||||
[{<<<[{(<{(<<<(){}>[<>[]]>[{[][]}<<>{}>]>)<<[{(){}}{()<>}]<<()[]>]>([[[]()]<{}[]>](<<>()><<><>>))>}>)({[<<[
|
||||
{<[([[([({([[(<>{})][([]()){[][]}]]{(<<><>>[()<>])<<{}<>>[()]>})})]{<[<((({}<>){{}{}}){<[]()>[<
|
||||
<[<<([(((<<<([{}{}][<>()])>>{[[<()()>([]<>)]({<>{}}<{}{}>)]([(<><>)([]<>}]{{()<>}{{}[]}})}>{[[{{[]<>}<
|
||||
<[{{{[<([[{[{[()[]]}(({}()){[]()})](({()}{{}()}){([]())<[]<>>}}}<{<([]())[()<>]>([[]()][{}{}]
|
||||
<(<<<<{[{(({[{{}<>}[(){}]}}([(<>())]{[[]](<>{})}))(<[{{}<>}{<>()}][[[]{}]({}[])]>[(([]())<[]()>)[[()]{[
|
||||
[<{[<<{[{{{[<{()[]}([]<>)>((<>{}))][[((){})[<>{}]]<(<>{})>]}}<({<{{}}[{}()])<(()<>)<{}{}>>}<<
|
||||
<({<{{<{<[[(((()<>)[()()])[{[][]}<<>{}>])(<({}<>)(()<>)>[<<>{}>([]<>)])][{{[{}[]]((){})}([[][
|
||||
<<<{{<<<<({(<{{}<>}<[]>>{<<><>>{[]{}}})<(<{}>({}<>)){{<>()}[()[]]}>]<{[<()<>>([]{})]{[(){}
|
||||
(({<({[[{[{{{{{}{}}{<>{}}}[<<>{}><{}()>)}}]}(([{(<()()><{}()>)[{<>()}(<>())]}][[<{{}{}}({})>[<[]<>>
|
||||
<{<<{[{[{(<([{<>[]}<()[]>]{{[]()}<{}[]>})<[[<>()]{()[]}](([][])[{}{}])>>)<({<({}[])[{}[]]>({[]{}}
|
||||
(<([{{{(({({<{<><>}[{}<>]>})<{[(<>())[<>[]]]}{<(<>{}){{}()}>}>})(([((<[]()><[]()>))(<<()[]>{<>{}
|
||||
<[[[{{[{<<[(({{}<>}<(){}>)[<{}{}>({}())])]<{<{{}[]}>}{([()]{<>{}})}>>>(<([(((){})[(){}])])(((<(){
|
||||
[[[{{[{[([(<[{()<>}((){})]{[{}()][<><>]}>)([{<(){}>}({<>}[<>[]])]<{{{}()}(<>[])}<(()())([]
|
10
10/input01_sample.txt
Normal file
10
10/input01_sample.txt
Normal file
@ -0,0 +1,10 @@
|
||||
[({(<(())[]>[[{[]{<()<>>
|
||||
[(()[<>])]({[<{<<[]>>(
|
||||
{([(<{}[<>[]}>{[]{[(<()>
|
||||
(((({<>}<{<{<>}{[]{[]{}
|
||||
[[<[([]))<([[{}[[()]]]
|
||||
[{[{({}]{}}([{[{{{}}([]
|
||||
{<[[]]>}<{[{[{[]{()[[[]
|
||||
[<(<(<(<{}))><([]([]()
|
||||
<{([([[(<>()){}]>(<<{{
|
||||
<{([{{}}[<[[[<>{}]]]>[]]
|
35
10/solve01.py
Normal file
35
10/solve01.py
Normal file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
score = {
|
||||
')': 3,
|
||||
']': 57,
|
||||
'}': 1197,
|
||||
'>': 25137,
|
||||
}
|
||||
closing = {
|
||||
'(': ')',
|
||||
'[': ']',
|
||||
'{': '}',
|
||||
'<': '>',
|
||||
}
|
||||
|
||||
|
||||
|
||||
def check_line_score(line):
|
||||
stack = ""
|
||||
for c in line:
|
||||
if c in '{([<':
|
||||
stack += c
|
||||
continue
|
||||
l = stack[-1]
|
||||
if c != closing[l]:
|
||||
return score[c]
|
||||
stack = stack[:-1]
|
||||
return 0
|
||||
|
||||
total = 0
|
||||
with open("input01.txt","r") as f:
|
||||
for line in f:
|
||||
total += check_line_score(line.strip())
|
||||
|
||||
print(total)
|
44
10/solve02.py
Normal file
44
10/solve02.py
Normal file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
score = {
|
||||
'(': 1,
|
||||
'[': 2,
|
||||
'{': 3,
|
||||
'<': 4,
|
||||
}
|
||||
closing = {
|
||||
'(': ')',
|
||||
'[': ']',
|
||||
'{': '}',
|
||||
'<': '>',
|
||||
}
|
||||
|
||||
def check_line_stack(line):
|
||||
stack = ""
|
||||
for c in line:
|
||||
if c in '{([<':
|
||||
stack += c
|
||||
continue
|
||||
l = stack[-1]
|
||||
if c != closing[l]:
|
||||
return None
|
||||
stack = stack[:-1]
|
||||
return stack
|
||||
|
||||
def count_line_score(stack):
|
||||
result = 0
|
||||
for i in reversed(range(len(stack))):
|
||||
result = result*5
|
||||
result += score[stack[i]]
|
||||
return result
|
||||
|
||||
scores = []
|
||||
with open("input01.txt","r") as f:
|
||||
for line in f:
|
||||
stack = check_line_stack(line.strip())
|
||||
if stack is None:
|
||||
continue
|
||||
scores.append(count_line_score(stack))
|
||||
|
||||
scores.sort()
|
||||
print(scores[int(len(scores)/2)])
|
Loading…
x
Reference in New Issue
Block a user