Skip to content

Instantly share code, notes, and snippets.

@lzychowski
Created February 8, 2020 00:16
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 lzychowski/a57c34008c47711b9557a328dada19d6 to your computer and use it in GitHub Desktop.
Save lzychowski/a57c34008c47711b9557a328dada19d6 to your computer and use it in GitHub Desktop.
class Image
def initialize(image)
@image = image
end
def find_ones
list_of_ones = [] # create empty array to track found 1's
row = 0
@image.each do |n|
col = 0
n.each do |m|
if m == 1
list_of_ones.push([row, col]) # when you find a one, track it
end
col +=1
end
row +=1
end
return list_of_ones # return the list of ones so that we can loop over it and flip the 0s to 1s
end
# you have to do the work in this or another function in this class
def output_image
@image.each do |image|
puts image.join(' ')
end
end
end
image = Image.new([
[0, 0, 0, 0],
[0, 0, 1, 0],
[0, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0]
])
image.find_ones
image.output_image
# arr[row][col - 1] = 1
# arr[row - 1][col] = 1
# arr[row][col + 1] = 1
# arr[row + 1][col] = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment