Jump to content

Langton's ant: Difference between revisions

Added 'Octave' 1st order recurrence relation implementation.
(→‎{{header|Julia}}: added version)
(Added 'Octave' 1st order recurrence relation implementation.)
Line 4,290:
if (~mod(k,100)),spy(A);pause(.1);end; %display after every 100 interations
end;
end</lang>
 
=={{header|Octave}}==
<lang OCTAVE>clear
E=100 % Size of lattice.
N=11200 % Number of iterations.
z(1:1:E^2)=-1; % Init lattice rotations (-1=right, 1=left)
k(1:1:E^2)=0;
k(1)=(E^2+E)/2; % Init the Ant @ 50,50
for t=1:1:N;
k(t+1)=mod(k(t)+real(round((0.5*(E+1)*exp(i*pi/4*(trace(diag(z))-E^2)))-(0.5*(E-1)*exp(-i*pi/4*(trace(diag(z))-E^2)))))+imag(round((0.5*(E+1)*exp(i*pi/4*(trace(diag(z))-E^2)))-(0.5*(E-1)*exp(-i*pi/4*(trace(diag(z))-E^2))))),E^2);
z(k(t+1)+1)=real(exp(2*i*pi/4*(1+z(k(t+1)+1))));
endfor;
imagesc(reshape(z,E,E)) % Draw the Lattice
end</lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.