26
2
This is sequel to this challenge by Adnan. If you like this challenge, chances are you'll like the other one too. Check it out!
A multiple choice test with 8 questions each with 4 choices might have the answers: BCADBADA
. Converted to four different arrays, with true and false if the current letter is the answer, it will look like this
Q#: 1 2 3 4 5 6 7 8
B C A D B A D A
A: [0, 0, 1, 0, 0, 1, 0, 1]
B: [1, 0, 0, 0, 1, 0, 0, 0]
C: [0, 1, 0, 0, 0, 0, 0, 0]
D: [0, 0, 0, 1, 0, 0, 1, 0]
This can be compressed using a bit of logic. Each of the choices A
, B
, C
and D
can be represented
by two true/false values shown below:
A: 1 0
B: 0 1
C: 0 0
D: 1 1
Using this logic, we can compress the four vectors above to just two:
1 2 3 4 5 6 7 8
B C A D B A D A
[0, 0, 1, 1, 0, 1, 1, 1]
[1, 0, 0, 1, 1, 0, 1, 0]
That is, the solution to your test is simply: 00110111
, 10011010
. By concatenating these, we get the binary number
0011011110011010
, or 14234
in decimal. Use this decimal value to cheat on your test!
Challenge
Take a number N
in the (inclusive) range [0, 65535]
, and output a string with the answer to the multiple choice test.
Test cases:
14234
BCADBADA
38513
ABBDCAAB
0
CCCCCCCC
120
CBBBBCCC
65535
DDDDDDDD
39253
ABCDABCD
The output may be in upper or lower case letters, but you can not use other symbols.
Does the output have to be the string as shown, or can the letters be on separate lines, in a list, etc? – xnor – 2016-09-25T16:47:24.430
@xnor Optional :-) – Stewie Griffin – 2016-09-25T17:10:41.437
Why not the obvious A=00,B=01,C=10,D=11? – user253751 – 2016-09-26T01:57:34.993
The reason was I first made
A=10, B=01
, thenC=nor(A,B)
, andD=and(A,B)
, inspired by Adnan's challenge. In hindsight it might have been better to do it the other way around, but well... Too late now... – Stewie Griffin – 2016-09-26T06:35:14.943