TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: JohnK on May 10, 2006, 08:45:08 AM

Title: Name the process :: Game 1
Post by: JohnK on May 10, 2006, 08:45:08 AM
The object of this game is to name the process you want done on this function. The first one to post, gets to name the overall process preformed. Then we have to build our procedures based on those instructions. For instance; here is a sample game played out.


*** POST 1

Given the list: (0 1 2 3 4 5 6 7 8 9)
I want to ___________.

*** POST 2

Return the list with he last item removed.

*** POST 3

(defun pop-last (l)
  (reverse (cdr (reverse l))) )


(Obviously, thats a very simple example, but im not going to build a complex example for something that im not entirely sure is going to 'fly'.) I think this game could be alot of fun because of the lack of direction (so to speak) You are free to do as you want without restraints.

So...

Given the list: (0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9)
I want to ___________.
Title: Re: Name the process :: Game 1
Post by: uncoolperson on May 10, 2006, 10:11:33 AM
dent it up real good?



list unique?
(create a list of lists of unique values from a list of not so unique values)


Title: Re: Name the process :: Game 1
Post by: JohnK on May 10, 2006, 11:49:13 AM
What?!
Title: Re: Name the process :: Game 1
Post by: uncoolperson on May 10, 2006, 12:38:24 PM
i did it once... and i forgot what i did to make it pretty...



turn a list like;
(1 2 3 4 5 4 4 2 1 3 6 7 4 6 9 6 5 1 3)

into
(( 1 2 3 4 5 6 7 9 ) ( 1 2 3 4 5 6 ) ( 1 3 4 6 ) ( 4 ))
Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 11, 2006, 08:55:44 AM
Code: [Select]
(defun for-theswamp (lst)
  (if lst
    ((lambda (x)
       (cons (vl-sort (car x) '<) (for-theswamp (cadr x)))
     ) ;_  lambda
      (for-theswamp-1 (cdr lst) (list (car lst)) nil)
    )
  ) ;_  if
) ;_  defun
(defun for-theswamp-1 (lst a1 a2)
  (if lst
    (if (member (car lst) a1)
      (for-theswamp-1 (cdr lst) a1 (cons (car lst) a2))
      (for-theswamp-1 (cdr lst) (cons (car lst) a1) a2)
    ) ;_  if
    (list a1 a2)
  ) ;_  if
) ;_  defun


(for-theswamp  '(1 2 3 4 5 4 4 2 1 3 6 7 4 6 9 6 5 1 3))
;; => '((1 2 3 4 5 6 7 9) (1 2 3 4 5 6) (1 3 4 6) (4))
Title: Re: Name the process :: Game 1
Post by: uncoolperson on May 11, 2006, 10:22:05 AM
i thought i had killed this
Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 11, 2006, 10:36:35 AM
i thought i had killed this
I have not understood you...
I have written this program today.
Title: Re: Name the process :: Game 1
Post by: CAB on May 11, 2006, 11:18:41 AM
AS I understand uncoolperson comment, I think he was saying that he killed the thread due to the lack of activity.
I just think people are too busy to participate, anyway that's my excuse.
Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 11, 2006, 12:54:50 PM
Thank for explanations Alan :-)
Title: Re: Name the process :: Game 1
Post by: CAB on May 11, 2006, 01:06:07 PM
You are welcome.
Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 11, 2006, 01:33:28 PM
You are welcome.

If, my course...

Sort the list which is not using SETQ, VL-*
Code: [Select]
(setq lst '(7 3 4 6 9 6 7 2 5 3 2 3 6 4 6 3 1)
      f   (function <)
)
(defun sort (lst f)
  ?????
)
  :-)
Title: Re: Name the process :: Game 1
Post by: CAB on May 11, 2006, 01:44:50 PM
Code: [Select]
(defun sort (lst)
  (dos_sortlist lst)
)
Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 11, 2006, 01:47:29 PM
Shortly, but for me does not work... :-(
Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 11, 2006, 01:49:30 PM
Code: [Select]
(defun sort (lst)
  (dos_sortlist lst)
)
For this program, it is necessary dos_lib?
Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 12, 2006, 01:42:52 PM
Probably, I have not understood, game rules...
Where I can see or explain me.
Beforehand thank!
Title: Re: Name the process :: Game 1
Post by: CAB on May 12, 2006, 02:46:22 PM
ElpanovEvgeniy
I think you got it.
You started with a hard one. I tried for about 15 minutes but no easy solution.
Perhaps you can post your solution.

Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 12, 2006, 02:57:23 PM
ElpanovEvgeniy
I think you got it.
You started with a hard one. I tried for about 15 minutes but no easy solution.
Perhaps you can post your solution.

Version 1
Code: [Select]
(defun rec-min (lst mi f)
  ;(rec-min (cdr lst) (car lst) f)
  (cond
    ((not lst) mi)
    (((eval f) (car lst) mi)
     (rec-min (cdr lst) (car lst) f)
    )
    (t (rec-min (cdr lst) mi f))
  ) ;_  cond
) ;_  defun
(defun rec-remove-singl (i lst)
  ;(rec-remove-singl (cadr lst) lst)
  (if lst
    (if (equal i (car lst))
      (cdr lst)
      (cons (car lst) (rec-remove-singl i (cdr lst)))
    ) ;_  if
  ) ;_  if
) ;_  defun
(defun rec-sort-min (lst f)
  ;(rec-sort-min lst)
  (if lst
    ((lambda (x)
       (cons
         x
         (rec-sort-min
           (rec-remove-singl
             x
             lst
           )
           f
         )
       )
     ) ;_  lambda
      (rec-min (cdr lst) (car lst) f)
    )
  ) ;_  if
) ;_  defun

  ; Check:
(setq lst '(7 3 4 6 9 6 7 2 5 3 2 3 6 4 6 3 1)
      f   (function <)
) ;_  setq
(rec-sort-min lst f)
Version 2
Code: [Select]
(defun rec-min-max (lst mi ma f)
  (cond
    ((not lst) (list mi ma))
    (((eval f) (car lst) mi)
     (rec-min-max (cdr lst) (car lst) ma f)
    )
    (((eval f) ma (car lst))
     (rec-min-max (cdr lst) mi (car lst) f)
    )
    (t (rec-min-max (cdr lst) mi ma f))
  ) ;_  cond
) ;_  defun
(defun rec-remove-singl (i lst)
  (if lst
    (if (equal i (car lst))
      (cdr lst)
      (cons (car lst) (rec-remove-singl i (cdr lst)))
    ) ;_  if
  ) ;_  if
) ;_  defun
(defun rec-sort-min-max (lst f)
  (cond
    ((not lst) nil)
    ((not(cdr lst)) lst)
    (t
     ((lambda (x)
        (cons
          (car x)
          (append
            (rec-sort-min-max
              (rec-remove-singl
                (car x)
                (rec-remove-singl
                  (cadr x)
                  lst
                ) ;_  rec-remove-singl
              ) ;_  rec-remove-singl
              f
            ) ;_  rec-sort-lists
            (cdr x)
          ) ;_  append
        ) ;_  cons
      ) ;_  lambda
       (rec-min-max (cdr lst) (car lst) (car lst) f)
     )
    )
  ) ;_  cond
) ;_  defun

  ; Check:
(setq lst '(7 3 4 6 9 6 7 2 5 3 2 3 6 4 6 3 1)
      f   (function <)
) ;_  setq
(rec-sort-min-max lst f)

Version 3
Code: [Select]
(defun rec-quicksort-2 (lst lst1 lst2 test f)
  (cond
    ((not lst)
      (list lst1 (list test) lst2)
    )
    (((eval f) (car lst) test)
     (rec-quicksort-2 (cdr lst) (cons (car lst) lst1) lst2 test f)
    )
    (t (rec-quicksort-2 (cdr lst) lst1 (cons (car lst) lst2) test f))
  ) ;_  cond
) ;_  defun

(defun rec-quicksort-1 (lst f)
  (cond
    ((not lst) nil)
    ((not (car lst)) (rec-quicksort-1 (cdr lst) f))
    ((not (cdar lst))
     (cons (caar lst) (rec-quicksort-1 (cdr lst) f))
    )
    ((not (cddar lst))
     (if (apply f (car lst))
       (cons (caar lst) (cons (cadar lst) (rec-quicksort-1 (cdr lst) f)))
       (cons (cadar lst) (cons (caar lst) (rec-quicksort-1 (cdr lst) f)))
     ) ;_  if
    )
    (t
     ((lambda (x)
        (rec-quicksort-1 (cons (car x) (cons (cadr x) (cons (caddr x) (cdr lst)))) f)
      ) ;_  lambda
       (rec-quicksort-2 (cdar lst) nil nil (caar lst) f)
     )
    )
  ) ;_  cond
) ;_  defun

(defun rec-quicksort (lst f)
  (rec-quicksort-1 (list lst) f)
) ;_  defun

  ; Check:
(setq lst '(7 3 4 6 9 6 7 2 5 3 2 3 6 4 6 3 1)
      f   (function <)
) ;_  setq
(rec-quicksort lst f)

Title: Re: Name the process :: Game 1
Post by: ElpanovEvgeniy on May 12, 2006, 03:09:38 PM
All this, you can see:

The original (RU):
http://www.autocad.ru/cgi-bin/f1/board.cgi?t=25113OT
Machine translation (EN):
http://babelfish.altavista.com/babelfish/trurl_pagecontent?lp=ru_en&trurl=http%3a%2f%2fwww.autocad.ru%2fcgi-bin%2ff1%2fboard.cgi%3ft%3d25113OT
{Editing = add
see: Lessons 8 - 10}
Title: Re: Name the process :: Game 1
Post by: CAB on May 12, 2006, 05:26:34 PM
No wonder I was having trouble figuring it out. :)
Thanks for the link, I'll do some reading. Just need more time....