You will be provided with a list of numbers. Your goal is to visit each index of the list. Starting from some element, you must look at the value stored in that element, and then move that many spaces left or right (if it is possible to do so within the bounds of the list).
If it is possible to visit all elements in this fashion, print / output a truthy value. Otherwise, a falsy one.
Inputs
A list / array of positive integers between 1 and 10,000 elements long, with each value being between 1 and 100,000 inclusive.
Outputs
A truthy or falsy value depending on if it is possible to traverse the array, exploring every element.
Rules
Code golf scoring
- You may start at any index
- You do not need to move off the finally visited element.
Worked examples
== Traversible == Step [4,2,6,1,3] 1 x 2 x x 3 x x x 4 x x x x 5 x x x x x = Untraversible = Step [6,4,3,2,1] 1 x 2 x x 3 x x x stuck - this is just one example of an attempt, but there is no way to successfully traverse this array. Test cases
Format: traversible,array 1,[1] 1,[10000] 1,[1,2] 1,[4,2,6,1,3] 1,[98, 21, 27, 18, 20, 62, 29, 24, 37, 84, 3, 5, 13, 53, 55, 84, 34, 75, 39, 53, 17, 59, 10, 37, 22, 33, 21, 51, 23, 66, 9, 31, 32, 9, 98, 13, 38, 31, 16, 31, 21, 8, 23, 22, 40, 1, 50, 15, 28, 7, 13, 33, 39, 48, 17, 26, 39, 19, 24, 52, 59, 26, 58, 35, 9, 32, 64, 44, 28, 19, 24, 6, 13, 30, 16, 48, 21, 62, 1, 70, 3, 48, 30, 8, 48, 1, 60, 2, 78, 48, 22, 32, 81, 59, 41, 19, 84, 26, 68, 85] 0,[6,4,3,2,1] 0,[37, 6, 77, 74, 48, 75, 11, 14, 11, 1, 71, 78, 23, 65, 44, 67, 10, 65, 2, 6, 14, 19, 8, 26, 4, 14, 71, 35, 38, 16, 66, 5, 12, 10, 29, 55, 5, 61, 14, 11, 43, 35, 17, 34, 44, 22, 23, 1, 16, 47, 4, 43, 39, 49, 22, 19, 1, 56, 10, 41, 48, 58, 37, 5, 58, 10, 20, 40, 25, 6, 28, 13, 23, 14, 8, 44, 9, 26, 6, 65, 12, 34, 65, 30, 28, 85, 64, 26, 50, 81, 25, 21, 81, 24, 34, 81, 25, 52, 25, 94] 0,[2,3] Example traversal order for the 5th test case (list of indexes):
[70, 94, 53, 5, 67, 23, 60, 1, 22, 32, 64, 73, 43, 65, 97, 71, 77, 15, 99, 14, 69, 88, 10, 13, 66, 2, 29, 95, 76, 55, 81, 33, 42, 19, 72, 85, 86, 26, 47, 62, 4, 24, 46, 96, 12, 25, 58, 82, 52, 91, 59, 7, 31, 0, 98, 30, 39, 8, 45, 44, 84, 36, 74, 90, 68, 40, 61, 87, 89, 41, 49, 56, 17, 92, 11, 16, 50, 63, 28, 51, 18, 57, 38, 54, 37, 6, 35, 48, 20, 3, 21, 80, 83, 75, 27, 78, 79, 9, 93, 34]