A 2ᵏ-to-1 multiplexer passes one of its data inputs to its output. The select bits, read as a binary number, say which one: data input D0 is the first bit of the data string.
Input
A line with k (1 ≤ k ≤ 5), a line with the 2ᵏ data bits as one string (D0 first), then any number of lines, each with k select bits (most significant first), ending with a line end.
Output
For each select line, the output bit.
Examples
Example 1 · Input
2 1001 00 01 10 11 end
Expected output
1 0 0 1
Example 2 · Input
1 01 1 end
Expected output
1
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
The select bits, read as a binary number, are the index of the data input.
Hint 2
int(select, 2) turns the select string into that number.
Solution
Show one correct solution (try it yourself first)
k = int(input())
data = input().strip()
while True:
s = input().strip()
if s == "end":
break
print(data[int(s, 2)])