### Author Topic: [challenge] A14 : Split a list into two parts  (Read 1470 times)

0 Members and 1 Guest are viewing this topic.

#### Marc'Antonio Alessi

• Swamp Rat
• Posts: 1343
• Marco
##### Re: [challenge] A14 : Split a list into two parts
« Reply #15 on: January 19, 2022, 03:34:20 AM »
Code: [Select]
`(defun Split_ALE (L n / g h r)  (if (> (setq g (length L)) n 0)    (progn      (setq g (- g (1+ n))   r (reverse L)   h (nth n L))      (while (/= n (length (setq r (cdr (member h r))))))      (while (/= g (length (setq L (cdr (member h L))))))      (list (reverse r) (cons h L))    )    L  ))`
« Last Edit: January 19, 2022, 03:52:21 AM by Marc'Antonio Alessi »

#### kirby

• Newt
• Posts: 120
##### Re: [challenge] A14 : Split a list into two parts
« Reply #16 on: January 19, 2022, 09:48:45 AM »
Lunchtime fun, but won't win any prizes for brevity...
Thanks to JohnK for keeping this challenge going.
...

Your welcome. I'm trying to think of more but I'm running out of ideas. lol

You've been going hot and heavy on list manipulations
Lots of other classic programming topics (without getting into AutoCAD entity-specific manipulation)
e.g.:
String operations
Selection methods
Computational Geometry
Xdata
Dialog/DCL operations
etc.

#### apricot125

• Mosquito
• Posts: 13
##### Re: [challenge] A14 : Split a list into two parts
« Reply #17 on: January 20, 2022, 09:37:02 PM »
i love it.
Code - Auto/Visual Lisp: [Select]
1. (defun split (l n)
2.   (defun f (l n a)
3.     (cond
4.       ((null l) (reverse a))
5.       ((zerop n) (list (reverse a) l))
6.       (T (f (cdr l) (1- n) (cons (car l) a)))
7.     )
8.   )
9.   (f l n ())
10. )