Referring to picture below at here, x and y means coordinates. For symmetrical coordinates part, the numbering will be symmetrical also and if its not symmetrical, it will keep adding i+1 index. For coordinates that is equal to each other side by side, the index will stay constant. I have attached a codepen file at here for javascript playground. The output that I want is the index in array as shown in picture. How do I go about in solving this algorithm :)?
Thank you for reading
x_all=[102,152, 202,252 ,202,152, 302,454 ,8745,8745 ,25, 25, 23, 10 , 332, 10 , 67 , 90, 67 ,8967];
y_all=[12, 153, 20, 52, 20, 153, 302,8745,9065,9065, 52, 34, 9 ,232, 9 , 232, 89 ,91, 89 ,8954];
arr=[];
jj=0
for (let i=0;i<x_all.length;i++){
if (x_all[i+1]==x_all[i-1]){
console.log(i)
jj=jj-1;
arr.push(jj+1)
}
arr.push(jj)
jj=jj+1;
}
console.log(arr)
PARTIAL ANSWER DISCLAIMER: I did not fully comprehend the question (The image in the question - https://ibb.co/qssJk3K - is also not accessible!) - and so this is in no way the complete answer.
but meh 🤷♀️ found it somewhat interesting to solve so tried this. Hope it helps.
Here's what I tried - For
x_all=[102,152, 202,252 ,202,152, 302,454 ,8745,8745 ,25, 25, 23, 10 , 332, 10 , 67 , 90, 67 ,8967];
Found enclosing palindromes and added them to a palindrome_x
[[152,202,252,202,152],
[8745,8745],
[25,25],
[10,332,10],
[67,90,67]]
Used an indexes array to push and pop as required. So the
Final Output For x: 1,2,3,4,3,2,5,6,7,7,8,8,9,10,11,10,12,13,12,14
Not sure if this is what is required... But there are commented console.log-er statements for further debugging.