in reply to Re: My first cpan module - App::ForKids::LogicalPuzzleGenerator
in thread My first cpan module - App::ForKids::LogicalPuzzleGenerator

> It's very slow

Most probably because of AI::Prolog

I have the impression - I might be wrong - that these clauses can be represented as entries in a 3x3x3 matrix = (name x profession x fruit) in the example given.

Entries would be undef, 0 and 1 and each 3x3 sub-square must have exactly one 1 entry and all others 0 for a solution.

A solver could be built by filling that matrix and constantly checking all 9 sub layers for deduced entries. (see example here)

Giving a set of random clauses it should be possible to pick n til the solver proves it's solvable (rejecting contradictory clauses)

This reminds me of a graphic technique we learned at uni for finding boolean rules and logical circuits from a given truth table, but I can't remember the name.

(Update: this looks right http://en.wikipedia.org/wiki/Karnaugh_map )

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery

  • Comment on Re^2: My first cpan module - App::ForKids::LogicalPuzzleGenerator

Replies are listed 'Best First'.
Re^3: My first cpan module - App::ForKids::LogicalPuzzleGenerator
by pawel.biernacki (Acolyte) on Feb 23, 2018 at 22:20 UTC

    You are probably right about the matrix. I have a website which contains the puzzles and there are some diagrams generated to fill them:

    http://www.pawelbiernacki.net/4kids/logicalpuzzle/4x4/puzzle_4x4_en_US_0.jsp.

    I think the diagram reflects the matrix you have mentioned.

    The version on my website is available in different languages but I was not sure how to apply gettext on a Perl project by ExtUtils::MakeMaker, so I simply removed the translations.

    Pawel Biernacki
      Actually I'm not sure how complicated your clauses can become, I'm a bit too busy to dive in now.

      But the example given in the OP should be solvable by filling 3 zeros for each clause and applying simple deduction rules on the 3x3 cuts.

      I think the strength of prolog comes to play if you apply more complicated rules.

      Please don't take this as a critic of your work, just theoretical observations. :)

      update

      Applying the rules given on a 3x3x3 matrix displayed by 3 cuts by name:

      • like The one who likes apples is not a blacksmith => 3 zeroes at (apple&blacksmith) x names.
      • and so on:
      FRUITS PROFESSIONS NAMES W B F pineapples apples 0 0 John pears 0 0 0 pineapples 0 apples 0 0 0 Patrick pears 0 pineapples 0 0 0 apples 0 0 0 James pears 0

      Deductions:

      • The apple cut has only one free field
      • => John is a witcher who likes apples
      • All free fields in the witcher and John cut must be filled with zeroes.
      FRUITS PROFESSIONS NAMES W B F pineapples 0 0 0 apples 1 0 0 John pears 0 0 0 pineapples 0 apples 0 0 0 Patrick pears 0 pineapples 0 0 0 apples 0 0 0 James pears 0 0

      Deductions:

      • The James cut has only one field free
      • => James is a blacksmith who likes pears.
      • the remaining fields in blacksmith and pears cut are filled with zeroes.
      FRUITS PROFESSIONS NAMES W B F pineapples 0 0 0 apples 1 0 0 John pears 0 0 0 pineapples 0 0 apples 0 0 0 Patrick pears 0 0 0 pineapples 0 0 0 apples 0 0 0 James pears 0 1 0
      • Only one field free
      • => Patrick is a fisherman who like pineapples.

      I did it manually, hope everything is right and I made the technique of a solver clearer.

      I think you need more complicated rules to challenge people and take advantage of the power of prolog. :)

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Wikisyntax for the Monastery

        Putting things into perspective! ;)

        FRUITS PROFESSIONS NAMES W B F pineapples . . . apples . 0 0 John pears 0 0 0 pineapples 0 . . apples 0 0 0 Patrick pears 0 . . pineapples 0 0 0 apples 0 0 0 James pears . . 0

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Wikisyntax for the Monastery