Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The core relation involved is one that captures the characteristics for an individual house:

    function house(position, country, color, pet, drink, cigar);
You need to define that relation by codifying the following:

a) The exclusivity rule. I.e. the fact that no two houses are the same colour, and no two owners have the same pet, and so on. You'll need to define your own "not equal" relation, the absence of which is a major issue with this library.

b) the positioning. Since this library can do arithmetic, I would just make position an integer, and do something like this:

    function left_of(pos_a, pos_b) {
        eq(logic.sub(pos_b, pos_a), 1)
    }

    function adjacent(pos_a, pos_b) {
        or(left_of(pos_a, pos_b), left_of(pos_b, pos_a))
    }
c) finally, just go in and codify all of the hints. This will probably be quite long and awkward because you'll need lots of lvars, and the conjunction relation is binary only, but it should be easy to do nonetheless.

For example:

> the Norwegian lives next to the blue house

    and(and( 
        house(pos_a, 'Norwegian', col_a, pet_a, drink_a, cigar_a),
        house(pos_b, country_b, 'Blue', pet_b, drink_b, cigar_b)),
        adjacent(pos_a, pos_b)
    )


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: