Skip to content

Conversation

@arsalan0c
Copy link
Member

@arsalan0c arsalan0c commented Apr 14, 2020

This PR adds solutions to the following exercises from SICP JS using Source 3 Non-Det, as part of our reach goals.

Exercise 4.31: Faster solution to multiple dwelling puzzle

Exercise 4.33: Liars puzzle

Exercise 4.35: eight-queens
Two solutions have been added. Each of them makes use of the generate-and-test paradigm.

The first (queens_slow) uses non-determinism for generating both the row and column for each position. It does so in an optimized manner, testing the corresponding condition as soon as the choice is generated, thereby reducing the search space. However, this is not enough to yield a quick solution when N = 8. This solution also gives repeated solutions (i.e different permutations that have all the same positions) upon backtracking.

The second (queens_fast) uses non-determinism in picking only the row and not the column of each position, with the columns being fixed. This further reduces the search space, yielding a quick solution when N = 8.

Example Usage:

const result = queens_fast(8, 8); pretty_print(result, 8); 

image

Depends on #34

Copy link
Member

@martin-henz martin-henz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic!

I'd like to make a small additional request: Can we include these examples in our source-programs test suite?

This will allow us to do system-level regression testing for the non-det variant.

In the case of the two examples, the test files can be empty, and just contain the expected result in a comment. Or you can use the testing library.

For this to work, the test setup needs to be able to set the chapter and variant when it calls js-slang, see #15

@martin-henz martin-henz changed the title Add non-det SICP JS solutions [WIP] Add non-det SICP JS solutions Apr 15, 2020
@arsalan0c arsalan0c marked this pull request as ready for review May 2, 2020 07:22
@arsalan0c arsalan0c requested a review from martin-henz May 2, 2020 07:22
@arsalan0c arsalan0c changed the title [WIP] Add non-det SICP JS solutions Add non-det SICP JS solutions May 2, 2020
Copy link
Member

@martin-henz martin-henz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat examples!

@martin-henz martin-henz merged commit 708ff96 into source-academy:master May 12, 2020
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.

3 participants