12
0
In Chinese Checkers, a piece can move by hopping over any other piece, or by making a sequence of such hops. Your task is to find the longest possible sequence of hops.
Input
A sequence of 121 zeroes or ones, each representing a place on a board. A zero means the place is empty; a one means the place is occupied. Positions are listed from left to right; top to bottom. For example, the input of this setup would be
1011110011000001000000000000000000000000100000000001000000000000000000000000000001000000000000000000000001000001100111111
Explanation:
The top-most place is occupied by a green piece, so the first digit in the input is
1
. The second row has one empty position and then one occupied position, so01
comes next. The third row is all occupied, so111
. The fourth row has two empty and two occupied spaces (going left to right), so0011
. Then comes five0
's, a1
, and seven0
's for the next row, and so on.
Like in that setup, there is a corner pointing straight up. There may be any number of pieces on the board (from 1 to 121). Note that pieces of different colors are not represented differently.
Output
The maximum length of a legal hop, using any piece on the board. You may not visit the same place more than once (including the starting and ending positions). However, you may hop over the same piece more than once. If there is no legal hop, output 0
. Do not consider whether there exists a legal non-hop move.
For example, the output to the setup described above is 3
.
Input and output may be done through stdin and stdout, through command-line arguments, through function calls, or any similar method.
Test Cases
Input:
0100000010000000000000000100000000000000000000000000000001010010000000000000000000000101000000000000000000100000000100001
Output: 0
(no two pieces are next to each other)
Input:
0000000000111100000000011100000000011000000000100000000000000000000000000000000000000000000000000000000000000000000000000
Output: 1
(initial setup for one player in top-left corner)
@DevonParsons actually, it is impossible to hop over the same piece twice. The hopping man can only move 2 spaces at a time, which restricts him to a quarter of the cells on the board. This in turn means he can only ever hop over the same piece in one of the three axes of the board. The only choice he has, is that depending on how he approaches it, there may exist paths where he can hop over it forwards and others where he can hop over it backwards. – Level River St – 2015-06-23T09:30:28.240
I play this with my great aunt; we're both reasonably good. This is an interesting challenge. – cjfaure – 2014-05-02T21:47:32.780
1Maybe you should specify more on how the input is stored/which bits go to where. – TheDoctor – 2014-05-02T22:00:53.223
Which pieces can you "hop over"? The way my mom and I used to play, you can hop over any single piece in one of the 6 directions any distance away (to the opposite spot of the piece you hopped over) as long as there is no piece in the way of the path for that hop. Others play that you can only hop over adjacent pieces. – Joe Z. – 2014-05-03T19:21:09.063
1@TheDoctor I added a more detailed explanation. – Ypnypn – 2014-05-04T01:29:29.123
Can you clarify a detail: am I allowed to occupy the same position twice? I assume I can't loop infinitely, but if I can hit a location moving left-right and then later hit it again moving up-left to down-right then it opens up possibilities. – Devon Parsons – 2014-05-07T16:58:53.707
Similarly, can you hop over the same piece twice? Not necessarily from the same starting point; if I am up-left from a piece and hop it, and later I am right of the piece, can I hop it again? – Devon Parsons – 2014-05-07T16:59:44.190
@DevonParsons "You may not visit the same place more than once." However, you may hop over the same piece more than once. – Ypnypn – 2014-05-07T17:01:56.820