Skip to content

Commit

Permalink
day 1 to day 10 of AoC2021
Browse files Browse the repository at this point in the history
  • Loading branch information
squell committed Dec 16, 2021
1 parent 89abc85 commit 27f7092
Show file tree
Hide file tree
Showing 33 changed files with 6,373 additions and 0 deletions.
2,000 changes: 2,000 additions & 0 deletions 1/input.txt

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions 1/solve.a68
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: finished);
INT x := 0, buf, acc := 0;
REF INT last := x;
DO
read((x));
IF x > last THEN acc +:= 1 FI;
REF INT(last := buf) := x
OD;
finished:
print((acc, new line))
END
17 changes: 17 additions & 0 deletions 1/solve2.a68
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: finished);
[3]INT window := (0,0,0);
REF INT a = window[1];
REF INT b = window[2];
REF INT c = window[3];
read(window);
INT acc := 0;
DO
INT d := 0;
read((d));
IF a + b + c < b + c + d THEN acc +:= 1 FI;
window := (b, c, d)
OD;
finished:
print((acc, new line))
END
106 changes: 106 additions & 0 deletions 10/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<<{(({<{[<[{<<<><>>{[]()}>[[{}<>]{[]{}}]}<<<{}<>>[(){})>[[<>{}]]>]>]<{((((<>{})([]{}))[[<>
[({[(<[{<(({({[]<>}){({})<{}[]>}}{[{[]<>}{()[]}]((<>[]))})[({{{}()}([]{})}[[[][]]{{}<>}]){[({}<>)<[][]>]{[[
{<<[<<<<[[<[<<()><[]{}>>([<><>])][<[[]()]({})>{<<><>><<>()>}]>]<<{{<[]<>><<>>>(<{}[]>[[]<>])}{<(()<>)<{}()>
[({{{[((<[[{<(()<>){<>()}>}[[({}{})<(){}>]<([]{})>]]]((<((<>())<[]{}>)<<<>>[[][]]>>{[[<>{}][(
[{<([{[([<[{[<()[]>{[]{}}](<{}<>>(()[]))}({(<>())[()()]}{[{}<>]{<><>}})]({(([]{}){{}<>})})>[{([{[
<({[[[({[[[{({{}[]}<[]{}>){{{}[]}[[]()]}}<(<{}[]>[{}<>])(<()<>>[[]{}])>]{(<{{}<>}[<><>]>((<>())({}[])))<<<()
<((<([{([{<<<[()()]<{}[]>><([]<>)([]<>)>>(({[]()}<{}[]>)(<()[]>(()())))><[<[<>{}](<>[])>(<{}<>>{[]{}})]>}
(<(({{[<<[[((<{}[]>(<>{}))(<<>()>({}<>)))[<([]{})<{}[]>><{[]<>}>]](<<([]<>)[[]]>({()[]}[<>])>{([
<<((<<{[[(<{{[<>[]}([]{})}({[]<>}[()[]])}{[({}{}){[]<>}]<<()<>>{<><>}>}>{({{{}()}<[]<>>}<(<>[]){
({([(([({[((((()<>){[]<>>))[<{[]{}}[[][]]>[(<>{})<{}<>>]])([{[{}<>]}<(()<>){[]{}}>]<[{[]<>}<[]>]<{(
([{{({(([[[<{[()()]{{}()}}{{()<>}<{}()>}><((<><>)<()[]>)<[<><>][[]<>]>>]<{<([][])({}<>)><{<>[]}{<>}>}{(<{}{
{{([{[(<[[<{<{[][]}(())>([(){}]{[]<>})}[([[]{}]{[]{}}){(<>())<[]{}>}]>{{<[()[]]{{}{}}>}[(([]<>)<[]<>})]}]
[({{<([([[{([{<>[]}]<<()[]>>){[<(){}>[[]<>]][{{}<>}<<><>>]}}]<[[<[<>{}](<>{})>{{<>{}}<<>()>}]]
<(<<((<<{[{((({}[])[<>{}])[{()()}{[]<>}])}]}>[{{<[<[()()][[]{}]>[([]())<<>[]>]]{([[][]][{}()])(([]<>)(
<<[({{([([({[{()[]}[<><>]]{[<><>]({}<>)}})([<(<>())><{{}()}>][{<<>><[]()>}<({}{})({}<>)>])]
[[<((<[<{<<<(<{}()>{[][]}){<[]<>>({}{})}><<[(){}]{{}{}}>>>>}([{{{{()()}}}<([<>[]]<<>>]<{(){}}>
{<[[[(<<([{{[[{}[]>]}}])[[{<<<()<>>({}{})>(<{}{}><<>()>)>}]{[([(()[])[[][]]]<<<>{}><[]<>>>)<<{(){}}<
([[<<((<[(([<{()<>}<{}[]>><(()[])>]([<(){}><{}{}>](<<>[]><[][]>)))<{<(()[])>({<>{}})}{((()[]){[]{}
{<[([(<({(<(({{}[]}([]<>})(([]<>)[{}{}]))<(<<>[]><{}<>>)<({}{}){<><>}>>>)(<({((){})[{}{}]}<<<>()>[[]
{<[({(<{[[[[[<()<>>[[][]]]{[{}<>]{[]<>}}][([()[]]<()[]>)[<[][]>]]]](<({(()())[<><>]}<{<>}({}<>)
(<([[[[[(((<[{{}{}}{(){}})>))(({<<(){}>[{}()]>}<[(<>{})]([{}{}]<[]>)>)([{[{}()]<{}<>>}][<{<>{}}(<>{
{((<[(([{{[<<<[]{}>{()<>}>>({[{}<>]<{}<>>}(<<>[]><[]<>>))][[[[[][]]{{}()}][<[][]>]]]}<(<<{
<{[<{<<{<(((((<>[]][[][]]){[<><>]})(<([][])>)))([([{<>}(()[])]{(()<>)(()<>)}){{[{}{}]}}])>}>{[<<
<{((<<<[({[{[(()<>)((){})]}[{[<>{}]{{}{}}}(<{}()>(()<>))]]}(<{[[<>[]]](<()()><<>()>)})({<<[][]>[[]
(<[(<{(<[({[(<(){}>([][]))<(()())[<>{}]>]{<{()<>}<(){}>><{{}{}}({})>)}<<{{{}[]}(())}[({}())<
[{{[[{{<<([[([[][]](<><>))<{<>[]}<()[]>>]][<[[<>[]](<><>)]{[[]()]<{}()>}>[<([]{}}<{}()>>{(()()){<>()}}]]
[(<(<{{{[([(<{{}{}}<{}{}>>[[<>[]][(){}]])<(({}())[{}{}]>((()[])([]()))>])[(<{<{}{}>}>{{([][])([][]
[(<<{<(<(<(<<[()()]({}{}}>{([]{})[()<>]}>)>)><{({{(<<>[]>){(()[])({}())}}((<{}[]>{<>[]})([()<>][<
{{<<[(<{<{{([((){})[[]<>]]{([]{})([]()}})<[<{}<>>([]())]{<[]()>{{}[]}}>}{<{<[]{}>{()[]}}(<{}[]>[[]{}])>
<{[[{[({<[(({(<>{})[()[]]}{[()[]]<[]()>}))(([(<>[])<()()>])({<()[]>(()[])}))]<[[{{[]}(<>{})}[[()[]){[]<
(((([<{(({<<[{{}()}][{{}{}}<<><>>]>>((([<><>]<<>{}>)[(()())[<>[]]]))}{[<({()[]}[()[]])<([]())<{
(<<{[({[<((<[([]<>){(){}}]{<()()>[(){}]}>(<[{}[]][()<>]>{([][]){[][]}})){{{<()[]><<>()>}(({}<>)<[]{}>
<{[[[{[<({[{((()<>)(<>[]})<{()[]}{()<>}>}[{<<>()>[{}[]]}<[()()][[][]]>]]}{<[<{<>()}<[]<>>><[()[
([[{<{[{{{{(<<<>()>>[(())<[]>]){[[{})]<({}()){<>[]}>}}((<[<>]<{}()>>{[()()]<()()>}))}{[[{{{}<>
[(<({<{{<[{<[[<>{}]({}())]]}]{({{[<><>](()())}([{}])}[[<<>()>({}<>)]<[<>][[]()]>])[{[[()[]][<>]]}[
{([{<[<[{[(<<{<><>}[<>()]>(((){})(()()))>[<<{}()>[<>{})>]){<<<[]<>>[[]<>]>{{<>{}}{(){}}}>([[()()][{}[]]](<
{{(([<{[{<({<({})[[]<>]>([[]]<{}{}>)}([[()()]<{}{}>])){{{{[]<>}<[]<>>}<(<>())<<>()>>}}>}]}
(<[{{<({{(<([[[]<>]]{{{}()}([]<>)})<(([][]))>>{[{{(){}}<[][]>}[[()]<()()>]](({[]{}}(<>())))})(
({{[{{[{({[(<(<>{})<(){}>><<[]{}>[[][]]>)[((()[])(()<>))]]<([[(){}]{[]<>}]<<()[]>([]<>)>)>}[{[{[()<>]}<<
(<[<<<([{{{[<([][])<(){}>>{<<><>>(<><>)}]{((()<>)<{}{}>)[{<><>}<[]<>>]}}}(([<{{}{}}{<><>}>]{{[{}()
({[[((([[<<([{(){}}(<><>)](<{}{}>{[]{}}))(<<[]()>([])>([[]{}]({}{})))><{{[[][]]{[][]}}({()[]})}{(([]<>
({<<({<[[[[[{<()<>>}({<>()}[<>[]])]]]<{{[[{}()](()())]}({([]())})}>]<({<<{(){}}<{}{})>((()[
((<{[<{<{<[[[<[][]>{{}()}]][({<><>}{()[]})<<[]()>(()<>)>]][[(<{}{}>({}))(({}<>){[]()})][[{()[]}(()[])]{(<>
<<<[(<{<{<(<<[<><>](()[])>([[]<>]<[]{}>)>)((<{<>{}}[{}<>]>[{{}()}(()<>)])[{(<>{}){()()}}])><({{{<
<<<{[([[(({<<{<>{}}>[<<><>>(<><>)]><([[]()][{}<>])<[{}{}]>>})<<<[[{}<>](<>())><(()[]){<>()}>>([(
[{{[(<<({[{{(([]{}))[[{}()]<[]{}>]})(([{[]{}}<{}[]>]<<()[]>>)<({(){}}[[]()])<{<>()}[[]<>]>>)]}
(<[[[<[<{[[[{{()<>}[{}<>]}[(<><>)<<>{}>]]]<<[(()<>)<[]{}>]{{{}<>}(()())}><<{[]<>}[[]{}]><{<>{}}{<>{}}>>>][
(((({<(<[{<{<(<>{})(<><>)>{(<>[])[()[]>}}[[(<>[])({})](<{}[]><{}()>)]>(<<[[]<>]({}())>(({}{})<{}{}>)>
{(([<[[<({<[{({}())<<>()>}{[{}()]<()[]>}]>(([{(){}}{()[]}])(<[[]{}][{}()]>[({}{})<{}{}>])}}(<([{()[]
[{<{{({({{<({<<>[]>[()()]>[{[]{}}([]{})])([(<>())[[][]]]([{}()](()<>)))>(<({<>[]}{<>{}})>([(()[])]))}}
{{({({[{([[{[[()[]][[]{}]][{[]<>}(<>{})]}{{[()()][[]()]}[<<>[]>((){})]}]])}]}<{[[{[((<{}{}>[(){}]
[{[({[[(<<{{[(()<>){{}()}]}<([{}])({{}{}}{<>()})>}<[[[{}[]]<<>{}>][[{}[]]([]())]]>>((<({(){}}<[]>){<{}()>
[([[<<[{[(([[{<>{}}]]}){(([{<>[]}])[([(){}]{<>[]})({{}{}}[(){}])])}]}]({<[{<{[(){}]<()()>}([<
{[[[({[[{<({{({}[]]}<(()<>)>}[([[][]])({{}{}}[[]()])])><([{<<>[]><{}<>>}(({}<>))][({<>}({}<>))])(<{([][])[()[
([{<{{<(<[{<[(()[]){{}()}]{(()())[<><>]}>}(<<<()<>>{<><>}>[(()[]){()<>}]>[{{()()}<[][]>}])]>)(<<[
[<(<({[[[{({([<>[]]<()<>>)[{[]()}]})<[[[[]<>]<{}<>>]([()[]){[]()})]{([{}<>][<>[]])[{()()}([
([<[{[(<[{[(([<>[]]<<>[]>))][({(<>())({}<>)}<<()()>[{}()]>][[([][]){<>()}]({[]{}}<{}[]>)]]}
[(((<[{<{{([[[{}]<()<>>]<{()<>}([][])>]){(<{{}()}{{}{}}>(<<>{}>{{}<>})){{([][]}{{}<>}}[[[][]][[]<>]]}}}
[<[{([(<(<<{<(<>{})<{}<>>>{(<>)({}[])}}><([(<>()}[<>{}]][<{}{}>[<>[]]])[{([][])<[][]>}[({}<>)({}())]
[[<<([[{[{[<((<><>){{}<>})>(<({}<>)[()()]>[{(){}}])][[((<>{})<[]()>)(({}())({}<>))]<{<{}{}
({<(({<[([{(({()<>}[[]<>])<(<><>)>)}[{[<<>()>]<({}<>)[[]{}>>}(<<{}{}>[()()]>)]])(<({({{}<>})([[]<>](<>[]
<{{{({{{{{[([([]{})({}[])]{{[]()}<(){}>})]}[[<<{[]()}<[]<>>><<{}()>((){})>>](<{{{}[]}<<>>}<
((([<{<<(<<({[<><>]{{}{}}}[{()()}{[]}])(({()()}[{}<>])[({}())<()[]>])>([<<[]{}>{{}[]}>{[<>[]](())
((<(<[(<[[[({(<><>)[{}()]}{<(){}><{}()>})<<<[][]>{<>{}}><{{}[]}<()[]>>>]<[[[{}][[]{}]][({}{})((){})]]
[<<{[<<[{{[{<[()<>]>(<{}{}>(<><>))}<<((){})<(){}>>>]}[{(<[{}[]][{}[]]>((()<>)([]()))){{<(){}>
<{[<[{<{<{({<[{}()][[][]]>[{()<>}{[][]}]}<[([]<>)]>>}>[([{{<[]()><()[]>}{[<>{}]{[][]}}}(<[[]<>]
{<[<[(([<<({[({}())([]{})][{{}}{[]{}}]}[[<[][]>[{}[]]][[<>()]]])[[[<(){}>{()<>}]((<>{}){()[]})]]>>]{[{
{{[{<[[{([({[[<>[]]{[]()}][[<>()](()[])]}[[(<><>)[()<>]]<([]<>)<{}>>])]<(<{{[]<>}}>[{[{}{}]<
[{{{(({(<[{(<{<>[]}<[]<>>>)}([<[<>()]<<>[]>>{<()<>>(<>{})}]<<(<><>){(){}}]{[[]<>]{<><>}}>)]>)<{[
[[[(({<{(<<{{<<>><<>{}>}[((){})<{}[]>]}{([[]{}]<<><>>)[(<>{})]}>>[<{<{{}{}}[{}[]]>{<[]>[()
((<(({<[<[[(((<><>){{}{}})[{()[]}[{}<>]])({([][])<{}()>}<{{}()}({}[])>)]][{<({()()}{<><>})>([({}[])<<>
{{<{[([<({<[((()())<[]()>)<({}[])({}{}}>]<{({}{})<<>>}(([]{})[{}{}])>>[<[<()<>>]>((<<>{}>{()
<[{[[[<{[[<{[{<>()}][<(){}>[{}{}]]}((<[]{}>({}[])){(<>{})})>]]}>(((([<({()<>}<()>)[{{}()}<{
[(<{[[(({({<<[(){}]{[][]}><{[]{}}([][])>>({<{}()>{<>{}}}({{}<>}<{}<>>))})<{<<({}[])>{([]())[{}{}]}>[{
[<<{{<<<[(<[(([][])[<>[]])][<[()[]]<[][]>>]>)]{[<[{{[][])({}[])}<<<>()>(<>[])>](((<>{})<<>{}>)((<>[])
<<{<[{((<[([{<{}()><{}{}>}{[{}{}]({}())}]{{{<>[]}<{}[]>}<<<>[]>{[]<>}>})][{[{{()[]}{()()}}({<>{}}<{}
[(<{{[{[<{<[[{()<>}(())][{{}[]}{[]<>}]][((<><>)(<>()))(<(){}>)]>(<({[]<>}(<>()))((()<>)<[]>)>{<[{
<[(((([[{{[[({()()}((){}))]<<([]<>)[<>{}]>([{}{}]<<>{}>)>][{<[{}[]][[][]]>[<{}>[[]{}]]}{([
{{(({[[({[<([{<><>}[[][]]]{[<>{}](<>())})>({(<{}()>(<><>))((()())[{}[]])}<<<()><{}()>>>)]}<<(([[<>{}]{[]<
({([[<[{<{[[{{[]<>}({}{})}{<[]()>{()<>}}]]}([{<[[]()]{[]{}}>{[()<>]<(){}>}}])>}[(<[{<[<><>)><[{}{
[<[(<({<[<{[<[(){}](<>())>]([<[]<>><[][]>]<[[]<>]{{}{}}>)}>(((((()[])<{}{}>))([<(){}>[[][]]]
<({(<{[(<{([([[]()]{<>()})[({}[])(<><>)]]<({[][]}{[]()})({[][]}(<>{}))>)}>([([<(<><>)<[]()>>{[{}<>]{<>
(<<<[((<{[(({({}())<{}()>}{{{}[]}<<>{}>})<((()())[[]()]){[<>{}]}>)[{([{}()]{{}{}})[([]())[(){}]]}]]
[[<<<[(<[{((<[{}<>]{[]{}}><(<><>)([]<>)>)[<({}[])<[]()>>(<<>[]><{}[]>)]}[<<[[]{}][{}[]]>(([][
{<[[((({[[[(<[()[]][[][]]>(<[]()>({}())))]<{{[{}<>]<<>{}>}{(()<>){()}}}{(({}[]){<>[]}){({}{})<()[]>}}>}][[
{<{{{{<([([<{{<>()}<(){}>}[{{}}([]<>)]>[{({}())(()[])}]]<{<(<>())[{}[]]}{((){}){[]{}}}}(((<>)<[]()>)<
{<{{{{{({{({([[]<>])[<()<>>>})<({[[]()][{}[]]}({[]<>}[{}()]))[<<{}()><<><>>>{[()<>]{()}}]>}})}<[({<(<{[]()}{
(<{[[{{<[[<(({[]()}<[]>)<[{}()]([]{})>)(<([][])(()<>)>[[()()][()()]])>][[{{(())([]<>)}<{[]()}(()<>)>>](
[[<[{((<{[[(({[]<>}([]())))]{<{<<><>>[{}<>]){{[]()}<<>()>}><{<()()>{[]()}}<{[][]}[[][]]>>}]{<<([<
[[[<(<([(([{((()[])[[]<>]){{<>}{<><>}}}]))])>)>][(({([<([<(<()[]>{<>()})<{[]()}<(){}>>>[<{[]<>}>{{<>{}}<<>
[<(({{(<(<[<{[<>()]([][])}{{{}[]}{{}{})}>[([()<>]([]()))[{[][]}<<>()>]]](({[()<>]{{}<>}}<({})
(<<<<([{{[{{<{{}()}[<>[]]><{()()}[<><>]>}<[[{}()]{[]<>}]{({}[])({}[])}>}]({<({(){}}{<>()})([{}()][
({([{(<<[(({((<>())([]<>))[[[]()]<<>[])]}))]{<{{{{{}()}{[]<>}}}(<({}{})[{}[]]>)}>}>[{((<{((){})
((<[<{<(<[((((<>[])([]{}))[{{}{}}[<>[]]]}{[[[]<>]([]{})]{(<>[])[()()]}})<{{<{}()>[[]<>]}}>]>([{[[<<>{
<<(<{{<<<({[[([]()){[]}]{<<><>><()()>}][[[(){}]<<><>>]]}[{<[()[]]>{([]<>)}}{({()[]})}])(([{(()[]
<{[(<{[<((<[<([]())<()[]>>[({}<>)[[]{}]]]<(<{}{}>(<>{}))<({}{}){{}()}>>>[({([]())<{}()]})<<[()[]]{
{<[<[{<{[[{<<<()[]>{()}>{<{}<>>{<>}}>}{[[([]())]{([])]][(<()[]>(()())){[{}{}](()[])}]}]]}>(
{(((<[<<{{[[(<<>{}>(()<>))][({[]{}}<{}<>>)<[<>](<>[])>]]<{([[]]{(){}})((<><>)[{}])}[{({}<>}<{}[]>}{(<>())<
[[[[[<({(<{([{[]<>}[{}[]]][{[]{}}<{}{}>])[([{}[]]<[]()>)<<<>{}>>]}>)})<(({({(([]{}))}(<[<>()
[<{<(([(<<{<(([]<>)[<><>]){<()()>[<>{}]}>}({{({}[])([]<>)}})>><([(<[()()][[]()]><[[]<>]{[][]}>)(
[<(<(<{([<(<{<<><>>{<>()}}((<><>)[{}])>)((({()<>}({}())){([]{})([]{})})(<(<>{})([]())>))><<((<(
[<<[[{[{{<([({(){}}({}()))[[[][]]]])([([[]]({}())){({}())({}{})}]<[[<><>]<<>()>]{[<>{}]{()[]}}>)><({[[()()]((
{([{(([(({({{[(){}]([])}({<>()})}{<[(){}]<<>[]>><{[]<>}[[]()]>})}))<{{[[{[()[]]<<><>>}([[]()]([]()))]]{{<[[
{((([<[<[{{(((<>()>))[[<()()>]{([][])[{}()]}]}(([{()[]}<<><>>][<[]()>])(({{}{}}((){}))({<>()
{<(<<(<{([{{[[<>()]{{}<>}]<<<>[]>[[]{}]>}{([[][]][<>{}]){[{}()][(){}]}}}]}<{{{[<<>[]>(<>{})][[<><>]]}{
[<<([{<({([[({{}<>}<<>{}>)((()())<{}()>)]<{(<>{})}([()()]<[][]>)>])}{[[(<<[]{}>(()<>)>{[(){}]([][])})[((
37 changes: 37 additions & 0 deletions 10/solve.a68
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
BEGIN
on logical file end(stand in, (REF FILE f)BOOL: done reading);
INT score := 0;
DO
PROC error = (STRING s)STRING:
BEGIN
IF s[1] = ")" THEN score +:= 3
ELIF s[1] = "]" THEN score +:= 57
ELIF s[1] = "}" THEN score +:= 1197
ELIF s[1] = ">" THEN score +:= 25137
FI;
break
END;

PROC parse = (STRING s)STRING:
IF (UPB s = 0 | TRUE | NOT char in string(s[1], LOC INT, "<({[")) THEN s ELSE
CHAR close char
= IF s[1] = "{" THEN "}"
ELIF s[1] = "<" THEN ">"
ELIF s[1] = "[" THEN "]"
ELIF s[1] = "(" THEN ")"
FI;
STRING rest = parse(s[2:]);
IF UPB rest = 0 THEN ""
ELIF rest[1] = close char THEN parse(rest[2:])
ELSE error(rest)
FI
FI;
STRING s; read((s, new line));
print((s,new line));
parse(s);
break:
SKIP
OD;
done reading:
print((score, new line))
END
56 changes: 56 additions & 0 deletions 10/solve2.a68
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
PROC score = (STRING s)LONG INT:
BEGIN
LONG INT acc := 0;
FOR i TO UPB s DO
INT p;
IF char in string(s[i], p, ")]}>") THEN acc := 5*acc + p FI
OD;
acc
END;

CO more plumbing CO
PROC insert = (REF FLEX[]LONG INT arr, LONG INT value)VOID:
BEGIN
[]LONG INT copy = arr;
arr := LOC [LWB arr:UPB arr+1]LONG INT;
FOR i FROM LWB copy TO UPB copy DO
arr[i] := copy[i]
OD;
arr[UPB arr] := value;
FOR i FROM UPB arr DOWNTO LWB arr+1
WHILE arr[i-1] > arr[i] DO
LONG INT tmp = arr[i-1]; arr[i-1] := arr[i]; arr[i] := tmp
OD
END;

BEGIN
FLEX[0]LONG INT scores;
on logical file end(stand in, (REF FILE f)BOOL: done reading);
DO
STRING complete := "";
PROC parse = (STRING s)STRING:
IF (UPB s = 0 | TRUE | NOT char in string(s[1], LOC INT, "<({[")) THEN s ELSE
CHAR close char
= IF s[1] = "{" THEN "}"
ELIF s[1] = "<" THEN ">"
ELIF s[1] = "[" THEN "]"
ELIF s[1] = "(" THEN ")"
FI;
STRING rest = parse(s[2:]);
IF UPB rest = 0 THEN
complete := complete + close char; ""
ELIF rest[1] = close char THEN parse(rest[2:])
ELSE break
FI
FI;
STRING s; read((s, new line));
parse(s);
LONG INT this score = score(complete);
print((complete, this score, new line));
insert(scores, this score);
break:
SKIP
OD;
done reading:
print((scores[(LWB scores+UPB scores)%2], new line))
END
Loading

0 comments on commit 27f7092

Please sign in to comment.