# Digit antitranspose

Convert a matrix or grid of digits to its antitranspose. For a square matrix , this is its reflection in its antidiagonal. More generally, for a rectangular matrix, this is its reflection in its skew diagonal.

Less formally, the line to reflect in is from South West to North East, at 45 degrees regardless of the proportions of the rectangle.

## Input

- A (not necessarily square) matrix or grid of single digit non-negative numbers
- This may be a matrix or any 2 dimensional data structure or a 1 dimensional data structure along with width and/or height, or a sequence of 1 dimensional data structures representing rows
- The width and height will always be at least 1 (the grid will never be empty)
- All rows will have the same length (the input will always be rectangular)
- The single digit numbers contained in this data structure may be of number types or characters or single character strings

For example, the input may be a string of numeric characters with delimiters between rows.

## Output

- The same data structure type as the input
- This applies to every nested level: if the input is a list of strings of characters, the output must be a list of strings of characters

- Each digit in the input is moved:
- from (x, y) to (height - y - 1, width - x - 1) (if zero indexed from top left)
- from (x, y) to (height - y + 1, width - x + 1) (if one indexed from top left)

## Examples

In these examples input and output are represented as newline separated strings of characters. You can check that the input and output match by holding a reflective surface such as a mirror or phone screen at 45 degrees next to the input. The reflected numbers won't be upright but they will be in the same locations as the output.

### Square input

```
012
345
678
```

### Square output

```
852
741
630
```

### Rectangular input

```
01
23
45
67
```

### Rectangular output

```
7531
6420
```

## Test cases

Test cases are in the format `"input" : "output"`

where the input and output are strings containing comma separated rows. For comparison, the first 2 test cases are the same as the examples shown above.

```
"012,345,678" : "852,741,630"
"01,23,45,67" : "7531,6420"
"852,741,630" : "012,345,678"
"7531,6420" : "01,23,45,67"
"0" : "0"
"12" : "2,1"
"2,1" : "12"
"3,4" : "43"
"43" : "3,4"
"56,78" : "86,75"
"86,75" : "56,78"
"7777" : "7,7,7,7"
"7,7,7,7" : "7777"
```

Explanations are optional, but I'm more likely to upvote answers that have one.

Vyxal, 3 bytes ``` ∩ṘR ``` …

1y ago

J, 8 char Solution: ``` | …

1y ago

Japt, 2 bytes Input as a mu …

1y ago

[Python 3], 35 bytes …

1y ago

## 4 answers

# Python 3, 35 bytes

```
lambda m:list(zip(*m[::-1]))[::-1]
```

The format is a list of tuples. The content of the tuples could be any type; in my tests I used single-digit strings because I was lazy when writing the testing code.

`seq[::-1]`

reverses a sequence (tuple ot list). `zip(*seq)`

does a normal transpose (it gives a tuple generator, which is why I use tuples for the rows), which I convert to a list (I use a list because `tuple`

has one character more than `list`

).

#### 0 comment threads

# J, 8 char

**Solution:**

```
|:|.|."1
```

**Test example:**

```
(i. 3 3)
0 1 2
3 4 5
6 7 8
|:|.|."1 (i. 3 3)
8 5 2
7 4 1
6 3 0
(i. 4 2)
0 1
2 3
4 5
6 7
|:|.|."1 (i. 4 2)
7 5 3 1
6 4 2 0
```

**How it works:**

```
|."1 reverses the order of each row of the array on its right
|. then flips the array on its right, horizontally
|: then reverses the axes of the array on its right
```

## 0 comment threads