let me straighten this out
The goal of this challenge is to indeed straighten out the image. The five pixel wide pink bar is the key. It took me a false start before I noticed that there is exactly one on each line. I had been trying to determine the relationship to the various length spaces between the key pixel blocks. The trick is to ‘rotate’ each line, moving the first (left most) pixel to the end (right side), until the ‘key’ is lined up on the side. First you need the key, since there are a few other runs of 5 or more identical pixels of the wrong color.
#!/usr/bin/ruby require 'RMagick' include Magick Image.new(640, 480).write("./ruby16.gif") moz = ImageList.new("./mozart.gif", "./ruby16.gif") line = moz[0].export_pixels(0, 0, 640, 1, "RGB") line.push line.shift until line[3, 3]*4 == line[6, 12] key = line[3, 15] for y in 0..(moz[0].rows) line = moz[0].export_pixels(0, y, 640, 1, "RGB") line.push line.shift until line[3, 15] == key moz[1].import_pixels(0, y, 640, 1, "RGB", line) end moz[1].write("./ruby16.gif")
Next: Python challenge 17; eat?
Advertisements