Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Solver(input) {
- var terrain = input[0].split(', ');
- var maxVisited = 0;
- var terrainLength = terrain.length;
- for (var i = 0; i < terrainLength; i+=1) {
- terrain[i] = terrain[i] | 0;
- }
- for (var jumpSize = 1; jumpSize < terrainLength; jumpSize+=1) {
- for (var startPos = 1; startPos < terrainLength; startPos++) {
- var currentMax = 1;
- var position = startPos;
- var nextStep = position + jumpSize >= terrainLength ?
- position + jumpSize - terrainLength : position + jumpSize;
- while (terrain[position] < terrain[nextStep]) {
- currentMax+=1;
- position = nextStep;
- nextStep = position + jumpSize >= terrainLength ?
- position + jumpSize - terrainLength : position + jumpSize;
- }
- if (currentMax > maxVisited) {
- maxVisited = currentMax;
- }
- }
- }
- return maxVisited;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement