day 10
This commit is contained in:
parent
edd0059e7e
commit
ce02b1c91b
|
@ -1,5 +1,5 @@
|
|||
import sys
|
||||
L = [int(l[:-1]) for l in sys.stdin.readlines()]
|
||||
L = list(map(int,sys.stdin.read().splitlines()))
|
||||
print(sum([0,1][a<d] for (a,d) in zip(L, L[3:])))
|
||||
|
||||
# window1 = [A,B,C] ; window2 = [B,C,D]
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
import sys
|
||||
from collections import deque
|
||||
|
||||
D = { ">":"<", ")":"(", "]":"[","}":"{", }
|
||||
S = { ")": 3, "]": 57, "}": 1197, ">": 25137, }
|
||||
L = sys.stdin.read().splitlines()
|
||||
N = 0
|
||||
for l in L:
|
||||
Q = deque(["y"]*120)
|
||||
for c in l:
|
||||
p = Q.pop()
|
||||
if c in D: # if closing char
|
||||
e = D[c]
|
||||
if p != e: # fail case
|
||||
N += S[c]
|
||||
break
|
||||
else: # just discard the pair
|
||||
pass
|
||||
else: # not closing
|
||||
Q.append(p)
|
||||
Q.append(c)
|
||||
print(N)
|
|
@ -0,0 +1,28 @@
|
|||
import sys
|
||||
from collections import deque
|
||||
D = { ">":"<", ")":"(", "]":"[","}":"{", }
|
||||
S = { "(":1, "[":2, "{":3, "<":4, }
|
||||
L = sys.stdin.read().splitlines()
|
||||
N = []
|
||||
for l in L:
|
||||
Q = deque(["y"]*120)
|
||||
fail = False
|
||||
for c in l:
|
||||
p = Q.pop()
|
||||
if c in D: # if closing char
|
||||
e = D[c]
|
||||
if p != e: # fail case
|
||||
fail = True
|
||||
break
|
||||
else: # just discard the pair
|
||||
pass
|
||||
else: # not closing
|
||||
Q.append(p)
|
||||
Q.append(c)
|
||||
if not fail:
|
||||
R = list(Q)[120:]
|
||||
s = 0
|
||||
for r in reversed(R):
|
||||
s = s*5 + S[r]
|
||||
N.append(s)
|
||||
print(sorted(N)[len(N)//2])
|
|
@ -0,0 +1,90 @@
|
|||
<[<<<<[{[<({{({}<>)<[]{}>}[<<>{}>{<>{}}]}{(({}<>){()<>}){{[]<>}{[]}}})>([{{(()[])[{}()]}}(<{{}<>}
|
||||
<<[<<{[<<<{{<(()[])>[({}{})]}}({{({}())[<>{}]}}{{(<><>)[<>()]}<<<>{}><<>()>>})>{[[<(<>[])[[]{}]>{{[]<>}<[]
|
||||
<[{<<(<([{<[<{()<>}<{}[]>>([<>()]{<>()})]{[([][])<{}<>>][<<><>>]}>}][[[<{{[]{}}[[][]]}([{}[]]<[]<>
|
||||
<{[(<<[({([{<[{}[]]{<>{}}>}[(({}()){[]<>])]]{{<<[]>([]<>)><<{}()>{<>[]}>}{({<><>}<<>{}>){(()[])<()<>>}}})
|
||||
[{<{[(({[[<<<<<>()>{(){}}>[{[]{}}(<><>)]>{[<[][]>(()<>)]<<[]()><()()>>}>])}(<{<[<<{}[]>>{[()[]]({}{})}]>{
|
||||
[<{<[[[<{[<<[{<>{}}<(){}>]{<{}{}><{}{}>}>{<(()<>){<><>}>}><[<{{}()}>{{<>()}{()<>}}]({<{}<>>}[{()<>}[()()]])
|
||||
(([(<({[<<({{<()()]{[]{}}}[{<>()}[[]()]]}({[<><>]}<[<>{}][()<>]>)){{[[[]<>]<<><>>](({}{}){{}()})}}>>]})>)<((
|
||||
(<<({((<<(<{([()]<()[]>)}[{(()<>)(()())}{{()<>}<()()>}]>)({[<(<>())((){})><{<><>}[{}<>]>][[[<>
|
||||
[(<([{[[[{{{([()()]([]()))[<[][]>[<><>]]}{(<[]>[(){}]){[<>{}]{{}()}}}>[<<[[][]][{}()]>[<<>{}>
|
||||
{<{[[[{<<([({[<><>][(){}]}({(){}}[{}<>]))<{[(){}][<>{}]}{(()()){{}[]}}>]{[((()[])<()[]>)<<(){}>{{
|
||||
[<[{{{({([({<<(){}>[{}<>]><{{}<>}[<><>]>}[[<(){}>([]{})]<{(){}}[{}[]]>])[<({<>{}}<{}<>>)({<><>})>]]){(<(({
|
||||
<<{[[{[[(<[{[[{}()][()[]]](<[]{}>(<>))}(([{}()])<[{}()](<>())))]><(<[[<>{}](<>())][[<>()][()]]>{<<<><>>[()[
|
||||
<<([<[{{[[({[{()}[{}<>]]({{}{}}{<><>})}<{{{}()}<()[]>}<<{}{}><[][]>>>)<{([[]<>]<{}()>)][([{}()
|
||||
[(<<[[{<<{<[[<()[]>({}<>)]<{[]<>}<{}<>>>]{<<()<>>[[]{}]>([{}()]{()()})}>[<{((){})[{}()]}[([]{})<()[
|
||||
[<<(<{[{{[<{(([])({}())){<<>>{()[]}}}{[(<><>)[[]()]]{<<><>><()<>>]}><((<<>()>{<>{}})){[{()()}][[()[]]([]{})
|
||||
((<[({<[(({[{(()())<(){}>}<[[]<>]{()()}>]({<()<>>(<>())})}<(<[[][]]{<>[]}><<[]<>>[{}[]]>)<{([]{})[{}()]}([[]
|
||||
[([{<[{(<<({[<{}()>([][])]{({}<>){{}[]}}}[<((){}){<>{}})[{(){}}]])({([{}<>]{<>{}})})>[<<{<{}<>><[
|
||||
[{{{[<({({{{[<{}()><[][]>]({{}{}}([]))}{<[<>{}]{{}{}>><{{}<>}>}}}[[[([{}()](()()))][({<>{}}{<>{}}){
|
||||
[<{[{{(<{[<[(<()()>{()[]}){{{}{}}(<><>)}]<<({}{}){{}()}>{([])(<><>)}>>[({{[]{}}})<{(<><>){(){}}}((()<
|
||||
<[<<[<(([<[{(<[][]>(<>[]}){{{}<>}[{}()]}}]<[[<{}{}>{()()}][[<>()]]]([<()>(()[])])>>][{[((<[
|
||||
[{({<[[{<<[<[(<>{})<[]{}>]<<[]{}>[<><>]>>{({()<>}[<><>])}]><{{{{[]()}{<>[]}}<((){})>}({<(){}>[
|
||||
{[<([[<(((<{<{[]<>}<[][]>>}>)))[<<{[([[]<>]([][]))(({}<>)<<><>>)]<{{{}{}}<<><>>}([()<>](()()>)>}>>]>{({<{
|
||||
{{{{(([<(<{({(()())([][])}{({}()){[]{}}})}({(((){})[{}[]])}{((<><>){<><>}>[<{}[]>{<>[]}]})><[{<(<>[
|
||||
<[<[<(<<<{(([[(){}]({}<>)]){<[()<>]{()()}>[[{}{}](<>)]})((((()<>)({}<>])[[{}<>][<><>]])(<<{}{}>(()()
|
||||
[[{(([<{<[[({{{}{}}<[]<>>}{([]){<>()}})[(<[]()>(<><>)){<<>()>{()[]}}]]]>(<[[{(()<>)[[]{}]}(([]())(()
|
||||
{<<(<<([(<(<({[]{}}{[]<>})>({([]<>)<[]{}>})){{([(){}]([]<>)){[[]()]}}}>{<{((()](<>()))}[(<{}<>>((){})
|
||||
[({{{{{(<{({[{<>())(()())][<[]<>><[][]>]}{<[<><>][()()]>[<()()>([]{})]})<[[([][])<[]()>]<([][])<()<>>>]
|
||||
[[[<([<[<(<{(([]<>)<{}<>>)<[{}[]]<()[]>>}{{([]()){()[]}}([{}{}](()()))}><{{<()<>><()()>}{<{}<>}{<>()}}}{{[[
|
||||
(<({({[[(<[{<{(){}}[{}{}]><{()()}>}[([<>()]({}<>)){<{}()>({}[])}]]>)[[(([(<>[])<()<>>]){[<
|
||||
({<[<{<<{{{({[()[]]})({[()()]{{}()}}(([]<>)<<>[]>))}}}>>(([({<[{[]}[[]()]][[<>[]]([]<>)]>({[<>()]{
|
||||
{{(<[{({<[{{[{{}()}(<>{})]{[()[]]([]{})}}{([[]()][[]])[[[]()][()[]]}}}[<[<{}()>[{}[]]]>({<[]()>([
|
||||
<(([(([[[[(([({}{}){()<>}]<{()[]}([]<>)]))]][{[({{<>()}<{}<>>})([[<>()]])](<[<<>()>]({()<>}{[]{}})>{[(()
|
||||
([<{[<<<(<[{(<{}<>>[<>()])[<(){}>]}[[[()[]][()<>]]<<[]{}><<>()>>]]<[<{{}<>}{()<>}>{{[]()}})(<<<><>>>{
|
||||
[{({{<(((({(<{(){}}>((())(()<>)))((<{}{}>((){}))<[[]]((){})>)})(<(([[]{}]<<><>>)<{()[]>(<>())>)>))))>}{{{({
|
||||
[{(<<{{(<[{({{{}{}}{<><>}})}(<{({}<>)[<>{}]}<[{}{}]{{}{}}>>)]>([[{(<[][])<[]<>>)<(()<>)[[][]]>}[({()<>
|
||||
<[([[((([{<[{(<>{}){<>()}}(({}[]])]([([]())<<>[]>])>[{<[{}<>](<>[])>}<[[(){}][{}()]]{{{}<>}[{}[]]}>]}])))][{(
|
||||
(<[[(({({{[<<[<>[]][<>{}]>[[<>{}]((){})]><<<{}<>>[<>{}]><{[]{}}[()<>]>>]([[[<>{}]{()()}]<<()<
|
||||
[{{{{<<{{{{<({<>()}((){}))(<[][]>{[][]})>{<(()<>)[()<>]><<{}{}>{{}[]}>}}<[[<{}{}>]{[<>()]<<><>>}]{<(()())<{}
|
||||
([(<<{[{(<{<(<{}{}><{}<>>)[(<>[]){(){}}]>({<[]()>(<>{})}<{[]{}}[(){}]>)}>([[<<[]()>(<>)>(<<>[
|
||||
<(<<{<{[{[<[{<()<>>([][])}]>]}]}><<<[([{(({}{})(()()))({()()}<<>>)}([(<>{})(<>[])][({}<>)[[]<>
|
||||
<([[((<[<[[((<{}<>><{}()>)<(<>{})<[]<>>>)[<{()}({}())>{[[]{}]{()[]}}]]<<[(()[])(<>())]{<[]<>>
|
||||
<<{{{<<({{<[<[<>()]{{}<>}>{<()<>>{[]{}}}]>}}{({[<[()[]][<>{}]>((()[])<{}()>)]}([{[[]{}]<[]<>>}{([]
|
||||
(({[(<({<{[[{<<><>>({}[])}(<<><>>[[]{}]))(<{<>{}}[[]{}]>[[<>{}]({}{})])][<[<()[]><()<>>]><[({}[])[<>()]]<([](
|
||||
([([[([(<{[<([<>{}][(){}]){<<>()><()<>>}>{[{()<>}[[][]]][[{}{}]<(){}>]}]([<[[]()]{{}[]}>[{<>[]}[[](
|
||||
({((<[(<(({{([{}[]](<>()))[({}())]}[{[<>{}]<<>()>}{[{}]}]}({{<[][])[{}[]]}}((<<>{}><<>{}>))))<[<{[(){}][{
|
||||
{([<{{(({[(<<{<>{}}[<><>]>{(<>[])({}())}>{((()[])[{}]){([][])((){})}})][<[<<[]()>{(){}}>]((<{}()>[{}()])<<{
|
||||
{{<<(<[<(((({{{}<>}{[]<>}}[(<><>){[]()}]))[<{([]<>)<[]()>}([[]{}]<()>)>{{[<>[]]({}<>)}{<<>[]>[<><>
|
||||
[<({{[{{[(<[[<[][]>{<>{}}][{{}[]}[(){}]]]>{{(<{}[]>(<>()))<((){})>}[{([])}]}){[<[{()<>}<[][]>][[
|
||||
({<{{{(({({<(<{}[]>[[]<>])>})}<{(([{<>{}}<<>()>](([]<>){()[]}))([({}{}]{{}{}}][{()[]}{()()}]
|
||||
((((<({[[<(<{(()[])((){})}>(([{}()]<<><>>)[{()[]]{{}}]))[[{(<>()){<><>}}{<<>[]>[[]<>]}][[{
|
||||
({<[<((<({<<((<><>)(<>[]))[{[]{}}{[]{}}]>{[[()()]{()()}]{[<>{}]}}><({[[][]][()<>]})>}([[[(
|
||||
({<(<<<<<(<[<[<>()](()>>][<<<>()>[{}[]]><(<><>)>]><({<<>{}>}[<<><>>{(){}}])[{{<>{}}<[]<>>}]>)(<{{{()()}
|
||||
[<<[{[<{([([{<()()>[{}[]]}<<()[]>{()()}>][<<{}>[[]<>]>{[()[]][[]()]}]){[((()<>)<{}[]>){[[]()][{
|
||||
[{[<{<{(({{<(({}[]))[[{}[]]{[][]}]>}}<([{(()[])}<[[]()]>]{<<<>()>[<>[]>>[[[]()][[][]]]})>){<<[<<{}()>(()
|
||||
<(({{<{{<[{(<[[]<>]><({}{}){[]{}}>){{[[]{}]({}<>)}<((){})<<><>>>}}{[(([]<>)[{}<>])({<><>})]<(<()<>>{(
|
||||
[[{[(<(<<[(<[[<>[]]((){})]{[<><>]<{}[]>}>)<[{{()[]>(<>{})}(({}[]){{}[]})]<<[{}{}]>{[{}{}]}>>][{([<()<>>({}
|
||||
[({<({[[<[{<<{{}[]}<(){}>><[[]()][{}{}]>><{([])([])}[({}<>){()()}]>}{[{<{}{}>[<>()]}]({({}[
|
||||
{{<[<[(([<{[{{[]{}}[[]{}]}]}>[[(<{[]()}(()())><{(){}}(<>())>)[<([]()){{}<>}>[<[]<>>{{}[]}]]](((({}
|
||||
{(<<[(({{[[{([[][]]{{}()})([()<>][{}{}])}]([[{[]<>}({}{}]][<{}[]>]](({{}[]}){<{}[]>((){})}))][<((
|
||||
{{{{({{({[{{([{}[]]<(){}>)<<[]()>([]<>)>>{[{{}()}]<[{}]<()()>>}}[[{<[][]>{[]{}}}({()[]}<[]()>)][<[{
|
||||
[{{[[({[[[[((<{}[]><{}[]>){[{}{}]{()[]}})({{(){}}([])}<<[]()>[{}{}]>)]}{{{({[]}({}))<((){}){{}<>}>}{{
|
||||
[<{([{(<{(((([()<>]<()<>>)[[<>()]([]{})])[(({}()))<<<>()><[]>>])[<{{<>{}}[()()]}(<[][]>{()()}
|
||||
({(({{<[{<{((<{}{}>{{}[]})<{{}()}{{}()}>)[[({}()){[]<>}]{<()>[{}<>]}]}><{[[(<>{})<[][]>]<{{}<>}{{
|
||||
(({{(({(<[[{[<<>{}>{[]()}][{[]{}]{(){}}]}(((()[]){{}{}})<(()())>)]([<[{}[]]>])][<{{[{}[]]<<><>>}{[[
|
||||
((<[[<<<[([<[<<><>>([][])](<[][]>{<><>})>((({}<>)((){})))>[[<[<><>]<{}<>>><({}[])([]{})>]])[{[{({}<>)[()[]
|
||||
[<((({{({(({<(()())<{}[]>>(<[]{}>({}{}))}))[<<[({}[])[{}[]]]<{{}{}}{[]}>>>]}[(<({<{}()>[<>()]}[<[]()>((){
|
||||
[[([(((<{[[[<[{}()}({}<>)>]]{<{{<><>}({}())}{{<><>}([]{})}>}]}[([{[{[][]}(()<>)]{{<>{}}[<>(
|
||||
<<([<{{<{<<(<([]<>)><(<><>){{}{}}>)<(<()<>>([]<>)){(<>{}><<>>}>>{(((()[]){{}[]})[[[][]][{}[]]])({([
|
||||
[<[{<[<<(([{({[]{}}([][]))<[()<>]{{}<>}>}]<<[<{}>[<>{}]][([]<>)(<>[])]>[{((){})(()())}<[{}()]{<>()}>]>){([
|
||||
[[[{[(({<<{{{((){})({})}{[<>()]([]<>)}}{[<<>{}>[{}[]]][[{}<>][()<>]]}}>{<{{([]{}){{}[]}}<{<>{
|
||||
{{{<{[[<[{[<[<<>()>{{}()}][[<>{}][[]<>]]>]<{<{(){}}({}{})><(<>())[{}()]>)<{[()()]}[<()<>>(<>)]>>}
|
||||
(([[<{(([<[((<(){}>[{}()]){([]{})[<>{}]})[[[<><>](<>[])]((()()))]][{{<()[]><<>{}>}}]>])<({[[({()<>}[<>{}])]]
|
||||
{{({[({[[<(((({}[])(()()))))(<<<{}()>[{}]>>(<[<>[]]{[]()}>{({}<>)([][])}))>]{({{<(<><>)>[{
|
||||
<<((({[([[{<<{<>{}}[[][]]><{()()}<{}<>>>>}[[[<<>()>([]())]({<><>}{{}[]})]<{<{}<>>[[]()]}{{(){}
|
||||
<[{(([<(<{{[[{{}()}([]<>)](<{}()>{[]{}})]}<[[<()[]>(()())]{([]{})[<>{}]}]<<{[][]}><<<>()>>>>
|
||||
<([(([{([([(<[{}[]][[]()]>(<{}[]>[<><>]))<<{{}()}<<>[]>>>])[[<[{<>()}[()()]]<[{}()]((){})>>]{[{(()[])<(
|
||||
((<([<[[{[{{[(<><>)<[]()>][(<><>)[<>{}]]}}<(([{}()]{<><>})<([])[()()]>)>]{(({[()[])[[]()]}[(<>)])[<{{}
|
||||
{<{<<{{[{<(([{(){}}<<>[]>]<{{}{}}{()[]}>)[<[[]{}><<><>>><[<>()]>])>{(<({{}{}}{<>{}})[<<>[]>]>)((<{
|
||||
[<<<(({{{[(<{([][])[{}<>]}<(()[])(()())>>[{{<>{}}({})}[<<>>[<>]]]){([{()()}[()[]]]{[()[]]<<>>
|
||||
<{{{<(<<{([[(<{}()>(<>{}))]](({[[][]]}({[]<>}{[]<>}))<([{}{}][[]])[<[]()><{}<>>]>))[<<<<()><[][]>>{(()())<[]
|
||||
{{[[{[[{{{[{([<>[]][<>[]>)[({}[]){{}{}}]}[(((){})[()])(({}[])[<>])]]}<[<{<[]{}>({}<>)}{[{}[]]((){}
|
||||
{([<([([{(((([()[]][[]<>])[<[]()><()>])({({}{})<[][]>}[([]<>){[]<>}])))<<{[[{}{}]][{(){}}{[]()}
|
||||
<<[(([{<((<[({<>{}})[(()){[][]}]]>))>}]<({((([{([][])({}<>)}<<()()>([]())>])){{{{[{}{}]<<>[]>}{(()[])
|
||||
[[{<([[{<{((({<>{}}[{}{}])([[]()]{{}[]}))({<[][]><<>{}>})){<(<<><>>({}<>))<([]){<>{}}>>(<<<
|
||||
([({<<{<(<((<(<>{})({})><[[][]](()())>)([[{}{}]([]())][<()[]>[{}[]]])){<[<{}{}]{<>()}][([]{}){<><>}]>}>)>{[[(
|
||||
{<(([<([(([(({[]<>}[{}<>])[(()<>){()[]}])<<{[][]}>({<>[]}{[]<>})>]{{{<(){}><()()>}({[]{}}{{}[]}))([([]())
|
||||
{[<([[{[({[<{{(){}}}{(()[])<()[]>}>]<<<{()[]}><{{}()}([]{})>>{{<<>()><<>[]>>{{<>[]}{<><>}}}>
|
||||
(<(<{[{[([[[([<><>])][({[]{}}({}[]))]]])[<[{({{}<>}([]()))(<{}><()()>)}(<<{}<>><<>()>)<<{}
|
||||
(<[(({{<[{({{<()[]>}{{<>}<<>[]]}}{[{<><>}[{}<>]]((<>))})([[[<>{}]]<([])>])}{<({<[]<>><<>()>}[({}())[<>
|
||||
{[({([(<{[[[<<<>[]>(()<>)>]<(([]{})[[][]])(<[]()><{}<>>)>](({{<><>}<()<>>}{[{}{}]([]<>)})[<{<>}[[]{}]
|
|
@ -0,0 +1,10 @@
|
|||
[({(<(())[]>[[{[]{<()<>>
|
||||
[(()[<>])]({[<{<<[]>>(
|
||||
{([(<{}[<>[]}>{[]{[(<()>
|
||||
(((({<>}<{<{<>}{[]{[]{}
|
||||
[[<[([]))<([[{}[[()]]]
|
||||
[{[{({}]{}}([{[{{{}}([]
|
||||
{<[[]]>}<{[{[{[]{()[[[]
|
||||
[<(<(<(<{}))><([]([]()
|
||||
<{([([[(<>()){}]>(<<{{
|
||||
<{([{{}}[<[[[<>{}]]]>[]]
|
Loading…
Reference in New Issue