Henry, 1) Can you explain what you have done and how is it equivalent to what I have asked? I am having trouble understanding particularly after what Dan has written as the characteristic of the sequence , viz., number of 1's in the binary representation.
2) OEIS tells me that "3 msks 64" is a sequence "Numbers with binary weight <= 3. " [3]. I am not able to see how Thanks, Yuva [3] http://www.research.att.com/~njas/sequences/index.html?q=0%2C+1%2C+2%2C+3%2C+4%2C+5%2C+6%2C+7%2C+8%2C+9%2C+10%2C11%2C12%2C13%2C14%2C16%2C17%2C18%2C19%2C20%2C21%2C22%2C24%2C25%2C26%2C28&language=english&go=Search On Fri, Jan 15, 2010 at 12:04 PM, Henry Rich <[email protected]> wrote: > With d wired to 2, you can use > > msks =: /:~@(> # ]) ~.@,@(+/~)@(0&,)@(i.@:>:@<.&.(2&^.)) > msks 64 > 0 1 2 3 4 5 6 8 9 10 12 16 17 18 20 24 32 33 34 36 40 48 > > If you need to change d, you can use > > msks =: (] #~ (>: +/"1...@#:)) i. > 2 msks 64 > 0 1 2 3 4 5 6 8 9 10 12 16 17 18 20 24 32 33 34 36 40 48 > 3 msks 32 > 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 19 20 21 22 24 25 26 28 > > > Henry Rich > > > Yuvaraj Athur Raghuvir wrote: > > Hello, > > > > I want to rewrite Java Code[1] to J Code[2] . I want to check with the > forum > > members if there is a better way to achieve this. > > > > The issue is that in the setBits loop, the values are set using the > > previously set values. In the process of loop elimination, I found a J > form > > and I hand coded the extension to the desired limit. The questions I have > > are: > > 1) For the J pattern I have found, is there a way to use ^: or $: forms? > > 2) Based on the math behind the Java Code, is there a different way to > > achieve this result? I am not able to formulate the problem so I did it > the > > debugging way. > > > > Thanks, > > Yuva > > > > Java Code: > > byte[] setBits = new byte[256]; > > int d = 2; > > for (int i = 0; i < 256; ++i) setBits[i] = (byte) ((i & 1) + > setBits[i > >>> 1]); > > //println(setBits); > > // for every possible key mask... > > masks = new int[0]; > > for (int i = 0; i < s; ++i) > > // if d or fewer bits are set... > > if (setBits[(i >> 24) & 0xFF] + > > setBits[(i >> 16) & 0xFF] + > > setBits[(i >> 8) & 0xFF] + > > setBits[ i & 0xFF] <= d) > > // add it to the list of masks. > > masks = append (masks, i); > > > > My J Attempt: > > ls =: (33 b.) NB. bit left shift > > and =: (17 b.) NB. bit and > > or =: (23 b.) NB. bit or > > exor =: (22 b.) NB. bitwise exclusive or > > > > > > v0 =: 13 : ' (2&| i...@# y) + (2&| i...@#y) {~ (_1&ls i...@#y) ' > > v1 =: 13 : ' (2&| i...@#y) + ( (-#y) {. (_1&ls i.+:@# y)) { y ' > > t2 =. (v0,v...@v0) NB. t2 i.2 gives a string of length 4 on i.2 > > t3 =. (t2,v...@t2) NB. 2^3 > > t4 =. (t3,v...@t3) NB. 2^4 > > t5 =. (t4,v...@t4) NB. 2^5 > > t6 =. (t5,v...@t5) NB. 2^6 > > t7 =. (t6,v...@t6) NB. 2^7 > > t8 =. (t7,v...@t7) NB. 2^8 > > sb =. t8 i.2 NB. setBits > > m0 =. (16bff&and)@:(0&ls + _8&ls + _16&ls + _24&ls) sb > > m1 =. <:&2 m0 > > msk =: I. m1 NB. masks > > > > t2 i.2 > > 0 1 1 2 > > t3 i.2 > > 0 1 1 2 1 2 2 3 > > t4 i.2 > > 0 1 1 2 1 2 2 3 1 2 2 3 2 3 3 4 > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
