deirh.mana
BAN USERCorrection:
3) if ( (i) >= (i-2) ) /* simple collision with i-3 */
Since two spirals can coexist peacefully (unless we are given infinite number of following steps) we need to compare the last length at least against 5 previous lengths.
So our window size should be 6. My take on this:
Let i be the value of last step. A positive collision should then satisfy all of the following:
1) i >= 4 /* can't collide with previous two */
// test lengths from now on, "len" omitted for brevity
2) (i-1) <= (i-3) /* collision possible, we are spiraling inside */
3) if ( (i)+(i-4) >= (i-2) ) /* simple collision with i-3 */
else /* we can still collide with i-5 as it could be between us and i-3 */
if ((i-2) >= (i-4) /* i-5 lies in front of us */
&& (i-1) + (i-5) >= (i-3) /* part of i-5 is in the way */
&& (i) + (i-4) >= (i-2)) /* we go far enough to collide with i-5 */
Note: If we have less than 6 nodes, assume value of the nonexistent ones to be 0.
Let me know what you think.
Hi Dave, I'd say considering only last 5 is not enough.
Consider [1, 1, 2, 5, 3, 3, 2] - this one should pass
while [ 1, 2, 2, 5, 3, 3, 2] should fail.
Both have same last 5 numbers.
I'd adjust the rules as following:
1) i >= 4
// test lengths from now on, "len" omitted for brevity
2) (i-1) <= (i-3) /* collision possible, we are spiraling inside */
3) if ( (i)+(i-4) >= (i-2) ) /* collision with i-3 */
else /* we can still collide with i-5 as it could be between us and i-3 */
if ((i-2) >= (i-4) /* i-5 lies in front of us */
&& (i-1) + (i-5) >= (i-3) /* part of i-5 is in the way */
&& (i) + (i-4) >= (i-2)) /* we go far enough to collide with i-5 */
Let me know what you think.
Correction:
- deirh.mana September 05, 20153) if ( (i) >= (i-2) ) /* simple collision with i-3 */