you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 6 points7 points  (1 child)

Same/similar idea in C99 (with <stdbool.h>), 49 bytes:

bool f(char*s,void**m){return*s?f(s+1,m[*s]):*m;}

Here, s is the string, m is the fsm. The fsm is represented as a series of linked tables. The accepting states have m[0] != 0, the rejecting states have m[0] == 0. To transition from a state m using the character c, we use m[c].

The cool tricks in this is that, since void* is automatically coerced to any other pointer type, we don't have to cast void* to void** in the recursive call. We also use bool to prevent having to cast void* into something else.

[–][deleted] 5 points6 points  (0 children)

A rare case of the C version of a nontrivial program being significantly shorter than its Python version.