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

0 Members and 1 Guest are viewing this topic.

whdjr

  • Guest
(Challenge - Advanced)
« 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.

SMadsen

  • Guest
(Challenge - Advanced)
« Reply #1 on: January 27, 2005, 09:10:11 AM »
What does the buzzer sound like?

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
(Challenge - Advanced)
« Reply #2 on: January 27, 2005, 09:23:56 AM »
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.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

SMadsen

  • Guest
(Challenge - Advanced)
« Reply #3 on: January 27, 2005, 09:34:30 AM »
Quote from: Se7en
.. and when you gave me some i claimed it as my own.
Probably, .. you always do!  :lol:  :lol:

whdjr

  • Guest
(Challenge - Advanced)
« Reply #4 on: January 27, 2005, 09:47:24 AM »
Quote from: SMadsen
What does the buzzer sound like?

I can't do it now because everyone will think the challenge is over.

Quote from: Se7en
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

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
(Challenge - Advanced)
« Reply #5 on: January 27, 2005, 10:18:21 AM »
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.)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

Jeff_M

  • King Gator
  • Posts: 4093
  • C3D user & customizer
Re: (Challenge - Advanced)
« Reply #6 on: January 27, 2005, 11:01:49 AM »
Quote from: whdjr
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

whdjr

  • Guest
Re: (Challenge - Advanced)
« Reply #7 on: January 27, 2005, 11:13:24 AM »
Quote from: Jeff_M
Quote from: whdjr
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:

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
(Challenge - Advanced)
« Reply #8 on: January 27, 2005, 11:14:32 AM »
Hey, no way Jeff. Thats cheeting! You have to meet the criteria not the application!?

I demand a recount!!

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

Donate to TheSwamp.org

Jeff_M

  • King Gator
  • Posts: 4093
  • C3D user & customizer
Re: (Challenge - Advanced)
« Reply #9 on: January 27, 2005, 11:28:45 AM »
Quote from: whdjr

That means you didn't follow directions. :?

Show Off!  :wink:

Wait, the directions stated:
Quote from: whdjr
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

whdjr

  • Guest
(Challenge - Advanced)
« Reply #10 on: January 27, 2005, 11:32:18 AM »
So what are using to determine if an even numbered list is 2d or 3d?

whdjr

  • Guest
(Challenge - Advanced)
« Reply #11 on: January 27, 2005, 11:50:18 AM »
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.

SMadsen

  • Guest
(Challenge - Advanced)
« Reply #12 on: January 27, 2005, 01:00:06 PM »
Gotta catch a train and I think the buzzer went (?) .. so:

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

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
(Challenge - Advanced)
« Reply #13 on: January 27, 2005, 01:02:11 PM »
Ahh recursion. I went the direct route.

Code: [Select]
;;; 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) )
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
(Challenge - Advanced)
« Reply #14 on: January 27, 2005, 02:01:49 PM »
Very Good.

I also went the recursive route.

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

Jeff_M

  • King Gator
  • Posts: 4093
  • 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.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
(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.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
(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.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

Jeff_M

  • King Gator
  • Posts: 4093
  • 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: 10623
(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: 10623
(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: 4093
  • 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.com http://cadanalyst.slack.com http://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10623
(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: