// Question 1

function res=boussole()
    a = rand()
    if a < 1/4 
        res = [-1,0]
    elseif a < 1/2
        res = [1,0]
    elseif a < 3/4
        res = [0,-1]
    else
        res=[0,1]
    end
endfunction

// Question 2

function M = position_2D(N)
    X = [0]
    Y = [0]
    pos = [0,0]
    for i=2:N
        pos = pos + boussole()
        X = [X,pos(1)]
        Y = [Y,pos(2)]
    end
    M=[X;Y]
endfunction

// Version alternative

//function M = position_2D(N)
//    X = zeros(1,N)
//    Y = zeros(1,N)
//    for i=1:N-1
//        res = boussole()
//        X(i+1) = X(i) + res(1)  
//         Y(i+1) = Y(i) + res(2)    
//    end
//    M=[X;Y]
//endfunction

// Question 3 (voir exo2.sce)

// Question 4

function distmax= max_distance(X,Y)
    dist = sqrt(X.^2+Y.^2)
    distmax=max(dist)
endfunction
