Easy as { 1 2 3 }? (when { 1 2 3 } ≠ { 1 2 3 })
07-15-2018, 05:21 PM
Post: #8
 DavidM Senior Member Posts: 853 Joined: Dec 2013
RE: Easy as { 1 2 3 }?
That's nice, Dave!

In this particular case, I believe the "==" steps can all be safely replaced with SAME. SIZE always returns a real, so those comparisons are all ok. The comparison of similarly positioned integers where one is a ROM reference works fine with SAME as well (since at that point they're not being lumped in with the entire list), so the == passed to DOLIST can also be a SAME in this case. SAME is generally faster than ==, so that gives it a boost in speed. Of course, this doesn't apply if the intent is to allow reals and integers to be evaluated as equivalent (ie. 1. == 1). That wasn't my original goal, but it could certainly apply in other situations.

3 of the IFTE clauses can be encapsulated in {} instead of « », which saves a few bytes as well.

Those changes reduce the size of the program from 183.5 to 161 bytes. Checking two lists of 1000 integers takes 18.8 seconds with the original code, and that reduces to 5.1 seconds with the alternate version.

Code:
«   DUP2 SIZE SWAP SIZE OVER SAME   «     0. SAME     { DROP2 1. }     «       2. « SAME » DOLIST       DUP SIZE 1. SAME       { LIST\-> DROP }       « « AND » STREAM »       IFTE     »     IFTE   »   { DROP2 DROP 0. }   IFTE »
 « Next Oldest | Next Newest »

 Messages In This Thread Easy as { 1 2 3 }? (when { 1 2 3 } ≠ { 1 2 3 }) - DavidM - 07-14-2018, 10:52 PM RE: Easy as { 1 2 3 }? - Joe Horn - 07-15-2018, 12:52 AM RE: Easy as { 1 2 3 }? - DavidM - 07-15-2018, 01:41 AM RE: Easy as { 1 2 3 }? - Joe Horn - 07-15-2018, 04:12 AM RE: Easy as { 1 2 3 }? - DavidM - 07-15-2018, 04:52 AM RE: Easy as { 1 2 3 }? - Claudio L. - 07-15-2018, 05:54 PM RE: Easy as { 1 2 3 }? - DavidM - 07-15-2018, 06:07 PM RE: Easy as { 1 2 3 }? - Claudio L. - 07-16-2018, 04:25 AM RE: Easy as { 1 2 3 }? - DavidM - 07-17-2018, 03:05 AM RE: Easy as { 1 2 3 }? - rprosperi - 07-17-2018, 03:26 AM RE: Easy as { 1 2 3 }? - DavidM - 07-17-2018, 03:31 AM RE: Easy as { 1 2 3 }? - Massimo Gnerucci - 07-17-2018, 06:33 AM RE: Easy as { 1 2 3 }? - John Keith - 07-17-2018, 12:32 PM RE: Easy as { 1 2 3 }? - Massimo Gnerucci - 07-17-2018, 02:11 PM RE: Easy as { 1 2 3 }? - John Keith - 07-17-2018, 08:49 PM RE: Easy as { 1 2 3 }? - John Keith - 07-15-2018, 01:01 PM RE: Easy as { 1 2 3 }? - Dave Britten - 07-15-2018, 02:38 PM RE: Easy as { 1 2 3 }? - DavidM - 07-15-2018 05:21 PM RE: Easy as { 1 2 3 }? - Eddie W. Shore - 07-17-2018, 12:43 PM RE: Easy as { 1 2 3 }? - rprosperi - 07-17-2018, 01:06 PM RE: Easy as { 1 2 3 }? - DavidM - 07-17-2018, 01:41 PM RE: Easy as { 1 2 3 }? - John Keith - 07-17-2018, 08:42 PM RE: Easy as { 1 2 3 }? - ttw - 07-17-2018, 04:00 PM RE: Easy as { 1 2 3 }? - BartDB - 07-17-2018, 04:51 PM RE: Easy as { 1 2 3 }? - pier4r - 08-07-2018, 04:07 PM RE: Easy as { 1 2 3 }? (when { 1 2 3 } ≠ { 1 2 3 }) - DavidM - 08-07-2018, 11:40 PM RE: Easy as { 1 2 3 }? (when { 1 2 3 } ≠ { 1 2 3 }) - pier4r - 08-08-2018, 07:06 AM

User(s) browsing this thread: 1 Guest(s)