-
Notifications
You must be signed in to change notification settings - Fork 18
Add non-det SICP JS solutions #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add non-det SICP JS solutions #16
Conversation
31c4419 to
850b67b
Compare
09edcc3 to
726cf39
Compare
There was a problem hiding this 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
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat examples!
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:
Depends on #34