Imagine that a list of integers describes the heights of some two-dimensional terrain as seen from the side.
Stamina: [ 4 4 4 4 4 4 3 3 3 3 2 2 2 - ] O /|\ / \ +---+ +---+ | | | | +---+ +---+---+ +---+ | | | | | | | +---+ +---+---+ +---+ +---+ | | | | | | | | | +---+ +---+---+ +---+---+ +---+ | | | | | | | | | | +---+---+ +---+---+---+ +---+---+---+ +---+ | | | | | | |OW!| | | |OW! STUCK!| | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | | | | | | | | | | | | | | | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+ Height: [ 6 2 1 2 5 6 1 2 3 5 1 1 1 4 ]
A climber is standing on the first piece of terrain. Her goal is to reach the far end. She has a stamina rating that determines the maximum height she can climb. Unfortunately, she has never heard of rappelling before, so she simply jumps off any cliffs she encounters. If she falls a greater distance than her current stamina, her stamina drops by one.
Task
Determine whether the climber can traverse the terrain.
Rules
- The climber moves strictly from left to right.
- The climber must visit every piece of reachable terrain.
- Stamina determines maximum climbing height.
- Stamina decreases by one when fall height exceeds stamina — no matter how long the drop.
- Zero is the minimum stamina.
- The terrain is untraversable if the climber encounters a cliff above her that is taller than her current stamina level.
- The terrain is traversable if the climber is able to stand on the last piece of terrain.
- This is code-golf, so the answer with the fewest bytes (in each language) wins.
Format
- You must accept an integer (representing starting stamina) and a list of integers (representing heights) in any reasonable format.
- You must output a truthy/falsy value. You may either use your language's convention for truthy/falsy or any two distinct values representing truthy and falsy.
- Starting stamina will be \$\geq0\$.
- The length of the list will be \$\geq2\$.
- All heights in the list will be \$\geq1\$.
Test cases
The farthest reachable piece of terrain is in bold.
Truthy | What is this testing? |
---|---|
|
|
Falsy | What is this testing? |
---|---|
|
|