UNIX is one of the few operating system that supports and can be run on a non-deterministic Turing Machine and use its full potential. Below is part of a C code solving 3-coloring (whether a graph can be colored in 3 colors) in non-deterministic polynomial time.
int n, m, G[N][N], color[N];
int main() {
scanf(" %d %d", &n, &m);
for (int i = 0, u, v; i < m; i++) {
scanf(" %d %d", &u, &v);
G[u][v] = G[v][u] = 1;
}
for (int u = 1; u <= n; u++) {
int ok[3] = {1, 1, 1};
for (int v = 1; v < u; v++) {
if (G[u][v]) {
ok[color[v]] = 0;
}
}
/* I will try the first color, my children try other options */
color[u] = -1;
for (int c = 0; c <= 2; c++) {
if (!ok[c]) {
continue;
}
if (color[u] == -1) {
color[u] = c;
if (u <= 2 || u == n) {
/* optimization */
break;
}
} else {
/* branching, or some call this guessing */
if (fork() == 0) {
/* I am the child */
color[u] = c;
break;
}
}
}
if (color[u] == -1) {
/* we're on a rejecting branch */
wait_or_fail();
}
}
printf("SUCCESS: ");
for (int u = 1; u <= n; u++) {
printf("%d ", color[u]);
}
printf("\n");
exit(SOLVED);
}
Although you are able to compile and run this on current x86 Linux machines, it is not recommended–the effects are pretty similar to the well-known :(){:|:&;}
.
Full source code is on my gist.