// Question 1

function res=pile_ou_face ()
    a = rand()
    res = -1
    if a> 0.5 then res = 1
    end
endfunction

// Version alternative

//function res=pile_ou_face ()
//    res = 2*floor(2*rand())-1
//endfunction
//


// Question 2

function pos= position_1D(N)
    pos = [0]
    for i=2:N
        pos = [pos, pos($)+pile_ou_face()]
    end
endfunction

// Version alternative

//function pos= position_1D(N)
//    pos = zeros(N)
//    for i=1:N-1
//        pos(i+1) = pos(i) + pile_ou_face()    
//    end
//endfunction

// Question 3 (voir exo1.sce)

// Question 4

function r= max_min(T)
    maxi=T(1)
    mini=T(2)
    for i=2:length(T)
        if T(i) < mini
            mini=T(i)
        elseif T(i) > maxi
            maxi=T(i)
        end
    end
    r=[maxi,mini]
endfunction

// Question 5

function pos= position_1D_bis()
    pos = [0]
    i = 1
    while i < 10000 & abs(pos($)) < 30
        pos = [pos, pos($)+pile_ou_face()]
        i = i+1
    end
endfunction
