Last active
October 13, 2015 14:03
-
-
Save gagaception/e1fae6ced4caf49b17fc 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 | |
attr_accessor :data | |
def initialize (data) | |
@data = data | |
end | |
def image_blur | |
all_done = false | |
@data.each_with_index do |row, row_index| | |
row.each_with_index do |value, column_index| | |
if value == 1 && column_index <= row.size-1 && column_index > 0 | |
@data[row_index][column_index-1] = 1 | |
end | |
if value == 1 && row_index <= @data.size && row_index > 0 | |
@data[row_index-1][column_index] = 1 | |
end | |
if value == 1 && row_index < @data.size-1 | |
@data[row_index+1][column_index] = 1 | |
end | |
if value == 1 && column_index < row.size - 1 | |
@data[row_index][column_index + 1] = 1 | |
all_done = true | |
break | |
end | |
end | |
break if all_done | |
end | |
end | |
def output | |
@data.each do |sub| | |
sub.each do |cell| | |
print cell | |
end | |
puts "\n" | |
end | |
end | |
end | |
image = Image.new([[0,0,0,0,0,0,0], | |
[1,0,0,0,0,0,0], | |
[0,0,0,0,0,0,0] | |
]) | |
image.image_blur | |
image.output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment