Re: Hints on recursion



OK, so I may be breaking netiquette, posting when I've not been here a
day, but I had to throw this out.

I'm a newbie, my Lisp sucks. But I did come up with what i think might
be a valid solution, although I did use cons:

1. return true when the element appears in the first two places in the
list
2. return false if the list has fewer than 2 elements
3. delete any non-matching elements from the list and recurse

My version looks like this, but someone who actually knows what they're
doing could do it better, I'm sure:

(defun find-twice (a lst)
(cond ((and (eq a (first lst)) (eq a (first (rest lst)))) lst)
((or (eq (first lst) nil) (eq (rest lst) nil)) nil)
((not (eq (first lst) a)) (find-twice a (rest lst)))
(t (find-twice a ((first lst) . (cdr (rest lst)))))))

- mpeever

.



Relevant Pages

  • Re: Caught Pussy Katz LYING again...but it was really easy
    ... Your first post was mid 2007. ... I changed my posting nick, ... NEWBIE PUSSY KATZ! ... Provide a Message ID like I did above, LIAR! ...
    (rec.food.cooking)
  • Re: This Ng and What I dont get! RANT!
    ... I'm a newbie as far as posting here and have never ... When I first started posting here I thought a love of food ... I had lost my recipe which used lime jello ... Consider this an attack if you want. ...
    (rec.food.cooking)
  • Re: Weber Silver A -- a top-posting dilemma
    ... >> seen in many OTHER newbie posters. ... >> sophistication is NOT a justification for poor communication. ... >> posting is done. ... >> the whooooole previous posts are left in a response. ...
    (alt.food.barbecue)
  • Re: I Like This Group!
    ... ugly quoting style to that of a newbie. ... Yet he/she/it posts anonymously through google groups and isn't even ... "Leroy" your "anonymous" posting name? ... If you are indeed a newbie, ...
    (rec.outdoors.rv-travel)
  • Re: Ho hum,
    ... is for certain persons to stop trying to justify themselves in the face of overwhelming evidence, and by that, I don't just mean in terms of this particular spate, but their continued pretence to claim to be a newbie around here when everyone knows they are in fact our favourite little woodworking friend. ... fathom out the mind of the bitter, ... because in spite of your "open" mind you don't like new people posting, ... Afterall another posters ...
    (uk.local.kent)