Skip to main content
Tweeted twitter.com/StackCodeGolf/status/1559691543295967233
specific title
Link

Help me golf this C program checking for string patterns in a sorted hand of cards

Became Hot Network Question
Source Link
TwilightSparkle
  • 3.9k
  • 1
  • 17
  • 33

Help me golf this C program

I could not think of a better title.

This is a tips question. I'm asking for tips on golfing my code.

I recently took part in a code golf competition in C. The competition ended and I lost. The problem is:

Input a line with a number n.

Then input n lines, each line contains only a set of cards in descending order, e. g. X2AAKKKKQT9765433 or DX22AKKQJTT884443. Figure out if it contains DX or four of the same cards in a row.

Obviously, this is a chameleon challenge (finding DX is essentially the same as checking the second character if it is X, and to check for four of the same cards you only need to check the first and the last card of the quadruplet, because the cards are in descending order.)

In that competition, the input format is strict, and error-terminating is disallowed.

After the competition, we continued to improve on this problem. We've got this so far (98 bytes):

char*p,s[99];main(){for(gets(s);gets(p=s);puts(s[1]>87?"Yes":"No"))for(;*p;)s[1]|=*p^p++[3]?0:88;}

I'm looking for tips to golf this down further.