Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class OlsFile
- @@mapping = {
- #PORT -> CHANNEL
- 0 => 6,
- 1 => 4,
- 2 => 2,
- 3 => 0,
- 4 => 1,
- 5 => 3,
- 6 => 5,
- 7 => 7
- }
- attr_accessor :data
- def initialize(input = nil)
- self.data = {}
- parse(input) if input
- end
- def parse(input)
- input.split("\n").each do |line|
- value, key = line.split('@')
- value = value.to_i
- if key && value > 0
- self.data[key.to_i] = [value, remap(value)]
- end
- end
- end
- def remap(value)
- v = 0
- @@mapping.each do |from, to|
- v |= ((value >> from) & 1) << to
- end
- v
- end
- end
- Dir["data/score*"].each do |file|
- puts
- puts
- print file
- file = OlsFile.new(File.open(file).read)
- last = 0
- file.data.each do |k,v|
- puts if (k - last > 20)
- last = k
- print ("%08b " % v.last) + "(#{v.last}) "
- end
- end
Add Comment
Please, Sign In to add comment