Monkey Business

A challenge by Decision Management Community.

A zoo has four monkeys, during the monkey lunchtime each one ate a different fruit in their favourite resting place. Sam, who doesn’t like bananas, likes sitting on the grass. The monkey who sat on the rock ate the apple. The monkey who ate the pear didn’t sit on the tree branch. Anna sat by the stream but she didn’t eat the pear. Harriet didn’t sit on the tree branch. Mike doesn’t like oranges.

  1. What kind of fruit each monkey ate?
  2. Where their favourite resting place was?

So, how to solve this in SQL? It is easy to identify domains, predicates and rules; after that it is straightforward. Continue reading “Monkey Business”

Murder Mystery

Another fun puzzle, based on the problem No. 55 in [PFJ86] and published as a challenge by Decision Management Community.

Someone in Dreadsbury Mansion killed aunt Agatha. Agatha, the butler, and Charles live in Dreadsbury Mansion, and are the only ones to live there. A killer always hates, and is no richer than his victim. Charles hates no one that Agatha hates. Agatha hates everybody except the butler. The butler hates everyone not richer than aunt Agatha. The butler hates everyone whom Agatha hates. No one hates everyone. Who killed Agatha?

The idea — as in previous posts — is to use concept of predicates, constraints, relations, and Continue reading “Murder Mystery”

Reindeer Ordering

The Decision Management Community posted a fun challenge: Santa’s elves are supposed to order nine reindeer according to a set of rules. The rules are:

  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.

The challenge is to create a decision model, but Continue reading “Reindeer Ordering”

Eight Queens in SQL [4]

This is the fourth and final part of the series showing how to solve the “Eight Queens” chess puzzle, using a database design and SQL. The main idea is to design using natural language and concepts of domains, predicates, constraints, sets, set operations, and relations.

Links to all previous and this post’s code.
Part Main Topic Code (pgSQL)
1 Domains, Types part 1
2 Predicates, Constraints, Relations part 2
3 Propositions and Facts part 3
4 The Algorithm and the Solution part 4

Algorithm

Say we place a queen, Q1, on square c5, Continue reading “Eight Queens in SQL [4]”