TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mark on December 01, 2006, 02:05:26 PM

Title: ( Challenge ) Just curious
Post by: Mark on December 01, 2006, 02:05:26 PM
I was wondering why none of you LISP masters participated in the latest challenge?

[ http://www.theswamp.org/index.php?topic=13679.0 ] HI LOW
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 01, 2006, 02:45:13 PM
No reason. Note, subs not included.
Quote
Command: hilow

 Elasped time 2.687 seconds.
Code: [Select]
(defun c:HiLow (/ File Opened TextLine TextList NumList Timer NewOpened NewFile)

(if
 (and
  (setq File (getfiled "" "" "csv" 4))
  (setq Opened (open File "r"))
  (setq NewFile (strcat (vl-filename-directory File) "\\Returned.csv"))
  (setq NewOpened (open NewFile "w"))
 )
 (progn
  (setq Timer (StartTimer))
  (while (setq TextLine (read-line Opened))
   (setq TextList (StrParse TextLine ","))
   (setq NumList (mapcar '(lambda (x) (cons (distof x) x)) TextList))
   (setq NumList (vl-sort NumList '(lambda (a b) (< (car a) (car b)))))
;   (prompt (strcat "\n " (cdar NumList) " - " (cdr (last NumList))))
   (write-line (strcat (cdar NumList) "," (cdr (last NumList))) NewOpened)
  )
  (close Opened)
  (close NewOpened)
  (prompt (EndTimer Timer))
 )
)
(princ)
)
Quote
13   922
133   992
337   980
39   869
76   944
149   877
87   959
82   777
235   980
307   834
Edit:  Forgot to add that I'm no master.
Title: Re: ( Challenge ) Just curious
Post by: Jeff_M on December 01, 2006, 02:51:49 PM
I'll admit that I whipped up one that I was going to post but Acad crashed doing something else (real work) before I saved it. I just never got back to re-writing it (forgot about it, actually, after trying to find what I did to crash), plus it was far slower than what the others came up with....but still faster than Tim's :-P at ~1.5 seconds. I'll see if I can duplicate it during lunch today (starts in about 10 minutes).
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 01, 2006, 02:59:21 PM
I didn't realize it was open to all languages.
Me no speak C++
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 01, 2006, 03:00:05 PM
I'll admit that I whipped up one that I was going to post but Acad crashed doing something else (real work) before I saved it. I just never got back to re-writing it (forgot about it, actually, after trying to find what I did to crash), plus it was far slower than what the others came up with....but still faster than Tim's :-P at ~1.5 seconds. I'll see if I can duplicate it during lunch today (starts in about 10 minutes).
Man the love is gone from this place I see.  :oops: :cry:

I would love to see how you do it Jeff.
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 01, 2006, 03:12:46 PM
Jeff that sounds a lot like "My dog ate my home work" .  :lmao:
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 01, 2006, 03:20:56 PM
Jeff that sounds a lot like "My dog ate my home work" .  :lmao:
x2  :angel:
Title: Re: ( Challenge ) Just curious
Post by: Jeff_M on December 01, 2006, 03:33:31 PM
Heh, I dunno what I'm doing differently but now I can only achieve a time of about 3.5 seconds :|

Code: [Select]
(defun c:max-min (/ file1 file2 lin linlist max1 min1 timer)
  (defun Split (str / i j lst)
    (setq i 0)
    (while (setq j (vl-string-search "," str i))
      (setq lst (cons (substr str (1+ i)(- j i)) lst)
    i (1+ j)
    )
      )
    (reverse (cons (substr str (1+ i)) lst))
    )
  ;;;main function
  (setq timer (getvar "millisecs"))
  (if (setq file1 (open "C:\\Base Maps\\Jeffs Test Files\\junk\\numbers.csv" "R"))
    (progn
      (setq file2 (open "C:\\Base Maps\\Jeffs Test Files\\junk\\results.csv" "W"))
      (while (setq lin (read-line file1))
(setq linlist (mapcar 'atoi (split lin)))
(setq min1 (apply 'min linlist)
      max1 (apply 'max linlist)
      )
(write-line (strcat (itoa max1) "," (itoa min1)) file2)
)
      (close file1)
      (close file2)
      (princ (strcat "Process took " (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2) " seconds."))
      )
    )
  (princ)
  )
Title: Re: ( Challenge ) Just curious
Post by: Jeff_M on December 01, 2006, 03:37:19 PM
Man the love is gone from this place I see.  :oops: :cry:

I would love to see how you do it Jeff.
No worries, Tim, there's plenty of love to go around....it IS that time of year :-)

I'm beginning to think I'd love to see how I did it, too. :|
Title: Re: ( Challenge ) Just curious
Post by: Mark on December 01, 2006, 03:55:54 PM
I didn't realize it was open to all languages.
Me no speak C++

Well if I posted the challenge here then the C/C++/C#, Python and VB folks would feel left out! :-)

Unless otherwise noted, all challenges are open to all languages.
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 01, 2006, 04:12:26 PM
Times:
Command: test
Process took 1.97 seconds.

Command:
Command: test
Process took 2.01 seconds.

Command:
Command: test
Process took 2.01 seconds.

Command:
Command: test
Process took 2.00 seconds.

Command:
Command: test
Process took 2.01 seconds.

Command:
Command: test
Process took 2.01 seconds.

Command:
Command: test
Process took 2.02 seconds.

Command:
Command: test
Process took 2.00 seconds.

Routines will need to be compared  on one computer for the times to mean anything.
1.2Ghz here

Code: [Select]
(defun c:test (/ FILEBASE FILEDATA FILENAME HANDLE LST PATH STREAM)
  (setq timer (getvar "millisecs"))

  (if
    (and
      (setq filename (findfile "numbers.csv"))
      (setq handle (open filename "r"))
    )
     (progn
       (while (setq stream (read-line handle))
         (setq FileData (cons stream FileData))
       ) ; while
       (close handle)
     )
  )

  (if FileData
    (progn
      (setq path     (vl-filename-directory filename)
            filebase (vl-filename-base filename)
            handle   (open (strcat path "\\" filebase "-out.csv") "w")
      )
      (mapcar
        (function
          (lambda (x)
            (setq lst
                   (mapcar
                     (function
                       (lambda (y)
                         (atoi y)
                       )
                     )
                     (sparser1 x ",")
                   )
            )
            (princ (apply 'max lst) handle)
            (princ "-" handle)
            (princ (apply 'min lst) handle)
            (princ "\n" handle)
          )
        )
        FileData
      )
      (close handle)
      (princ (strcat "Process took "
                     (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                     " seconds."
             )
      )

    )
  )

  (princ)
)



;;  parser by CAB 
(defun sparser1 (str delim / ptr lst)
  (while (setq ptr (vl-string-search delim str))
    (setq lst (cons (substr str 1 ptr) lst))
    (setq str (substr str (+ ptr 2)))
  )
  (reverse (cons str lst))
)
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 01, 2006, 04:14:18 PM
Well if I posted the challenge here then the C/C++/C#, Python and VB folks would feel left out! :-)

Now you know how we felt.

Just kidding  :-D
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 01, 2006, 04:51:46 PM
Routines will need to be compared  on one computer for the times to mean anything.
1.2Ghz here
I guess I can do that.
Quote
Command: test
Process took 1.11 seconds.

Command:
Command:
TEST Process took .91 seconds.

Command:
Command:
TEST Process took .92 seconds.

Command:
Command:
TEST Process took .91 seconds.
Edit: vvv
I added a reverse to your function Alan (so the order would be the same as the first csv file), and reran it.
Quote
Command: test
Process took .91 seconds.

Command:
Command:
TEST Process took .95 seconds.

Command:
Command:
TEST Process took .91 seconds.
Title: Re: ( Challenge ) Just curious
Post by: Jeff_M on December 01, 2006, 05:00:25 PM
Hmmm, evidently the amount of RAM in use also plays a role in the speed of execution. When I was testing my code at lunch I was in R2002 but I had C3D2007 open (among numerous other smaller programs), too. I closed the C3D about 10 minutes ago and tried CAB's and it came in at:

Command: test
Process took 2.52 seconds.

I then re-ran mine and got this:

Command: max-min
Process took 2.14 seconds.

That's a HUGE difference from the 3.5-3.6 seconds I was getting earlier.....but it's also still a far cry from the sub 1 second performance of the C++/C#/Python crowd.

Oh, the other smaller programs in use during all tests.....
outlookExpress6, Firefox 1.5.0.8, WinExplorer x2, Map5.
Computer:
Toshiba Laptop
P4@2.8 ghz, 1gb RAM

Holy Katz, Tim! Is my laptop really that slow?. <grumble.wav>
Title: Re: ( Challenge ) Just curious
Post by: It's Alive! on December 01, 2006, 05:04:12 PM
Mark, I think you need to go wakeup those VBA guys too!  :police:
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 01, 2006, 05:17:53 PM
Holy Katz, Tim! Is my laptop really that slow?. <grumble.wav>
Intel(R)Xeo (processor?)
2.8GHz
1Gb Ram
I have Lotus Notes, Outlook 6, Firefox, Exploer,  Winamp (ssshh!! don't tell my boss) AutoCAD Electrial '06 running at the time tested.
Title: Re: ( Challenge ) Just curious
Post by: Kerry on December 01, 2006, 07:04:47 PM
Jeff,  Alan ,

I've noticed that some of the others are opening the file before they start the timer .... that may shave a little bit off if you are concerned about time.
Title: Re: ( Challenge ) Just curious
Post by: Jeff_M on December 01, 2006, 07:20:18 PM
Thanks for the thought, Kerry. Although it doesn't save all that much...:

Code: [Select]
(progn
  (setq timer (getvar "millisecs"))
  (setq file1 (open "C:\\Base Maps\\Jeffs Test Files\\junk\\numbers.csv" "R"))
  (close file1)
  (princ (strcat "Process took " (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2) " seconds."))
  )
Process took 0.03 seconds.

Of course I guess this just proves that Lisp was not designed to work, at least not quickly, with large data sets.
Title: Re: ( Challenge ) Just curious
Post by: Kerry on December 01, 2006, 07:57:59 PM
Still, 2.5 seconds is not too slouchfull for an interpreted language ..

read 10,000 line of text with 10 values each line
translate text in each line to numbers
evaluate min
evaluate max
write values to file

rinse and repeat ....

.... there's a lot going on there ....

Title: Re: ( Challenge ) Just curious
Post by: Andrea on December 01, 2006, 08:31:28 PM
there is mine...

Code: [Select]
(defun c:minmax (/ start-time f1 l1 lineM #low #hi newfile end-time fr)
(setq f1 (open (getfiled "Please select your file..." "" "csv" 8) "r")
      l1 (read-line f1))
(setq start-time (getvar "cdate"))
(if l1 (setq newfile (open "c:\\result.txt" "w")))
(while l1
(setq lineM (read (strcat "(" (acet-str-replace "," " "  l1) ")"))
       #low (car (vl-sort lineM '<))
        #hi (car (vl-sort lineM '>)))
(write-line (strcat (rtos #hi) " " (rtos #low)) newfile)

(setq l1 (read-line f1)))

(close f1)
(close newfile)

(setq end-time (getvar "cdate")
fr (substr (rtos (- end-time start-time) 2 10) 7))
(alert (strcat "Done in only ..." (substr fr 1 2) "," (substr fr 3) " sec."))
)
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 02, 2006, 04:46:42 AM
Process took 0.03 seconds.
:-o

for my pc...
Code: [Select]
(progn
  ;;Jeff_M
  (setq timer (getvar "millisecs"))
  (repeat 100
  (setq
    file1 (open "D:\\numbers.csv"
                "R"
          ) ;_ open
  ) ;_ setq
  (close file1)
    )
  (princ
    (strcat "Process took "
            (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
            " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
)

repeat 100:
Process took 0.015 seconds.
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 02, 2006, 06:20:45 AM

Code: [Select]
(defun c:test_1 (/ f timer)
  ;;(c:test_1)
  ;; ElpanovEvgeniy
  (defun pars (s f f1)
    (if s
      (progn
        ((lambda (l)
           (if (< (car l) (cadr l))
             (min_max (car l) (cadr l) (cddr l) f1)
             (min_max (cadr l) (car l) (cddr l) f1)
           ) ;_ if
         ) ;_ lambda
          (read (strcat "(" (VL-STRING-TRANSLATE "," " " s) ")"))
        )
        (pars (read-line f) f f1)
      ) ;_ progn
      (progn
        (close f)
        (close f1)
      ) ;_ progn
    ) ;_ if
  ) ;_ defun
  (defun min_max (mi ma l f)
    (if l
      (if (< (car l) mi)
        (min_max (car l) ma (cdr l) f)
        (if (> (car l) ma)
          (min_max mi (car l) (cdr l) f)
          (min_max mi ma (cdr l) f)
        ) ;_ if
      ) ;_ if
      (write-line (strcat (itoa mi) " " (itoa ma)) f)
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (pars (read-line (setq f (open "D:\\numbers.csv" "R"))) f (open "D:\\result.csv" "W"))
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
) ;_ defun

(defun c:test_2 (/ f f1 timer)
  ;;(c:test_2)
  ;; ElpanovEvgeniy
  (defun pars (s f)
    (if s
      (cons (read (strcat "(" (VL-STRING-TRANSLATE "," " " s) ")"))
            (pars (read-line f) f)
      ) ;_ cons
      (close f)
    ) ;_ if
  ) ;_ defun
  (defun min_max (mi ma l f)
    (if l
      (if (< (car l) mi)
        (min_max (car l) ma (cdr l) f)
        (if (> (car l) ma)
          (min_max mi (car l) (cdr l) f)
          (min_max mi ma (cdr l) f)
        ) ;_ if
      ) ;_ if
      (write-line (strcat (itoa mi) " " (itoa ma)) f)
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (setq f1 (open "D:\\numbers.csv" "R"))
  (setq f (open "D:\\result.csv" "W"))
  (foreach l (pars (read-line f1) f1)
    (if (< (car l) (cadr l))
      (min_max (car l) (cadr l) (cddr l) f)
      (min_max (cadr l) (car l) (cddr l) f)
    ) ;_ if
  ) ;_ foreach
  (close f)
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
) ;_ defun

(defun c:max-min (/ file1 file2 lin linlist max1 min1 timer)
  ;;(c:max-min)
  ;;Jeff_M
  (defun Split (str / i j lst)
    (setq i 0)
    (while (setq j (vl-string-search "," str i))
      (setq lst (cons (substr str (1+ i) (- j i)) lst)
            i   (1+ j)
      ) ;_ setq
    ) ;_ while
    (reverse (cons (substr str (1+ i)) lst))
  ) ;_ defun
;;;main function
  (setq timer (getvar "millisecs"))
  (if
    (setq
      file1 (open "D:\\numbers.csv" "R")
    ) ;_ setq
     (progn
       (setq file2
              (open "D:\\results.csv"
                    "W"
              ) ;_ open
       ) ;_ setq
       (while (setq lin (read-line file1))
         (setq linlist (mapcar 'atoi (split lin)))
         (setq min1 (apply 'min linlist)
               max1 (apply 'max linlist)
         ) ;_ setq
         (write-line (strcat (itoa max1) "," (itoa min1)) file2)
       ) ;_ while
       (close file1)
       (close file2)
       (princ
         (strcat "Process took "
                 (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                 " seconds."
         ) ;_ strcat
       ) ;_ princ
     ) ;_ progn
  ) ;_ if
  (princ)
) ;_ defun
(defun c:minmax (/ #HI #LOW F1 L1 LINEM NEWFILE TIMER)
  ;;(c:minmax)
  ;; Andrea
  (setq timer (getvar "millisecs"))
  (setq f1 (open "D:\\numbers.csv"
                 "r"
           ) ;_ open
        l1 (read-line f1)
  ) ;_ setq
  (if l1
    (setq newfile (open "D:\\result.txt" "w"))
  ) ;_ if
  (while l1
    (setq lineM (read (strcat "(" (acet-str-replace "," " " l1) ")"))
          #low  (car (vl-sort lineM '<))
          #hi   (car (vl-sort lineM '>))
    ) ;_ setq
    (write-line (strcat (rtos #hi) " " (rtos #low)) newfile)
    (setq l1 (read-line f1))
  ) ;_ while
  (close f1)
  (close newfile)
  (princ
         (strcat "Process took "
                 (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                 " seconds."
         ) ;_ strcat
       )
 
  (princ)
) ;_ defun

(defun c:test (/ FILEBASE FILEDATA FILENAME HANDLE LST PATH STREAM)
  ;; CAB
  ;;(c:test)
  (defun sparser1 (str delim / ptr lst)
    ;;  parser by CAB 
    (while (setq ptr (vl-string-search delim str))
      (setq lst (cons (substr str 1 ptr) lst))
      (setq str (substr str (+ ptr 2)))
    ) ;_ while
    (reverse (cons str lst))
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (if
    (and
      (setq filename "D:\\numbers.csv")
      (setq handle (open filename "r"))
    ) ;_ and
     (progn
       (while (setq stream (read-line handle))
         (setq FileData (cons stream FileData))
       )                                ; while
       (close handle)
     ) ;_ progn
  ) ;_ if
  (if FileData
    (progn
      (setq path     (vl-filename-directory filename)
            filebase (vl-filename-base filename)
            handle   (open (strcat path "\\" filebase "-out.csv") "w")
      ) ;_ setq
      (mapcar
        (function
          (lambda (x)
            (setq lst
                   (mapcar
                     (function
                       (lambda (y)
                         (atoi y)
                       ) ;_ lambda
                     ) ;_ function
                     (sparser1 x ",")
                   ) ;_ mapcar
            ) ;_ setq
            (princ (apply 'max lst) handle)
            (princ "-" handle)
            (princ (apply 'min lst) handle)
            (princ "\n" handle)
          ) ;_ lambda
        ) ;_ function
        FileData
      ) ;_ mapcar
      (close handle)
      (princ
        (strcat "Process took "
                (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                " seconds."
        ) ;_ strcat
      ) ;_ princ
    ) ;_ progn
  ) ;_ if
  (princ)
) ;_ defun


Check:

Code: [Select]
(c:test) ;; CAB
(c:minmax) ;; Andrea
(c:max-min) ;;Jeff_M
(c:test_2) ;; ElpanovEvgeniy
(c:test_1) ;; ElpanovEvgeniy

;
 VLX-Application packed D:/Work/Project/lib/test/test.VLX
_$
Process took 0.83 seconds.
 Process took 1.67 seconds.
 Process took 0.84 seconds.
 Process took 0.469 seconds.
 Process took 0.5 seconds.


check 2
_$
Process took 0.81 seconds.
 Process took 1.66 seconds.
 Process took 0.88 seconds.
 Process took 0.469 seconds.
 Process took 0.5 seconds.
 
check 3
_$
Process took 0.83 seconds.
 Process took 1.64 seconds.
 Process took 0.88 seconds.
 Process took 0.453 seconds.
 Process took 0.5 seconds.
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 02, 2006, 07:39:11 AM
Evgeniy,
Very fast, I see that vl-string-translate makes a huge deference.
Thanks  :-)

I revised mine & cut the time here in half.

Code: [Select]
;;  CAB Revised
(defun c:test2 (/ FILEBASE FILEDATA FILENAME HANDLE LST PATH STREAM
               sparser)
  (setq timer (getvar "millisecs"))

  (if
    (and
      (setq filename (findfile "numbers.csv"))
      (setq handle (open filename "r"))
    )
     (progn
       (while (setq stream (read-line handle))
         (setq FileData (cons stream FileData))
       ) ; while
       (close handle)
     )
  )

  (if FileData
    (progn
      (setq path     (vl-filename-directory filename)
            filebase (vl-filename-base filename)
            handle   (open (strcat path "\\" filebase "-out.csv") "w")
      )
      (mapcar
        (function
          (lambda (x)
            (setq lst (read (strcat "(" (vl-string-translate "," " " x) ")")))
            (princ (apply 'max lst) handle)
            (princ "-" handle)
            (princ (apply 'min lst) handle)
            (princ "\n" handle)
          )
        )
        FileData
      )
      (close handle)
      (princ (strcat "Process took "
                     (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2)
                     " seconds."
             )
      )

    )
  )

  (princ)
)
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 02, 2006, 07:53:26 AM
Evgeniy,
Looking more at your routine I suspect the recursive min_max may be faster than
(apply 'max lst) but I haven't tested that. 8-)
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 02, 2006, 08:03:03 AM

 :-)
Code: [Select]
(c:test2) ;; CAB Revised
(c:test) ;; CAB
(c:minmax) ;; Andrea
(c:max-min) ;;Jeff_M
(c:test_2) ;; ElpanovEvgeniy
(c:test_1) ;; ElpanovEvgeniy

;
 VLX-Application packed D:/Work/Project/lib/test/test.VLX
 
_$
Process took 0.44 seconds.
 Process took 0.86 seconds.
 Process took 1.81 seconds.
 Process took 0.8 seconds.
 Process took 0.469 seconds.
 Process took 0.5 seconds.
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 02, 2006, 08:13:52 AM
Thanks you Sir.
My test were similar, relatively speaking.
Your fastest version I suspect must be that you simulated the APPLY MIN MAX with your
faster code. Very nice! :-)
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 02, 2006, 08:42:23 AM
new version...
 :-)
Code: [Select]
(defun c:test_3 (/ f f1 timer)
  ;;(c:test_2)
  ;; ElpanovEvgeniy
  (defun pars (s f)
    (if s
      (cons (read (strcat "(" (VL-STRING-TRANSLATE "," " " s) ")"))
            (pars (read-line f) f)
      ) ;_ cons
      (close f)
    ) ;_ if
  ) ;_ defun
  (defun min_max (mi ma l f)
    (if l
      (if (< (car l) mi)
        (min_max (car l) ma (cdr l) f)
        (if (> (car l) ma)
          (min_max mi (car l) (cdr l) f)
          (min_max mi ma (cdr l) f)
        ) ;_ if
      ) ;_ if
      (strcat (itoa mi) " " (itoa ma) "\n")
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (setq f1 (open "D:\\numbers.csv" "R"))
  (setq f (open "D:\\result.csv" "W"))
  (princ
    (apply
      (function strcat)
      (mapcar
        (function
          (lambda (l)
            (if (< (car l) (cadr l))
              (min_max (car l) (cadr l) (cddr l) f)
              (min_max (cadr l) (car l) (cddr l) f)
            ) ;_ if
          ) ;_ lambda
        ) ;_ function
        (pars (read-line f1) f1)
      ) ;_ mapcar
    ) ;_ apply
    f
  ) ;_ princ
  (close f)
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
) ;_ defun

Check:

Code: [Select]
(c:test2) ;; CAB Revised
(c:test_2) ;; ElpanovEvgeniy
(c:test_3) ;; ElpanovEvgeniy

;
 VLX-Application packed D:/Work/Project/lib/test/test.VLX
 
_$
Process took 0.47 seconds.
 Process took 0.5 seconds.
 Process took 0.406 seconds.
Title: Re: ( Challenge ) Just curious
Post by: Mark on December 02, 2006, 08:50:21 AM
You guys never fail to amaze me! :-)
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 02, 2006, 09:02:16 AM
Evgeniy you're about the break the 'Sound Barrier'  8-)
Title: Re: ( Challenge ) Just curious
Post by: Andrea on December 02, 2006, 09:08:12 AM
wOo !...

i'm the slowest... ^-^

do i win something ?... :-D
Title: Re: ( Challenge ) Just curious
Post by: Andrea on December 02, 2006, 09:55:06 AM
ok....i've made some modification..


Code: [Select]
(defun c:minmax (/ timer f1 l1 lst #low #hi newfile)
(setq f1 (open (getfiled "Please select your file..." "" "csv" 8) "r")
      l1 (read-line f1))
  (setq timer (getvar "millisecs"))

(if l1 (setq newfile (open "c:\\result.txt" "w")))
(while l1
(setq lst (vl-sort (read (strcat "(" (acet-str-replace "," " "  l1) ")")) '<))
  (setq #hi (last lst)
        #low (car lst))
(write-line (strcat (rtos #hi) " " (rtos #low)) newfile)
(setq l1 (read-line f1)))

(close f1)
(close newfile)
 (princ (strcat "Process took " (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2) " seconds."))
)
 
Title: Re: ( Challenge ) Just curious
Post by: Andrea on December 02, 2006, 10:04:51 AM
or...much better....


Code: [Select]
(defun c:minmax (/ timer f1 l1 lst #low #hi newfile)
(setq f1 (open (getfiled "Please select your file..." "" "csv" 8) "r")
      l1 (read-line f1))
 

(if l1 (setq newfile (open "c:\\result.txt" "w")))
(while l1
(setq lst (vl-sort (read (strcat "(" (acet-str-replace "," " "  l1) ")")) '<))
  (setq #hi (last lst)
        #low (car lst))
(write-line (strcat (rtos #hi) " " (rtos #low)) newfile)
(setq l1 (read-line f1)))
(setq timer (getvar "millisecs"))
(command "_delay" "10")
(close f1)
(close newfile)
 (princ (strcat "Process took " (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 2) " seconds."))
 )

LOL   :lmao:
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 02, 2006, 10:07:55 AM
(command "_delay" "10")

 :-D
Title: Re: ( Challenge ) Just curious
Post by: Mark on December 02, 2006, 10:14:39 AM
OK guys, I posted a new challenge [ http://www.theswamp.org/index.php?topic=13771.0 ], please post your code in that thread OK! :-)
Title: Re: ( Challenge ) Just curious
Post by: Joe Burke on December 02, 2006, 10:46:09 AM
Personally the word "challenge" will always turn me off immediately.

Why turn programming into a game show? It reminds me of the TV Food Network,
which was nice back when it was mostly about cooking rather than, "and the
winner is..."

These things could be presented as collaborative work. IOW, it's not a
competition, but rather a joint effort aimed at sharing knowledge. Which I
think is what this place is about. Right, Mark?

(setq str idea)
(if
  (or
    (eq str "winner")
    (eq str "loser")
  )
  (princ "\nBoring!")
  (princ "\nLet's kick it around.")
)
Title: Re: ( Challenge ) Just curious
Post by: Mark on December 02, 2006, 11:17:20 AM
Personally the word "challenge" will always turn me off immediately.
OK, what would you prefer?

Quote
These things could be presented as collaborative work. IOW, it's not a
competition, but rather a joint effort aimed at sharing knowledge. Which I
think is what this place is about. Right, Mark?
Well the last time I posted a collaborative project I was accused of using this forum and the members knowledge as a way of getting my work done, which of course I would never do. Being accused of that hurt my feelings, to say the least.

Perhaps "challenge" is the wrong word. I do feel we, the members, learn quite a lot from seeing the unique solutions of the others. Plus it gives us a way of showcasing our talent. So yes, sharing knowledge is what this place is all about.
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 02, 2006, 11:36:58 AM
Joe,
I like a "Challenge" & you don't have to make it a competition with others but
with yourself. It seems to be a "human nature" thing that turns the Challenge
into a "Competition". Although the competition usually focuses on speed, I see
it take on other goals as well. Mostly I see "Shortest number of lines" or
"Cleverest methods" but seldom do I see "Most Readable" or "Easiest to
maintain".

In a competition for the fastest we (I) discover methods or functions I did not
consider. For me, I think I learn something in each one of the "Challenges" and
it may not seem as though the aim was at sharing knowledge but knowledge was
shared none the less. As you pointed out they do turn into competitions rather
than collaborations.  I have seen times when "speed goals" do produce a
collaborate routine to get the best results.

It's tough to overcome human nature though.
Title: Re: ( Challenge ) Just curious
Post by: Joe Burke on December 02, 2006, 11:49:52 AM
Mark,

The downside of backing off from what you think is right, is it tends to lend
support to those who accused you.

And BTW, what's wrong with using this forum as a way of getting your work done?
Who said that's not allowed? Or you shouldn't do that?

The more I read here, the more I don't understand.

What I want is an open ended forum where ideas flow freely without artificial constraints.

A "challenge" is an artifact by definition IMO.

Regards
Joe
Title: Re: ( Challenge ) Just curious
Post by: Joe Burke on December 02, 2006, 12:44:51 PM
It's tough to overcome human nature though.

I don't accept the idea human nature is defined by competition, as you seem to imply. I think you are confusing evolution with what actually defines us as a species. Learning to cooperate with each other is primarily what sets us apart from all other species on the planet.

IOW, we demean ourselves when we let the primitive stuff kick in.

Excuses along the lines of, "tough to overcome" fall on deaf ears as far as I'm concerned. What I hear is just old nonsense applied to the web. The greateat tool yet invented aimed at cooperation.

Regards
Title: Re: ( Challenge ) Just curious
Post by: JohnK on December 02, 2006, 12:58:55 PM
Pure semantics; the ``Taste'' of theSwamp has always been ``help'' over ``flame''. Everyone knows that when you participate in a `challange' you are entering the classroom where everyone is a teacher. The whole idea behind the ``challanges'' i was seeking when i created them was to promote fun with learning. The concept was to promote creative thinking --take this ``simple'' task and make it better, faster, cleaner, funny, difficult, whatever you want.

The whole goal was to show everyone the bounds of the common computer process--believie it or not a programing language is only a gateway, logic is logic.


Title: Re: ( Challenge ) Just curious
Post by: Joe Burke on December 02, 2006, 01:20:34 PM
It's not a matter of semantics given I saw a message from Luis recently which said something like, "someone should judge the entries and declare a winner."

Ya'll may choose to distance yourselves from this nonsense. So be it.

All I'm interested in is an end to it.

Please know I'm not flaming here or accusing anyone of anything. I just think we could do better than what we've done.
Title: Re: ( Challenge ) Just curious
Post by: LE on December 02, 2006, 01:32:54 PM
I see a name like mine....   :roll:

and I remember posting something like that, and was more about that if someone start something - to me I want to see an end point a conclusion.

in my own case, when I like to participate it is first, to show my way of solving a problem, second because I do not have anything else to do and I prefer to waste my time in something that can keep my mind occupied, the only 2 brain cells left - required a lot of effort nowdays, third the part of seeing a winner was in a sarcastic form of saying "hey where is this topic going - or?"

and yes mi amigo Jose I agree with you.

 :-)
Title: Re: ( Challenge ) Just curious
Post by: Joe Burke on December 02, 2006, 01:57:12 PM
Luis,

Your two remaining brain cells still work better than whatever I have left.  ;-)

And BTW, I quoted you because I assumed you agreed with me. I read it, back when, as something similar to my point now.
Title: Re: ( Challenge ) Just curious
Post by: Chuck Gabriel on December 02, 2006, 02:11:46 PM
I've always looked at the challenges as an opportunity to stretch my mind a little and see the various ways different folks approach the same problem.  There is usually a little good-natured competition, but I've never seen a challenge degenerate into anything ugly.

In summary, I think they are great.
Title: Re: ( Challenge ) Just curious
Post by: JohnK on December 02, 2006, 04:18:08 PM
It's not a matter of semantics given I saw a message from Luis recently which said something like, "someone should judge the entries and declare a winner."

Ya'll may choose to distance yourselves from this nonsense. So be it.

All I'm interested in is an end to it.

Please know I'm not flaming here or accusing anyone of anything. I just think we could do better than what we've done.

And i have seen many a post from people that say ``challenge'' but sound suspiciously like actual work or actual needs (``phishing'' if you will). Well, wait a min; i came up the first challenge by taking something from actual work i was doing at the time. Now i guess it was alright, because i had already written my solution, and it was a ``trivial'' process to begin with. ...

I understand your feelings and I'm not saying that YOU were flaming anyone or anything... I was just making a blanket statement. I guess what i was trying to say is: when you offer help, should you feel the need to be gratified beyond a ``thanx dude''? Then theswamp isn't for you. We are a friendly bunch who LIKE to help for the sake of help not fame and glory. But you already know that, that's why your here....get it? (I don't know if that is gonna make any more sense or not, but I'm sure you know what I'm trying to say.)

And end to what? The Challenges or the World? (What is `it' --and don't try to tell me the answer can be found on eBay either....gawd i hate those stupid commercials.)

If you dont like the challenges, then i guess make a complant to the mods and or just dont participate it-sup to you dude.

BTW, did you read Cornbread's challenge. That was ama-az-zing!!
Title: Re: ( Challenge ) Just curious
Post by: Arizona on December 02, 2006, 05:17:49 PM
Personally the word "challenge" will always turn me off immediately.
Thanks for sharing such personal information regarding yourself.
I guess I was under the misconception that most men liked competition and challenges. I appreciate your honesty in helping me correct this misconception.

Why turn programming into a game show? It reminds me of the TV Food Network,
which was nice back when it was mostly about cooking rather than, "and the
winner is..."

While both programming and cooking can be fun, I fail to understand where you see any other similarities with game shows. Perhaps you could explain to me, what the common factor is?


These things could be presented as collaborative work. IOW, it's not a
competition, but rather a joint effort aimed at sharing knowledge. Which I
think is what this place is about. Right, Mark?
 
Speaking of semantics…



Mark,
The downside of backing off from what you think is right, is it tends to lend
support to those who accused you.

Certainly not by anyone that knows him and is a part of the community. This seems a little like the thief accusing the homeowner for not having what he would like to steal.

And BTW, what's wrong with using this forum as a way of getting your work done?
Who said that's not allowed? Or you shouldn't do that?
I would believe that if you consistently used others work to get your work done (i.e. profited financially) this would classify as unethical.
While there is nothing wrong with generating new ideas and getting people to think creatively, and/or using snippets of code that others freely give, taking code for financial gain would just be wrong!

The more I read here, the more I don't understand.
What I want is an open ended forum where ideas flow freely without artificial constraints.
A "challenge" is an artifact by definition IMO.
Maybe you want to try:
Autodesk forums - an open ended forum where ideas flow freely without artificial constraints. Nope
AUGI - an open ended forum where ideas flow freely without artificial constraints. Nope
Or your own forum- an open ended forum where  (your own) ideas flow freely without artificial constraints.

It's not a matter of semantics given I saw a message from Luis recently which said something like, "someone should judge the entries and declare a winner."

Ya'll may choose to distance yourselves from this nonsense. So be it.

All I'm interested in is an end to it.

Please know I'm not flaming here or accusing anyone of anything. I just think we could do better than what we've done.

<said with a real Southern accent>Y’all just haven’t a clue about such nonsense…semantics, rubbish!<end real Southern accent>
If you were really interested in ending it you would never have continued in such a “challenging” manner. And yes, I’m sure we could all do better, but remember that starts with you, the individual, first.
Title: Re: ( Challenge ) Just curious
Post by: Kerry on December 02, 2006, 05:26:58 PM
It IS all semantics I think.  ... but I know it has caused blood to be spilled in other places.
'Challenge' has connotations of personal battle, but also of personal stimulation derived from overcoming a situation.

I personally prefer the word 'Problem', 'cause that's how I look at all my programming 'Challenges'
.... a problem to be solved.
Sometimes the solution requires speed, sometimes security, or other criteria,
sometimes all are required.

Elegance, brevity, clever use of a language construct are all to be admired, but the core of the evaluation will always be ;
"does this solve my problem"



I think the best challenge is :
"this is the answer you want , please define the problem ... "  but perhaps that's just me ...

/// kwb


editted: t is nowwhere near p on the keyboard, so I can't blame fat fingers ...
Title: Re: ( Challenge ) Just curious
Post by: Jeff_M on December 02, 2006, 05:36:35 PM
Joe, while I do appreciate your valuable input here, I just don't see how you can take this as anything but what it's intended to be. From Answers.com the definition of Challenge is:Note the last one, this, IMHO, is the intended meaning for any challenge posted to theSwamp. I'm at a loss for any other single word that could be used in place of challenge.

Further, my old math teacher in High School used this same format to get us to go beyond the everyday classwork. He'd post a challenge to the class every Monday and it was up to the individual student whether they would participate, or not. Those that did earned extra credit and those that turned in a working solution (there were usually multiple ways to solve) received even more credit.....but NO ONE ever knew how much credit the other student(s) received. It was fun to participate in these, just as I find it fun to participate here.

Yes, I kidded Tim about mine (that I didn't post) being faster than his, but that's all it was ..... kidding around and having fun. In the mean time, we have all learned something that we didn't know last week. If I had even a small perception that these were contests with winners & losers declared I probably wouldn't even read the thread, much less participate in it.

Jeff
Title: Re: ( Challenge ) Just curious
Post by: LE on December 02, 2006, 05:57:21 PM
Quote
were contests

In any form they are.

Quote
with winners & losers

That, to me can be translated into "Conclusions"

It is true that not always one would expect to wait for an answer to whatever one end up posting, many reasons language barrier, lack of interest, being busy, etc.

If there are not any conclusions one end up getting bored and might not participate in the next one.
Title: Re: ( Challenge ) Just curious
Post by: Chuck Gabriel on December 02, 2006, 06:27:41 PM
I think the participants each draw their own conclusions.
Title: Re: ( Challenge ) Just curious
Post by: LE on December 02, 2006, 06:41:51 PM
I think the participants each draw their own conclusions.

See language barrier case 101.

I agree.

-------------
Yo me refiero a que las conclusiones es la parte en donde gana o pierde el individuo que participa, no importa en que nivel este haya sido a final de cuentas lo importante que se llego a un proposito.

La parte en donde implicitamente comento el que en ocaciones se nota el bajo interes, es solo para hacer notar esa parte, e invitar a que esta sea cada vez mas reducida, simplemente eso, porque si se propone algun nuevo topico, si en este ademas de ser uno excelente, si los demas ven que se refleja interes en el, claro que habra mas participacion.... a eso me refiero escencialmente, sino pues para que uno participa si el interes es bajo... Creo que esa parte es la primordial, para que este foro continue creciendo, mas que nada por la gran mayoria de los excelentes miembros con los que cuenta.

Ven, asi mas facil me explico...   :-)
---------------
Title: Re: ( Challenge ) Just curious
Post by: It's Alive! on December 02, 2006, 09:52:13 PM
Is it a problem to go skydiving or a challenge? Who wins? All who participate and don’t bounce. It’s certainly not who can make it down the fastest haha. The conclusion is having a beer afterwards, well assuming you have won. What’s my point? Let’s all do our programming challenges and drink beer!

Title: Re: ( Challenge ) Just curious
Post by: Keith™ on December 02, 2006, 10:07:38 PM
<homer> mmmmm beer </homer>
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 02:24:49 AM

Probably, all have noticed...
I try to write many variants in reply to call!
Try to guess, why?
I always know, what of variants is better, but I write it is more...
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 04:10:51 AM
Evgeniy you're about the break the 'Sound Barrier'  8-)


Code: [Select]
(defun c:test_4 (/ f f1 timer)
  ;;(c:test_4)
  ;; ElpanovEvgeniy
  (defun pars (s f)
    (if s
      (cons (read (strcat "(" (VL-STRING-TRANSLATE "," " " s) ")"))
            (pars (read-line f) f)
      ) ;_ cons
      (close f)
    ) ;_ if
  ) ;_ defun
  (defun min_max (mi ma l f)
    (if l
      (if (< mi (car l) ma)
          (min_max mi ma (cdr l) f)
        (if (< (car l) mi)
          (min_max (car l) ma (cdr l) f)
          (min_max mi (car l) (cdr l) f)
        ) ;_ if
      ) ;_ if
      (strcat (itoa mi) " " (itoa ma) "\n")
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (setq f1 (open "D:\\numbers.csv" "R"))
  (setq f (open "D:\\result.csv" "W"))
  (princ
    (apply
      (function strcat)
      (mapcar
        (function
          (lambda (l)
            (if (< (car l) (cadr l))
              (min_max (car l) (cadr l) (cddr l) f)
              (min_max (cadr l) (car l) (cddr l) f)
            ) ;_ if
          ) ;_ lambda
        ) ;_ function
        (pars (read-line f1) f1)
      ) ;_ mapcar
    ) ;_ apply
    f
  ) ;_ princ
  (close f)
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
)


Check:

Code: [Select]
(c:test_3) ;; ElpanovEvgeniy
(c:test_4) ;; ElpanovEvgeniy

 VLX-Application packed D:/Work/Project/lib/test/test.VLX
 
_$
Process took 0.375 seconds.
 Process took 0.344 seconds.
Title: Re: ( Challenge ) Just curious
Post by: Joe Burke on December 04, 2006, 10:26:25 AM
Thanks to all who replied.

Sorry, I'm not able to reply to specific issues right now. But I hope the fact we kicked it around will be helpful in some way.

Regards
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 04, 2006, 10:57:59 AM

Probably, all have noticed...
I try to write many variants in reply to call!
Try to guess, why?
I always know, what of variants is better, but I write it is more...
Perhaps to show deferent ways of solving the problem.
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 11:07:17 AM

Probably, all have noticed...
I try to write many variants in reply to call!
Try to guess, why?
I always know, what of variants is better, but I write it is more...
Perhaps to show deferent ways of solving the problem.

Yes. I want to show different variants.
In such subject, I do not see sense to win, in other languages will be faster...
The main thing to share experience!
In this problem slowly, but in another it will be fast.


PS. But I like to show a unusual code :)
Title: Re: ( Challenge ) Just curious
Post by: Arizona on December 04, 2006, 11:14:53 AM
Yes. I want to show different variants.
In such subject, I do not see sense to win, in other languages will be faster...
The main thing to share experience!
In this problem slowly, but in another it will be fast.


PS. But I like to show a unusual code :)

Thanks for doing this!  :-)
It certainly helps me to learn from what you are doing!
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 04, 2006, 11:30:04 AM
Evgeniy
Looking at your Test4, and others I see you reading a line from the file, then processing it before
reading another line. I thought it would be faster to read the entire file into a list & then process
the list. Now that I think about it, I suppose that the disk speed & disk cashing would play a part
in that, as well as how long the data processing took.
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 11:37:20 AM
Evgeniy
Looking at your Test4, and others I see you reading a line from the file, then processing it before
reading another line. I thought it would be faster to read the entire file into a list & then process
the list. Now that I think about it, I suppose that the disk speed & disk cashing would play a part
in that, as well as how long the data processing took.

No..
for Test_4
I all over again read all file, and then it I process MAPCAR...
Code: [Select]
(mapcar
        (function
          (lambda (l)
            (if (< (car l) (cadr l))
              (min_max (car l) (cadr l) (cddr l) f)
              (min_max (cadr l) (car l) (cddr l) f)
            ) ;_ if
          ) ;_ lambda
        ) ;_ function
        (pars (read-line f1) f1)
      ) ;_ mapcar

http://www.theswamp.org/index.php?topic=13771.0
I read and at once I process what to not read all file - he too long....
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 04, 2006, 12:19:37 PM
OK, i see, but I would call that a split process as you do convert the incoming data to a list of numbers
line by line before the mapcar to get min / max.

I tried to test it but my timing varied so I'm not sure of the results.


Code: [Select]
(defun c:test_5 (/ f f1 timer ldata data)
  ;;(c:test_5)
  ;; ElpanovEvgeniy - Modified
  (defun min_max (mi ma l f)
    (if l
      (if (< mi (car l) ma)
        (min_max mi ma (cdr l) f)
        (if (< (car l) mi)
          (min_max (car l) ma (cdr l) f)
          (min_max mi (car l) (cdr l) f)
        ) ;_ if
      ) ;_ if
      (strcat (itoa mi) " " (itoa ma) "\n")
    ) ;_ if
  ) ;_ defun
  (setq timer (getvar "millisecs"))
  (setq f1 (open "c:\\numbers.csv" "R"))
  (while (setq ldata (read-line f1))
    (setq data (cons ldata data))
  )
  (close f1)
  (setq f (open "c:\\result.csv" "W"))
  (princ
    (apply
      (function strcat)
      (mapcar
        (function
          (lambda (l)
            (setq l (read (strcat "(" (vl-string-translate "," " " l) ")")))
            (if (< (car l) (cadr l))
              (min_max (car l) (cadr l) (cddr l) f)
              (min_max (cadr l) (car l) (cddr l) f)
            ) ;_ if
          ) ;_ lambda
        ) ;_ function
        data
      ) ;_ mapcar
    ) ;_ apply
    f
  ) ;_ princ
  (close f)
  (princ
    (strcat
      "Process took "
      (rtos (/ (- (getvar "millisecs") timer) 1000.0) 2 4)
      " seconds."
    ) ;_ strcat
  ) ;_ princ
  (princ)
)
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 12:35:51 PM
OK, i see, but I would call that a split process as you do convert the incoming data to a list of numbers
line by line before the mapcar to get min / max.

I tried to test it but my timing varied so I'm not sure of the results.



At me exact results have failed...
See.



Code: [Select]
(c:test_3) ;; ElpanovEvgeniy
(c:test_4) ;; ElpanovEvgeniy
(c:test_5) ;; CAB - Modified


Process took 0.359 seconds.
 Process took 0.344 seconds.
 Process took 0.375 seconds.
 
_$
Process took 0.36 seconds.
 Process took 0.359 seconds.
 Process took 0.375 seconds.
 
_$
Process took 0.375 seconds.
 Process took 0.36 seconds.
 Process took 0.359 seconds.
 
_$
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 04, 2006, 12:46:50 PM
Yes, I could not get exact results.
My computer :

Command: test_4
Process took 0.7810 seconds.
TEST_4 Process took 0.7710 seconds.
TEST_4 Process took 0.7810 seconds.
TEST_4 Process took 0.7810 seconds.
TEST_4 Process took 0.7810 seconds.
TEST_4 Process took 0.7810 seconds.
TEST_4 Process took 0.7810 seconds.

Command:
Command: test_5
Process took 0.7410 seconds.
TEST_5 Process took 0.7610 seconds.
TEST_5 Process took 0.7910 seconds.
TEST_5 Process took 0.7510 seconds.
TEST_5 Process took 0.7810 seconds.
TEST_5 Process took 0.7910 seconds.
TEST_5 Process took 0.7510 seconds.

test 4 had steady results while the test 5 varied. Not sure why.
But there seems to be no real advantage in doing it with the WHILE in test5.
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 04, 2006, 01:29:19 PM
Here is mine based off what you two (Evgeniy and Alan) are doing.  I didn't think it would be that much of a difference, but it is.  Thanks for the showing.
Code: [Select]
(defun c:HiLow (/ File Opened TextLine TextList NumList Timer NewOpened NewFile MinNum MaxNum Num Pos StPos Str)

(if
 (and
;  (setq File (getfiled "" "" "csv" 4))
  (setq Timer (StartTimer))
  (setq Opened (open "c:/test/numbers.csv" "r"))
  (setq NewOpened (open "c:/test/results.csv" "w"))
;  (setq Opened (open File "r"))
;  (setq NewFile (strcat (vl-filename-directory File) "\\Returned.csv"))
;  (setq NewOpened (open NewFile "w"))
 )
 (progn
  (while (setq TextLine (read-line Opened))
   (function
    (lambda (/ MinNum MaxNum)
     (setq cnt 0)
     (mapcar
      '(lambda (x / Num)
       (if (or (not MinNum) (> MinNum Num))
        (setq MinNum Num)
       )
       (if (or (not MaxNum) (< MaxNum Num))
        (setq MaxNum Num)
       )
      )
      (read (strcat "(" (vl-string-translate "," " " TextLine) ")"))
     )
     (princ (strcat (itoa MinNum) "," (itoa MaxNum) NewOpened))
    )
   )
  )
  (close Opened)
  (close NewOpened)
  (prompt (EndTimer Timer))
 )
)
(princ)
)
Quote
Command: hilow

 Elasped time 0.016000 seconds.
Command:
Command: hilow

 Elasped time 0.047000 seconds.
Command:
Command:
HILOW
 Elasped time 0.016000 seconds.
Command:
Command:
HILOW
 Elasped time 0.016000 seconds.
Command:
Command:
HILOW
 Elasped time 0.031000 seconds.
Command:
Command:
HILOW
 Elasped time 0.031000 seconds.
Command:
Command:
HILOW
 Elasped time 0.015000 seconds.
Command:
Command:
HILOW
 Elasped time 0.047000 seconds.
Command:
Title: Re: ( Challenge ) Just curious
Post by: CAB on December 04, 2006, 01:49:34 PM
Tim,
The Results.csv is empty. :-)
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 04, 2006, 02:35:35 PM
Tim,
The Results.csv is empty. :-)
Stupid parenthesis!!!  Here is one that works.
Code: [Select]
(defun c:HiLow (/ Opened TextLine Timer NewOpened MinNum MaxNum Num)

(if
 (and
  (setq Timer (StartTimer))
  (setq Opened (open "c:/test/numbers.csv" "r"))
  (setq NewOpened (open "c:/test/results.csv" "w"))
 )
 (progn
  (while (setq TextLine (read-line Opened))
   (
    (lambda (/ MinNum MaxNum)
     (mapcar
      '(lambda (Num)
       (if (or (not MinNum) (> MinNum Num))
        (setq MinNum Num)
       )
       (if (or (not MaxNum) (< MaxNum Num))
        (setq MaxNum Num)
       )
      )
      (read (strcat "(" (vl-string-translate "," " " TextLine) ")"))
     )
     (princ (strcat (itoa MinNum) "," (itoa MaxNum) "\n") NewOpened)
    )
   )
  )
  (close Opened)
  (close NewOpened)
  (prompt (EndTimer Timer))
 )
)
(princ)
)
Not as fast as your guys stuff, but still a lot faster than my other one, here are the times.
Quote
Command: hilow

 Elasped time 0.578000 seconds.
Command:
Command:
HILOW
 Elasped time 0.594000 seconds.
Command:
Command:
HILOW
 Elasped time 0.609000 seconds.
Command:
Command:
HILOW
 Elasped time 0.609000 seconds.
Command:
Command:
HILOW
 Elasped time 0.594000 seconds.
Command:
Command:
HILOW
 Elasped time 0.609000 seconds.

Side note: 'princ'ing to a file , with adding a new line to the string, is faster than useing 'write-line' to the file.  It shaved off about 1/10 sec.
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 02:45:31 PM

Not as fast as your guys stuff, but still a lot faster than my other one, here are the times.


It is not known, for whom works faster...  :-)
Try to look, it is what is the time fulfilled TEST_4 on your computer then it will be possible to compare!

Speed for all different

CAB
TEST_4 = 0.7710 seconds
ElpanovEvgeniy (work)
TEST_4 = 0.344 seconds.
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 04, 2006, 02:51:36 PM
Evgeniy - test_4
Quote
Command: test_4
Process took 0.4370 seconds.

Command:
Command:
TEST_4 Process took 0.4070 seconds.

Command:
Command:
TEST_4 Process took 0.4060 seconds.

Command:
Command:
TEST_4 Process took 0.3750 seconds.

Command:
TEST_4 Process took 0.4060 seconds.

Command:
Command:
TEST_4 Process took 0.4380 seconds.

Alan - test_5
Quote
Command: test_5
Process took 0.4220 seconds.

Command:
Command:
TEST_5 Process took 0.4530 seconds.

Command:
Command:
TEST_5 Process took 0.4530 seconds.

Command:
Command:
TEST_5 Process took 0.4690 seconds.

Command:
Command:
TEST_5 Process took 0.4220 seconds.

Mine - hilow
Quote
Command: hilow

 Elasped time 0.594000 seconds.
Command:
Command:
HILOW
 Elasped time 0.594000 seconds.
Command:
Command:
HILOW
 Elasped time 0.609000 seconds.
Command:
Command:
HILOW
 Elasped time 0.562000 seconds.
Command:
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 02:58:34 PM
Evgeniy   - test_4
CAB        - test_5
T.Willey   - hilow

I think, our score identical...
Drawn game? :-)
Title: Re: ( Challenge ) Just curious
Post by: T.Willey on December 04, 2006, 03:12:42 PM
In my book you would win.  My was over two seconds first, only after I copied your routine (to help me understand it) did my time come down to yours.  Thanks for the lesson Evgeniy, I learned something new!!  This has been fun.
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 03:16:23 PM

In my book.......


You write the book?
Title: Re: ( Challenge ) Just curious
Post by: LE on December 04, 2006, 03:22:53 PM

In my book.......


You write the book?


Evgeniy;

Это - способ сказать на английском языке, что Вы очень шикарны
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 03:29:18 PM

Evgeniy;

Это - способ сказать на английском языке, что Вы очень шикарны


Luis, you do not cease to surprise me!
You know Russian? (I do not trust, that the previous message has been translated by the program)
Title: Re: ( Challenge ) Just curious
Post by: ElpanovEvgeniy on December 04, 2006, 03:31:45 PM
In my book you would win.  My was over two seconds first, only after I copied your routine (to help me understand it) did my time come down to yours.  Thanks for the lesson Evgeniy, I learned something new!!  This has been fun.

Thanks!
To me it is very pleasant  :-)
Title: Re: ( Challenge ) Just curious
Post by: LE on December 04, 2006, 03:54:23 PM

Evgeniy;

Это - способ сказать на английском языке, что Вы очень шикарны


Luis, you do not cease to surprise me!
You know Russian? (I do not trust, that the previous message has been translated by the program)

 :-)

I know few words now... I asked my nephew to do the translation for me...
Title: Re: ( Challenge ) Just curious
Post by: Didge on December 06, 2006, 02:32:26 AM
I'm no "Master" either, this little snippet averaged 1.06 seconds on my home PC.
If I wasn't so lazy I would've combined the two functions into something a touch more efficient.

Surprisingly this same code took 1.28 seconds on an identically spec'd PC.

Code: [Select]
(defun c:MIN-MAX (/ IN-FILE OUT-FILE LST)
  (setq IN-FILE (open (getfiled "Select Source File" "" "csv" 0) "r")
       OUT-FILE (open (getfiled "Save Results to"    "" "csv" 1) "w")
          START (getvar "DATE"))
  (while (setq LINE (read-line IN-FILE))
    (setq LST (strlst-intlst (csv-2-list "," LINE)))
    (write-line (strcat (rtos (apply 'min LST)) " " (rtos (apply 'max LST))) OUT-FILE)
  )
  (close IN-FILE)
  (close OUT-FILE)
  (princ (strcat "\nElapsed time: " (rtos (* 86400.0 (- (getvar "date") START)) 2 2) " secs."))
)
(defun CSV-2-LIST (delim str1 / x)
  (if (atom str1)(setq x delim)(setq x (cadr str1) str1 (car str1)))
  (while (not (eq str1 (setq str1 (vl-string-subst "\" \"" x str1)))))
  (setq STR (read (strcat "(\"" str1 "\")")))
)
(defun STRLST-INTLST (lst / )
  (setq return (list))
  (foreach STR LST
    (setq return (append return (list (atof STR))))
  )
)
Title: Re: ( Challenge ) Just curious
Post by: Cathy on December 06, 2006, 04:48:36 PM
Well the last time I posted a collaborative project I was accused of using this forum and the members knowledge as a way of getting my work done, which of course I would never do. Being accused of that hurt my feelings, to say the least.

Mark, I am so sorry!  I certainly never meant to be mean, malicious, or to hurt your feelings when I mentioned Tom Sawyer in that thread.  I should know by this time that I should never try to be humorous. 

I had actually intended on participating in that project, but then suddenly things got busy here and I didn't have the time.  I have certainly enjoyed the recent challenges though, and appreciate your doing them. 

Please accept my apology.   
Title: Re: ( Challenge ) Just curious
Post by: Mark on December 06, 2006, 05:20:13 PM
Well the last time I posted a collaborative project I was accused of using this forum and the members knowledge as a way of getting my work done, which of course I would never do. Being accused of that hurt my feelings, to say the least.

Mark, I am so sorry!  I certainly never meant to be mean, malicious, or to hurt your feelings when I mentioned Tom Sawyer in that thread.  I should know by this time that I should never try to be humorous. 

I had actually intended on participating in that project, but then suddenly things got busy here and I didn't have the time.  I have certainly enjoyed the recent challenges though, and appreciate your doing them. 

Please accept my apology.   

Apology accepted.

Thanks Cathy, I feel all warm and cozy now. :-)