Santa always leaves plans for his elves to determine the order in which the reindeer will pull his sleigh. This year, for the European leg of his journey, his elves are working to the following schedule, which will form a single line of nine reindeer

The Rules

  1. Comet behind Rudolph, Prancer and Cupid.
  2. Blitzen behind Cupid
  3. Blitzen in front of Donder, Vixen and Dancer.
  4. Cupid in front of Comet, Blitzen and Vixen.
  5. Donder behind Vixen, Dasher and Prancer.
  6. Rudolph behind Prancer
  7. Rudolph in front of Donder, Dancer and Dasher.
  8. Vixen in front of Dancer and Comet.
  9. Dancer behind Donder, Rudolph and Blitzen.
  10. Prancer in front of Cupid, Donder and Blitzen.
  11. Dasher behind Prancer
  12. Dasher in front of Vixen, Dancer and Blitzen.
  13. Donder behind Comet and Cupid.
  14. Cupid in front of Rudolph and Dancer.
  15. Vixen behind Rudolph, Prancer and Dasher.

Create a rule model that determines the order of the reindeer.


The Approach

The 12 statements above are effectively the rules that solve the problem.

The challenge is to find a way to represent them in Corticon such that we can use the power of Corticon’s inferencing to continue working until all the reindeer are in the correct order.

The basic idea is to assign a sequence number to each reindeer (initially one).

Then compare reindeer (two at a time) and use the rules to adjust that sequence number whenever reindeer are found to out of order. Because modifying a reindeer’s sequence number may cause that reindeer to break other rules we’ll need to repeat the process of applying the rules until no more changes are made to the sequence numbers. Then we will have a solution. This means we will need to make the rule sheet iterate. This is done by drawing the rule flow diagram and marking the rule sheet with the iterate symbol:


Rule Sheet

How it Works

By specifying two aliases to the entity Reindeer Corticon will automatically try every possible combination of two reindeer from the set of reindeer that is passed in as the data payload.

The rules then modify the sequence number of one of the reindeer if it is found to break the rules.

This process repeats until no more rules fire (i.e. no reindeer are out of sequence)

Test Case

Note that it’s the value of the attribute called order that determines the sequence. The reindeer are not displayed in the tester in order. But the tester automatically compares the attributes of the reindeer and if there were any differences they would be highlighted in red.

Playing with the Rule Model

If we apply the Corticon compression feature to the rule sheet we’ll see that Corticon is able to express the same logic in fewer rules. 10 rules instead of 15.

Rules 2, 4 and 14 can be merged since they all apply to cupid

Rules 6, 10 and 11 can be merged since the all apply to prancer.

Rules 5 and 13 can be merged since they all apply to donder.