Initial commit

This commit is contained in:
Philipp Matthias Schaefer 2021-12-22 11:33:30 +01:00
commit cd6cc0be1e
73 changed files with 10338 additions and 0 deletions

2000
1.data Normal file

File diff suppressed because it is too large Load Diff

14
1.jl Normal file
View File

@ -0,0 +1,14 @@
include("utils.jl")
input_lines = non_empty_lines("1.data")
integers = map(s->parse(Int, s), input_lines)
"1"
zipped = zip(view(integers, 1:length(integers)-1), view(integers, 2:length(integers)))
result1 = mapreduce(t->t[1] < t[2], +, zipped)
"2"
zipped2 = zip(view(integers, 1:length(integers)-2), view(integers, 2:length(integers)-1), view(integers, 3:length(integers)))
summed = map(t->t[1]+t[2]+t[3], zipped2)
zipped_again = zip(view(summed, 1:length(summed)-1), view(summed, 2:length(summed)))
result2 = mapreduce(t->t[1] < t[2], +, zipped_again)

94
10.data Normal file
View File

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

62
10.jl Normal file
View File

@ -0,0 +1,62 @@
using Pkg
Pkg.add("Match")
using Match
include("utils.jl")
function corrupt(line)
first, rest... = line
check = [first]
for char in rest
if char in "<{[("
push!(check, char)
else
match, score = @match char begin
'>' => ('<', 25137)
'}' => ('{', 1197)
']' => ('[', 57)
')' => ('(', 3)
end
if last(check) == match
pop!(check)
else
return score
end
end
end
0
end
function solution10_1()
sum(map(corrupt, non_empty_lines("10.data")))
end
function fix(line)
first, rest... = line
check = [first]
for char in rest
if char in "<{[("
push!(check, char)
else
pop!(check)
end
end
value = 0
for char in reverse(check)
value *= 5
value += @match char begin
'<' => 4
'{' => 3
'[' => 2
'(' => 1
end
end
value
end
function solution10_2()
values = sort(map(fix, filter(line->corrupt(line)==0, collect(non_empty_lines("10.data")))))
values[div(length(values), 2)+1]
end
solution10_2()

10
10_ex.data Normal file
View File

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

10
11.data Normal file
View File

@ -0,0 +1,10 @@
7777838353
2217272478
3355318645
2242618113
7182468666
5441641111
4773862364
5717125521
7542127721
4576678341

43
11.jl Normal file
View File

@ -0,0 +1,43 @@
include("utils.jl")
function parse_input(filename)
map(x->parse.(Int, x), split.(non_empty_lines(filename), ""))
end
function flash(octopuses)
sum(map(CartesianIndices((2:11, 2:11))) do coord
if octopuses[coord] > 9
octopuses[coord] = -8
for neighbor in CartesianIndices((coord[1]-1:coord[1]+1, coord[2]-1:coord[2]+1))
octopuses[neighbor] += 1
end
1
else
0
end
end)
end
function solution11_1()
octopuses = transpose(reshape(reduce(vcat, [[fill(-2000000, 12)]; map(x -> [-2000000; x; -2000000], parse_input("11.data")); [fill(-2000000, 12)]]),(12,12)))
sum(map(1:100) do _
map!(x->x+1, octopuses, octopuses)
flashes = sum(collect(Iterators.takewhile(>(0), (flash(octopuses) for _ in 1:100))))
clamp!(octopuses, 0, 9)
flashes
end)
end
function solution11_2()
octopuses = transpose(reshape(reduce(vcat, [[fill(-2000000, 12)]; map(x -> [-2000000; x; -2000000], parse_input("11_ex.data")); [fill(-2000000, 12)]]),(12,12)))
for i in 1:1000
map!(x->x+1, octopuses, octopuses)
flashes = sum(collect(Iterators.takewhile(>(0), (flash(octopuses) for _ in 1:100))))
if flashes == 100
return i
end
clamp!(octopuses, 0, 9)
end
end
solution11_2()

10
11_ex.data Normal file
View File

@ -0,0 +1,10 @@
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526

24
12.data Normal file
View File

@ -0,0 +1,24 @@
by-TW
start-TW
fw-end
QZ-end
JH-by
ka-start
ka-by
end-JH
QZ-cv
vg-TI
by-fw
QZ-by
JH-ka
JH-vg
vg-fw
TW-cv
QZ-vg
ka-TW
ka-QZ
JH-fw
vg-hu
cv-start
by-cv
ka-cv

74
12.jl Normal file
View File

@ -0,0 +1,74 @@
include("utils.jl")
function solution12_1()
lines = non_empty_lines("12.data")
adj_mat = Dict()
for line in lines
front, back = split(line, "-")
push!(get!(adj_mat, front, []), back)
push!(get!(adj_mat, back, []), front)
end
result = []
growing = [["start"]]
while length(growing) > 0
new = []
for path in growing
for neighbour in get(adj_mat, last(path), 0)
if Base.Unicode.isuppercase(neighbour[1])
push!(new, [path; neighbour])
else
if neighbour == "end"
push!(result, [path; neighbour])
else
if !(neighbour in path)
push!(new, [path; neighbour])
end
end
end
end
end
growing = new
end
length(result)
end
function small_twice(path)
length(filter(unique(path)) do element
Base.Unicode.islowercase(element[1]) && length(filter(==(element), path)) > 1
end) > 0
end
function solution12_2()
lines = non_empty_lines("12.data")
adj_mat = Dict()
for line in lines
front, back = split(line, "-")
push!(get!(adj_mat, front, []), back)
push!(get!(adj_mat, back, []), front)
end
result = []
growing = [["start"]]
while length(growing) > 0
new = []
for path in growing
for neighbour in get(adj_mat, last(path), 0)
if Base.Unicode.isuppercase(neighbour[1])
push!(new, [path; neighbour])
else
if neighbour == "end"
push!(result, [path; neighbour])
else
if neighbour != "start" && (!small_twice(path) || !(neighbour in path))
push!(new, [path; neighbour])
end
end
end
end
end
growing = new
end
length(result)
end
solution12_2()

7
12_ex.data Normal file
View File

@ -0,0 +1,7 @@
start-A
start-b
A-c
A-b
b-d
A-end
b-end

10
12_ex_2.data Normal file
View File

@ -0,0 +1,10 @@
dc-end
HN-start
start-kj
dc-start
dc-HN
LN-dc
HN-end
kj-sa
kj-HN
kj-dc

18
12_ex_3.data Normal file
View File

@ -0,0 +1,18 @@
fs-end
he-DX
fs-he
start-DX
pj-DX
end-zg
zg-sl
zg-pj
pj-he
RW-he
fs-DX
pj-RW
zg-RW
start-pj
he-WI
zg-he
pj-fs
start-RW

972
13.data Normal file
View File

@ -0,0 +1,972 @@
587,795
930,267
306,240
1052,763
177,826
681,841
1062,413
840,878
232,271
965,165
319,612
1027,215
524,707
939,887
1210,740
284,126
579,38
1079,826
509,73
542,381
1163,560
1208,775
83,306
177,266
348,297
1001,729
621,162
1081,92
557,802
1039,87
1290,824
1096,513
1034,711
446,105
955,523
371,7
1039,759
246,556
321,143
1277,747
768,157
644,382
895,471
1285,252
751,87
237,30
1057,453
1119,747
1086,551
940,514
279,345
1064,879
1061,32
833,138
637,541
900,207
145,709
50,437
870,466
604,367
164,773
688,658
698,156
477,714
759,721
1233,354
808,382
669,121
1034,576
694,208
1210,224
67,756
1292,770
1124,371
1185,455
1016,549
957,226
641,87
559,795
229,840
446,287
706,576
542,466
753,502
1173,390
95,266
1081,840
271,87
858,821
1067,418
408,879
494,684
525,291
852,411
826,313
626,502
918,808
259,714
1133,266
567,79
1272,354
74,756
125,7
1026,380
812,509
465,390
1243,756
242,609
1251,665
264,796
945,82
25,535
378,823
1300,512
559,68
484,313
298,52
885,129
1016,345
140,819
750,467
485,805
1171,173
90,42
191,371
38,514
637,93
858,799
997,569
1017,162
939,455
999,876
909,444
557,392
751,387
408,422
378,631
1017,284
249,204
405,204
25,617
438,751
1087,497
343,218
903,614
1216,686
826,562
1078,175
139,721
919,732
765,35
977,312
999,533
1036,367
284,799
990,700
698,14
1064,472
689,823
184,645
102,551
567,815
547,359
1034,479
229,92
715,609
805,180
113,644
721,502
1063,112
460,464
1255,477
560,203
758,327
718,651
1304,131
1036,11
698,351
435,278
571,54
662,357
885,502
253,892
909,854
1078,7
241,606
724,539
181,185
1243,490
284,516
644,512
33,610
659,197
346,572
263,162
18,236
170,497
94,887
147,442
380,267
698,238
797,285
964,740
239,471
94,686
1066,687
547,87
898,285
1061,862
1198,466
999,894
49,411
1062,481
840,206
1064,422
430,551
50,661
1031,345
33,215
196,35
957,568
669,404
430,631
147,560
393,819
407,280
132,793
115,35
274,367
636,434
1052,656
90,852
845,60
83,364
1101,218
266,439
425,129
759,173
38,380
49,467
736,422
1163,442
361,162
276,711
805,308
544,591
602,194
1083,801
1091,278
636,770
1261,336
97,18
674,770
847,147
900,332
238,539
766,476
1046,89
908,786
557,502
864,329
1046,691
179,697
48,383
751,196
666,834
72,490
689,299
674,231
539,859
605,558
708,866
299,299
858,73
1197,644
684,842
682,175
376,551
1258,703
214,9
733,526
1295,309
452,768
554,446
1293,386
693,887
189,504
699,455
201,455
403,486
920,796
1091,168
626,842
684,54
328,233
663,730
237,854
231,703
1063,784
920,0
699,614
1144,131
309,165
410,780
1039,554
266,485
365,119
769,196
1022,1
208,789
1215,266
361,757
689,75
1305,413
226,516
1113,743
636,796
900,543
571,588
579,856
1304,2
1161,143
319,282
902,463
1108,73
416,84
513,285
97,17
1136,270
1220,490
417,406
1096,428
1044,455
801,821
151,595
965,505
120,655
875,168
838,187
346,154
1250,343
1215,826
64,86
865,116
994,158
473,165
141,285
264,89
1104,544
1272,211
567,472
592,719
1061,480
1109,439
888,243
739,54
1129,185
694,540
626,54
693,439
470,206
258,432
391,732
166,539
498,133
82,463
1258,143
715,161
1277,732
743,815
72,861
2,131
1227,306
1034,599
671,876
87,24
991,707
166,131
522,206
264,546
1001,521
917,523
517,837
800,635
704,717
219,535
801,73
715,665
1235,883
343,0
479,147
52,703
567,422
231,308
415,471
1078,427
356,842
731,11
768,381
577,368
865,218
1126,231
945,119
587,11
1227,364
74,138
586,847
334,642
1185,439
616,290
1243,138
1208,844
880,263
1242,439
1277,679
383,807
1213,18
905,592
1113,757
683,187
830,494
309,93
192,26
706,16
629,535
547,807
934,343
607,673
944,235
746,490
497,766
1063,614
38,113
0,661
1064,662
288,669
574,562
1046,805
689,519
1250,103
611,439
390,348
552,791
755,613
888,875
1268,514
1073,30
977,560
38,561
18,7
1034,556
967,632
1237,749
309,521
962,597
920,348
85,466
865,564
1260,457
758,50
1280,576
1046,98
1034,295
950,549
73,2
545,859
837,389
60,791
745,226
587,180
60,343
365,775
902,472
875,127
559,87
95,807
141,509
999,890
1067,476
893,304
656,681
13,404
745,369
64,808
430,263
219,168
939,7
724,47
467,61
95,826
1071,423
914,579
756,154
621,183
266,7
507,782
733,354
276,338
48,717
487,652
319,264
1272,540
348,533
1297,82
551,173
751,835
196,483
858,95
100,313
1119,579
423,835
818,121
320,357
580,586
1198,94
902,422
694,333
604,599
410,207
37,364
746,404
734,817
1180,187
1225,428
982,380
299,595
1216,467
1285,642
885,392
684,392
112,878
166,355
967,710
957,277
599,359
197,757
470,361
1066,780
718,670
1235,491
246,662
1059,408
664,357
735,700
1034,31
940,351
716,73
621,732
858,156
1144,539
446,271
341,878
833,502
686,634
440,542
488,579
735,252
1255,417
935,549
933,336
997,430
989,751
669,542
271,554
18,98
577,32
356,536
887,835
962,688
1036,627
38,540
1099,859
15,466
595,665
75,446
724,91
475,25
572,431
605,467
25,252
666,60
1215,59
736,332
1046,546
174,606
1173,504
32,259
1011,299
637,205
202,745
523,19
1200,303
284,380
33,162
693,7
706,437
1118,500
276,631
559,387
470,645
1099,35
1293,353
1262,791
416,450
999,18
1238,490
587,782
612,238
263,732
875,87
440,437
731,311
756,446
751,68
557,278
1136,830
1064,214
1061,690
202,149
984,661
648,357
1001,165
125,455
1001,93
554,313
1230,472
845,834
311,361
689,610
283,455
181,505
249,862
95,180
1215,852
1027,7
569,18
662,131
887,628
551,721
182,488
311,302
621,375
246,463
1118,394
423,628
10,508
100,581
652,579
246,15
864,271
1084,378
112,16
689,711
751,99
189,642
1009,326
191,579
954,392
812,761
232,7
922,485
671,38
560,691
805,514
1044,439
253,453
124,785
253,702
191,763
59,161
283,679
768,16
266,821
403,408
346,740
604,457
191,131
447,663
976,642
850,464
853,603
1073,854
80,562
244,207
326,233
621,711
530,745
758,485
763,359
239,696
785,603
223,497
177,290
930,303
440,430
294,549
1165,877
1297,404
835,679
219,278
156,385
853,743
982,233
1102,341
43,439
694,290
1307,473
1081,392
229,54
661,334
907,486
1186,540
661,560
939,280
252,672
214,162
708,194
1002,175
1063,280
298,502
1071,696
1140,397
102,396
808,158
407,782
1136,606
534,543
170,397
184,663
232,427
853,599
893,864
1051,714
90,490
999,4
25,502
490,667
577,592
67,138
1133,826
87,359
177,806
765,859
1133,806
130,187
1140,497
1108,745
289,231
20,16
1113,137
422,243
80,472
1176,618
864,105
945,812
490,227
1,560
736,562
266,551
422,651
38,686
888,651
107,87
510,572
1033,483
1290,518
33,519
261,819
1279,467
452,156
1119,131
18,434
232,175
13,352
15,224
232,691
422,208
1198,800
962,533
1292,460
1044,821
390,796
492,219
177,88
1198,513
1057,444
77,144
739,784
1128,406
612,156
606,717
569,876
617,7
780,574
991,264
544,303
38,290
915,547
308,175
505,751
244,780
639,38
1126,249
1046,446
991,282
651,473
110,418
182,406
1200,418
840,430
930,527
1026,462
48,791
572,15
803,452
1295,466
182,712
87,311
1285,617
396,763
629,54
822,579
763,127
812,133
863,663
52,303
1250,73
1073,864
716,567
838,707
214,885
797,385
403,535
370,516
1220,42
990,418
704,177
969,325
699,7
659,869
1278,259
616,208
370,351
460,430
962,297
758,844
1293,613
77,316
636,231
554,670
1268,156
80,332
756,448
67,404
73,749
283,215
246,879
1012,502
559,99
249,32
79,252
1033,336
1267,166
808,64
1186,785
1228,463
219,359
288,652
626,840
883,93
365,231
837,165
706,599
1129,505
1292,98
999,184
492,675
715,49
830,624
320,418
1131,334
820,331
179,334
932,631
147,452
1178,793
800,707
1081,205
1178,814
571,840
87,870
276,823
1,334
232,887
604,878
253,889
1064,108
840,533
542,878
609,218
1309,334
55,502
422,686
739,110
17,613
743,760
1215,135
371,280
858,126
786,187
43,166
887,266
1021,775
85,428
232,686
1293,281
258,686
177,628
559,196
1119,371
485,312
845,390
715,733
572,463
95,628
197,585
494,131
309,613
405,32
13,490
214,605
1078,271
1079,255
817,889
612,656
237,406
1186,428
80,422
651,25
465,642
940,516
793,57
1078,238
209,330
348,688
232,875
1034,71
83,82
1203,731
151,747
48,551
17,508
15,551
1192,287
375,345
900,351
552,485
1208,103
189,281
fold along x=655
fold along y=447
fold along x=327
fold along y=223
fold along x=163
fold along y=111
fold along x=81
fold along y=55
fold along x=40
fold along y=27
fold along y=13
fold along y=6

36
13.jl Normal file
View File

@ -0,0 +1,36 @@
include("utils.jl")
function parse_input(filename)
lines = collect(non_empty_lines(filename))
dots = map(l->parse.(Int, split(l,',')), filter(line->Base.Unicode.isnumeric(line[1]), lines))
folds = map(filter(line->!Base.Unicode.isnumeric(line[1]), lines)) do line
front, coord = split(line, '=')
'x' in front ? 1 : 2, parse(Int, coord)
end
sort(dots), folds
end
function solution13_2()
dots, folds = parse_input("13.data")
for (axis, coord) in folds
foreach(dots) do dot
if dot[axis] > coord
dot[axis] -= 2 * (dot[axis] - coord)
end
end
dots = sort(unique(dots))
end
for y in 0:5
for x in 0:38
if [x, y] in dots
print('#')
else
print(' ')
end
end
println("")
end
end
solution13_2()

21
13_ex.data Normal file
View File

@ -0,0 +1,21 @@
6,10
0,14
9,10
0,3
10,4
4,11
6,0
6,12
4,1
0,13
10,12
3,4
3,0
8,4
1,10
2,14
8,10
9,0
fold along y=7
fold along x=5

102
14.data Normal file
View File

@ -0,0 +1,102 @@
SCVHKHVSHPVCNBKBPVHV
SB -> B
HH -> P
VF -> N
BS -> S
NC -> C
BF -> H
BN -> H
SP -> H
BK -> H
FF -> N
VN -> B
FN -> C
FS -> S
PP -> F
ON -> H
FV -> F
KO -> F
PK -> H
VB -> S
HS -> B
NV -> O
PN -> S
VH -> B
OS -> P
BP -> H
OV -> B
HK -> S
NN -> K
SV -> C
PB -> F
SK -> F
FB -> S
NB -> K
HF -> P
FK -> K
KV -> P
PV -> F
BC -> S
FO -> N
HC -> F
CP -> B
KK -> F
PC -> S
HN -> O
SH -> H
CK -> P
CO -> F
HP -> K
PS -> C
KP -> F
OF -> K
KS -> F
NO -> V
CB -> K
NF -> N
SF -> F
SC -> P
FC -> V
BV -> B
SS -> O
KC -> K
FH -> C
OP -> C
CF -> K
VO -> V
VK -> H
KH -> O
NP -> V
NH -> O
NS -> V
BH -> C
CH -> S
CC -> F
CS -> P
SN -> F
BO -> S
NK -> S
OO -> P
VV -> F
FP -> V
OK -> C
SO -> H
KN -> P
HO -> O
PO -> H
VS -> N
PF -> N
CV -> F
BB -> H
VC -> H
HV -> B
CN -> S
OH -> K
KF -> K
HB -> S
OC -> H
KB -> P
OB -> C
VP -> C
PH -> K

59
14.jl Normal file
View File

@ -0,0 +1,59 @@
include("utils.jl")
function parse_input(filename)
template, rawrules... = collect(non_empty_lines(filename))
rules = Dict()
for rule in rawrules
front, back = split(rule, " -> ")
first, second = split(front, "")
rules[[first[1], second[1]]] = back[1]
end
pairs = Dict()
for i in 1:length(template)-1
get!(pairs, [template[i], template[i+1]], 0)
pairs[[template[i], template[i+1]]] += 1
end
pairs, rules, [first(template), last(template)]
end
function countpoly(pairs, singles)
result = Dict()
for (key, value) in pairs
get!(result, key[1], 0)
result[key[1]] += value
get!(result, key[2], 0)
result[key[2]] += value
end
for single in singles
result[single] += 1
end
for key in keys(result)
result[key] = div(result[key], 2)
end
result
end
function solution14_2()
pairs, rules, singles = parse_input("14.data")
steps = 40
for step in 1:steps
new = Dict()
for (key, value) in pairs
insert = get!(rules, key, nothing)
if typeof(insert) == Char
get!(new, [key[1], insert], 0)
new[[key[1], insert]] += value
get!(new, [insert, key[2]], 0)
new[[insert, key[2]]] += value
else
get!(new, key, 0)
new[key] += value
end
end
pairs = new
end
counts = sort(collect(values(countpoly(pairs, singles))))
last(counts) - first(counts)
end
solution14_2()

18
14_ex.data Normal file
View File

@ -0,0 +1,18 @@
NNCB
CH -> B
HH -> N
CB -> H
NH -> C
HB -> C
HC -> B
HN -> C
NN -> C
BH -> H
NC -> B
NB -> B
BN -> B
BB -> N
BC -> B
CC -> N
CN -> C

100
15.data Normal file
View File

@ -0,0 +1,100 @@
7257173117871274148119191397411866741961893915191233591781237171134183111991588567743913598398999129
9199956198317542321811795167539333593959845233586245178771259721629672984999396181817424129792113429
5678391114239515741618386378916979112716269165195269215584939279279177393199175187199511833999819385
7149919968927397171639311441114199789621399783958844626227879671633692776519178119978312379854918472
9571133571872511883799281362819193417112413972551887416264299171789218539132957196979811132721291672
8172584925581929988661688649146133971138896125391412411926754121134983167188929529959966385437588844
4914518468152915388917729744941583692326581473756415317665271248313684872717734981831164961169161441
2519894881987711813817528992187872878321614865385871812543911299816979364869972221856158852969592112
9859391668949943293812278997458981968712239911133451788394169935992685191958894671638974814216612719
2192529153611518191595896814996141119517992288611125714717119399491112913829241231917539211119881849
2337843263693226789699931111398112969887535286492296226999311848178157169949315516494848924316823474
1191281328169873275751982595447194592918411459316261266123821567822849396139339812112776322962112239
4587143466247931931363896317279914687959418292417719618921579781314932674121288194141812419924513491
9188217988495399118711317519126435116785399685763129885168131465437119937687542179912685827611129973
9281999423754831489181352222362255825969879819312357829319722961312991751988497399311813231979551234
8411642818749914959745792191319718911388132253292482346295961171634916811938584616484592994128913896
3388255416913192166863912671592797172349778144861261162626679169122118178816999781511482128586841931
1544111521579847285289829899211419185418871795132727999177828715458885628798278694521919225186212479
6112394533149912224244478554154888237766677192511968451313528663845219413639188496229811993163929889
7198784899159217522265428239842119185341314211991273329136173711277137989451533985143943379599711279
5322174898961411153515736312827315967799457744138498991267929611147897735269199298727139863199825449
9389598982325839969741219429682597992913484299849122148988986313319119891881251311761168419988993984
9731391996727591141584769372292618329676991274389449899178113115589128811112539136473142798111999659
5158499781719185191335698726337225419942769281296219215168381368296377583192114793345154114939919138
9489436472297254387595375823195948188155998979224885397929111219894329444244314131186498373329899628
5115948294552681116994961691838819122926817811428719719487293692225795236769313128246954783896581419
7842378538599781529689123131749873922371451111511113114844145628981899497289212258729489151386198379
5657182954384884192389177113923946799271142897712314759172399912237297817994565459889643847449996591
2114463882686822117918787199822775881529895139151499196692246274147217497821149527235387719991114714
2911917115481432912158219697929535145897818898214661343833193385121919978318122826712681212138729941
7919482212881442617559399592111184197611192148899237895295211389594619418194519266268597128875922164
5122782781762591222295946745991662147485323299849117125858933893496129327282821421189644352917799563
1136291298829627566691527929262125187126922289732289227716821815619551911944779995415278137991622552
4929328679851289388213321419985631998929472889692146329429231293698273199118713262892523784612611999
1327734151191996421344997185478394257228713274441955249899986342244731153572974191897991393662691931
2781117154312271979199389368319489151943763236781711191122134726691762925242929616867585411791129159
1439186637181196485238285593819594866112889871679966657834249176324314497819969991879491995926214924
8198715159568382591431231227339698151116662552918333813978498567586137499214111391961922138831958891
1791636999843894411347725615937522999231159118674816321332412988177251964743241117549699136494419193
2347191949569898652196299127952395252161168176339428456658821198913454439135327112298841851793131139
6517373396832351522818699933865532731822114597879322225665521379149517111835298818315911951121182358
9989219811198438961112789214341437915858986541454335893139567183897549391541933121816392249992757195
2751242393169519965822749148113198418478749175225597965669585119898274413133594511599239813819261729
2333615561781383963589211869624423159983279225123169449222598319329695159532597919931391498257683522
2326925593466238521963381246934599431321918392819124294951311331116521125288316176431186199751635491
9341367399225381779967242896675118399271292593248972922271792198875912499185119129993955719191131219
9419488192386241298831213479619891591112812195761439362996925799233613913141343831817117189287994755
9695968821621727482419983392371417945181396516317947384995853931879231912925789698357961179754119511
9819267839831973911319938469292179778511998125121931891146223692296192299952153342285175781729419271
1863816696271622173271985549176326189359343784972161815896794319879938399995919111197381311974788614
9951198498951459991236295523134837224482241663114944798913138999819143627393989956711324837996945589
5636493872291432645969776969437321939689259195165871611951271619514731193819693277839717689838523535
1599873877797591958659883217591162792939133915996748148738729819416279661719716399869947198411871934
8794639995351381527537286278892222682139243726394685977188691436889598769141824739519232576663818623
9312694112319895396113225123691699114916381799538178372616115397895462387932975997638239393799315212
5832652557695274383198568431192817489141326899824429893139485722158832888768989154554522478498498714
8782845924111831912127921565587919113818125774499381223562975114549551996121626761137916739478221568
9811929922686225152399211122397597158513891191615161416432783564767191169849849511985178913416153852
1137711214593792114391112795839813891552389836983814596893489181536998977653386261925692938856897897
2891454257881276297539979515161138819723112914812122617911912212922972482812982987377897974782821188
7671589249839457412545235186153935156941884381134221489611219191921272892597772389234492565914198258
1552483399116635372974898931188883743171689242311789612968114416972112951486134993116143393399793998
8711188851122588629852724495172527356897321495229616597821333465358285422331924491418522517979118993
9593315278649975951219952268211871741223727356181132397183838894499829221111978873973591418997289513
3969997988729933184995613429919894232321166598283911973373115779211228919166877393889434215381781389
5588221472469964598623295656797377199853717996631331495111278692241929496187813341637872397899624175
9921637195158912596622263381891921897978588191413981249169189173199699294541171879989121615634351342
3798931227871974751799777995169123924251123997219388112822621636398239724484812154741112812741472923
1318745799964813125829815417129787311384489283415939129112478189111179617966392125599951899588399933
9919168243159595589113819319611976889991646271868112472392818222893941139743434115977476121333191818
3115972825613468816687921319481739413919883837749478584158912513417673612383549994987313463899975111
9819245879871957475393932424291294189961391917998628819131487621819218799996929997391516748191973218
2543119159599118542114782197275925148321199297951316238291197471953953113117231732381348855871885341
8597192929968786896989279839331134411223192189898926119875521124153282436126568329811999323445191679
3975785449971831818312568579176154978689122133184732928183381881141862482849263341279915278911683894
3179111996949988298153199151389479257689125228811639199771592599998978715664289996372311512944263139
3717731949295466943999325285695444691229948881923328813265999285999127111938229969918689613331778988
3899774572142914257631398127999644341916848491762691872194259535697139312281868155191287342929193183
3419531741121147372119481389754229993641415577459396295899232815823975392974927395711568972974293925
1722176361244419285779288543598751211392531919462574932268633933695192352441119172662173735119515712
8259287379497359112197399192874789929899857534134534892997117372192299398799696792833998919968157692
9113588331521199442922126152433321148852971919741151158559612459789766141191421226791434779238851542
9934485995397918323116671821935121371411639119196141711221111598878781853442188129954293234742142941
5863996738774189559631311914763988372133998564893667341114799688887419869498499571261945352924543659
1219173111621632848325722799121771234351313226119137299611516914998734631224397849155891733316457236
2581119126696683198948223933432829124786552193519396275241779267529656466959196852322344769712989425
9967141179556989992264146994141761832265411668193157248414232474791714884711961318296968187812563731
2489879759889926897312354996751186797873869898953112749555984922414591917338857833991412625172181498
9389457158881973888911321813181681241492541783691881299169396894618761158125679495966134894392982199
9619992269841241296891999961333629572281414928995452682633291959449286127129612124227252269791663654
1614835267511194414153578263179929291589313129387133978158911722592272783869578732691311815861241491
9652116592834327221168619761719533625339966299211384947128885411279177514867942937963481178919941711
2933298721252991578245341817819977199267549571111491876711439883927615991991196211296294697272313774
1431715794741427753127381461152185596778586461419451428969132784392522194651111917169662896769767812
5919195742129923589897349316296264144952749521471522921641452152978765849165829872135669664214112327
6339474432243943991959119983361889756918344251994119969825144749941178381321286493218961118191911875
5517228343299391617317192214769719192189853799115811159493116197825637676714396432979816281155693495
6388461935842284623142112416943162883259817194297799981283439458172297191119123521515932483495126961
7843191912999868941538811232841971381689242136381989791436989848478992513449168132392761291119899184
1424114349573937523917871789194999469999119751164761884221519813273935995996288159921682217898434989

63
15.jl Normal file
View File

@ -0,0 +1,63 @@
include("utils.jl")
function parse_input(filename)
map(x->parse.(Int, x), split.(non_empty_lines(filename), ""))
end
function search(entry_risk)
width, height = size(entry_risk)
total_risk = fill(typemax(Int64), width, height)
total_risk[1, 1] = 0
to_visit = [(CartesianIndex(1,2), 0), (CartesianIndex(2,1), 0)]
while length(to_visit) > 0
rounds += 1
coord, cost = popfirst!(to_visit)
cost += entry_risk[coord]
if cost < total_risk[coord]
total_risk[coord] = cost
if coord[1] > 1
push!(to_visit, (CartesianIndex(coord[1] - 1, coord[2]), cost))
end
if coord[1] < width
push!(to_visit, (CartesianIndex(coord[1] + 1, coord[2]), cost))
end
if coord[2] > 1
push!(to_visit, (CartesianIndex(coord[1], coord[2] - 1), cost))
end
if coord[2] < height
push!(to_visit, (CartesianIndex(coord[1], coord[2] + 1), cost))
end
end
end
total_risk[width, height]
end
function solution15_1()
entry_risk = parse_input("15.data")
width = length(entry_risk)
height = length(entry_risk[1])
entry_risk = transpose(reshape(reduce(vcat, entry_risk), height, width))
search(entry_risk)
end
function solution15_2()
entry_risk = parse_input("15.data")
width = length(entry_risk)
height = length(entry_risk[1])
entry_risk = map(entry_risk) do line
[line;
map(x->mod((x-1)+1, 9)+1, line);
map(x->mod((x-1)+2, 9)+1, line);
map(x->mod((x-1)+3, 9)+1, line);
map(x->mod((x-1)+4, 9)+1, line);
]
end
for _ in 1:(4*height)
push!(entry_risk, map(x->mod((x-1)+1, 9)+1, entry_risk[length(entry_risk) - (height - 1)]))
end
entry_risk = transpose(reshape(reduce(vcat, entry_risk), height*5, width*5))
search(entry_risk)
end
solution15_2()

10
15_ex.data Normal file
View File

@ -0,0 +1,10 @@
1163751742
1381373672
2136511328
3694931569
7463417111
1319128137
1359912421
3125421639
1293138521
2311944581

1
16.data Normal file
View File

@ -0,0 +1 @@
420D610055D273AF1630010092019207300B278BE5932551E703E608400C335003900AF0402905009923003880856201E95C00B60198D400B50034400E20101DC00E10024C00F1003C400B000212697140249D049F0F8952A8C6009780272D5D074B5741F3F37730056C0149658965E9AED7CA8401A5CC45BB801F0999FFFEEE0D67050C010C0036278A62D4D737F359993398027800BECFD8467E3109945C1008210C9C442690A6F719C48A351006E9359C1C5003E739087E80F27EC29A0030322BD2553983D272C67508E5C0804639D4BD004C401B8B918E3600021D1061D47A30053801C89EF2C4CCFF39204C53C212DABED04C015983A9766200ACE7F95C80D802B2F3499E5A700267838803029FC56203A009CE134C773A2D3005A77F4EDC6B401600043A35C56840200F4668A71580043D92D5A02535BAF7F9A89CF97C9F59A4F02C400C249A8CF1A49331004CDA00ACA46517E8732E8D2DB90F3005E92362194EF5E630CA5E5EEAD1803E200CC228E70700010A89D0BE3A08033146164177005A5AEEB1DA463BDC667600189C9F53A6FF6D6677954B27745CA00BCAE53A6EEDC60074C920001B93CFB05140289E8FA4812E071EE447218CBE1AA149008DBA00A497F9486262325FE521898BC9669B382015365715953C5FC01AA8002111721D4221007E13C448BA600B4F77F694CE6C01393519CE474D46009D802C00085C578A71E4001098F518639CC301802B400E7CDDF4B525C8E9CA2188032600E44B8F1094C0198CB16A29180351EA1DC3091F47A5CA0054C4234BDBC2F338A77B84F201232C01700042A0DC7A8A0200CC578B10A65A000601048B24B25C56995A30056C013927D927C91AB43005D127FDC610EF55273F76C96641002A4F0F8C01CCC579A8D68E52587F982996F537D600

116
16.jl Normal file
View File

@ -0,0 +1,116 @@
using Pkg
Pkg.add("Match")
using Match
include("utils.jl")
function parse_input(filename)
reverse(collect(collect(non_empty_lines(filename))[1]))
end
mutable struct BinaryReader
input
rest
BinaryReader(input) = new(input, [])
end
function fill_rest(reader)
char = pop!(reader.input)
code = codepoint(char)
number = code < 0x3A ? code - 0x30 : code - (0x41 - 10)
reader.rest = reverse(parse.(Int, collect(string(number, base=2, pad=4))))
end
function read_bits(reader, count)
result = []
while length(result) < count
if length(reader.rest) == 0
fill_rest(reader)
end
push!(result, pop!(reader.rest))
end
result
end
function reader_length(reader)
length(reader.rest) + length(reader.input) * 4
end
function to_int(bits)
parse(Int, reduce(*, string.(bits)), base=2)
end
function parse_literal(reader, version)
result = []
cont = 1
while cont == 1
cont = read_bits(reader, 1)[1]
result = [result; read_bits(reader, 4)]
end
(version, 4, to_int(result))
end
function parse_operator(reader, version, type)
length_type = read_bits(reader, 1)[1]
subpackets = []
if length_type == 0
subpacket_bits = to_int(read_bits(reader, 15))
start_remaining = reader_length(reader)
while reader_length(reader) + subpacket_bits > start_remaining
push!(subpackets, parse_packet(reader))
end
else
subpacket_count = to_int(read_bits(reader, 11))
for _ in 1:subpacket_count
push!(subpackets, parse_packet(reader))
end
end
(version, type, subpackets)
end
function parse_packet(reader)
version = to_int(read_bits(reader, 3))
type = to_int(read_bits(reader, 3))
if type == 4
parse_literal(reader, version)
else
parse_operator(reader, version, type)
end
end
function sum_versions(packet)
result = packet[1]
if packet[2] != 4
result += reduce(+, sum_versions.(packet[3]))
end
result
end
function solution16_1()
input = parse_input("16.data")
reader = BinaryReader(input)
packet = parse_packet(reader)
sum_versions(packet)
end
function value(packet)
@match packet[2] begin
0 => reduce(+, value.(packet[3]))
1 => reduce(*, value.(packet[3]))
2 => reduce(min, value.(packet[3]))
3 => reduce(max, value.(packet[3]))
4 => packet[3]
5 => value(packet[3][1]) > value(packet[3][2]) ? 1 : 0
6 => value(packet[3][1]) < value(packet[3][2]) ? 1 : 0
7 => value(packet[3][1]) == value(packet[3][2]) ? 1 : 0
end
end
function solution16_2()
input = parse_input("16.data")
reader = BinaryReader(input)
packet = parse_packet(reader)
value(packet)
end
solution16_2()

1
16_ex.data Normal file
View File

@ -0,0 +1 @@
D2FE28

1
16_ex_2.data Normal file
View File

@ -0,0 +1 @@
38006F45291200

16
16_ex_3.data Normal file
View File

@ -0,0 +1,16 @@
9C0141080250320F1802104A08
9C005AC2F8F0
F600BC2D8F
D8005AC2A8F0
CE00C43D881120
880086C3E88112
04005AC33890
C200B40A82
A0016C880162017C3686B18A3D4780
C0015000016115A2E0802F182340
620080001611562C8802118E34
8A004A801A8002F478
EE00D40C823060

1
17.data Normal file
View File

@ -0,0 +1 @@
target area: x=153..199, y=-114..-75

54
17.jl Normal file
View File

@ -0,0 +1,54 @@
include("utils.jl")
function parse_input(filename)
line = collect(non_empty_lines(filename))[1]
println(line)
map(x->parse(Int, x.match), eachmatch(r"-?[0-9]+", line))
end
function inverse_gauss(x)
sqrt(1/4 + 2 * x) - 1/2
end
function valid_x_velocities(left, right)
Int64(ceil(inverse_gauss(left))):Int64(floor(inverse_gauss(right)))
end
function hitp(left, right, bottom, top, vel)
pos = [0, 0]
mpos = [0, 0]
velocity = copy(vel)
while pos[2] > bottom
pos += velocity
mpos = max(pos, mpos)
velocity[1] = velocity[1] > 0 ? velocity[1] - 1 : 0
velocity[2] -= 1
if pos[1] >= left && pos[1] <= right && pos[2] >= bottom && pos[2] <= top
return true, mpos[2], vel
end
end
false, mpos[2], vel
end
function solution17_1()
left, right, bottom, top = parse_input("17.data")
for vx in valid_x_velocities(left, right)
shots = map(v->hitp(left, right, bottom, top, v), [[vx, vy] for vy in 1:10000])
hits = collect(Iterators.filter(x->x[1], shots))
println(last(sort(hits, by=x->x[2])))
end
end
function solution17_2()
left, right, bottom, top = parse_input("17.data")
sum = 0
for vx in 1:right
shots = map(v->hitp(left, right, bottom, top, v), [[vx, vy] for vy in bottom:1000])
hits = collect(map(x->x[3], Iterators.filter(x->x[1], shots)))
sum += length(hits)
end
sum
end
solution17_2()

1
17_ex.data Normal file
View File

@ -0,0 +1 @@
target area: x=20..30, y=-10..-5

100
18.data Normal file
View File

@ -0,0 +1,100 @@
[[[[8,1],8],[[8,1],0]],[[8,[2,4]],[0,8]]]
[[[[2,2],[7,4]],[[9,1],6]],8]
[[[3,6],[[8,7],[2,9]]],[8,[[2,3],9]]]
[[[[4,5],[1,4]],1],[[0,8],[2,[6,8]]]]
[[7,[[4,6],[0,0]]],[[4,3],5]]
[[[[8,4],4],[[4,4],[1,0]]],[[5,[5,5]],[[5,2],1]]]
[[[0,[5,8]],[1,7]],[[[5,0],[1,3]],7]]
[4,[[[6,2],[7,8]],[0,[4,4]]]]
[[[3,[5,3]],8],[[[6,8],4],[8,9]]]
[[[6,0],[9,[8,1]]],[[[9,7],3],0]]
[[9,[[9,3],[0,8]]],[[[5,3],0],[[5,6],2]]]
[[3,[[7,7],3]],[[7,[5,2]],[[6,9],0]]]
[1,[4,[3,8]]]
[[[[0,2],9],[[0,7],8]],[[5,4],[2,8]]]
[[[[1,8],9],[1,7]],[[4,[8,5]],[[6,3],[1,0]]]]
[[9,[[4,3],[3,3]]],[[[4,9],[0,9]],6]]
[7,[[8,0],[5,6]]]
[[[[3,2],1],[[4,9],6]],[[9,[1,1]],[[8,7],1]]]
[[[[5,1],[3,3]],0],[1,[[3,2],2]]]
[[7,9],[[9,9],[5,[9,5]]]]
[[[[4,3],[1,7]],[4,[9,2]]],[[6,[1,7]],[[8,0],3]]]
[[[5,[2,8]],[[1,2],7]],[[3,[0,5]],[[3,5],8]]]
[[[[2,2],6],[[2,1],7]],[[[4,6],8],7]]
[[2,[[3,0],[0,5]]],[[[3,4],[0,1]],0]]
[[[[9,9],5],[[9,9],6]],[[[4,1],2],0]]
[4,[[2,9],[6,2]]]
[[[8,6],6],7]
[[7,[8,2]],[[[5,5],6],[9,0]]]
[5,[[2,5],[[4,9],[8,6]]]]
[[4,[7,[9,6]]],7]
[[[9,[3,3]],[[3,1],[8,7]]],[[6,[3,5]],[4,1]]]
[[8,6],[8,[[0,2],[8,1]]]]
[6,[8,[[7,7],0]]]
[3,4]
[[9,[8,0]],[[[7,8],3],1]]
[5,[[3,[8,7]],[[5,0],[9,7]]]]
[[[[4,2],9],[6,[0,2]]],6]
[[4,[3,[4,9]]],[[4,[1,6]],1]]
[[[6,3],[8,8]],[5,[[9,3],[6,3]]]]
[[[9,9],[[7,1],6]],[[[1,0],[7,4]],[3,[2,0]]]]
[[[[2,5],9],[3,[6,2]]],[4,7]]
[[1,[7,8]],[[[0,1],8],[[1,1],9]]]
[[[9,[6,4]],[[9,8],[0,2]]],[[[8,9],[2,3]],[3,[8,0]]]]
[[[[6,8],2],3],[[2,2],5]]
[[[4,[8,5]],[[4,3],1]],[[[2,4],[4,4]],[[4,1],[1,7]]]]
[[[[2,6],6],[[9,2],4]],[[[9,9],[9,5]],5]]
[[[[7,5],[4,9]],4],[[[0,7],[3,6]],[[6,5],[3,0]]]]
[[[4,4],[[5,7],[8,5]]],[0,8]]
[[3,[[1,3],[7,5]]],[6,[[8,1],0]]]
[[[9,9],[5,[9,6]]],[[[4,0],[5,4]],6]]
[0,[[[9,2],4],3]]
[[[1,[8,5]],[0,[6,0]]],[[[6,5],[3,1]],[[6,2],[1,5]]]]
[[[4,0],[4,7]],6]
[1,[[[5,2],9],[[3,9],4]]]
[[[[9,6],[4,1]],4],[2,[[0,2],6]]]
[9,[[[1,5],[3,1]],1]]
[5,0]
[9,[[[7,5],[2,1]],[[2,3],[5,3]]]]
[[5,[[0,5],[9,5]]],[[[2,7],3],[[2,9],[3,5]]]]
[[[1,9],2],[[7,[1,7]],[8,[9,8]]]]
[[8,9],[[5,[9,0]],[[6,8],[5,2]]]]
[6,[[[1,3],[0,8]],4]]
[[[[9,8],[0,9]],[[8,4],[3,5]]],[[[5,0],8],[[6,8],1]]]
[[6,[[1,4],[7,0]]],[[3,4],[[2,1],[2,7]]]]
[[[5,0],[3,[4,7]]],[[9,3],[[9,4],[9,6]]]]
[[[[8,3],[8,0]],5],[[[5,5],[0,2]],[[0,1],9]]]
[[[[6,4],[1,8]],[3,[0,2]]],[8,[[8,8],5]]]
[2,[[2,1],[1,4]]]
[8,[0,[3,5]]]
[[[[0,2],3],[[4,9],[1,2]]],[[8,2],[6,[7,1]]]]
[[[0,0],9],1]
[8,[[4,1],[[1,3],9]]]
[[[8,[5,9]],9],[[[5,7],[9,0]],3]]
[[5,[2,9]],7]
[5,6]
[[[[7,5],[8,3]],[[4,3],8]],[[2,2],[[7,2],[4,2]]]]
[[[9,5],[3,[1,5]]],6]
[[[[7,4],[7,9]],[[3,1],[3,1]]],[[[6,4],[0,1]],1]]
[[3,[[7,4],9]],[[[5,8],[2,7]],[[0,4],[3,6]]]]
[[[3,[2,3]],[[6,0],[7,7]]],1]
[[2,[[8,8],[2,3]]],[5,2]]
[[[0,[5,5]],[8,1]],5]
[[3,9],[6,[[0,5],[1,7]]]]
[[[[3,0],9],[8,2]],[[[2,2],8],0]]
[[[9,6],[[5,1],[4,9]]],[[[1,1],[0,3]],[[4,9],[7,5]]]]
[[[2,[6,1]],[[5,7],[9,2]]],[[[4,2],8],9]]
[[9,[7,1]],[[4,5],[9,1]]]
[[9,[5,0]],[[1,7],[[9,6],[4,5]]]]
[[[[1,1],[8,7]],4],[[0,4],[[1,7],[3,5]]]]
[[5,[1,[8,4]]],[[[9,4],0],[1,[5,5]]]]
[[[5,[1,6]],[6,0]],[[0,[9,7]],1]]
[2,[9,[[0,3],[2,3]]]]
[3,[4,[[0,9],8]]]
[[5,6],[[[9,9],[4,0]],[7,[2,0]]]]
[[[[5,1],6],[[1,0],[7,1]]],[[6,[1,0]],[[4,2],[0,0]]]]
[[[4,[0,2]],6],[[[4,3],[8,0]],[[9,6],[1,5]]]]
[[[[5,3],[2,2]],[8,[8,3]]],[[9,1],2]]
[[3,4],[[[4,7],[2,3]],[9,[9,0]]]]
[[[5,[6,2]],[[1,5],[9,2]]],[[[7,9],3],[[6,7],[6,2]]]]
[[[5,3],9],[[2,[4,3]],[[5,3],1]]]

135
18.jl Normal file
View File

@ -0,0 +1,135 @@
include("utils.jl")
function parse_value(line, index)
if line[index] == '['
parse_tuple(line, index)
else
digits = match(r"^[0-9]+", SubString(line, index)).match
index += length(digits)
parse(Int, digits), index
end
end
function parse_tuple(line, index=1)
@assert line[index] == '['
index += 1
first, index = parse_value(line, index)
@assert line[index] == ','
index += 1
second, index = parse_value(line, index)
@assert line[index] == ']'
index +=1
return Any[first, second], index
end
function parse_input(filename)
map(x->x[1], map(parse_tuple, non_empty_lines(filename)))
end
function split_sf(a)
if typeof(a) == Int64
if a > 9
Any[div(a,2),div(a,2)+rem(a,2)], true
else
a, false
end
else
l, changed = split_sf(a[1])
a[1] = l
if changed
a, true
else
r, changed = split_sf(a[2])
a[2] = r
a, changed
end
end
end
function add_left_sf(a, number)
if typeof(a) == Int64
a + number
else
a[1] = add_left_sf(a[1], number)
a
end
end
function add_right_sf(a, number)
if typeof(a) == Int64
a + number
else
a[2] = add_right_sf(a[2], number)
a
end
end
function explode_sf(a, level=1)
if typeof(a) == Int64
return a, false, 0, 0
end
if level == 5
@assert typeof(a[1]) == Int64 && typeof(a[2]) == Int64
0, true, a[1], a[2]
else
l, changed, to_left, to_right = explode_sf(a[1], level + 1)
if changed
Any[l, add_left_sf(a[2], to_right)], true, to_left, 0
else
r, changed, to_left, to_right = explode_sf(a[2], level + 1)
if changed
Any[add_right_sf(l, to_left), r], true, 0, to_right
else
a, false, 0, 0
end
end
end
end
function reduce_sf(a)
changed = true
while changed
a, changed = explode_sf(a)
if changed
continue
end
a, changed = split_sf(a)
end
a
end
function add_sf(a, b)
reduce_sf(Any[deepcopy(a), deepcopy(b)])
end
function mag_sf(a)
if typeof(a) == Int64
a
else
3 * mag_sf(a[1]) + 2 * mag_sf(a[2])
end
end
function solution18_1()
mag_sf(reduce(add_sf, parse_input("18.data")))
end
function solution18_2()
input = collect(parse_input("18.data"))
max_mag = 0
for a in input
for b in input
print('.')
max_mag = max(max_mag, mag_sf(add_sf(a, b)))
end
end
println("")
max_mag
end
solution18_2()

10
18_ex.data Normal file
View File

@ -0,0 +1,10 @@
[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]]
[[[5,[2,8]],4],[5,[[9,9],0]]]
[6,[[[6,2],[5,6]],[[7,6],[4,7]]]]
[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]]
[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]]
[[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]]
[[[[5,4],[7,7]],8],[[8,3],8]]
[[9,3],[[9,9],[6,[4,9]]]]
[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]]
[[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]]

1023
19.data Normal file

File diff suppressed because it is too large Load Diff

140
19.jl Normal file
View File

@ -0,0 +1,140 @@
include("utils.jl")
function parse_input(filename)
scanners = []
current = []
for line in non_empty_lines(filename)
if line[1] == '-' && line[2] == '-'
push!(scanners, current)
current = []
else
coord = collect(map(m->parse(Int, m.match), eachmatch(r"-?[0-9]+", line)))
push!(current, coord)
end
end
push!(scanners, current)
scanners[2:length(scanners)]
end
transforms = [
# up: z
a -> a,
a -> [-a[2], a[1], a[3]],
a -> [-a[1], -a[2], a[3]],
a -> [a[2], -a[1], a[3]],
# up: -z
a -> [-a[1], a[2], -a[3]],
a -> [a[2], a[1], -a[3]],
a -> [a[1], -a[2], -a[3]],
a -> [-a[2], -a[1], -a[3]],
# up: x
a -> [-a[3], a[2], a[1]],
a -> [a[2], a[3], a[1]],
a -> [a[3], -a[2], a[1]],
a -> [-a[2], -a[3], a[1]],
# up: -x
a -> [a[3], a[2], -a[1]],
a -> [-a[2], a[3], -a[1]],
a -> [-a[3], -a[2], -a[1]],
a -> [a[2], -a[3], -a[1]],
# up: y
a -> [a[1], -a[3], a[2]],
a -> [-a[3], -a[1], a[2]],
a -> [-a[1], a[3], a[2]],
a -> [a[3], a[1], a[2]],
# up: -y
a -> [a[1], a[3], -a[2]],
a -> [-a[3], a[1], -a[2]],
a -> [-a[1], -a[3], -a[2]],
a -> [a[3], -a[1], -a[2]],
]
function try_match(a, b)
for c in a
for d in b
t = c - d
if length(intersect(a, map(x->x+t, b))) > 11
println("pos $t")
#println(intersect(a, map(x->x+t, b)))
return true, collect(map(x->x+t, b))
end
end
end
false, nothing
end
function find_match(fixed, scanners)
for (f,j) in fixed
for i in 1:length(scanners)
s,k = scanners[i]
for t in transforms
td = collect(map(t, s))
matchp, transformed = try_match(f, td)
if matchp
println("f: $(j-1) s: $(k-1)")
return i, transformed
end
end
# println("f: $(j-1) s: $(k-1) x")
end
end
end
function solution19_1()
scanners = collect(parse_input("19.data"))
zipped = collect(zip(scanners, 1:length(scanners)))
fixed = [popfirst!(zipped)]
while length(zipped) > 0
index, transformed = find_match(fixed, zipped)
s = popat!(zipped, index)
# println(s[1])
# println(transformed)
push!(fixed, (transformed, s[2]))
l = length(fixed)
println("located $l")
end
length(reduce(union, map(x->x[1], fixed)))
end
function solution19_2()
positions = [[0, 0, 0],
[-28, 1245, -161],
[1163, 26, -170],
[-1254, 90, -158],
[-18, 1355, -1280],
[1146, -1193, -28],
[-2380, 15, -13],
[-1078, 63, 1010],
[-1105, 28, -1236],
[-12, 2400, -1318],
[-1075, 1190, -1385],
[-2348, 173, -1313],
[-2450, -1024, -26],
[-3547, 0, -79],
[-1233, -1211, 1144],
[-1092, 1288, 1125],
[-2449, 1277, -1238],
[-2290, -2266, -141],
[-4753, 30, -166],
[-3532, 97, 1132],
[-1224, 2573, 1061],
[-2428, 1249, 1069],
[-2269, -3556, -95],
[-1131, -2278, -172],
[-2337, -2411, 1197],
[-4722, 31, 1198],
[-6042, 159, -182],
[-3560, 131, 2245],
[-2385, -3457, 1117],
[-2369, -4811, -22],
[-1144, -3615, -89],
[-4732, -17, 2315],
[-5936, -1062, -10],
[-2339, -3488, 2394],
[-2334, -4684, 1017],
[-3472, -3589, 2361],
[-1256, -3495, 2220]]
reduce(max, map(a->sum(abs.(a)), map(a->a[1]-a[2], [(a,b) for a in positions for b in positions])))
end
solution19_2()

136
19_ex.data Normal file
View File

@ -0,0 +1,136 @@
--- scanner 0 ---
404,-588,-901
528,-643,409
-838,591,734
390,-675,-793
-537,-823,-458
-485,-357,347
-345,-311,381
-661,-816,-575
-876,649,763
-618,-824,-621
553,345,-567
474,580,667
-447,-329,318
-584,868,-557
544,-627,-890
564,392,-477
455,729,728
-892,524,684
-689,845,-530
423,-701,434
7,-33,-71
630,319,-379
443,580,662
-789,900,-551
459,-707,401
--- scanner 1 ---
686,422,578
605,423,415
515,917,-361
-336,658,858
95,138,22
-476,619,847
-340,-569,-846
567,-361,727
-460,603,-452
669,-402,600
729,430,532
-500,-761,534
-322,571,750
-466,-666,-811
-429,-592,574
-355,545,-477
703,-491,-529
-328,-685,520
413,935,-424
-391,539,-444
586,-435,557
-364,-763,-893
807,-499,-711
755,-354,-619
553,889,-390
--- scanner 2 ---
649,640,665
682,-795,504
-784,533,-524
-644,584,-595
-588,-843,648
-30,6,44
-674,560,763
500,723,-460
609,671,-379
-555,-800,653
-675,-892,-343
697,-426,-610
578,704,681
493,664,-388
-671,-858,530
-667,343,800
571,-461,-707
-138,-166,112
-889,563,-600
646,-828,498
640,759,510
-630,509,768
-681,-892,-333
673,-379,-804
-742,-814,-386
577,-820,562
--- scanner 3 ---
-589,542,597
605,-692,669
-500,565,-823
-660,373,557
-458,-679,-417
-488,449,543
-626,468,-788
338,-750,-386
528,-832,-391
562,-778,733
-938,-730,414
543,643,-506
-524,371,-870
407,773,750
-104,29,83
378,-903,-323
-778,-728,485
426,699,580
-438,-605,-362
-469,-447,-387
509,732,623
647,635,-688
-868,-804,481
614,-800,639
595,780,-596
--- scanner 4 ---
727,592,562
-293,-554,779
441,611,-461
-714,465,-776
-743,427,-804
-660,-479,-426
832,-632,460
927,-485,-438
408,393,-506
466,436,-512
110,16,151
-258,-428,682
-393,719,612
-211,-452,876
808,-476,-593
-575,615,604
-485,667,467
-680,325,-822
-627,-443,-432
872,-547,-609
833,512,582
807,604,487
839,-516,451
891,-625,532
-652,-548,-490
30,-46,-14

39
19_ex_2.data Normal file
View File

@ -0,0 +1,39 @@
--- scanner 0 ---
-1,-1,1
-2,-2,2
-3,-3,3
-2,-3,1
5,6,-4
8,0,7
--- scanner 0 ---
1,-1,1
2,-2,2
3,-3,3
2,-1,3
-5,4,-6
-8,-7,0
--- scanner 0 ---
-1,-1,-1
-2,-2,-2
-3,-3,-3
-1,-3,-2
4,6,5
-7,0,8
--- scanner 0 ---
1,1,-1
2,2,-2
3,3,-3
1,3,-2
-4,-6,5
7,0,8
--- scanner 0 ---
1,1,1
2,2,2
3,3,3
3,1,2
-6,-4,-5
0,7,-8

10
1_ex.data Normal file
View File

@ -0,0 +1,10 @@
199
200
208
210
200
207
240
269
260
263

1000
2.data Normal file

File diff suppressed because it is too large Load Diff

51
2.jl Normal file
View File

@ -0,0 +1,51 @@
using Pkg
Pkg.add("Match")
using Match
include("utils.jl")
function solution2_1()
input_lines = non_empty_lines("2.data")
function parse_line(line)
(command, amount) = split(line, " ")
parsed_amount = parse(Int, amount)
end
map(fline->split(line, " "), input_lines)
x = 0
y = 0
for line in input_lines
(command, amount) = split(line, " ")
parsed_amount = parse(Int, amount)
@match command begin
"forward" => begin x += parsed_amount end
"up" => begin y -= parsed_amount end
"down" => begin y += parsed_amount end
end
end
(x, y, x*y)
end
function solution2_2()
input_lines = non_empty_lines("2.data")
aim = 0
x = 0
y = 0
for line in input_lines
(command, amount) = split(line, " ")
parsed_amount = parse(Int, amount)
@match command begin
"forward" => begin x += parsed_amount; y += parsed_amount * aim end
"up" => begin aim -= parsed_amount end
"down" => begin aim += parsed_amount end
end
end
(x, y, x*y)
end
(solution2_1(), solution2_2())

102
20.data Normal file
View File

@ -0,0 +1,102 @@
#.#.....##...##..#.#......#.#...#.#.#...###.##......###.##.##..##.#...#.....###.#.....#.#.#...#.#..###.###..###..#..##..###..##..##.##.#..###########.##....#.#......#...#.###..###...#.####..########.#####.#.#..##.##.##..###.##.####.#..##.##..#...#####..#.#.##.##...##..#..##.....###.#.#....####.##.#...##.########.#.##.#.....###....#..###.####....############.#.##...#.####...#...##.#.#..#..#......#..##...#.########.#.#...#####..#..######.#.#.....#####...##.###.#.#.##.........#.#.##..##.#..#..##..##.###.##.##.
#.#...##.#.##.##...#......##....##...#.#....##.##.#.##....###.#####.#......###......#.#.##.####..#.#
#.#...###.#.#.#...##...###....#####.#...#.####..########.#.#.#..#.###..##..#.####....#.#..#..##.####
.....#.######..#.#.....#..#..####.########..#.#.####..#####..##.#..##..##.##.#..###.#.#.#.#...#..###
#.#........#.###.#..######.##..#.##...#.....#.#.......#.##.....#.###.##.#..##..#.##...##...##.####..
#...#.#.##..###..#..####..#####.##...###.#....#..###..#.#....####..####.####..#..###.####.###.#..###
#..###..##.#....#.##..##.#..#.##....#.#.#.##..#.#.##..#..##.....#####..#..##.##.##..#.#####.###.#...
..####..##...#....##.#...#######..#....##.###...#.#.........##........###.#.##....#.#.###...#...###.
#######..#......##...##..###..##.#..##.#...###..##..#.#.##....##...##.#..##..##....#..###...##...#..
.###.....#..#..##....#...#.##.#..#.#.#...#..#...#..#.#.###.####..#.###.###.###.#.#..#....#.#.#.#.##.
...##.#.#.#..#..#..#.#.##..#.....#...#####..#####..#.#..#...##..#..#...###.....#...#.#.#....#..##.##
.#####.##.##..#...###.#....##...###..#..#...#...########..#.#...#.#..####........####...###...##....
.#..#..#.#....##..#.###...#..#.###...##.###.##.#...#####....#.###..#.#..#....#.##..#.......#.....#.#
.#..##..#..####..##.#.#..##..###..#.......#...#...#.####.#.#.#..#.##......#.##.###.###.####.##.#.###
.##..##.#..##..#.##.###...#.#####.#.#.#.##...#..#...##..##...#..###.###.##..##.#######.###....######
....#.#..##...#..#####...##.#.##......#.###.#.#.###..#...###..##.#..#..####..#.#....#..#.####...#..#
.#..##..##...#.####.#####.#######.######.####.......#.#.###.##.#.#.#.#.##.....#....#....#..###....##
###.##..#.#.#.#.#..#######.#.########.#.#.#..####.#####.#.#..##..#..##.....#...#....#.##.##.#....#.#
#..#.####.####.##.####...#.###.#.##......###..##.####..#..####..##.#.#....##..##.######...#..##.....
#.##...#...#..##...#.#......#..######.#.###.####..#######..#.##...#.#...#.##..###.#####..#...#.####.
##.###.#.######.#...#..##.#...#..##.##.....###..#.##.#..#..####....#.##.##..#.#..#.#....#.....####..
.#.##.##.###..#...#.#.#.#.#.......#.####.#####..####.#....##.#...##.##.#.#.##.#..#.###.##..###...#.#
#.###.#.##.#.........#..#.#.#.#..##.#..##.#####.###.#.#..#.#.#..##..###..#.##.####.#..#...###.....##
##..#####.#...#.....###.#.#...##.####..#..###....##...#.##.##.##...#.###..#.##...........###.####.##
.###....###.#..#.#..#..#.###..########..##......########.#..#######...#........#.#######..####..#..#
####......#...#..#...#.######..#.##.#.##....#.##.#.#.##.#....##...###..##....#.#.##.##.....###.#.##.
.#.####.##..##.#.#.#.##.###.##....#..#...#.###.#.#...#.....##..##.####....#..######.#.#.#.##...#...#
...#.##...##..##.###..###....#..##.....#####.#.#..#.....##..##.###..##..##.##.....#.#..##.#..###..#.
..##....####...##.....###.#...#.###...##.#.#..##.###....###.##........#.#..#..##..#.######..##......
###.##.##.#...##.#...###.##.##.######.###.###..###.#....#.#....#.#.#...###..###.#.#...######.#...###
..#.####.########.####.#.#...#..##...##...###..####.###..##..#.##..###..#.####.###..#.#.#.#######..#
###..#.##.##.#..#..#.#..#.###...#...#.##.#####.#.###.#.###.#.##..#...#.#...##...###.....#..###....##
..####.#....####..#.##.....#..#.#.###.###.#.#......#.....####.......##.#.######..####..#######.#..##
.##.#.#..#..###....#....#...##.##.###..##.##...#.######......##....##..#.#.#..##..#####....#.#...#..
##...##..#...#.#######..#.....#..##.....#####..#...##.###.####.###..###...#..###........###.##.#.###
...###.#....#...##.....##.####..##.##.#.#..##.######.#..###.##.....##.####..#..##.###.##..###.###..#
#.#...##....#....#.##....##...##..#.#...######..###.#.#..#.#.###.#####.#..###....#.##...####..####..
#....###.###.#...########.##.##.######.##....#...##.#.#.#..#.##.#.....#..#.....#..........#.##..#...
.#.#.#.#.##.##.###...#.#.#...##...#.##.##..#..#...##...##..#.##.#.##....#.###....####..#..###.#..###
...#.#..##.#..##.#.##.####.#.#...###...#.#.###..########.#...###...###..#..#.###..####..##.#..#...#.
##.#...#######.....#.###..#.#..####.##..##.#..##...#.##..##.#####......######.#.#.##.#..####..#.####
#.......#.#########...#...#####...##.###.#..##..##..#...##..##.#.#.###.#.##..#...#....##..#.#.#...#.
###..###..#...##.#...####.###..##.###..##..##.##.....#.#.#.####.######........#...#####.....#..#####
##.#.#.########..#.#.##.#####..##.###...#...#.#.##...###.#.###..#..##.#......#.#.#.##.#.#.#....###.#
#.##.#..#...##..###..##..#..##..##.###...#.##.##.#.#..........##...##.##..##..#....##.#####..##..#..
.#...##.##.#..#.##....#..##.##...#...####.###..##...#...#.##...######.#.##.#.#.##.####.##..#.###.###
##.#.#..#.#.###.#..#.##.#....#....####..#.#..##.#######..##..#...#..####.#####....#.####.#..#.#.###.
....##.##..#.#####.###.#.###.#.#.#.#..#.###.#..######....##.##.....#.#.#...###..###..#..###....##.##
#.#######.#..#.#.##.##...#.#..###.##.##..#..###...#.#...#..##.##..##.#.#.##.##.#######.#..#.#..#.#.#
###.....#####..####..#...#..##.#....##.##...##...##..###...#..##..##..####.#.....##.####..#...##....
####..##..##.#...#.###.##...###.#..#...##.##.#...#.##....####.#.#..#...##..##.##..###.......#..#..#.
#.#.#####..#....#.#...#..##.##..##..#.####..###.####.####.#####.#.#..###.##....#....#.#.###.#.#..##.
...##...#.#.#####.#.#....##.##..#...##...........#.#....#.##.##.....##..###...#.#####..........##.##
.#..#..#.#...#.........####....##........##...#...#######.####.###.###...#....###..#.###.##.#.####.#
..#.#.....#...###.####......###.#..#.#.#.#...####...#####.#..#....#.#.#....#.##.###....#..#....##.##
##.#...##....###.#......####.#.####.##...#..#.#.#.#...#####.#..#..##.#.#...#.####....###.####.#.#.##
.#.#..#....#.####.#..#.###..#.#.#.#.#.###...#.##.##.#.##...####..######....####...##.##.#..##.#.#..#
..##.#...##.####..#.###..##..#.###.#.##..##.###.#.#####..#.##.#.....#.#####.####..#.#.######.#.##.#.
#.....##..###..###.....###.##.###.#..##.#..##.###....#..#.#.##....#.##.##.#...###.###.#......#..#...
.##.#..#...#...#.#..##.....#..#.###....###..#.##...#.##.#.##..##......#.#.#.####.#..#..##...##..##.#
####...##...#......##.##..#######....###.##.#.###.#.#.###...####..#..#.#.##.........#.##.#....#####.
.####.#####..##..###..#.##.##.####.......#.###.#####.#..#...#..#..####.#.....#.####.#.....###...####
#.##......#.#.#.##....#.#.##..#...#.#.#..#...##..#.##.##..#..#####..###.##.#...##...#..#...##.##..#.
.##.#.#.###..###.##....#...###...####...####..##.###.####.###.#..#.###.#..#.....#.##.#..#.##.#.#.#.#
...#.###.#..#..#.###.#....##..##.#..###.######.#...##..#.#...###.....#.###.#.#....##...##.###.#.####
.#..#..#....###..##..#....##.##..####.#.#.#..#.######....####.##.##....##.#.#.####.#..#.##.##....#..
#..##.#...#.###..#.###..###..#.##.#.######.#.#.####....###.##....#.##.#......##.##...##....#.#.###.#
#...##.#.####...#######..#....##.#...##..#.#....#.#.#####.####.##...#.###.##.#.#.##...##.#....##..##
....#.##.#.##.##.#.#..###...##.#.#.#....#...#..........###.#####.##...##..#..#.##.#...#..###..#####.
###..###.##..#.###.#.#.#...##.#.###.##.###...##.###.....####.#...##.#.#.#..#.##...#.....#..#.#.#...#
####...#.####.#.#.#..#.##.##.##.#.#.####...#...#.#..###....##.##..##.###...##.#...#####.###.#..#....
##..##...###..###.#.###.##.####.#..#.#..####.##.#...#..#..#.....##.#.#####...##.....#.#.#..#..##..#.
.....#......#..##..#...#.#.#.######....###.##.##..#.###...#...#.####.##.##.###.#.######.#..#.#.##...
#.#.#.###........#..#.#.#.#....##..##..###...##.#.##.#..#######.#..###.###.#.###.###.#.#.#.....##..#
#.##....####.......#..##.####.#.##..###.##.###.#.#.###...###.....######...######.#.....###.##.......
#.##..#...#..#..#....#.##...#..#.###...#...#########.#.#...#.....#...#..#.#...#.#.#...#.###.####..##
.#..##........###.#.#....#.......##.#..#.#.#.##.......#.#.#.#..#.#.....#....#.###.#.##...###.....#..
.#.#...##...#....#.##..##.#...#.##..#..##.#..###.#####..##.#.##.####.####.###...##....##......###..#
#..##....##.###.##.....#.#.....#.#...#..##....##.###.#....###.....######.#.##.###..#..#.#...#.....#.
....#.####.....#..#..#...#.###.#####..##...#.#..###.#...#...##.###.##..#.######..####.#.#....#.#..##
##.#..##.#.#.##..##..#...###..##.##..#.###..#...###..##.#.###.####...#..#.#######.##.###.###.#.#..#.
...##...##.#.#.##.#.##.###..##...##.#..#..##.##.##.##.#.####..##.######....#..#.#.#....###.#.##.#.#.
.#.....#.###...##.#.##.#..###.##..####.###..#.#.....#..##.#.#..##...##.#..#.##..#########..#.#.##.#.
####.#..#.#..##...#..#.##..#..#...#.###.....#..##...#..####....#######.....#.##.##..##...#.##..####.
########...#.#.####..####.#.#.#..##.#.#.##...#...#..#...#..###.#.#..##..#####.#.#.#.##.#.###...#.##.
.#....#..######.#.#.#..##.#.#...#####....##..##.##.#####....#.##..#..#.#.#.###..#.####.###.........#
...####..##......###..#..###..#.#.###.#...#..####.#.#..###....#..##.####.#..#.....#.........##..###.
.####...##...#####.##.##...##...##..##...#.#####...#...##...#.####..####.###.....##.##...##.#######.
##..####....#.#..#.#....##..#####....#.#...#.####..#######..##.#####.#.#.#.##.#.#..#...#.###.##.#.##
#.####....#..##########...###.#..#####.#.#.##....#..#....######.....#...#.##.##.#.##..#.###..###..#.
##.#.##.###..#.###.....##..#.###.#....#####.###...#.#.##.#..#.###.#.#.#####.#.##.##.##.#.#.###.###..
.###.#.#.##.######.#.#..##.#..####..#....##......#...##.##.#.......#.#.#.####.#.#.##....##.####..#.#
####..#...##....#.#.#....#.#####...#..#....##..#..####...#..###...........####.###.###......#..##..#
..##.####.##....####....#.#.####..#...###.#....#.##.###.#.##..####.#..###..#...#..#####..#...##...#.
...#..#....#.#..##.#.####....#..####...##.#..#####.###..#.##..###.######...#...#...######.##....##..
..#########.#####.#####.###.##.#.###.###..#.#.#.#.###.#...###........####..#####.#.##.##.#..#..#.##.
#..###.##.###.#...#.#.#.##.###........#.#.#.#..#..##.##.#.....#.#.....##...#..#.##..#..#..#......#.#
...##..#...##.....##...####.....#.##..###.....#..#.###.#..#.#...#..#.#.....###.###.##.#.#.#..#.#....
#...#...#.#.#...#####.####..#....##...##.##.##.#...#.#.#..#...##....#...###.#.##.##....########..#..
.#.####....#.#.....########.#....######.#.#######...##..#.###.#.###..###.#..###....#.#.###.....###.#
..#.##.##....#..#...#..#.#.#...###...#..#.#.#.####.#.#####.####....##..#..###.#.#..####....##.####..

58
20.jl Normal file
View File

@ -0,0 +1,58 @@
include("utils.jl")
function convert_to_binary(string)
map(x->x=='#' ? 1 : 0, collect(string))
end
function parse_input(filename, iterations)
lines = collect(non_empty_lines(filename))
algorithm = convert_to_binary(lines[1])
dim = length(lines[2])
buffered_dim = 2 * iterations + dim
fix_lines = fill(fill(0, buffered_dim), iterations)
i = [fix_lines;
map(convert_to_binary, map(x-> reduce(*, fill(".", iterations)) * x * reduce(*, fill(".", iterations)), lines[2:length(lines)]));
fix_lines]
image = transpose(reshape(reduce(vcat, i), buffered_dim, buffered_dim))
algorithm, image
end
function getv(algorithm, image, i, x, y)
address = []
for ox in (x-1):(x+1)
for oy in (y-1):(y+1)
if ox < 1 || ox > size(image)[1] || oy < 1 || oy > size(image)[1]
# example
# push!(address, "0")
# real
push!(address, i % 2 == 1 ? "0" : "1")
else
push!(address, string(image[ox,oy]))
end
end
end
algorithm[parse(Int, reduce(*, address), base=2)+1]
end
function enhance(fname, iterations)
algorithm, image = parse_input(fname, iterations)
for i in 1:iterations
new = copy(image)
for x in 1:size(image)[1]
for y in 1:size(image)[1]
new[x, y] = getv(algorithm, image, i, x, y)
end
end
image = new
end
length(filter(==(1), image))
end
function solution20_1()
enhance("20.data", 50)
end
solution20_1()

7
20_ex.data Normal file
View File

@ -0,0 +1,7 @@
..#.#..#####.#.#.#.###.##.....###.##.#..###.####..#####..#....#..#..##..###..######.###...####..#..#####..##..#.#####...##.#.#..#.##..#.#......#.###.######.###.####...#.##.##..#..#..#####.....#.#....###..#.##......#.....#..#..#..##..#...##.######.####.####.#.#...#.......#..#.#.#...####.##.#......#..#...##.#.##..#...##.#.##..###.#......#.#.......#.#.#.####.###.##...#.....####.#..#..#.##.#....##..#.####....##...##..#...#......#.#.......#.......##..####..#...#.#.#...##..#.#..###..#####........#..####......#..#
#..#.
#....
##..#
..#..
..###

70
21.jl Normal file
View File

@ -0,0 +1,70 @@
function make_dice(max_value)
next = max_value - 1
r = 0
function roll()
r += 1
next += 1
next %= max_value
return next + 1
end
function rolls()
r
end
roll, rolls
end
function advance(pos, dice)
pos += dice()+dice()+dice()
((pos - 1) % 10) + 1
end
function solution21_1()
pos_a = 8
pos_b = 5
dice, times = make_dice(100)
score_a = 0
score_b = 0
while true
pos_a = advance(pos_a, dice)
score_a += pos_a
println("a -> $pos_a ($score_a)")
if score_a >= 1000
r = times()
println("$score_b $r $(score_b * r)")
break
end
pos_b = advance(pos_b, dice)
score_b += pos_b
println("b -> $pos_b ($score_b)")
if score_b >= 1000
r = times()
println("$score_a $r $(score_a * r)")
break
end
end
end
using Pkg
Pkg.add("Memoize")
using Memoize
DICE = [(a,b,c) for a in 1:3 for b in 1:3 for c in 1:3]
@memoize function round(pa, pb, sa, sb)
sum(map(DICE) do dice
npa = pa + sum(dice)
npa = ((npa - 1) % 10) + 1
nsa = sa + npa
if nsa >= 21
[1, 0]
else
circshift(round(pb, npa, sb, nsa), 1)
end
end)
end
function solution21_2()
round(8, 5, 0, 0)
end
solution21_2()

420
22.data Normal file
View File

@ -0,0 +1,420 @@
on x=-9..45,y=-15..37,z=-2..46
on x=-48..2,y=-11..37,z=3..48
on x=-47..4,y=-47..-3,z=-12..34
on x=-24..29,y=-12..40,z=-20..29
on x=-48..3,y=-38..16,z=-22..31
on x=-35..13,y=-10..43,z=-11..42
on x=-4..47,y=1..47,z=-26..18
on x=-49..1,y=-29..22,z=-44..2
on x=-12..33,y=-14..38,z=-9..35
on x=-44..8,y=0..46,z=-28..20
off x=-44..-31,y=-37..-21,z=35..49
on x=-2..42,y=-49..-4,z=-10..39
off x=-26..-17,y=-38..-29,z=-32..-18
on x=-41..10,y=-1..49,z=-22..24
off x=-49..-35,y=-26..-15,z=11..24
on x=-5..47,y=-34..10,z=-3..42
off x=-16..-7,y=-9..0,z=-4..12
on x=-45..1,y=-25..22,z=-2..49
off x=21..40,y=30..44,z=-16..1
on x=-11..37,y=-44..1,z=-20..25
on x=7379..15679,y=62885..66145,z=40785..66699
on x=55922..93809,y=1651..21593,z=-29830..-6845
on x=-31566..-20771,y=49570..87512,z=-38744..-20396
on x=4993..41166,y=-27079..-6497,z=-88189..-66473
on x=60741..69319,y=-13925..8370,z=-62720..-33863
on x=34284..42689,y=-71439..-58324,z=22610..47957
on x=8592..42171,y=-65708..-43885,z=-61206..-46568
on x=64371..79931,y=28477..37185,z=13392..20753
on x=-59117..-37612,y=-64167..-37759,z=35921..54572
on x=-14064..20202,y=-90417..-70077,z=25371..40391
on x=-67395..-41025,y=17787..31773,z=-57128..-48199
on x=-70962..-46942,y=19586..45376,z=-54426..-31169
on x=31777..46666,y=-28152..-20207,z=-66876..-55373
on x=13530..27088,y=-90327..-70591,z=-1912..25782
on x=40408..67678,y=38887..66828,z=-30776..-13301
on x=-29414..-16610,y=56466..86239,z=20871..32428
on x=-76113..-67766,y=37613..40645,z=-16702..13708
on x=-53053..-28552,y=57577..78562,z=14326..42575
on x=-58889..-42881,y=16768..21306,z=42955..76041
on x=-73073..-51398,y=46632..48316,z=20149..34615
on x=-66303..-54970,y=-61600..-49802,z=-11768..9094
on x=-53654..-27948,y=9591..45638,z=-71810..-58350
on x=-69622..-52612,y=-45011..-38959,z=24484..44518
on x=3515..15378,y=41121..59682,z=-61133..-55743
on x=-90134..-62577,y=208..23739,z=26851..46343
on x=65530..81406,y=42070..52596,z=-11235..13125
on x=64169..84257,y=-10178..17467,z=-29044..-16366
on x=17446..26654,y=-66194..-47798,z=-42530..-24698
on x=-58456..-32175,y=-57823..-50339,z=35867..54337
on x=47156..63257,y=-36128..-21908,z=33134..41699
on x=-48529..-31263,y=-62437..-39211,z=-56496..-37240
on x=-34149..-14003,y=-79123..-45929,z=-55215..-40418
on x=-84191..-64387,y=-11156..17366,z=31098..34346
on x=-82865..-68797,y=-5798..8421,z=28104..58202
on x=29311..45767,y=-88790..-62482,z=-29612..-214
on x=8842..27908,y=68184..82736,z=-55247..-19216
on x=-42756..-14515,y=74498..84491,z=-20007..4343
on x=-37638..-28150,y=-72221..-45636,z=49412..60164
on x=32841..44894,y=-62963..-55317,z=-44129..-18308
on x=41325..48341,y=14656..22614,z=-63334..-57171
on x=39491..70558,y=48229..67699,z=14708..39318
on x=-16935..-15423,y=72793..82573,z=-9454..8508
on x=28720..40689,y=29779..36750,z=-74342..-54201
on x=65984..88372,y=-3884..15208,z=19130..38834
on x=-85972..-61107,y=-27882..-5274,z=-23592..-4731
on x=-65737..-48051,y=-4370..32823,z=-51562..-27039
on x=53568..75174,y=13164..34585,z=-62900..-49637
on x=43348..67279,y=37890..47849,z=6060..34285
on x=-88633..-60579,y=-40956..-20401,z=-20101..8972
on x=-70097..-44904,y=37603..69889,z=-21021..-5234
on x=-76016..-71353,y=10592..39343,z=5961..25639
on x=26814..51079,y=-76683..-51852,z=-32221..-7926
on x=78022..90710,y=-6329..7380,z=-30398..3225
on x=-81947..-59036,y=6212..27865,z=-30191..-23650
on x=-14260..5518,y=-59292..-33347,z=-80781..-44527
on x=61127..77249,y=-44821..-16717,z=-15659..9963
on x=7812..29885,y=46232..56927,z=56252..66587
on x=-70864..-55068,y=36351..66673,z=2115..29365
on x=-21385..-5787,y=-24942..-1426,z=62656..77888
on x=21748..31508,y=44194..75368,z=42392..61013
on x=-30140..-13716,y=60038..82957,z=-55563..-22103
on x=15892..46641,y=28104..45417,z=-69780..-49812
on x=-35304..-14704,y=-69612..-54212,z=-64119..-43604
on x=-75511..-53167,y=-16408..-5573,z=-34276..-13669
on x=-49880..-26128,y=-78019..-53301,z=563..27150
on x=-3710..31007,y=635..31231,z=-89739..-67701
on x=16417..27647,y=59484..83416,z=-38071..-8125
on x=-55486..-36218,y=-18343..-1162,z=48973..70778
on x=6364..25168,y=-73763..-55266,z=-47439..-20212
on x=-77074..-63388,y=13325..37503,z=26475..47125
on x=47836..63427,y=-22005..-1081,z=-56895..-36496
on x=52594..78952,y=1602..34837,z=-55674..-29580
on x=9195..36803,y=-42634..-16959,z=49912..77645
on x=-43313..-9809,y=-61189..-27305,z=-73518..-57945
on x=-15098..-247,y=-84505..-61173,z=-6903..10359
on x=-14761..20062,y=42726..66812,z=-67450..-36194
on x=-6269..13514,y=27764..51152,z=-65770..-56309
on x=-11702..12085,y=4154..19444,z=74342..85810
on x=20250..40759,y=-12245..12965,z=-85663..-56952
on x=14397..31766,y=-77031..-60677,z=-13856..14510
on x=-57268..-50706,y=-61409..-55384,z=-8347..2644
on x=27634..48898,y=66690..87119,z=-27363..-7996
on x=11697..40665,y=-92019..-67357,z=-28564..-4579
on x=-23635..-7962,y=23732..32687,z=-83083..-62791
on x=40495..46668,y=-62018..-49602,z=-65022..-33630
on x=13198..30010,y=-82290..-65531,z=-17978..9547
on x=12582..25248,y=-22745..3631,z=70846..86218
on x=-26583..-5966,y=41977..55683,z=36463..75892
on x=-65277..-49356,y=37876..57024,z=-52763..-45440
on x=-64608..-41498,y=-8129..16874,z=50097..71345
on x=42175..49606,y=-70140..-50383,z=35730..40798
on x=54705..58189,y=-56152..-49341,z=-400..24932
on x=68337..79185,y=-25307..-6874,z=-3313..19891
on x=5018..29619,y=62462..81105,z=18248..30135
on x=-76041..-38663,y=38551..70709,z=-12671..23088
on x=-72729..-54213,y=-6076..24031,z=-57821..-37810
on x=43326..72010,y=20000..41816,z=51160..69275
on x=1558..30222,y=-73358..-70358,z=16312..51532
on x=-35043..-18417,y=-44261..-25881,z=-78549..-52077
on x=28098..46713,y=18474..22660,z=-78742..-54633
on x=-14412..8266,y=70802..80415,z=-14992..9258
on x=-26641..-7645,y=60425..75589,z=-43589..-23911
on x=-25876..-19902,y=53219..77507,z=-48144..-17584
on x=-43367..-22330,y=68271..77937,z=9057..20584
on x=-17237..2381,y=3583..28698,z=-94572..-73051
on x=-6829..3379,y=65792..90689,z=-5002..16981
on x=-54132..-45538,y=-78237..-50736,z=-11644..8605
on x=-59532..-53419,y=34745..56394,z=30582..53444
on x=-20732..5101,y=-77256..-61756,z=30478..35782
on x=14347..38867,y=9283..24381,z=-87398..-53279
on x=36595..57756,y=38640..51025,z=-58273..-44565
on x=-54582..-27927,y=-78804..-46081,z=13910..33182
on x=16349..35830,y=71332..87852,z=8157..16797
on x=-43956..-33473,y=33808..56755,z=42846..61246
on x=11314..13439,y=-38033..-17400,z=-76284..-68981
on x=46492..76990,y=8474..15734,z=-55742..-41584
on x=27131..36354,y=-29792..-5590,z=-74708..-55530
on x=52353..74451,y=33392..55689,z=19093..30505
on x=10590..26407,y=26646..44875,z=53669..85124
on x=10328..23456,y=52345..77588,z=31705..56684
on x=-46182..-26197,y=20916..52128,z=-61613..-51850
on x=-5902..15644,y=7302..32746,z=-89842..-71630
on x=-13813..21172,y=-87032..-70414,z=-36..11650
on x=-43300..-20544,y=-39391..-20796,z=-78685..-54411
on x=53826..59621,y=-22659..6182,z=34874..57854
on x=56180..78116,y=-17473..-11209,z=33329..48534
on x=-27987..-9324,y=45080..55335,z=48847..80731
on x=71719..89566,y=-25531..-10083,z=-22109..-12785
on x=-29430..-21311,y=-89432..-55080,z=14731..25873
on x=32126..44985,y=48444..71257,z=16998..38903
on x=24388..50981,y=-66328..-57172,z=-52521..-27884
on x=30463..45384,y=-7855..28748,z=-86869..-55644
on x=-67671..-45297,y=-29469..-5222,z=44296..53119
on x=35058..42106,y=-69099..-47111,z=40655..63310
on x=33046..64904,y=-70169..-43042,z=13896..36888
on x=-22322..-13112,y=-25157..-2838,z=-93853..-69670
on x=73781..84202,y=-1016..31182,z=9547..30589
on x=-72865..-63710,y=-50800..-28031,z=-15998..20829
on x=6767..15631,y=-17255..-11461,z=-97425..-59135
on x=25319..31792,y=-93050..-64825,z=8041..20183
on x=-70089..-30927,y=36115..69616,z=-39401..-14311
on x=62942..69074,y=-22392..-1078,z=-66440..-27451
on x=-13913..4148,y=-75097..-42466,z=35698..57507
on x=-85917..-59242,y=-11125..2601,z=19575..55603
on x=15134..42927,y=-79064..-64982,z=-1971..24343
on x=39880..58909,y=56469..72390,z=-1437..26115
on x=-21090..-12306,y=-94355..-77198,z=-29560..52
on x=-28671..-8856,y=45669..64627,z=31384..51891
on x=-75912..-56733,y=-23901..1139,z=28555..57092
on x=-47744..-10650,y=71138..83710,z=4554..27540
on x=25710..42555,y=-33622..-14274,z=52056..65528
on x=-76115..-63779,y=-29627..-15804,z=-1106..16981
on x=14189..34263,y=-62546..-38815,z=42727..81264
on x=7852..41042,y=31315..42334,z=55681..71183
on x=-88315..-67768,y=-8097..8232,z=22878..36892
on x=-75367..-48994,y=-65971..-49798,z=-331..14292
on x=-25718..1445,y=-80169..-61373,z=-57242..-32282
on x=-13075..7644,y=-14640..-3379,z=75167..96592
on x=35741..67984,y=-60591..-37834,z=-42879..-23133
on x=-26071..-15399,y=-54535..-33151,z=64373..77023
on x=70725..90684,y=8312..29942,z=-28004..2695
on x=54936..67698,y=10377..30841,z=-45783..-36371
on x=-2020..25407,y=-78434..-50839,z=-48610..-39223
on x=-45717..-43647,y=48801..70774,z=31062..45511
on x=34206..54314,y=-70584..-47392,z=-45786..-24983
on x=-49858..-27145,y=-8313..12257,z=-80733..-65761
on x=19194..48953,y=-76824..-50937,z=-38483..-20184
on x=-11056..8975,y=60011..77711,z=-47016..-22798
on x=23444..61412,y=-8792..27162,z=54757..77897
on x=-75528..-48686,y=-2534..13417,z=-72418..-47078
on x=21664..55288,y=9053..15264,z=54771..84777
on x=45230..57868,y=-35816..-19600,z=-70489..-40910
on x=30646..56513,y=-73290..-51396,z=-48109..-23594
on x=-19927..8133,y=20111..22064,z=-78790..-65966
on x=-73214..-50284,y=-42781..-29543,z=-52080..-40858
on x=59641..92804,y=-14320..9890,z=10580..32686
on x=6948..24112,y=59008..83939,z=9209..29435
on x=20747..42638,y=54010..87392,z=-10349..6792
on x=-82467..-56030,y=-63078..-36419,z=-18052..-7281
on x=43143..53517,y=-42852..-33677,z=-75322..-38352
on x=34903..68087,y=-53600..-43300,z=19263..37332
on x=-75090..-51229,y=39553..54421,z=-29984..-11983
on x=31297..41923,y=40810..55544,z=41336..65242
on x=48907..76926,y=44120..55019,z=19408..32113
on x=-28350..-11619,y=-96073..-68302,z=7131..23826
on x=-71444..-52453,y=-46437..-37331,z=-23610..-7727
on x=-90114..-62112,y=-11142..11966,z=10310..30329
on x=-8298..10663,y=-89901..-65346,z=26819..55136
on x=-83214..-52210,y=-28546..-6449,z=26105..44117
on x=-48292..-15887,y=-32421..-24179,z=-72733..-50252
on x=2675..6592,y=57643..77972,z=-45680..-31319
on x=-27301..-19021,y=52139..65771,z=40324..62506
on x=-15122..12261,y=76124..83252,z=-6966..26871
on x=-28135..-5592,y=42253..66391,z=61120..81631
on x=41458..59123,y=-65686..-28325,z=18007..42560
on x=-7254..2575,y=-37975..-25118,z=-83436..-55842
on x=-69756..-51850,y=-14700..11743,z=-64913..-57730
on x=46050..60943,y=29947..49852,z=-29174..-16871
on x=-24798..-1730,y=72778..96749,z=7809..19201
on x=-23651..-9598,y=-57234..-34582,z=-70338..-60811
off x=-62738..-27200,y=9928..29860,z=-82061..-55735
off x=-35621..-8459,y=71584..77639,z=-24783..543
on x=5884..24918,y=4508..27365,z=-79957..-56399
off x=50195..64289,y=48376..65137,z=-21184..896
off x=24188..59760,y=-44337..-27583,z=42362..66284
off x=-57347..-28736,y=-60601..-44136,z=-63070..-43716
off x=48377..66842,y=5381..28487,z=-56713..-36405
off x=-30632..-10325,y=-68112..-57776,z=-70249..-44986
on x=-27258..-24687,y=-27831..179,z=67481..80119
off x=25197..36490,y=58147..79063,z=-55819..-29388
on x=-42369..-14014,y=35824..40212,z=49626..67639
on x=72482..78811,y=2743..24960,z=-21034..9641
on x=-38737..-16444,y=-19459..-7136,z=70522..89734
off x=-47053..-18446,y=-49781..-27644,z=-63382..-45445
on x=-61779..-53562,y=-68401..-43173,z=-26499..2615
on x=70280..90492,y=-22017..-1048,z=-11788..9915
on x=16973..40998,y=55375..78623,z=5729..32627
on x=6679..29613,y=46958..81428,z=27700..55392
off x=-54278..-31989,y=37760..65264,z=47082..48144
on x=-24395..-1817,y=-3077..6849,z=62195..88101
off x=32931..47933,y=-80935..-47905,z=12414..35416
on x=-4833..29094,y=-74517..-46510,z=-50662..-36261
off x=17745..39300,y=-77063..-52076,z=14430..34896
on x=-4254..2793,y=-27799..-2199,z=61332..85652
on x=-11125..-6797,y=-67626..-59797,z=45783..53770
on x=-51997..-22683,y=-75871..-59016,z=-35612..-29371
off x=-53070..-30804,y=-37612..-16817,z=-61098..-33579
on x=-52249..-27676,y=65019..73794,z=8944..31489
on x=54561..70311,y=8710..27762,z=-60193..-29447
on x=-79526..-54134,y=-48561..-39181,z=12782..46387
off x=19885..33599,y=62071..83093,z=-50279..-13755
on x=23245..46830,y=20494..44306,z=-73620..-54933
on x=-79449..-67759,y=-24475..-10791,z=5687..32934
off x=-30071..-21031,y=54871..72346,z=32042..55267
off x=-30238..-2898,y=-77564..-51143,z=35341..64987
off x=54103..57884,y=36694..60345,z=-45985..-16112
on x=52740..71478,y=15648..46995,z=9255..41940
off x=47709..56624,y=42824..76404,z=-16692..-4361
off x=-79808..-65764,y=11636..14621,z=6874..40024
off x=-53031..-20679,y=-63906..-40440,z=24661..46608
off x=21238..38683,y=-78416..-46878,z=-47880..-35504
on x=-53581..-36276,y=-1941..20566,z=-71887..-54358
off x=-32154..-11432,y=-79738..-67958,z=-10706..17360
off x=10696..21438,y=-53803..-22129,z=-87224..-56070
off x=28285..52461,y=-49037..-26856,z=36499..53886
on x=-260..5955,y=24586..37153,z=-83960..-67924
off x=-50570..-23890,y=-75797..-57497,z=-41895..-29533
off x=-4478..14154,y=25690..41167,z=-78169..-65042
off x=53823..62681,y=-65274..-48164,z=11640..36739
off x=7445..17160,y=3112..20438,z=-79277..-66317
off x=-72283..-62851,y=-18551..17812,z=26518..45970
off x=-59435..-35677,y=-61145..-49053,z=-28620..-19260
on x=52909..71776,y=-35904..-8679,z=-45640..-18257
on x=-28198..-10547,y=47520..75387,z=-56238..-36602
on x=-78021..-57108,y=-202..20511,z=22910..26211
on x=6366..17660,y=-81206..-59720,z=-20739..4299
off x=62320..70434,y=-46472..-33338,z=24434..41197
on x=65053..71471,y=16283..27975,z=-53360..-32879
on x=25858..60433,y=-26017..-21914,z=48513..63801
off x=-79152..-68671,y=22088..30479,z=-22648..-10494
off x=67085..79404,y=-9147..17587,z=-34597..-22908
on x=-25433..-14453,y=-65170..-45979,z=46473..59725
on x=-85030..-67943,y=-43295..-20298,z=-28190..-8337
off x=14793..29071,y=51299..70682,z=-63333..-48581
on x=-22738..-3843,y=62665..91255,z=-40441..-6764
off x=-69466..-51782,y=-28726..-4741,z=51052..65722
off x=-37894..-19524,y=-83016..-54967,z=-15269..4234
off x=-51737..-36058,y=49755..52567,z=40935..52695
on x=5160..16270,y=-63557..-29172,z=-66325..-60455
on x=-12754..14999,y=42410..57660,z=-81237..-44235
off x=-21896..-1639,y=-6683..12111,z=-86947..-66486
on x=17671..34865,y=25801..50054,z=-69110..-52941
off x=53780..79949,y=-19080..-1582,z=-51267..-26442
on x=11705..31955,y=-18273..10873,z=-79513..-72321
off x=42225..64739,y=-63751..-38399,z=-21976..3241
on x=-83556..-68733,y=-27434..-7743,z=-13017..9177
on x=56237..76149,y=-34497..-16008,z=-39077..-19458
on x=-43305..-25014,y=-73343..-49996,z=-7825..-3892
on x=-64308..-43967,y=-33788..-28512,z=52866..68806
on x=-70700..-50756,y=31972..50876,z=-38908..-15838
off x=-57164..-42932,y=19342..48612,z=33732..55624
on x=-36748..-10589,y=51955..83318,z=-48442..-26669
on x=25359..40927,y=-79085..-59846,z=8036..36888
off x=10380..14539,y=71572..87896,z=-24628..-4781
off x=-47176..-28461,y=65456..67163,z=-40894..-16836
off x=-18332..8399,y=47821..71986,z=26668..47522
on x=-20965..-9481,y=-20308..4897,z=-95419..-57801
off x=31539..51751,y=35462..53163,z=-57494..-42838
off x=-18472..1572,y=75988..93471,z=-26864..1039
on x=-70785..-33731,y=-73997..-43660,z=-23224..9946
on x=19380..37078,y=53776..78064,z=-31936..-10509
on x=-8062..-2825,y=-82342..-69826,z=-13266..3969
off x=10179..29342,y=31007..48598,z=64959..69127
off x=-60805..-32266,y=43431..69404,z=8577..28595
off x=-22720..-3203,y=60404..66611,z=34857..59638
off x=-53582..-38618,y=52017..73240,z=27473..42769
off x=-72814..-66689,y=-45388..-21812,z=-14516..3856
on x=-73641..-69708,y=-15500..7339,z=-39764..-29382
off x=-4677..17044,y=-91970..-68336,z=-5685..15742
on x=11739..24073,y=35242..45244,z=-80024..-60736
on x=64670..76998,y=26199..39053,z=-15372..11264
on x=32930..62408,y=7820..14870,z=-84786..-50274
off x=1793..28795,y=19984..43135,z=67050..87662
on x=62730..81556,y=-59681..-32462,z=-9119..17314
off x=51211..84860,y=-10649..27833,z=33629..61327
on x=4877..24218,y=58754..64225,z=-51294..-29252
on x=-34998..-23262,y=-7791..15688,z=-77251..-73653
on x=-8985..2565,y=-80674..-57237,z=31372..66054
on x=26910..46858,y=-70174..-50719,z=-39433..-6303
on x=-77313..-45494,y=-35534..-19783,z=-56939..-23493
off x=-86093..-58555,y=-10764..-7163,z=32984..39939
off x=22629..45516,y=56413..69690,z=23879..45264
off x=6426..22257,y=-81295..-58682,z=-4833..30396
on x=-20499..-623,y=68725..85089,z=-3165..16088
on x=-22113..-8769,y=50723..69731,z=35423..63761
off x=17927..28889,y=66820..87168,z=7146..17344
on x=-51150..-32434,y=4434..29601,z=-87179..-50635
on x=44312..65806,y=-17376..-4824,z=-60807..-46664
off x=-74021..-63274,y=18155..23737,z=23087..44175
on x=53142..78645,y=11091..24149,z=-33898..-15733
on x=-89734..-59095,y=5415..39645,z=-30819..-14415
off x=-3526..9687,y=44579..60215,z=-61672..-41733
off x=73321..97678,y=7224..33092,z=-23526..-6480
on x=-38319..-18652,y=-94091..-57143,z=-27008..-10399
off x=-39624..-25656,y=-27151..-17149,z=62826..73496
off x=11777..31489,y=27498..41343,z=-66823..-64400
off x=-86379..-57406,y=1305..22612,z=-19292..-12364
off x=46778..72347,y=-30615..-14497,z=-57631..-38999
off x=11620..35158,y=60858..89766,z=3059..17854
off x=12508..29190,y=-69508..-58455,z=23048..41891
on x=-18252..13098,y=36042..44460,z=50978..82816
on x=-6496..13599,y=-32852..-21957,z=70926..82031
on x=69343..93866,y=-13495..12902,z=20150..37520
on x=14399..46141,y=-16440..-4786,z=64520..82073
on x=34907..49197,y=-77417..-58364,z=7116..41283
off x=-964..13645,y=-84374..-61091,z=5528..26680
on x=17413..51768,y=18101..39773,z=59112..72097
on x=-66173..-34985,y=-64364..-26681,z=-46312..-32514
on x=4907..25817,y=-86293..-63574,z=20626..51969
off x=25870..59523,y=34211..49946,z=40232..74133
off x=-54230..-38453,y=30481..43869,z=-54591..-40302
on x=-19584..11278,y=-61815..-44911,z=-59169..-54278
off x=9524..37706,y=69604..90591,z=2047..19112
off x=-55707..-36536,y=32805..48941,z=-69826..-44814
off x=-47397..-26251,y=-45541..-17561,z=51498..63966
on x=-26274..-8974,y=-11082..14341,z=-95770..-63704
on x=63227..82757,y=-53349..-33869,z=6276..38367
off x=-9009..17116,y=-1685..15956,z=-89391..-75291
off x=-60467..-32934,y=-16532..8638,z=66520..73970
on x=42282..63814,y=-52404..-29292,z=16300..39083
on x=59807..76726,y=-59577..-30112,z=-6617..22740
off x=-71581..-61332,y=-11793..7729,z=28377..51215
off x=58949..86888,y=-38405..-857,z=-27434..-1959
on x=-38039..-18664,y=-52842..-30904,z=-69197..-39328
on x=34271..60705,y=-13427..9155,z=-86631..-62294
on x=-47181..-37507,y=52951..66180,z=31932..41322
on x=50153..80932,y=-4041..16916,z=32832..52829
on x=-5561..25588,y=-10476..10520,z=78611..97383
off x=-83214..-60530,y=-3562..17310,z=7405..28737
on x=-60777..-54134,y=54086..73346,z=-11397..12806
on x=8008..14420,y=-63596..-41593,z=-68526..-45673
off x=24007..49083,y=-16462..-7045,z=57536..81481
off x=-11681..3645,y=-58012..-41953,z=55142..76200
off x=-76656..-52954,y=35846..55582,z=-53872..-34722
on x=-12038..8659,y=-87346..-69918,z=28070..47940
on x=-11947..10184,y=-53409..-34027,z=-72583..-47438
off x=-55067..-35621,y=-69939..-60505,z=-14835..1042
off x=32935..37139,y=-85226..-70552,z=-25685..4412
on x=-28948..-4652,y=36671..63289,z=-68708..-50580
off x=11959..12834,y=37735..57272,z=-76650..-51945
off x=-80869..-62027,y=-29135..1722,z=-41049..-20272
off x=-16105..-9908,y=13813..43802,z=-91236..-73026
on x=-49560..-40469,y=43630..61941,z=-52839..-35457
off x=9147..25541,y=-80287..-59670,z=42741..55735
off x=50379..79472,y=29160..49483,z=-5978..29107
on x=-88412..-58603,y=-3423..3159,z=19531..41416
off x=-1015..23656,y=53461..84876,z=27264..47816
off x=-34955..-31932,y=56566..75983,z=-11994..10763
off x=-33477..-1860,y=19104..24306,z=-77651..-71897
on x=-73047..-48583,y=28931..56704,z=23154..30012
off x=70083..72794,y=-5597..15786,z=-51791..-23271
on x=28989..57370,y=40583..60178,z=-62971..-45863
on x=55125..91706,y=-15559..4561,z=15786..49181
off x=-24690..-3730,y=59694..97039,z=724..22523
on x=50442..59532,y=-34136..-13939,z=-73167..-41283
on x=-42457..-22829,y=28486..55735,z=-61093..-54803
off x=59374..88933,y=-35520..-16575,z=21065..24982
off x=47891..77004,y=-55581..-33892,z=-24958..-20207
on x=-39381..-6103,y=25106..44027,z=51236..84981
off x=53027..72033,y=-66349..-40215,z=-1886..6465
off x=-16688..3581,y=-13126..2347,z=-92211..-65235
on x=-42613..-26870,y=-29924..-12291,z=-67035..-61494
off x=63092..79122,y=988..21133,z=-16953..3867
off x=-67216..-58011,y=-53495..-33034,z=-11608..-1856
off x=53934..86965,y=-44444..-9436,z=16273..30447
off x=-4034..19635,y=-54143..-37719,z=-78365..-41039
on x=-34211..-14894,y=-25413..-719,z=56386..88338
on x=-57326..-35994,y=-38049..-8173,z=-56649..-54035
off x=30271..50936,y=-87052..-56522,z=3300..32145
on x=55833..75804,y=18495..43321,z=-27127..-11497

106
22.jl Normal file
View File

@ -0,0 +1,106 @@
include("utils.jl")
function interval(coords)
coords[1]:coords[2]
end
function parse_input(filename)
map(non_empty_lines(filename)) do line
command, coords = split(line)
coords = map(x->parse(Int, x.match), eachmatch(r"-?[0-9]+", coords))
coords = [interval(sort(coords[1:2])),
interval(sort(coords[3:4])),
interval(sort(coords[5:6]))]
command, coords
end
end
function ccontains(a, b)
all(issubset.(a, b))
end
function cempty(cube)
reduce(min, length.(cube)) == 0
end
function setdiffcubes(cube, subcube)
above = [cube[1], cube[2], (subcube[3].stop+1):(cube[3].stop)]
below = [cube[1], cube[2], (cube[3].start):(subcube[3].start-1)]
far = [cube[1], (subcube[2].stop+1):(cube[2].stop), subcube[3]]
near = [cube[1], (cube[2].start):(subcube[2].start-1), subcube[3]]
right = [(subcube[1].stop+1):(cube[1].stop), subcube[2], subcube[3]]
left = [(cube[1].start):(subcube[1].start-1), subcube[2], subcube[3]]
filter(c->!cempty(c), [above, below, far, near, right, left])
end
function add_cube(cubes, cube)
if length(cubes) == 0
return [cube]
end
if any(map(c->ccontains(cube, c), cubes))
return cubes
end
cubes = filter(c->!ccontains(c, cube), cubes)
result = [cube]
for c in cubes
inter = intersect.(c, cube)
if cempty(inter)
push!(result, c)
else
append!(result, setdiffcubes(c, inter))
end
end
result
end
function remove_cube(cubes, cube)
if length(cubes) == 0
return []
end
result = []
for c in cubes
if ccontains(c, cube)
continue
end
inter = intersect.(c, cube)
if cempty(inter)
push!(result, c)
continue
end
append!(result, setdiffcubes(c, inter))
end
result
end
function magnitude(cube)
reduce(*, length.(cube))
end
function run(filter=nothing)
cubes = []
for (command, coords) in parse_input("22.data")
if typeof(filter) == Int64 && reduce(max, map(x->reduce(max, abs.(x)), coords)) > filter
continue
end
if command == "on"
cubes = add_cube(cubes, coords)
else
cubes = remove_cube(cubes, coords)
end
end
sum(map(magnitude, cubes))
end
function solution22_1()
run(50)
end
function solution22_2()
run()
end
solution22_1(), solution22_2()

4
22_ex.data Normal file
View File

@ -0,0 +1,4 @@
on x=10..12,y=10..12,z=10..12
on x=11..13,y=11..13,z=11..13
off x=9..11,y=9..11,z=9..11
on x=10..10,y=10..10,z=10..10

22
22_ex_2.data Normal file
View File

@ -0,0 +1,22 @@
on x=-20..26,y=-36..17,z=-47..7
on x=-20..33,y=-21..23,z=-26..28
on x=-22..28,y=-29..23,z=-38..16
on x=-46..7,y=-6..46,z=-50..-1
on x=-49..1,y=-3..46,z=-24..28
on x=2..47,y=-22..22,z=-23..27
on x=-27..23,y=-28..26,z=-21..29
on x=-39..5,y=-6..47,z=-3..44
on x=-30..21,y=-8..43,z=-13..34
on x=-22..26,y=-27..20,z=-29..19
off x=-48..-32,y=26..41,z=-47..-37
on x=-12..35,y=6..50,z=-50..-2
off x=-48..-32,y=-32..-16,z=-15..-5
on x=-18..26,y=-33..15,z=-7..46
off x=-40..-22,y=-38..-28,z=23..41
on x=-16..35,y=-41..10,z=-47..6
off x=-32..-23,y=11..30,z=-14..3
on x=-49..-5,y=-3..45,z=-29..18
off x=18..30,y=-20..-8,z=-3..13
on x=-41..9,y=-7..43,z=-33..15
on x=-54112..-39298,y=-85059..-49293,z=-27449..7877
on x=967..23432,y=45373..81175,z=27513..53682

60
22_ex_3.data Normal file
View File

@ -0,0 +1,60 @@
on x=-5..47,y=-31..22,z=-19..33
on x=-44..5,y=-27..21,z=-14..35
on x=-49..-1,y=-11..42,z=-10..38
on x=-20..34,y=-40..6,z=-44..1
off x=26..39,y=40..50,z=-2..11
on x=-41..5,y=-41..6,z=-36..8
off x=-43..-33,y=-45..-28,z=7..25
on x=-33..15,y=-32..19,z=-34..11
off x=35..47,y=-46..-34,z=-11..5
on x=-14..36,y=-6..44,z=-16..29
on x=-57795..-6158,y=29564..72030,z=20435..90618
on x=36731..105352,y=-21140..28532,z=16094..90401
on x=30999..107136,y=-53464..15513,z=8553..71215
on x=13528..83982,y=-99403..-27377,z=-24141..23996
on x=-72682..-12347,y=18159..111354,z=7391..80950
on x=-1060..80757,y=-65301..-20884,z=-103788..-16709
on x=-83015..-9461,y=-72160..-8347,z=-81239..-26856
on x=-52752..22273,y=-49450..9096,z=54442..119054
on x=-29982..40483,y=-108474..-28371,z=-24328..38471
on x=-4958..62750,y=40422..118853,z=-7672..65583
on x=55694..108686,y=-43367..46958,z=-26781..48729
on x=-98497..-18186,y=-63569..3412,z=1232..88485
on x=-726..56291,y=-62629..13224,z=18033..85226
on x=-110886..-34664,y=-81338..-8658,z=8914..63723
on x=-55829..24974,y=-16897..54165,z=-121762..-28058
on x=-65152..-11147,y=22489..91432,z=-58782..1780
on x=-120100..-32970,y=-46592..27473,z=-11695..61039
on x=-18631..37533,y=-124565..-50804,z=-35667..28308
on x=-57817..18248,y=49321..117703,z=5745..55881
on x=14781..98692,y=-1341..70827,z=15753..70151
on x=-34419..55919,y=-19626..40991,z=39015..114138
on x=-60785..11593,y=-56135..2999,z=-95368..-26915
on x=-32178..58085,y=17647..101866,z=-91405..-8878
on x=-53655..12091,y=50097..105568,z=-75335..-4862
on x=-111166..-40997,y=-71714..2688,z=5609..50954
on x=-16602..70118,y=-98693..-44401,z=5197..76897
on x=16383..101554,y=4615..83635,z=-44907..18747
off x=-95822..-15171,y=-19987..48940,z=10804..104439
on x=-89813..-14614,y=16069..88491,z=-3297..45228
on x=41075..99376,y=-20427..49978,z=-52012..13762
on x=-21330..50085,y=-17944..62733,z=-112280..-30197
on x=-16478..35915,y=36008..118594,z=-7885..47086
off x=-98156..-27851,y=-49952..43171,z=-99005..-8456
off x=2032..69770,y=-71013..4824,z=7471..94418
on x=43670..120875,y=-42068..12382,z=-24787..38892
off x=37514..111226,y=-45862..25743,z=-16714..54663
off x=25699..97951,y=-30668..59918,z=-15349..69697
off x=-44271..17935,y=-9516..60759,z=49131..112598
on x=-61695..-5813,y=40978..94975,z=8655..80240
off x=-101086..-9439,y=-7088..67543,z=33935..83858
off x=18020..114017,y=-48931..32606,z=21474..89843
off x=-77139..10506,y=-89994..-18797,z=-80..59318
off x=8476..79288,y=-75520..11602,z=-96624..-24783
on x=-47488..-1262,y=24338..100707,z=16292..72967
off x=-84341..13987,y=2429..92914,z=-90671..-1318
off x=-37810..49457,y=-71013..-7894,z=-105357..-13188
off x=-27365..46395,y=31009..98017,z=15428..76570
off x=-70369..-16548,y=22648..78696,z=-1892..86821
on x=-53470..21291,y=-120233..-33476,z=-44150..38147
off x=-93533..-4276,y=-16170..68771,z=-104985..-24507

6
2_ex.data Normal file
View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2

1000
3.data Normal file

File diff suppressed because it is too large Load Diff

61
3.jl Normal file
View File

@ -0,0 +1,61 @@
include("utils.jl")
function parse_input(filename)
input_lines = collect(non_empty_lines(filename))
width = length(input_lines[1])
integers = map(x->parse(Int, x, base = 2), input_lines)
(integers, width)
end
function most_common_bit(integers, width)
score = zeros(Int, width)
for int in integers
for index in 1:width
score[index] += ((int >> (index-1) & 1) - 0.5) * 2
end
end
map(map(sign, score)) do x
if x == 0
1
else
x
end
end
end
function solution3_1()
integers, width = parse_input("3.data")
score = most_common_bit(integers, width)
result = 0
cresult = 0
for i in 1:width
result += ((score[i] + 1) >> 1) << (i - 1)
cresult += (((score[i] * -1) + 1) >> 1) << (i - 1)
end
(result, cresult, result * cresult)
end
function filterdata(integers, width, score_factor)
ints = copy(integers)
for i in reverse(1:width)
score = most_common_bit(ints, width) * score_factor
ints = filter(ints) do x
(x & (1 << (i - 1))) >> (i - 1) == (score[i] + 1) >> 1
end
if length(ints) == 1
break
end
end
ints[1]
end
function solution3_2()
integers, width = parse_input("3.data")
oxy = filterdata(integers, width, 1)
co2 = filterdata(integers, width, -1)
(oxy, co2, oxy * co2)
end
solution3_2()

12
3_ex.data Normal file
View File

@ -0,0 +1,12 @@
00100
11110
10110
10111
10101
01111
00111
11100
10000
11001
00010
01010

601
4.data Normal file
View File

@ -0,0 +1,601 @@
31,50,79,59,39,53,58,95,92,55,40,97,81,22,69,26,6,23,3,29,83,48,18,75,47,49,62,45,35,34,1,88,54,16,56,77,28,94,52,15,0,87,93,90,60,67,68,85,80,51,20,96,61,66,63,91,8,99,70,13,71,17,7,38,44,43,5,25,72,2,57,33,82,78,89,21,30,11,73,84,4,46,14,19,12,10,42,32,64,98,9,74,86,27,24,65,37,41,76,36
31 5 70 8 88
38 63 14 91 56
22 67 17 47 74
93 52 69 29 53
33 66 64 19 73
35 63 17 48 77
25 58 33 14 96
32 87 90 66 70
16 4 98 72 23
19 74 39 29 59
40 29 44 17 27
56 98 83 62 70
25 91 20 60 84
42 66 34 77 31
16 8 6 50 28
13 6 58 39 74
3 15 69 5 23
81 65 0 85 93
72 7 60 42 52
45 64 47 53 67
94 21 67 0 14
2 75 77 15 78
38 25 49 99 92
76 35 69 4 64
42 96 86 84 70
46 7 74 65 80
99 12 4 38 77
30 90 78 94 21
22 15 72 52 57
11 67 59 3 9
18 17 63 53 96
16 76 55 5 92
33 82 60 51 8
29 99 87 95 58
88 15 75 61 21
10 24 79 28 90
64 43 21 48 99
45 85 80 71 94
68 39 57 50 72
47 60 3 62 49
82 92 58 16 89
76 90 74 61 29
2 72 43 69 23
84 38 0 4 55
5 64 49 78 94
79 60 28 45 95
47 2 93 89 77
56 18 54 97 33
55 91 68 58 90
87 37 88 35 10
42 76 25 15 38
6 34 33 88 30
43 10 27 26 72
78 66 62 14 37
1 65 95 54 5
14 0 46 72 75
83 2 62 76 26
65 85 19 18 95
57 45 87 51 29
32 37 61 34 43
9 75 56 60 50
53 81 41 55 11
86 54 29 85 2
92 6 97 46 84
5 0 70 3 82
3 15 61 94 85
62 7 12 10 45
84 66 18 33 86
91 19 11 22 39
57 16 80 26 9
1 69 46 98 61
19 7 63 56 90
9 3 66 38 73
40 49 72 0 94
42 23 75 89 32
33 59 17 15 86
62 96 84 2 18
27 63 55 3 82
0 89 19 73 24
56 93 12 87 41
31 56 33 3 9
55 52 87 57 30
44 89 6 5 65
15 53 62 51 11
61 35 13 4 46
15 84 95 88 65
96 18 93 14 21
49 40 46 1 30
50 64 69 80 81
3 19 87 9 38
71 68 18 81 41
95 26 45 24 25
42 73 62 36 94
5 61 98 99 48
31 55 8 1 88
0 73 19 12 4
72 22 27 59 48
71 26 28 66 37
54 87 8 2 65
20 60 35 32 29
44 41 93 76 47
24 33 15 14 61
78 49 81 67 52
74 73 54 23 66
75 10 18 3 60
94 95 52 23 10
55 14 35 44 56
0 49 50 60 79
59 54 90 67 46
17 81 4 37 58
38 29 8 79 77
91 98 1 68 30
86 13 95 46 61
55 36 90 42 97
69 7 0 93 27
82 5 67 40 3
61 16 56 68 29
55 20 13 15 0
75 28 45 17 77
86 85 10 2 26
98 73 72 43 17
32 41 56 46 76
85 7 31 69 91
86 21 37 40 82
33 57 15 39 30
83 18 90 75 29
17 73 32 88 50
51 99 5 23 22
60 47 35 42 2
37 86 82 14 30
17 47 7 54 0
65 83 33 11 57
85 16 27 75 61
60 90 44 69 81
71 73 38 46 28
57 79 76 91 99
96 20 13 34 52
0 21 5 47 63
60 62 55 29 71
44 59 58 78 65
83 30 7 1 80
90 2 11 41 92
3 27 33 10 78
63 75 0 38 86
96 76 87 67 6
63 19 42 56 12
35 89 87 13 81
21 23 4 16 11
64 78 25 92 33
41 10 66 68 99
56 76 37 18 41
38 27 17 50 14
60 23 0 6 1
9 8 30 93 44
58 99 16 46 26
40 77 4 96 68
55 21 30 24 76
81 58 41 91 98
56 46 20 78 0
82 29 87 67 53
59 33 4 18 95
2 52 54 96 19
46 72 3 43 81
20 97 87 55 53
9 80 84 76 29
2 25 44 64 46
93 35 17 84 67
14 48 21 73 90
89 62 53 54 52
38 59 69 45 50
71 96 56 57 72
47 39 25 15 90
29 65 44 3 83
36 30 92 59 95
97 86 48 74 94
51 91 75 25 28
72 56 9 21 93
88 32 58 24 37
82 48 95 53 23
68 20 43 84 69
68 75 33 39 96
0 65 45 27 53
36 71 2 91 97
10 82 44 41 7
11 42 17 26 14
61 36 56 6 64
72 10 62 77 21
99 73 37 38 25
60 7 44 43 14
81 59 29 19 92
63 49 13 31 56
59 76 62 83 44
69 24 57 40 91
20 41 2 55 9
50 60 46 15 52
87 90 97 53 23
85 67 7 71 98
1 22 48 82 69
15 21 17 91 80
99 57 28 94 79
24 25 44 95 99
55 97 9 18 27
71 37 13 52 39
30 3 79 14 28
81 62 98 22 31
49 90 17 65 4
59 42 15 14 54
91 55 67 58 8
13 61 79 32 99
92 28 16 72 20
73 47 39 94 45
93 53 95 71 27
66 40 65 37 58
15 61 63 50 55
57 8 99 90 85
6 45 79 9 14
82 12 42 38 15
31 71 48 5 96
35 81 25 63 19
2 90 64 22 33
62 56 60 29 63
47 33 75 77 76
86 7 90 34 46
85 3 0 16 65
71 44 11 40 52
18 19 73 67 64
66 85 37 10 51
62 46 11 40 35
83 69 57 1 78
81 48 36 6 22
99 0 41 81 52
68 31 27 30 5
12 62 54 43 50
58 36 10 55 86
61 69 97 22 49
59 18 91 86 90
87 20 57 61 42
15 99 31 32 73
23 89 64 96 49
79 47 97 19 51
17 46 19 20 58
67 29 4 8 22
52 18 13 34 70
82 73 71 95 47
35 28 33 42 62
15 16 78 99 74
61 81 84 72 69
12 11 17 62 94
76 63 96 42 98
89 64 10 32 18
18 21 63 89 14
95 5 79 19 11
29 82 77 59 90
13 3 31 46 45
80 37 97 78 61
75 9 94 11 80
93 27 10 2 82
89 32 64 52 60
42 56 23 20 18
70 78 45 76 40
16 98 0 94 73
28 13 48 90 11
30 43 20 9 78
14 39 89 4 6
15 63 91 45 37
41 55 44 2 39
38 14 19 72 64
75 95 35 6 47
70 7 1 29 86
83 79 90 96 82
32 29 42 60 3
85 93 16 41 35
11 90 46 13 58
26 19 79 30 86
72 56 63 18 95
25 71 26 35 59
80 21 11 24 87
48 29 64 66 34
74 83 84 60 57
44 30 95 20 32
29 60 31 2 7
51 78 32 45 14
70 6 59 33 81
16 26 11 38 88
49 74 39 46 3
58 91 95 21 47
61 52 30 2 96
83 19 89 9 1
41 64 28 23 11
62 55 43 60 53
81 15 33 4 19
51 97 88 70 13
76 38 58 28 82
67 3 6 22 47
57 41 53 31 79
29 42 12 64 86
23 0 14 28 82
99 63 79 9 17
75 73 3 45 1
93 52 43 54 76
15 70 19 3 44
47 60 46 93 59
16 87 41 30 68
88 9 26 45 43
28 49 73 98 78
57 30 65 22 25
99 21 36 47 11
70 83 31 73 16
61 77 94 93 23
91 26 13 87 63
13 58 63 4 82
5 89 11 39 51
12 43 75 97 8
15 56 21 0 74
23 66 62 70 44
37 25 82 80 86
58 89 30 91 38
75 40 87 50 67
78 4 55 0 39
54 64 52 96 45
61 57 42 74 26
88 48 8 13 70
81 69 7 97 10
16 23 18 55 36
11 46 68 39 27
37 85 59 41 2
3 29 91 87 84
65 18 70 78 12
9 80 97 19 24
1 75 58 13 92
62 8 80 34 86
72 6 40 57 3
85 82 48 84 37
79 29 70 21 96
41 5 33 32 94
58 21 50 7 72
34 71 93 35 90
77 43 79 55 88
57 12 45 95 70
38 9 29 37 52
57 26 2 22 98
87 4 53 17 97
75 25 70 62 93
3 9 86 33 28
58 50 72 27 5
16 15 71 64 94
37 56 84 32 7
54 99 73 20 8
60 19 22 70 27
69 83 79 48 77
94 38 0 31 19
43 58 22 93 84
2 88 56 13 50
90 68 46 95 47
32 59 89 42 69
94 60 26 63 86
21 64 81 47 71
36 32 93 20 67
16 10 68 39 74
75 99 82 27 18
24 31 35 82 18
49 16 98 90 26
8 64 25 87 92
54 76 2 22 15
7 50 44 94 68
1 31 72 28 18
76 93 20 4 16
35 54 49 30 10
59 32 53 62 84
99 52 92 75 25
1 75 51 22 90
61 83 58 63 28
9 5 85 43 92
69 8 62 93 48
84 31 21 82 78
99 6 70 73 75
65 53 29 31 16
78 61 37 90 7
54 64 20 35 4
97 44 1 10 3
73 50 53 24 49
15 56 94 82 39
31 40 65 79 44
92 70 57 95 30
21 74 55 3 64
44 42 78 31 37
33 69 71 24 81
12 7 23 8 30
10 9 11 68 29
93 28 94 63 87
87 53 75 85 0
34 52 37 49 28
11 72 2 86 62
66 17 61 46 45
13 96 18 99 29
50 76 71 10 92
4 99 46 39 86
23 94 12 73 40
5 70 96 43 51
55 61 67 18 15
51 88 97 58 33
36 12 90 53 85
86 5 42 6 2
95 57 19 34 17
26 1 77 78 20
61 17 79 97 10
29 65 21 55 63
19 88 74 62 6
73 76 89 33 31
50 30 12 22 39
18 94 15 17 26
69 37 91 30 85
13 67 25 84 58
95 90 27 82 33
20 56 62 4 65
58 19 17 83 89
14 82 48 36 97
5 46 20 50 57
60 92 52 85 9
95 34 31 53 73
89 47 3 15 21
2 10 59 76 36
5 24 14 30 72
37 77 57 48 91
16 9 73 94 26
62 1 32 85 9
13 52 75 34 84
93 24 95 51 90
86 35 22 72 38
0 46 96 88 7
67 80 84 34 4
39 11 37 47 82
29 63 57 86 77
78 64 5 32 96
38 69 55 87 50
91 26 89 87 54
51 43 22 68 21
74 62 88 38 53
28 92 4 39 40
96 97 73 72 29
40 83 35 5 91
41 45 57 94 60
61 31 59 47 95
81 89 69 25 33
3 36 15 93 27
19 49 37 14 48
96 55 43 6 12
22 21 50 47 75
78 40 51 91 63
59 87 28 93 86
86 44 3 54 17
71 82 70 88 49
14 43 63 76 15
78 81 61 22 46
84 65 9 29 83
15 28 5 45 29
12 19 64 93 48
83 40 7 99 74
20 30 85 67 58
22 21 59 76 18
42 1 46 8 62
69 27 67 68 38
88 35 83 14 84
53 85 82 29 59
61 73 39 74 99
38 32 50 9 74
75 66 63 3 62
68 15 17 98 6
81 29 52 88 21
58 2 87 96 56
49 12 26 89 98
92 69 90 50 35
74 40 0 87 48
19 47 65 42 31
17 3 33 28 85
47 64 43 73 81
32 49 65 42 24
95 93 36 78 62
34 96 79 10 4
39 54 15 17 51
53 32 41 16 95
54 47 56 69 17
31 0 42 66 13
88 9 43 38 79
21 8 19 98 92
78 43 38 75 14
36 62 64 45 53
31 96 16 46 44
93 11 57 56 65
27 3 73 74 68
66 23 39 13 58
40 85 68 50 57
97 37 77 28 83
48 29 51 84 91
95 1 70 78 56
51 74 68 89 91
49 54 8 83 36
86 65 99 28 47
82 57 32 81 58
13 66 3 94 67

83
4.jl Normal file
View File

@ -0,0 +1,83 @@
include("utils.jl")
function parse_boards(lines)
num_boards = div(length(lines),5)
boards = Array{Array{Int}}(undef, num_boards)
for i in 1:num_boards
boards[i] = zeros(5, 5)
for li in 1:5
values = map(x->parse(Int, x), split(lines[(i - 1)*5+li]))
boards[i][li,:] .= values
end
end
boards
end
function parse_input(filename)
lines = Iterators.Stateful(non_empty_lines(filename))
numbers = map(x->parse(Int, x), split(popfirst!(lines), ","))
boards = parse_boards(collect(lines))
numbers, boards
end
function apply(number, boards)
for board in boards
for i in CartesianIndices((1:5, 1:5))
if board[i] == number
board[i] = -1
end
end
end
end
function check(boards)
for board in boards
for i in 1:5
if (reduce(+, board[i,:]) == -5) || (reduce(+, board[:,i]) == -5)
return true, board
end
end
end
false, nothing
end
function solution4_1()
numbers, boards = parse_input("4.data")
for number in numbers
apply(number, boards)
winning, board = check(boards)
if winning
score = reduce(+, filter(>(0), board))
return (score, number, score * number)
end
end
end
function remove_winning_boards(boards)
last = nothing
filtered = filter(boards) do board
for i in 1:5
if (reduce(+, board[i,:]) == -5) || (reduce(+, board[:,i]) == -5)
last = board
return false
end
end
true
end
filtered, last
end
function solution4_2()
numbers, boards = parse_input("4.data")
for number in numbers
apply(number, boards)
boards, board = remove_winning_boards(boards)
if length(boards) == 0
score = reduce(+, filter(>(0), board))
return (score, number, score * number)
end
end
end
solution4_2()

19
4_ex.data Normal file
View File

@ -0,0 +1,19 @@
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
22 13 17 11 0
8 2 23 4 24
21 9 14 16 7
6 10 3 18 5
1 12 20 15 19
3 15 0 2 22
9 18 13 17 5
19 8 7 25 23
20 11 10 24 4
14 21 16 12 6
14 21 17 24 4
10 16 15 9 19
18 8 23 26 20
22 11 13 6 5
2 0 12 3 7

500
5.data Normal file
View File

@ -0,0 +1,500 @@
427,523 -> 427,790
94,639 -> 94,951
757,371 -> 465,663
503,935 -> 503,148
655,565 -> 655,951
167,754 -> 710,211
634,433 -> 245,433
449,889 -> 449,509
152,753 -> 207,808
301,90 -> 301,982
566,405 -> 482,405
758,741 -> 847,652
342,686 -> 921,107
741,317 -> 741,533
976,917 -> 976,664
273,272 -> 273,899
326,616 -> 326,478
483,906 -> 391,814
20,165 -> 20,349
860,533 -> 860,137
846,834 -> 846,610
155,923 -> 241,923
989,984 -> 17,12
711,681 -> 82,52
312,788 -> 312,281
319,746 -> 892,746
568,555 -> 757,555
659,450 -> 940,450
870,260 -> 870,487
110,794 -> 604,794
509,141 -> 509,99
29,68 -> 29,713
340,688 -> 820,688
428,46 -> 902,520
539,525 -> 539,210
181,822 -> 806,822
551,338 -> 551,79
894,542 -> 894,151
700,625 -> 700,60
143,736 -> 143,770
810,975 -> 54,219
44,373 -> 44,514
849,794 -> 120,794
347,690 -> 97,440
10,625 -> 57,625
541,202 -> 799,202
375,491 -> 809,925
271,474 -> 271,905
980,825 -> 980,908
600,751 -> 624,751
120,978 -> 958,140
262,916 -> 262,794
399,350 -> 399,666
623,270 -> 158,735
585,792 -> 585,381
168,34 -> 168,88
256,806 -> 566,806
196,397 -> 326,397
583,677 -> 172,677
45,242 -> 311,508
530,469 -> 433,566
46,101 -> 877,932
607,655 -> 485,777
773,672 -> 461,360
340,30 -> 659,30
846,952 -> 846,917
457,700 -> 125,368
571,656 -> 561,656
251,30 -> 576,30
79,197 -> 79,87
518,51 -> 518,904
916,802 -> 181,67
23,626 -> 485,626
956,106 -> 956,811
849,384 -> 743,278
893,153 -> 893,608
17,989 -> 933,73
701,119 -> 701,704
494,580 -> 494,821
605,740 -> 605,363
823,58 -> 823,166
250,363 -> 566,363
418,178 -> 783,178
273,82 -> 273,115
545,489 -> 656,489
468,671 -> 966,671
376,744 -> 178,942
62,728 -> 589,201
588,150 -> 467,29
202,664 -> 751,115
519,547 -> 916,150
803,483 -> 380,60
599,459 -> 922,459
162,680 -> 162,385
823,94 -> 18,899
802,734 -> 415,347
115,964 -> 115,935
749,595 -> 749,770
229,64 -> 582,64
103,496 -> 551,48
137,581 -> 707,11
501,563 -> 895,957
59,222 -> 620,222
874,249 -> 874,938
201,927 -> 927,201
630,619 -> 655,619
666,331 -> 413,78
517,650 -> 425,558
803,256 -> 803,598
303,460 -> 606,763
124,975 -> 967,132
867,528 -> 867,363
239,140 -> 239,211
975,779 -> 364,168
971,49 -> 531,49
408,932 -> 143,932
927,663 -> 392,128
497,246 -> 497,389
849,935 -> 15,101
582,517 -> 543,517
410,85 -> 237,85
292,316 -> 841,316
753,708 -> 753,38
266,328 -> 267,327
789,980 -> 16,207
514,963 -> 514,180
865,532 -> 687,710
544,620 -> 956,208
132,287 -> 557,287
268,710 -> 268,684
234,746 -> 234,688
51,906 -> 51,911
191,159 -> 428,159
834,956 -> 834,565
916,242 -> 230,928
227,789 -> 227,689
206,767 -> 705,268
291,403 -> 578,403
35,890 -> 956,890
185,618 -> 402,401
989,858 -> 284,858
391,284 -> 391,74
717,158 -> 670,111
188,146 -> 785,743
602,696 -> 602,367
975,972 -> 975,317
146,301 -> 146,205
328,215 -> 861,215
15,653 -> 990,653
48,101 -> 48,34
929,547 -> 506,970
901,519 -> 670,519
801,560 -> 19,560
953,829 -> 876,829
856,317 -> 856,787
618,171 -> 86,703
823,622 -> 369,168
209,291 -> 846,928
944,601 -> 944,544
678,223 -> 987,223
893,143 -> 54,982
30,740 -> 244,740
974,974 -> 15,15
497,557 -> 63,557
846,193 -> 846,964
83,119 -> 946,982
864,179 -> 864,387
583,312 -> 77,818
612,154 -> 612,641
487,136 -> 487,938
502,611 -> 215,898
648,978 -> 648,885
373,372 -> 318,372
582,988 -> 168,574
453,261 -> 899,261
467,578 -> 33,578
876,138 -> 683,331
708,248 -> 132,824
686,56 -> 686,211
687,964 -> 687,485
626,76 -> 626,222
630,176 -> 630,485
968,608 -> 968,382
943,69 -> 943,856
173,344 -> 173,902
193,918 -> 326,918
811,748 -> 379,316
484,941 -> 113,570
277,635 -> 156,514
770,573 -> 691,573
37,475 -> 464,475
720,856 -> 676,856
988,13 -> 25,976
414,74 -> 140,74
169,158 -> 29,298
611,910 -> 611,718
851,161 -> 507,161
76,969 -> 76,114
270,243 -> 976,949
375,607 -> 325,657
738,450 -> 196,450
153,776 -> 153,325
862,123 -> 862,535
705,933 -> 931,933
900,26 -> 35,891
870,66 -> 79,857
815,569 -> 347,569
950,290 -> 757,290
719,446 -> 317,848
243,531 -> 671,531
320,807 -> 380,807
221,984 -> 221,858
832,308 -> 832,950
522,694 -> 584,694
412,48 -> 412,328
898,690 -> 646,690
602,191 -> 106,191
58,961 -> 58,879
177,413 -> 147,383
48,159 -> 48,639
18,935 -> 883,70
26,68 -> 406,68
579,73 -> 579,523
975,825 -> 975,737
390,125 -> 737,472
127,179 -> 127,111
506,557 -> 576,487
161,210 -> 324,47
524,165 -> 524,67
938,790 -> 184,36
302,431 -> 548,677
559,363 -> 559,913
936,10 -> 176,770
828,976 -> 657,976
864,14 -> 864,607
28,46 -> 28,347
732,742 -> 732,615
91,712 -> 91,279
982,884 -> 772,674
917,47 -> 683,47
631,697 -> 83,697
463,413 -> 463,949
719,348 -> 197,870
980,25 -> 24,981
64,608 -> 410,954
103,882 -> 103,842
279,10 -> 830,561
409,573 -> 409,247
673,291 -> 222,291
315,143 -> 942,770
216,89 -> 80,225
134,936 -> 967,103
387,566 -> 82,566
282,259 -> 862,839
930,225 -> 930,775
460,370 -> 460,922
276,254 -> 518,496
647,881 -> 293,527
983,977 -> 90,84
336,836 -> 336,392
96,888 -> 963,21
42,47 -> 978,983
923,280 -> 726,83
311,486 -> 505,292
496,637 -> 861,637
575,438 -> 575,498
228,754 -> 228,599
965,963 -> 21,19
834,171 -> 730,171
497,234 -> 497,448
977,970 -> 977,618
335,422 -> 335,640
931,954 -> 36,59
140,966 -> 871,235
352,88 -> 449,88
631,332 -> 735,332
765,823 -> 48,106
496,685 -> 103,685
89,416 -> 89,37
121,544 -> 569,544
643,712 -> 596,712
662,656 -> 739,656
42,386 -> 42,697
959,875 -> 959,527
874,967 -> 120,213
962,649 -> 240,649
627,714 -> 266,714
148,301 -> 148,383
883,491 -> 883,605
242,401 -> 348,401
660,931 -> 420,931
475,72 -> 955,552
912,949 -> 912,881
928,330 -> 45,330
474,203 -> 131,203
805,459 -> 818,459
534,645 -> 639,750
68,911 -> 933,46
717,276 -> 21,972
233,615 -> 957,615
902,495 -> 902,867
230,427 -> 230,421
630,917 -> 845,917
884,903 -> 34,53
157,205 -> 157,409
857,588 -> 608,588
422,863 -> 422,469
890,83 -> 722,251
546,318 -> 138,726
691,881 -> 52,242
171,435 -> 209,435
978,15 -> 702,15
581,86 -> 581,282
61,767 -> 61,903
835,289 -> 835,941
176,351 -> 707,882
571,84 -> 571,788
700,373 -> 700,650
40,40 -> 945,945
82,616 -> 809,616
351,402 -> 455,402
517,242 -> 73,686
489,795 -> 814,795
543,734 -> 611,734
688,849 -> 688,571
631,903 -> 883,903
312,636 -> 667,281
213,575 -> 699,89
752,128 -> 161,719
754,931 -> 754,474
748,666 -> 748,54
123,667 -> 57,667
140,497 -> 140,644
634,961 -> 187,514
822,865 -> 822,126
58,162 -> 632,736
417,164 -> 166,164
943,597 -> 943,274
355,756 -> 355,167
340,546 -> 232,438
166,125 -> 166,96
354,394 -> 354,579
147,844 -> 155,844
652,723 -> 719,656
584,582 -> 667,665
514,373 -> 685,202
308,404 -> 966,404
124,179 -> 916,971
706,597 -> 455,597
52,822 -> 510,364
419,900 -> 860,900
153,649 -> 872,649
915,160 -> 56,160
422,346 -> 422,38
940,73 -> 940,784
922,581 -> 922,753
949,821 -> 949,621
591,778 -> 145,778
93,685 -> 164,756
287,469 -> 287,948
953,952 -> 446,445
935,47 -> 12,970
458,109 -> 458,639
71,643 -> 644,70
812,214 -> 812,655
488,496 -> 158,496
113,868 -> 755,226
666,429 -> 666,920
962,246 -> 517,246
400,261 -> 400,713
601,617 -> 943,275
904,847 -> 120,63
556,334 -> 278,612
416,463 -> 59,463
724,401 -> 871,548
701,210 -> 426,485
786,116 -> 786,904
976,979 -> 157,160
674,377 -> 674,891
321,829 -> 891,829
404,84 -> 404,800
975,850 -> 906,781
753,331 -> 978,331
87,240 -> 87,383
167,390 -> 167,20
258,931 -> 107,780
672,313 -> 696,313
589,88 -> 589,13
637,65 -> 637,808
532,610 -> 532,756
612,482 -> 318,482
522,322 -> 135,322
89,49 -> 89,679
475,506 -> 475,973
385,348 -> 229,348
633,978 -> 633,255
978,833 -> 978,436
746,553 -> 707,553
970,820 -> 970,548
589,59 -> 589,19
674,890 -> 16,890
838,315 -> 413,740
39,129 -> 860,950
923,755 -> 425,257
757,929 -> 940,746
639,390 -> 104,925
650,512 -> 260,902
718,90 -> 987,90
352,228 -> 795,671
141,629 -> 491,279
755,616 -> 368,616
117,113 -> 707,703
206,73 -> 926,793
372,415 -> 372,130
894,632 -> 611,632
974,554 -> 878,554
823,710 -> 823,972
730,711 -> 582,859
94,912 -> 108,912
782,190 -> 88,884
668,567 -> 336,567
87,266 -> 327,506
738,303 -> 36,303
320,358 -> 445,358
566,725 -> 695,725
94,364 -> 94,64
884,184 -> 159,909
947,575 -> 947,662
658,741 -> 658,470
512,776 -> 512,960
96,757 -> 950,757
349,604 -> 349,760
459,247 -> 355,143
90,12 -> 95,12
28,27 -> 981,980
388,959 -> 508,959
704,194 -> 148,194
349,546 -> 349,259
30,38 -> 720,728
307,631 -> 307,282
520,417 -> 154,417
746,771 -> 924,771
838,932 -> 20,114
406,141 -> 406,75
15,35 -> 963,983
264,143 -> 948,827
545,899 -> 742,899
759,356 -> 309,356
686,707 -> 224,245
226,985 -> 962,249
826,628 -> 826,637
985,329 -> 683,631
586,283 -> 586,258
602,703 -> 243,703
419,883 -> 419,556
475,375 -> 211,111
981,15 -> 19,977
989,10 -> 10,989
238,350 -> 479,591
720,714 -> 603,714
969,985 -> 35,51
844,356 -> 837,349
450,354 -> 450,834
385,870 -> 385,758
911,856 -> 89,34
948,124 -> 989,124
439,556 -> 439,310
990,233 -> 990,633
747,723 -> 943,527
418,23 -> 804,23
876,96 -> 38,934
556,92 -> 532,92
727,155 -> 727,279
674,545 -> 940,811
118,879 -> 420,879
141,50 -> 426,335
591,180 -> 591,537
662,511 -> 681,511
776,858 -> 776,956
872,329 -> 87,329
183,985 -> 114,985
186,179 -> 186,801
354,933 -> 491,933
10,223 -> 759,972
112,626 -> 702,36
498,78 -> 161,78
196,61 -> 814,679
629,71 -> 116,71
23,281 -> 23,32
819,810 -> 432,423
187,276 -> 187,912
95,683 -> 576,683
125,813 -> 856,82
98,882 -> 140,882
843,909 -> 198,909
192,904 -> 192,335
375,342 -> 375,668
61,804 -> 61,832
475,387 -> 966,878
822,740 -> 822,186

67
5.jl Normal file
View File

@ -0,0 +1,67 @@
include("utils.jl")
function parse_input(filename)
map(non_empty_lines(filename)) do line
collect(map(x->parse(Int, x.match), eachmatch(r"[0-9]+", line)))
end
end
function solution5_1()
max_x = 0
max_y = 0
lines = filter(parse_input("5.data")) do line
max_x = max(max_x, line[1], line[2])
max_y = max(max_y, line[2], line[4])
line[1] == line[3] || line[2] == line[4]
end
board = fill(0, max_x + 1 , max_y + 1)
for line in lines
if line[1] == line[3]
if line[2] <= line[4]
for i in line[2]:line[4]
board[line[1] + 1, i + 1] += 1
end
else
for i in line[4]:line[2]
board[line[1] + 1, i + 1] += 1
end
end
else
if line[1] <= line[3]
for i in line[1]:line[3]
board[i + 1, line[2] + 1] += 1
end
else
for i in line[3]:line[1]
board[i + 1, line[2] + 1] += 1
end
end
end
end
length(filter(>(1), board))
end
function solution5_2()
max_x = 0
max_y = 0
lines = filter(parse_input("5.data")) do line
max_x = max(max_x, line[1], line[2])
max_y = max(max_y, line[2], line[4])
true
end
board = fill(0, max_x + 1 , max_y + 1)
for line in lines
x = line[1]
y = line[2]
board[x + 1, y + 1] += 1
while x != line[3] || y != line[4]
x += sign(line[3]-line[1])
y += sign(line[4]-line[2])
board[x + 1, y + 1] += 1
end
end
length(filter(>(1), board))
# transpose(board)
end
solution5_2()

10
5_ex.data Normal file
View File

@ -0,0 +1,10 @@
0,9 -> 5,9
8,0 -> 0,8
9,4 -> 3,4
2,2 -> 2,1
7,0 -> 7,4
6,4 -> 2,0
0,9 -> 2,9
3,4 -> 1,4
0,0 -> 8,8
5,5 -> 8,2

1
6.data Normal file
View File

@ -0,0 +1 @@
2,1,1,4,4,1,3,4,2,4,2,1,1,4,3,5,1,1,5,1,1,5,4,5,4,1,5,1,3,1,4,2,3,2,1,2,5,5,2,3,1,2,3,3,1,4,3,1,1,1,1,5,2,1,1,1,5,3,3,2,1,4,1,1,1,3,1,1,5,5,1,4,4,4,4,5,1,5,1,1,5,5,2,2,5,4,1,5,4,1,4,1,1,1,1,5,3,2,4,1,1,1,4,4,1,2,1,1,5,2,1,1,1,4,4,4,4,3,3,1,1,5,1,5,2,1,4,1,2,4,4,4,4,2,2,2,4,4,4,2,1,5,5,2,1,1,1,4,4,1,4,2,3,3,3,3,3,5,4,1,5,1,4,5,5,1,1,1,4,1,2,4,4,1,2,3,3,3,3,5,1,4,2,5,5,2,1,1,1,1,3,3,1,1,2,3,2,5,4,2,1,1,2,2,2,1,3,1,5,4,1,1,5,3,3,2,2,3,1,1,1,1,2,4,2,2,5,1,2,4,2,1,1,3,2,5,5,3,1,3,3,1,4,1,1,5,5,1,5,4,1,1,1,1,2,3,3,1,2,3,1,5,1,3,1,1,3,1,1,1,1,1,1,5,1,1,5,5,2,1,1,5,2,4,5,5,1,1,5,1,5,5,1,1,3,3,1,1,3,1

19
6.jl Normal file
View File

@ -0,0 +1,19 @@
function solution6(n)
initial = parse.(Int, split(readline("6.data"),","))
fish = [count(initial .== i) for i in 0:8]
for _ in 1:n
fish = circshift(fish, -1)
fish[7] += fish[9]
end
sum(fish)
end
function solution6_1()
solution6(80)
end
function solution6_2()
solution6(256)
end
solution6_1(),solution6_2()

1
6_ex.data Normal file
View File

@ -0,0 +1 @@
3,4,3,1,2

1
7.data Normal file
View File

@ -0,0 +1 @@
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,478,1187,253,1892,900,155,20,787,17,248,1397,407,167,686,638,1020,960,124,840,220,1824,700,373,4,551,229,294,567,254,350,1144,679,124,361,145,483,335,202,1334,367,60,870,11,557,482,645,672,1296,1538,427,78,542,1135,13,65,0,140,705,13,642,187,1085,36,1118,349,601,382,584,941,26,949,200,763,198,430,204,1352,1135,210,342,11,1089,830,1523,9,523,167,762,254,805,8,132,29,102,1299,936,756,59,134,183,235,316,139,48,182,44,88,213,113,93,169,565,601,1899,1191,189,796,770,32,1183,365,374,867,918,1084,86,75,20,47,99,1140,2,99,1024,366,455,752,556,1220,66,326,450,213,1,342,756,49,675,160,280,68,221,193,379,88,179,94,16,109,570,1145,1207,824,355,1389,1601,168,86,236,923,120,759,14,478,460,84,167,1723,1005,269,6,171,861,311,832,952,701,3,1598,1466,96,780,57,161,631,572,276,105,594,276,17,405,688,1444,173,23,199,177,689,19,565,472,151,986,76,379,1430,212,928,106,25,143,84,833,942,860,1555,271,239,720,596,1209,235,535,361,1794,79,283,275,17,342,1687,1434,173,967,740,217,1370,18,1579,1259,546,94,623,475,834,1000,456,101,520,120,1023,360,167,213,617,42,1149,629,760,17,33,27,1347,414,646,1116,1340,134,259,143,407,249,328,968,677,241,438,98,313,27,791,1,634,3,918,1482,213,123,444,45,24,26,26,1203,64,67,1562,1,4,298,12,384,32,443,37,268,674,356,202,286,694,272,163,950,1022,54,59,21,73,519,462,106,76,1112,10,72,388,194,6,120,9,645,209,1121,75,599,362,661,439,69,62,339,390,23,1247,365,1266,4,246,511,47,467,134,276,497,130,458,427,669,1191,701,917,168,1191,294,641,236,801,375,106,872,800,87,356,583,1096,253,459,951,1331,719,66,1091,525,15,370,290,141,1201,30,43,37,76,1131,616,297,172,402,1016,654,301,63,872,303,69,1195,502,351,52,1659,86,104,294,807,166,120,190,333,60,283,819,198,184,144,278,343,1395,496,103,705,485,172,642,225,181,583,188,38,436,801,91,5,634,180,28,20,146,488,676,121,420,965,220,1564,1011,241,423,3,1631,709,106,725,164,1032,65,205,503,188,397,1072,49,121,761,721,249,418,87,126,258,712,500,435,157,127,681,108,270,647,504,505,83,407,212,165,1177,160,715,1292,491,195,141,25,829,1316,242,754,364,1707,33,594,434,488,368,298,183,1156,29,1674,537,378,8,9,860,240,571,749,471,331,501,156,62,427,1103,52,12,832,1198,284,388,827,556,194,288,218,397,84,1485,95,401,739,986,994,305,668,1324,1437,312,993,15,822,923,707,135,42,423,37,1183,1344,997,19,699,395,119,7,168,1711,50,151,38,20,163,686,1364,21,24,411,32,335,188,55,628,274,1766,439,180,286,1024,87,15,1498,290,561,971,32,294,67,113,219,42,18,715,3,664,242,583,221,1045,236,74,46,1612,639,325,164,100,69,518,38,502,26,329,112,1174,127,124,90,144,527,468,152,1098,800,125,349,191,290,191,27,651,446,267,9,1304,269,586,64,983,152,236,512,8,248,177,109,311,957,47,126,69,13,709,204,381,1151,580,340,994,865,258,190,9,1149,930,1128,321,100,471,0,507,1308,326,585,813,1088,76,174,333,387,631,186,430,988,24,820,11,45,173,167,1494,98,1467,456,167,21,1363,1173,394,318,1601,1111,1249,757,282,672,1227,1214,277,336,815,136,1192,681,689,431,130,1488,154,465,14,709,339,1123,68,151,1280,143,1797,23,250,1231,1007,302,1103,2,585,552,1732,994,225,771,1495,82,229,700,910,15,38,159,1122,316,1044,711,1436,920,1722,523,1398,188,443,1032,93,33,397,272,187,24,489,53,79,1277,671,1094,68,1705,984,1096,512,145,389,167,161,1174,94,4,534,1295,648,75,24,366,995,175,220,714,843,412,267,634,1209,66,1094,125,822,1114,1513,694,1520,30,676,817,245,26,77,1146,552,143,165,39,343,971,87,0,90,1434,588,616,99,297,1034,114,5,702,917,582,733,31,54,820,0,212,192,282,33,639,1661,460,75,680,115,178,194,271,274,582,1008,89,139,611,707,0,376,65,9,161,135,40,134,566,66,601,95,817,745,202,352,447,322,842,6,1247,175,468,330,608,368,139,21,29,486,121,9,1293,298,73,328,302,145,889,1794,677,56,952,520,80

14
7.jl Normal file
View File

@ -0,0 +1,14 @@
function solution7(costfunction)
start = parse.(Int, split(readline("7.data"),","))
min(map(x -> costfunction(x, start), min(start...):max(start...))...)
end
function solution7_1()
solution7((x, positions) -> sum(abs.(positions .- x)))
end
function solution7_2()
solution7((x, positions) -> sum(div.(map(n->n * (n+1), abs.(positions .- x)), 2)))
end
solution7_1(), solution7_2()

1
7_ex.data Normal file
View File

@ -0,0 +1 @@
16,1,2,0,4,2,7,1,2,14

200
8.data Normal file
View File

@ -0,0 +1,200 @@
dcagfb cbegda cabdf bagedf dcb cd dcbegaf aebcf bgdaf dgcf | dacebgf cbafd dbacf cdgf
dfgbc ceagbd egb cgdae eafcgd ecbgd eb aefbgcd bfaceg deba | baed ecabgd aebd cadfebg
acbd bagfec bedcf efbca dbfecag gadcfe dc dbcaef cde fbegd | deacfg bfagcde bgedf cde
dgec dfc fabgd bfcgae dfbcg baegdcf cd fbdace cdbefg becgf | cedg adfbecg badgf dgbfc
be bacedg dfacb fbge deagcf eba egacf gcebfa febac dbgacfe | befg be egbf aedgcbf
gafbd gbafce agced fdgae bcedgaf gdeacb efdc eaf fe cgeadf | cgdae fdec fcdeabg ef
cdaefgb cfadbe gc afgcbe afedcg faecb cabg egc bfgde bfgce | fbaedc gc abgc bfcea
egcafb adgecf caebf fdgbaec fbaed cebg facbgd cfe fgabc ec | fbgca deagfc ce ce
fcdab deb cdbfea fecb befcdga abecd gdcae efbgda fcdgba be | cfbad dacge gbdeaf bed
afdecg gfcadb ecadfbg facgd ed egda efbgc ecd cdegf bfadec | becgf fcbeg de cgefb
caedbg gcfdba bfdae ge beagfdc bedag gcabd egac gcefbd deg | fdbecg acge bgfacd abefd
befad ecgad adgefcb febg gb afdcbe dcbfag beafgd dbg eagdb | feabd aedfb gbd aebdcf
bcfde acbfed dcaf dbcae gacbfe fc dgbcae egbacfd fcb edbfg | gbdfe gbeafc bcf cebfga
cgbade adcbgfe fb efgbad gbcfde aecfd edgba afbg bfeda fbe | ecafbdg bfdea fgab edfbgc
cbfa gefbd bcfedga bagefc ab bga ecdgab gbaef gfacde fcage | acdegf gab cegadb gab
cafbeg dfaebc fdca dgcbe eacbf fde debgfca egabfd dfceb fd | df eabcf egbdc dfe
egcdfa ebdac fdaecbg ed fdacb agecb cbdgaf ecd efdb dbaecf | dcabf cbeag ebdf ecgba
gacdebf decfbg afbdg dcagbf cg agdbc agcf ebcad abgedf bcg | badec dcbga cgfa abcde
fgcad dfebga gdbef ec ebcd fbcgea ceg fgedc defgbac dcfgbe | ce gbdfe fbcgdea fcgbdea
cgbef afcbeg dgbec ebafcd cgbfeda adbge cd ecd gfcd fgbdec | edc gcebd fegacdb cd
bafdcg egfdc bcfge dgeabf cd cgbadfe agefd facegd eadc cgd | cgd dcg defbagc cfdbega
degfcb fdg edabgf cadge fg gfcb cdeafbg bcefd dgfec beadcf | dgcbfe cabfed fecbd cgdfbea
dbfaec bfcgae cdb cdaf defbcg abgde ceabf adceb decgafb cd | fcda bdc dc afgecb
cead efcdg adbcfeg fagdc def acegfd fcbagd cbgef ed fgdaeb | ecad fcaedg cgadf cfaged
egdbfa cbgefad dgacbf cb dfbgec gefbd cbf gefbc gcefa bdec | ebcd ecgdbf fgebc cfb
fagbe acbged bf eagcf dgaebcf gbf febadg deabg cdagbf fbed | fbcdag fgeca abgdcf cdbage
baefc febgadc fcag dbgec feg gacfbe gfecb afedgb fg edafcb | aegdfb feabc agbfed fabged
gfedcb eadgcf fed befdagc gaedf bgdea bdafcg fe acdfg feca | bcfdga cagfd afce efca
cbfed degfba fgdbac acdg fdcab ac acgebf agdfb bac gcbfdea | cbdegfa caefgbd ca gdbcafe
dbcgea dc dcg cadf abgcdf efgdb afgbc gefacdb fbcdg agebfc | dabgce gbceda dgc dc
ef dgfbc cefbg gabecfd agceb feg gbcadf dfbe fcdgeb dfagec | gfe cafegd dfeb fe
ebgdc egdacb dfbcega dfe dbfge bagef ecdbfg bdcf df fgecad | dbgce fd cfdb edf
bdage ab fbgaecd aefb bfadeg gefad cdgeb agcbdf gba fgcdae | cgdbfa befa dgefca acebfdg
aecb dbgecf eagfcb ecdbfag fdegba geacf gebfa cge cgdfa ec | acgfe gec cabe fgcda
acd cafg abedcgf cfebda efcbgd cegfd ca cdgafe agcde bgeda | egcfbda gcfdae gefacd dca
dcefga gdefa db fbaed abefdgc faebc fbgaed bdf gbed dcafgb | bfd db db gbdfae
befac abcd bdcfe ecd cd baegfc edfgca adfbce aebcdgf edbfg | cgedfab feabc cd dabc
eacdgf cebgdfa acgebd ecdba dbcfea fdgcb dag ga acgdb abge | ag ga adg ag
gca fagbe dfageb bagce ecgfab gfce gc dcfeabg fadbcg bedac | afbdceg gadfeb cga acbdfg
gbad febac dea gadbecf fdegbc edfacg da bdecg cdbea bdcgae | dbag cdeabg gcdaeb adbg
cdgfeb cbeaf adef cfa fa aecbg fedcb acdebf bdcfga cdefbga | fdea eadf efad caefb
aedgb df cgbaed gdef bfcgda bfd efbac dgfeab debfa aegcbdf | acbfe egfd afebgd gefd
badcfe fcbg bf dfecbga faged gfadbc dfb dfgab abdcg dbceag | bf fb dafbgec fbd
bdae decgbf afcbge bdecfa afcbd edgfcab ebcaf bd dfacg dbc | ebda db cbd cbd
acfgde ae eac agbdec gadcb ebgcafd baed gfcbe cgabe bfgadc | cea fecdga ebgdac eac
cbedga cfb adcbe bfae afcdgeb cgdaf fcedab bf fcbdeg dacbf | dfceba fcdga fbc fcebda
cdafg dfgeac fc dbgcef gadbc gacfebd dcf edfgab gefad caef | fadgc facged adgefb ecgbdaf
gdcbf eabdgf gaefd fbdge afcedg bacgfe fagbedc dbea efb be | ecagfb dgaef be eb
gbecad faced abgedf cd cbfd abedcf dacgbfe cde deabf agcfe | cd edbfac cgabed daebfg
cgebaf dacbge gafed eadbgf dgcef ad fadgbce dea bgafe dafb | fegad dgeaf ad gdfae
ecfadb eagdbc afbcdge abfcgd cf bgedf agfc cfd gbfdc bcagd | fcga fcd befgd gdbfc
afcbg gfeb gfcad ecgdba cbf cafbeg bacge fb ebdfac baedcfg | fbc gabce egabc fcadg
agd gadbc da agcfed gcebad dgfcb ecabg ebcagdf eadb becfag | fgbeadc bcega geacb gceab
gaebf gfdbce aefbgd fde aefcbg ed dcaebfg agde aefdb acfdb | efd agcdebf cbgefd ebgfa
cdgfe ecbafd ebgca ad gedbcfa cad adbg cedabg egcad fcebga | gbedac adgb ecdgab daceg
efcb fcdag begdfa egcdf edf fe gfcdeb cdbega geacdbf becdg | dagfc gbadef decbg fe
bgaed agfdc fdgea fae fabcgd gcfe fe decfga afgedcb facbed | gdafe ef eacfbgd fe
ebgfca def fd ecgfbd efbda eabdg edgcfba afdc ecbfa bfdaec | abcefd fd dafc debcagf
eacbg efbdgca fdbga gde abecdg beagd cdeafg de cebd ecagbf | gaedbc gdcbafe gaecdf bgdeac
bafce cedb edacgfb fbgac fbe aedfgb be cbedfa cdefa eacfgd | be acbfg gfbac edbc
dgba cbgfdea gbe fbaegc cbedga fegdc decafb cdbge bg daecb | cadfbe bgad beadgc bgedc
abd fdbcae aedfb daec ad bacfdg dgefcb agbef cbefd cbagdef | ad dab acde da
cdagbe dagbe fageb gdfbeca gdcba edac dgcfba egd egcfbd ed | fbgcad cafdbg de facbged
dbecf egadfb cfagde da fcebga cagef dae fadec dagc dfbcaeg | da dgac bfedc ad
efa adcf fgcde acgeb bgedfa efcga degfbc aegcfdb fa efdgac | cfgea fedgc ecagf efdacgb
fecga eafgd acgefb cf gceab fbcdag gecdafb cabedg fbec gcf | agcbfd gfc cgf ceagf
egcaf ecdafgb dfgea cbafe dfebgc bgac cbagef cg gfc ecdfab | edbfgca edafg cgf gfc
afdcgb decgb fbdegca fbgae fdbaeg dgfbe gbafce df fdb efda | gcbed dafe gbfdca aefgb
gaebd baefg cfadbg fb gaedfbc gadbef cfgea bfde baf gacdeb | abf cdbagf aecbdg fagec
cfdb dcg geadbf febdg edfabcg dc bgecd eabcg fcgead cgbfde | dgc dc bdfge dcfebga
dfbcaeg fdgcae gfdab bagc gabcdf fecbgd cadgf gb fbade bdg | bdg gacb bgac ecfbdg
eg befdg fceabd badfg dbecf egbcfa bedgcf gbacefd egb dceg | beg faecdb gfdbe dbacef
cdagef edfca dgfa fca fa agedc gfcabe bdfec bdcage fbcaedg | caedbfg ecafgbd fdcega decgfba
gfc cfeb cafgdb fc aedgbfc cgdfe degfb aedcg fbegcd dfgbea | acdge fedbg agedc ebgdfa
aegdcb gde dgbfca eg bdecfga fedbgc gcbfd fgecd bfge acefd | ge debcag bgedcf bfeg
gbd eagbc cbefagd gcde aefdb gcebad cgdafb dg aegbd facbge | cdeg cged ebdaf gbd
eagbcf cba aebd cdfga cdegbf afcbedg dcbfe ab adfcb acfbde | bcfeag fgdcbe daeb bdae
gc dabcfg dcfageb acg ecabf bgadef facge gfeda ecdg fagced | gcde efdga agc fgaed
bcgdea bacfdg aeg cdabg dfeagc befgd aebc dabfgec ae degba | ebfdg egadcf aceb gbdac
ceadf defagb fg agbed dfgaebc bfaecg eacdbg afgde efg fgbd | gf egbda fabegc badfgec
begcfd fdecb fbdga ca bace cfadb egfdca cda cfaedb efabdcg | gacefd fdgba fcdebg bcae
bcga agbefc fageb ca afc debfc dafegc fdgeab abfdgec fecab | gdafceb befac fdecga ac
fce adcfg cgdefa bgcfda fdae acegf fe cgbae adgfceb cdegfb | gedacbf fdebgac deaf afde
agcf dbegf bga cfeba gfdebca fgaeb cbdefa ag egadcb cbfega | fbdge gcabef cagf ebdafc
aedg ge decbga bafce ecg gcdab degfcab gcfdeb ceabg abdcfg | cbfea ecg bafec eacfb
gfdceb cgb bcdfe gebdc egcabdf egcf bafcgd bgdae edabfc cg | gbc bgdfca cgfe gc
bg bedcf dgfaec fdbgc gcbafed fbg bfaged gadcf cgab acbgfd | agfbde bg bgcdf fgb
gafcb cdfgab abfcge cbgde bdcfae ea faeg dbgcafe ace agebc | decbaf fbacde bcagf ace
bgfdac cgabdef efdca fagce febagc cd fcd dfeacg gdce aefdb | dc dgcfba ecdagf gfacbe
bde eb egfbdc ebgfd fbdgc daebgc cagfbd gfbceda efbc aedfg | cgebadf becf cfbdg cfbedg
ebcdfag fadec daceg gbecaf eabcfd fd fad aebfc fcgbad efbd | dcefbag fceagb fdecabg adf
efgd fd bfagcd acefb febad gdbaef edcgba badge dbgaefc daf | eafbd gbcdfa gdfe edgba
cefdag bfagec bedcg da acd bcfead bdgcefa gcaef acdeg agfd | geacbf faegdc fcdgbea eacgfdb
bcedgaf bgfae cab bdcg cb gcade egdacf abdegc agbec becfad | gfcadbe adgbec gebfcda cfaedg
gf edbcafg cfge gdafe gdf cdabfg eabdg dgefac acfed fbceda | geabd cbgdfa ceadbf agbfdc
fcbgde fbged cgfdb gdebcaf cfge ebg deabf baedcg ge dfabcg | beadf ge dcbgef cfeg
eafdcb gcdfbea eag dgcba gacdef agebd dbefag deabf ge fgbe | fcbdea bgcdeaf dbgac fagcebd
dc fgebad ecd aedcfb cdga ebcagd dfbaecg adebg debcg gbecf | bcegd gcdeb dacg eagdb
cad feabgd fadegc bgcdfea gbcfa bgcda bgaced decb dc ebadg | acd adfbge cd dc
af cfbge fadecg afbgc dbaf gbdfac bdgeacf dbcga cfa gebcda | fa dabcg dafb gbceda
fbgdea gcefa agfdb fecdba egbd fdgea de bagfcd gdcbafe dae | ed eda abdefc fadgeb
fdbcga fdbae bfa adfcge gcbfaed bfeg fdage eacbd fgbaed fb | bdcfage fbeg eadfbg gbef
cfdbga fdeab gefbad bcaefd egad fdaegbc ag gcefb afg agefb | abfgecd egda bgcfe adefb
fbeda ae dae bdgfe gcadbf beac fedabc badfc ceagfd dgcbafe | bfcad gfabdc aed fbdac
fgcaed bagcef bdfc edabg efacd ebcadf fb afb abefd agfbdce | cfdb fb abf abf
fed bfaedc fceab edabg bfdea ecdagf begfdac df fceabg bfcd | cebgfa df eagbd gafced
egfdc fcg cadg dfebc dfebcga cg dgabef ebgacf dfgea gcfade | fbedc gcfed dcag fgc
fcbde fbeacgd afedb da fcegda dabg ebgaf dgfaeb dea febagc | da bfdce egfacb ad
fcdeg cdbe fgcab dceagf febcg eb cebdgf geb edfgab dbgcaef | abgcfed bdec gdcfe cfgdbe
degfb ebdacf edbfcg agdfce dbf bd bgcd dgfce gfdcbae abegf | gebfcd fgeab gecdfb gdafcbe
egacd abedg decfgba dagceb ca cabe cag dagfcb badfeg cegfd | gca caeb cfgde ca
gfa ebafd fg gafdbec gaecfb gbdfa edfg gaedbf bdgca ecadfb | fbagec fecabd caegbf fg
dfgce cgfbe cefad bfdace fcaged cdg badceg fdceagb dg afdg | gcfbe dg gadf edfabc
dfgbc cbfeda bdgcfe fdb efbg bf gcedb fdaecgb gdecba fgadc | bgdafec bgcde fbgdc agdfc
fgecd dbegfac adbfgc fa bdcage acegb eacgf efab fca fceabg | gafce af gdcbea af
fgdacb fbdec adb gfda acbdegf edbcga cfgba da cbgefa cadfb | gbcfea bgcfda da dab
fbcdg abfcdg cfegbda ed dbcaef gedcfb aecgb dcegb ced egdf | cabfgde egcdfb fbcade dgcfab
dbec fcd cegbdf dc fdacgeb abdfg baefcg gbfcd dafgce gfbec | dcf cfd fcd agefcb
fcdeg gdefb cfgadbe fb bef bfcg edfacb fecdgb gcdfea gadeb | efb feb fbcg dabge
acebd dacfg bdf agdcbfe gcafdb fcegad afgdbe bcfg bfcad bf | dbf bdaec bf febacdg
acdegf bdfa afdebg febcga gaefb fd fed dgefcab bedgf edbcg | efgdab aecdgf cedgbfa def
ecdfabg dfge cedfba fcadgb fgabd ebgfad fea egafb bcgae ef | efgdbca eagcfdb defg bfgda
efacgd bfda bcadg gab gbceadf ab cfbdga gadfc bcgfae dgbec | fgecad dbaf ba abfgdec
bcgaed fbgc edcfg dgbecf fgdae dgc cg abdcef gfcbdea ebfdc | cg cdfeb cg edbcfag
cagb fgcdeab gdebaf fcegd ecabfd acfeg ag afceb fga acgbfe | ga agf bcadfe fag
fbgde efbagc ecgd efdgabc ebdcf fdcgbe abfdg fcbead egb eg | dcge cedbgf fbgad acegfbd
febadcg cfdbge bgcef gecd ed gbdaf bfdeg deb gfabce fcbead | efdbca ed fgcbe cebdaf
eagbc cgde cafbg abdge fbdgae gacedb aec ec acefbgd abcefd | bgacf cgbfeda agbed dgec
efgbdca gfdb cadbfg dag dg degfac bcdaef gdacb bfcad agebc | gda dfagecb gcfdea dag
gefab bfde acbfgde gfdac ebfgad bfgeca aegbcd eda gfade de | gafbce gcfeabd aefgd fgbcae
gaecfb cdebgf fec ebcafgd bgecad cf debgc bfead ebfdc cgdf | cdbfe gfcd egbdca edfcgb
cfdeba bfgd gcedfa gbdae dgefcab cbega dg febadg agd bdaef | dfgb adg gecdfa fcebda
dea bgdeaf da befdc gdcfaeb ecdbga abecd gacd bgafce eagcb | aedcb facebg abfecdg bagefdc
gcebf dfbae dbgcfe egdc dgebcaf febcd bcd cagfeb fdgcba dc | bcd efcbd daefb agbdfce
fa acged bdfec afeg gcfadb bfdagce ecgafd caf acdfe dgaecb | debfc af afge adegc
bacfdg fadbe egbdfc ba bage acefd baf bgdafe fgebd gdacbef | dbfage bgedf aedgbf acedf
acgb dgcbfa dba edgbfac acdefb begdf bdgfa dceafg dcagf ba | abd dfbge abd gacb
gcdea gc agfdce egdfa egcf fbeagd aecbd dgc fcebgad cagfbd | acebd egcf defag gfadceb
fab begadc ebcad dfbea gfcdab acdfgbe fa fedgb adcfbe feca | cbgead bfcdega fba gbadce
gb efcagd fgcad cfbg bedca abg fcgbda dgbcafe acbgd bdafeg | abcdgf bcgf cgfb bg
fbcagd fcdae beacgf gf agf baecdg fecag bgfe cagdbef gbcea | edbagfc ebfg gebf bgcae
cdgfea bdeacf aefcgb dbca beafc bcgdefa ebdgf ad defab ade | dbcgefa da ade bacd
bcgaedf badecg cfegb afceg dcbf egdbfa gcedb gbf bf fgcdbe | bagfed bdagfe fdbc gefcbd
cegba bgeda cgefa cbde fegadb dagcbe acfgdb cb cbg ecbdafg | cdegabf ebgda bfgade ebgac
afbdg gdabec gcafdeb fc cfdeba bcf fgebdc cefg gcdbf ecdbg | fecg cdbefg gdbfc gfce
bgdfa egbf bcdgfa fe dfcbea aef feadgb edcag dagef afdcegb | fea cbedfa acdfgeb dfgeab
eacgfd caegdb gbfecad bdfce edcfa dgaf fea fa egdac aegbcf | af fa edbcf gdeacbf
baefg fedabcg gbfac gacbfe cb dfageb dcfag cgb bcea cfdegb | cabe eabc gfacd fgdcabe
fgdeac cgd ebdfga agefdbc bfcegd cdgbf cd cfabg dceb befgd | cgd cfgab fdgeb efbgd
aedgbf cgebda dbcagf gbf gbefd gdecf gdfabec fb eabdg feab | bf fbea cefdagb adgbe
fcgea fbgedca gbecfa efbadc efgd fcagd df cdfaeg fdc acgdb | efgac fcd dfceba fegac
egdfac cab cadbf gbdaf bc eadcf dcebagf dbecag fbdace cebf | cedabfg cgbaed bc efacbdg
be abcged afcgb ebg bgefc gebfcd cgefd efdb gdeafc daecgbf | gabedc dbeafcg debf febcadg
dgebafc cefdbg db edfb fcgdb fdceg dgecfa bdc abcfg baecdg | fegdca baecdfg bcd bd
fbgead cfab cdbgefa agcbdf aedgc fgcbd fa fagcd ecgbdf gaf | adgcebf gaf gaf af
debagfc eb fcedba ebc cgdab efdgac befa eadcf edabc gdbefc | bcdagfe fbae ecadb eabf
gaedcb bfcgd bcegf bagdcf fd aedfgbc bfd cbdga cabefd adfg | ecfbda cbfgda cfbadg fbgcd
agdcfbe bcfega cbeag ge dacfeb facged bcaef gbdac gce efbg | feabc acfbdeg aefbc gce
febcdg egdacb bedcf debfacg abdfce ba bae fbeda gdfea acfb | eadbf ab ab eab
cdfbg dfbcae dcabe egba ag cgdfea abdcg aefcdgb cga decagb | defabc edacb cbfgd ag
fgac dfgec eag cfbdge bacde ag abdgef bagfdec dcgfae agcde | aecbdgf gcaf efcgd befcdg
de gecad fbcgae gcafd dge edfbcg eadb eacfdbg bcedag acbge | gabce fcegba bgfcead ed
gbacd dbefcg fdcgae edgca afdeg aecf egc gfaedb dcfagbe ce | feac acegd caefbdg aecf
egacbd aedbc dagbc fcdagb ec bacefdg ace dcge ecfagb febda | afecgb fgdbac bcade cea
ceadgb cgaedf bfdge cfg cf fdgbc dgabc cfdabg gdcebaf bacf | gebdf fdeacg dafbgec cgf
bgfda gdcfae afce bfecgd ac acdfg afebdgc dgefc bdcaeg cag | gdbfec gcedf gfdaceb cegdab
fa fgeabdc bfga faedb fad ebgdfa daceb fgbcde fgdeb dafcge | efdab gcdfeb fa gabf
ebfc fb aedbgc ebagdf fab cgfeab gcdfeba acbeg abcfg gfdca | gbfac bgfeac bfa bcfga
fagdec gadebc cg cabfegd agdfb cbge dbeac cdfabe adcbg cgd | acgbed dgfeabc fdeacb dgbacef
fgbdc gbedaf bdgaf dfc cbfadg gfceb degcfa dc bacd gbafcde | dcf egfdca cd cdegaf
fcb aebf bf cafgb efgabc cgadbe egbadfc egbca gcfebd acdgf | beacgfd gebfcd dfbgec bf
bfgcd deb bfacdg ed fcebgd baefg dbaecfg efdc dabecg fdgbe | de gebaf dbcgfe bde
facgdbe gda ebdfag gabdf da cagfeb gebaf deaf dbagec dcfbg | egfba dgebca aefd cgdbf
deabg eg gdfacb bdfea egd gebfdca ecdgab acge dacbg cefgbd | eg dgcbef agcdb fadbceg
cafbged feacb gbafd dc gfdc agdcbf fcabd deabgf cad acgedb | fdcba egbfdac cad dca
dfagce fbd eabdfc gdfeb ebgfa dfabcge fdgce cedfbg bcgd bd | cdbg agbcefd db db
fdagec fcg gf gbace efbgacd ecgbfd dfcea caefg dagf dbecaf | acdegfb fg gbdfaec fadg
edfag bgfced dga ag cfbgdea bfdcag bfged decfa afedbg bgae | abeg dgaef ag edfgb
dcaegb fageb cdga begda adbce gd dge gbecafd cabfed cgfebd | gdaebc ged egd dcga
cfb agebfc fegb fb adcef afbec ebgdca bafdgc gbcea fdbeagc | ebfg gabce fbc agfdceb
fdcega cbgfea febg agdebfc cfe afecb gbcae ef bcdfa acgedb | fbgdeac egbf acfgeb bfge
fbadge dfgebc fbgacde bg fdage afdcge cedba agbf bge dgbea | adgbe fgba gabf fceagd
cfbda bgedca fgdcba abcfe dc agbfd dbc fdgc facbged dagfeb | cd fbcda fdcab fdgc
cdefa fbgdce aebdg geacd ebcdgfa gc cdg baegdc febdag gbac | fdeca cg dgfbcae bcgfde
gcadeb ef ecbfga acbgfed fbdga bcade dafcbe dcfe deabf feb | fdegacb agdbf fgbedac fcdbaeg
adgc fac ca gdfcae cfdegb gcdef adcfbe dgefcba cagef abgef | gcadbfe feabdc cdefg bgdeafc
cfdeba dega fga gadfec cdfabeg aecbfg cbdfg ag faedc dfcag | ag ga acfed cebfad
efcgb feagdc gdfbea fadc ac cea gadbfce cfgae aedgbc geafd | fcgeabd cafeg cbadge ca
ebfda cfgbea cgdbef fbadgec dgcb cedfga dg fdbeg efcgb gfd | fgdeb bfgcde ebfdg dg
dcafg facgdb bgfa dbacf ba gdcefa ecfdb cfegdba bac acedbg | gcbdaf fbadc begdac dgcbaf
eagf agedbcf acdegb abg gcfba fcegb befgcd fbcda ag ebcfag | dbcegfa bfecg cafdebg faeg
fbgcd cba fgacdb gabcdef fbgdec gdabc gacf bafdec begad ac | eacbdf badge acb becfad
eacbd dabfec dbgfeac ag eagdb fcdbag bga agec dbfge bacged | agecdb bag gebcdaf cdbea
bfgcd bcdegfa fdabgc da efgca cfagd efbdca cda dgfecb bgda | acdebf badfcg abdg cafgd
efcbgd cadefg cfegd dcgba cafedgb cagfd gaf acef fa bedafg | agf fcedg gefdcb cfdge
afdceg dcaf fd dfg aefgc gdbecf cafbdeg dbage ecagfb deafg | adefgc bfdecga fdg cefag
bfdacg dagbf abdefcg acfg fbcda beafdc egdab cfdegb gfd gf | bcafgd efgcabd cfga dcaegfb
dbage dfagbe cadfeb gfeb bae fabgdc be bafdg cdgea bgdfaec | fedacbg eb dfcbea eab
gebfd cfedga begfa dagbfc fgeadcb ecdgbf bced edfgc dgb db | dbec gadcfb db aefbg
dbcg fbagc bcf bc cdaebgf aegbdf faecg fdcaeb cdafbg afbgd | adfbg fadebgc dgbafc febagd

96
8.jl Normal file
View File

@ -0,0 +1,96 @@
include("utils.jl")
function parse_input(filename)
map(non_empty_lines(filename)) do line
notes, output = map(split, split(line, "|"))
end
end
function count_unique(strings)
length(filter(x -> x in (2,3,4,7), length.(strings)))
end
function solution8_1()
sum(map(count_unique, getindex.(parse_input("8.data"), 2)))
end
function solution8_2()
summe = 0
for (notes, output) in parse_input("8.data")
recordings = [notes;output]
# find length 2 => c,f
cf = first(filter(x->length(x)==2, recordings))
# find length 3 => c,f,a => a
cfa = first(filter(x->length(x)==3, recordings))
a = setdiff(cfa, cf)[1]
# find length 4 => c,f,d,b => d,b
cfdb = first(filter(x->length(x)==4, recordings))
db = setdiff(cfdb, cf)
d = "X"
b = "X"
f = "X"
c = "X"
# find length 5 =>
for fives in filter(x->length(x)==5, recordings)
common = intersect(fives, db)
if length(common) == 1
# is there one missing d,b? => present is d missing is b
d = common[1]
b = setdiff(db, d)[1]
else
# is there one with d AND b => has one of c,f => f (and thus c)
f = intersect(fives, cf)[1]
c = setdiff(cf, f)[1]
end
end
abcdf = "$a$b$c$d$f"
g = "X"
for sixes in filter(x->length(x)==6, recordings)
new = setdiff(sixes, "$a$b$c$d$f")
if length(new) == 1
g = new[1]
end
end
abcdfg = "$a$b$c$d$f$g"
e = "x"
for anything in recordings
new = setdiff(anything, abcdfg)
if length(new) == 1
e = new[1]
break
end
end
digits = Dict(sort(collect("$a$b$c$e$f$g")) => 0,
sort(collect("$c$f")) => 1,
sort(collect("$a$c$d$e$g")) => 2,
sort(collect("$a$c$d$f$g")) => 3,
sort(collect("$b$c$d$f")) => 4,
sort(collect("$a$b$d$f$g")) => 5,
sort(collect("$a$b$d$e$f$g")) => 6,
sort(collect("$a$c$f")) => 7,
sort(collect("$a$b$c$d$e$f$g")) => 8,
sort(collect("$a$b$c$d$f$g")) => 9)
result = 0
power = 0
for digit in reverse(output)
value = get(digits, sort(collect(digit)), -1)
result += value * 10^power
power += 1
end
# println("$(join(notes, ' ')) | $(join(output, ' ')): $result")
summe += result
end
summe
end
solution8_2()

10
8_ex.data Normal file
View File

@ -0,0 +1,10 @@
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce

1
8_ex_mini.data Normal file
View File

@ -0,0 +1 @@
acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | cdfeb fcadb cdfeb cdbaf

100
9.data Normal file
View File

@ -0,0 +1,100 @@
4567894301299921298789654345689439843295436789543298765432345678986789756901239998765634567895986555
3458963212989890989678943234678998764989945678932198764321456799215678949892398999854525658934895434
2348954329876799876567899195789469999767896989949019965432567897434569998789987898743212345695679423
1237895498765698765479998989890359878956789999898929876545678996545698987678976987654563456789798912
3456797987854569954398987678921298766545678998777899987766789987656987676569895498765676567899987893
4567989896543498765987876567892987655434567897656798799897894598767899565458789329876787678999876789
5679878789432579879876743458989876542123456996545987678998923459878998433347678910987898789998865678
8798765678921456989865432365678987678012345989439878569899012398989987321234567899998949898987654568
9987654688932368998765421234567898632125499878998767476789323987399876510126789998769434967896543456
2398543567893458999876510195978976543236989656989654345895439876210965432345678989754323456987432345
1987652356954567899985431989899987654549878949878943234976545985431986583556899679943212569898541234
0198621237899778999996569878789698765698765436567890125987689987642398874567976567894323498789210123
9239432348998989998987698765679549878789876323456789239898992398543498765678965456789434999654321234
8998543459987899987898798754678932989899985434567894398789943987659569898789654329899949898765432345
7987674569876789876789987643767891296929876765678965987656894998998979979898763210169898769896543456
6599795678965699965679876321458942965439987878989879898545899899987898965919874323456789656987654578
5459898789654569874589765432349899876598998989894998765434789789876567894301986545678998734598787689
4345979896543498763459896565456789987987989998763219896545697698765456965212397696989654321239898793
3254567965432987654567987886767891299876767899854323987676789569876345894343498989898975434345999892
0123979879521098975678998997878910198965656789967456798789893498985256799454569978797896545656789991
1239899998632129996789989798989992987654547899996567899893912987654345678965698765686789656767899989
4398789876543234989899976659999989998743234598989699989932102398965457789898789654345898787878999878
6987654997654399878999865545898678999654123987678989876545293459878968898769899983236789898989998767
9876563498969989769899854236789567898763234976567878989676989598989879997656999874345899949899989756
9765432349898876658789743145678978999854569865453569998789878987899989789743298765456789234789876545
9897561298767435345697653234567899989967698774312478999898767856789997678932109876567892125678987634
8999990129854321234589754745678999879878987685101387899997656345678954567893212987678943034599299846
7898889298743210125678965678989998767989999543215456999898743237567893478954563499789956745989398767
6787678987654321367889876989999887656799898654323567898765432123456789589765679599899877659878989878
5674569898765432456789987898998786545698798765434678979878741012367998678978798989924989798767878989
4323498789878543567897698967899654323987679878555789567997652323458998789989987678912398987856567899
3212347678989697689976569458789765219886587989676894456989543456767899893499876567893987996543456789
2101234567898798797895435365698954398775456898789932349879656567878954901298775456789896789612345678
3232345678979899896789423234567965699674345679894321298968987678989543212987654345698765678923458989
4563656789765932945678910123679899986545234569965432987857899799898954329898765257789674567934567897
5674767899854321234789543234598798997632123678996949876546978998767899998789954348998543456895688976
6789898998765430123897654345987687889875012399989899985434569987658998875657895767987432388996789765
7895919987654321234998765499876576778964323989878789876323568998899987764546789879876321276989899876
8954323498765434345699878987655485567895439876567678987212567899999876543534995989865410125678999987
9765434679876595456789989987643213458996545985434569874323456789998765432323894399986423234789998998
7976765789987876567994399876543201246789759886323498765434569899879894321012789459876534345689987989
6989876894598987878973234997875212345678998765434999876545679998767987652345678967987649876798765678
5492987923679598989862125987654345456789329876565899987786789987656399543458789978998956987899654568
6321098912395439799654434598765456567893212987876789699898899876543297654567893989879987898998743489
5499999101987325678969547679976787998999543498989896545999932999632198775878932398767898969997632378
6987893245896534567898956789987898949698956569193987659899891098949019896989991987654329459876541267
9876789356789645678987897996598989434567897692012798998789789987898923987899989998763212345998765459
8765678969898756789256789543459876323456789789125679989678679876767994598999878989854301456789876567
5874789998979867894345678932398765614347899899434599876534598765656789679998767678965212367899987678
4343467897767998965456789321459654301256789998765987988323989854345678999987654589654343479999898789
3212989926456999987567895432396543212367899899899876543219876543236799989876543458965494989698769894
4343499212347894398878989693987665323456789789989987695499965432125678978985432367896989896569654923
5454578901456943219989878989998786734569897679878798986989876743234599769876921456999976789696543219
6567689212567899324599967678999897895878944598765659987976987654345678956989890967898765698987654998
7678998343456898935679756567899998976989432129654745698965498765458789545698789899987654567898769897
8789997654597987899798743456789879987896545098743434899876569896567890124987698768894323458999998786
9897898765989876568987654567898765698989652196542123987987678989698921239876567656789214567899989645
9956789879876543456798765678989854349678943987663039876498789878999632345985454347898996789979878434
9745698998767432345679896789876543234567894598754198765339899867996543459876321238957889895659762123
8634567899654321238789997898987654349978965679865299873210998759889654569985432349546778954349843234
6525898998765432345893298967898795998899876789876789954321989645678965678996543489435568893234956785
5436789129887643458932139456789989876789987895987899977439876434599876789987687678923456789125987996
6545679012998786567891012345899876765898998934598999876567965323689987895398798789212345699934598987
9876789199129987698972357896789995854567899325679999987679873212347898943219999892103479789895679298
3987899988997598789765456789899984323456789212389989898989932101236789992103498943212567998789792149
2198979876789459899896987999939876434598994323459878799999876512345699983212987654323456789678989234
3239567965679345999989898998929987545989987654598765634789965423457999874323498767654567898567878945
4999459854567956789878789987898797659876998765965834323679876567568998765454999878765678997434569896
9878398765699897898765679976545698998965789899894321014567987698989549878969891989889789986545789789
9765129876986789989874798765434569987654891998789543223478998789794323989998710195999897987696897678
8654234989875679876743459983125689998785992989678965354567899895699456799987623234599976798789977567
9766545698764568995432369894012378999876789878567896765678932923988998899876544395989897899898765456
9878656799853656789321298765623567894987898765456989896789671019977789921987895989878789978987632345
9989867987942345693210129898794678923498949987345678987896532198866678930298999876765678954596543456
9896979876543456789521345999898789213999239876239789498986545987755567891979998765874567893987656567
8755699987654567897432567899989892109878998765458991349997679876643456789767987654323456912998767778
5444598798767678996543456789876989298767879986767890145989998965432387893458998765534567899889898989
9323497679989789987894568998765678987656767897878921239876897896521298932347899876765678965678999496
8939986545698993498989979349654349876545856998989432398965986789430989549456910997876889954567894325
7898965434577892109879893298743212965432147899996545987654875678949878998967891298989997892349993214
6587894323456943998765789349892109876543236789987659876543534567898767897898932999292356793498989323
5456789434567899899854578998765412987656745893299767985452123679987656786789999899101236789987879434
4345678946678998789943469549894329898767856794999879876321014989699542345999987678912345699996768965
3235789987889997678912568932985498769878967989899989965432127894598431259899976567893456789865657896
2124899998999876589893467899876987654989879876789999876543236893987640198788893478999567998754346789
4235998989998765498794878945987896543296999765678998987664345992987651987677789567898979899893235678
5345987878999654346689989234598987654345989654567897898785456789298769876545678978957898789762124568
5459876567898953234579890123499998785459876543678965439976567892129898987634389899545987689654335679
6798765456587892145656789294989899896567985432349876521989878921019987896521256789434596578965445799
7999874343456921012345999989876789987679876545678965439997989532198756965432345694323987459878556789
9899983212457892123456789876765695498789987658789997698976596545349867896545696789109876367989769899
9789874343468943234567899985634789219898998969899989987897697655459878987856789895414995499999878998
8676965656578998745678999894323478901987899878999879876789798798767989498979899954323986989899989987
6565698767889109656789698765434567899876789989898765765678999899878995349989998765456899876789899886
5454569878999998767895549898745679978987897696789654344567899945989965210995439876787898965678789765
4323456989769899878934135987656789567898976545698743213456789434597894329874321987898987654565678954
5434567893656789989321014598967993456799895434997654302345678923456789459765210298959996543534567893
6547978932345678995432323459978942367898754329876543212456789014567896598654354349543985432123489932
7656889321256789876543434567899431234789843212987655433469894323478987698765565458932976543234567891
8798995432367899989656657678976532345678932101298766545678965435689998799876676567891098764546678910

86
9.jl Normal file
View File

@ -0,0 +1,86 @@
include("utils.jl")
function parse_input(filename)
map(x->parse.(Int, x), split.(non_empty_lines(filename), ""))
end
function sink_locations(width, height, heights)
sinks = []
for x in 1:width
for y in 1:height
minimum = true
if x > 1
minimum &= heights[x - 1, y] > heights[x, y]
end
if x < width
minimum &= heights[x + 1, y] > heights[x, y]
end
if y > 1
minimum &= heights[x, y - 1] > heights[x, y]
end
if y < height
minimum &= heights[x, y + 1] > heights[x, y]
end
if minimum
push!(sinks, (x, y))
end
end
end
sinks
end
function solution9_1()
input = collect(parse_input("9_ex.data"))
width = length(input[1])
height = length(input)
heights = reshape(reduce(vcat, input),(width,height))
sinks = sink_locations(width, height, heights)
risk = 0
for sink in sinks
risk += heights[sink[1], sink[2]] + 1
end
risk
end
function basin_size(x, y, width, height, heights)
heights = copy(heights)
to_visit = [CartesianIndex(x, y)]
visited = []
while length(to_visit) > 0
current = pop!(to_visit)
if current in visited
continue
end
push!(visited, current)
if heights[current] == 9
continue
end
if current[1] > 1
push!(to_visit, CartesianIndex(-1, 0) + current)
end
if current[1] < width
push!(to_visit, CartesianIndex(+1, 0) + current)
end
if current[2] > 1
push!(to_visit, CartesianIndex(0, -1) + current)
end
if current[2] < height
push!(to_visit, CartesianIndex(0, +1) + current)
end
heights[current] = -1
end
length(filter(==(-1), heights))
end
function solution9_2()
input = collect(parse_input("9.data"))
width = length(input[1])
height = length(input)
heights = reshape(reduce(vcat, input),(width,height))
sizes = map(sink_locations(width, height, heights)) do sink
size = basin_size(sink[1], sink[2], width, height, heights)
end
reduce(*, Iterators.take(reverse(sort(sizes)), 3))
end
solution9_2()

5
9_ex.data Normal file
View File

@ -0,0 +1,5 @@
2199943210
3987894921
9856789892
8767896789
9899965678

3
utils.jl Normal file
View File

@ -0,0 +1,3 @@
function non_empty_lines(path::String)
Iterators.filter(!isempty, eachline(path))
end