Skip to content

Instantly share code, notes, and snippets.

@anhnguyen1618
Created January 9, 2020 17:08
Show Gist options
  • Save anhnguyen1618/66d006dbb3c1361f6c8efe70b72c1e67 to your computer and use it in GitHub Desktop.
Save anhnguyen1618/66d006dbb3c1361f6c8efe70b72c1e67 to your computer and use it in GitHub Desktop.
function f(a, b) {
const list = [[a, 1, 0], [b, 0 ,1], [], [], [], [], [], []];
let i = 1;
while(list[i][0] > 0) {
list[i][3]= Math.floor(list[i-1][0] / list[i][0]);
list[i + 1][0] = list[i-1][0] - list[i][3] * list[i][0];
list[i + 1][1] = list[i - 1][1] - list[i][3] * list[i][1];
list[i + 1][2] = list[i - 1][2] - list[i][3] * list[i][2];
i++;
}
console.log(list);
return i-1;
}
0: (3) [1234567, 1, 0]
1: (4) [123, 0, 1, 10037]
2: (4) [16, 1, -10037, 7]
3: (4) [11, -7, 70260, 1]
4: (4) [5, 8, -80297, 2]
5: (4) [1, -23, 230854, 5]
6: (3) [0, 123, -1234567]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment