Length of String 2
提出詳細
// 上限突破により時間切れかOOMするまで数える type _UnwrapInternal<T> = T extends { __rec: never } ? never : T extends { __rec: { __rec: infer U } } ? { __rec: _UnwrapInternal<U> } : T extends { __rec: infer U } ? U : T; type Unwrap<T, H extends "__hack" = "__hack"> = T extends { __rec: unknown } ? { [H0 in H]: Unwrap<_UnwrapInternal<T>> }[H] : T; type Split<S extends string, Acc extends string[] = []> = S extends `${infer L}${infer R}` ? { __rec: Split<R, [...Acc, L]> } : { __rec: Acc } type Len<T extends { __rec: unknown }, N = Unwrap<T>> = N extends unknown[] ? N["length"] : never type LengthOfString<S extends string> = Len<Split<S>>
提出日時 | 2024-09-12 06:28:52 |
---|---|
問題 | Length of String 2 |
ユーザー | ookkoouu |
ステータス | Accepted |
import type { Equal, IsTrue } from '@type-challenges/utils' type cases = [ IsTrue<Equal<LengthOfString<''>, 0>>, IsTrue<Equal<LengthOfString<'1'>, 1>>, IsTrue<Equal<LengthOfString<'12'>, 2>>, IsTrue<Equal<LengthOfString<'123'>, 3>>, IsTrue<Equal<LengthOfString<'1234'>, 4>>, IsTrue<Equal<LengthOfString<'12345'>, 5>>, IsTrue<Equal<LengthOfString<'123456'>, 6>>, IsTrue<Equal<LengthOfString<'1234567'>, 7>>, IsTrue<Equal<LengthOfString<'12345678'>, 8>>, IsTrue<Equal<LengthOfString<'123456789'>, 9>>, IsTrue<Equal<LengthOfString<'1234567890'>, 10>>, IsTrue<Equal<LengthOfString<'12345678901'>, 11>>, IsTrue<Equal<LengthOfString<'123456789012'>, 12>>, IsTrue<Equal<LengthOfString<'1234567890123'>, 13>>, IsTrue<Equal<LengthOfString<'12345678901234'>, 14>>, IsTrue<Equal<LengthOfString<'123456789012345'>, 15>>, IsTrue<Equal<LengthOfString<'1234567890123456'>, 16>>, IsTrue<Equal<LengthOfString<'12345678901234567'>, 17>>, IsTrue<Equal<LengthOfString<'123456789012345678'>, 18>>, IsTrue<Equal<LengthOfString<'1234567890123456789'>, 19>>, IsTrue<Equal<LengthOfString<'12345678901234567890'>, 20>>, IsTrue<Equal<LengthOfString<'123456789012345678901'>, 21>>, IsTrue<Equal<LengthOfString<'1234567890123456789012'>, 22>>, IsTrue<Equal<LengthOfString<'12345678901234567890123'>, 23>>, IsTrue<Equal<LengthOfString<'aaaaaaaaaaaaggggggggggggggggggggkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'>, 272>>, ]