Skip to content

Bugfixes#1

Open
carwash wants to merge 27 commits intommalita:masterfrom
carwash:bugfixes
Open

Bugfixes#1
carwash wants to merge 27 commits intommalita:masterfrom
carwash:bugfixes

Conversation

@carwash
Copy link
Copy Markdown

@carwash carwash commented Oct 18, 2020

This PR addresses syntax errors and missing puzzle constraints that cause the programs to fail in various ways.

Changes in summary:

  • Added additional problems present at https://ypologist.com/mmalita17/HOMEPAGE/logic/ but missing from the repo:
    • knight.pro
    • phone.pro
    • queen2.pro
    • river.pro
    • seating.pro
    • secretNumber.pro
    • soccer.pro
  • Silenced warnings of singleton variables by declaring them with _;
  • Replaced all instances of not/1 (deprecated) with \+/1 or \=/2;
  • Replaced all instances of assert/1 (deprecated) with assertz/1;
  • Replaced all instances of name/2 (deprecated) with atom_codes/2;
  • Replaced all instances of sumlist/2 (deprecated) with sum_list/2;
  • aa6.pro: Removed dangling close-bracket (syntax error);
  • anagram.pro: Appended false/0 to ensure all solutions are found;
  • buffalo.pro:
    • Added write_list/1 (called but not defined);
    • Added missing clauses for the puzzle's fourth restriction;
  • costume.pro:
    • Added before/3 (called but not defined);
    • Removed duplicate instance of 'sue' in girl/1 and added 'tess' per the puzzle description;
    • Normalised singleton variables for girls and boys;
  • flashlight2.pro: Applied msort/2 to normalise order for list comparisons so that flashlight2.pro and flashlight.pro both find the same two solutions;
  • gradepuzzle.pro: Renamed predicate best/2 (not defined) to first/2;
  • jazz.pro: Added missing clauses for the puzzle's final restriction;
  • jobs1.pro:
    • Singleton variable Son_F corrected to Son_S;
    • Spelling of 'tailor'/'taylor' normalised to 'tailor';
    • Asserted is_set/1 for both fathers and sons as an unstated premise of the puzzle;
    • Nonetheless, the puzzle is still ambiguous, and four alternative solutions are produced.
  • knight.pro: Initialised Path to the empty list rather than the start node to avoid unnecessary duplication;
  • queen2.pro: Added missing predicate colon (syntax error);
  • secretNumber.pro: Removed write/1 since the toplevel prints the solution anyway;
  • sudoku.pro:
    • Removed superfluous instances of write_square/1;
    • Applied constraints consistently over all rows;
  • sudokuSolver.pro:
    • Removed superfluous instances of write_square/1;
    • Corrected different/2 to work as described and properly account for ungrounded variables;
    • Applied good/2 and different/2 constraints consistently for all rows;
    • This is still an extremely slow sudoku solver which essentially brute-forces the puzzle. Difficult to recommend even for pedagogical purposes.
  • writer.pro: Added constraints present in the puzzle description but missing from the code; nonetheless, the puzzle is still ambiguous, and multiple alternative solutions are produced.
  • zebra.pro: Corrected the the green house to be to the right of the white house, not merely near it (produced multiple solutions);

I've been using these puzzles to help me teach myself Prolog – thank you so much for sharing them online! They've been extremely useful. I didn't initially intend to fix – or even find! – any bugs, just to read and learn from the code. But over time, working out why the code sometimes didn't work and how to fix it became even more instructive. This PR is submitted in a constructive spirit of appreciation, not as criticism.
This PR includes only bugfixes, but otherwise leaves the files as they are. I have other branches at https://github.com/carwash/PrologPuzzles which incorporate changes in code formatting/style and consistency, as well as adding your logic puzzle solving library bibmm.pro. These are not included with this PR, as formatting is a matter of taste. But if you'd also like to incorporate those changes in a separate PR, let me know.
Thanks again for providing this useful resource!
/Marcus

carwash added 27 commits April 13, 2020 12:59
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Definition taken from `aa1.pro`.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
… not implemented, in `buffalo.pro`

Definition for write_list\1 taken from `bibmm.pro`

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
…irst/2 was intended.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
…t is deprecated in favour of \+.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
… leading to multiple reported solutions where there should only be one.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
- Singleton variable Son_F should be Son_S
- Inconsistent spelling of 'tailor' (as 'taylor') causes errors
- Both puzzle and solution have an unstated premise, namely that no fathers have the same profession, and no sons have the same profession (i.e. each profession occurs exactly once within those groups). This causes a significant number of incorrect solutions. Fixed by asserting is_set/1 for each group.
- Nonetheless, the puzzle is still ambiguous, and four alternative solutions are produced.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
…olutions to repeat the starting position unnecessarily..

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
…oes this for us anyway.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Nonetheless, multiple valid solutions are produced. Suspect the puzzle may be incomplete.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
… house is to the right of the white house, not merely near it.

This gave two alternative solutions, where there should only be one.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
…nd has singletom variables G & W for girls, which should be the same.

Also changed variable names för boys' costumes for consistency.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
…s are output.

Since there is no argument to start/0, the toplevel didn't backtrack to try other permutations, outputting only one.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
…u.pro`

These caused partial solutions to be printed with non-ground values.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
- write_square/1 not called until the end, so incomplete solutions with ungrounded variables are no longer output;
- different/2 corrected to work as described and properly account for ungrounded variables;
- good/2 and different/2 constraints applied consistently for all rows;

NB. This is still an extremely slow sudoku solver which essentially brute-forces the puzzle.
Difficult to recommend even for pedagogical purposes.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
List order was not normalised, leading to unintentional inequality in comparision.

Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Signed-off-by: Marcus Smith <marcus@runinskrifter.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant