Data update
This commit is contained in:
parent
61b93a2cd1
commit
5af6d93694
858 changed files with 20572 additions and 2082 deletions
36
Task/Set-right-adjacent-bits/11l/set-right-adjacent-bits.11l
Normal file
36
Task/Set-right-adjacent-bits/11l/set-right-adjacent-bits.11l
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
F set_right_adjacent_bits_list(Int n, [Int] b) -> [Int]
|
||||
R (0 .< b.len).map(i -> Int(any(@b[max(0, i - @n) .. i])))
|
||||
|
||||
F _list2bin([Int] b) -> String
|
||||
R b.map(x -> String(x)).join(‘’)
|
||||
|
||||
F _to_list(String bits) -> [Int]
|
||||
R bits.map(char -> Int(char))
|
||||
|
||||
print("SAME n & Width.\n")
|
||||
V n = 2
|
||||
V bits_s = ‘1000 0100 0010 0000’
|
||||
V first = 1B
|
||||
L(b_str) bits_s.split(‘ ’)
|
||||
V b = _to_list(b_str)
|
||||
V e = b_str.len
|
||||
I first
|
||||
first = 0B
|
||||
print(‘n = ’n‘; Width e = ’e":\n")
|
||||
V result = set_right_adjacent_bits_list(n, b)
|
||||
print(‘ Input b: ’_list2bin(b))
|
||||
print(‘ Result: ’_list2bin(result)"\n")
|
||||
|
||||
print("SAME Input & Width.\n")
|
||||
bits_s = ‘01’(10.<0).step(-1).map(x -> ‘0’ * x).join(‘1’)
|
||||
L(n) 4
|
||||
first = 1B
|
||||
L(b_str) bits_s.split(‘ ’)
|
||||
V b = _to_list(b_str)
|
||||
V e = b_str.len
|
||||
I first
|
||||
first = 0B
|
||||
print(‘n = ’n‘; Width e = ’e":\n")
|
||||
V result = set_right_adjacent_bits_list(n, b)
|
||||
print(‘ Input b: ’_list2bin(b))
|
||||
print(‘ Result: ’_list2bin(result)"\n")
|
||||
Loading…
Add table
Add a link
Reference in a new issue