Author Topic: list comparison  (Read 10831 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: list comparison
« Reply #15 on: July 07, 2005, 05:59:22 PM »
Quote from: daron
I want to compare these lists to return t or nil if either number in the first list is = to any number in the second list.


I though he just wanted to know if there were any items in the lists that matched.
So at the first match, return a non nil result.

That's the way I read the request.
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.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
list comparison
« Reply #16 on: July 07, 2005, 06:30:09 PM »
Quote from: MP
 ......... BTW, does LE = Luis Esquivel?


That sure looks like something Luis would post :)
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

LE

  • Guest
list comparison
« Reply #17 on: July 07, 2005, 10:38:02 PM »
Yes;

Is me.... whatever is left :)

daron

  • Guest
list comparison
« Reply #18 on: July 08, 2005, 07:43:23 AM »
What MP gave worked perfectly. I'm sure what LE gave and CAB would work as well, since if you get a return it works in a cond statement and if there aren't any matches, you'd return nil.

Yes, all I wanted was to see if one list contained a value equal to that in another list. Didn't really care about the output as long as cond could translate it to the desired results. Sorry for not being more clear. Heh, lack of clarity brings on some really interesting results and about 100 different ways to skin the same cat. Thanks for all your efforts. Hopefully, I'll be able to glean the knowledge contained therein.

BTW, welcome Luis Esquivel. What brings you about these parts, if you don't mind me asking?

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
list comparison
« Reply #19 on: July 08, 2005, 08:57:02 AM »
Hey i didnt know we were making a challange outa this?! ...Hold on a sec.


***
Okay im back.

Matt Stachoni once waxed my butt with a nifty lil app kinda along these lines. So... Im gonna take the "Matt route" on this one and hopefully wax someones butt. *gack* Okay that didnt sound so good?! But you know what i mean! *click* What dahell did you just say?!

Darn, i cant find his code, but i think i re-created it. (I'll look for it later)

Code: [Select]
(defun rip-n-flip (lm lc / l-m cntr)
  (setq cntr (length lc) l-m (mapcar 'list lm))
  (while (> cntr -1)
    (setq l-m (subst nil (list (nth cntr lc)) l-m))
    (setq cntr (1- cntr))
    (apply 'append l-m)
  )
)


[] (setq li-m '(1 2 3 4 5 6 7 8 9 0) li-c '(1 2 5))
[] (rip-n-flip li-m li-c)
>> (3 4 6 7 8 9 0)
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
list comparison
« Reply #20 on: July 08, 2005, 09:27:28 AM »
I believe >this< is what you were looking for.

Nice app., but I think it's doing the opposite of what I was looking for. Yours seems to return the items that are unique to both lists. Certainly usable in a different situation.

JohnK

  • Administrator
  • Seagull
  • Posts: 10605
list comparison
« Reply #21 on: July 08, 2005, 09:42:53 AM »
yeah, that's it. That lil peice of code floored me. *Thinking at the time: WOW, its so simple, so clean, so efficient! Awesome!*

yes Daron, thats the point.

Code: [Select]
[] (setq li-m '(1 2 3 4 5 6 7 8 9 0) li-c '(1 2 5))
;; set up

[] (setq test (rip-n-flip li-m li-c))
;; which will return: (3 4 6 7 8 9 0)

(cond
  ((eq (length test) (length li-m))
   "*ERROR* No matches found!")
  ((< (length test) (length li-m))
   "Matches found, I can now process the information..."))
;; test the results to see if a match was found.


This would be good for several reasons.
1. You can test to see if there are matches.
2. Ultimatily you can see all the matches and the remaining.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

whdjr

  • Guest
list comparison
« Reply #22 on: July 08, 2005, 10:28:02 AM »
Here's another link to some more lists talks we've had recently.

daron

  • Guest
list comparison
« Reply #23 on: July 08, 2005, 11:02:48 AM »
Well, offerings abound. Thanks.

LE

  • Guest
list comparison
« Reply #24 on: July 08, 2005, 11:06:13 AM »
Quote from: daron

BTW, welcome Luis Esquivel. What brings you about these parts, if you don't mind me asking?


Thank you,

Just want it to share whatever I can of what I know about customization and whenever is possible.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #25 on: July 08, 2005, 11:24:55 AM »
Welcome Louis.
Glad to have aboard.
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.

daron

  • Guest
list comparison
« Reply #26 on: July 11, 2005, 10:59:53 AM »
Quote from: Se7en
...
Code: [Select]
(defun rip-n-flip (lm lc / l-m cntr)
  (setq cntr (length lc) l-m (mapcar 'list lm))
  (while (> cntr -1)
    (setq l-m (subst nil (list (nth cntr lc)) l-m))
    (setq cntr (1- cntr))
    (apply 'append l-m)
  )
)


[] (setq li-m '(1 2 3 4 5 6 7 8 9 0) li-c '(1 2 5))
[] (rip-n-flip li-m li-c)
>> (3 4 6 7 8 9 0)

John, I've been studying this piece this morning and found a couple of things that might be needed. First item and this is a small item. Please tell me if I'm off my rocker here, but the way you're starting your counter off, starts you one above the nth value of the list. Wouldn't it make sense to start 1- the length of the list? This way the procedure doesn't have to process more than necessary. As well, instead of (apply 'append l-m) within each run of while, wouldn't it make sense to slap that down one time after you have a list with all your nil's in it? It just seems to me that it would speed up execution, not that it's slow or anything. It just seems that it would be cleaner code if it were. I'm sure this was just a slapped together, get us all thinking and learning procedure, but this is just my feedback. Anyway, here's what I did to tidy it up a bit. Just wanted to show the class my work.
Code: [Select]

(defun rip-n-flip (lm lc / l-m cntr)
     (setq cntr (1- (length lc))
  l-m (mapcar 'list lm)
     )
     (while (> cntr -1)
 (setq l-m (subst nil (list (nth cntr lc)) l-m))
 (setq cntr (1- cntr))
     )
 (apply 'append l-m)
)


Of course, I like this code and I'm one who can't leave well enough alone, so...
Code: [Select]
(defun rip-n-flip2 (lm lc / l-m)
     (setq l-m (mapcar 'list lm))
     (foreach item lc
 (setq l-m (subst nil (list item) l-m))
     )
     (apply 'append l-m)
)

To me, that's just easier to understand. Less is more, ya know.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #27 on: July 11, 2005, 11:13:48 AM »
This is the way I'd handle the counter.
Code: [Select]
(defun rip-n-flip (lm lc / l-m cntr)
  (setq cntr (length lc)
        l-m  (mapcar 'list lm)
  )
  (while (> (setq cntr (1- cntr)) -1)
    (setq l-m (subst nil (list (nth cntr lc)) l-m))
  )
  (apply 'append l-m)
)
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.

daron

  • Guest
list comparison
« Reply #28 on: July 11, 2005, 11:26:48 AM »
Not to split hairs here, but I believe that Stig taught a lesson once about proper use and handling of variables and related it to having to go to the store to buy a bag of salt everytime you want to use salt, as opposed to using the salt you already have. Anyway, setting the counter each time the way you have it there CAB is similar to the buying the bag each time you want to use it. Plus, if we have lists, why do we need to worry about counters at all? Wouldn't my second version work faster and read easier than having counters and using while at all?

Anybody have those timers handy and want to run some tests on all these codes?

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #29 on: July 11, 2005, 11:49:12 AM »
I wasn't saying that was the best code for the job. You revised
John's code addressing the counter starting value. I just said
I would handle that particular code in a different way.
As you stated the foreach is easer to read & I agree.

As for "proper use and handling of variables" I haven't a clue what you mean.
Perhaps a link to that thread or further explanation.
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.