EDIT: Here is the answer he was looking for. To calculate the rounds based on matches:
Math.round(match# / 2) + Round-1-match-count
Glad you could solve it yourself :]
Another way of looking at it:
Let's redesign the problem here. Right now it seems like you're adapting this sort of tree
1
5
2
7
3
6
4
Something like that and you kind of want an algorithm that will get 1/2 to 5, 3/4 to 6, etc. I bet you could make a formula for this but it might be a little more complicated than necessary. If you think about it, 1/2 never has to enter 6, 3/4 never has to enter 5, etc. In fact I think it'd be a lot easier, and accurate, to look at it like this:
0a
2a
1a
3a
0b
2b
1b
Idk how your code is formatted right now but if you wanted to differentiate them, you could do a's and b's .
Now the algorithm to move up is just
if (spot == 0) {
spot=spot+2; //we'll move it to the next because 0 is the only exception
} else { //if odd
spot=spot+1; //ideally we only need to add one to move to the next bracket
}
You can use parseInt
to get the number only. But wait! how will it know which slot to go to because they are the same number? That's why we can use the letters. The cool thing about strings is that they are are just an array of characters stringed together. Example:
var word = "Hello";
word[0] = "H";
So you can access the letter by doing spot[1]
and that way you can make sure that a's stick with a's and b's stick with b's. Hope this helps.
Oh and one last thing. You might be wondering what about the 3a? There is no b there. Well I'm not entirely sure if you want a letter there anyways but if you did want it, you could just make your code to see if a b exists. If it doesn't, then put it in a because that's the only spot it can go.