Skip to content

Instantly share code, notes, and snippets.

@ktym
Last active March 7, 2018 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktym/56f82d29ab5739639c8f46f9fd92eab5 to your computer and use it in GitHub Desktop.
Save ktym/56f82d29ab5739639c8f46f9fd92eab5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
matrix = []
ARGF.each do |line|
ary = line.strip.split
matrix << ary
end
matrix.transpose.each do |row|
node_id = row.shift
sum = row.map {|x| x.to_i}.inject(0) {|s, i| s + i}
if sum == 1
puts [node_id[/\d+/], row].flatten.join("\t")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment