The pyramid I want you to build is made entirely of cubes. It has 24 layers, and the Nth layer from the top contains N2 cubes arranged in an N by N square. The pyramid looks like this:
To build the pyramid, you will need a supply of cubes. You are given 4900 cubes arranged in a 70 by 70 square that looks like this:
(Okay, I admit that the picture of the square is entirely unnecessary.)
Since 12 + 22 + 32 + ... + 242 = 702, you have exactly the right number of cubes to build the pyramid. All you have to do is tell me where each cube should go.
You should pick an arbitrary bijection between the cubes in the square and the cubes in the pyramid. (It would be nice if your answer said which of the 4900! different bijections you're using.)
Then, write a function or program that does the following:
- Given the location of a cube in the 70 by 70 square (as a pair of coordinates
- Output its location in the pyramid (as a triple of coordinates
The input and output coordinates can all be either 0-indexed or 1-indexed. Assuming 1-indexed, your input
(X,Y) will be a pair of integers between 1 and 70. Your output
(A,B,C) will be a triple of integers;
A should be the layer counting from the top (between 1 and 24) and
(B,C) should be the coordinates of that cube within that layer (between 1 and
- the top cube of the pyramid has coordinates
- The four corners of the base of the pyramid have coordinates
- If you decide to place the corners of the square at the corners of the pyramid, then on input
(70,1)you might give the output
You may assume you will only be given valid coordinates
(X,Y) as input. Correctness is entirely determined by the following rule: two different valid inputs should always give two different valid onputs.
This is code-golf: the shortest code wins.