Church Numerals in ski by 51b

a[9999][3];char*p,s[999]="``";m,k;f(n){(*a[n]=*p++-96)||f(a[n][1]=++m)+f(a[n][2]=++m);}g(n,r){int*p=a[n],*q,*P,*Q;!*p?g(r=p[1]),q=a[r],r=p[2],*q?*q-9||memcpy(p,a[r],12):*(P=a[q[1]])?*P-11||memcpy(p,a[q[2]],12):*a[P[1]]>18?Q=a[p[1]=++m],*Q=0,Q[1]=P[2],Q[2]=r,Q=a[p[2]=++m],*Q=0,Q[1]=q[2],Q[2]=r:0:0;}main(x){for(;gets(s+2);printf("%d\n",k))for(strcat(p=s,"ab"),f(x=k=m=0);*a[x]-2;*a[a[x][1]]==1?x=a[x][2],k++:0)g(x);}

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page