parent
b9bb36966a
commit
303194dfbc
|
@ -3,5 +3,5 @@ project(aoc_2021 C)
|
|||
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
|
||||
add_executable(aoc_2021 src/main.c src/day_1.c src/day.h src/day_2.c src/puzzle_input.c src/puzzle_input.h src/day_3.c src/day_4.c src/day_5.c src/day_6.c src/day_7.c src/day_8.c src/day_9.c src/queue.c src/queue.h)
|
||||
add_executable(aoc_2021 src/main.c src/day_1.c src/day.h src/day_2.c src/puzzle_input.c src/puzzle_input.h src/day_3.c src/day_4.c src/day_5.c src/day_6.c src/day_7.c src/day_8.c src/day_9.c src/queue.c src/queue.h src/day_10.c src/stack.c src/stack.h)
|
||||
target_link_libraries(aoc_2021 m)
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
<([<({{[<{{((<()>({}{})}<({}<>)>)}}>[<{(([()<>]<<>{}>))}<{({<>[]}<<>>)[([]<>)<{}{}>]}>>]]}}[<[{{[{{[<><>]
|
||||
[<{{{[((({<<<[()[]]{()()}><{<><>}(<>{})>><<{<><>}{{}[]}>{(()())[[]{}]}>>{[[(<>[]){<>{}}][(()())(()[])]]
|
||||
(((<{<[[<[{(((<><>)[{}{}]){{{}<>}[()<>]})(([<>()][<>{}]){{[]()}})}[({([][])<{}<>>}{[[]<>]{()
|
||||
[(<{<[<<<<[[{<[]()><<>()>}[{{}<>}<()>]]<<[[]{}]>{({}())}>]((((<>())<(){}>)<{[]{}}<(){}>>)[{[[]<>]<[
|
||||
[[{(<{<<[{(<({<>{}}<()[]>){<<>[]>{<>}}><[[()[]]]{{()<>}{()<>}}])[{[(<>())]<<[]{}>(<>[])>}<[{
|
||||
(<<<[[<{({<<([{}{}](<><>)){{<><>}(())}>{<{(){}}{[][]}>[{[][]}([]())]}><([{{}[]}[[]{}]](<[]{}><{}<>>))((<(){
|
||||
<<<{((<<{[([<[[]{}]([][])>{[<>()][[][]]}]<<[()[]][[]{}]>[<<><>>(<><>)]>)<({{{}<>}{{}}}{{<><
|
||||
{[(<[{{{<[{({([]{}){{}{}}}[({}<>)])[([()[]]<[]{}>)<[{}{}]{{}()}>]}(<{{{}<>}(()[])}>{{<()<>><[]<>>}
|
||||
[<<{({[{((({<<<><>>(()())>{{[][]}<{}()>}}[[((){})[{}()]]<[()<>]>]){{(<{}<>>[()<>]){{[][]}(()<>
|
||||
({[([([<(<<[{<<><>>({}())}[[(){}][[][]]]]>><<(({<><>}{[][]})<{()()}[[]<>]>)[{((){}){{}[]}}(<<>()>{{}()})]><<
|
||||
[[[{[<({{<[[[<{}{}>(()())]{(<>[])([][])}]({{(){}}})]<[<{{}[]}{()}>[{<><>}]][<((){})([][])>]
|
||||
[(<{<{(<<<<{{[[][]]<()[]>}){{<<>{}>}}>({[(()())(<>[])]}(<{()()}[<>]>{[[]]<<>()>}))>(<[{({}{})}][{[{}()]
|
||||
<(<<[([[((<<{<[]{}>{{}<>}}(({}())[[]{}])>(<{<>()}[()()]>>>))]{<{{<(<()<>>{{}()})([{}<>](<><>))>
|
||||
[{[<[([[<[((([()[]]<{}{}>))<{[{}()][(){}]}([{}<>]<()<>>)>)]>[{((([{}()]{()()>)<(<><>)(()[])>)[(([]()
|
||||
{[{[{<<([({<<[{}()]<()<>>>{[[][]]({}())}>}[[<{{}<>}{<>}>]])(<<{[()[]]}(((){})({}{}))>[({{}()})]>)](
|
||||
({{{<<<<(([([[<><>]<<>[]>]{<()<>><()[]>})<([<>{}])>])(<<{{()}<()[]>}<([]<>)>>{{[{}()][[]<>]}[{<>}{()()
|
||||
[{(([{<{{(<{<<[]()>{{}<>}>}[<({}[])<{}<>>><{<>()}>]>)}<{{{{<<>{}>{()()}}}[[{()()}(()<>)><<{}<>>>]}[[(<(){}>(
|
||||
[[{<[<(<[[<<({{}()}{{}})(({}{})[[]{}])>[([<>{}]({}<>))])]{<[<[[][]]<()<>>>]{([()()]{<><>})<{[]{}}[[]()]>}><
|
||||
([<<{({[({[({<{}[]>{{}<>}}){<[<>[]]>[(()())]}]{{{{{}[]>{()<>}}}<[{{}<>}<[]()>]([<>]<<><>>)>}})
|
||||
(([<[[{{(<[{{(()<>)}<<{}()>{<>{}}>}<[<[]()>[()()]]([<>()]{()})>)[(<[<><>]{{}<>}>{{{}()}{[]()}})<
|
||||
[([[[([[[<[{{<()()>{[][]}}(<[][]>)}[{<{}()>{<>[]}}]]>({[[{<><>}<[][]>]([()]{()[]})]}{([<<><>>[{}(
|
||||
(<({<[[[[(((({[]{}}<{}<>>)[<(){}>[()<>]])){<(<<>{}>)<<()<>><()[]>>>{[[()()]<[][]>][{{}()}<<>{
|
||||
{{{{[[<{<{(<(([]())[{}[]])<(()<>){{}{}}}>){{{<{}[]><{}<>>}{(()[])[<><>]}}<{{()()}<<>[]>}>}}><(<[(<{
|
||||
<<[(<<<([{<{(({}())[{}[]])(<(){}>(<><>))}>([[(<>[])(<>[])]<({}{})<{}>>](((<>())<{}[]>)[[<>
|
||||
<{{((([[<{[(({<>{}}({}())))[([[]()][{}{}])]]}(([<([][])<<>()>>]<{{<>[]}(()())}[({}())[()()]]>)
|
||||
(({[{[[[[(<<[[(){}][(){}]]<{()<>}<[][])>>{({[][]}{<>{}}){<[][]>}}><{(([]{}){{}<>}){[()<>][(
|
||||
{<[[<<([<{<<{[<>{}}{<><>}}(({}()))>[[{[]()}](<<>>{<><>})]><<([<>{}]{[][]})[<{}[]>{<><>}]>>}{[{(<<>()><{}<>
|
||||
({{{((({<<({<[<>()](()[])]}){((<{}()>{[]<>}){<[]{}>[[][]]})<[[[]{}](())](<{}<>>[{}])>}>[{{[(<>[])]}[<({}{
|
||||
{<(<[{({[[[{[[{}<>][(){}]]{{(){}}}}<<[[]()]{<>}><[{}[]]>>]{<<((){})[{}]>({<><>}{()[]})><<[{}()]{
|
||||
[[[(({<((<({<<{}>>}<[([]{})[[]]]>)<<{[()[]](<><>)}><<{[]{}}[[]]>{{()[]}{[]()}}>>><[((<(){}
|
||||
{{<{{{<<{<{<((<>[])<()[]>)<(<>{}){[][]}>><(({}<>){[][]}){[()<>]{<>{}}}>}>[((<<(){})({}())><([]
|
||||
[[[{({<[{[[<<(()<>)({}())>({<><>}[<><>])>]]<(<{<()<>>([]())}{[[]<>]{<>()}}>{<([][])((){})>([{}][()<>])})>}]<(
|
||||
<<{[{[[<([[<<[{}<>]>[({}())<()[]>]>[{<(){}><{}<>>}[<<>>({}{})]]]<<{<()[]><()()>}({{}()}[{}<>])>>]<<([([](
|
||||
{<<<(<{{[{{{<<{}[]>{()()}>{[<>[]]({}())}}}<[<([]())>{<()()>(()())}][<(()())<{}<>>>((<><>)[[][]]]]>
|
||||
[[[({<(([[(<({()<>}<[]<>>)>[({[]}{<><>})<<(){}>{<><>}>])]]<(<[<<()()]<{}()>>(<{}()>([][]))]<<{<><>}>>>){
|
||||
<<[[<({<({[<{(()[])}{{[]()}<[]{}>}>]<[(<[]{}><<>{}>)<[()[]]([]{})>]>})>((<([<[<><>]([]{}}><{<>()}<()[]>>]{
|
||||
({[[[{{([[((<<{}<>}[{}<>]>)(({{}<>}<()()>)[[[]<>]<()<>>]))<(<{[][]}>)<{{[]<>}<[]<>>}[(<><>){(){}}]>>][<
|
||||
{<[[[[[<[[{{{{()}[[][]]}[<(){}>[[][]]]}(<[{}{}]>)}(<<<()()>{<>}>>)]<([[[()<>]((){})]([[]()]<{}{}>)]([{{}(
|
||||
[<(({(((<[(<<[[]{}][<><>]>[{(){}}[[]]]><{{()[]}<<>()>}{{()}{(){}}}>)(<[([]())]<{{}{}}(())>>)]([([{()[]}[[
|
||||
(({[([{{((({{<<>[]>}}<([{}[]][[]()])[{{}[]}<<>{}>]>)<({([])<[]{}>}){(((){})[<>[]]){<<>[]>[{}()
|
||||
<{<{(<<({([([([]())(<>[])][{()<>}{<>{}}])](({<()()>{()<>}}{{[]}[[][]]})[[[{}{}][()[]]]])]}(({[[{<>()}[{}()]
|
||||
[[{[{{[({<{<(<{}<>>)[[{}{}>[<><>]]>[((())([]<>)){([]())<<><>>}]}>{{{<{<>[]}({}{})>{([]{}){[][]}}}[{{<>
|
||||
[[{[<([{([<<<(<><>){[]{}}>{{[][]}([]<>)}>><{<<<>()>{<><>}>[<[][]>([]())]}({[{}[]]{<>()}}({()()}(()<>)))>])}])
|
||||
{{<((([<[({{(([]){[][]})[(()<>)<()()>]}{{{()[]}}([()[]][{}{}])}})<{({[()[]]<[]{}>}[<()()><()[]>])
|
||||
([<<<([{{<({{[{}<>][<>()]}{([]<>){(){}}}}){({<{}()>}[(()){<><>}])}><{<(<()[]>({}{}))(({}{})
|
||||
{{[([<[{<<{<{[{}[]][(){}]}[[[]()]{()[]}]>}><[(([<>{}]){{<>()}{()<>}}){[{<>{}}[[]<>]]{<[]<>>}}][[[{[]<
|
||||
{<<<<{(((<{([{{}{}}][[[]()]<<>()>])<([()<>]([]))[[<><>][{}()]]>}{<{{(){}}<()<>>}<{<>{}}{<>()}>>(<{
|
||||
<[({<{{{<((<<({})([]<>)>((<>[]){[]()}}>)(<[<(){}>({}[])]>[<({}<>){[][]}>[{()<>}<<><>>]]))>[({[([<>{}][{}()])<
|
||||
(({[[{<{[[((<[<>()]><{()<>}[[]<>]>)([{[]()}[[]()]](({}{}){<>()})>){<{(()())(<>[])}[<()[]>[()()]
|
||||
[(([{{<{<[{{{[{}{}]<(){}>}[<[]{}>({}())]}({[()[]]{[]()}}[<{}[]>(<>)])}[{{<[]{}>(()<>)}<[[]()]<<>[]>)}<<<<>()
|
||||
<(<<{<([([(<[{{}<>}<()()>][{()[]}(<><>)]>{{<[]<>><{}[]>>{{{}}{[]<>}}})({[<[]{}>[[][]]]}{{<
|
||||
((<<<([[<<{([<<>{}>{<>()}])<<{[]{}}[()[]]>>}[<{([]())[<>{}]}>{((()[]){{}<>))[<()<>>([]<>)]}]>{(({[[]]
|
||||
{<<((({({[<[[[<><>][<>{}]]{({}<>)<()[]>}][<<[]{}}<[]()>>[[[]<>]]]>([[[{}{}]]<<<><>><<>{}>>
|
||||
[{<([{{<{(<{{{(){}}{{}[]}}(<<>()>[()[]])}{{{{}}(()())}{[()<>]}}>[{[{[][]}{{}<>)]}((((){}){[]{}})(({})<<>{}
|
||||
[{[(<[{<{{[<{{()()}{()[]}}<<()()><{}[]>>>][<({()()}[()[]]){([][])[<>{}]}>(((()()))((<>{})<{}{
|
||||
(<(<([<<<{[<({<>}{()()})><((<>))<<{}[]><<><>>>>]{<{[[][]]}{{[]{}}{[]<>}>>[[[[]()]({})]]}}><<<<
|
||||
<([<(<<<(({{<[<><>]<[]<>>>(<[]()>[{}<>])}[<(()()){{}<>}>]}))<<[{{[<>[]]<()[]>}{(()<>){()()
|
||||
<[(<{{[[[<(([[<>()]([][])])){{{[()()]{{}[]}}[([]{}){(){}}]}{[<[]>{[]()}][[<>]({}())]}}>]]<(<[{<{<>()}{()[
|
||||
<{{{[(<{<[<{{<()>(<>{})}[({}()){()()}]]([{<>{}}[()()]](<[]<>><<>{}>))>[<{<[]()>(<>)}<{[]{}}[(
|
||||
<{(<[<[<{<({<[<><>}[[]()]>}([<(){}><<><>>][<()()><<><>>]))([[([]())<{}>]<[()()]{<>{}}>]{(({}
|
||||
<(<({(<[<[(((<<>{}>{{}()})){{[[]()](())}{{<><>}<<><>>}})([<<()()><[]())>[[<>()]<<>[]>]][<{()()}
|
||||
((<[{{(<[([<([()()](<>{}))(<{}()>[{}{}])>({<{}{}>(<>[])})])]>)}<({((([(<[]{}>({}[]))]{((<><>)(()()))}))(({{<{
|
||||
{({[<<[(<<((<<{}[]>[()<>]>{<<>[]>{[]()}}){[<<><>>[()[]]]<<{}()>[()<>]>})[{[{{}<>}{()}]}<(<()[]><{}{}>)[[
|
||||
{{[<((<((<{[([[][]]<{}<>>)((()[]))]}>{[{(({}())[()[]]){{[][]}([][])}}](<<[<><>]{<>}><<{}<>><[][]>>>
|
||||
[[[<(<{{([{(<(<>{})(()<>)><(<>[])[{}()]>)([[[]()][[]<>]])}[[{<[]()>(<><>)}[(()){<>()}]]({{[]()}})]])[[
|
||||
<({([{(<{{[<<[(){}][[]()>>[[{}{}](()[])]>]{{[[{}<>]{{}<>}]{({}<>)[{}{}]}}[({()()}[{}<>]){((){})}]}}{{[[{{
|
||||
[[[[{<[<(([<[<[]{}><<>{}>]<<[]<>>(()[])>>([(<>)<{}()>])])<{{({[]{}}{[]()})}<[[<><>]{[]<>}]{<<>()><<>()>}>
|
||||
<<<[([[(({(<[<{}>[{}()]]{{()}(()[]}}>(<<<>()>(<>[])>))<<[{<>()}{<>[]}][{[]{}}<{}[]>]>>}){<<<(<<>
|
||||
{{<[{{({{(([[([]{})<{}()>]]))){(<{{<<>[]>(<>[])}<<()><[]<>>>}>([([<>()]<{}[]>)(({}{}))]<<([]())[<>
|
||||
([<[({[{{[[[({<>{}}<(){}>)({<>[]}{()<>})](([(){}]{[]()}))]<[<(<>[])({}<>)>][[[[]{}]<()>]<<<>[]>{[]<>}>]>]
|
||||
{[{[[{<(<<({{([]<>)([]{})}<<{}<>><<>[]>>}(({()()}[{}()]){(<><>)[<>[]]]))<<[([])(<>[])]{([]())(
|
||||
({<<{{[<<[{{<[(){}][[]]><{[]()}<[]{}>>}[<<<>()>{{}()}>[<{}<>>[<><>]]]}](<<[(<>{})[()]}{<<>><[]
|
||||
<<<([{[([{{[{[[]<>][<>[]]}]}{<([[][]]){[<>[]]<{}()>}><(<[]<>>(<>{}))[<[][]>{<>}]>}}{<{{[<>{}]{()
|
||||
<((<([([<{<[([{}<>](<>()))<([]<>)([]<>)>][<{()<>}{[]<>}>]>}<{[(<[]()>(<><>))[<(){}>[[][]]]](<([]())<<>[]>>[
|
||||
{[<[<<{{(<{[{((){})<{}[]>}[([][])]]}{[({()<>}){[{}<>](<>{}))]}>)}<[[(<(<()<>>){(()())([]{})}>({[{}[]]
|
||||
<([[<({{[<({[({}{}){{}()}]<((){})[<><>]>})([[{[][]}<()<>>]<[()<>][{}{}]>])>]}}){{[(({(({[]()}{()()}
|
||||
<({([<[{(<[{(({}[]))}[[{[]<>}{{}[]}](({}[]))]]<[[(()[])[()()]]{[{}()>}]>>{<<{[[]<>](()())}[<{}[]>(<>
|
||||
(([[<(<<[{<(<[{}{}]{()<>}>)((<(){}>([]))({<>{}}[<>[]]))>(<<{()[]}{(){}}>[[<>()]]>[<{()[]}<()[]>>{({}<>){[]<
|
||||
{<[<<{(<{{<[{[{}()][<><>]}][{({}{})(<>[]))]>{<[[<><>]]<<<>()>({}[])>>({<[]<>>([]<>)}{[(){}]([]{})})
|
||||
{{<((([<{(([{[<>{}]{{}<>}}])<<<{<>[]}{(){}}>{(()[])[()[]]}>{{<<>()>}([(){}]{{}<>})}>)}{(([{{{}[]}(<>())
|
||||
{[(<{{{<[[{{[[()[]](<>{})]((()<>)({}[]))}}]][{([[{{}[]}<[]<>>]][{(<>{})}[(<>()){<><>}]])}>>[([
|
||||
<<<{([((<<{(({{}{}}({}{})))}{(<(<><>)[[]<>]>{[{}[]](<>)})<{{<>()}{{}<>}}<<<>[]><<>()>>>}>>))]){
|
||||
<{(<[[(({<[{{<<><>><{}<>>}<<<>{}>{()()}>}]>}))[((([([{[]{}}]([{}()][<><>]))(((<>())(<>]))][
|
||||
([<<[({(({{((<[]{}>{()[]}})({[<><>][<>()]}(<<><>>[[]()]))}{{{(()<>)({}{})}(<{}()><[]()>)}{{{<><>}
|
||||
[<<<{{<<{<{<<[()()](<><>)>>([({}){{}[]}]{<[]()>{{}()}})}<[{([]())<{}<>>}([{}()]<{}[]>)]<(<[]
|
||||
{{<[({({<{({((()<>)){[[]()]<(){}>>}<[[{}]{<><>}]<(()<>)<()()>>>)}(({((<><>)[{}[]]){[[]()][()[]]}})<({
|
||||
<[{<({<({(({{<(){}>[[]{}]}<<[][]><{}{}>>})[(([{}()][<>()]))[(<<>{}>([][]}){[[]{}]}]])[<[{(()<>)[{}<>]}]>]
|
||||
([(([{<(<{[<{([][]){[][]}}(<<>><[]{}>)>({[<>()]{{}<>}}(<<>[]>{<>{}}))][({{[]()}{[]}}(([]{})(()<>))
|
||||
<{<<<({[[(<<{(()<>)[[]{}]}<<()()>>>><[({()[]}[[][]]){<[][]>(<><>)}][(({}{})<()[]>){{{}()}<[]{}>}]>)[<((([]{}
|
||||
<([[([<<<{<<<<<><>>({}())>{{[]()}[{}[]]>>[<[<>()]({}{})>]>(({<{}{}>{<>{}}}{<{}[]>{{}()}}){[<[]()>{()<>}
|
||||
[{{<{[{{{<{{<([][])[()<>]>{{[]{}}({}())}}((<<>[]>([][])))}><{<<<{}<>><<>()>>{(()<>){[]{}}}>}{([{[][]}{<>{}}])
|
||||
[({<((({(<{[{<[][]}(<>[])}<<{}<>>{{}<>}>]({{<>()}[{}{}]})}(<{{{}()}<<>[]>}[([]{})<[][]>]>[{(<>
|
||||
<([[[<{{<<<[(((){})(()()))([<><>]{()})]<<[<>]([])>(([]<>))>>{{[<()>]<(()[])([][])>}[({{}}<{}{
|
||||
{<<((<[{<{<[{[[][]]{<><>}}{<(){}>{<><>}}]<((<>{})<<>[]>)>>((((<>[]){[]()})({<>()}))([[{}[]]{<>[]}]<
|
||||
(<{(<[[([[([<({}{})[()<>]>])][<{<({}())><{()()}>}>{[{[{}<>]([])}](([()()]))}]])]]>)}>[[({{
|
||||
(<[[[{<{[<([{({}{}){{}()}}[(<>{})<()()>]][{{{}()}}<{<>[]}[()<>]>]){{((<><>){()<>])<<<>()>[{}[
|
||||
<{<<[((<<<{([{{}<>}({})]{((){})[[]<>]})<[[()<>]([]())](<[]<>>({}<>))>}{(<{()[]}>{<[]<>>})<
|
||||
{[([<[<[({{[<[<>()][{}[]}>((<>())<[]<>>)]{(<{}<>>(()()))([()()])}}}<(<(<<>{}>{<>{}})><({[]{}}[
|
||||
{{[[[<<<<[[{({[]<>}<()()>)<<(){}>{<><>}>}{[([]<>)[<>[]]]}]{<[{()()}(<><>)]{{<>{}}<[]{}>}>((<{}()>{(){}}))}>>>
|
||||
({[<[[<{<([<<<()<>}<{}{}>>(<<>[]>(<>()))><{[<>()]({}<>)}<{[]{}}>>])>}{{{<{({[]{}}<<>>)<<[]<>
|
||||
([((((<(<[({((<>())<()<>>)}([<{}()>{<>()}]{{{}()}{[]<>)}))([<(<>{})><[(){}][<>()]>](([()]<[]{}>)(<{}{}>{()
|
||||
{[(<{({(<([(<[{}()][{}()]>)[[[{}()](()())]<{[][]}<[]<>>>]][({[()()]{{}{}}}((<><>)(<>())))<<{()()}{[]{}}}[{[]
|
||||
<([[{<<{<<{(([()<>]{<>[]})<<[][]>({}[])>)({<{}{}>([]<>)})}{<{{[][]}{[]{}}}[((){})((){})]><([[][]]){{()()}}>}
|
||||
(([<[[[(({{[[[[][]](<>())]{<<>><<>()>}]<<(()<>)>[<<>{}>{<><>}]>}[<(<<><>><{}{}>)[<()<>><[]()>]>[{<()[]>[<
|
||||
{[{{{[(<<[<[{[()()]<{}<>>}[([]<>)({}<>)]][<{()()}[<>[]]>]>]>>)]{([({[{({<>}(<>{}))[({}())[[][]]]}<{{()[]
|
||||
(<(<{<{<[[(({[<>[]]<{}[]>}[([]{})(()[])]))({([[]])([()()]{()[]})}<[<<><>><[]<>>]>)]]<([{{{{}<>}(<>)}}<({
|
||||
[<[{[<<[<<[<{<<>[]}<()>}{(()[])[{}[]]}><[<(){}>{{}[]}]>]>(((<{{}<>}{()[]}><<<>{}>{()[]}>)[[(
|
||||
[<{(<[<{{([{{<<>{}><[]()>}({(){}}[[]{}])}{[<[][]>[<><>]][<<><>>[{}{}]]}](<<{(){}}({}<>)>(<()[]>[()[]])>
|
||||
<[{<({((([(<([[]<>]<()[]>)<(<>())>>(<{[][]>(<>{})>[{(){}}]))])))}<<{({<<<([]{})([]())>[{()()}<()<>>]
|
||||
<[(<{((({<<{{[{}<>]}[[<>{}]({}[])]}{(<{}[]}{<>})<{[]()}[()[]]>}>>}))(<<[<<(<<>{}><<>{}>)<<
|
|
@ -10,5 +10,6 @@ int day_6();
|
|||
int day_7();
|
||||
int day_8();
|
||||
int day_9();
|
||||
int day_10();
|
||||
|
||||
#endif //AOC_2021_DAY_H
|
||||
|
|
|
@ -0,0 +1,193 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "puzzle_input.h"
|
||||
#include "day.h"
|
||||
#include "stack.h"
|
||||
|
||||
#define MAX_LINES 200
|
||||
#define MAX_LINE_LEN 200
|
||||
#define NAV_DATA_SIZE (MAX_LINES * MAX_LINE_LEN)
|
||||
#define MAX_STACK_SIZE 100
|
||||
|
||||
static char nav_data_g[MAX_LINES*MAX_LINE_LEN];
|
||||
|
||||
static char stack_data_g[MAX_STACK_SIZE];
|
||||
|
||||
typedef enum {
|
||||
NONE,
|
||||
PARENTHESES,
|
||||
SQUARE_BRACKET,
|
||||
CURLY_BRACKET,
|
||||
ANGLE_BRACKET,
|
||||
} char_classes_t;
|
||||
|
||||
parse_ret_t parse_str_line(char * buffer, void * data, uint16_t index) {
|
||||
char * nav_data = ((char *)data) + (index*MAX_LINE_LEN);
|
||||
|
||||
strncpy(nav_data, buffer, MAX_LINE_LEN);
|
||||
|
||||
return PARSER_OK;
|
||||
}
|
||||
|
||||
static int uint64_t_cmp(const void * a, const void * b) {
|
||||
uint64_t a_int = *(uint64_t *)a;
|
||||
uint64_t b_int = *(uint64_t *)b;
|
||||
|
||||
if (a_int < b_int) {
|
||||
return -1;
|
||||
}
|
||||
else if (a_int > b_int) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int day_10() {
|
||||
parse_ret_t res;
|
||||
uint16_t len;
|
||||
uint32_t syntax_error_score = 0;
|
||||
int autocomplete_ndx = 0;
|
||||
uint64_t autocomplete_scores[MAX_LINES];
|
||||
|
||||
res = read_input_single_line("../inputs/day_10.txt", (void *)nav_data_g, NAV_DATA_SIZE, parse_str_line, &len);
|
||||
|
||||
if (res != PARSER_OK) {
|
||||
printf("Failed to parse puzzle input: %d\n", res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (uint16_t line_ndx = 0; line_ndx < len; line_ndx++) {
|
||||
char * star_line_ptr = nav_data_g + (line_ndx * MAX_LINE_LEN);
|
||||
char * line_ptr = star_line_ptr;
|
||||
stack_t stack = {};
|
||||
stack_init(&stack, stack_data_g, MAX_STACK_SIZE, sizeof(char));
|
||||
uint8_t corrupted = 0;
|
||||
|
||||
while (*line_ptr != '\0') {
|
||||
char_classes_t invalid_char = NONE;
|
||||
uint8_t char_class = NONE;
|
||||
stack_ret_t stack_ret;
|
||||
switch (*line_ptr) {
|
||||
case '(':
|
||||
char_class = PARENTHESES;
|
||||
stack_ret = stack_push(&stack, &char_class);
|
||||
break;
|
||||
case '[':
|
||||
char_class = SQUARE_BRACKET;
|
||||
stack_ret = stack_push(&stack, &char_class);
|
||||
break;
|
||||
case '{':
|
||||
char_class = CURLY_BRACKET;
|
||||
stack_ret = stack_push(&stack, &char_class);
|
||||
break;
|
||||
case '<':
|
||||
char_class = ANGLE_BRACKET;
|
||||
stack_ret = stack_push(&stack, &char_class);
|
||||
break;
|
||||
case ')':
|
||||
stack_ret = stack_pop(&stack, &char_class);
|
||||
|
||||
if (char_class != PARENTHESES) {
|
||||
invalid_char = PARENTHESES;
|
||||
}
|
||||
|
||||
break;
|
||||
case ']':
|
||||
stack_ret = stack_pop(&stack, &char_class);
|
||||
|
||||
if (char_class != SQUARE_BRACKET) {
|
||||
invalid_char = SQUARE_BRACKET;
|
||||
}
|
||||
|
||||
break;
|
||||
case '}':
|
||||
stack_ret = stack_pop(&stack, &char_class);
|
||||
|
||||
if (char_class != CURLY_BRACKET) {
|
||||
invalid_char = CURLY_BRACKET;
|
||||
}
|
||||
break;
|
||||
case '>':
|
||||
stack_ret = stack_pop(&stack, &char_class);
|
||||
|
||||
if (char_class != ANGLE_BRACKET) {
|
||||
invalid_char = ANGLE_BRACKET;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("Invalid char: %c\n", *line_ptr);
|
||||
return -2;
|
||||
}
|
||||
|
||||
if (stack_ret == STACK_FULL) {
|
||||
printf("Need more stack space!\n");
|
||||
return -3;
|
||||
}
|
||||
|
||||
if (invalid_char != NONE) {
|
||||
corrupted = 1;
|
||||
switch (invalid_char) {
|
||||
case PARENTHESES:
|
||||
syntax_error_score += 3;
|
||||
break;
|
||||
case SQUARE_BRACKET:
|
||||
syntax_error_score += 57;
|
||||
break;
|
||||
case CURLY_BRACKET:
|
||||
syntax_error_score += 1197;
|
||||
break;
|
||||
case ANGLE_BRACKET:
|
||||
syntax_error_score += 25137;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
line_ptr++;
|
||||
}
|
||||
|
||||
if (!corrupted) {
|
||||
uint64_t autocomplete_score = 0;
|
||||
char_classes_t next = 0;
|
||||
while (stack_pop(&stack, &next) == STACK_OK) {
|
||||
autocomplete_score *= 5;
|
||||
|
||||
switch (next) {
|
||||
case PARENTHESES:
|
||||
autocomplete_score += 1;
|
||||
break;
|
||||
case SQUARE_BRACKET:
|
||||
autocomplete_score += 2;
|
||||
break;
|
||||
case CURLY_BRACKET:
|
||||
autocomplete_score += 3;
|
||||
break;
|
||||
case ANGLE_BRACKET:
|
||||
autocomplete_score += 4;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
autocomplete_scores[autocomplete_ndx++] = autocomplete_score;
|
||||
}
|
||||
}
|
||||
|
||||
qsort((void *)autocomplete_scores, autocomplete_ndx, sizeof(uint64_t), uint64_t_cmp);
|
||||
|
||||
int middle_ndx = autocomplete_ndx/2;
|
||||
|
||||
printf("PART 1: The total syntax error score is %d\n", syntax_error_score);
|
||||
printf("PART 2: The total autocomplete score is %lu\n", autocomplete_scores[middle_ndx]);
|
||||
|
||||
return 0;
|
||||
}
|
18
src/day_9.c
18
src/day_9.c
|
@ -117,7 +117,7 @@ static queue_ret_t queue_point(queue_t *queue, int pos_i, int pos_j, uint16_t ma
|
|||
return QUEUE_DATA_INVALID;
|
||||
}
|
||||
|
||||
return push(queue, &point);
|
||||
return queue_push(queue, &point);
|
||||
}
|
||||
|
||||
point_t q_data_g[QUEUE_SIZE] = {0};
|
||||
|
@ -127,12 +127,12 @@ static int flood_fill( int pos_i, int pos_j, uint16_t max_i, uint16_t max_j, uin
|
|||
point_t point = {0};
|
||||
queue_ret_t res;
|
||||
|
||||
init(&queue, q_data_g, QUEUE_SIZE, sizeof(point_t));
|
||||
queue_init(&queue, q_data_g, QUEUE_SIZE, sizeof(point_t));
|
||||
|
||||
point.ii = pos_i;
|
||||
point.jj = pos_j;
|
||||
|
||||
res = push(&queue, &point);
|
||||
res = queue_push(&queue, &point);
|
||||
|
||||
basin_counts[basin_count - 1] = 1;
|
||||
|
||||
|
@ -142,10 +142,10 @@ static int flood_fill( int pos_i, int pos_j, uint16_t max_i, uint16_t max_j, uin
|
|||
}
|
||||
|
||||
while (queue.queued_elements > 0) {
|
||||
res = pop(&queue, &point);
|
||||
res = queue_pop(&queue, &point);
|
||||
|
||||
if (res != QUEUE_OK) {
|
||||
printf("Unable to pop element: %d", res);
|
||||
printf("Unable to queue_pop element: %d", res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -163,28 +163,28 @@ static int flood_fill( int pos_i, int pos_j, uint16_t max_i, uint16_t max_j, uin
|
|||
res = queue_point(&queue, point.ii + 1, point.jj, max_i, max_j);
|
||||
|
||||
if (res != QUEUE_OK) {
|
||||
printf("Unable to push element: %d\n", res);
|
||||
printf("Unable to queue_push element: %d\n", res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
res = queue_point(&queue, point.ii, point.jj + 1, max_i, max_j);
|
||||
|
||||
if (res != QUEUE_OK) {
|
||||
printf("Unable to push element: %d\n", res);
|
||||
printf("Unable to queue_push element: %d\n", res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
res = queue_point(&queue, point.ii -1, point.jj, max_i, max_j);
|
||||
|
||||
if (res != QUEUE_OK) {
|
||||
printf("Unable to push element: %d\n", res);
|
||||
printf("Unable to queue_push element: %d\n", res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
res = queue_point(&queue, point.ii, point.jj - 1, max_i, max_j);
|
||||
|
||||
if (res != QUEUE_OK) {
|
||||
printf("Unable to push element: %d\n", res);
|
||||
printf("Unable to queue_push element: %d\n", res);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,9 @@ int main(int argc, char * argv[]) {
|
|||
case 9:
|
||||
day_9();
|
||||
break;
|
||||
case 10:
|
||||
day_10();
|
||||
break;
|
||||
default:
|
||||
printf("Invalid day ding dong!\n");
|
||||
return -2;
|
||||
|
|
|
@ -5,7 +5,7 @@ static size_t next_element(size_t index, size_t max_len) {
|
|||
return (index + 1) % max_len;
|
||||
}
|
||||
|
||||
queue_ret_t init(queue_t * queue, void * data, size_t max_data_size, size_t element_size) {
|
||||
queue_ret_t queue_init(queue_t * queue, void * data, size_t max_data_size, size_t element_size) {
|
||||
queue->data = data;
|
||||
queue->max_data_size = max_data_size;
|
||||
queue->element_size = element_size;
|
||||
|
@ -16,7 +16,7 @@ queue_ret_t init(queue_t * queue, void * data, size_t max_data_size, size_t elem
|
|||
return QUEUE_OK;
|
||||
}
|
||||
|
||||
queue_ret_t push(queue_t * queue, void * element) {
|
||||
queue_ret_t queue_push(queue_t * queue, void * element) {
|
||||
if (queue->queued_elements >= queue->max_data_size) {
|
||||
return QUEUE_FULL;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ queue_ret_t push(queue_t * queue, void * element) {
|
|||
return QUEUE_OK;
|
||||
}
|
||||
|
||||
queue_ret_t pop(queue_t * queue, void * store_to) {
|
||||
queue_ret_t queue_pop(queue_t * queue, void * store_to) {
|
||||
if (queue->queued_elements == 0) {
|
||||
return QUEUE_EMPTY;
|
||||
}
|
||||
|
|
10
src/queue.h
10
src/queue.h
|
@ -7,8 +7,8 @@
|
|||
typedef enum {
|
||||
QUEUE_OK,
|
||||
QUEUE_FULL = -1,
|
||||
QUEUE_EMPTY = -1,
|
||||
QUEUE_DATA_INVALID = -1,
|
||||
QUEUE_EMPTY = -2,
|
||||
QUEUE_DATA_INVALID = -3,
|
||||
} queue_ret_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -20,9 +20,9 @@ typedef struct {
|
|||
size_t element_size;
|
||||
} queue_t;
|
||||
|
||||
queue_ret_t init(queue_t * queue, void * data, size_t max_data_size, size_t element_size);
|
||||
queue_ret_t push(queue_t * queue, void * element);
|
||||
queue_ret_t pop(queue_t * queue, void * store_to);
|
||||
queue_ret_t queue_init(queue_t * queue, void * data, size_t max_data_size, size_t element_size);
|
||||
queue_ret_t queue_push(queue_t * queue, void * element);
|
||||
queue_ret_t queue_pop(queue_t * queue, void * store_to);
|
||||
|
||||
|
||||
#endif //AOC_2021_QUEUE_H
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
#include "string.h"
|
||||
#include "stack.h"
|
||||
|
||||
stack_ret_t stack_init(stack_t * stack, void * data, size_t max_data_size, size_t element_size) {
|
||||
stack->data = data;
|
||||
stack->top_of_stack = -1;
|
||||
stack->max_data_size = max_data_size;
|
||||
stack->elem_size = element_size;
|
||||
|
||||
return STACK_OK;
|
||||
}
|
||||
|
||||
stack_ret_t stack_push(stack_t * stack, void * element) {
|
||||
if ((stack->top_of_stack != -1) && (stack->top_of_stack >= stack->max_data_size)) {
|
||||
return STACK_FULL;
|
||||
}
|
||||
|
||||
memcpy(stack->data + (stack->top_of_stack * stack->elem_size), element, stack->elem_size);
|
||||
|
||||
stack->top_of_stack++;
|
||||
|
||||
return STACK_OK;
|
||||
}
|
||||
|
||||
stack_ret_t stack_pop(stack_t * stack, void * store_to) {
|
||||
if (stack->top_of_stack < 0) {
|
||||
return STACK_EMPTY;
|
||||
}
|
||||
|
||||
memcpy(store_to, stack->data + ((stack->top_of_stack - 1) * stack->elem_size), stack->elem_size);
|
||||
|
||||
stack->top_of_stack--;
|
||||
|
||||
return STACK_OK;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
//
|
||||
// Created by joey on 12/11/21.
|
||||
//
|
||||
|
||||
#ifndef AOC_2021_STACK_H
|
||||
#define AOC_2021_STACK_H
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum {
|
||||
STACK_OK,
|
||||
STACK_FULL = -1,
|
||||
STACK_EMPTY = -2,
|
||||
} stack_ret_t;
|
||||
|
||||
typedef struct {
|
||||
void * data;
|
||||
int top_of_stack;
|
||||
size_t max_data_size;
|
||||
size_t elem_size;
|
||||
} stack_t;
|
||||
|
||||
stack_ret_t stack_init(stack_t * stack, void * data, size_t max_data_size, size_t element_size);
|
||||
stack_ret_t stack_push(stack_t * stack, void * element);
|
||||
stack_ret_t stack_pop(stack_t * stack, void * store_to);
|
||||
#endif //AOC_2021_STACK_H
|
Loading…
Reference in New Issue