Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- b=[]
- i=0
- j=[0,3,6]
- p=%w(012 345 678 036 147 258 048 246)
- w=nil
- $<.read.each_char{|c|b[c.to_i-1]=(i+=1)%2
- p.each{|s|r=b.values_at(*s.split(//).map(&:to_i))
- if r.compact.size==3
- m=r.inject(0,&:+)
- w=m/3 if m/3==m/3.to_f
- end}
- break if w}
- x={1=>'X',0=>'O'}
- puts 'Winner: '+(x[w] || 'Nobody'),j.map{|n|b[n..n+2].map{|z|x[z]||' '}.join '|'}.join('
- -+-+-
- ')
Add Comment
Please, Sign In to add comment