Author Topic: ==={challenge}=== Word Puzzle  (Read 18438 times)

0 Members and 1 Guest are viewing this topic.

LE3

  • Guest
Re: ==={challenge}=== Word Puzzle
« Reply #30 on: May 10, 2012, 09:05:13 AM »
Excellent work Luis .  Can't say I understand it at all, But  I'll start digging in to your code later and try to  figure out your method.

Word found[GLAD]at[GLADC]  <-- I like the way it prints  the result on the command prompt.

thanks!

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ==={challenge}=== Word Puzzle
« Reply #31 on: May 11, 2012, 11:41:27 AM »
my variant:
Code - Auto/Visual Lisp: [Select]
  1. (defun wordpuzzle (l / A B C I S)
  2.   (defun f (b i)
  3.     (cond ((or (not (car b)) (< i 0)) nil)
  4.           ((nth i b) (cons (car (nth i b)) (f (mapcar (function cdr) b) (1- i))))
  5.           ((f (mapcar (function cdr) b) (1- i)))
  6.     )
  7.   )
  8.   (defun f1 (b i)
  9.     (if (<= 0 i)
  10.       (cons (f b i) (f1 b (1- i)))
  11.     )
  12.   )
  13.   (if (setq s (ssget "_x" '((0 . "text"))))
  14.     (progn (setq a (vl-sort (mapcar (function (lambda (a) (setq a (entget (cadr a))) (cons (cdr (assoc 1 a)) (cdr (assoc 11 a)))))
  15.                                     (ssnamex s)
  16.                             )
  17.                             (function (lambda (a b)
  18.                                         (if (equal (cadr a) (cadr b) 1e-3)
  19.                                           (>= (caddr a) (caddr b))
  20.                                           (>= (cadr a) (cadr b))
  21.                                         )
  22.                                       )
  23.                             )
  24.                    )
  25.                  b nil
  26.            )
  27.            (while a
  28.              (setq b (cons (vl-remove-if-not (function (lambda (b) (equal (cadar a) (cadr b) 1e-3))) a) b)
  29.                    a (vl-remove-if (function (lambda (b) (equal (cadar a) (cadr b) 1e-3))) a)
  30.              )
  31.            )
  32.            (setq i (+ (length b) (length (car b)) -2)
  33.                  b (list b
  34.                          (mapcar (function reverse) b)
  35.                          (apply (function mapcar) (cons (function list) b))
  36.                          (apply (function mapcar) (cons (function list) (reverse b)))
  37.                    )
  38.                  b (apply (function append) (append b (mapcar (function (lambda (a) (f1 a i))) b)))
  39.                  c (mapcar (function
  40.                              (lambda (a) (cons (apply (function strcat) (mapcar (function car) a)) (mapcar (function cdr) a)))
  41.                            )
  42.                            b
  43.                    )
  44.            )
  45.            (foreach a l
  46.              (if (setq b (vl-member-if (function (lambda (b) (setq i (vl-string-search a (car b))))) c))
  47.                (entmakex (list '(0 . "line") (cons 10 (nth (1+ i) (car b))) (cons 11 (nth (+ i (strlen a)) (car b)))))
  48.              )
  49.            )
  50.     )
  51.   )
  52.   (princ)
  53. )

test:
Code - Auto/Visual Lisp: [Select]
  1. (wordpuzzle '("BOX" "MAD" "AMASS" "LSP" "EGG" "AXE" "ATTIC" "GLAD" "test"))

pBe

  • Bull Frog
  • Posts: 402
Re: ==={challenge}=== Word Puzzle
« Reply #32 on: May 12, 2012, 02:03:00 AM »
Great code  ElpanovEvgeniy. Another head spinner  :-D

Question for you guys,
Whats the diffrerence?

Code - Auto/Visual Lisp: [Select]
  1.               (lambda (j)
  2.                     (+ (* j j) j)))
  3.         '(1 2 3 4))

Code - Auto/Visual Lisp: [Select]
  1. (mapcar '(lambda (j)
  2.                (+ (* j j) j))
  3.         '(1 2 3 4))



ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)

pBe

  • Bull Frog
  • Posts: 402
Re: ==={challenge}=== Word Puzzle
« Reply #34 on: May 12, 2012, 02:39:12 AM »
http://www.theswamp.org/~john/avlisp/#function

Thanks Evgeniy, does that mean with the use function function it acts as if the code is compiled? Does it mean better perfiormance? or just a "cleaner" code and easier to debug?

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: ==={challenge}=== Word Puzzle
« Reply #35 on: May 12, 2012, 02:44:08 AM »
http://www.theswamp.org/~john/avlisp/#function

Thanks Evgeniy, does that mean with the use function function it acts as if the code is compiled? Does it mean better perfiormance? or just a "cleaner" code and easier to debug?

function increases the speed of the program, after compiling!  :-)
For me, this is the most important thing...

I have long been accustomed to, be sure to write a FUNCTION.

pBe

  • Bull Frog
  • Posts: 402
Re: ==={challenge}=== Word Puzzle
« Reply #36 on: May 12, 2012, 02:58:53 AM »
function increases the speed of the program, after compiling!  :-)

Got it.

For me, this is the most important thing...

I believe  it does matter a lot doesnt it?  :-)

Thank you for your insights Evgeniy.
kudos to you.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: ==={challenge}=== Word Puzzle
« Reply #37 on: May 12, 2012, 08:27:42 AM »
function increases the speed of the program, after compiling!  :-)

Though, I think the use of function only has an effect on compiled performance when used with the anonymous lambda function, not with regular AutoLISP functions which are already compiled and optimised.

http://www.theswamp.org/index.php?topic=40271

Will be spending some time looking over your code Evgeniy :-)

pBe

  • Bull Frog
  • Posts: 402