/ avoiding the /: altogether seems like a good idea<o:p></o:p>
q)\ts {(x;l:((,)scan d)m;c:1+m:maxs(d:`u#distinct x)?x)}s<o:p></o:p>
1 3080048<o:p></o:p>
<o:p> </o:p>
Interesting.<o:p></o:p>
<o:p> </o:p>
Normally scan is slow but since the distinct numbers are small <=7 the loop does not slow down the calculation.<o:p></o:p>
<o:p> </o:p>
Kim<o:p></o:p>
<o:p> </o:p>
Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von Attila Vrabecz
Gesendet: Freitag, 30. September 2016 23:53
An: [kdb+] [kdb+]
Betreff: Re: [personal kdb+] function define<o:p></o:p>
<o:p> </o:p>
nice ideas<o:p></o:p>
<o:p> </o:p>
q)\ts:1000 {flips
slsc!enlist[x;m#\:u;]m:1+maxs(u:
u#distinct x)?x}s<o:p></o:p>
1545 263664<o:p></o:p>
<o:p> </o:p>
avoiding the /: altogether seems like a good idea<o:p></o:p>
q)\ts:1000 {(x;l:((,)scan d)m;c:1+m:maxs(d:`u#distinct x)?x)}s<o:p></o:p>
302 329504<o:p></o:p>
<o:p> </o:p>
q)s:10000?-1000?`7<o:p></o:p>
q)\ts {flips
slsc!enlist[x;m#\:u;]m:1+maxs(u:
u#distinct x)?x}s<o:p></o:p>
11 34770144<o:p></o:p>
q)\ts {(x;l:((,)scan d)m;c:1+m:maxs(d:`u#distinct x)?x)}s<o:p></o:p>
1 3080048<o:p></o:p>
<o:p> </o:p>
q)s:100000?-10000?`7<o:p></o:p>
q)\ts {flips
slsc!enlist[x;m#\:u;]m:1+maxs(u:
u#distinct x)?x}s<o:p></o:p>
wsfull (on 32bit)<o:p></o:p>
q)\ts {(x;l:((,)scan d)m;c:1+m:maxs(d:`u#distinct x)?x)}s<o:p></o:p>
60 300920688<o:p></o:p>
<o:p> </o:p>
Cheers,<o:p></o:p>
Attila<o:p></o:p>
On 30 Sep 2016, at 22:05, Kim Tang <kuentang@vodafone.de> wrote:<o:p></o:p>
<o:p> </o:p>
If you are interested in performance here is the result:<o:p></o:p>
<o:p></o:p>
s:10000?a
bc
ca
d`k<o:p></o:p>
<o:p></o:p>
/ this is the worst case<o:p></o:p>
\t:10 {s,‘exec flip sl
sc!flip {(foo;zoo:count foo:distinct x til y)}[s]’[1+i] from (s)} s<o:p></o:p>
2195<o:p></o:p>
<o:p></o:p>
\t:10 {flips
slsc!enlist[x;m#\:u;]m:1+maxs(u:
u#distinct x)?x}s<o:p></o:p>
6<o:p></o:p>
<o:p></o:p>
\t:10 flip s
sl`scs!flip{(last;::;count)@:/:distinct each(1+til count x)#:x}s<o:p></o:p>
981<o:p></o:p>
<o:p></o:p>
\t:10 {(s:x;s2:(distinct@,))}s<o:p></o:p>
41<o:p></o:p>
<o:p></o:p>
\t:10 {[s]update s2:union[s] from (s)}s<o:p></o:p>
33<o:p></o:p>
<o:p></o:p>
Kim<o:p></o:p>
<o:p></o:p>
Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von Terry Lynch
Gesendet: Freitag, 30. September 2016 19:34
An: Kdb+ Personal Developers
Betreff: Re: [personal kdb+] function define<o:p></o:p>
<o:p></o:p>
q)update s2:union[s] from (s)<o:p></o:p>
s s2<o:p></o:p>
------------<o:p></o:p>
a `a<o:p></o:p>
b a
b<o:p></o:p>
c a
b`c<o:p></o:p>
c a
b`c<o:p></o:p>
a a
b`c<o:p></o:p>
d a
bc
d<o:p></o:p>
k a
bc
d`k<o:p></o:p>
<o:p></o:p>
then count each.<o:p></o:p>
<o:p></o:p>
Terry<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
On Fri, Sep 30, 2016 at 11:36 AM, Jorge Sawyer <jfsawyer88@gmail.com> wrote:<o:p></o:p>
For a running list of distinct values in your list s you can do<o:p></o:p>
<o:p></o:p>
(distinct@,)[s]<o:p></o:p>
<o:p></o:p>
and then you can count each element of the output list to get the result of the function you want. The full function can be written as<o:p></o:p>
<o:p></o:p>
f:{count each (distinct@,)}<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
On Fri, Sep 30, 2016 at 11:03 AM, <rex.gm.yu@gmail.com> wrote:<o:p></o:p>
s:a
bc
ca
d`k <o:p></o:p>
myfunction s<o:p></o:p>
result:1 2 3 3 3 4 5<o:p></o:p>
<o:p></o:p>
s s list s count sums<o:p></o:p>
-----------------------------------------------------<o:p></o:p>
a
a 1<o:p></o:p>
b
a`b 2<o:p></o:p>
c
ab
c 3<o:p></o:p>
c
ab
c 3<o:p></o:p>
a
ab
c 3<o:p></o:p>
d
ab
c`d 4<o:p></o:p>
k
ab
cd
k 5<o:p></o:p>
<o:p></o:p>
how to define myfunction?<o:p></o:p>
<o:p></o:p>
thks<o:p></o:p>
<o:p></o:p>
Rex Yu<o:p></o:p>
*_*_*_*_*_*_*_*_*_*_*_*<o:p></o:p>
–
Submitted via Google Groups