TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: whdjr on January 27, 2005, 08:52:35 AM
-
This is an advanced challenge (or at least I thought it was). Please allow 4 hours from the time of this post before submitting your answers. You may post a comment saying you're finished or you may post a question, but no answers until the buzzer sounds.
Challenge:
Turn a supplied point list (assume it is an even length) into a 2d point list.
Ex. '(1 2 3 4 5 6 7 8 9 10) would become '((1 2) (3 4) (5 6) (7 8) (9 10)).
An application for this would be to take a point list from a lightweight polyline and turn it into a 2d list of coordinates.
Please respect this forum by not posting an answer until the allotted time has expired.
-
What does the buzzer sound like?
-
Hey, this sounds familiar. Hey Stig werent you and i working somthing like this at one time? (By that i mean, didnt i ask you for code and when you gave me some i claimed it as my own.)
-
.. and when you gave me some i claimed it as my own.
Probably, .. you always do! :lol: :lol:
-
What does the buzzer sound like?
I can't do it now because everyone will think the challenge is over.
Hey Stig werent you and i working somthing like this at one time?
Ok you two are not allowed to post your answers because you confessed to already looking at the answers.
MARK! STIG AND SE7EN ARE CHEATERS!:P
-
Well Stig and i (read: Stig) may have already figured this out (read: i claimed it as my own.) but i just created my very own. (Just now) the one we worked on was a little more complicated then this. It was for picking points and creating a list on the fly... but anyways
I have mine ready.
Total of 5 lines of code. (Its meats your criteria exactly.)
-
You may post a comment saying you're finished or you may post a question, but no answers until the buzzer sounds.
I have mine that will accept a list returned from LWPlines or 3dPlines..... :D
-
You may post a comment saying you're finished or you may post a question, but no answers until the buzzer sounds.
I have mine that will accept a list returned from LWPlines or 3dPlines..... :D
That means you didn't follow directions. :?
Show Off! :wink:
-
Hey, no way Jeff. Thats cheeting! You have to meet the criteria not the application!?
I demand a recount!!
:P
-
That means you didn't follow directions. :?
Show Off! :wink:
Wait, the directions stated:
Turn a supplied point list (assume it is an even length) into a 2d point list.
So if mine takes a list and converts it to a 2d point, then it's just as requested.....it's just that mine can ALSO do 3d.... :D
-
So what are using to determine if an even numbered list is 2d or 3d?
-
I have to go to an AIA luncheon, so if I fall asleep and don't get back in time you guys go ahead and post your code when the buzzer hits 4 hours.
-
Gotta catch a train and I think the buzzer went (?) .. so:
(defun pairup (lst)
(cond ((null lst) nil)
((cons (list (car lst) (cadr lst)) (pairup (cddr lst))))
)
)
(setq alst '(1 2 3 4 5 6 7 8 9 10))
(pairup alst) -> ((1 2) (3 4) (5 6) (7 8 ) (9 10))
-
Ahh recursion. I went the direct route.
;;; Command: (setq alst '(1 2 3 4 5 6 7 8 9 0))
;;; (1 2 3 4 5 6 7 8 9 0)
;;;
;;; Command: (lstoftwo alst)
;;; ((1 2) (3 4) (5 6) (7 8) (9 0))
;;;
;;; Command: (setq alst '(1 2 3 4 5 6 7 8 9))
;;; (1 2 3 4 5 6 7 8 9)
;;;
;;; Command: (lstoftwo alst)
;;; ((1 2) (3 4) (5 6) (7 8) (9 nil))
(defun lstoftwo (x / nlst)
(while (> (length x) 0)
(setq nlst (cons (list (car x) (cadr x)) nlst))
(setq x (cddr x))) (reverse nlst) )
-
Very Good.
I also went the recursive route.
(defun lst->2dlst (lst / a b)
(setq a (list (car lst) (cadr lst)))
(if (setq b (cddr lst))
(append (list a) (lst->2dlst b))
(list a)
)
)
-
Well, here's mine:
;convert a flat list of coordinates as returned by ActiveX properties
; of objects like LWPlines, 3dplines, etc.
; arguments are the coordinate list and 2 or 3 for a 2d or 3d list
(defun list2coordpairs (clist 2or3 / newlist)
(if (= 2or3 2)
(while clist
(setq newlist (cons (list (car clist)
(cadr clist))
newlist)
clist (cddr clist))
)
(while clist
(setq newlist (cons (list (car clist)
(cadr clist)
(caddr clist))
newlist)
clist (cdddr clist))
)
)
(reverse newlist)
)
and in use:
_$ (setq mylist '(1.0 2.0 0.0 1.0 3.0 0.0 15.0 18.0 0.0 18.0 6.0 0.0))
(list2coordpairs mylist 2)
(list2coordpairs mylist 3)
(1.0 2.0 0.0 1.0 3.0 0.0 15.0 18.0 0.0 18.0 6.0 0.0)
((1.0 2.0) (0.0 1.0) (3.0 0.0) (15.0 18.0) (0.0 18.0) (6.0 0.0))
((1.0 2.0 0.0) (1.0 3.0 0.0) (15.0 18.0 0.0) (18.0 6.0 0.0))
_$
-
For fun ...
(defun pairs ( lst / result x )
(while lst
(setq
result (cons (mapcar 'set '(x x) lst) result)
lst (cddr lst)
)
)
(reverse result)
)
(pairs '(1 2 3 4 5 6))
=> ((1 2) (3 4) (5 6))
And just to give Se7en a headache, the same thing somewhat obfuscated:
(defun pairs ( lst )
(reverse
( (lambda ( lst / x r )
(while lst
(setq
r (cons (mapcar 'set '(x x) lst) r)
lst (cddr lst)
)
)
r
)
lst
)
)
)
:D
-
What the holly banana's is dat?! ...I understand one word out of that ..."thing"
-
Nice MP. I like the first one.
-
Thanks whdjr. :)
Here's another for Se7en ...
(defun pairs ( lst / result x )
(eval
(read
(vl-list->string
'(
040 112 114 111 103 110 032 040
119 104 105 108 101 032 108 115
116 032 040 115 101 116 113 032
114 101 115 117 108 116 032 040
099 111 110 115 032 040 109 097
112 099 097 114 032 039 115 101
116 032 039 040 120 032 120 041
032 108 115 116 041 032 114 101
115 117 108 116 041 032 108 115
116 032 040 099 100 100 114 032
108 115 116 041 041 041 032 040
114 101 118 101 114 115 101 032
114 101 115 117 108 116 041 041
)
)
)
)
)
(pairs '(1 2 3 4 5 6))
=> ((1 2) (3 4) (5 6))
:D
-
*blink* OMG?! You are such a K-neeeerd!
Hey whdjr, you better take a close look at MP's first one and mine. They are almost the same thing. (And i didnt get a 'cool vote' *herumph!*) Well i guess he pulled a fancy trick in there.
But, Stig didnt get a 'cool vote'? Or Jeff for that matter? (Well actually Jeff dosent deserve a cool vote cause he didnt follow the rules. [text only jeff can see] *na-na-na-na* *pthhhht!*[/text only jeff can see]
:lol: :P
-
Ahh recursion. I went the direct route.
(defun lstoftwo (x / nlst)
(while (> (length x) 0)
(setq nlst (cons (list (car x) (cadr x)) nlst))
(setq x (cddr x))) (reverse nlst) )
Cool!
-
(Well actually Jeff dosent deserve a cool vote cause he didnt follow the rules. [text only jeff can see] *na-na-na-na* *pthhhht!*[/text only jeff can see]
Fine..... :moon: I'll just take my oh so portable code and go back to silent mode :fart: :cry:
-
Fine..... :moon: I'll just take my oh so portable code and go back to silent mode :fart: :cry:
LMAO!
-
Ahhh Thanx MP!
(But i still think your a k-nerd!)
:P
-
And BTW Se7en, if you look closely our code for the 2 elements per coordinate a nearly identical...the only reason I posted my full function is because I use it often and thought it would help others...... :D and if I woulda just posted the smaller snippet you would've accused me of swipin' yours.... ;)
-
Knurd pride mang.
-
And BTW Se7en, if you look closely our code for the 2 elements per coordinate a nearly identical...the only reason I posted my full function is because I use it often and thought it would help others...... :D and if I woulda just posted the smaller snippet you would've accused me of swipin' yours.... ;)
Holly cow!? Well you know what they say Jeff. "Great minds think alike."
Nah, i wouldnt do that :lol: (I would just claim yours as mine later. :p)
-
Cool!
Thanks for picking up the slack MP.
Se7en, yours (probably a copy of stig's) and Stig's code are KOOL.
Thanks for all the code and laughs guys. It was great fun.
That would a good name for a k-nerd bar: "CODES -n- LAUGHS"
You bring the code and we'll laugh. :lol: :lol: