Read EAN13 barcodes by jpl

#!ruby -n
d,h=$_[5,42],$_[52,42]
l=13,25,19,61,35,49,47,59,55,11
g=39,51,27,33,29,57,5,17,9,23
r=l.map{|i|127^i}
f=0,11,13,14,19,25,28,21,22,26
p=0
t=""
def u i,o
o[i*7,7].tr('# ','10').to_i 2
end
6.times{|i|p<<=1
t<<(l.index(b=u(i,d))||(p^=1;g.index b))+48}
t<<32
6.times{|i|t<<(r.index u i,h)+48}
t="#{f.index p} "+t
k=0
12.times{|i|k+=[1,3][i%2]*(t.tr(" ","")[i]-48)}
puts (10-k%10)%10==t[-1]-48?t:"ERROR"
$<.read(981)

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return top