The TransCompilator

Solved LeetCode program · 952 of 1,000

#1318 · Minimum Flips to Make a OR b Equal to c

Medium Bit Manipulation chunk-20.md

Original English source

The first is 2. The second is 6. The target is 5. The flips is 0.
Repeat while first is more than 0 or second is more than 0 or target is more than 0.
The firstbit is first modulo 2. The secondbit is second modulo 2. The targetbit is target modulo 2. The wanted is (1 minus firstbit) times (1 minus secondbit). Set first to first divided by 2. Set second to second divided by 2. Set target to target divided by 2. If targetbit is 0, Add firstbit to flips, Add secondbit to flips, otherwise Add wanted to flips.

Show flips.

Open in Playground Browse all 1,000 problems

Expected stdout

3