Added 2021 (python)

This commit is contained in:
Karma Riuk
2023-08-02 11:46:44 +02:00
parent 410815acf8
commit 11600f7ba9
82 changed files with 8693 additions and 0 deletions

106
2021/10/input Normal file
View File

@ -0,0 +1,106 @@
{{[([{{[<{{<[[()()]]((<>())[<>[]])>{{{[]<>}[<>]}<[{}{}][[]{}]>}}<<<<<>()>>((<>())<{}()>)><{{[]()}{()
{<<{({{[<<[<(<<>[]><<>>){<{}()>[{}()]}>]{{[{{}{}}([]())][{[]()>[[][]]]}<(<{}()><<>[]>)>}>>{[(
[[<{<{{{([[{[[{}()]<<>{}>]}{{<(){}>{<>}}{{<><>}{<><>}}}][[<<()[]>(<>())>[(())([]())]>]])<{
{<[([[<<<(<<<<(){}>>{([]<>){[]{}}}><<[()()][{}[]]>[(<><>)[<>]]>>){[<[<()<>>[[]()]]<<()[]>(<>{})>>[(([](
{[<(<<{{[[[[(<{}()>[(){}]){[()()]{<>{}}}]]]]{([(<<[]{}><<>[]>><[{}[]]{()[]}>)])([<({<>[]}({}<>))([()]({}[]))>
(<[{<[{([[(<<<{}<>){[]<>}>(([][])([]()))>[({()[]}<{}<>>)<{{}<>}{(){}}>])(([{{}()}<[]()>]<({}<>)(<>
{[<<((<{([({([()]<()()>)({<>{}}<[][]>)}<[{(){}}](<<>>)>){<[(<>{})]({(){}}<<>{}>)><{<{}()><[]()>}>}
[[([{<<(((((({<>[]}<<>()>))((({}{})<[][]>)({<>()})))[{[[()]{<>[]}]}[(<<><>>{[][]})({<>[]}[{}<>])]])[<{<
(<([[{{<((<<[(<>{})]<[<><>](()[])>>>(<<{[][]}([]()))>)))>}}]])[[[({[(((<([{}<>])[([]{})<()()>]>))(<<[(<><>)<[
{(<([<[[[<<{<<{}[]>>}[{(<><>)[{}<>]]{[[][]]<[]<>>}]>[<[<()[]>[{}()]]<([]<>){<>{}}>>[{{()[]}([])}[[[]]]]
({{<{(<(({[{{<<>()><()<>>}}]}){[{{(({}<>>)}}<{<<{}[]>>}>]})((<((((<><>)[(){}]){<(){}><{}()>}){({(
[(<{((<[{({<[<{}><[][]>]<{[]<>][[]()]>>[[[[]{}]](<{}<>><{}>)]}({{{[]()}[[][]]}[<{}[]>[{}[]]]}{(({}
(((<<[{{{{{{<[<>][<>[]]>)}}}<<[[[[[]{}]<[]{}>](<[]{}>)][(<<>{}>({}()))]]([[{{}{}}[{}<>]]{{[]
([<[<({(({<{[{()[]}][({}[]){<>{}}]}>{{{[[]{}][<>()]}}<(({}){()()})<[()<>][()]>>}}<([({<><>}({}))({()()}[
<[{<[{{<{(<{<(()[]){{}{}}><{[]{}}{{}()}>}<{[[][]][<><>]}<<()}({}())>>><([[[][]](()<>)])>)(<([<[]<>><<>[]>]{
<((({{<<([[<{({}<>)({}<>)}{[<><>][(){}]}>({[[]][()<>]}<([]<>){<><>}>)]][{{{{<>[]}[{}()]}[(()())<[][]>]}{
<([<[[(<(((({[{}[]][[]<>]}<([][])<[]{}>>){[(()())({}{})](<<>{}>)})))))[{[({[[{{}{}}({}())]][
([[(([{([[<<{[[]()]{[]{}}}{{<>()}}><[<()()>([]<>)]{<(){}>((){})}>>({(<()<>>{()[]})}[(<[][]><[]<>>)]>]{
(({{[([{({{([<()<>>{{}[]}]{({}<>)(()[])})}((<[[]]<{}[]>>{(()<>)[{}<>]})[(<()()>){{()[]}({}()]}])}{(([
[[[(<[<{{([[[({}[])]({(){}}{<>})]<[<{}>]>](([[<>()]{{}{}}]{<<>()>[<>[]]})((({}())<{}()>)<<[]{}>>))]}(<<(
{{([<[<<({({[[{}[]]<[]()>]<{<>{}}[[]<>]>}(([{}{}]{{}<>})[<[][]><[]{}>]))[[[{()[]}{<><>}]]]}<
{([<[<[{[(<{([()()]<[]<>>}<[()()]<()()>>}<{[[]()]<(){}>}([<>[]]{<>()})>>[[((<>[])(<><>))[{{}()}[<>[]]]]<
<{<{((({[[[<{<[]{}><()[]>}>([<<>[]><<>()>]<[<>()][[]<>]>)]]]}(<({<<[(){}]><{[]<>}[{}[]]>><{{[]{}}((){})
[{{{([{[([<[({[]{}})<({}<>){<>{})>][{{<>}<<>()>}<[<>{}]{()[]}>]>{{[[{}<>][<><>]]{<{}()><[][]>}
<<{<<([[([[(<(()<>){[]()}><{<>[]}<<>[]>>)]{<(<[]{}>((){}))([[][]]({}[]))>{[({}[])(<>)]({()()}<<>[]>)}}]
[[([{(([(<[({({}[])<{}[]>})(<(()())(()())>[{<>{}}({}[])])]>[(<<(<>{})>[<{}{}>[<><>]]><<[()()]
[[{{<<((<[{{<(<>[])(())>}}<{{<()<>>}}>]{{<{<[]>(()[])}(<()()><(){}>)>}(<{<{}[]>(<>())}[<()()>{<>()
<<({<<([({((({{}{}}<[]()>)([{}{}])))[<[<<>{}><{}[]>}{((){}){{}{}}}>(<((){})<{}[]>>([<><>](<>[])))]})[
{({<(([[<{{<[<()>][[[]{}]{<>{}}]>[[[()[]]({}<>)][{[][]}{[][]}]]}<<{[()[]][()()]}[({}{})(<>{})]>)}>{[[[{
(({[[<(<[((<(({}[])([]()))<(<>[])[()<>]>>))<[[[{{}[]}<()[]>}]<{{<>[]}{(){}}}>]>]{[{<<<{}<>
<{{<<[(([[([<{[][]}<<>()>><<<>>>])<{((<>{})[[][]])({{}<>}<[]{}>)}(<<{}{}><{}{}>><(<>[])({}<>)>)>]]{<<
{([[<<[({[<(<(()())><{[]()}<()[]>>)<<([][])(()[])>[<[]<>><<>()>]>><{([<>[]]{{}})<{{}[]}{<><>}>}[{{[]}{[]{}
<{[<<(<[[<{(<{{}[]}<[][]>>{[(){}]})([({}{})<{}()>]<<()><{}>>)}>({<{([][])}<{[]{}}<<>{}>>>{(<[]
{{<[[<([[[{[[{<>[]}<(){}>]([<>[]]({}<>])]{<[{}()]{{}[]}>[<{}()>(()[])]}}<{[((){})]}([({}<>){<><>
([<([{<(<[{[{{{}<>}[()<>]}<<()>{[]<>}>]}[[[<<><>><[]<>>]{<{}[]>{<>{}}}]]](<([<<><>><()()>][({}
{{{[{[{([([<[[{}<>]{{}[]}]{<<><>>{{}<>}}>][<<[[]{}][()()]>{{[]}{{}{}}}>{[<[][]>[{}<>]]{(()<>){[]
[<{{<[[[[<{<({(){}}[<><>]>({{}}<<><>>)><({{}<>}[[][]])(([][])(<>{}))>}>]<[(<{[{}()]{()()}}<((){})>
{<<{{<{<({[{{({}())<{}{}>}[[{}[]](<>[])]}<({[][]}<{}<>>)<<<>[]>[{}[]]>>]{{<{[]<>}<[]<>>>{<<>[]>}}}}<
{[(<({([([{[{[<>[]][()()]}<{{}[]}[{}{}]>]}([{{{}<>}([]())}<[<>()](()[])>]{[(()<>)(<><>)]})]<[([{[]
({((<<({{([[<{(){}}<()[]>>(<[]{}>{<>[]})]<{{{}()}(<>[])}[<()[]><{}()>]>]<<[[{}[]]{{}[]}]({()()}[{
{<{<(((<({[<{{(){}}[<><>]}<<{}{}><{}{}>>>]({<[[]{}](<>)>{[[][]]{(){}}}}[{(())<{}[]>}{<<>[]]{()
<<{<({((<[((<<()<>>[<>[]]>{{{}<>}({}<>)})([(()()){[]()}]))[[[<[]<>><<>>]{<<>()><()[]>}]]]>)[(<{(<{{}{}
[({<{{<<{<<{<[<>[]]<()<>>>[({}())([][])]}>>}>>}((([{{<([()[]]{{}()})<<(){}>(<><>)>><(<()()>(<>{}
{[{<<[(<<[(<<{<>[]}{[]{}}>[[[]{}](()())]>)(([(<>[])(<><>)](<[]<>>(()())))[(({}{})([]{}))])](<<({{}()}
<<((({((({<{{{{}{}}[[]()]}([()<>]{<>()})}>}){<{{<(<>())><<()()>[()()]>}}>{[{([()<>]<[]<>>)[<{}(
(([[[{{[{{<<(<{}>{{}()}){{[]()}{<><>}}><[({}[])<<>{}>](<<>{}>[{}[]])>>([<<[]{}>[()<>]>[([]()){(
<({<{<[({{(([{{}()}[[][]]]<{()<>}{<>()}>))<[[({}())({})][{<><>}<[]()>]]{[[<>]{[]{}}]}>}[({{<{}<>>}}
[({{[<[[[[({<{<>[]}{{}{}}>{{{}{}){()[]}}}(<<()<>>{[]{}}>))]({[{<[]()>(<>[])}[(<><>)]]})]]]{<[<(
<<<[({{{[{[(<{()}(()[])><([][])([][])>)({{{}}{<>{}}})]{<[([]<>)[{}()]]((<>())(<><>))>>}{<{{
({([<(([({<<<<[]()>(<>{})><<[]>{<><>}>>{<{<>}{{}()}>({<><>}{[]{}})}>}[<<{(()<>)[{}<>]}([()()]<()()>)>[
[<({{<{<[{{{(((){}))({{}()})}}({[[{}<>]<<>{}>](((){})[[]<>])})}(<<<<()()><[]<>>><<[]{}><()<>>>><<<()<>><<>()
{{(([<<{{({[<{[]}[<>[]]>(<<><>>[[]{}])]{{(<>())({}())}[<[]()>[()[]]]}}[(<[{}()](<>{})><<{}
{<({{([({<<[[[[]{}]{<>()}]{<(){}>{()()}}]>(<{{(){}}({}{})}<<{}()>>>{[<<>()>>{[<>{}]{<>{}}}})>}
{{([<<{<[<([{[{}[]]}(<<>{}>(<>{}))]<<{()()}[<>[]]>{<[]()>([]{})}>)({(<[]><[]>)[<[]<>><{}()>]}(
<((<(({({[(<{[<>[]][{}{}]}{{(){}}}>{{<<>[]>{[]}})){<{<<><>>}<<[]{}>{[][]}>>((<()<>>{()()})([[]()]([]{})))}][[
[<[(<(<{(<<{[[{}<>]]}[{{<>{}}{<><>}}[<[][]>{(){}}]]><{<({}<>){{}[]}>(({}[])({}[])>}[{{{}{}}
<((({{[([<<(<(<>())({}())>({()<>}))({<[][]>([]{})}({(){}}[{}{})))>>])]{<[{[<({(){}}{<>})>{{[{}()](
(<<([<<(<[({(<{}()>[<>[]])[({}{}){<>[]}]}(({()[]}<()()>)([[]()]<(){}>)))(<{{<>{}}[{}[]]}([<>{}][(
<({<(([[((([<<()[]>[<>{}]>](<[(){}]<[]{}>)<[[]][[]<>]>))(([<<><>>{[]{}}]))))[({({<[]()><{}()>}<[
{[{{([(({[{[<[[][]]((){})>[[<><>]([][])]]{([[]{}][<>()]){(()[])[[]<>]}}}[<({{}[]}{<>()})[([]())<{}()>
(<(<[<(<({[[((()()){<><>))[(<>())(()())]][[<<>{}>([]())][{<>()}[<>]]]]}[([{[[]<>]}{<[]{}>}]){<<([]{}){{}[]}>>
[([{(<{[({(([<[][]>[{}<>]]<(<><>)>){({()[]}{()[]})({()}(<>[]))})<[[([]())[(){}]]{[()<>]<[]<>>}]((<<>(
<(<{([{<[{<<[[<>[]]]><<[<>{}][{}{}]>>>([({[]()}<<>()>)[<[]()>]]{<{()<>}>[{[]()}{<>[]}]})}({{[(()[])<[]()
({{<{{[<({{([<()[]><{}<>>]<{[][]}[<><>)>)[<(<>{}){{}()}>(<<>{}>[{}[]])]}<{((()<>)[()()])<((){}){{}{}}>
<{[[{{{[(([<({<><>}{<>()})>({<[]{}>[<><>]})]){<[[[{}[]]{()()}]{[<><>)[{}{}]}]><((([][])){[[]
{[{[[[{[<<{{[[[][]]{{}()}][<<>()>{(){}}}}{{<<>{}>[{}[]]}}}[({<<>[]>{[]{}}}<({}<>)[[]()]>)]>({(<<[]<>>
<[[{(<({<({<([()<>])<{<>[]}{{}()}>>})<([<(<>[])<()()>>(<(){}>[{}[]])>([[{}[]]({})]{{<><>}<<>[]>}))[[{[{}
<{{[[{<(<[((((()<>)<{}[]>)<((){})[(){}]>))][[<[({}<>){()}]<[<>{}]{[][]}>>({[()()][()()]})]]>)>}]<<<(
[<[<{(<{<[(([<[][]>])[((<>()>([][]))[{()}{{}<>}]])({[[{}<>](()())](({}())<()[]>)}<{(<>())[(){}]
[<<[[(([[[({[{()[]}(<>{})]{[{}]<<>()>}}{[{[]<>}{()()}]<([][])>})][{((<<>()>(<>[])){{<><>}<()[]>})<[[{}(
<{<([[[([[{[{{[]<>}<{}<>>}](<{()[]}(<>)>{<{}{}>([]{})})}]<<{{{<>{}}{<>()}}<<<>()>[()[]]>}[{[[]
{[[[([{<([(([[()[]]([][])][[<>()](()<>)]]<<{(){}}[(){}]>[{[]()}(<>)]>)<[[[{}()][()]]<({}{}){<>()}>]([[()()]{
(({<(({[(<(({({}[])({}[]]}([[]()]([]())))[<<()<>>{{}()}>[[()()]]])>)<([[[[{}[]]{<>()}]]({([]())(<>())
<[<{({{<{({<{[{}()]{[]}}<[()<>]<(){}>>>[[<[]{}>{{}<>}]<[[]]<<>[]>>]}<{<[<>()][{}{}]>{[()()][<>]}}>)}{{{[[[[]<
(({{([([{{{[{{{}[]}{<><>}}<{{}}(<>())>][(([]{}){<><>})<<[]<>>[<>()]>]}}{{[([<>{}]<()()>)({(){}})]({(<
<<<<(([(([{[<[(){}]([]<>)>]((([][])({}{}))(([]{})<[]>))}])(({{[{{}()}<[]<>>](({}<>)[<>()])}({{[
{{[<[<[([{(({([]())(<>())}[[[]<>]([]{})])[{<[][]>({}{})}{({}[]){()<>}}])}][{{(<(<><>)([]<>)>([<>()](()())))
[[[(<[<([[{[<<(){}>((){})>{<{}<>>({}())}][<<()>([]<>)>([<>[]]<[]>)]}{{<[<>()]<{}<>>><<()<>>{{}<>}>}<<[[]
[<<(<<({<{{(((()())))<[{()()}(()[])][[()()]]>}[{{(()<>)[[]()]}<<<>{}>{<><>}>}[([()[]]<()()>)(
<<{{{<<{{{<[{<[]()>([][])}<{<>{}}{[]{}}>]([{<>()}({}<>)])>}<<[([{}{}][{}])[{{}<>}(()<>)]][<({}())({}()
[<<<{[{(([<<[{<><>}[[]<>]][([][]){[][]}]>[[{()[]}[{}[]]]({()[]}[{}{}]>]>{<[<[]()><<>{}>]<{()[]}([][])>>}]<{
{{([({<[({{{<{[]<>}{<><>}>[<{}{}>{{}()}]}<<<[]()><<>()>}{(()[])[{}{}]}>}}<<([[[]()]{[]<>}]<(()[])([]{})>)[<((
[{<{{<[[<[{<(([]{})<()<>>)(<[][]><[]()])>[{({}<>){{}()}}({()[]}[(){}])]}]>]]{[<({<{<<><>>}<{(
[[<[(<{[<({[(<{}{}>(()()))]<[<[]<>>[{}()]]<({}())([]())>>})>[([[(({}{}){[][]}){{{}<>}({}{})}]]({<[{}[]][()
([(<[<<(<{((<{()[]}([]{})>(<(){}>)){(({}<>){()[]})<[<>[]]<(){}>>}}}>[{{{[[{}[]]]}((<<>()><{}{}>
({{{[(<({[<{<({}<>){()[]}>[<()<>>(<>{})]}<[<{}()>([]<>)]((<>{})[{}[]])>>({[{{}<>}(<><>)}}{({{}()}<<><>>){[
([[<<{<<[<{(<({}<>)<[]<>>>)[[[{}[]][{}<>]]([()[]](<>()>)]}>][{{[[<<><>>][[{}()]<{}[]>]]{<{()[]}{{
{(<<[(<<({[{<[[]()){(){}}>{[[]{}]<{}{}>}}<{<()>[()()]}[<()()><<><>>]>]<<[<[][]><<>{}>]{{[]
[<({[({{{<[<({[]{}}[[][]])>]>[{{{{<>{}}({}()}}(<[][]>{[]()})}([<<><>><{}{}>])}{[<<{}{}>(()[])><{<
{([[<[({{<(({(()<>){<>{}}}{[<>[]](<>[])}))<[<[<><>]>[([][]){{}()}]]{<(<>())>}>>}[({[{<<>{}>({}[])}<{[]{}
(<<[[[[[<<(({([]()){<>()}}{[{}<>]<<>()>})[{(<>{}){[]()}}]]<<[<[]()>[[][]]]>[<[[]<>]([]{})>{
{[[([({<[{<(({{}()}([]())){{[]()}[(){}]}){[<[]<>>[[]<>]]<(()){<>{}}>}>({((()())({}<>))([()()](
[({<{<{[[{{<<{[]}>{<{}[]>[{}()]}>([<[]()>(())])}}<(((({}())(<><>))))(<[{(){}}([]())][[{}[]][()[]]]>[{{{}()}
[[((([[{<(<<<{{}{}}{()()}>{[[]()]{(){}}}><<(<>())>([<>{}]{<>{}})>>)>[{({{([]{}){<>[]}}{(()
{([{([<({[[[([{}{}]<<>()>)((()())<[]<>>)][<[(){}]<[]()>>[<<><>>]]]<<<({}<>)[()()])<<[]<>><()()
{<(<<{({{([<{[()<>]{()<>}}<[(){}]<{}[]>>>](([<[]>([]())]{([])((){})})((([][])(()<>})[{{}}<(){}>])))}<<((<
([{<{{<{[{<{<{<><>}{{}()}><<[]()>(()[])>}{<(<>())[<>[]]>{{[][]}<()()>}}><<{(()[]){{}()}}>>)(({[[{}
{{(<({<[<([{([()<>]([]()))<<[]{}>[[]{}]]}{<({}<>)(<>[])><<[]{}>[[]()]>}][{{((){})<{}[]>}<(<><>
<({<{[[{[({(<[()[]]{[][]}>{<[]()><()()>>)<{<(){}>((){})}(([]{})({}{}))>}[<({[]<>}([]<>))<({}){<>[]}
([[{(((({{{[<<{}{}>{()()}>({[]<>}[[]()])][{[{}<>]<()()>}([<><>]))}}{({(<[][]>[<><>])}[{[<>()]<[]{}
([{{<[(<([{{(([]())({}[]))}{{(<>())[<>{}]}<(()[])([]())>}}{<{<()>{{}{}}}>(<[{}]<{}{}>><{{}{}}([]{})>)}]){<
{((<{[<<(<([(<{}<>>)]<(<[]{}>{[][]}}[[()()][[]<>]]>){{{[[]{}][<>()]}<((){})(<>())>}{(([]{})<[][]>)[([]())
{({[<{<{[{[<{([]<>)({}<>)}<({}())({}[])>>{{{<>{}}([][])}[<[][]>]}]}((([<<>{}>{<>[]}][<{}{}><()()>])[
{({{(({(<<<[(<<><>><<>[]>)((())<{}<>>)]>{<[<()<>><[]>]{{<><>}[{}[]]}>}>><{[{([{}{}]{<><>})[{
(<{[[({(<{[[(<[]()><<><>})<([]()){[][]}>]{((<>{})[()<>])}]}{[{{<[]<>>{[][]}}[<[]<>><<><>>]}]{{{{
<<(({[[{[<((<[{}{}]{[]()}>{{()[]}<<><>>})([[(){}](<>[])]<<{}[]>[(){}]>))<<{{{}[]}({}{})}(<()<>>[

76
2021/10/prog.py Normal file
View File

@ -0,0 +1,76 @@
from collections import deque
VERBOSE = True
def verbose(s = "", *args, **kwargs):
if VERBOSE:
print(s, *args, **kwargs)
def get_input(sample = False, part = 1):
with open(f'sample_p{part}' if sample else 'input', 'r') as f:
return [line.strip() for line in f.readlines()]
def result(inp, part = 1):
res = 0
opening = ["(","[", "{", "<"]
closing = [">", "}" ,"]", ")"]
pairs = {
"(": ")",
"[": "]",
"{": "}",
"<": ">",
}
points_1 = {
")" : 3,
"]" : 57,
"}" : 1197,
">" : 25137
}
points_2 = {
")" : 1,
"]" : 2,
"}" : 3,
">" : 4
}
tmp_res = []
for line in inp:
stack = deque()
ignore = False
for c in line:
if c in opening:
stack.append(c)
elif c in closing:
op = stack.pop()
if pairs[op] != c:
ignore = True
if part == 1 :
res += points_1[c]
break
if part == 2 and (not ignore) and len(stack) > 0:
tmp = 0
verbose("stack before: ", stack, end="")
while len(stack) > 0:
tmp *= 5
tmp += points_2[pairs[stack.pop()]]
# insert sort
verbose(" = ", tmp)
if len(tmp_res) == 0 or tmp > tmp_res[len(tmp_res) - 1]:
tmp_res.append(tmp)
else:
for i, r in enumerate(tmp_res):
if tmp < r:
tmp_res = tmp_res[:i] + [tmp] + tmp_res[i:]
break
verbose(tmp_res)
if part == 1:
return res
else:
return tmp_res[len(tmp_res)//2]
if __name__ == "__main__":
VERBOSE = False
print(result(get_input(), part = 2))

10
2021/10/sample_p1 Normal file
View File

@ -0,0 +1,10 @@
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]

12
2021/10/test.py Normal file
View File

@ -0,0 +1,12 @@
from prog import *
import unittest
class Tests(unittest.TestCase):
def test_part1(self):
self.assertEqual(result(get_input(sample = True)), 26397)
self.assertEqual(result(get_input()), 341823)
def test_part2(self):
self.assertEqual(result(get_input(sample = True), part = 2), 288957)