Skip to content

Commit

Permalink
feat(question): add #31820 - Transposed Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
E0SelmY4V committed Jan 23, 2024
1 parent e77262d commit b06d09f
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
18 changes: 18 additions & 0 deletions questions/31820-extreme-transposed-matrix/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Transposition is a math concept.
We can use 2d tuples to describe a matrix in TS.
Like this:

```ts
type SomeMatrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];
type TransposedSomeMatrix = [
[1, 4, 7],
[2, 5, 8],
[3, 6, 9]
];
```

It's easy to understand, so the mission of making a type which can transpose given 2d tuple as accurate as possible is now assigned to you!
6 changes: 6 additions & 0 deletions questions/31820-extreme-transposed-matrix/info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
difficulty: extreme
title: Transposed Matrix
author:
github: E0SelmY4V
name: Eosellmay Li

2 changes: 2 additions & 0 deletions questions/31820-extreme-transposed-matrix/template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type Matrix = readonly (readonly any[])[];
type Transposed<T extends Matrix> = any;
112 changes: 112 additions & 0 deletions questions/31820-extreme-transposed-matrix/test-cases.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import type { Equal, Expect } from '@type-challenges/utils'
import { ExpectFalse, NotEqual } from '@type-challenges/utils'

type cases = [
Expect<Equal<Transposed<[
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]>, [
[1, 4, 7],
[2, 5, 8],
[3, 6, 9]
]>>,
Expect<Equal<Transposed<[
['a', 'b', 'c', 'd'],
['e', 'f', 'g', 'h'],
['i', 'j', 'k', 'l']
]>, [
['a', 'e', 'i'],
['b', 'f', 'j'],
['c', 'g', 'k'],
['d', 'h', 'l']
]>>,
Expect<Equal<Transposed<[
[1, 2, 3],
[4, 5]
]>, [
[1, 4],
[2, 5],
[3]
]>>,
Expect<Equal<Transposed<number[][]>, number[][]>>,
Expect<Equal<Transposed<[
[1, 2],
[3],
[4, 5]
]>, [
[1, 3, 4],
[2, undefined, 5]
]>>,
Expect<Equal<Transposed<[
[1, 2],
[3],
...[4][],
]>, [
[1, 3, ...4[]],
[2]
]>>,
Expect<Equal<Transposed<[
[1, 2],
[3],
...[4, 5, 6][],
]>, [
[1, 3, ...4[]],
[2, undefined, ...5[]],
[undefined, undefined, ...6[]]
]>>,
Expect<Equal<Transposed<[
[1, 2, 3],
[4],
...[5][],
[6, 7]
]>, [
[1, 4, ...5[], 6],
[2, undefined, ...undefined[], 7],
[3]
]>>,
Expect<Equal<Transposed<[
[1, ...2[]],
[3, 4, ....5[]]
]>, [
[1, 3],
[2 | undefined, 4],
...[2 | undefined, 5 | undefined][]
]>>,
Expect<Equal<Transposed<[
[1, ...2[], 3],
[4, 5, ....6[], 7, 8],
[...9[], 0]
]>, [
[1, 4, 9 | 0],
[2 | 3, 5, 9 | 0 | undefined],
[2 | 3 | undefined , 6 | 7, 9 | 0 | undefined],
[2 | 3 | undefined , 6 | 7 | 8, 9 | 0 | undefined],
...[2 | 3 | undefined , 6 | 7 | 8 | undefined, 9 | 0 | undefined][]
]>>,
Expect<Equal<Transposed<[
[1, 2],
...[3, ...4[]][]
]>, [
[1, ...3[]]
[2, ...4[]],
...[undefined, ...4[]][]
]>>,
Expect<Equal<Transposed<
[1, 2, 3][]
>, [
1[],
2[],
3[]
]>>,
Expect<Equal<Transposed<[
[1],
...[2, ...3[], 4, 5][],
[6, 7, ...8[], 9]
]>, [
[1, ...2[], 6],
[undefined, ...(3 | 4)[], 7],
[undefined, ...(3 | 4 | 5)[], 8 | 9],
...[undefined, ...(3 | 4 | 5 | undefined)[], 8 | 9 | undefined][]
]>>
]

0 comments on commit b06d09f

Please sign in to comment.