KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Binary iteration question Re: Binary iteration question

  • rocuinneagain

    Member
    May 17, 2022 at 12:00 am

    This becomes easier by splitting the problem in 2 parts.

    1. Finding the indexes where needed number of 1b is hit
    2. Finding the indexes where needed number of 0b is hit

    These are the only indexes that matter. Then a prototype list can be populated with nulls before having the important indexes overlaid. Then the prevailing values are carried forward by fills.

    q)f:{o:count[z]#0N;o:@[o;where x=x msum z;:;1];y:y+1;"b"$0^fills @[o;where y=y msum not z;:;0]} 
    
    q)f[3;2] 00001111000111001101000b 00000011110001111111110b
    q)f[3;2] 110010111001111b 000000001111111b