Created
September 3, 2013 05:29
-
-
Save darrenrogan/6420003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Question { | |
void arrayquestion(){ | |
int[] numbs = new int[]{1, 3, 5, 8, 9, 2, 6, 7, 6, 8, 9}; | |
//int[] numbs = new int[]{1, 3, 5, 8, 1, 2, 6, 7, 6, 8, 9}; | |
//int[] numbs = new int[]{10, 1, 2, 3, 4, 5, 6, 7}; | |
//int[] numbs = new int[]{1, 1}; | |
int hops = arrayquestion_sub(numbs,0,1,numbs.length,1); | |
System.out.println(hops); | |
} | |
private int arrayquestion_sub(int[] array,int cur,int move, int length,int counter){ | |
int range = move; | |
if((cur+move)>=length){ | |
System.out.println("Done in " +counter); | |
return counter; | |
} | |
for (int i=1;i<=range;i++){ | |
cur = cur+i; | |
if(cur>=length) return counter--; | |
int possible_hop = array[cur]; | |
//System.out.println(possible_hop); | |
if (possible_hop == 0){ | |
return 0; | |
} | |
counter = arrayquestion_sub(array,cur,possible_hop,length,++counter); | |
counter--; | |
} | |
return counter; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment