Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Home
Help
Login
Register
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
=={challenge}==Find k th smallest element
« previous
next »
Print
Pages:
1
[
2
]
All
|
Go Down
Author
Topic: =={challenge}==Find k th smallest element (Read 6077 times)
0 Members and 1 Guest are viewing this topic.
irneb
Water Moccasin
Posts: 1794
ACad R9-2016, Revit Arch 6-2016
WWW
Re: =={challenge}==Find k th smallest element
«
Reply #15 on:
July 10, 2012, 05:10:08 AM »
We're discussing something which is not really of any consequence in this thread. It was me who started it, so I should apologise and start a new thread for that.
Logged
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.
Lee Mac
Seagull
Posts: 12925
London, England
WWW
Re: =={challenge}==Find k th smallest element
«
Reply #16 on:
July 10, 2012, 12:14:31 PM »
My revision of Highflyingbird's method:
Code - Auto/Visual Lisp:
[Select]
(
defun
LM:kth2
(
l k
/
a b x
)
(
if
(
cdr
l
)
(
progn
(
setq
x
(
car
l
)
)
(
foreach
y
(
cdr
l
)
(
if
(
<
x y
)
(
setq
a
(
cons
y a
)
)
(
setq
b
(
cons
y b
)
)
)
)
(
cond
(
(
=
k
(
setq
l
(
length
b
)
)
)
x
)
(
(
<
k l
)
(
LM:kth2 b k
)
)
(
(
LM:kth2 a
(
-
k l
1
)
)
)
)
)
(
car
l
)
)
)
Bench:
Code - Auto/Visual Lisp:
[Select]
_$
(
length
(
repeat
10000
(
setq
lst
(
cons
(
LM:randomrange
0
200
)
lst
)
)
)
)
10000
_$
(
setq
low
0
high
(
length
lst
)
k
(
/
(
length
lst
)
2
)
)
5000
_$
(
benchmark
'
(
(
H:kth lst low high k
)
(
LM:Kth lst k
)
(
LM:Kth2 lst k
)
(
IB:kth
-
smallest
-
r lst k
)
(
IB:kth
-
smallest
-
i lst k
)
)
)
Benchmarking .........Elapsed milliseconds
/
relative speed for
64
iteration
(
s
)
:
(
LM:KTH2 LST K
)
................
1482
/
29.21
<
fastest
>
(
H:KTH LST LOW HIGH K
)
.........
1622
/
26.69
(
LM:KTH LST K
)
.................
3370
/
12.85
(
IB:KTH
-
SMALLEST
-
I LST K
)
.....
27566
/
1.57
(
IB:KTH
-
SMALLEST
-
R LST K
)
.....
43290
/
1.00
<
slowest
>
«
Last Edit: July 10, 2012, 12:24:04 PM by Lee Mac
»
Logged
Lee Mac Programming
•
Twitter
•
Exchange App Store
Print
Pages:
1
[
2
]
All
|
Go Up
« previous
next »
TheSwamp
»
Code Red
»
AutoLISP (Vanilla / Visual)
»
Topic:
=={challenge}==Find k th smallest element