This seems to take advantage of the fact that the max of the partition is the 1st element in the list. If you move it as below the solution does not work.
x:1 1 0 0 0 1 0 0 1 1
y:3 4 5 2 8 6 9 4 5 4
k),/|'(&x)_ y
/Output:
3 4 5 5 8 6 9 9 5 4j
Suggestion :
I take away the 1st element; do a max and join it later
Ag,
I think you are close but might not be right because according to me a partition is section of the y array which is all x array 11’s and 00’s. Since this is a q idiom from their output it seems like they think a partition is just the ones in y array whose x array counterparts are 0’s. Their answer does work with their version of y array but it ( potentially ) has a flaw pointed out by me i.e. the max 8 2 5 (1st partition) and 9 5 (2nd partition) is that the max is the 1st element. i.e. 8 and 9 . If you make the 1st partition as 5 2 8 (in which max 8 is the last element in this partition) their solution does not work. I suggested a fix and wanted to validate it with someone else.
I emphasize the “might not”, “according to me part” , “potentially” in the above statement.
For your 2 personal question, I do not know the best q answer because I am not the best q programmer. I have a suggestion for the 1st one below but it want to focus on my observation in the idiom that 1) is it a bug ? 2) is my suggestion correct or is there a better answer out there ?
I think the difference here is the understanding of the desired output.
The original problem, as well as the code, deals with a “max scan,” i.e., the running maximum of a sequence given a partitioning scheme annotated 0’s & 1’s. Thus, the “error” indicated by your original post was actually the correct output:
x:1 1 0 0 0 1 0 0 1 1
y:3 4 5 2 8 6 9 4 5 4
o:3 4 5 5 8 6 9 9 5 5
Note that in the 2nd partition (5 2 8), the running maximum is indeed 5 5 8. That is, your can only find the maximum of each partition by taking the last element of each partition from the output.
Ag,
I think you are close but might not be right because according to me a partition is section of the y array which is all x array 11’s and 00’s. Since this is a q idiom from their output it seems like they think a partition is just the ones in y array whose x array counterparts are 0’s. Their answer does work with their version of y array but it ( potentially ) has a flaw pointed out by me i.e. the max 8 2 5 (1st partition) and 9 5 (2nd partition) is that the max is the 1st element. i.e. 8 and 9 . If you make the 1st partition as 5 2 8 (in which max 8 is the last element in this partition) their solution does not work. I suggested a fix and wanted to validate it with someone else.
I emphasize the “might not”, “according to me part” , “potentially” in the above statement.
For your 2 personal question, I do not know the best q answer because I am not the best q programmer. I have a suggestion for the 1st one below but it want to focus on my observation in the idiom that 1) is it a bug ? 2) is my suggestion correct or is there a better answer out there ?
Flying you DUH boss :-) Btw on another topic, I do do “deep-dives” of kdb code. If you would like to be involved, would you want to ping me offline ? I cannot tell your email from this forums.