Back
Close

Multiplexer

Statement
A multiplexer (MUX) is a logic gate posessing control inputs, data inputs and a single output. Given values on its control inputs it is able to select the corresponding data input and forward the value of that data input to its output. The control inputs can be understood as representing a number in base 2, so for example, on a multiplexer with 2 control inputs, if {{0}} is on c0 and {{1}} on c1, the multiplexer would forward data input {{0b10 == 2}} to its output: ` c1 c0 | | _1_0_ data0 -1-| | data1 -0-| ,--|-0- out data2 -0-|--' | data3 -1-| | '-----' ` If the values of the control inputs would be both {{1}}, then - as {{0b11 == 3}} - {{data3}} would be moved to the multiplexer's output: ` c1 c0 | | _1_1_ data0 -1-| | data1 -0-| ,--|-1- out data2 -0-| | | data3 -1-|--' | '-----' ` Create a program that simulates a multiplexer given [[t]] strings that define the values of all the multiplexer's inputs.

Input description
<<[ Line 1 ]>> [[c]], the number of control inputs on the multiplexer, and [[t]], the number of input strings to handle; separated by a space. <<[ Next [[t]] lines ]>> String containing values of all the multiplexer's inputs. The first [[c]] characters describe the values of the control inputs (Most significant bit first). The other [[2**c]] characters describe the values of the data inputs (From {{data0}} to {{data[2**c-1]}}).

Output description
<<[ Line 1-[[t]] ]>> The multiplexer's output for the given input; either {{0}} or {{1}}.

Constraints
Each of the strings describing the multiplexer's input will consist exclusively of {{0}} and/or {{1}}. {{0}} < [[c]] <= {{8}}

Game modes

Test cases
Changing control Test
Input
2 2 101001 111001
Output
0 1

vChanging control Validator
Input
2 2 011110 001110
Output
1 1

Changing data Test
Input
2 3 111001 110001 110000
Output
1 1 0

vChanging data Validator
Input
2 3 010110 010001 010101
Output
1 0 1

Pulse Test
Input
1 18 110 110 110 110 101 001 001 001 001 010 110 110 110 110 101 001 010 110
Output
0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 1 0

vPulse Validator
Input
1 18 001 001 010 110 110 110 101 001 001 001 010 110 101 001 001 010 110 110
Output
0 0 1 0 0 0 1 0 0 0 1 0 1 0 0 1 0 0

Where's all the data? Test
Input
2 10 100000 010000 100000 100000 000000 010000 000000 110000 110000 100000
Output
0 0 0 0 0 0 0 0 0 0

vWhere's all the data? Validator
Input
2 10 010000 110000 100000 000000 000000 010000 100000 010000 111111 111111
Output
0 0 0 0 0 0 0 0 1 1

Staircase Test
Input
3 16 00011000000 00111100000 01001110000 01100111000 10000011100 10100001110 11000000111 11100000011 11000000111 10100001110 10000011100 01100111000 01001110000 00111100000 00011000000 11111100000
Output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0

vStaircase Validator
Input
3 16 11101100101 11001001000 01011110011 10001100100 11011111010 01011110001 00101101111 00100010000 11000000000 01100110101 01001000110 00011101011 10110001011 11110110000 00001111001 00000001010
Output
1 0 1 0 1 1 1 0 0 1 0 1 0 0 0 0

Tracer Test
Input
3 20 01000100000 01000100000 01100010000 01100010000 01100010000 10000001000 01100010000 01000100000 01000100000 01100010000 10000001000 10100000100 11000000010 11000000010 11000000010 11000000010 10100000100 10000001000 10000001000 01100010000
Output
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

vTracer Validator
Input
3 20 00000100101 10011110111 01100000000 00110010100 11010011011 10100000010 01101111100 01000000000 10000100101 01000000010 10000000001 11011100001 10110100000 00100110110 10011100000 10110010111 11000100000 10100000010 11111010000 00011001001
Output
0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1

2:1 Test
Input
1 16 101 101 110 100 111 000 010 000 001 010 001 010 100 111 100 110
Output
1 1 0 0 1 0 1 0 0 1 0 1 0 1 0 0

v2:1 Validator
Input
1 16 010 010 010 011 110 111 111 100 101 000 001 010 001 010 110 110
Output
1 1 1 1 0 1 1 0 1 0 0 1 0 1 0 0

8:1 Test
Input
3 24 00001110110 00101110010 01001110111 01101101010 10011010010 10111110000 11001011001 11100001110 00000000111 00111010001 01011111000 01101001000 10000001101 10101000110 11001010000 11111000110 00011000011 00100000100 01011111101 01110110111 10010010010 10110101111 11011000011 11110001110
Output
0 1 1 0 0 0 0 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 0

v8:1 Validator
Input
3 24 11000101011 01000110000 11011110101 00110011111 00100011001 10101111101 11001111000 01000001110 01001111000 00101001101 00101110010 11100100010 00010011001 01111011111 00111101001 00100100010 11111010011 10110110011 10000110100 01101011110 01100100111 10011010111 11100101111 01000100000
Output
1 1 0 0 0 1 0 0 1 1 1 0 1 1 1 0 1 0 0 1 0 0 1 1

Comically oversized Multiplexer Test
Input
8 15 000100010001001110001001110001000000011001010101010011101000110101110011000101100101101011001101011000101010010110010101110000011100111011000100001001101111100100001000001100011011000000000110101111001101011010000101110011010111000101000000101111000110110000100111 101011100101101111111100001000101001011001000111000101001000010010010010011001101000110011000100010011100100010101011110101111101001110100100110101010110000000110001111011100000101000110100110010111001010100011111100010000011100101111010001011001101100110100101011 010101010011111001101000000100100000001010111100010101010100100000010001011100010010110111000110111100100001001011101100101111100010110111110110000011100100110110001001010001000011110000100000010001101100011010011001101110101100001110000100010000000011101011010011 011001011011010000011010100111001111000000101100000110101101010011110100010101001111101011000100011111100001011001111001001000010111001001000000101110101111011000101001001111100100010010000011111100010001010111001001110100101111101110010010100101010010111001110000 100000110000110000010010101100111001101110011001010111101110101110101101100010100100010101001101011011010000000001110011011000110001010100001000101001110000011011110100010110100101111001111010111001001110110010010001011110011110011001110001000001011101000110001010 111011000011000001011010010001010101101000101111011010101110111000110110101010101010010011000010001001111100011101111100110111010011010001001111001111011110001111111110110100100100100001011011101100101100101010110001101011100011000000011010000101111101101101011010 001010000101000111011100110001011111010011101000100011111110011111011111001111100000110111010010110001101001001011000100011000111011111111100001100011110100101010010001001011101101000011110110101011000101101001001101010010100110010100001100101010100010111001110000 010011001010100110100111100101001011111011000111001101100101000101010101111011110110011011100101010110010001011100001111110000111111010101100101111100110010011001011000000010101011000101110000011000001100001010101100010111000001001111110101101111110011011000011100 001001101100000111111110011111101100110000100100101010001011110010011001011110010010100011010101001110101101101100110111111100110110111010000110110010110111001001101110111101110010001111100001111110010010000000100000010001010011110110011011110110100110110010111101 010110001010000001010110101011100110110110110101010100011000111101001111100110110110110000010000010011111001001011011101101000010000111010100001010010001010110011001100110100110011000001000011000101001100000100010011111110000000011000101000010000100100110000101110 001011100011101011010010000000001111001110101000110001000010111010110101100011111101100110101110011110100110111101101010111101100000011000001001110110111101111000101100011001111001100010100101110110101000001000110101001110010101110010101111101001011011010110000111 110001111010011011001010110110001001100100101111011100000110111010001001110100101011110001001101011101011010101110000100111111100010111001010111010000000110011010000011001000111101000001010100100011110011010001001110000010101011010101011101001111101011100111010110 100011000110110111101111100100010001100010011011111011111001011011011111100010110010101100011011101010101000111111100001001010000011010101100110010000100001011001011100100010010111101010010101001010010101011010111101101001010011100011100010111010010101010010100010 110001111100100011111011111110010011011011111011001111011010000000001101110110000011011101010100111101011001011110110001110100010001100101100000010101000100110111011111110000001110011000000011111100110010100011100111101010001011110100111101111100111011110001000001 110110000101000110010000010011101100010001100100000110000101110001101000110111111100100101101001111111100011110011010110010101011001000110011101100011100000111101100111101001110100100010111101111000010010111011011101010111000001111010111100010011110001001110101110
Output
1 0 1 1 0 0 1 0 0 0 0 0 0 0 0

vComically oversized Multiplexer Validator
Input
8 15 100001011011101101011010110011101011100110001011100110011000111111111010111111011111111000011000000110100111010010101000010010100100110001011110011011110010101101110101000101110101111001010101110001111110001100011010111011101001000100000100110001110010011111111100 000111001101100111011011101000000111101100010111101111000010111010110100101011011001001110101010010001101010100111110010001011100010010001011000101010101110000000101110111101000001010000111100110000000001111001110000100000011011110001010011001000111011000110111111 000010001000001111100111000010011001001000100001010011111111001111111110000110100110011110111110000111010001010101010000011111110001000110001111011001011111110110001010101001011011010000010100100001001100010111001001111111001111101010100100101101100001111010101010 111000110110100100001111110111001101111101011000100110110110101010101001100010100100000011011010001111000000010100001100010101000011011011110111010110001000011010111100101110101111010010000010100000011100001111110011001001100101100110111111110010101111000101001110 010110001011101110011101000101010101111101100101100111101001101111111111011001100110111101100010000110111101011101000001011110111010010010101110010101011000111110000111111111010011010110100111101100001001110000101000001010100101110111111110100011111001000010101010 100000001001010001100010111001000001001000000111000111100100110101111101100110010010101000001110111001011100100111001100000101000000000111010100000100001110010000010000101010110110010010111010011100010111101100100000010011001111100011010000110111011101110011010111 101110001000100101010101111111011000010101101001000010000111111010010111010100011100110101100001111100000100100111110000110000001011101011100001101001100110011000111010011110001000110110110010100001011101101111011111001110000100001000000100011000000111111001100101 110001010101100101000001011100000010011111001010001101100010010111111001010011000010011100000110001110010001000110001001000111100011101111010100000101110010010101101010100100100010011111111101100100010110110100100100011110111000101011010101111001010001100100111011 011111111011001110101011100011010111111011110000010111011001001101111001110100011111101110001100101011111000101101010011111111111100100111011000111010100000101110001000011001111000111100010011001101110011101011001110110010001011010001010010011110001010110001001001 010010010011000111000111011110010000011110110011011110111000110011011111101011001110111001101001011110011110110100010000011000001111111011101111101000000011011110101101110000001110110001000111000001001011110001100011011011111010111111110101100010000011110010110111 100010110011000011111000111010010001001111111100101011001110000100001011100111000011101010011001111101110010010101101110100010011111000100100110111101101101011011000110110010001011011110011010011110011110001010010110111101011101101000100110110110000010101100000100 111110110100110100000010110110101100011011011000011010100000000000000100001101100100110111010101010110101011011011100001001010011001100110010001110101010011011110011101111010111001100000001100011001010100000000111001101110110111100001110000001111000000000000110100 000000101110111111011100111101110011000010101011011001111111010111111010100100010001001010101111010001010011110011001110100110000111100001010000100011010001100000110110010111111101011110001010010010010110001111011011111011110111000010110101011111101101111110111110 011010111111111001111101100110010110100011100011101010110001100000111001111011100111001001111010111011101000100100001101111010110001101011100100010100100010001000010101010001001000011010111111010010001001001101011111011101000100011010010101111000100101111000010101 010110111001010111100111011111010110101001100010010100001001110110010111000110011111001000011101110010111101001000101110101011000011111110111001010101110110000001100100111010111000000110110100110000101010010101001000110011010001010111101111001010000111110100001011
Output
1 1 1 1 0 1 1 1 1 1 1 1 1 0 0

Solution language

Solution

Stub generator input