Set right-adjacent bits: Difference between revisions

Added AutoHotkey
(J)
(Added AutoHotkey)
Line 162:
Result : 011110000000111100000011110000011110000111100011110011110111111111
</pre>
 
=={{header|AutoHotkey}}==
<lang AutoHotkey>setRight(num, n){
x := StrSplit(num)
for i, v in StrSplit(num)
if v
loop, % n
x[i+A_Index] := 1
Loop % n
x.removeAt(StrLen(num)+1)
for i, v in x
res .= v
return res
}</lang>
Examples:<lang AutoHotkey>test1 := [
(join,
"1000"
"0100"
"0010"
"0000"
)]
 
test2 := [
(join,
"010000000000100000000010000000010000000100000010000010000100010010"
"010000000000100000000010000000010000000100000010000010000100010010"
"010000000000100000000010000000010000000100000010000010000100010010"
"010000000000100000000010000000010000000100000010000010000100010010"
)]
 
for i, num in test1
result .= "n=2; Width e = 4:`nInput :`t" num "`nResult :`t" setRight(num, 2) "`n`n"
 
for i, num in test2
result .= "n=" i-1 "; Width e = 66:`nInput :`t" num "`nResult :`t" setRight(num, i-1) "`n`n"
 
MsgBox % result
return</lang>
{{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|F_Sharp|F#}}==
299

edits