Skip to content

Instantly share code, notes, and snippets.

@audreybongalon
Last active October 28, 2016 15:40
Show Gist options
  • Select an option

  • Save audreybongalon/804379ee2bd238d71ec1fa5b37c94091 to your computer and use it in GitHub Desktop.

Select an option

Save audreybongalon/804379ee2bd238d71ec1fa5b37c94091 to your computer and use it in GitHub Desktop.
meant to calculate the length of a polyline, to help solve level 7.10 in the Android game Pythagorea
// calculates the total length of the polyline on Pythagorea, puzzle 7.10
var polyline = [[4,3], [1,2], [2,1], [1,1], [1,3],
[1,1], [2], [1,2], [2,1], [1,3],
[1,1], [1], [1,1], [2], [1]];
var grandtotal = 0;
function findc(a, b) {
var a2pb2 = 0;
a2pb2 += (a * a);
a2pb2 += (b * b);
a2pb2 = Math.sqrt(a2pb2);
console.log(a2pb2);
grandtotal += a2pb2;
}
for (var i = 0; i < polyline.length; i++) {
if (polyline[i].length == 2) {
// console.log(polyline[i]);
findc(polyline[i][0], polyline[i][1]);
}
else {
// console.log(polyline[i]);
grandtotal += polyline[i][0];
}
console.log((i + 1) + " - " + grandtotal);
}
grandtotal /= 2;
console.log(grandtotal);
@audreybongalon
Copy link
Author

calculates the total length of the polyline on Pythagorea, puzzle 7.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment