MinusOne
提出詳細
type LUT = [9, 0, 1, 2, 3, 4, 5, 6, 7, 8] type Reverse<T extends string, O extends string = ""> = T extends `${infer L}${infer R}` ? Reverse<R, `${L}${O}`> : T extends string ? `${T}${O}` : O type MinusOne_<T extends string> = Reverse<T> extends `${infer Digit extends number}${infer Rest}` ? Digit extends 0 ? `${MinusOne_<Reverse<Rest>>}9` : `${Reverse<Rest>}${LUT[Digit]}` : never type TrimZero<T extends string> = T extends `${infer H extends number}${infer R}` ? R extends "" ? `${H}` : H extends 0 ? TrimZero<R> : T : T type ParseInt<T extends string> = T extends `${infer N extends number}` ? N : never type MinusOne<T extends number> = ParseInt<TrimZero<MinusOne_<`${T}`>>>
提出日時 | 2024-09-10 16:20:52 |
---|---|
問題 | MinusOne |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<MinusOne<1>, 0>>, Expect<Equal<MinusOne<55>, 54>>, Expect<Equal<MinusOne<3>, 2>>, Expect<Equal<MinusOne<100>, 99>>, Expect<Equal<MinusOne<1101>, 1100>>, ]