Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyBUK authored Mar 6, 2022
1 parent 0ed364d commit 3d4df4d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions 2015/Day03/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ The basic algorithm is to count how many unique times each pair of X/Y values oc

As per Part 1, except rather than a single X/Y pair, we now need to keep track of two indepently moving X/Y pairs. This is achieved internally with a very simple trick to manipulate an array index, whereby we just want to alternative Santa moves and Robot moves every other cycle. The code achieves this with:

nCurrent = 1 - nCurrent
nCurrent = 1 - nCurrent

Which will alternative the value of nCurrent every cycle between 0,1,0,1 etc. This could have also been achieved with:

nCurrent = (nCurrent + 1) % 2
nCurrent = (nCurrent + 1) % 2

or

if nCurrent == 0 : nCurrent = 1
else : nCurrent = 0
if nCurrent == 0 : nCurrent = 1
else : nCurrent = 0

They all achieve the same thing.

Expand Down

0 comments on commit 3d4df4d

Please sign in to comment.