Created
February 8, 2020 00:16
-
-
Save lzychowski/a57c34008c47711b9557a328dada19d6 to your computer and use it in GitHub Desktop.
This file contains 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
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