|
I'm a little disappointed that I was able to solve it so quickly, I thought it was going to be a big multi-stage puzzle where the color values and image dimensions/row boundaries would all be important factors... Still, my solution (in JS) was a little more verbose than yours... <img src="puzzle2.png" id="puzzle-image">
<script>
/*
Pink (white) 232,3,138
Blue (black) 58,185,229
*/
window.addEventListener("load", function() {
var image = document.getElementById("puzzle-image"),
canvas = document.createElement("canvas"),
context = canvas.getContext("2d");
canvas.width = image.width;
canvas.height = image.height;
context.drawImage(image, 0, 0, image.width, image.height);
// Test 1 - rle
(function() {
var rle = [], prev = null, count = 0;
for (let y = 0; y < image.height; y++) {
for (let x = 0; x < image.width; x++) {
let pd = context.getImageData(x, y, 1, 1).data;
if (prev === null) {
prev = pd[0];
}
if (pd[0] == prev) {
count++;
} else {
rle.push(count);
count = 1;
prev = pd[0];
}
}
}
var r1 = "";
for (let i = 0; i < rle.length; i++) {
r1 += String.fromCharCode(rle[i]);
}
console.log(r1);
var r2 = "";
for (let i = 0; i < r1.length; i += 3) {
r2 += String.fromCharCode(parseInt(r1[i] + r1[i + 1], 16));
}
console.log(r2);
}());
}, false);
</script>
(Where puzzle2.png is the image in black & white)(Edited to fix indentation...) |