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.
- What kind of fruit each monkey ate?
- 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”
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”
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:
- Comet behind Rudolph, Prancer, and Cupid.
- Blitzen behind Cupid.
- Blitzen in front of Donder, Vixen, and Dancer.
- Cupid in front of Comet, Blitzen, and Vixen.
- Donder behind Vixen, Dasher, and Prancer.
- Rudolph behind Prancer.
- Rudolph in front of Donder, Dancer, and Dasher.
- Vixen in front of Dancer and Comet.
- Dancer behind Donder, Rudolph, and Blitzen.
- Prancer in front of Cupid, Donder, and Blitzen.
- Dasher behind Prancer.
- Dasher in front of Vixen, Dancer, and Blitzen.
- Donder behind Comet and Cupid.
- Cupid in front of Rudolph and Dancer.
- Vixen behind Rudolph, Prancer, and Dasher.
The challenge is to create a decision model, but Continue reading “Reindeer Ordering”
In the previous post I demonstrated how small typos in SQL become large logical errors, and how a “proper” type system could help in preventing these. This time I explore how PostgreSQL’s enum data type can be leveraged to gain some data safety and prevent logical errors.
In PostgreSQL the enum data type offers some type safety, for example:
CREATE TYPE d1 AS ENUM
('1', '2', '3');
CREATE TYPE d2 AS ENUM
('1', '2', '3');
Enumerated values are labels, hence the quotation marks. Continue reading “Types and Typos in SQL ”