RosettaCodeData/Task/Set-right-adjacent-bits/11l/set-right-adjacent-bits.11l
2023-09-01 09:35:06 -07:00

36 lines
1.1 KiB
Text
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")