codekofi
← All problems

Problem 67

Medium

1 · Worked examples

0 / 3

Type an input and write what you think is the output . Each problem is converted to Web Assembly, so any possible input will show the corresponding output. Only correct predictions count.

solution()
returns

2 · Which problem is it?

Locked until you have predicted 3 outputs correctly.

The accepted solution

1int solution(int a, int b) {
2
3 unsigned int x = a;
4 unsigned int y = b;
5
6 while (y) {
7
8 unsigned int carry = x & y;
9
10 x = x ^ y;
11 y = carry << 1;
12 }
13
14 return (int)x;
15}

Names have been stripped. The signature is the only clue you get for free. Compiled as C++20 with the standard headers and using namespace std; already in scope.