Skip to content

Instantly share code, notes, and snippets.

@itguy51
Created July 23, 2013 01:50
Show Gist options
  • Save itguy51/6059263 to your computer and use it in GitHub Desktop.
Save itguy51/6059263 to your computer and use it in GitHub Desktop.
require 'matrix'
def parseMatrixCols(matrixInput)
columnCount = (0..matrixInput.column_count-1)
colsWithBraces = []
columnCount.each do |n|
proc = matrixInput.column(n)
if proc.include?(1)
colsWithBraces.push(n)
end
end
colsWithBraces = colsWithBraces.uniq
if colsWithBraces.length == matrixInput.column_count
return true
else
return false
end
end
def parseMatrixRows(matrixInput)
rowCount = (0..matrixInput.row_count-1)
rowsWithBraces = []
rowCount.each do |n|
proc = matrixInput.row(n)
if proc.include?(1)
rowsWithBraces.push(n)
end
end
rowsWithBraces = rowsWithBraces.uniq
if rowsWithBraces.length == matrixInput.row_count
return true
else
return false
end
end
def secondaryArray(matrix)
rowTest = parseMatrixRows(matrix)
colTest = parseMatrixCols(matrix)
if rowTest && colTest
return true
else
return false
end
end
def randomN()
r = Random.new
return r.rand(0..1)
end
def rigidCount(m,n)
arrays = []
trueArr = []
lastIter = 0;
itera = 0;
while true
lastIter = trueArr.uniq.length
m_rand = makeArray(m,n)
arrays.push(m_rand.to_a.flatten.join)
if secondaryArray(m_rand)
trueArr.push(m_rand.to_a.flatten.join)
if (lastIter == trueArr.uniq.length)
itera += 1
else
itera = 0
end
end
if itera > m+n*100
puts trueArr.uniq
break
end
arrays.push(m_rand.to_a.flatten.join)
end
end
def makeArray(x,y)
rows = (0...x).map do
(0...y).map do
randomN()
end
end
l = rows.to_s[1..-1][0..-2]
i = "Matrix[" + l + "]"
m_rand = eval(i)
return m_rand
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment