Post History
C (gcc), 301 bytes Function taking in an array of null-terminated strings and the array's length. #include <string.h> #include <stdlib.h> char*s="edellowreenrowncarletlackchreachuby...
Answer
#2: Post edited
# [C (gcc)], 302 bytes- Function taking in an array of null-terminated strings and the array's length.
- ```c
- #include <string.h>
- #include <stdlib.h>
char*s="d llow een own arlet ack hre ach by ive olet wn lac ld ocolate uve eam imson lver se ure mon sset ey rple ite nk ange ue";int g(const void*a,const void*b){return strstr(s,*(char**)a+2)-strstr(s,*(char**)b+2);}void f(char**a,int l){qsort(a,l,sizeof*a,g);}- ```
- [Try it online!][TIO-kscnji8v]
I shamelessly stole the idea of removing the first two characters from [user](https://codegolf.codidact.com/users/53837)'s [solution](https://codegolf.codidact.com/posts/283376/283384#answer-283384).- [C (gcc)]: https://gcc.gnu.org/
- [TIO-kscnji8v]: https://tio.run/##hVPBjpswED0nXzFiVQkIabtJTmW3Uo899djDdg/GGLBi7KxtEmWj/HrTGQMK2RwqIXn8/N54PLzhy5rzy@VBaq66UsCT81bq@nPzfT7FSiULwnjDbOqeoxKUMgcQQoM5aGBWCQ@Mb6GxAtcGiiPIvQBDOBIU46BKMNwo5gV0eCRYC7J1Bg/3woJDFLUt7p1DkTiC3SkBEul6C0zXSBBRLrWHOuZGOw97I8uUZZNNkZys8J3FJN7iF7ssjUPRacIWq2R5DxcI52dSQzVgLKNbVHJ6c8b6mGUqc/JdmApPaiTftKuUhjozDxl22Dz/w1p2HFNZm0HIJnQCp/msMhZiAiQ8w9cclyc6y2GxkIEwCzmqOPrkIMqwtfZFvib5fHaen4dbvHB@yO9vs4/aP/qn3nX@G0SknFSFfOIiWE3iq@xX5/@ju3KJgyXR/S2TOg4VUFmQhhIfX17xjaeotugTfEpUKPyDuFpRhq1F70Tn/Ea0GkVGBRKKj8Mq7sjrgWy7AknRUZArMQgX9NIPis19@r62ih3CemjQcRSwd/RjqNY40VePBqdg15EzKTKWfEmRk@TiQA@1XB@rJOoo4DbYPWSQettDOAWBJNr@xHbk/unDjcJBomAvaZooalnXQ7wZJoo24@sxvcARvHaYkvCmf4zjYVbHv0DdCW4K/yuDTTIFVhmsb4D1R8Ymg34y@ubCl3Gbhj0Z5PKXV4rV7rL8zZS6LHeiZNpL/g8 "C (gcc) – Try It Online"
- # [C (gcc)], 301 bytes
- Function taking in an array of null-terminated strings and the array's length.
- ```c
- #include <string.h>
- #include <stdlib.h>
- char*s="edellowreenrowncarletlackchreachubyliveioletawnilacoldhocolateauvereamrimsonilverosezuremonussetreyurplehiteinkrangelue";int g(const void*a,const void*b){return strstr(s,*(char**)a+1)-strstr(s,*(char**)b+1);}void f(char**a,int l){qsort(a,l,sizeof*a,g);}
- ```
- [Try it online!][TIO-kscnji8v]
- ~~I shamelessly stole the idea of removing the first two characters from [user](https://codegolf.codidact.com/users/53837)'s [solution](https://codegolf.codidact.com/posts/283376/283384#answer-283384).~~ Note: My original solution had a bug where the `wn` from `fawn` matched the `own` from brown and broke the order. This updated solution only removes the first character, making `rown` and `awn` distinct.
- [C (gcc)]: https://gcc.gnu.org/
- [TIO-kscnji8v]: https://tio.run/##hVPBjpswED0nXzFiVQkIabtJTmW3Uo899djDdg/GGLBi7KxtEmWj/HrTGQMK2RwqIXn8/N54PLzhy5rzy@VBaq66UsCT81bq@nPzfT7FSiULwnjDbOqeoxKUMgcQQoM5aGBWCQ@Mb6GxAtcGiiPIvQBDOBIU46BKMNwo5gV0eCRYC7J1Bg/3woJDFLUt7p1DkTiC3SkBEul6C0zXSBBRLrWHOuZGOw97I8uUZZNNkZys8J3FJN7iF7ssjUPRacIWq2R5DxcI52dSQzVgLKNbVHJ6c8b6mGUqc/JdmApPaiTftKuUhjozDxl22Dz/w1p2HFNZm0HIJnQCp/msMhZiAiQ8w9cclyc6y2GxkIEwCzmqOPrkIMqwtfZFvib5fHaen4dbvHB@yO9vs4/aP/qn3nX@G0SknFSFfOIiWE3iq@xX5/@ju3KJgyXR/S2TOg4VUFmQhhIfX17xjaeotugTfEpUKPyDuFpRhq1F70Tn/Ea0GkVGBRKKj8Mq7sjrgWy7AknRUZArMQgX9NIPis19@r62ih3CemjQcRSwd/RjqNY40VePBqdg15EzKTKWfEmRk@TiQA@1XB@rJOoo4DbYPWSQettDOAWBJNr@xHbk/unDjcJBomAvaZooalnXQ7wZJoo24@sxvcARvHaYkvCmf4zjYVbHv0DdCW4K/yuDTTIFVhmsb4D1R8Ymg34y@ubCl3Gbhj0Z5PKXV4rV7rL8zZS6LHeiZNpL/g8 "C (gcc) – Try It Online"
#1: Initial revision
# [C (gcc)], 302 bytes Function taking in an array of null-terminated strings and the array's length. ```c #include <string.h> #include <stdlib.h> char*s="d llow een own arlet ack hre ach by ive olet wn lac ld ocolate uve eam imson lver se ure mon sset ey rple ite nk ange ue";int g(const void*a,const void*b){return strstr(s,*(char**)a+2)-strstr(s,*(char**)b+2);}void f(char**a,int l){qsort(a,l,sizeof*a,g);} ``` [Try it online!][TIO-kscnji8v] I shamelessly stole the idea of removing the first two characters from [user](https://codegolf.codidact.com/users/53837)'s [solution](https://codegolf.codidact.com/posts/283376/283384#answer-283384). [C (gcc)]: https://gcc.gnu.org/ [TIO-kscnji8v]: https://tio.run/##hVPBjpswED0nXzFiVQkIabtJTmW3Uo899djDdg/GGLBi7KxtEmWj/HrTGQMK2RwqIXn8/N54PLzhy5rzy@VBaq66UsCT81bq@nPzfT7FSiULwnjDbOqeoxKUMgcQQoM5aGBWCQ@Mb6GxAtcGiiPIvQBDOBIU46BKMNwo5gV0eCRYC7J1Bg/3woJDFLUt7p1DkTiC3SkBEul6C0zXSBBRLrWHOuZGOw97I8uUZZNNkZys8J3FJN7iF7ssjUPRacIWq2R5DxcI52dSQzVgLKNbVHJ6c8b6mGUqc/JdmApPaiTftKuUhjozDxl22Dz/w1p2HFNZm0HIJnQCp/msMhZiAiQ8w9cclyc6y2GxkIEwCzmqOPrkIMqwtfZFvib5fHaen4dbvHB@yO9vs4/aP/qn3nX@G0SknFSFfOIiWE3iq@xX5/@ju3KJgyXR/S2TOg4VUFmQhhIfX17xjaeotugTfEpUKPyDuFpRhq1F70Tn/Ea0GkVGBRKKj8Mq7sjrgWy7AknRUZArMQgX9NIPis19@r62ih3CemjQcRSwd/RjqNY40VePBqdg15EzKTKWfEmRk@TiQA@1XB@rJOoo4DbYPWSQettDOAWBJNr@xHbk/unDjcJBomAvaZooalnXQ7wZJoo24@sxvcARvHaYkvCmf4zjYVbHv0DdCW4K/yuDTTIFVhmsb4D1R8Ymg34y@ubCl3Gbhj0Z5PKXV4rV7rL8zZS6LHeiZNpL/g8 "C (gcc) – Try It Online"