Skip to content

Commit

Permalink
Update 2.1.md
Browse files Browse the repository at this point in the history
[Fix] Update to solution for 2.1-4

The previous solution has a couple mistakes involved (utilizing the loop variable beyond its block, incorrect output). I wrote up the issue report via this link: walkccc#437
  • Loading branch information
AndrewRoe34 authored and Peng-Yu Chen committed Mar 21, 2022
1 parent 22a31b2 commit 19b8167
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions docs/Chap02/2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,15 @@ LINEAR-SEARCH(A, v)

```cpp
ADD-BINARY(A, B)
r = 0
C = new integer[A.length + 1]
carry = 0
for i = 1 to A.length
C[i] = (A[i] + B[i] + carry) % 2 // remainder
carry = (A[i] + B[i] + carry) / 2 // quotient
C[i + 1] = carry
for i = A.length to 1 do
s = A[i] + B[i] + r
C[i + 1] = s % 2
if s > 1
r = 1
else
r = 0
C[1] = r
return C
```

0 comments on commit 19b8167

Please sign in to comment.