Skip to main content
removed explicit type for `c`, replaced `for` with `while` and inlined the increment
Source Link

C - 74 71 7164

This doesn't beat Peter Taylor's solution, but I think it's pretty fun (plus, this is a complete working program, not just a function)

main(int c,char**v){for(;*v[1]!=0;++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 
 
main(int c,char**v){for(;*v[1];++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 
main(int c,char**v){for(;*v[1];++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 
___ main(c,v)char**v;{while(*v[1])v[2]+=*v[1]++==*v[2];return*v[2];}

And ungolfed:

main(int argc, char** argv){ char * input = argv[1]; char * test = argv[2]; // advance through the input string. Each time the current input // character is equal to the current test character, increment // the position in the test string. for(; *input!='\0'; ++input) test += *input == *test; // return the character that we got to in the test string. // if it is '\0' then we got to the end of the test string which // means that it is a subsequence, and the 0 (EXIT_SUCCESS) value is returned // otherwise something non-zero is returned, indicating failure. return *test; } 

To test it you can do something like:

./is_subsequence banana anna && echo "yes" || echo "nope" # yes ./is_subsequence banana foobar && echo "yes" || echo "nope" # nope 

C - 74 71

This doesn't beat Peter Taylor's solution, but I think it's pretty fun (plus, this is a complete working program, not just a function)

main(int c,char**v){for(;*v[1]!=0;++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 
main(int c,char**v){for(;*v[1];++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 

And ungolfed:

main(int argc, char** argv){ char * input = argv[1]; char * test = argv[2]; // advance through the input string. Each time the current input // character is equal to the current test character, increment // the position in the test string. for(; *input!='\0'; ++input) test += *input == *test; // return the character that we got to in the test string. // if it is '\0' then we got to the end of the test string which // means that it is a subsequence, and the 0 (EXIT_SUCCESS) value is returned // otherwise something non-zero is returned, indicating failure. return *test; } 

To test it you can do something like:

./is_subsequence banana anna && echo "yes" || echo "nope" # yes ./is_subsequence banana foobar && echo "yes" || echo "nope" # nope 

C - 74 71 64

This doesn't beat Peter Taylor's solution, but I think it's pretty fun (plus, this is a complete working program, not just a function)

main(int c,char**v){for(;*v[1]!=0;++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 
 
main(int c,char**v){for(;*v[1];++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 
___ main(c,v)char**v;{while(*v[1])v[2]+=*v[1]++==*v[2];return*v[2];}

And ungolfed:

main(int argc, char** argv){ char * input = argv[1]; char * test = argv[2]; // advance through the input string. Each time the current input // character is equal to the current test character, increment // the position in the test string. for(; *input!='\0'; ++input) test += *input == *test; // return the character that we got to in the test string. // if it is '\0' then we got to the end of the test string which // means that it is a subsequence, and the 0 (EXIT_SUCCESS) value is returned // otherwise something non-zero is returned, indicating failure. return *test; } 

To test it you can do something like:

./is_subsequence banana anna && echo "yes" || echo "nope" # yes ./is_subsequence banana foobar && echo "yes" || echo "nope" # nope 
improved code sample
Source Link

C - 7474 71

This doesn't beat Peter Taylor's solution, but I think it's pretty fun (plus, this is a complete working program, not just a function)(plus, this is a complete working program, not just a function)

main(int c,char**v){for(;*v[1]!=0;++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 
main(int c,char**v){for(;*v[1]!=0;++v[1];*v[1];++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 

And ungolfed:

main(int argc, char** argv){ char * input = argv[1]; char * test = argv[2]; // advance through the input string. Each time the current input // character is equal to the current test character, increment // the position in the test string. for(; *input!='\0'; ++input) test += *input == *test; // return the character that we got to in the test string. // if it is '\0' then we got to the end of the test string which // means that it is a subsequence, and the 0 (EXIT_SUCCESS) value is returned // otherwise something non-zero is returned, indicating failure. return *test; } 

To test it you can do something like:

./is_subsequence banana anna && echo "yes" || echo "nope" # yes ./is_subsequence banana foobar && echo "yes" || echo "nope" # nope 

C - 74

This doesn't beat Peter Taylor's solution, but I think it's pretty fun (plus, this is a complete working program, not just a function)

main(int c,char**v){for(;*v[1]!=0;++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 

And ungolfed:

main(int argc, char** argv){ char * input = argv[1]; char * test = argv[2]; // advance through the input string. Each time the current input // character is equal to the current test character, increment // the position in the test string. for(; *input!='\0'; ++input) test += *input == *test; // return the character that we got to in the test string. // if it is '\0' then we got to the end of the test string which // means that it is a subsequence, and the 0 (EXIT_SUCCESS) value is returned // otherwise something non-zero is returned, indicating failure. return *test; } 

To test it you can do something like:

./is_subsequence banana anna && echo "yes" || echo "nope" # yes ./is_subsequence banana foobar && echo "yes" || echo "nope" # nope 

C - 74 71

This doesn't beat Peter Taylor's solution, but I think it's pretty fun (plus, this is a complete working program, not just a function)

main(int c,char**v){for(;*v[1]!=0;++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 
main(int c,char**v){for(;*v[1];++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 

And ungolfed:

main(int argc, char** argv){ char * input = argv[1]; char * test = argv[2]; // advance through the input string. Each time the current input // character is equal to the current test character, increment // the position in the test string. for(; *input!='\0'; ++input) test += *input == *test; // return the character that we got to in the test string. // if it is '\0' then we got to the end of the test string which // means that it is a subsequence, and the 0 (EXIT_SUCCESS) value is returned // otherwise something non-zero is returned, indicating failure. return *test; } 

To test it you can do something like:

./is_subsequence banana anna && echo "yes" || echo "nope" # yes ./is_subsequence banana foobar && echo "yes" || echo "nope" # nope 
Source Link

C - 74

This doesn't beat Peter Taylor's solution, but I think it's pretty fun (plus, this is a complete working program, not just a function)

main(int c,char**v){for(;*v[1]!=0;++v[1])v[2]+=*v[1]==*v[2];return*v[2];} 

And ungolfed:

main(int argc, char** argv){ char * input = argv[1]; char * test = argv[2]; // advance through the input string. Each time the current input // character is equal to the current test character, increment // the position in the test string. for(; *input!='\0'; ++input) test += *input == *test; // return the character that we got to in the test string. // if it is '\0' then we got to the end of the test string which // means that it is a subsequence, and the 0 (EXIT_SUCCESS) value is returned // otherwise something non-zero is returned, indicating failure. return *test; } 

To test it you can do something like:

./is_subsequence banana anna && echo "yes" || echo "nope" # yes ./is_subsequence banana foobar && echo "yes" || echo "nope" # nope