Set right-adjacent bits: Difference between revisions

Content added Content deleted
(J)
Line 330: Line 330:
Result : 011110000000111100000011110000011110000111100011110011110111111111
Result : 011110000000111100000011110000011110000111100011110011110111111111
</pre>
</pre>

=={{header|J}}==

Implementation:

<lang J>smearright=: {{ +./ (-i.1+x) |.!.0"0 1/ y }}</lang>

Here, we use J's bit array structure, so <tt>e</tt> is implicit in the length of the list.

Task examples:

<lang J>b=: '1'&= :.(' '-.~":)
task=: {{y,:x&smearright&.:b y}}

0 task '010000000000100000000010000000010000000100000010000010000100010010'
010000000000100000000010000000010000000100000010000010000100010010
010000000000100000000010000000010000000100000010000010000100010010
1 task '010000000000100000000010000000010000000100000010000010000100010010'
010000000000100000000010000000010000000100000010000010000100010010
011000000000110000000011000000011000000110000011000011000110011011
2 task '010000000000100000000010000000010000000100000010000010000100010010'
010000000000100000000010000000010000000100000010000010000100010010
011100000000111000000011100000011100000111000011100011100111011111
3 task '010000000000100000000010000000010000000100000010000010000100010010'
010000000000100000000010000000010000000100000010000010000100010010
011110000000111100000011110000011110000111100011110011110111111111</lang>

<code>b</code> converts from character list to bit list (and its obverse converts back to character list, for easy viewing).
<code>task</code> uses b on the right argument to <code>smearright</code> and its obverse on the result, which it provides with the original value (again, for easy viewing).


=={{header|Julia}}==
=={{header|Julia}}==