Prolog – Sorting Hat Challenge

hogwarts-sorting-hatProlog is a language built around the Logical Paradigm: a declarative approach to problem-solving.

There are only three basic constructs in Prolog: facts, rules, and queries.

A collection of facts and rules is called a knowledge base (or a database) and Prolog programming is all about writing knowledge bases. That is, Prolog programs simply are knowledge bases, collections of facts and rules which describe some collection of relationships that we find interesting.

So how do we use a Prolog program? By posing queries. That is, by asking questions about the information stored in the knowledge base. The computer will automatically find the answer (either True or False) to our queries.


Knowledge Base (Facts & Rules)

Check the following knowledge base used by the Sorting Hat in the Harry Potter story:

Note that \+ means NOT


We can know query this database. For each of the queries listed below, what do you think the computer will return (True or False?)

Try It Online

Test these queries online:

Share Button
Posted in Computer Science, Computing Concepts Tagged with:

Our Latest Book