Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save geoffreyadebonojo-zz/4b5fe51e775772b1b6b2f9dbba072df8 to your computer and use it in GitHub Desktop.
Save geoffreyadebonojo-zz/4b5fe51e775772b1b6b2f9dbba072df8 to your computer and use it in GitHub Desktop.
arrayMatrix1 =
[
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]
]
arrayMatrix2 =
[
[1, 2, 3], # 0
[4, 5, 6], # 1
[7, 8, 9] # 2
]
def snail(arrayMatrix)
snail = []
# top row
arrayMatrix.first.each do |x|
snail << x
end
arrayMatrix.shift
# right side
arrayMatrix.each do |x|
snail << x.pop
end
# bottom row
arrayMatrix.last.reverse.each do |x|
snail << x
end
arrayMatrix.pop
# left side
arrayMatrix.reverse.each do |x|
snail << x.shift
end
if arrayMatrix != []
arrayMatrix.first.each do |x|
snail << x
end
arrayMatrix.shift
end
if arrayMatrix != []
arrayMatrix.first.reverse.each do |x|
snail << x
end
arrayMatrix.shift
end
snail.flatten
end
if snail(arrayMatrix1) == [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10]
puts "4 x 4 array = MATCH"
elsif
puts "NO MATCH"
end
if snail(arrayMatrix2) == [1, 2, 3, 6, 9, 8, 7, 4, 5]
puts "3 x 3 array MATCH"
elsif
puts "NO MATCH"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment