The goal of the task is to write a program describing the behavior of a particle in some imaginary quantum world.
A particle is designated by a string made from any combination of the numbers {0,1,2,3}.
Just like particles a quantum history is also designated by a string of numbers {0,1,2,3}, however a quantum history
includes all particles that are its prefix (ex. the history 0123
includes particles 0
, 01
, 012
and 0123
)
Each declared particle can have energy value assigned to it The energies of two declared particles can be equated, which means that a change in energy for one of these particles also causes a change in the energy of the other.
The energy equation relationship attributed to histories is equivalence.
After starting the program, no quantum histories are declared, so no particle is assigned energy and no two particles are equated.
Then, the program accepts the following commands:
-
DECLARE history
- declares every particle that is a prefix ofhistory
. -
REMOVE history
- removes every particle that starts withhistory
. -
VALID particle
- Checks ifparticle
given is declared. -
ENERGY particle energy
- Ifparticle
is declared has no energy assigned to it, assignsenergy
to it (overwrites existing energy). -
ENERGY particle
- Ifparticle
is declared and has energy assigned, prints that energy. -
EQUAL particle_a particle_b
- Ifparticle_a
andparticle_b
were declared, then:- (a) if at least one of the particles has energy assigned, balances their energies and closes the equivalence relationship.
- (b) if both particles have energy assigned to them, then assigns the arithmetic average of these energies to both of them (with rounding down if necessary).
- (c) if both particles are identical or already have equal energies, doesn't change anything.
After a correct execution of a command, the program writes:
OK
for every recognized command exceptVALID
and a single parameter version ofENERGY
.YES
orNO
depending on the result of the commandVALID
.integer
that is the energy value for the single parameter commandENERGY
.ERROR
tostderr
for each incorrect line of command.
Example tests for the program can be found in the folder tests
.
compile and run executable particles
:
make run
run with valgrind:
make valgrind
check against the tests located in the folder tests
:
make test
Tests can be found here