-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(question): add #31820 - Transposed Matrix
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
112
questions/31820-extreme-transposed-matrix/test-cases.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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][] | ||
]>> | ||
] |