Langton's ant (4)

1 Name: #!/usr/bin/anonymous : 2009-07-09 13:02 ID:JoKJPP6/ This thread was merged from the former /code/ board. You can view the archive here.

So I thought I'd implement Langtons ant without if, switch or the like:

#include <stdio.h>
#define W 8 //*32
#define H 256
#define CYCLES 12300

int main(){
short int x=W*16-1,y=H/2-1,d=2,c,dy,ax,bx,i;
int field[W][H];
for(i=0;i<CYCLES;i++){
x+=d/2+d%2+d%3%2-2;
dy=d%4+1;
y+=dy/2+dy%2+dy%3%2-2;
ax=x/32,bx=x%32;
c=field[ax][y]>>bx&1;
d=(d+2*c)%4+1;
field[ax][y]^=1<<bx;
printf("i: %d\tx: %d\ty: %d\td: %d\n",i,x,y,d);
}
}

while the transitions for x and y (and d) are correct, they are still somewhat complicated... an ideas how to simplify/optimize them?

2 Name: #!/usr/bin/anonymous : 2009-07-23 13:56 ID:w+8oa1IK

Does it bite?

3 Name: #!/usr/bin/anonymous : 2009-07-23 20:43 ID:1YJaw5oA

#define DD(d) d/2+d%2+d%3%2-2
dy=d&3;d++;x+=DD(d);y+=DD(dy);
ax=x>>5;bx=(x&31)-1;c=field[ax][ay]>>b&1;
d+=c;d&=3;d++;field[ax][y]^=2<<bx;

4 Post deleted.

Name: Link:
Leave these fields empty (spam trap):
More options...
Verification: