I'm making snake using the TI basic on my calculator, and that works well and all. the sublist would always be 2 long.
I am aware of:
max(not(L1-X))
but this only checks for 1 value and I need to check for the sublist {X,Y} not just X...
the issue is, the larger you get, the slower the snake moves, because the list can get over 100 characters long. the code that I'm using:
:0 -> T
:For(I,2,dim(L1)-2,2):
:(L1(I-1)=X)(L1(I)=Y) + T -> T
:if T ≥ 1:Then:1->P:End
You can store coordinates as complex numbers instead of pairs of adjacent numbers. Complex numbers intrinsically represent 2-dimentional values, so many of their operations map nicely to operations on 2D coordinates. For example instead of storing three coordinates (1, 1), (1, 2), (2, 2) as
{1,1,1,2,2,2}, store them as{1+1i,1+2i,2+2i}.To convert coordinates to complex numbers, you just need to use the imaginary unit, i, like
X+Yi.To extract the coordinates from a list element
I, you can take the real and imaginary parts of the element,real(L1(I))→Xandimag(L1(I))→Y.You can check for inclusion of a coordinate in a list of complex numbers using a modified version of the trick you mentioned,
max(not(abs(L1-(X+Yi)))).abstakes the magnitude of each complex number in the listL1-(X+Yi)which will be zero if and only if the components of the complex number areXandY.