Skip to content
New issue

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

30575 - BitwiseXOR #32481

Open
lvjiaxuan opened this issue Mar 5, 2024 · 0 comments
Open

30575 - BitwiseXOR #32481

lvjiaxuan opened this issue Mar 5, 2024 · 0 comments
Labels
30575 answer Share answers/solutions to a question en in English

Comments

@lvjiaxuan
Copy link
Contributor

type Reverse<S extends string> = S extends `${infer First}${infer Rest}` ? `${Reverse<Rest>}${First}` : ''

type GetLastAndRest<S extends string, _S extends string = Reverse<S>>
  = _S extends `${infer Last extends string}${infer Rest extends string}`
    ? { Last: Last, Rest: Reverse<Rest> }
    : { Last: '', Rest: '' }

type XOR<S1 extends string, S2 extends string> = S1 extends S2 ? '0' : '1'

type BitwiseXOR<
  S1 extends string,
  S2 extends string,
  _S1 extends { Last: string, Rest: string } = GetLastAndRest<S1>,
  _S2 extends { Last: string, Rest: string } = GetLastAndRest<S2>
> = `${ _S1['Rest'] }${ _S2['Rest'] }` extends ''
    ? `${XOR<_S1['Last'], _S2['Last']>}`
    : `${BitwiseXOR<_S1['Rest'], _S2['Rest']>}${XOR<_S1['Last'], _S2['Last']>}`
@lvjiaxuan lvjiaxuan added answer Share answers/solutions to a question en in English labels Mar 5, 2024
@github-actions github-actions bot added the 30575 label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
30575 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

1 participant