Excellent point Ambrose ;) And here it is:
(define (subchecko w sl r o n)
(conde
((== sl ())
(fresh (a d)
(domfd a (range 1 100))
(conde
((conso a d r) (plusfd a 1 w)
(conso w r o))
((== r '()) (conso w r o)))))
((fresh (a b c ro0 ro1 nw nsl)
(domfd a b c (range 1 100))
(conso a nsl sl)
(plusfd a b w) (plusfd a w c)
(subchecko b nsl r ro0 n)
(subchecko w nsl ro0 ro1 n)
(subchecko c nsl ro1 o n)))))
(define (checko ws sl r n)
(conde
((== ws '())
(fresh (a) (caro r a) (== a n)))
((fresh (w wr nsl nr)
(conso w wr ws)
(subchecko w sl r nr n)
(conso w sl nsl)
(checko wr nsl nr n)))))
(define (matches a b c d n)
(fresh (s1 s2)
(domfd a b c d n s1 s2 (range 1 100))
(all-differentfd `(,a ,b ,c ,d))
(<fd a b) (<fd b c) (<fd c d)
(== a 1)
(plusfd a b s1) (plusfd s1 c s2) (plusfd s2 d n)
(checko `(,a ,b ,c ,d) () () n)))
(run* (q)
(matches 1 3 9 27 q)) ;; (40)
(run* (q)
(fresh (a b c d)
(== q `(,a ,b ,c ,d))
(matches a b c d 40))) ;; ((1 3 9 27))
On Sat, Nov 12, 2011 at 12:31 AM, Ambrose Bonnaire-Sergeant <
[email protected]> wrote:
> I assume the cKanren version can run backwards with a little tweak?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en