kill(all)$

maxima :programming :random walk ([N,S,W,E]),version 1.0
peter.vlasschaert@gmail.com,21/01/2019.

load packages
============

load(combinatorics)$
load(lrats)$

random choice :random_perm(n), n = integer
===================================
  =>  Four directions : 
  -  North  = 1
  -  South  =  2
  -  West   =  3
  -   East   =  4

random_perm(4);

for i:1 thru 5 do(
print( random_perm(4)))$

we take first number '  from permutation above  ' = integer.
============================================
  =>    integer={1,2,3,4}.
-------------------------------------------------------------------------------

for i:1 thru 5 do(
print( random_perm(4)[1])
                          )$

corresponding to "four directions"., 'see : above'.
------------------------------------------------------------------------------

make function : random_walk(n),  n = integer
=====================================
=> suppose street perpendicular to each other 
=>  both x & y direction  (perpendicular), 
=====================================
example :  1e)  start  (x=0,y=0)
                   2e)  randomwalk (n)
                           =>  end (x=a,y=b),integer ={a,b}
======================================
How to use : packages function : random_perm(n)

1e) test_walk (argument)
-----------------------------------

function : 
=======
How block statement be used

p1:test_walk(nn):=block([x:0,y:0],   
x:x+1,
y:y+1,
return([x,y]));

output : 'function'
============

p2:test_walk(5);

p2a:test_walk(5)[1];
p2b:test_walk(5)[2];

rem : see 'local variable 'x,y' from function:test_walk(integer) '

x;
y;

2e) random_walk (arguments)
------------------------------------------

kill(x,y)$

 set_random_state ( make_random_state (654321) )$
 l:makelist(fix(random(4.0)+1),j,1,6 );

function
======

random_walk(nn,m):=block([],    
     a:m, 
     b:["North =","South=","West =","East="],
     print(b[a],a), 
     (  if 1=a  then
     y:y+1        
      else if  2=a  then
     y:y-1
       else if 3=a then
     x:x-1
        else
     x:x+1),
    return([x,y])
   )$

rem :x,y global variables.

given : list , 'll'
============

ll:[1,4,4,2,4,1,1,4];

[x:0,y:0];

for i:1 thru  length(ll) do(
    random_walk(i,ll[i]),
    print(x,y)      
)$
[x,y];

x;
y;

result:
=====

example: beginpoint :[0,0]  => endpoint:[4,2]

random :list, 'l'
===========

kill(x,y);
[x:0,y:0];
for i:1 thru  length(l) do(
    random_walk(i,l[i]),  
    print(x,y)    
)$
[x,y];

x;
y;

result:
=====

random: beginpoint :[0,0]  => endpoint:[-1,-1]