The TransCompilator

Solved LeetCode program · 819 of 1,000

#1073 · Adding Two Negabinary Numbers

Medium Array chunk-17.md

Original English source

The first is a list of 1, 1, 1, 1, and 1. The second is a list of 1, 0, and 1. The firstspot is the last position of first. The secondspot is the last position of second. The carry is 0. The digits is an empty list of whole numbers.
Repeat while firstspot is at least 0 or secondspot is at least 0 or carry is not 0.
The firstbit is 0. If firstspot is at least 0, set firstbit to item firstspot of first. The secondbit is 0. If secondspot is at least 0, set secondbit to item secondspot of second. The total is carry plus firstbit plus secondbit. If firstspot is at least 0, subtract 1 from firstspot. If secondspot is at least 0, subtract 1 from secondspot. The bit is total modulo 2. If bit is less than 0, add 2 to bit. Place bit into digits. Set carry to (total minus bit) divided by (0 minus 2).

The last is the last position of digits.
Repeat while last is more than 0 and item last of digits is 0.
Remove the last item from digits. Set last to the last position of digits.

For every step from 0 to last.
The place is last minus step. Show item place of digits.

Open in Playground Browse all 1,000 problems

Expected stdout

1
0
0
0
0