Author Topic: ( Challenge ) Just curious  (Read 8700 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
( Challenge ) Just curious
« 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
TheSwamp.org  (serving the CAD community since 2003)

T.Willey

  • Needs a day job
  • Posts: 5218
Re: ( Challenge ) Just curious
« Reply #1 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.
« Last Edit: December 01, 2006, 02:46:40 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 3944
  • C3D user & customizer
Re: ( Challenge ) Just curious
« Reply #2 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).

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: ( Challenge ) Just curious
« Reply #3 on: December 01, 2006, 02:59:21 PM »
I didn't realize it was open to all languages.
Me no speak C++
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: ( Challenge ) Just curious
« Reply #4 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.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: ( Challenge ) Just curious
« Reply #5 on: December 01, 2006, 03:12:46 PM »
Jeff that sounds a lot like "My dog ate my home work" .  :lmao:
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: ( Challenge ) Just curious
« Reply #6 on: December 01, 2006, 03:20:56 PM »
Jeff that sounds a lot like "My dog ate my home work" .  :lmao:
x2  :angel:
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 3944
  • C3D user & customizer
Re: ( Challenge ) Just curious
« Reply #7 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)
  )

Jeff_M

  • King Gator
  • Posts: 3944
  • C3D user & customizer
Re: ( Challenge ) Just curious
« Reply #8 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. :|

Mark

  • Custom Title
  • Seagull
  • Posts: 28685
Re: ( Challenge ) Just curious
« Reply #9 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.
TheSwamp.org  (serving the CAD community since 2003)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: ( Challenge ) Just curious
« Reply #10 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))
)
« Last Edit: December 01, 2006, 04:15:12 PM by CAB »
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10365
Re: ( Challenge ) Just curious
« Reply #11 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
I've reached the age where the happy hour is a nap. ()
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5218
Re: ( Challenge ) Just curious
« Reply #12 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.
« Last Edit: December 01, 2006, 04:59:01 PM by T.Willey »
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Jeff_M

  • King Gator
  • Posts: 3944
  • C3D user & customizer
Re: ( Challenge ) Just curious
« Reply #13 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>

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6942
  • AKA Daniel
Re: ( Challenge ) Just curious
« Reply #14 on: December 01, 2006, 05:04:12 PM »
Mark, I think you need to go wakeup those VBA guys too!  :police: