-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from yitsushi/day10
Day 10
- Loading branch information
Showing
14 changed files
with
590 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package day10 | ||
|
||
import "fmt" | ||
|
||
// UnknownCharacterError occurs when an unknown character was found ina | ||
// sequence. | ||
type UnknownCharacterError struct { | ||
Character rune | ||
} | ||
|
||
func (e UnknownCharacterError) Error() string { | ||
return fmt.Sprintf("unknown character: %c", e.Character) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[({(<(())[]>[[{[]{<()<>> | ||
[(()[<>])]({[<{<<[]>>( | ||
{([(<{}[<>[]}>{[]{[(<()> | ||
(((({<>}<{<{<>}{[]{[]{} | ||
[[<[([]))<([[{}[[()]]] | ||
[{[{({}]{}}([{[{{{}}([] | ||
{<[[]]>}<{[{[{[]{()[[[] | ||
[<(<(<(<{}))><([]([]() | ||
<{([([[(<>()){}]>(<<{{ | ||
<{([{{}}[<[[[<>{}]]]>[]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[({(<(())[]a>[[{[]{<()<>> | ||
{([(<{}[<>[]}>{[]{[(<()> | ||
{([(<{}[<>[4]}>{[]{[(<()> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
[<(<<([[[{<[{[[]()](<>())}<{()[]}<[]<>>>](<[()[]][()()]>)>[{{(()())(<>())}({()[]}{{}{}})}[( | ||
{{{(({[<<[{[(<()()>[<>{}])<<()()>[[]]>]{{<(){}>{()[]}}([()<>]<<>{}>)}}([[<[][]>({}{})]<({}[]) | ||
<[[[(<[{{{(<({()<>)([][]))(<{}()>{[][]})>{[[{}()][[][]]]({{}[]}[()()])})}[{<([()()]{()<>}){([] | ||
[{[(<<{({{<<<{<>[]}{{}}>[({}<>){<>}]>[<<{}()>{<>[]}>[(()())({}())]]>}}({[(<({}{})<<>{}>>{<()()><[ | ||
{{[{<<{[<{([({[]{}})])}>]}>><<<[[[<[([<>{}])<{[]{}}(<><>))]>]]({([{(<>())(()[])}<<()<>>>]< | ||
((<<{<[{[((<([()[]])<{<>{}}>>((<{}[]><(){}>)[<()<>>(<>())])}[<{<()[]>{()()}}>])]([{<{<()[]>({}<>)}>}]{ | ||
{<[<<({{<<{(<<()()>((){})>[{<>()}{(){}}]){(<()()>){([]{})[()]}}}[([<<>[]>{{}}])]>>(<{([[[][]]({ | ||
<({{[[[[[<[(<((){})({})>)[<({}<>)(<>)>{{<>}}]]><[<{[[][]]<<>{}>}{(<>()){[]{}}}>{({()}<()[] | ||
<<{<{{[[([<{{[(){}]<()[]>}<{<><>}[[][]]>}>[[[<()[]>]<{<>()}<[]{}>>]}]{<(<<<>{}>(<>[])>[{()( | ||
({{(({<([(<{{[[][]]<{}<>>}{{[]<>}}}>[({{()<>}(<>[])}<<<>[]>>){[([]{})]<{()<>}{(){}}>}])[<[{[{}[]]}[ | ||
<([<{[{(<[[[((()[])[[]()]){[[]()](()<>)}][<(<>[]){()()}>{(<><>)[<>]}]]][((({{}[]}{[]()}))<[[{}<>]<[] | ||
{[[([<[<{({{{[<>{}]{(){}}}{{[]{}}<{}<>>}}<(<()<>>{()[]})<(<>())[[]()]>>}[<[{[]<>}(()()))<<[]{}>{< | ||
{<<<(([(((<[{(()[]){()<>}}]>)([<[<<><>>((){})]>][{[[{}[]][{}<>]]<<()<>>[{}[]]>}[[<<>{}>[{}[]]]<{[]()}>]] | ||
{{[(<<<(({{<<{{}<>}[<>[]]>([[]<>]<{}{}>)>{({{}{}}{[]<>})}}}[[{<{<><>}(<>())>{[()]}}<[(<>{}) | ||
((({([{[[<{{([{}][{}<>]){[[]{}]{{}<>}}}[<{<>{}}><[[]{}]<<>()>>]}([(<()[]>[<>])[[[]()](())] | ||
({{<[{{<(([<{<<>[]><{}{}>}[(<>{})<()[]>]><[[[][]](()())](<[]()>(<>[]))>]{<{<{}[]>[{}[]>}><[[[]{}]<[]{} | ||
{{<[{<[<{[{((<[]<>>{{}[]})[([]<>)(()())])}][({[({}()){{}<>}]}({<[][]><<><>>}<[()<>]<[]<>>>))(<<<<>{}><(){}> | ||
{[<[{<{((<[(<([][])[(){}]>{([]())<[][]>})<{<<><>>{<>}}>]<<[{{}()}{<><>}][[{}()]{[]<>)]>{[{[]<>}<{}{}>]((<> | ||
<(<({(([{<[((<[]{}>[()[]]){((){})[(){}]})[[<[][]>{()<>}]({{}()})]]([(<<>()>{<>})<({}{})({}<>)>]((<< | ||
<<<[<<[(<<{{(<<>()>([]()))[{(){}}{{}[]}]}{<[(){}]>{[<>[]]([]<>)}}}([<<<><>>([]<>)]]{{<()()>{{}[]}}[{< | ||
{[<(<([([[<[{{<>{}}<{}()>}{<[]<>><<>()>}][{((){})[{}<>]}<{<>()}{<>{}}>]>{{<<[][]>[<>[]]><<()<>><[]<>>>} | ||
[{({<[{{([[[{({}<>)[<>[])}[[[][]]({}())]]](<<<(){}>[<>]>({(){}})>[(({}()){{}{}})<<<>{}>{<>[]}>])])} | ||
<[[<<((((<<([<()<>>{[]()}]({{}{}}<[]()>))>>{<<<{<>{}}>{(()[]){[][]}}>(({{}{}})[[<><>]{{}{} | ||
({[({<[{{[(([{<>()}([][])](<<>{}><[]>))[{{[]<>}<<>()>><[<>()]>])]}<<{<([()<>]){{(){}}(()())} | ||
((<{{<(<{<<({(<>{})}<[{}<>]{[]<>}>){{[<>]<<><>>}{[<>()]((){})}}>({({{}()}{()()}){[<>()]<<>{}>}}(<({}<>)([]()) | ||
{{[<{({{[[({<([]<>)(()<>)>([{}<>]{()()})}([{{}{}}<<>[]>]{<()[]>{()()}}))]<<[{[<>()]<{}[]]}[[[]() | ||
[((<<{(<{(([{[<>{}]({}[])}([{}[]][()<>])])[[[(<>())([]<>)]]]){<([{[]{}}[<>()]]<[<>[]][<>{}]>)(<({}{}) | ||
((<([(<<([{(<<<>{}><<><>>>[{[]()}])[{[<>{}][[]{}]}]}([[{<>()}({}[])]<<{}>{(){}}>]{[<[]<>>[(){}]>})][<<((()() | ||
<[<[<{({{{{({[[][]][<>[]]}<[[][]]>)[[<[]>((){})]]}<(<([]()){[][]}>[<<><>><[]<>>]]{(<<><>>)[<()[]> | ||
{<[((<(<[({<({[]()}([]{}])<[<>{}]{{}<>}>>({<()()><<>{}>}{[<><>]<<>[]>})}{[((<>)[[]()])]})[({{[()[]]< | ||
<{({[[{<{[<{([()[]][{}{}])}>({[<()()>(<><>)]<[()<>]([][])>}([<{}<>>(<>[])]({<>[]}(<>()))))]}(([{(([]) | ||
<<(([[[({(<({[{}()]<()()>}<[{}{}]<[]()>>){[(<>{})[<>[]]][(()<>)(<>())]}>(<<[()()]([]{})>[[[]{}]{(){}}] | ||
({<{<<<{<<{(<<[]{}>([]{})><{{}}[()<>]>)}[([([]{})[{}[]]]{{<><>}[()<>]})]>{{<{<<>{}>}(<[]{}>[[]])>[<<()()><() | ||
(<<{[<{<{(<{[[{}[]]<()[]>]([()][{}[]])}(({()[]})({<><>}<{}<>>))>[[[<[][]>{(){}}]][<[(){}][{}] | ||
[[{{({[<<([{{[<><>]{<>{}}}}])><[{[{[[][]]{()<>>}{({}<>){[]}}]({{<>{}}<[]()>})}<{[<()<>>]([()[]][()])}{{<[] | ||
[([({<[[[[<<<[<>][<><>]><{[][]}{<>[]}>><{[[]]<<>{}>}>>[[(({}<>){{}<>})[<()[]>[()[]]]]]>{([{{<>}< | ||
{{[<[[<<{<{({{(){}}{(){}}}({<>()}{{}{}}))((({}())({}<>))([{}()][{}<>]))}>({(({()[]}){(<><>)<{}>}](< | ||
[({[<{{([[{([{()<>}<<>{}>]{<[]{}>})}({{[<>{})<{}()>}[[[][]]<{}[]>]})]]{<{<[<{}()>]>{{{()}(<> | ||
{[(([[(([<[(({()}<()<>>)<(<>[])({}[])>)]>])({[([[({}<>){<>()}](<{}<>>)](<((){})[<>[]])))([<([]())({}<>)>{[{} | ||
{([[({[[(<<(<[<>()]{{}()}>)<<(()[])>>><(((<>{})[[][]])[[[][]]{<>[]}])({<<>{}><{}[]>}<{{}[]}>)>>[{(([{} | ||
[(([<{[<<[<{<[{}{}]{[]()}><(<>())([]{})>}{[{[]()}[{}[]]]((()<>){()()})}>{([{<>[]}([]{})]<{[][]}({}{})>){{[[]{ | ||
[<{<[<[([{{{{<<><>>}((()()){[]()})}{{{{}<>}([]{})}([<><>]{()()])}}{{({<>{}}<{}{}>)[<<><>>({}())]}}}< | ||
[<[[<{[((({(([<>{}]([][])){{[]()}<[][]>})[{[()<>}<()<>>}{<{}[]>}]}(<([<>{}]([]())){({}[])[<>{ | ||
[{{<{<[<{([({([]())([]{})}{<()[]>[()<>]])(([<>{}][()[]])(<{}{}><()<>>))])}>]({(<[<(([]<>)([]<>))<[()<>](() | ||
<({<(([[<<[[{[{}()][()<>]}((<>[])[[]])]]{{<{{}{}}{<><>}><(<>)([]{}))}({(<>{})(<>[])}{<{}<>>{<>()}})}>({{{< | ||
(({<[([(<<(<(<<><>>)({{}()})>{{[<>()]}}){{[[()[]]{<>{}}]({[]{}})}[([()<>]{{}()}){{[]{}}(<>[])}]}>>({(<((( | ||
<[[{([<<[[(<<([][])[<>]>[[<>[]]]>)([<(()())<()[]>><[{}][[]]>])]((<[((){})[[]()]]<({}[]>[{}[]]>> | ||
[(<<<<({<[{<<<(){}>{[]{}}>([{}{}]({}[]))><<<[]{}>(()[])>{[{}()](()<>)}>}][<<[(<>[])<(){}>]({(){}}((){ | ||
<[[[[{(<{([{((<>())[()<>]){<{}[]><{}()>}}][{{{<><>}[<>{}]}({{}{}}[<>{}])}[({(){}}[{}<>]){[{}[]]}] | ||
(<<[<(<(<[[{<[<>()]<<>>>{{()<>}<[]{}>}}[(<[][]>{{}()})({()[]}(()[]))]]({((()())[{}])<<{}()){{ | ||
{{<([{{[(({([([][]){(){}}]){[{[]<>}(()<>)]<[{}]<<>>>}}<({{{}()}[{}()]}{<(){}>{<>[]}})<<[{}()]<<>()>]({ | ||
((<<{<{[[(<[{([]())(<><>)}](<<{}()>(()<>)>[((){})[[]{}]})>([(<[]<>><{}<>>)][<<{}()>>[({}[])([][])]]))<{(( | ||
[[<{{<[{({{[(<<>[]>[<><>])<{[]<>}<(){}>>]<[[{}<>]<{}()>]<<[][]><<>()>>>}<[({[]()})<(<><>)<<>{} | ||
<(({[[[<{<[(<([][])(<>{})>{{{}}[{}()]})]((<{(){}}(<>[])>([{}[]]{<>{}})){{({})}{[{}[]]}})>}{[[(((<><>}(()())) | ||
{[[{[({{[((<(({}{})){<[][]){{}()}}>){[({{}[]}([]{}))]{[<[]{}><[]{}>]}})({[{[[]{}]{()[]}}]<(<<>>)[{{}()}<{}<> | ||
{[[<{({([(<[[{{}[]}[()[]]][[[][]]({}{})]]<[<[]<>>[{}()]]<<<>()>[()()]>>>>{[([[()()]<<>[]>] | ||
<([[[[{([<{{(<[]{}>[[]]){<[]()>{()<>}}}[<<[][]>((){})>{{()<>}[[]{}]}]}>[{{{<()()><(){}>}<{()()}>}{[(() | ||
{(<{<([<[(({{[{}[]]({}[])}{{[]()}{<><>}}})[<<({}())[()[]]>{[[][]]<()[]>}>[<<()<>>([]())><[(){})<()()>>]] | ||
{[[(<([<(((([[{}{}]{[]()}]<(<>{})<[][]>>){{<{}{}><[][]>}[{()<>}[()[]]]})<(((<>{}){[]{}})[{[]()} | ||
{{<<<{[({{{{([(){}}[<>{}])[<(){}><{}{}>]}}[<[{<>{}}{{}{}}](<[]{}>[[][]])>]}({<{{{}{}}<{}[]>}([[]][{}<>] | ||
({{{(<[{{<[[(({}{})<[]<>>)([{}[]]{()[]})]((<()()>)[<[]{}>{<>[]}])])<[{(<{}>[[][]])<([]())[[]()]>}< | ||
(((<{{{(((([({()<>})<<[]<>>[<>]>])[((<<>[]>({}))[[[]()]<<><>>])(<{[][]}[{}()]><{{}[]}[()()]>) | ||
{[<[[<{<<({(<(<>()){[]()}><([]{})[<>{}]>)[[<{}[]><[]{}>][[{}[]]<[]<>>]]})>[<{<([()<>]{{}[]})<{{}[]}<{}<>>> | ||
((({{[(((([{<(())({}<>)>{[[]{}][[][]]}}{<<{}<>>{{}[]}>{(<><>)({}<>)}}][{{[(){}](<>{})}{<() | ||
{{<{({({[[<{{(()[])<()[]>}}[[{{}<>}(()[])][{{}{}}{{}<>}]]>{((<{}[]>{[]<>})({[]<>}{[][]}))[([[]<>]<()()>)<<< | ||
[[{{{{{[[{[(<[{}()]{[]()}><<()()>[(){}]>)<[[{}<>]{<>[]}]>]([(<{}<>>[[][]]){(<><>)(()[])]]<[[ | ||
{({<[<{[<[[([[<><>][<><>]])[{{{}()}([]<>)}[[[]()][[][]]]]]<[<<()[]]{<>[]}><([])<<>()>>]{(<()<>>< | ||
({<<<{<<{({<{[()[]]{(){}}}{((){}){{}[]}}><<{(){}}><{<>()}<{}{}>}>}<{[[[]]([]{})](<()<>>(()<>))}>)}<<[({[<> | ||
(<<<<{[{<({{{(<><>)<()[]>}{{[]()}{()()}}}<[<[]{}>(<>[])]{[[]<>]<[]<>>}>})[((([<>]{(){}})([(){}]<<> | ||
(([(((((<<{<[<()<>><[]()>]([()[]][<>{}])>{(((){})({}[]))(<[]{}><[]<>>)}}{(<<(){}>[{}]>{{()())<()[ | ||
(({<([({(<{((<()()>{()[]}){<[][]>[[]<>]})[[{[]}{<><>}]<<[]><{}()>>]}(<(<[]{}><{}{}>)[(<><>){{}()}]>)> | ||
{<<{[{[<{{{({({})<<>()>})<{[{}{}]}[[{}()]]>}}([{(({}{}}(<><>))([<>[]](<>()))}[{[{}<>]}(<<>{}>(()<>))]])}< | ||
({[[{{{{[<{[([<>[]]{{}{}}><<<>[]>>]{[{()()}[()()]]}}((<[{}()][<>{}]>{([]()){()[]}})({[()<>](()[] | ||
[[{{(({{({<{<<{}()>>{<<>()><{}()>}}{[{<>[]}<{}>]{<[]<>>[{}[]]}}>{[[[{}<>]({}{})]<[{}{}]<(){}}>][{({} | ||
([[<<(<[<{{[[{(){}}<()[]>]{{()[]}}]({{[]{}}[(){}]](({}{})[[][]]))}{<[{<>[]}{{}<>}]{(<>{}){()()}}>}}<<{<( | ||
{[<[(({[[(([[[{}()](<><>)]{{{}()}({}[])}])[<((()[])<()()>)<{<>{}}>><[{<><>}(()[])]>])](<({ | ||
{[{<<[(<{({<[[()<>]<[]{}>][(<>){{}<>}]>}<(<<<>[]>(()())>[(()<>)[[]<>]])<[<<>{}>[<><>]]{[<>{}]{[]}}>>)[ | ||
[{([{<([[{[([{{}<>}[{}[]]][({}{})({}{})]){({<>[]}(()()))}](<[(()[])([]{})][<()[]>{[]{}}]><{(<>())<( | ||
([{({(((((({<({}<>)<<>[]>>{[<>[]][<><>]}}(<({}())<<>[]>>(([]<>)[<>{}])))[{({{}()}(()[])){<[]()><()( | ||
{[{[{{<{<{<{(<()<>><()[]>)}<<<()[]><{}{}>>((<>[])<{}<>>)>><<(([]())[<>{}])({<>()}<{}>)>{([[]<> | ||
([[(<<({{{{{[{()<>}[{}<>]]{{{}<>}<(){}>}}(([[][]][()()]))}({[{{}()}{()<>}]}<[([]<>)(<>())][(<>[] | ||
{[<<{<<<<{<((<{}[]>[[]{}])([()<>](<>())))<{[()()]<(){}>>{<()[]>[{}{}]}>>}<[(<{{}{}}[{}{}]>)[([[] | ||
<{{[(<(<{([{({{}[]})(<{}[]>{()<>})}]<[<<[]<>>([]<>)>{<[]{}><<>[]>}][[{()<>}[[]()]][{[]<>}(())]]>)([[[<{} | ||
(<(<{<[({[<(<<{}<>>{{}()}>{(<>[])<()>})<{(<>())<{}()>}{[()()]<[]{}>}>><(({(){}}[[]{}]){{{} | ||
[<[[[([{{<{[([<>]<[]()>){<()>[{}<>]}]{({[]()}[{}{}])[({}[])({}())]}}>}(<(<[[()[]]<(){}>]<<[][]>{()()}>>)(( | ||
[<<{<<([<{<(<(<>{}){()<>}>(({}{})({}{})))<<(<>[]){[][]]>{[{}{}]{()()}}>><[[[<><>]{[]{}}](<{}< | ||
<{<{(<<((<{{[<<>()>[()<>]]{{<>()}(<>{}))}}>({[{{[]{}}[[][]]}({(){}}[[]()])][[<<>[]>[{}<>]]{(<>[])[(){ | ||
((({([<{[[<(({{}{}}[{}()])(([]()){{}{}})){<<[]<>>{{}()}>{{{}[]}{[]()}}}>[((<()[]>(()()))((()<>)([]{})))(( | ||
<(<<([{[(<<<{[{}<>]{()()}}(<<>>)>([([]()){[]<>}][[()<>][<>()]])>{[<((){})[{}[]]>{((){})({}())}][([<>[]]{[] | ||
{[({{[<{<[<(<([]<>)(<>())>[<(){}>({}[])])>]>([<{[{[]}{{}<>}][({}<>)[[]<>]]}[{(<>[])(<><>)}({()<>>{[][] | ||
<((((<<<{<[(<[{}{}]{{}}>){({<>()}{{}{}})[[{}<>]([]())]}]([<(()[])<{}()>>][(<[]{}>(<>{}))<(()()){[]( | ||
<[<<(({([[[<<<[]()>[()<>]>([<>()][()()])>[{(<>[])[<>]}{<{}()><[]{}}}]]]]([<{[<{}{}>{[]{}}]<<<><>>[()()]>}> | ||
<[<{<{<({{{<<<[]<>>>((<>[])[{}()])][{<<>()><()()>}(<[][]>)]}<(<((){}){{}{}}>)>}})><{[{[{([{}{}]<[]( | ||
({<{<{{([[{[((<>[]))]}<<<({}{})>(<[]{}>({}[]))>{[(<>())([]<>)]{{<>{}}{()<>}}}>]([<({<><>}{{}<>})[[[]<>]( | ||
([[[([{[(<({([()[]])[{[][]}<{}<>>]}<(({}{}){()[]}){{<>[]}{(){}}}>)[<({<><>}{[]})(<(){}>(<><>))>{<[ | ||
[{{<<{<{(<<({[()()]<()[]>})[{(<>[]){()[]}}{((){})(<>[])}]>}){<[[[[<><>]<[][]>]]<([[][]](<>[]))((<>{}) | ||
<[((<{<(<[<[[<{}()>[[]<>]]([<>[]]<()>)]<<[<>[]]{()()}>]>([({()}((){}))]<{({}())[[]()]}(({}<>)<[]{}>)> | ||
[{{<(<{({(<<(<()[]><{}<>>)<<<>>>><<(<>[])[{}[]]>>>({[{[]<>}]<<<>[]><{}()>>}<({{}}<()<>>)<[<>()][<><>]>>))}) | ||
([({({{{{<(<{{<>()}({}<>)}({{}<>}<[]<>>)>)>}[{(<{[[]<>][[]{}]}[[()<>]{<>}])){(<(<>[]){<>[]}><<()>[< | ||
{({[{{(([[<({[{}{}]})><{<<<>[]><{}[]>><{()<>}<()()>>}(<[<>()]{()()}><[{}[]]>)>]]<[[((({}())<[]()>)<<()[]>{ | ||
[(<([{{([[<({{[]()}<(){}>}{({}<>)({}[])})>[(<{[][]}>({<>()}<[]<>>))]]{<{<<{}{}>[()[]]>[{[]<>}{()[] | ||
([<((<<({([[([()()][()[]])[<<>{}>]]])}]>>)[<<(([[[(<<>()>)[{<><>}([][])]][((<><>)<[]{}>)[[()()]<{}{} | ||
[[<{[[({[{{({[<>()][{}{}]}){[<()[]>][<()[]>[[]()]]}}}[[[([{}{}]{{}<>})[[{}[]]{(){}}]]]]]}{[{[<(< | ||
[[<({[<{{<<[[({}[])][<{}<>>({}{})]]{(<<><>>{<>[]})}><<<{{}{}}{{}()}>{{<>}<<>>}]<<[()()]<[]<>>>([<>()]{[]< | ||
<{{{([{[([{{({<><>}<[]<>>)}[({[]<>}){<{}())[<>[]]}]}{<[{{}{}}[{}{}]]>[[[()()][<>[]]]<{{}<>} | ||
({[{{([<[<<{{<<>()><{}()>}}[[<<><>>(<>{})][{[]{}}]]><{(([]))<([]{})(<>[])>}(({<>{}}{()})(<{}{}]<<>>))>>]>[{ | ||
<(<([{{[[([[{<[]()>[[][]]}{[{}[]]<{}{}>}]<{<<>()><{}{}>}({{}})>]<((<()<>>[{}[]])({{}}<{}()>)){([[]<>]{< | ||
(({{(((<<{<{<{{}[]}<[]()>>[<()<>><{}<>>]}>[[(([][])<[]<>>)][[<()()><[]>]{(<><>)<()()>}]]}[<[<{()<>} | ||
(({{{{(<[<{([{{}()}<<>{}>][<{}[]>])}[{{{[]<>}[[]]}[<(){}>]}(<{[]()}{(){}}>{([]{}){[][]}})]>]>)}[([{[[[<<()<> | ||
(<{<[([{[(((({()}<[]()>)>))<{<[(<>[]){<>()}][(<>())(<><>)]><[<()()>][((){})<<>()>]>}{{[({}{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package day10 | ||
|
||
import ( | ||
"bufio" | ||
"io" | ||
) | ||
|
||
// Solver is the main solver. | ||
type Solver struct { | ||
input []string | ||
} | ||
|
||
// SetInput receives the input and parses its content. | ||
func (d *Solver) SetInput(input io.Reader) error { | ||
scanner := bufio.NewScanner(input) | ||
|
||
for scanner.Scan() { | ||
d.input = append(d.input, scanner.Text()) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package day10_test | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/yitsushi/advent-of-code-2021/days/day10" | ||
test "github.com/yitsushi/go-aoc/testing" | ||
) | ||
|
||
func TestSolver_SetInput(t *testing.T) { | ||
example, err := test.LoadFixture("example") | ||
if !assert.NoError(t, err) { | ||
return | ||
} | ||
|
||
day := day10.Solver{} | ||
err = day.SetInput(ioutil.NopCloser(bytes.NewReader(example))) | ||
|
||
assert.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package day10 | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
"github.com/yitsushi/go-aoc/perf" | ||
) | ||
|
||
const ( | ||
missingScoreMultiplier = 5 | ||
) | ||
|
||
// Part1 for this day. | ||
func (d *Solver) Part1() (string, error) { | ||
defer perf.Duration(perf.Track("Part1")) | ||
|
||
finalScore := 0 | ||
|
||
for _, sequence := range d.input { | ||
valid, item, _ := parse(sequence) | ||
if valid { | ||
continue | ||
} | ||
|
||
finalScore += scoreError(item) | ||
} | ||
|
||
return fmt.Sprintf("%d", finalScore), nil | ||
} | ||
|
||
// Part2 for this day. | ||
func (d *Solver) Part2() (string, error) { | ||
defer perf.Duration(perf.Track("Part2")) | ||
|
||
scoreList := []int{} | ||
|
||
for _, sequence := range d.input { | ||
score := 0 | ||
|
||
valid, _, stack := parse(sequence) | ||
if !valid { | ||
continue | ||
} | ||
|
||
for !stack.IsEmpty() { | ||
item, ok := stack.Pop().(Item) | ||
if !ok { | ||
continue | ||
} | ||
|
||
score = score*missingScoreMultiplier + scoreMissing(item) | ||
} | ||
|
||
scoreList = append(scoreList, score) | ||
} | ||
|
||
sort.Ints(scoreList) | ||
|
||
return fmt.Sprintf("%d", scoreList[len(scoreList)/2]), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package day10 | ||
|
||
import "github.com/yitsushi/go-aoc/generic" | ||
|
||
type ( | ||
blockKind string | ||
blockType string | ||
) | ||
|
||
const ( | ||
squareBracket blockKind = "square" // [] | ||
curlyBracket blockKind = "curly" // {} | ||
angleBracket blockKind = "angle" // <> | ||
parentheses blockKind = "parentheses" // () | ||
unknownBlockType blockKind = "unknown" | ||
|
||
opening blockType = "opening" | ||
closing blockType = "closing" | ||
unknownBlockPosition blockType = "unknown" | ||
) | ||
|
||
// Item is one item XD. | ||
type Item struct { | ||
Kind blockKind | ||
Type blockType | ||
} | ||
|
||
func typeof(character rune) (Item, error) { | ||
switch character { | ||
case '[': | ||
return Item{Kind: squareBracket, Type: opening}, nil | ||
case ']': | ||
return Item{Kind: squareBracket, Type: closing}, nil | ||
case '{': | ||
return Item{Kind: curlyBracket, Type: opening}, nil | ||
case '}': | ||
return Item{Kind: curlyBracket, Type: closing}, nil | ||
case '<': | ||
return Item{Kind: angleBracket, Type: opening}, nil | ||
case '>': | ||
return Item{Kind: angleBracket, Type: closing}, nil | ||
case '(': | ||
return Item{Kind: parentheses, Type: opening}, nil | ||
case ')': | ||
return Item{Kind: parentheses, Type: closing}, nil | ||
default: | ||
return Item{ | ||
Kind: unknownBlockType, | ||
Type: unknownBlockPosition, | ||
}, UnknownCharacterError{Character: character} | ||
} | ||
} | ||
|
||
func parse(sequence string) (bool, Item, generic.Stack) { | ||
stack := generic.NewStack() | ||
|
||
for _, character := range sequence { | ||
item, err := typeof(character) | ||
if err != nil { | ||
return false, item, stack | ||
} | ||
|
||
if item.Type == closing { | ||
last, ok := stack.Pop().(Item) | ||
if !ok { | ||
continue | ||
} | ||
|
||
if last.Kind != item.Kind { | ||
return false, item, stack | ||
} | ||
|
||
continue | ||
} | ||
|
||
stack.Push(item) | ||
} | ||
|
||
return true, Item{Kind: "", Type: ""}, stack | ||
} | ||
|
||
//nolint:gomnd // I see no reasons to put them in a constant. | ||
func scoreError(item Item) int { | ||
switch item.Kind { | ||
case parentheses: | ||
return 3 | ||
case squareBracket: | ||
return 57 | ||
case curlyBracket: | ||
return 1197 | ||
case angleBracket: | ||
return 25137 | ||
case unknownBlockType: | ||
return 0 | ||
default: | ||
return 0 | ||
} | ||
} | ||
|
||
//nolint:gomnd // I see no reasons to put them in a constant. | ||
func scoreMissing(item Item) int { | ||
switch item.Kind { | ||
case parentheses: | ||
return 1 | ||
case squareBracket: | ||
return 2 | ||
case curlyBracket: | ||
return 3 | ||
case angleBracket: | ||
return 4 | ||
case unknownBlockType: | ||
return 0 | ||
default: | ||
return 0 | ||
} | ||
} |
Oops, something went wrong.