Skip to content

Instantly share code, notes, and snippets.

@XanClic
Created April 26, 2023 08:29
Show Gist options
  • Save XanClic/5988895fe7e68770c07a040a49037a39 to your computer and use it in GitHub Desktop.
Save XanClic/5988895fe7e68770c07a040a49037a39 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'json'
CLUSTER_SIZE = 65536
map = JSON.parse(IO.read('map.txt')).select { |e| e['offset'] }.sort { |x, y| x['offset'] <=> y['offset'] }
ofs = 0
max_gap = 0
output = []
for e in map
gap = (e['offset'] - ofs) / CLUSTER_SIZE
if gap > 0
output << "Gap of #{gap} clusters between #{ofs} and #{e['offset']}"
max_gap = gap if gap > max_gap
end
ofs = e['offset'] + e['length']
end
IO.write("/tmp/gaps.txt", output * $/)
puts "Maximum gap: #{max_gap} clusters"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment