function z = choose(x, y)

if ((x < 0) || (y < 0) || (y > x))
    z = 0;
elseif ((x == y) || (y == 0))
    z = 1;
else
    if (x < 170)
        z = factorial(x)/(factorial(x - y)*factorial(y));
    else
        z = x-y+1;
        for j=x-y+2:x
            z = z*j;            
        end
        z = z/factorial(y);
    end
end


 