The LAMBCHOP doomsday device takes up much of the interior of Commander Lambda's space station, and as a result the prison blocks have an unusual layout. They are stacked in a triangular shape, and the bunny prisoners are given numerical IDs starting from the corner, as follows:
| 4 8
| 2 5 9
| 1 3 6 10
Each cell can be represented as points (x, y), with x being the distance from the vertical wall, and y being the height from the ground.
For example, the bunny prisoner at (1, 1) has ID 1, the bunny prisoner at (3, 2) has ID 9, and the bunny prisoner at (2,3) has ID 8. This pattern of numbering continues indefinitely (Commander Lambda has been taking a LOT of prisoners).
Write a function answer(x, y) which returns the prisoner ID of the bunny at location (x, y). Each value of x and y will be at least 1 and no greater than 100,000. Since the prisoner ID can be very large, return your answer as a string representation of the number.
Here is my solution:
y = int(input()) x = int(input()) sum_in_x = 1 for i in range(x): sum_in_x = sum_in_x + range(x)[i] in_sum =i + 2 sum_in_y = sum_in_x for j in range(y - 1): sum_in_y = sum_in_y + in_sum in_sum += 1 print(sum_in_y)
It works and generates the needed solutions, but I am trying to understand if there are better ways of doing this.