partial paths
partial paths
CAN ANY ONE HELP
Write the function partialpaths, of two arguments. The
first argument is a list of lists, representing a graph(adjacency list
representation of a graph). The second argument is a partial path in the
reverse order, for example the path "from a to b to c" is represented by
the list (c b a). The function should return a list of sublists containing
all possible expansions of this partial path by one node.
For example:
(partialpaths '( (a b c) (b c d) (c d a) (d)) '(b a))
should return:
( (c b a) (d b a))
Write the function partialpaths, of two arguments. The
first argument is a list of lists, representing a graph(adjacency list
representation of a graph). The second argument is a partial path in the
reverse order, for example the path "from a to b to c" is represented by
the list (c b a). The function should return a list of sublists containing
all possible expansions of this partial path by one node.
For example:
(partialpaths '( (a b c) (b c d) (c d a) (d)) '(b a))
should return:
( (c b a) (d b a))
-
- Posts: 47
- Joined: Fri Jun 03, 2011 5:30 am
- Location: Behind you.
- Contact:
Re: partial paths
I'm tired now, lol. May I also suggest the #lisp IRC channel? It is very useful for real-time responses\help.
Don't take the FUN out of DEFUN !
Re: partial paths
k thank u very much for u r help my friend
-
- Posts: 59
- Joined: Sun May 29, 2011 8:52 pm
- Location: NY
- Contact:
Re: partial paths
I'm not exactly sure what this code is supposed to be doing, could you elaborate on it a bit more?
Re: partial paths
i got some code like this
(define (partialpaths X Y)
(cond
((null? X) Y)
((member1 (car(car X)) Y) (partialpaths (cdr X) Y))
(#t (cons (car(car X)) Y))
)
)
(define (member1 X Y)
(cond
((null? X) #f)
((eq? Z (car X)) #t)
(#t (member1 Z (cdr X)))
)
)
but i am not sure this code by using lisp.
(define (partialpaths X Y)
(cond
((null? X) Y)
((member1 (car(car X)) Y) (partialpaths (cdr X) Y))
(#t (cons (car(car X)) Y))
)
)
(define (member1 X Y)
(cond
((null? X) #f)
((eq? Z (car X)) #t)
(#t (member1 Z (cdr X)))
)
)
but i am not sure this code by using lisp.
-
- Posts: 59
- Joined: Sun May 29, 2011 8:52 pm
- Location: NY
- Contact:
Re: partial paths
You want that code converted into Common Lisp code? To me it looks like it is currently in Racket, or a language much like that. Might I suggest a bit of formatting when you write lisp code. Do not have parenthesis alone on a line.
Don't do this:
Do this:
Makes it easier on the eyes.
Don't do this:
Code: Select all
(defun hello ()
(print "hello")
)
Do this:
Code: Select all
(defun hello ()
(print "hello"))
Last edited by I X Code X 1 on Sat Jul 02, 2011 9:16 pm, edited 1 time in total.
-
- Posts: 47
- Joined: Fri Jun 03, 2011 5:30 am
- Location: Behind you.
- Contact:
Re: partial paths
define would be defun, the parameters are in their own brackets after the name, then the body, then the final end-function brackets.
null? would be null, #t => t, eq? => eq or eql or equal, and I think #f means false(?) which would be nil in CL.
null? would be null, #t => t, eq? => eq or eql or equal, and I think #f means false(?) which would be nil in CL.
Don't take the FUN out of DEFUN !