Set right-adjacent bits: Difference between revisions

added Arturo
m (syntax highlighting fixup automation)
(added Arturo)
Line 162:
Result : 011110000000111100000011110000011110000111100011110011110111111111
</pre>
 
=={{header|Arturo}}==
<syntaxhighlight lang="arturo">setBits: function [inp, n][
e: size inp
print "n = " ++ (to :string n) ++ "; Width e = " ++ (to :string e) ++ ":"
 
result: new ø
if? or? zero? e n =< 0 -> result: inp
else [
result: split inp
loop 0..e-1 'i [
if inp\[i] = `1` [
j: i + 1
while [and? j =< i+n j < e][
result\[j]: `1`
j: j + 1
]
]
]
result: join result
]
 
print ["\tinput :" inp]
print ["\tresult :" result]
]
 
setBits "1000" 2
setBits "0100" 2
setBits "0010" 2
setBits "0000" 2
 
setBits "010000000000100000000010000000010000000100000010000010000100010010" 0
setBits "010000000000100000000010000000010000000100000010000010000100010010" 1
setBits "010000000000100000000010000000010000000100000010000010000100010010" 2
setBits "010000000000100000000010000000010000000100000010000010000100010010" 3</syntaxhighlight>
 
{{out}}
 
<pre>n = 2; Width e = 4:
input : 1000
result : 1110
n = 2; Width e = 4:
input : 0100
result : 0111
n = 2; Width e = 4:
input : 0010
result : 0011
n = 2; Width e = 4:
input : 0000
result : 0000
n = 0; Width e = 66:
input : 010000000000100000000010000000010000000100000010000010000100010010
result : 010000000000100000000010000000010000000100000010000010000100010010
n = 1; Width e = 66:
input : 010000000000100000000010000000010000000100000010000010000100010010
result : 011000000000110000000011000000011000000110000011000011000110011011
n = 2; Width e = 66:
input : 010000000000100000000010000000010000000100000010000010000100010010
result : 011100000000111000000011100000011100000111000011100011100111011111
n = 3; Width e = 66:
input : 010000000000100000000010000000010000000100000010000010000100010010
result : 011110000000111100000011110000011110000111100011110011110111111111</pre>
 
=={{header|AutoHotkey}}==
1,532

edits