We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// 解答をここに記入 type BinaryToDecimal<S extends string, Counter extends never[] = [never], Ans extends never[] = []> = S extends `${infer Rest}1` ? BinaryToDecimal<Rest, [...Counter, ...Counter], [...Ans, ...Counter]> : S extends `${infer Rest}0` ? BinaryToDecimal<Rest, [...Counter, ...Counter], Ans> : Ans["length"]
非常にシンプルな解答です。
2進数を下(2^0の方)から処理していく再帰で、Counter はその桁に対応する長さを持っています。
Ans は、解答となる数字を配列長で表現するための配列で、S の下一桁が 1 だったら Ans に Counter の要素を追加する(これはその桁の分をインクリメントする行為と同じ)ことで、10進数に変換していきます。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
非常にシンプルな解答です。
2進数を下(2^0の方)から処理していく再帰で、Counter はその桁に対応する長さを持っています。
Ans は、解答となる数字を配列長で表現するための配列で、S の下一桁が 1 だったら Ans に Counter の要素を追加する(これはその桁の分をインクリメントする行為と同じ)ことで、10進数に変換していきます。
The text was updated successfully, but these errors were encountered: