Puzzle 3: a 4-D puzzle
There is a shorter description available
here.
Note: The objectives of this puzzle has been clarified (2017-01-29)
Consider the following (undistorted) image:
In ahk it can be represented as a 3-Dimensional array, eg
where
i=1,2,...,h,
h is the height of the image,
j=1,2,...,w,
w is the width of the image,
k=1,2,3 are the color components (red, green and blue, respectively) , finally,
n=0,1,...,255 is the color intensity,
0 is no intensity (black) and
255 is full intensity (white).
As a reference, these are the three color components of the image, displayed as grayscale images:
From left to right: Red, green and blue components of the undistorted image, as grayscale images.
To make a grayscale image of color component
x, simply let,
Code: Select all
I_grey[i,j,k]:=I[i,j,x] ; for all i,j and k
In this puzzle, we have
w=h=32 and
I[1,1] is the top-left corner of the image, and
I[32,32] is bottom-right. Eg, the intensity of the red component of the top-left pixel, is at
I(1,1,1), green is at
I(1,1,2) and blue is at
I(1,1,3).
Puzzle objective: Restore a, hard-coded, distorted version of this image, where each color plane has been (independently from the others) transformed in a fully reversible matter.
Puzzle objective clarification:
Running the code below, should show you this image (enlarged for easy viewing):
- distorted.png (24.26 KiB) Viewed 15616 times
which is a distorted version of the first image in this post. The pixel data of this image is stored in the 3D-array
I in the code, the objective is to manipulate
I such that
imshow(I) shows the undistorted image (i.e., the first image of this post).
Puzzle rules: You are only to manipulate the array
I containing the
(EDIT: distorted) pixel data as it is returned by the function
imread() given in the code snippet below, you do not read in the images from this post. To complete this puzzle, post your code for fully restoring the image.
Code: Contains the distorted image, which is given in the array
I, and a function,
imshow(I), to display an image on the form of a 3-D array, as described in this post.
Code: Select all
#SingleInstance, force
I:=imread() ; Reads in the distorted image
; Code to restore the image
imshow(I) ; Shows the image
return
; You may add any functions or labels here:
return
GuiClose:
esc::exitapp
; Below is not to be modified - You do not need to look at this code to solve the puzzle. The image is not distorted in this code.
imshow(im)
{
static scale:=12, w:=32, h:=32
p:=w/2!=w//2
VarSetCapacity(lpvBits,3*(w+p)*h,0)
o:=0,i:=0
Loop, % w*h
j:=mod(A_Index-1,w)+1, j==1?++i:"" , NumPut(im[i,j,3], lpvBits, o, "Uchar"), NumPut(im[i,j,2], lpvBits, o+1, "Uchar"), NumPut(im[i,j,1], lpvBits, o+2, "Uchar"), o+=3+(j=w?p:0)
hBitmap := DllCall("gdi32.dll\CreateBitmap", "Int", w, "Int", h, "UInt", 1, "Uint", 24, "Ptr", 0)
hBmp := DllCall("user32.dll\CopyImage", "Uint", hBitmap, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008)
DllCall("gdi32.dll\SetBitmapBits", "Uint", hBmp, "UInt", 3*(w+p)*h, "Uint", &lpvBits)
Gui, new
Gui, margin,0,0
Gui, add,picture, % "w" w*scale " h" h*scale " 0x4E hwndpicId"
Gui, show,, % "Imshow: " w*scale "-by-" h*scale " pixels."
SendMessage, 0x172, 0x0, hBmp,, % "ahk_id " picId
return
}
imread()
{
A=
(
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 38 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 38 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 38 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 38 91 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 45 0 0 0 0 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0 66 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 177 0 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 177 0 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0 80 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 46 0 0 0 0 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 170 0 0 0 0 170 170 170 170 170 38 92 171 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 0 0 206 204 0 0 170 170 170 170 38 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 0 200 200 200 200 0 172 170 170 170 38 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 170 170 170 170 0 200 200 200 200 0 172 170 170 170 38 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 7 7 7 0 0 200 200 200 200 0 0 7 8 8 2 6 9 9 9 9 18 170 170 170 170 12 7 7 7 7 0
0 70 70 70 70 85 200 200 200 200 98 70 70 70 70 15 43 59 59 59 39 0 170 170 170 170 0 51 59 59 59 0
0 200 200 200 200 200 200 200 200 200 200 200 200 200 200 44 125 170 170 170 177 0 170 170 170 170 0 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 200 200 200 44 125 170 170 170 179 0 170 170 170 172 0 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 200 200 200 44 125 170 170 170 170 0 0 177 149 0 0 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 200 205 207 12 125 170 170 170 170 170 0 0 0 81 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 0 0 0 0 141 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 0 0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 0 174 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 36 0 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 0 0 0 0 131 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 200 200 200 30 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 200 200 200 44 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 200 200 200 44 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 200 200 200 200 200 200 200 200 200 200 200 200 200 200 44 125 170 170 170 170 170 170 170 170 170 170 170 170 170 170 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
)
B=
(
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 160 57 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 160 57 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 160 57 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 160 39 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 167 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 0 47 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 221 0 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 0 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 216 0 0 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 216 216 216 216 216 216 216 216 216 180 0 0 0 0 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 216 105 0 0 0 216 216 216 216 216 160 15 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 0 0 118 141 0 0 216 216 216 216 160 57 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 0 136 135 135 135 0 227 216 216 216 160 57 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0
0 216 216 216 216 0 135 135 135 135 0 224 216 216 216 160 57 255 255 255 255 255 255 255 255 255 255 255 255 255 255 0
0 74 74 74 64 0 135 135 135 135 0 50 74 74 74 55 19 90 90 90 90 118 255 255 255 255 106 90 90 90 90 0
0 5 5 5 5 10 135 135 135 135 15 7 7 7 7 5 1 6 6 5 0 0 255 255 255 255 0 0 5 5 5 0
0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 99 29 135 135 135 137 0 255 255 255 255 0 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 99 29 135 135 135 137 0 255 255 255 255 0 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 99 29 135 135 135 135 0 0 255 255 0 0 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 73 29 135 135 135 135 135 0 0 0 0 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 0 0 0 0 36 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 63 0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 0 141 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 0 141 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 52 0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 0 0 0 0 36 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 71 29 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 99 29 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 99 29 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 135 135 135 135 135 135 135 135 135 135 135 135 135 135 99 29 135 135 135 135 135 135 135 135 135 135 135 135 135 135 0
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0
)
C=
(
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 98 98 98 98 98 98 98 98 98 98 98 98 98 98 22 165 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 98 98 98 22 165 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 98 98 98 22 165 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 98 98 98 15 165 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 0 0 0 0 172 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 18 0 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 0 230 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 0 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 0 0 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 0 0 0 0 187 224 224 224 224 224 224 224 224 224 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 98 100 101 5 165 224 224 224 224 224 0 0 0 108 224 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 98 98 98 22 165 224 224 224 224 0 0 0 0 0 0 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 98 98 98 22 165 224 224 224 235 0 0 0 0 0 0 224 224 224 224 0
0 98 98 98 98 98 98 98 98 98 98 98 98 98 98 22 165 224 224 224 233 0 0 0 0 0 0 224 224 224 224 0
0 35 35 35 35 41 98 98 98 98 47 35 35 35 35 8 57 77 77 77 51 0 0 0 0 0 0 67 77 77 77 0
0 10 10 10 0 0 98 98 98 98 0 0 10 10 10 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 0 98 98 98 98 0 213 210 210 210 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 0 98 98 98 98 0 213 210 210 210 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 0 0 101 100 0 0 210 210 210 210 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 0 0 0 0 210 210 210 210 210 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 57 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 218 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 219 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 210 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 56 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 210 210 210 210 210 210 210 210 210 210 210 210 210 210 46 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 2 2 2 2 2 2 2 2 2 2 2 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
)
A:=txt2arr(A), B:=txt2arr(B), C:=txt2arr(C)
I:=[]
for l, plane in [A,B,C]
for m, row in plane
for n, num in row
I[m,n,l]:=num
return I
}
txt2arr(txt)
{
rows:=StrSplit(txt,"`n")
arr:=[]
for m, row in rows
for n, num in StrSplit(row,"`t")
arr[m,n]:=num
return arr
}
Good luck, and happy holidays