-
Senior Member
Ralgoth your cycle2 has a logical problem...
Code:
function cycle2(len:uint,position:int):uint
{
if(position < 0) position = len + -position;
return position%len;
}
len = 10
position = -1
position = len + -position == 11
11%10 = 1
but position -1 should correspond to item [9] in the array.
What about:
Code:
//edit:
//edit #3. argh:
position = position<0 ? len-(-position%len) : position%len;
///edit: alright I think I finally got it, I'm too wasted to be doing this at 12:30 am...
///edit #47, I think I just reproduced what Moagrius did like six posts ago by trial and error. Just shoot me please.
Last edited by joshstrike; 01-19-2010 at 04:29 AM.
-
newb of many sorts
haha, yeah I didn't get it right until I woke up at 6AM after the whiskey wore off. (most of my friends drunk dial/text... I give drunk coding advice)
it ended up that you cant check if position is a negative, you have to do the modulo first. otherwise if the position is a multiple of the len then the modulo would be 0, and no longer a negative.
the above code would return the array's length (len-(0)).
--- edit --- whiskey goes well w/ coffee.
Last edited by Ralgoth; 01-19-2010 at 10:33 AM.
Search first, asked questions later.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|