Skip to content

Instantly share code, notes, and snippets.

@framallo
Last active November 25, 2015 02:19
Show Gist options
  • Select an option

  • Save framallo/0732c8c7fa7aa726d9ea to your computer and use it in GitHub Desktop.

Select an option

Save framallo/0732c8c7fa7aa726d9ea to your computer and use it in GitHub Desktop.
require 'pp'
class Image
attr_accessor :image
def initialize(image)
@image = image
end
def output_image
@image.each do |e|
puts e.join('')
end
end
def find_ones
r = []
@image.each_with_index do |row, y|
# puts "starting a row #{y}"
row.each_with_index do |element, x|
# puts "visiting element #{x}"
puts "#{element} #{x} #{y}" if element == 1
r << [x, y] if element == 1
end
end
r
end
def replace_1_to_0
find_ones.each do |x,y|
@image[y][x] = '*'
end
end
end
image = Image.new([
[0, 0, 0, 0],
[0, 1, 0, 0],
[0, 0, 0, 1],
[0, 0, 0, 0]
])
image.output_image
puts 'find ones'
pp image.find_ones
image.replace_1_to_0
image.output_image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment