ruby challenge 11

odd even

This challenges only hint is the page title, nothing in the page source and no page text, even the photo is fuzzy. In fact if you zoom in on it you will find that it has a checkerboard pattern. I don’t know how much time I wasted trying to coax a secret message out of the color code numbers in the pixels. Most of those numbers are beyond the scope of ascii codes and the ones that weren’t just yielded gibberish.

If you zoom in to the image to try and find some pattern to grasp onto you will notice the dark and light checker board of the pixel layout. Very strange you might say odd, even. When you finally give up on the numbers in the pixel data you may start to sort out the pixels themselves and come up with something like this;

#!/usr/bin/ruby
require 'RMagick'
include Magick
cave = ImageList.new("./cave.jpg")
wid, hgt = cave.columns, cave.rows
Image.new(wid/2, hgt/2).write("./ruby11.jpg")
ruby11 = ImageList.new("./ruby11.jpg")
cavePix = cave.export_pixels(0, 0, wid, hgt, "RGB")
rubyPix, n = [], 0
(hgt/4).times do
  (wid/2).times do
    rubyPix[(n/2),3] = cavePix[n,3]
    n = n + 6
  end
  (wid/2).times do
    rubyPix[(n/2),3] = cavePix[n+3,3]
    n = n + 6
  end
end
ruby11.import_pixels(0, 0, wid/2, hgt/2, "RGB", rubyPix)
ruby11.write("./ruby11.jpg")

Or, slightly more condensed;

#!/usr/bin/ruby
require 'RMagick'
include Magick
cave = ImageList.new("./cave.jpg")
w, h, a = cave.columns, cave.rows, []
Image.new(w/2, h/2).write("./ruby11.jpg")
ruby11 = ImageList.new("./ruby11.jpg")
c = cave.export_pixels(0, 0, w, h, "RGB")
0.step((w*h)*3, 6){|n|
  if (n/(w*3))%2 == 0
    a[(n/2),0] = c[n,3]
  else
    a[(n/2),0] = c[n+3,3]
  end
}
ruby11.import_pixels(0, 0, w/2, h/2, "RGB", a)
ruby11.write("./ruby11.jpg")

Next: python challenge 12; dealing evil

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s