Your intuition that this can be done through recursion or a loop is correct
(the latter being a more specialised version of the former).

When dealing with recursion, it often helps to consider the base case, i.e.
where the recursion stops. Typically this is when you get to zero or one
elements.

You may wish to consider the following questions:

1. How do you find the last element of a seq with exactly one element?
2. How do you find out whether a seq has one element, or more than one
element?
3. How do you find out the last element if a seq with exactly two elements?
4. How do you find out the last element of a seq that may have one *or* two
elements?

- James



On 30 April 2014 07:08, Roelof Wobben <rwob...@hotmail.com> wrote:

> Hello,
>
> IM busy with 4Clojure and I have now two challenges which I think can be
> solved the same way.
>
> On a list I first have to find the last item of a list without using last
> and after that I have to do the same for a nth item and im not allowed to
> use nth.
>
> Now I can convert the list to a vector and use the vector things but I
> think this is cheating at some way.
>
> Could a recurvice way or a loop do the trick. And how do I then take the
> right value.
> Should I use first then or is there a better way. I also read about doseq
> but then I have to find out how to print only the item I want.
>
> Anyone who can give a hint without spoiling the answer.
>
> Roelof
>
>  --
> 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 unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to