LoginSignup
1
0

More than 5 years have passed since last update.

第二回オフラインリアルタイムどう書くの解答例

Posted at

第2回 オフラインリアルタイムどう書く( http://atnd.org/events/30900 )。
問題は http://nabetani.sakura.ne.jp/hena/ord2/
まずは、とりあえず書いた ruby。

#!ruby

def bitetris( q )
  s=q.split('-').map{ |i| i.to_i(16) }
  lines_to_kill = (0...8).select{ |i|
    s.all?{ |x| x[i]!=0 }
  }
  lines_to_kill.reverse.each{ |b|
    s=s.map{ |x|
      ((x>>1)&(-1<<b)) | (~(-1<<b)&x)
    }
  }
  s.map{ |i| "%02x"%i }.join('-')
end

DATA.each{ |line|
  q,ex=line.split(/\s+/)
  r=bitetris q
  p [r==ex, r, ex ]
}
__END__
ff-2f-23-f3-77-7f-3b   1f-03-00-1c-0d-0f-06

テストデータは本当はもっとあるけどここには一個だけで。

普通に bit 演算をするとこんなかんじかなという実装。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0