In this challenge you will be simulating a frog jumping from lily-pad to lily-pad in a pond. A frog's jump distance is uniquely determined by the size of the lily pad it jumps from. So for example there are lily-pads that let a frog jump 1
unit, lily-pads that let a frog jump 2
units etc. A frog can never jump more or less than the allowed amount, nor can it jump out of the pond, but it can jump in either direction.
So we will represent a lily-pad by the number of units it allows a frog to jump. This number is always positive. We will then represent a pond as a list of lily-pads.
Our question is then: If a frog starts on the first lily-pad can they visit every lily-pad in the pond by following the jumping rules?
For example if we have the following pond the answer is yes
[2, 3, 1, 4, 1]
🐸
[2, 3, 1, 4, 1]
🐸
[2, 3, 1, 4, 1]
🐸
[2, 3, 1, 4, 1]
🐸
[2, 3, 1, 4, 1]
🐸
However for the following pond the answer is no:
[3,2,1,2,1,2]
The frog can never reach any lily-pad labeled with a 1.
The frog is allowed to visit the same lily-pad more than once. The following example requires it:
[2, 1, 1, 1]
🐸
[2, 1, 1, 1]
🐸
[2, 1, 1, 1]
🐸
[2, 1, 1, 1]
🐸
[2, 1, 1, 1]
🐸
Some lily-pads are dead ends and need to be visited last for example:
[2,3,1,1]
Here there is nowhere to go from 3
so that has to be the final pad.
Task
For this task you will take as input a non-empty list of positive integers. You should output one of two distinct values, the first if it a frog can reach every lily-pad the second if not.
This is code-golf so your goal is to minimize the size of your source code as measured in bytes.
Test cases
Possible
[10]
[2,1,1,1]
[3,1,4,2,2,1]
[6,1,1,1,1,1,3]
[2,3,1,1]
[2,2,1,2]
[8,9,1,5,2,5,1,7,4]
Impossible
[2,1]
[3,2,1,2,1,2]
[3,2,2,2,2,2]
[3,4,1,2,1,1]
[2,9,1,9]
[3,3,3,1,3,3]