Created
March 10, 2014 17:06
-
-
Save tom-galvin/9469248 to your computer and use it in GitHub Desktop.
DailyProgrammer Challenge #140 Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reddit.com/r/DailyProgrammer | |
# Solution to Challenge #140: Adjacency Matrix | |
nodes, lines = gets.chomp.split(' ').map {|s| s.to_i} | |
mat = Array.new(nodes) {Array.new(nodes) {0}} | |
(1..lines).step 1 do |x| | |
line = gets.chomp.split('->').map {|s| s.split(' ').map {|t| t.to_i}.compact} | |
combos = line.first.product line.last | |
combos.each do |b| | |
mat[b[0]][b[1]] = 1 | |
end | |
end | |
mat.each do |x| | |
puts x.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment