Problem Statement
NOTE: This problem statement contains images that may not display properly if viewed outside of the applet.
Taro and Hanako are playing Bunny Puzzle. There are several bunnies standing on a line. You are given a int[] bunnies, where each element is the initial position of a single bunny.
They must perform the following routine exactly once:
The jump is not allowed if another bunny is already at point 2*b-a.
The jump is also not allowed if A jumps over more than one bunny.
Return the number of different ways in which Taro and Hanako can choose the pair of bunnies A and B. "A jumps over B" and "B jumps over A" are considered to be different.
Taro and Hanako are playing Bunny Puzzle. There are several bunnies standing on a line. You are given a int[] bunnies, where each element is the initial position of a single bunny.
They must perform the following routine exactly once:
- Choose two different bunnies A and B, located at points a and b, respectively.
- A jumps over B and lands at point 2*b-a.
The jump is not allowed if another bunny is already at point 2*b-a.
The jump is also not allowed if A jumps over more than one bunny.
Return the number of different ways in which Taro and Hanako can choose the pair of bunnies A and B. "A jumps over B" and "B jumps over A" are considered to be different.
Definition
- Class:
- BunnyPuzzle
- Method:
- theCount
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int theCount(int[] bunnies)
- (be sure your method is public)
Constraints
- bunnies will contain between 2 and 50 elements, inclusive.
- Each element of bunnies will be between -10^6 and 10^6, inclusive.
- bunnies will be sorted in strictly ascending order.
Examples
{5, 8}Returns: 2
There are two possible moves: A bunny jumps from 5 to 11 A bunny jumps from 8 to 2{-1, 0, 1}Returns: 2
There are two possible moves: A bunny jumps from 0 to -2 A bunny jumps from 0 to 2{0, 1, 3}Returns: 3
There are three possible moves: A bunny jumps from 0 to 2 A bunny jumps from 1 to -1 A bunny jumps from 1 to 5{-677, -45, -2, 3, 8, 29, 384, 867}Returns: 7
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}Returns: 2