Flip and filter a grid
You are given an integer grid with r rows and c columns.
Using comprehensions instead of loops, build and print these three things.
1) The flipped grid: the j-th column of the original (top to bottom) becomes the j-th row of the new grid.
Print c lines with r numbers each, separated by single spaces.
2) Squares of multiples of 3: read the grid from the top row down, and left to right within a row, keep only the multiples of 3 (including 0 and negatives) and square them.
Print the count k first, then the k squares in reading order, all on one line separated by spaces.
If there are none, print just 0.
3) Print the number of distinct values in the grid.
- Input
- First line r c, then r lines of c integers.
1 ≤ r, c ≤ 50, -1000 ≤ value ≤ 1000 - Output
- c lines of the flipped grid, then a line with k and the k squares, then a line with the number of distinct values
2 3 1 3 -6 4 9 3
1 4 3 9 -6 3 4 9 36 81 9 5