12

Powergrid Kruskals Algorithm

A C++ algorithm that solves a puzzle consisting of 3 jugs with set capacities of water in the least amount of moves.

Usage

./powergrid []

Explanation

The initial state of water has bucket A and B as empty, and bucket C is filled to capacity. The algorithm will find the combination of pours to reach the goal capacities in each bucket.

Example

./powergrid test.txt

Test.txt file:
6
1,2,3,A
1,5,6,B
1,6,5,C
2,3,1,D
2,6,4,E
3,4,6,F
3,6,4,G
4,5,8,H
4,6,5,I
5,6,2,J
Capacities: Jug A can hold 1 gallon. Jug B can hold 3 gallons. Jug C can hold 4 gallons.
Goal: Jug A: 0 gallons, Jug B: 2 gallons, Jug C: 2 galllons

Steps to achieve the goal:

  • Pour from Jug C to Jug B

Jug A: 0 gallons, Jug B: 3 gallons, Jug C: 1 galllons

  • Pour from Jug B to Jug A

Jug A: 1 gallons, Jug B: 2 gallons, Jug C: 1 galllons

  • Pour from jug A to Jug C

Jug A: 0 gallons, Jug B: 2 gallons, Jug C: 2 galllons

Languages

C++