Skip to content

Instantly share code, notes, and snippets.

@youchan
Created September 14, 2015 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youchan/93b4c53da408e244b82a to your computer and use it in GitHub Desktop.
Save youchan/93b4c53da408e244b82a to your computer and use it in GitHub Desktop.
「プログラマの数学」(結城 浩) P76 恋人探しをプログラムで求める
# 「プログラマの数学」(結城 浩) P76 恋人探しをプログラムで求める
#
# 読書会で書いたやつを捨てるのもったいないので貼っとく
#
graph = {a: [:b, :e, :d], b: [:a, :c, :f], c: [:b, :d, :g], d: [:a, :c, :h],
e: [:f, :h, :a], f: [:e, :g, :b], g: [:f, :h, :c], h: [:e, :g, :d]}
c = {a: 0, b: 0, c: 0, d: 0, e: 0, f: 0, g: 1, h: 0}
12.times do |i|
cc = {a:0, b:0, c:0, d:0, e:0, f:0, g:0, h:0}
c.each do |d|
graph[d[0]].each do |s|
cc[s] += d[1].to_r / 3
end
end
p cc
c = cc
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment