I am new to Common Lisp and functional programming, but I have a lot of experience in languages ββlike C, C ++, C #, Java, etc. I am having trouble finding the most nested list inside the list. My input looks something like this:
(0 1 (2 3) 4 (5 (6 (7) 8)) 9)
I would like to get the most nested list inside this list, which in this case
(7)
I had the idea that I can somehow smooth the list until there is only one additional list left. To illustrate what I mean, follow these steps:
Step 1. - input:
(0 1 (2 3) 4 (5 (6 (7) 8)) 9)
Step 2. - smooth on the "first level":
(0 1 2 3 4 5 (6 (7) 8) 9)
Step 3. - smooth on the "second level":
(0 1 2 3 4 5 6 (7) 8 9)
Now only one nested list is left, which means that this is the most nested list. But I see a problem here when two or more such lists appear. Share your thoughts on this.
I'm having trouble implementing this procedure in Common Lisp, so I would be grateful for some pointers in the right direction, maybe in some sample code, and so on. This is homework, so I do not expect a complete solution, but I would be glad if someone pointed out, perhaps, an easier and better solution and its implementation.
lisp common-lisp nested-lists
brozo
source share