7 kyu

Hop Across

257 of 561marbiru

Description:

You are trying to cross a river by jumping along stones. Every time you land on a stone, you hop forwards by the value of that stone. If you skip over a stone then its value doesn't affect you in any way. Eg:

 x--x-----x-->
[1][2][5][1]

Of course, crossing from the other side might give you a different answer:

 <--------x--x
   [1][2][5][1]

Given an array of positive integers, return the total number of steps it would take to go all the way across the river (and past the end of the array) and then all the way back. All arrays will contain at least one element, and may contain up to 100 elements.

Examples

  x--x-----x-->
 [1][2][1][2]
<----x-----x

therefore hop_across([1,2,1,2]) = 3 + 2 = 5

   x-----x--------x------>
  [2][2][3][1][1][2][1]
<--------x--x-----x--x

therefore hop_across([2,2,3,1,1,2,1]) = 3 + 4 = 7
Fundamentals

More By Author:

Check out these other kata created by marbiru

Stats:

CreatedJan 18, 2018
PublishedJan 18, 2018
Warriors Trained1216
Total Skips46
Total Code Submissions1455
Total Times Completed561
Python Completions257
Groovy Completions24
JavaScript Completions161
Ruby Completions53
C# Completions111
Total Stars20
% of votes with a positive feedback rating91% of 169
Total "Very Satisfied" Votes146
Total "Somewhat Satisfied" Votes17
Total "Not Satisfied" Votes6
Total Rank Assessments7
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • marbiru Avatar
  • romerojp Avatar
  • adrian.eyre Avatar
  • Blind4Basics Avatar
  • Souzooka Avatar
  • saudiGuy Avatar
Ad