Write a Python program that accepts stacks of balls

  • Job DurationLess than a week
  • Project LevelBasic Level
  • Project deadlineExpired

Project detail

Write a Python program that accepts stacks of balls as input, conducts a Uniform-Cost Graph Search, and displays a solution as shown in the following example.
The program should output “No solution” when a given puzzle cannot be solved.

Ball Sort Puzzle: We have 16 balls. Each ball is labeled by either A, B, C, or D. We also have 6 stacks. Each stack can contain 4 balls. The 16 balls are randomly placed in 4 stacks. Two stacks are left empty. The goal of this puzzle is to sort the balls by label, so that 4 non-empty stacks contain 4 balls of the same label. There are two restrictions:
1. Only the top ball of each stack can be moved, and
2. A ball can only be placed on top of another ball of the same label or in an empty stack.
The following figure shows an example of the ball sort puzzle with an initial state and a possible goal state. Note that given an initial state, there may be multiple goal states.

Here are additional information

1) Your program must accept four lines of input using Python input() function. The first line is the top of the four stacks, the second line is the second element of the four stacks, etc. For example, the following input shows an initial state that is also a goal state.

A B C D
A B C D
A B C D
A B C D

2) Your program does not need to validate the input values. You can assume that the input values contain 4 As, 4 Bs, 4 Cs, and 4 Ds arranged in random order placed is the first four stacks.

Skills Required

Industry Categories

Freelancer type required for this project