Skip to content

Commit 8662273

Browse files
committed
add header
1 parent 73daa07 commit 8662273

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/examples/liars.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
SICP JS Exercise 4.33
3+
4+
This file contains a solution to the Liar's puzzle
5+
*/
6+
7+
function distinct(items) {
8+
return is_null(items)
9+
? true
10+
: is_null(tail(items))
11+
? true
12+
: is_null(member(head(items), tail(items)))
13+
? distinct(tail(items))
14+
: false;
15+
}
16+
17+
const betty = amb(1, 2, 3, 4, 5);
18+
const ethel = amb(1, 2, 3, 4, 5);
19+
const joan = amb(1, 2, 3, 4, 5);
20+
const kitty = amb(1, 2, 3, 4, 5);
21+
const mary = amb(1, 2, 3, 4, 5);
22+
23+
require(amb(kitty === 2, betty === 3));
24+
require(amb(ethel === 1, joan === 2));
25+
require(amb(joan === 3, ethel === 5));
26+
require(amb(kitty === 2, mary === 4));
27+
require(amb(mary === 4, betty === 1));
28+
29+
require(distinct(list(betty, ethel, joan, kitty, mary)));
30+
31+
list(list('betty', betty), list('ethel', ethel), list('joan', joan),
32+
list('kitty', kitty), list('mary', mary));

0 commit comments

Comments
 (0)