Finding minimum in list
03-22-2017, 04:32 PM (This post was last modified: 03-22-2017 04:32 PM by Han.)
Post: #5
 Han Senior Member Posts: 1,882 Joined: Dec 2013
RE: Finding minimum in list
Here's some code to do a time comparison, should you also need speed in addition to succinctness.

Code:
EXPORT MAKEL0(K) BEGIN   L0:=MAKELIST({IP(RANDOM*10), IP(RANDOM*10)},J,1,K); END; EXPORT MINFIRST1() BEGIN   L1:=MAKELIST(L0(J,1),J,1,SIZE(L0));   R:=MIN(L1);   R:=POS(L1,R);   RETURN(L0(R,2)); END; EXPORT MINFIRST2() BEGIN   L1:=SORT(L0,1);   RETURN(L1(1,2)); END; EXPORT TIMEM() BEGIN   LOCAL T1,T2;   T1:=TEVAL(MINFIRST1());   T2:=TEVAL(MINFIRST2());   RETURN({T1,T2}); END;

Run with TIMEM(<blah>) where <blah> is an integer; you'll need large lists to see any differences in time (which, depending on your project's needs, may or may not realize any significant speed differences).

I'll update with anyone else's code should more be provided.

Graph 3D | QPI | SolveSys
 « Next Oldest | Next Newest »

 Messages In This Thread Finding minimum in list - DrD - 03-22-2017, 03:14 PM RE: Finding minimum in list - Han - 03-22-2017, 03:30 PM RE: Finding minimum in list - DrD - 03-22-2017, 05:29 PM RE: Finding minimum in list - Han - 03-22-2017, 05:42 PM RE: Finding minimum in list - Tyann - 03-23-2017, 05:38 AM RE: Finding minimum in list - DrD - 03-25-2017, 02:25 PM RE: Finding minimum in list - Han - 03-25-2017, 03:10 PM RE: Finding minimum in list - Didier Lachieze - 03-22-2017, 04:06 PM RE: Finding minimum in list - Han - 03-22-2017, 04:11 PM RE: Finding minimum in list - Han - 03-22-2017 04:32 PM RE: Finding minimum in list - DrD - 03-23-2017, 10:18 AM RE: Finding minimum in list - John P - 03-26-2017, 04:11 AM RE: Finding minimum in list - cyrille de brĂ©bisson - 03-28-2017, 10:30 AM RE: Finding minimum in list - DrD - 03-28-2017, 01:52 PM RE: Finding minimum in list - DrD - 03-29-2017, 10:54 AM RE: Finding minimum in list - Didier Lachieze - 03-29-2017, 06:50 PM

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