(Using topcoder.com problem statement format. You have an 8 second program execution limit on a 700 MHz Pentium III.)
PROBLEM STATEMENT
In the game of Peg Solitaire, you are given a arrangement of pegs that fit into a line of equally-spaced holes. In order to win the game, you must reduce the number of pegs to one, by using a series of jumps. Each jump occurs according to the following rules:
·A peg may only jump over those immediately adjacent to it on the left or right.
·A jumping peg must jump exactly one other peg, no more, no less.
·Once the jump is completed, the peg that was jumped over is removed.
For example, given the configuration of pegs and holes
...1234.5....
where a period represents an empty hole, and where a digit represents a peg, the only two legal moves are as follows:
...12..35.... [peg 3 jumped over peg 4, which was then removed]
..2..34.5.... [peg 2 jumped over peg 1, which was then removed]
A position is defined as "winnable" if, through a series of jumps, it can be reduced to one peg. For example, the above position is winnable, since it can be reduced to one peg by the following set of jumps:
...1234.5.... [initial]
...12..35.... [peg 3 jumped over peg 4]
.....1.35.... [peg 1 jumped over peg 2]
.....15...... [peg 5 jumped over peg 3]
....5........ [peg 5 jumped over peg 1]
Given a number N of pegs, write a method that returns the number of winnable positions that consist of N pegs.
NOTES
·When considering whether two positions are identical, disregard excess empty holes on the left and right side.
·Note that there is no "edge" of the playing field; there are essentially infinitely many empty holes.
·An input is valid if the following criterion is met: size will be an integer between 2 and 35, inclusive
TEST CASES
Input: 2
Output: 1
There is only one winnable case with 2 pegs; when they are adjacent.
Input: 4
Output: 3
The patterns containing 4 pegs are:
..12.3.4..
..12..34..
..1.2.34..
Input: 8
Output: 23
2007-01-29 19:21:28
·
answer #1
·
answered by Anonymous
·
1⤊
2⤋
Did u Worked With Solitaire Game in Ms Windows and
Spider Solitaire in Win XP.
the Peg Solitaire is also a game like that.
2007-01-30 05:37:59
·
answer #2
·
answered by Ravi Nanjunda Rao 3
·
0⤊
0⤋
Peg Solitaire is a board game for one player involving movement of pegs on a board with holes. The game is known simply as Solitaire in the United Kingdom where the card games are called Patience. It is also referred to as Brainvita (especially in India). Some sets use marbles in a board with indentations.
According to a popular story, the game was invented by a French aristocrat in the 17th century, when incarcerated in the Bastille. John Beasley (author of "The Ins and Outs of Peg Solitaire") has extensively searched for evidence to support this, and has found it lacking. The first reference to this story appeared in 1810, more than a hundred years after the alleged event. He believes that the colorful tale is fiction, yet it persists. In other sources, the invention of the game is attributed to the American Indians--there is also no evidence to support this.
The first evidence of the game can be traced back to the court of Louis XIV, and the specific date of 1697. Several works of art from that time show peg solitaire boards, demonstrating that the game was highly fashionable.
2007-01-30 03:15:16
·
answer #3
·
answered by msu_milk_chocolate 3
·
0⤊
0⤋