LibertyOne Posted April 20, 2011 Posted April 20, 2011 Just another thought building on what I added earlier. If you still wanted to keep the last element in the first list, you could add a 0 to the end of the second list to be added to the first list. => (setq lst (list 1 2 3 4 5 6 7 8 9)) ;returns (1 2 3 4 5 6 7 8 9) (mapcar '+ lst (reverse (cons 0 (reverse (cdr lst))))) ;returns (3 5 7 9 11 13 15 17 9) you could even loop around to the beginning of the list and add the first element to the last => (mapcar '+ lst (reverse (cons (car lst) (reverse (cdr lst))))) ;returns (3 5 7 9 11 13 15 17 10) Quote
Lee Mac Posted April 20, 2011 Posted April 20, 2011 Apologies but this task appears to be made overcomplicated - refer to my post #17. Quote
LibertyOne Posted April 20, 2011 Posted April 20, 2011 Apologies but this task appears to be made overcomplicated - refer to my post #17. true, but like you also said is that the result wasn't really clearly defined in the beginning of the thread. I was solving more on the lines of list manipulation by returning a modified list and not just that of an equation by adding up a list of numbers. What it all boils down to is what you want as a result and how generic can you build a function to suit different needs of many different programs. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.