Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Coat of Many Colours

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...

posted 3y ago by Moshi‭  ·  edited 3y ago by Moshi‭

Answer
#2: Post edited by user avatar Moshi‭ · 2021-09-26T20:22:39Z (about 3 years ago)
Fixed a bug
  • # [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 by user avatar Moshi‭ · 2021-08-16T03:25:58Z (over 3 years ago)
# [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"