Skip to content

Instantly share code, notes, and snippets.

@Locke23rus
Created September 18, 2014 21:32
Show Gist options
  • Select an option

  • Save Locke23rus/8ae167f5b7f7c045a663 to your computer and use it in GitHub Desktop.

Select an option

Save Locke23rus/8ae167f5b7f7c045a663 to your computer and use it in GitHub Desktop.
N = 7
tmp_array = Array.new(N) { Array.new(N) { 0 } }
result = Array.new(N) { Array.new(N) { 0 } }
k = 0
N.times do |i|
N.times do |j|
k += 1
k = k % N if k > N
tmp_array[i][j] = k
end
k += 1
end
tmp_array.shuffle.each_with_index do |row, i|
row.each_with_index do |col, j|
result[j][i] = col
end
end
result.shuffle.each { |row| puts row.join(', ') }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment