diff options
author | Ian C <ianc@noddybox.co.uk> | 2021-12-10 15:04:44 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2021-12-10 15:04:44 +0000 |
commit | 4a00a5935086c964ac04263fa42ac81658de99fe (patch) | |
tree | 1b7073bcb3323a4f97753dc0188ea2467df44bf3 | |
parent | c52a19c71cf16346c5de5e21425063047311b786 (diff) |
Added data for day 10 and started work on day 8, part 2
-rw-r--r-- | 8a.c | 49 | ||||
-rw-r--r-- | data.10 | 90 |
2 files changed, 119 insertions, 20 deletions
@@ -2,6 +2,13 @@ #include <stdio.h> #include <string.h> +struct digit +{ + char sig[10]; + int digit; + int unique; +}; + static char *ReadLine(char *p, size_t size, FILE *fp) { if ((p=fgets(p, size, fp))) @@ -17,27 +24,26 @@ static char *ReadLine(char *p, size_t size, FILE *fp) return p; } -static int GetDigit(const char *p) +static int CompareLen(const void *a, const void *b) { - static struct - { - const char *sig; - int digit; - int unique; - } digit[10] = - { - {"acedgfb", 8, 1}, - {"cdfbe", 5, 0}, - {"gcdfa", 2, 0}, - {"fbcad", 3, 0}, - {"dab", 7, 1}, - {"cefabd", 9, 0}, - {"cdfgeb", 6, 0}, - {"eafb", 4, 1}, - {"cagedb", 0, 0}, - {"ab", 1, 1} - }; + const char **pa = a; + const char **pb = b; + int l1; + int l2; + + l1 = strlen(*pa); + l2 = strlen(*pb); + + return l1 - l2; +} + +static int CalcCodes(struct digit digit[10], char *signal[10]) +{ + qsort(signal, 10, sizeof signal[0], CompareLen); +} +static int GetDigit(const struct digit *digit, const char *p) +{ int check[10] = {0}; int f; @@ -79,6 +85,7 @@ int main(void) char buff[0x8000]; char *signal[10] = {0}; char *digit[4] = {0}; + struct digit dig[10]; int num = 0; int sum = 0; int f = 0; @@ -92,13 +99,15 @@ int main(void) signal[f] = strtok(f == 0 ? buff : NULL, " |"); } + CalcCodes(dig, signal); + for(f = 0; f < 4; f++) { size_t len; digit[f] = strtok(NULL, " |"); - num = GetDigit(digit[f]); + num = GetDigit(dig, digit[f]); result[f] = '0' + num; } @@ -0,0 +1,90 @@ +[[<<<{<<<(<<(([]())(<><>))<[{}()][(){}]>>(([()[]]<{}()>)[<[]{}>[(){}]])>)>([{<<<()()>[<>() +[<[<{[[({[({{[(){}][()[]]}<[{}<>](<>[])>}{<[{}{}][<>()]]{{[]}{[][]}}}){(([<>{}]<(){}>))<({<>{}}{{}{}}){[[]<> +[<<<[{{[[{({{[<>{}][()]}}[[[[][]][{}<>]]])<{(({}<>)<()>)<[{}<>][()()]>}>}(<{[[()()]{{}()}]>[<<{} +([[{<{{({<[{[([][]){[]<>}>(<[][]>[<>()])}([<<>><{}<>>]{({}{})[{}[]]})]>})[[[<<(<()[]>{<>() +{([<(({[[<{{[[{}<>]({}[])><{(){}}{()()}>}<<[()[]][{}[]]><[<>{}]([]{})>>}([(<(){}>{{}()})<<{}{}>{[]{ +[[(<{[<(<<([<{<>()}<<><>>><({}{}}{{}[]}>]{[{<>()}(<>{})]{{()[]}{(){}}}})><<{({<>[]}[<>[]]){[()[]]}}((<<>{}> +{([{({([((<<{(()())<<>[]>}<{()[]}({}<>)>>({<{}()>[<>{}]}[<(){}>{()<>}])>{[<{<>{}}>({()[]}<<>()>)]({({}<>)<{ +{([((<{({[[{<{<>{}}>}{[{{}{}}({}{})]{[[]])}][<[<{}{}><()()>][(<>{})]><<{{}{}}({}{})>>]](<[([{}()]({}()))[( +(({<{[{{([<{[<()()>]<{{}()}{[][]}>}<{[<>()]{()[]}}<(()()>{{}()}>>>[<{{[]<>}}>]]{{[{{[][]}[[]{}] +[(((<{({<{<(({<><>}({}()))<[()()]{()<>}>)({(()<>)[(){}]}<{{}[]}[{}{}]>)]}{([{[[]()]{{}{}}}[((){}){<> +({{{((<(<<<[<({}<>]{<>{}}>{{()<>}{<>()}}][[[()()]{[]<>}]{[{}][[][]]}]>>>)>{{({({{{()<>}(<>{})} +({[[(<[[(((([({}<>)[()[]]]{<()()>[[][]]})([[<>{}][()()]]{{<>{}}[{}[]]})})[<{<(<>[])({}[])>}{<((){})>{{{} +{[<<{([[<<({{((){})(()[])}(<[]<>>{()[]}))<[[<>][[][]]][(<><>)<<>()>]>){{[<<>()>(<>[])]([()[]]{() +<[{({<<[{[[({[[]]([]{})}[(()())<<>{}>])([[<>()]<[]{}>][{<>()}<[]()>]}]](<<{{{}<>}<<>[]>}<(()())>>>{{<[[]]<<>< +<[[<(({<({[[<[{}[]]{()()}>[[<>{}]]]<(<[][]>[{}{}]>>]})[({<[[{}[]](()())](<{}<>>[{}[]])>[(<<>{}>({}<> +[([([(<[({([[(()()){()()}]])}<[{<[<>{}]>{<[]()>{()()}}}][<<[[]}[[]<>]>([[]()](<>()))>[{{(){}}({ +({[[<((<{[<{({[][]}<{}{}>)<[[]()][()()]>}>(<[[(){}][()[]]]{[<>][<><>]}>([[()[]]{<>{}}]{[<>]{<>[]} +[({<{<((({{<{{[]{}}(()[])}>}<{[[<>()][{}]]{<<>{}>[[]()]}}{<<[]{}>>[<<>()><<>()>]}>}{{{[(<>())(()[ +<(<<{(<(([[[<[<>{}][()()]>({{}{}}[[]{}])]][<<<<>()><<>{}>>[{[][]}]>([{[][]}<()()>]<<{}<>>>)]]<<{({<>()}{[] +((<<(({{<{({<<<>()>[()()]>((<><>)<(){}>)}({<()<>><<>()>}{(<>())[[][]]}))<({(<><>)([]())}<<[]<>>( +({(<<[{<<<{<{([]{})<[]<>>}<<<>()>(<>{})>>[[{[][]}{()[]}](<<><>>)]}([[{{}{}>(()[])]{({}<>)<[][]>}](<<()<> +{{<[<[{([({[([(){}](()[]))([{}<>][[]{}])]}({[({}{})](({}{})[{}{}]))<{(()())}{[[]()](<><>)}>))]{(<{{[() +[{[{({<{<([<<<{}{}>[[]()]>{<[]<>>(()[])}>{([()<>]<()()>){[{}{}>(<>[])}}]((<{<>{}}<{}{}>>)))[[<<<()() +{({({<[([<[{[(<>[])<<>[]>]}{<(<>()){{}<>}>({<>{}}<<>[]>)}][(<[{}()][<><>]>([<>()]))]>{({(({}())<[]()>)}[ +({((<{{([[{<{<<><>>([]<>)}{([]()]{<>()}}><{({}<>)(()())}{[()<>][{}[]]}>}(<{{()}[[]{}]}{[[][]][[]()]}>(([< +{{<[<[{[({{[{(()[])[[]<>]}<{[]<>}{[]<>}>]}(({[{}<>]{<>[]}}([{}()]))(<[{}[]][[]{}]>{(()<>)}))}{[[[([]())(()< +[{{[{[[([{(([((){})[{}()]>{{[][]}(<><>)})[<<{}{}><()<>>>({[]()}[{}{}])])}[[<[({}{}){[][]}]{(()())<{} +{[<(({[(({[{[<[][]>[<>()]][(<>()){<>[]}]}]([{[{}()}<<><>>}[<()[]><[]()>]]{<[()()][<>]>({<>{}}{()()})}) +((<<[<(({{<({{()<>}(()())}{{[]{}}}){<[[]{}][[]<>]><<<>()>{{}<>}>}><({[()<>]})<<((){})[[]<>]>>>}{(<[[ +(([<({[[{{((<(()<>)<<><>>><{()<>}[[][]]>))}{({<((){})(<><>)>}<{[<>[]][()()]}[<()><[]{}>]>)<[(((){})<{}[]> +<{[<{<{(<({(([{}<>]<()<>>)[{{}<>}(()<>)})(({()<>}<[]{}>)({()}))}[[({[]}<<>[]>)[[{}()][[]<>]]][{{ +(<[([[((<<<(([{}{}])([()()](()<>))){[[{}{}]<()[]>]{<[]()>{{}{}}}}>{([[()()](<><>)]){{<(){}>} +([({<[([[<<<<(<>())({}[])><[{}<>](<><>)>><[<()[]><<>()>]{{<>[]}([]<>)}>>>]<[[<{[(){}]([]{})}([[]{}] +([{([[([[{([<{{}[]}(()<>)><<{}<>>[<>[]]>]{[(<><>)[<>()]][{{}{}}]})}{<[{([]())[[]]}<[[]{}][<>()]>]>([<[<>< +[{<[([{([([({<<><>>(<><>)}{[{}{}]<()>})])[[[<{<>{}}[[]()]>{<<>>[[]<>]}]<<<<>{}>([][])>({()()}[[]<>])>]]] +(([{(({(<([<<(<>())[{}<>]>>({(()[])[<>()]})]<[([(){}]<{}<>>)<((){})<[][]>>]({(<>()){()<>}}[{()()}<( +{<{{{({{{{([<([]{})<<>[]>><{[][]}{[]<>>>]([<[]<>><()[]>]{[{}<>](<>[])}))<({(()<>)([][])})>}{[<<[{} +((<({[([{<<<{([][])[[]]}{<<>[]>[{}[]]}}>((<[()]{()()}>){[[<><>]([]{})]})><<[<{<><>}[()()]>(<[]{}>([]())) +[<[{[[[[{{{(([{}[]]<{}[]>))[{<[]<>>}[([][])([]())]]}(([([]{}]]<({}{})<<><>>>)[<{{}[]}<{}()>>[< +<([<{[{<[<{<<{(){}}[{}<>]>({[]{}}}>}<<({[][]}{[]<>})[(()<>)({}<>)]>>><[{({<>}([]<>))[<{}<>> +{[[{(<(<<([[<<[]()><{}()}>]<<{<>[]}([]{})>{[<>[]]<{}[]>}>][[[<{}()>({}<>)]]<{<<>>}<<[]{}>>> +([{<<<(<[([<([[]{}]<[][]>)<{<>[]}[[][]]>>{{{<>{}}[[][]]}{[{}()])}]{(<[<><>]<()<>>>){([{}()][<>[]]) +[{[[<{[<<{{[([[]{}])]}<[<[{}()]{(){}}>[<()[]><()()>]]>}({{<<{}<>><{}[]>>}[<<<>{}>{(){}}>]})>><[ +[{[{<[<(([[{{{()()}<()<>>}[[[]<>]<[]()>]}{{<{}{}><<>[]>}[([]<>)[{}{}]]}]{{<<()()>[[][]]><{()()}(()())>}}] +([<{{(<(<<(<([()[]]<<>[]>){{()()}(<>[])}>)<[<[<><>]{()[]}><<{}{}>{[][]}>][([()[]]<{}[]>)<<<><>> +[{<{[[{<([{[<[<><>]{()()}>[({}<>)]]}({[(<>{})<{}<>>]{[<>()][[]{}]}}[<([]<>)(<>[])>[[()()]{ +(<{{(<({[(<{[([]())[[][]]][(<>())]}>)[<<[{{}<>}<<>[]>][({}())<[][]>]><[([][])]<{()()}({}{})>>>[([<(){}>{{}[] +[([<(<{{{{{[[(())<[]<>>]([()()])]<{{<><>}(()<>)}[<<>>[<>{}]]>}(({{<><>}{<>}}[([])<{}()}]){{<{}()><[]() +(<[[[({(<(<[{({}<>)<<><>>}]>(<[<[]{}>{{}()}][[<>()](<>)]>))<{{<{(){}}[<><>]>[<()<>>]}[(<<>{}><< +[([(<[[({<<([{(){}}([][])]{[[][]][{}<>]}){<({}()){<>{}}>[((){})[[][]]]}>((<<[]{}>>({<>[]}]){<(<>( +(({<(<(<({{({<[]()>})[<{<>{}}{<><>}><(<>[])(<><>)>]}{{{{<>{}}(())}}<[{{}<>}<{}{}>]{(()()){{}{}}}>}})>[(<{({[< +([<[([<{[[<({<()[]>}{{{}{}}[()[]]})(<[{}[]]{<>{}}><{{}[]}<[]<>>>)>{[[{{}[]}<[]{}>]{{<>{}}<{}()>]]<[{<>[]}[ +{{[([<<{((({{{[]}(()[])}[({}{})(()<>)]}(((()){()[]})[<{}<>)<{}{}>])){[<<{}()>[()<>]>[(()<>)[()[]]]]})({{[ +{<<[<({<[[<{((()[])({}())){{{}[]}<{}()>}}{<<[][]>[(){}]>((<>{})[()()])}>]{{{{[[]()](()())}(< +<<{[{<{([{{{[{()<>}}[<<>[]>]}}{(<[<><>]<<>{}>><[()<>]({}())>)<{<<>{}>[<><>]}[([]())<<>>]>}}][{[[{[<>[] +[(({{{{({({{<{[]()}>(({}{}){<>()})}})<(<(<[][]>)[<<>><[][]>]>(<(<>[])(<>())>))>})<<<[{<({}[]){()[]}>[ +({{<(<{({{[[<[{}()]<[]<>>>([()<>]<[]<>>)][[[<>{}]{()()}]{{[]()}<()>}]][([[()<>][[][]]]<({}[]){<>}>)[<<{} +[<(<(<[([<<{<[[][]][<>{}]>}(<{{}()}{(){}}>)>>]){([<{(<[]{}>{()}){[{}()]<<><>>}}{{<<>()>}]><[<<[][]>[[]<>]> +<({[{(<(<[({((()())[<>()])[<{}[]>({}())]}{{([]())<<><>>}{[{}()]{{}{}}}})[(<{<><>}<[]{}>>[[[] +<[<[<{({{[<[(([]<>)<[]<>>)<{[]<>}{()[]}>]<<<{}<>><{}>><[{}{}]<[]()>>>><(({<>[]]<[]{}>))[{<[]{}><[]<>>}(( +<<{<(<{{(<{<<<(){}>[[]<>]>>({[{}()]<{}>})}<[<{[][]]{<>[]}><{{}[]}<[]{}>>]([{{}()}]{<()><{}[]>})>>)}<[<[< +[<<{{<[[([<{({[]()}{[]<>})<[(){}]<()[]>>}<[{<>()}<{}<>>]>><<[<(){}><()[]>]{[[]()]}><{{()[]}{(){}}}{[[] +[<{((<{(({{<{{()<>}[<>()]}((()[]))>}([({<>()}[<>{}])<({}{})<()[]>>][<([]())<{}{}>>[({}{}){[]{}}]])}){ +({[{{{<(<[[([{<>()}<{}<>>])({[[]<>]{{}<>}}[({}())<{}<>>])]([{<()()>}({()[]})])](<<{[{}{}][<>[]]}{[<>](()[ +{<{{([<<[({({<(){}>[<><>]}[<<>{}>{{}[]}])}[[[<(){}>[[]()]][{[]()}]]<([()[]][[]<>])[<{}{}><<>[]>]>>)<<[ +<<(<{{(({<<(<{{}{}}{{}<>}><{[]<>}{{}()}>)>{{<{[]()}[()()]>[<[]()>{{}{}}]}<(<[]()>{()()})[[[][]]]> +<{<[{{<[((({<<[]()>{()[]}>}{{[(){}]{{}()}>{[{}[]]((){})}})<([[{}()]{[]()}])>)){<[[[<<>[]>{[]} +[<(({[(<<<<<{[<>[]][[]<>]}(<<>()>{[]()})>><[(<<>[]>(()<>))<([]{})({}{})>]([[(){}]]{[{}[]]([] +<[[({[((<[{[({[]<>})({[]{}}[()()])]}<[[[<><>]<(){}>]{(<><>){[]<>}}][<{<>[]}{<>{}}>([<>()])]>]<((<{[][ +<<[{([{<<<[[[{()[]}([]<>)]<({}()){[]()}>](<((){}){{}<>>><{{}()}{[]<>}>)]>>><<<<<[{[]}]>{({()<>}( +([([{<{{{[([({{}<>}{()()>)]<{[()()]}({(){}}[[]<>])>)[({<<>{}>}[[()][<>[]]]){[<()[]>]}]]}<[(<(({}())[( +([<[<{{({<{({[()[]]{[][]>}[[<>[]]<<>{}>])<<[[]]{<><>}>({[]()}[{}{}])>}[{<[{}[]]<{}()>><<()[ +((<<({<<([{<<((){}){{}()}>>}([<{{}()}({}{})>[<[]>[{}{}]]]<[({}[])[<>{}]][(<>{})<(){}>]>)])(<[<{{[]()}[<>()]}[ +[{([(<<([[<(({[]{}}[<>])[{<>{}}{<>{}}])((<[]>))>][{[[({}()){[]{}}]]<([()][{}{}])>}({(<[]()>(<>() +(<([((<<[{[<[[<>{}][{}{}]]>]{(<(<>[])<{}[]>>{(<>[])[()<>]})[{{<>()}{{}[]>}{{(){}}[<>[]]}]} +<{{[{{<[{{{[<[<><>]{()()}>((<><>)([]()))]<{<()()>[()]}<<[][]>{{}[]}>>>{[{{[]<>}}[{()<>}([][])]]} +<{<<[({((({<(<{}>[()[]])((()){{}{}})>({([]<>)[[]{}]}[([]()){[][]}])}{(<{()[]}(<>{})>{{<>[]}[[]{}]}){[( +(<{[<[{<[(<<<{[]()}[[]<>]>{(()<>)([]<>)}>(({{}()}))>[([{<>[]}]{[<><>]<[]{}>})(<<[]<>>{()()}><[<>{}] +{<{<<{<<{{{<(<{}><[]<>>)({(){}}[[][]])><{{[]()}{<>{}}}>}}{[[[{[][]}([]())][([]<>){<>}]]][<((< +{(<{[[[{([{[<<{}>[(){}]>[<[]()>([]())]]({({}[])[[][]]}({{}{}}(()[])))}{(([()[]]{{}[]})<{<>[]}<()[]> +[[{{<{(([{{{[(<><>)]({{}[]}[()])}<<<<>[]><{}())><([]{})>>}<<{[[]()]{{}{}}}{{[][]}[()<>]}>>}<<([{[ +(<({[<{<({<[{<[]{}>[<>()]}]<[{()[]}<()[]>][([]{}){()()}]>>})>}[<([{{<({})<[]<>>>{{<><>)}}[[([])[ +{[{({[[[[{(([{(){}}<[]<>>][{<>()}<[]()>])([(()[])]{{{}}([]<>)}))}{{{<[{}()][<>()]>{{()()}[( +{{{[[({{{{<[[{{}{}}((){})]<<<>{}><<>[]>>]>{<[[{}[]]{[]()}][<[]()>{{}}]>{[(<>{}){[]{}}]{(()[])((){})}}}}{ +(<[{({<(([<((<{}{}>[[]{}])[<()()>[<>{}]])>(<[<[]()>{{}[]}]{<{}<>><()[]>}>{{[<>[]]<{}>}<{{}<>} +[{({<{[{[[{([<[]>[()()]]<{()[]}>)}[<<<[]>[()()]>>]]]<{<<{((){})<<><>>}[([]{}){(){}}]>>{([[<> +[{<[[(<(([([[[{}<>]({}[])]{<()<>>{{}{}}}))]{[([<{}<>>{()[]}][(()<>)([][])]){([[]()][{}{}])<[()<>]{ +<<(<{[<{{[<([{()<>}<()()>]<<[]{}><[]<>>>)>]({[<([]{})[<><>]><{(){}}<[]()>>]})}[({[[<<>>(<>{}) +{({<{[<<({{(([(){}](<><>)))({{<><>}[[][]]}{({}()){<>{}}})}{<[((){})]<([]())>>([[{}<>]{()[]}])}})([<[{[<><> +[[<[[<({<(<({({}<>)[[][]]}){<<()><[][]>>[({}())[()[]]]}>[(((()())([]())))])>({({{{()()}({}())} |