Skip to content

Instantly share code, notes, and snippets.

@amrishodiq
Created June 8, 2016 02:11
Show Gist options
  • Save amrishodiq/2a07a4fed9d906c517fb444d4ee14d63 to your computer and use it in GitHub Desktop.
Save amrishodiq/2a07a4fed9d906c517fb444d4ee14d63 to your computer and use it in GitHub Desktop.
public class Hoop {
public static void main(String[] args) {
Hoop hoop = new Hoop();
int n = 3, m = 8;
int[] turns = new int[] {1, 2, 3, 4, 4, 0, 0, 0};
int[] result = hoop.hoop(n, m, turns);
int i = 0;
for (int item:result) {
if (i>0) System.out.print(", ");
System.out.print(item);
i++;
}
}
int[] hoop(int n, int m, int[] turns) {
int[] result = new int[m];
int counter = 0, currentPlayer, correctAnswer;
for (int i=0; i<m; i++) {
currentPlayer = (i % n)+1;
correctAnswer = i+1;
if (correctAnswer % 3 == 0 || correctAnswer % 7 == 0) {
correctAnswer = 0;
}
if (turns[i] != correctAnswer) {
result[counter] = currentPlayer;
counter++;
}
}
int[] theResult = new int[counter];
for (int i=0; i<theResult.length; i++) {
theResult[i] = result[i];
}
return theResult;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment