Loop 2D-Array

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

Loop 2D-Array

Postby Sylfighter » Tue Feb 07, 2017 4:02 am

Hey,
i need a function that gives me the first position of a T in the *world*- array.
The *world*-array looks like that.

#2A((W G G G G R W T G G W G G G)
(W G G T G G W G G G W G G G)
(W W W G W W W W T W W W W G)
(G G G G G T G G G G G G G G)
(W W W G W W W W W W T W W W)
(G T W G W G G G W G G G W W)
(G G W G W G G G W G G G W W)
(G G G G G G G G W T T G W W)
(G G W G W G G G W W W W W W)
(W W W G W W W W W W W W W W)
(G T W G W G G G W W W W W W)
(G G G G W G G G W W W W W W)
(G G W G G G T G W W W W W W))

My function looks like this. My function always return NIL and i don't no why it should return (0 7).

(defun get-treasure-coordinate ()
(loop for x from 0 to 12 do
(loop for y from 0 to 13 when(eql 'T (aref *world* x y))
collect (list x y)
)
)
)
Sylfighter
 
Posts: 1
Joined: Tue Feb 07, 2017 3:53 am

Re: Loop 2D-Array

Postby peterlane » Wed Feb 08, 2017 2:08 am

You are close. How does 'loop' return a value?

Consider:
> (loop for x from 1 to 3 do x)
NIL
> (loop for x from 1 to 3 collect x)
(list 1 2 3)

Then look again at your two loops ... if you change one word you will get some results back, which will still need some tidying up.
peterlane
 
Posts: 7
Joined: Wed Jan 18, 2017 5:34 am


Return to Homework

Who is online

Users browsing this forum: No registered users and 1 guest

cron