Last active
October 28, 2016 15:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
calculates the total length of the polyline on Pythagorea, puzzle 7.10