Hardware interview practice
Constrain a bounded zig-zag address walk
Randomize 20 addresses from 0 through 255 where every step is 1-8 and the step direction alternates up, down, up, down or vice versa.
Reviewed example
Work through one case
Input
randomize 20 addresses in 0..255 with alternating step direction and magnitude 1..8Expected output
One valid result: [100,104,102,108,105,110,109,117,112,118,114,121,115,120,116,123,119,125,122,127]Every adjacent value differs by 1..8, all values stay in range, and step signs alternate +,- throughout. Other walks are valid.
What to cover
Requirements
- Adjacent addresses must never be equal.
- The absolute difference of each step must be at most eight.
- Starting with the third address, consecutive step directions must differ.
