Here is a Python version (http://pastebin.com/reW5eaCy):

def valid(a,b,c,d):
    return set(w*a + x*b + y*c + z*d
               for w in [-1,0,1]
               for x in [-1,0,1]
               for y in [-1,0,1]
               for z in [-1,0,1]) > set(range(1,41))

ws = [(a,b,c,d) for a in range(1,41-1-1-1)
                for b in range(a,41-a-1-1)
                for c in range(b,41-a-b-1)
                for d in range(c,41-a-b-c)
                if valid(a,b,c,d)]

I wonder if you can make the cKanren version just as declarative as
this one (cKanren's purpose being declarative).

Jules

On 1 nov, 04:48, David Nolen <dnolen.li...@gmail.com> wrote:
> A blog post explaining the solution step by 
> stephttp://dosync.posterous.com/another-taste-of-ckanren.
>
>
>
>
>
>
>
> On Mon, Oct 31, 2011 at 9:36 PM, David Nolen <dnolen.li...@gmail.com> wrote:
> > Here's a correct version that solves the puzzle in ~12ms,
> >https://gist.github.com/1329580. A bit longer but it fun to combine
> > constraints w/ search.
>
> > Will try to find some time to write a more detailed explanation.
>
> > On Sun, Oct 30, 2011 at 9:00 PM, David Nolen <dnolen.li...@gmail.com>wrote:
>
> >> Heh, as someone pointed out this doesn't actually solve the puzzle since
> >> I'm not considering putting stones on either side of the scale. Still I
> >> think the idea of what cKanren can do is communicated :)
>
> >> On Sun, Oct 30, 2011 at 8:34 PM, Brent Millare 
> >> <brent.mill...@gmail.com>wrote:
>
> >>> Looks really cool. Can't wait to see the talk.
>
> >>> --
> >>> You received this message because you are subscribed to the Google
> >>> Groups "Clojure" group.
> >>> To post to this group, send email to clojure@googlegroups.com
> >>> Note that posts from new members are moderated - please be patient with
> >>> your first post.
> >>> To unsubscribe from this group, send email to
> >>> clojure+unsubscr...@googlegroups.com
> >>> 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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to