In [294]:
M =[1,2,3]
F =[1,2,3]


Out[294]:
3-element Array{Int64,1}:
 1
 2
 3

In [295]:
M1 = [2,3,0,1]
M2 = [3,0,1,2]
M3 = [2,1,3,0]
m_prefs = [[M1] [M2] [M3]]


Out[295]:
4x3 Array{Int64,2}:
 2  3  2
 3  0  1
 0  1  3
 1  2  0

In [296]:
F1 = [2,3,1,0]
F2 = [1,3,0,2]
F3 = [2,0,1,3]
f_prefs = [[F1] [F2] [F3]]


Out[296]:
4x3 Array{Int64,2}:
 2  1  2
 3  3  0
 1  0  1
 0  2  3

In [297]:
m_matched= zeros(length(M))
f_matched= zeros(length(F))


Out[297]:
3-element Array{Float64,1}:
 0.0
 0.0
 0.0

とりあえず、男性全員が1回希望リストの最高位の女性にプロポーズする場合を考えてみる。


In [374]:
for i = [1:length(M)]
    if m_prefs[1,i]==0
        m_matched[i]=0
        else m_matched[i]=m_prefs[1,i]
    end
    for l in i+1:length(M)
        if m_matched[i] == m_matched[l]
            if {find(f_prefs[:,m_matched[i]].==i) .< find(f_prefs[:,m_matched[i]].==l)} == trues(1)
                m_matched[l] = 0
            else
                m_matched[i] = 0
            end
        end
    end
end

In [375]:
m_matched


Out[375]:
3-element Array{Float64,1}:
 0.0
 3.0
 2.0

In [ ]: