Data update
This commit is contained in:
parent
29a5eea0d4
commit
5c1bb7bfa9
2011 changed files with 35081 additions and 3229 deletions
27
Task/Set-right-adjacent-bits/Jq/set-right-adjacent-bits.jq
Normal file
27
Task/Set-right-adjacent-bits/Jq/set-right-adjacent-bits.jq
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# Input should be an array of 0s and 1s
|
||||
def setRightBits($e; $n):
|
||||
if $e == 0 or $n <= 0 then .
|
||||
else . as $bits
|
||||
| reduce range(0; $e - 1) as $i ({bits2: .};
|
||||
$bits[$i] as $c
|
||||
| if $c == 1
|
||||
then .j = $i + 1
|
||||
| until (.j > ($i + $n) or .j >= $e;
|
||||
.bits2[.j] = 1
|
||||
| .j += 1 )
|
||||
end)
|
||||
| .bits2
|
||||
end;
|
||||
|
||||
def b:
|
||||
"010000000000100000000010000000010000000100000010000010000100010010";
|
||||
|
||||
def tests:
|
||||
[["1000", 2], ["0100", 2], ["0010", 2], ["0000", 2], [b, 0], [b, 1], [b, 2], [b, 3]];
|
||||
|
||||
tests[] as [$bits, $n]
|
||||
| ($bits|length) as $e
|
||||
| "n = \($n); Width e = \($e):",
|
||||
" Input b: \($bits)",
|
||||
( ($bits | [explode[] | . - 48]) as $b
|
||||
| " Result: \($b | setRightBits($e; $n) | join(""))\n" )
|
||||
Loading…
Add table
Add a link
Reference in a new issue