Author Topic: (Challenge - Advanced)  (Read 8128 times)

0 Members and 1 Guest are viewing this topic.

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
(Challenge - Advanced)
« Reply #15 on: January 27, 2005, 02:09:27 PM »
Well, here's mine:
Code: [Select]

;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:
Code: [Select]

_$ (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))
_$

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(Challenge - Advanced)
« Reply #16 on: January 27, 2005, 02:42:03 PM »
For fun ...
Code: [Select]
(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:
Code: [Select]
(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
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(Challenge - Advanced)
« Reply #17 on: January 27, 2005, 02:44:17 PM »
What the holly banana's is dat?!  ...I understand one word out of that ..."thing"
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
(Challenge - Advanced)
« Reply #18 on: January 27, 2005, 02:57:36 PM »
Nice MP.  I like the first one.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(Challenge - Advanced)
« Reply #19 on: January 27, 2005, 03:57:32 PM »
Thanks whdjr. :)

Here's another for Se7en ...
Code: [Select]

(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
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(Challenge - Advanced)
« Reply #20 on: January 27, 2005, 08:26:54 PM »
*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
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(Challenge - Advanced)
« Reply #21 on: January 27, 2005, 09:56:29 PM »
Quote from: Se7en
Ahh recursion. I went the direct route.

Code: [Select]
(defun lstoftwo (x / nlst)
  (while (> (length x) 0)
     (setq nlst (cons (list (car x) (cadr x)) nlst))
       (setq x (cddr x))) (reverse nlst) )

Cool!
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
(Challenge - Advanced)
« Reply #22 on: January 27, 2005, 09:59:14 PM »
Quote from: Se7en
(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:

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(Challenge - Advanced)
« Reply #23 on: January 27, 2005, 10:01:42 PM »
Quote from: Jeff_M

Fine..... :moon: I'll just take my oh so portable code and go back to silent mode  :fart:   :cry:

LMAO!
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(Challenge - Advanced)
« Reply #24 on: January 27, 2005, 10:02:32 PM »
Ahhh Thanx MP!

(But i still think your a k-nerd!)

:P
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
(Challenge - Advanced)
« Reply #25 on: January 27, 2005, 10:06:34 PM »
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.... ;)

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
(Challenge - Advanced)
« Reply #26 on: January 27, 2005, 10:06:50 PM »
Knurd pride mang.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
(Challenge - Advanced)
« Reply #27 on: January 28, 2005, 08:37:51 AM »
Quote from: Jeff_M
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)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
(Challenge - Advanced)
« Reply #28 on: January 28, 2005, 10:01:22 AM »
Quote from: MP
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: