1 <span class="co1">#!/usr/bin/ruby</span>
2 lines = <span class="kw4">IO</span>.<span class="me1">read</span><span class="br0">(</span>ARGV<span class="br0">[</span>0<span class="br0">]</span><span class="br0">)</span>.<span class="kw3">split</span><span class="br0">(</span><span class="st0">"<span class="es0">\"</span>,<span class="es0">\"</span>"</span><span class="br0">)</span>;
3 lines<span class="br0">[</span><span class="nu0">0</span><span class="br0">]</span>.<span class="me1">delete</span>!<span class="br0">(</span><span class="st0">"<span class="es0">\"</span>"</span><span class="br0">)</span>
4 lines<span class="br0">[</span><span class="sy0">-</span><span class="nu0">1</span><span class="br0">]</span>.<span class="me1">delete</span>!<span class="br0">(</span><span class="st0">"<span class="es0">\"</span>"</span><span class="br0">)</span>
5 lines.<span class="me1">sort</span>!
7 lines.<span class="me1">each_index</span><span class="br0">{</span><span class="sy0">|</span>i<span class="sy0">|</span>
8 l = lines<span class="br0">[</span>i<span class="br0">]</span>
9 <span class="kw3">p</span> = 0
10 l.<span class="me1">bytes</span>.<span class="me1">each</span><span class="br0">{</span><span class="sy0">|</span>b<span class="sy0">|</span>
11 <span class="co1">#print "#{b}: #{b.to_i - 'A'[0].to_i + 1}\n"</span>
12 <span class="kw3">p</span> <span class="sy0">+</span>= b.<span class="me1">to_i</span> <span class="sy0">-</span> <span class="st0">'A'</span><span class="br0">[</span>0<span class="br0">]</span>.<span class="me1">to_i</span> <span class="sy0">+</span> 1 <span class="kw1">if</span> b.<span class="me1">to_i</span> <span class="sy0">></span> 0
13 <span class="br0">}</span>
14 res <span class="sy0">+</span>= <span class="kw3">p</span> <span class="sy0">*</span> <span class="br0">(</span>i <span class="sy0">+</span> 1<span class="br0">)</span>
16 <span class="kw3">print</span> <span class="st0">"#{res}, #{p}:#{l}<span class="es0">\n</span>"</span>
17 <span class="br0">}</span>