day 10
This commit is contained in:
		| @@ -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] | ||||
|   | ||||
							
								
								
									
										22
									
								
								d10/d10_1.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								d10/d10_1.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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) | ||||
							
								
								
									
										28
									
								
								d10/d10_2.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								d10/d10_2.py
									
									
									
									
									
										Normal file
									
								
							| @@ -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]) | ||||
							
								
								
									
										90
									
								
								d10/input
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								d10/input
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | ||||
| <[<<<<[{[<({{({}<>)<[]{}>}[<<>{}>{<>{}}]}{(({}<>){()<>}){{[]<>}{[]}}})>([{{(()[])[{}()]}}(<{{}<>} | ||||
| <<[<<{[<<<{{<(()[])>[({}{})]}}({{({}())[<>{}]}}{{(<><>)[<>()]}<<<>{}><<>()>>})>{[[<(<>[])[[]{}]>{{[]<>}<[] | ||||
| <[{<<(<([{<[<{()<>}<{}[]>>([<>()]{<>()})]{[([][])<{}<>>][<<><>>]}>}][[[<{{[]{}}[[][]]}([{}[]]<[]<> | ||||
| <{[(<<[({([{<[{}[]]{<>{}}>}[(({}()){[]<>])]]{{<<[]>([]<>)><<{}()>{<>[]}>}{({<><>}<<>{}>){(()[])<()<>>}}}) | ||||
| [{<{[(({[[<<<<<>()>{(){}}>[{[]{}}(<><>)]>{[<[][]>(()<>)]<<[]()><()()>>}>])}(<{<[<<{}[]>>{[()[]]({}{})}]>{ | ||||
| [<{<[[[<{[<<[{<>{}}<(){}>]{<{}{}><{}{}>}>{<(()<>){<><>}>}><[<{{}()}>{{<>()}{()<>}}]({<{}<>>}[{()<>}[()()]]) | ||||
| (([(<({[<<({{<()()]{[]{}}}[{<>()}[[]()]]}({[<><>]}<[<>{}][()<>]>)){{[[[]<>]<<><>>](({}{}){{}()})}}>>]})>)<(( | ||||
| (<<({((<<(<{([()]<()[]>)}[{(()<>)(()())}{{()<>}<()()>}]>)({[<(<>())((){})><{<><>}[{}<>]>][[[<> | ||||
| [(<([{[[[{{{([()()]([]()))[<[][]>[<><>]]}{(<[]>[(){}]){[<>{}]{{}()}}}>[<<[[][]][{}()]>[<<>{}> | ||||
| {<{[[[{<<([({[<><>][(){}]}({(){}}[{}<>]))<{[(){}][<>{}]}{(()()){{}[]}}>]{[((()[])<()[]>)<<(){}>{{ | ||||
| [<[{{{({([({<<(){}>[{}<>]><{{}<>}[<><>]>}[[<(){}>([]{})]<{(){}}[{}[]]>])[<({<>{}}<{}<>>)({<><>})>]]){(<(({ | ||||
| <<{[[{[[(<[{[[{}()][()[]]](<[]{}>(<>))}(([{}()])<[{}()](<>())))]><(<[[<>{}](<>())][[<>()][()]]>{<<<><>>[()[ | ||||
| <<([<[{{[[({[{()}[{}<>]]({{}{}}{<><>})}<{{{}()}<()[]>}<<{}{}><[][]>>>)<{([[]<>]<{}()>)][([{}() | ||||
| [(<<[[{<<{<[[<()[]>({}<>)]<{[]<>}<{}<>>>]{<<()<>>[[]{}]>([{}()]{()()})}>[<{((){})[{}()]}[([]{})<()[ | ||||
| [<<(<{[{{[<{(([])({}())){<<>>{()[]}}}{[(<><>)[[]()]]{<<><>><()<>>]}><((<<>()>{<>{}})){[{()()}][[()[]]([]{}) | ||||
| ((<[({<[(({[{(()())<(){}>}<[[]<>]{()()}>]({<()<>>(<>())})}<(<[[][]]{<>[]}><<[]<>>[{}[]]>)<{([]{})[{}()]}([[] | ||||
| [([{<[{(<<({[<{}()>([][])]{({}<>){{}[]}}}[<((){}){<>{}})[{(){}}]])({([{}<>]{<>{}})})>[<<{<{}<>><[ | ||||
| [{{{[<({({{{[<{}()><[][]>]({{}{}}([]))}{<[<>{}]{{}{}>><{{}<>}>}}}[[[([{}()](()()))][({<>{}}{<>{}}){ | ||||
| [<{[{{(<{[<[(<()()>{()[]}){{{}{}}(<><>)}]<<({}{}){{}()}>{([])(<><>)}>>[({{[]{}}})<{(<><>){(){}}}((()< | ||||
| <[<<[<(([<[{(<[][]>(<>[]}){{{}<>}[{}()]}}]<[[<{}{}>{()()}][[<>()]]]([<()>(()[])])>>][{[((<[ | ||||
| [{({<[[{<<[<[(<>{})<[]{}>]<<[]{}>[<><>]>>{({()<>}[<><>])}]><{{{{[]()}{<>[]}}<((){})>}({<(){}>[ | ||||
| {[<([[<(((<{<{[]<>}<[][]>>}>)))[<<{[([[]<>]([][]))(({}<>)<<><>>)]<{{{}{}}<<><>>}([()<>](()()>)>}>>]>{({<{ | ||||
| {{{{(([<(<{({(()())([][])}{({}()){[]{}}})}({(((){})[{}[]])}{((<><>){<><>}>[<{}[]>{<>[]}]})><[{<(<>[ | ||||
| <[<[<(<<<{(([[(){}]({}<>)]){<[()<>]{()()}>[[{}{}](<>)]})((((()<>)({}<>])[[{}<>][<><>]])(<<{}{}>(()() | ||||
| [[{(([<{<[[({{{}{}}<[]<>>}{([]){<>()}})[(<[]()>(<><>)){<<>()>{()[]}}]]]>(<[[{(()<>)[[]{}]}(([]())(() | ||||
| {<<(<<([(<(<({[]{}}{[]<>})>({([]<>)<[]{}>})){{([(){}]([]<>)){[[]()]}}}>{<{((()](<>()))}[(<{}<>>((){}) | ||||
| [({{{{{(<{({[{<>())(()())][<[]<>><[][]>]}{<[<><>][()()]>[<()()>([]{})]})<[[([][])<[]()>]<([][])<()<>>>] | ||||
| [[[<([<[<(<{(([]<>)<{}<>>)<[{}[]]<()[]>>}{{([]()){()[]}}([{}{}](()()))}><{{<()<>><()()>}{<{}<>}{<>()}}}{{[[ | ||||
| (<({({[[(<[{<{(){}}[{}{}]><{()()}>}[([<>()]({}<>)){<{}()>({}[])}]]>)[[(([(<>[])<()<>>]){[< | ||||
| ({<[<{<<{{{({[()[]]})({[()()]{{}()}}(([]<>)<<>[]>))}}}>>(([({<[{[]}[[]()]][[<>[]]([]<>)]>({[<>()]{ | ||||
| {{(<[{({<[{{[{{}()}(<>{})]{[()[]]([]{})}}{([[]()][[]])[[[]()][()[]]}}}[<[<{}()>[{}[]]]>({<[]()>([ | ||||
| <(([(([[[[(([({}{}){()<>}]<{()[]}([]<>)]))]][{[({{<>()}<{}<>>})([[<>()]])](<[<<>()>]({()<>}{[]{}})>{[(() | ||||
| ([<{[<<<(<[{(<{}<>>[<>()])[<(){}>]}[[[()[]][()<>]]<<[]{}><<>()>>]]<[<{{}<>}{()<>}>{{[]()}})(<<<><>>>{ | ||||
| [{({{<(((({(<{(){}}>((())(()<>)))((<{}{}>((){}))<[[]]((){})>)})(<(([[]{}]<<><>>)<{()[]>(<>())>)>))))>}{{{({ | ||||
| [{(<<{{(<[{({{{}{}}{<><>}})}(<{({}<>)[<>{}]}<[{}{}]{{}{}}>>)]>([[{(<[][])<[]<>>)<(()<>)[[][]]>}[({()<> | ||||
| <[([[((([{<[{(<>{}){<>()}}(({}[]])]([([]())<<>[]>])>[{<[{}<>](<>[])>}<[[(){}][{}()]]{{{}<>}[{}[]]}>]}])))][{( | ||||
| (<[[(({({{[<<[<>[]][<>{}]>[[<>{}]((){})]><<<{}<>>[<>{}]><{[]{}}[()<>]>>]([[[<>{}]{()()}]<<()< | ||||
| [{{{{<<{{{{<({<>()}((){}))(<[][]>{[][]})>{<(()<>)[()<>]><<{}{}>{{}[]}>}}<[[<{}{}>]{[<>()]<<><>>}]{<(()())<{} | ||||
| ([(<<{[{(<{<(<{}{}><{}<>>)[(<>[]){(){}}]>({<[]()>(<>{})}<{[]{}}[(){}]>)}>([[<<[]()>(<>)>(<<>[ | ||||
| <(<<{<{[{[<[{<()<>>([][])}]>]}]}><<<[([{(({}{})(()()))({()()}<<>>)}([(<>{})(<>[])][({}<>)[[]<> | ||||
| <([[((<[<[[((<{}<>><{}()>)<(<>{})<[]<>>>)[<{()}({}())>{[[]{}]{()[]}}]]<<[(()[])(<>())]{<[]<>> | ||||
| <<{{{<<({{<[<[<>()]{{}<>}>{<()<>>{[]{}}}]>}}{({[<[()[]][<>{}]>((()[])<{}()>)]}([{[[]{}]<[]<>>}{([] | ||||
| (({[(<({<{[[{<<><>>({}[])}(<<><>>[[]{}]))(<{<>{}}[[]{}]>[[<>{}]({}{})])][<[<()[]><()<>>]><[({}[])[<>()]]<([]( | ||||
| ([([[([(<{[<([<>{}][(){}]){<<>()><()<>>}>{[{()<>}[[][]]][[{}{}]<(){}>]}]([<[[]()]{{}[]}>[{<>[]}[[]( | ||||
| ({((<[(<(({{([{}[]](<>()))[({}())]}[{[<>{}]<<>()>}{[{}]}]}({{<[][])[{}[]]}}((<<>{}><<>{}>))))<[<{[(){}][{ | ||||
| {([<{{(({[(<<{<>{}}[<><>]>{(<>[])({}())}>{((()[])[{}]){([][])((){})}})][<[<<[]()>{(){}}>]((<{}()>[{}()])<<{ | ||||
| {{<<(<[<(((({{{}<>}{[]<>}}[(<><>){[]()}]))[<{([]<>)<[]()>}([[]{}]<()>)>{{[<>[]]({}<>)}{<<>[]>[<><> | ||||
| [<({{[{{[(<[[<[][]>{<>{}}][{{}[]}[(){}]]]>{{(<{}[]>(<>()))<((){})>}[{([])}]}){[<[{()<>}<[][]>][[ | ||||
| ({<{{{(({({<(<{}[]>[[]<>])>})}<{(([{<>{}}<<>()>](([]<>){()[]}))([({}{}]{{}{}}][{()[]}{()()}] | ||||
| ((((<({[[<(<{(()[])((){})}>(([{}()]<<><>>)[{()[]]{{}}]))[[{(<>()){<><>}}{<<>[]>[[]<>]}][[{ | ||||
| ({<[<((<({<<((<><>)(<>[]))[{[]{}}{[]{}}]>{[[()()]{()()}]{[<>{}]}}><({[[][]][()<>]})>}([[[( | ||||
| ({<(<<<<<(<[<[<>()](()>>][<<<>()>[{}[]]><(<><>)>]><({<<>{}>}[<<><>>{(){}}])[{{<>{}}<[]<>>}]>)(<{{{()()} | ||||
| [<<[{[<{([([{<()()>[{}[]]}<<()[]>{()()}>][<<{}>[[]<>]>{[()[]][[]()]}]){[((()<>)<{}[]>){[[]()][{ | ||||
| [{[<{<{(({{<(({}[]))[[{}[]]{[][]}]>}}<([{(()[])}<[[]()]>]{<<<>()>[<>[]>>[[[]()][[][]]]})>){<<[<<{}()>(() | ||||
| <(({{<{{<[{(<[[]<>]><({}{}){[]{}}>){{[[]{}]({}<>)}<((){})<<><>>>}}{[(([]<>)[{}<>])({<><>})]<(<()<>>{( | ||||
| [[{[(<(<<[(<[[<>[]]((){})]{[<><>]<{}[]>}>)<[{{()[]>(<>{})}(({}[]){{}[]})]<<[{}{}]>{[{}{}]}>>][{([<()<>>({} | ||||
| [({<({[[<[{<<{{}[]}<(){}>><[[]()][{}{}]>><{([])([])}[({}<>){()()}]>}{[{<{}{}>[<>()]}]({({}[ | ||||
| {{<[<[(([<{[{{[]{}}[[]{}]}]}>[[(<{[]()}(()())><{(){}}(<>())>)[<([]()){{}<>}>[<[]<>>{{}[]}]]](((({} | ||||
| {(<<[(({{[[{([[][]]{{}()})([()<>][{}{}])}]([[{[]<>}({}{}]][<{}[]>]](({{}[]}){<{}[]>((){})}))][<(( | ||||
| {{{{({{({[{{([{}[]]<(){}>)<<[]()>([]<>)>>{[{{}()}]<[{}]<()()>>}}[[{<[][]>{[]{}}}({()[]}<[]()>)][<[{ | ||||
| [{{[[({[[[[((<{}[]><{}[]>){[{}{}]{()[]}})({{(){}}([])}<<[]()>[{}{}]>)]}{{{({[]}({}))<((){}){{}<>}>}{{ | ||||
| [<{([{(<{(((([()<>]<()<>>)[[<>()]([]{})])[(({}()))<<<>()><[]>>])[<{{<>{}}[()()]}(<[][]>{()()} | ||||
| ({(({{<[{<{((<{}{}>{{}[]})<{{}()}{{}()}>)[[({}()){[]<>}]{<()>[{}<>]}]}><{[[(<>{})<[][]>]<{{}<>}{{ | ||||
| (({{(({(<[[{[<<>{}>{[]()}][{[]{}]{(){}}]}(((()[]){{}{}})<(()())>)]([<[{}[]]>])][<{{[{}[]]<<><>>}{[[ | ||||
| ((<[[<<<[([<[<<><>>([][])](<[][]>{<><>})>((({}<>)((){})))>[[<[<><>]<{}<>>><({}[])([]{})>]])[{[{({}<>)[()[] | ||||
| [<((({{({(({<(()())<{}[]>>(<[]{}>({}{}))}))[<<[({}[])[{}[]]]<{{}{}}{[]}>>>]}[(<({<{}()>[<>()]}[<[]()>((){ | ||||
| [[([(((<{[[[<[{}()}({}<>)>]]{<{{<><>}({}())}{{<><>}([]{})}>}]}[([{[{[][]}(()<>)]{{<>{}}[<>( | ||||
| <<([<{{<{<<(<([]<>)><(<><>){{}{}}>)<(<()<>>([]<>)){(<>{}><<>>}>>{(((()[]){{}[]})[[[][]][{}[]]])({([ | ||||
| [<[{<[<<(([{({[]{}}([][]))<[()<>]{{}<>}>}]<<[<{}>[<>{}]][([]<>)(<>[])]>[{((){})(()())}<[{}()]{<>()}>]>){([ | ||||
| [[[{[(({<<{{{((){})({})}{[<>()]([]<>)}}{[<<>{}>[{}[]]][[{}<>][()<>]]}}>{<{{([]{}){{}[]}}<{<>{ | ||||
| {{{<{[[<[{[<[<<>()>{{}()}][[<>{}][[]<>]]>]<{<{(){}}({}{})><(<>())[{}()]>)<{[()()]}[<()<>>(<>)]>>} | ||||
| (([[<{(([<[((<(){}>[{}()]){([]{})[<>{}]})[[[<><>](<>[])]((()()))]][{{<()[]><<>{}>}}]>])<({[[({()<>}[<>{}])]] | ||||
| {{({[({[[<(((({}[])(()()))))(<<<{}()>[{}]>>(<[<>[]]{[]()}>{({}<>)([][])}))>]{({{<(<><>)>[{ | ||||
| <<((({[([[{<<{<>{}}[[][]]><{()()}<{}<>>>>}[[[<<>()>([]())]({<><>}{{}[]})]<{<{}<>>[[]()]}{{(){} | ||||
| <[{(([<(<{{[[{{}()}([]<>)](<{}()>{[]{}})]}<[[<()[]>(()())]{([]{})[<>{}]}]<<{[][]}><<<>()>>>> | ||||
| <([(([{([([(<[{}[]][[]()]>(<{}[]>[<><>]))<<{{}()}<<>[]>>>])[[<[{<>()}[()()]]<[{}()]((){})>>]{[{(()[])<( | ||||
| ((<([<[[{[{{[(<><>)<[]()>][(<><>)[<>{}]]}}<(([{}()]{<><>})<([])[()()]>)>]{(({[()[])[[]()]}[(<>)])[<{{} | ||||
| {<{<<{{[{<(([{(){}}<<>[]>]<{{}{}}{()[]}>)[<[[]{}><<><>>><[<>()]>])>{(<({{}{}}{<>{}})[<<>[]>]>)((<{ | ||||
| [<<<(({{{[(<{([][])[{}<>]}<(()[])(()())>>[{{<>{}}({})}[<<>>[<>]]]){([{()()}[()[]]]{[()[]]<<>> | ||||
| <{{{<(<<{([[(<{}()>(<>{}))]](({[[][]]}({[]<>}{[]<>}))<([{}{}][[]])[<[]()><{}<>>]>))[<<<<()><[][]>>{(()())<[] | ||||
| {{[[{[[{{{[{([<>[]][<>[]>)[({}[]){{}{}}]}[(((){})[()])(({}[])[<>])]]}<[<{<[]{}>({}<>)}{[{}[]]((){} | ||||
| {([<([([{(((([()[]][[]<>])[<[]()><()>])({({}{})<[][]>}[([]<>){[]<>}])))<<{[[{}{}]][{(){}}{[]()} | ||||
| <<[(([{<((<[({<>{}})[(()){[][]}]]>))>}]<({((([{([][])({}<>)}<<()()>([]())>])){{{{[{}{}]<<>[]>}{(()[]) | ||||
| [[{<([[{<{((({<>{}}[{}{}])([[]()]{{}[]}))({<[][]><<>{}>})){<(<<><>>({}<>))<([]){<>{}}>>(<<< | ||||
| ([({<<{<(<((<(<>{})({})><[[][]](()())>)([[{}{}]([]())][<()[]>[{}[]]])){<[<{}{}]{<>()}][([]{}){<><>}]>}>)>{[[( | ||||
| {<(([<([(([(({[]<>}[{}<>])[(()<>){()[]}])<<{[][]}>({<>[]}{[]<>})>]{{{<(){}><()()>}({[]{}}{{}[]}))([([]()) | ||||
| {[<([[{[({[<{{(){}}}{(()[])<()[]>}>]<<<{()[]}><{{}()}([]{})>>{{<<>()><<>[]>>{{<>[]}{<><>}}}> | ||||
| (<(<{[{[([[[([<><>])][({[]{}}({}[]))]]])[<[{({{}<>}([]()))(<{}><()()>)}(<<{}<>><<>()>)<<{} | ||||
| (<[(({{<[{({{<()[]>}{{<>}<<>[]]}}{[{<><>}[{}<>]]((<>))})([[[<>{}]]<([])>])}{<({<[]<>><<>()>}[({}())[<> | ||||
| {[({([(<{[[[<<<>[]>(()<>)>]<(([]{})[[][]])(<[]()><{}<>>)>](({{<><>}<()<>>}{[{}{}]([]<>)})[<{<>}[[]{}] | ||||
							
								
								
									
										10
									
								
								d10/sample
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								d10/sample
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| [({(<(())[]>[[{[]{<()<>> | ||||
| [(()[<>])]({[<{<<[]>>( | ||||
| {([(<{}[<>[]}>{[]{[(<()> | ||||
| (((({<>}<{<{<>}{[]{[]{} | ||||
| [[<[([]))<([[{}[[()]]] | ||||
| [{[{({}]{}}([{[{{{}}([] | ||||
| {<[[]]>}<{[{[{[]{()[[[] | ||||
| [<(<(<(<{}))><([]([]() | ||||
| <{([([[(<>()){}]>(<<{{ | ||||
| <{([{{}}[<[[[<>{}]]]>[]] | ||||
		Reference in New Issue
	
	Block a user