Add tags

Add tags to the following comment

ハッシュを利用しました.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
VOTE_ARY = [123, 4, 56, 78]
N = 100
class Hash
  def gen_vote(ary)
    key = 'a'
    ary.each{|x| self[key.succ!] = x}
  end
  def gen_vote_list
    keys.each{|key|
      2.upto(N){|i| self["#{key}#{i}"] = self[key].quo(i)}
    }  
  end
end
votes, counter = Hash.new, Hash.new
votes.gen_vote(VOTE_ARY)
votes.gen_vote_list
votes.keys.sort{|a, b| -1*(votes[a] <=> votes[b])}.
  map{|x| x.match(/^([a-zA-Z]+)/)[0]}[0..N-1].
  each{|key| eval("counter[key]#{counter.has_key?(key) ? '+' : ''}=1")}
p counter.values

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...