Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


While studying, I tried to come up with several ways to cheat a multiple choice test. It basically is a compressed version of the multiple choice answers. The method goes as following:

The answers to the test:


These can be converted to 3 different arrays, which indicates true or false if the current letter is the answer:

    B  C  A  A  B  A  B  A
A: [0, 0, 1, 1, 0, 1, 0, 1]
B: [1, 0, 0, 0, 1, 0, 1, 0]
C: [0, 1, 0, 0, 0, 0, 0, 0]

Interpreting these numbers as binary would compress this a lot. But this can actually be compressed a bit more. If you know the positions of A and B, you don't need the positions for C. This can be done with a bitwise NOT operator:

A: [0, 0, 1, 1, 0, 1, 0, 1]
B: [1, 0, 0, 0, 1, 0, 1, 0]

A+B: [1, 0, 1, 1, 1, 1, 1, 1]
C:   [0, 1, 0, 0, 0, 0, 0, 0]

Converting the arrays A and B to binary numbers would result in:

A: 00110101
B: 10001010

That means that 8 multiple choice answers can be compressed to two bytes!


Given two numbers in binary, or two arrays consisting of only 0's and 1's with the same length, output the multiple choice answers


  • Input can be in the any form you like, like [1, 0, 0, 1] or 1001.
  • You may provide a program or a function.
  • You may assume that the input is always valid.
  • You may also output as a list, separated with spaces, etc.
  • The multiple choice answers only consist of A's, B's and C's. You may however use lower case instead.
  • This is , so the submission with the least amount of bytes wins!

Test cases

Input: [1, 0, 0, 1, 0, 0, 1] [0, 1, 0, 0, 1, 0, 0]

Input: [0, 0, 0, 0, 1, 0, 1, 1] [1, 0, 1, 0, 0, 0, 0, 0]

Input: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]


var QUESTION_ID=69770,OVERRIDE_USER=34388;function answersUrl(e){return""+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return""+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",,t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",,i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src=""></script> <link rel="stylesheet" type="text/css" href="//"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

share|improve this question
Here is my solution. It is written in English (interpreter freely available wherever you are), and is Study.. Six bytes. Beat that. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 20 at 19:01
@CᴏɴᴏʀO'Bʀɪᴇɴ Sadly, English does not meet our standards of a programming language and is therefore not a valid submission :p – Adnan Jan 20 at 19:05
You can actually compress eight multiple choice questions to 1.625 bytes (13 bits) by interpreting the answers as base 3, so technically this isn't the most efficient method. :P – Doorknob Jan 20 at 23:29
You could add another answer in the same space by using all four combinations of two bits, 00, 01, 10, 11 for answer a, b, c or d. You are not using 11. – Filip Haglund Jan 21 at 9:23
English satisfies all the criteria. The only problem is there isn't an interpreter available before this question is asked. – jimmy23013 Jan 22 at 2:06

32 Answers 32

up vote 48 down vote accepted

Jelly, 7 6 bytes


Typing on phone. Will add description.

(1,0) goes to A, (0,1) to B, and (0,0) to C. Arrays in Jelly are 1-based, and the indexing function works cyclically. Therefore, we can just fold subtraction over the input.

_              [vectorized] subtraction
_/             Fold subtraction over the input
   “ḃ»         "ABC" compressed. '»' terminates a compressed string.
  ị            Vectorized cyclic index.

Try it here.

share|improve this answer
how on earth did you type that on a phone? o-O – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 20 at 19:41
Samsung's clipboard history. It wasn't easy. – lirtosiast Jan 20 at 19:45
:-DD And congrats on 10k! – Luis Mendo Jan 20 at 19:55
Lol, same size as English now @CᴏɴᴏʀO'Bʀɪᴇɴ – RK. Jan 20 at 21:31
I golf my answer to "Study"; I am using an interpreter that is okay with grammatical mistakes. @RK. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 20 at 21:56

Retina, 44 bytes

B(?=(.)* .*B(?<-1>.)*(?(1)!)$)

The trailing linefeed is significant. Input is like

001101010 100010100

Try it online!



Start by turning 0s into B and 1s into A. That makes the first half correct, except that it lists B when it should contain C. We can identify those erroneous Bs by checking whether there's a B in the same position of the second string:

B(?=(.)* .*B(?<-1>.)*(?(1)!)$)

The lookahead is a classic balancing group counting technique to match up the positions of the two Bs. The (.)* counts the suffix after the first B by pushing one capture onto group 1 for each character. Then (?<-1>.)* pops from that group again. The $ ensures that we can reach the end of the string like that, and the (?(1)!) ensures that we've actually depleted the entire group.

Finally, we get rid of the separating space and the second string:


share|improve this answer
3 upvotes in the first 15 seconds of posting; that must be some kind of record. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 20 at 20:00
@CᴏɴᴏʀO'Bʀɪᴇɴ Flattering, but I wonder how many of those 3 upvoters actually read and understood the answer in 15 seconds. :/ – Martin Ender Jan 20 at 20:01
I did. I am rather fluent in reading regex and retina. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 20 at 20:04

J, 8 bytes



   0 0 1 0 0 1 ('CAB'{~-) 0 1 0 1 0 0

Try it online here.

share|improve this answer

JavaScript ES6, 36 bytes


Very simple, and probably obvious enough to understand: Map each item and index in a to the char at position (x*2 + item at index y in b) in "CBA".

share|improve this answer
Please add this as your ungolfed version :3 – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 20 at 19:45
@CᴏɴᴏʀO'Bʀɪᴇɴ He CBA to do that. Also, he can't anyway, because do is a reserved keyword, so that's invalid syntax. – Patrick Roberts Jan 21 at 15:49
@Patrick simple fix: Do(...) – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 21 at 19:09

MATL, 14 9 bytes

2*+ 67w-c

Uses current version (10.1.0)

Try it online!


Summary of what the code does

2*       % implicitly input array and multiply it by 2
+        % implicitly input array and add it to the first one
67w-    % subtract from 67
c        % convert to char. Implicitly display

Detailed explanation of how it works

2        % Push number 2 onto the stack
*        % Multiply the top two stack elements. Since there's only one
         % element, this triggers implicit input of a (yet inexistent)
         % element below the existing one. This is the first input array,
         % which will be called "A". Both "A" and number 2 are consumed,
         % and the array 2*A is left on the stack.
+        % Add the top two stack elements. Again, since there's only
         % one element (namely array 2*A) this triggers implicit input
         % of the second array, call it "B". Both 2*A and B are consumed
         % and 2*A+B is left on the stack
         % A blank space is needed after the "+" symbol to prevent it from
         % being interpreted as part of number "+67"
67       % Push number 67 onto the stack. The stack now contains, bottom
         % to top, 2*A+B and 67.
w        % Swap top two elements. The stack now contains 67 and 2*A+B
-        % Subtract top two elements. These are consumed and the result
         % 67-A*B is left on the stack
c        % Convert to char array, interpreting each number as ASCII code.
         % Number 67 corresponds to letter 'C'. Therefore at positions
         % where both arrays A and B were 0 this gives 'C' as result.
         % Where A was 1 and B was 0, i.e. 2*A+B is 2, this gives 'A'.
         % Where A was 0 and B was 1, i.e. 2*A+B is 1, this gives 'B'.
         % The stack contents, namely this char array, are implicitly
         % displayed at the end of the program.
share|improve this answer
This is amazing! Can you write a bit more about why this works? Why 67? And how does multiply input array by 2 and then add input array differ from 'multiply input array by 3'? – Vincent Jan 22 at 9:22
@Vincent Sure! I'll add some more detailed explanation later in the day – Luis Mendo Jan 22 at 9:44
@Vincent Done! Let me know if it's clearer now – Luis Mendo Jan 22 at 22:39
Very clever! Thanks! – Vincent Jan 23 at 13:09

Haskell, 29 bytes

zipWith(\x y->"BCA"!!(x-y+1))

An anonymous function. Use like:

>> zipWith(\x y->"BCA"!!(x-y+1)) [1, 0, 0, 1, 0, 0, 1] [0, 1, 0, 0, 1, 0, 0]

I tried making the function point-free but got a total mess.

share|improve this answer
a point-free version of equal length: zipWith((!!).(["CB","AC"]!!)) – nimi Jan 21 at 14:29

Java, 81 bytes

No reputation to comment the already existing Java solution, so here goes:

void x(int[]a,int[]b){int j=0;for(int i:a)System.out.printf("%c",67-2*i-b[j++]);}
share|improve this answer
This is smart. :D I like. I see that you got a teensy bit of inspiration, though. ;) – VTCAKAVSMoACE Jan 22 at 23:38
Damn, that's clever. I spent ages trying to figure out how I could get a foreach loop to fit... – CameronD17 Jan 23 at 14:00

brainfuck, 52 bytes


Requires an interpreter that lets you go left from cell 0 and has 8-bit wrapping cells. Unlike most of my answers, EOF behaviour doesn't matter.

Takes byte input, with 0xFF as a delimiter. A stream of bytes representing the first input under "Test cases" would look like this:

0x01 0x00 0x00 0x01 0x00 0x00 0x01 0xFF 0x00 0x01 0x00 0x00 0x01 0x00 0x00

I could save a couple bytes by having 0x00 as a delimiter and using 0x01 and 0x02 as 0 and 1 respectively, but that felt like cheating :P

Once I figured out my strategy, writing this program was very easy. To find the nth letter to output, start with 0x43 (capital C in ASCII) and subtract ((nth element of first sequence)*2 + nth element of second sequence)

For what it's worth, here's the 52 byte program split into 3 lines and with some words beside them:

Get input until hitting a 255 byte; put a 67 byte to the right of each one

For each 67 byte: Subtract (value to the left)*2 from it

For each byte that used to contain 67: Subtract input and print result
share|improve this answer

Pyth, 18 16 10 bytes

3rd attempt: 10 bytes

Thank FryAmTheEggman for reminding me of the existence of G!


Input is of the form [ [0,0,1,1,0,1,0,1] , [1,0,0,0,1,0,1,0] ], which is essentially a matrix: row for choice and column for question number.

Hand-compiled pythonic pseudocode:

              G = "abcdefghijklmnopqrstuvwxyz"    // preinitialized var
VCQ           for N in transpose(Q):    // implicit N as var; C transposes 2D lists
   @<G3           G[:3][                // G[:3] gives me "abc"
       xN1            N.index(1)        // returns -1 if no such element

2nd attempt: 16 bytes


Input is of the form [ [0,0,1,1,0,1,0,1] , [1,0,0,0,1,0,1,0] ], which is essentially a matrix: row for choice and column for question number.

This compiles to

for N in num_to_range(Pchr(Q)):
   imp_print(("A" if head(N) else ("B" if N.pop() else "C")))

Ok, I know that looks messy, so let's hand-compile to pythonic pseudocode

                 Q = eval(input())
VCQ              for N in range transpose(Q): // implicit N as var; transposes 2D lists
   ?hN               if head(N):              // head(N)=1st element of N
      \A                 print("A")           // implicit print for expressions
        ?.)N             if pop(N):
            \B               print("B")
              \C             print("C")

1st attempt: 18 bytes


With input of the form [0,0,1,1,0,1,0,1,1,0,0,0,1,0,1,0], essentially concatenation of two lists. This compiles to

for N in num_to_range(8):
   imp_print(("A" if lookup(Q,N) else ("B" if lookup(Q,plus(8,N)) else "C")))

Again, compiling by hand

                   Q = eval(input())
V8                 for N in range(8):
  ?@QN                 if Q[N]:
      \A                  print("A")
        ?@Q+8N            if Q[N+8]:
              \B              print("B")
                \C            print("C")

And there goes the first codegolf in my life!!! I just learned Pyth yesterday, and this is the first time I ever participated in a code golf.

share|improve this answer
Welcome to Programming Puzzles and Code Golf! This looks very nice for a first time, +1 – Adnan Jan 21 at 13:52
Always nice to see someone learning Pyth! You can golf .) to be e, and I think it can be golfed quite a bit more. Consider the variable G which contains the lower case alphabet, I believe you can get to around 10 bytes using it, happy golfing! :) – FryAmTheEggman Jan 21 at 14:03
@FryAmTheEggman oh e! I was searching for it for several minutes! Also, thank you for reminding me of G. You are right, 10 bytes! – busukxuan Jan 21 at 14:38

Python 3, 39 bytes.

Saved 1 byte thanks to FryAmTheEggman.
Saved 2 bytes thanks to histocrat.

Haven't been able to solve with a one liner in a while!

lambda*x:['CBA'[b-a]for a,b in zip(*x)]

Here's my test cases. It also shows the way I'm assuming this function is called.

assert f([1,0,0,1,0,0,1], [0,1,0,0,1,0,0]) == ['A', 'B', 'C', 'A', 'B', 'C', 'A']
assert f([0, 0, 0, 0, 1, 0, 1, 1], [1, 0, 1, 0, 0, 0, 0, 0]) == ['B', 'C', 'B', 'C', 'A', 'C', 'A', 'A']
assert f([0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == ['C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C', 'C']

It uses zip to iterate through the arrays pairwise, and then indexes into a string to pick the correct letter. This all happens in a list comprehension, so it automagically becomes a list. The core of this solution is that the only possible combinations of a and b are [0, 1], [1, 0], [0, 0]. So if we subtract them, we get one of -1, 0, 1 which gets us the last, first, middle element respectively.

share|improve this answer

Ruby, 35 bytes



=> ["A", "B", "C"]

Takes the (x-y)th zero-indexed character of "CAB". (1-0) gives 1, and thus A. (0-0) gives 0, and thus C. (0-1) gives -1, which wraps around to B.

Alternate shorter solution with weirder output:

->a,b{{|x,y|p :CAB[x-y]}}

Output is quoted strings separated by newlines, which seems a bridge too far somehow.

share|improve this answer

Mathematica, 30 24 22 bytes


Quite simple.

share|improve this answer

Japt, 13 bytes


Try it online!

How it works

¡#C-X*2-VgY)d  // Implicit: U, V = input lists
¡              // Map each item X and index Y in U to:
 #C-X*2        //  The char code of C (67), minus 2X,
       -VgY)   //  minus the item at index Y in V.
            d  //  Convert to a char code.
share|improve this answer

Octave, 19 bytes



f([1 0 0 0 1 1],[0 1 0 0 0 0])
ans = ABCCAA

I'll add an explanation later when I have a computer in front of me. This was written and tested on octave-online on my cell.

share|improve this answer

TI-BASIC, 59 57 50 37 36 bytes

Takes one list from Ans, and the other from Prompt L₁. Saved 13 bytes thanks to Thomas Kwa's suggestion to switch from branching to sub(.

Prompt X
Disp sub("ACB",2+∟X(A)-Ans(A),1

I'll have to look for what Thomas Kwa said he found in the comments tomorrow. ¯\_(ツ)_/¯

share|improve this answer
You still have some bytes to save! Replace the Prompt L₁ with Prompt X and L₁ with ∟X. There's even more, but I'll let you find it. – lirtosiast Jan 21 at 3:20
@ThomasKwa L1 is a one-byte token, last I checked. Referencing it again with the list+x would be two bytes... am I not correct? – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 21 at 3:36
L1 is two bytes. – lirtosiast Jan 21 at 3:56
@ThomasKwa Oh. Dang. – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 21 at 3:57
I count 37 bytes as it is currently. (You can get 35.) – lirtosiast Jan 22 at 18:11

Rust, 79

Saved 8 bytes thanks to Shepmaster.
Saved 23 bytes thanks to ker.

I'm positive this could be golfed down a lot, but this is my first time writing a full Rust program.

fn b(a:&[&[u8]])->Vec<u8>{a[0].iter().zip(a[1]).map(|(c,d)|67-d-c*2).collect()}

Here's the ungolfed code and test cases in case anyone wants to try to shrink it.

fn b(a:&[&[u8]])->Vec<u8>{
fn main() {
    assert_eq!("ABCABCA", b(&[&[1, 0, 0, 1, 0, 0, 1], &[0, 1, 0, 0, 1, 0, 0]]));
    assert_eq!("BCBCACAA", b(&[&[0, 0, 0, 0, 1, 0, 1, 1], &[1, 0, 1, 0, 0, 0, 0, 0]]));
    assert_eq!("CCCCCCCCCC", b(&[&[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], &[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]));

The approach is pretty similar to my Python answer. The main difference being that I can't directly index strings, so I can't do the c-d trick.

share|improve this answer
would it be legal to use a closure instead of a function? then you could skip all the types in the declaration and just pass a[0] and a[1] as two separate arguments. – ker Jan 22 at 8:21
also using the 64-y-2*x trick from the Octave solution saves quite a few bytes due to being able to use u8 instead of usize: – ker Jan 22 at 8:28
@ker I'm not totally sure about using a closure. I would assume it's okay, because it's essentially an anonymous function, right? – Morgan Thrapp Jan 22 at 14:11
as long as you don't capture any surroundings it's exactly like an anonymous function. – ker Jan 22 at 15:18
@ker Then yeah, closure should be fine. – Morgan Thrapp Jan 22 at 15:28

Vitsy, 40 bytes

sigh My baby was not made to do array manipulation.

Expects input through STDIN (something I never do) with a leading ".


Explanation in the (soon available) verbose mode:

remove top;
make new stack;
remove top;
push length of stack;
repeat next instruction set top times;
begin recursive area;
push 6;
push 8;
multiply top two;
subtract top two;
push 1;
add top two;
goto top method;
end recursive area;
rotate right a stack;
push 6;
push 8;
multiply top two;
subtract top two;
push 2;
multiply top two;
toggle quote;
push cosine of top; // this is character literal "C"
toggle quote;
subtract top two;
push input item;
multiply top two;
output top as character;
rotate right a stack;
toggle quote;
toggle quote;
output top as character;
rotate right a stack;
remove top;
rotate right a stack;

This is getting golfed better real soon, people. I'm so sorry for its current length.

Basically, I treat the input as a string, and then manipulate from there.

Try it online!

share|improve this answer
:O Cannot wait until verbose mode. That will be interesting. Like the use of W! – Cᴏɴᴏʀ O'Bʀɪᴇɴ Jan 23 at 4:01
@Adnan It is the input tab in tryitonline, but on the local interpreter, simply run the program and input each set of 0 and 1 with a leading " and a trailing newline while the program is running (W technically is prompt). – VTCAKAVSMoACE Jan 23 at 14:08
Ahh, I gave the input in the arguments section :p. Nice answer though :) – Adnan Jan 23 at 14:10
@Adnan It took me a while to figure this out - Vitsy autoparses input if it recognizes that it's a double. You can technically have a leading anything except for numbers, and it'll work the same. – VTCAKAVSMoACE Jan 23 at 14:12
Heh, that is quite weird, but on the other side it can be useful. – Adnan Jan 23 at 14:33

CJam, 10 bytes


Input as a list of two lists, e.g.

[[1 0 0 1 0 0 1] [0 1 0 0 1 0 0]]

Test it here.


Treating the pairs as bits of a base-2 number, we get 2 for A, 1 for B and 0 for C.

'C  e# Push the character C.
q~  e# Read and evaluate input.
z   e# Transpose the pair of lists to get a list of pairs.
2fb e# Convert each pair from base 2.
f-  e# Subtract each result from the character C.
share|improve this answer

Python 3, 48 45 bytes

I thought I had an elegant solution, then I saw @Morgan Thrapp's answer...

edit: Saved three bytes thanks to the aforementioned.

lambda*x:['A'*a+b*'B'or'C'for a,b in zip(*x)]

lambda *x:[a*'A'or b*'B'or'C'for a,b in zip(*x)]

share|improve this answer
Ah nice. Didn't see lamba*x:. I always think it's as compact as can be then I get told/find even more tricks. I really like your solution btw, very nice. – Ogaday Jan 22 at 17:44

Java, 131 122 110 90 bytes

EDIT: Thanks to Bifz / FlagAsSpam for the help and inspiration

void x(int[]a,int[]b){int j=0;for(int i:a){System.out.print(i>0?"A":b[j]>0?"B":"C");j++;}}

First submission, naive Java solution. Can almost certainly be improved :)

static String x(int[]a,int[]b){String o="";for(int i=0;i<a.length;i++)o+=a[i]>0?"A":b[i]>0?"B":"C";return(o);} 

share|improve this answer
==1 can be >0; it would also be better for you to return o rather than printing. – lirtosiast Jan 22 at 0:47
How about: void x(int[]a,int[]b){for(int i=0;i<a.length;i++)System.out.print(a[i]>0?"A":b[i]>0?"B":"C");} (94 bytes)? You don't need the static declaration on functions. – VTCAKAVSMoACE Jan 22 at 23:07
You have to declare i first, +4 bytes :D – Bifz Jan 23 at 23:20

PowerShell, 40 Bytes


Takes input as two explicit arrays, e.g.. PS C:\Tools\Scripts\golfing> .\cheating-a-multiple-choice-test.ps1 @(1,0,0,1,0,0,1) @(0,1,0,0,1,0,0), and stores them in $a and $b. Next, loop through $a with $a|{...}. Each loop, we output a character indexed into the string "CBA", with the index decided by twice the current value $_, plus the value of $b indexed by our helper variable that's been pre-added then subtracted.

As an example, for the first test case, $a = @(1,0,0,1,0,0,1) and $b = @(0,1,0,0,1,0,0). The first loop iteration has $_ = 1, $d = $null (since $d hasn't previously been declared). We pre-add to $d so now $_ = 1 and $d = 1 (in PowerShell, $null + 1 = 1), meaning that $b[1-1] = $b[0] = 0. Then 2 * 1 + 0 = 2, so we index "CBA"[2], or A.

share|improve this answer

𝔼𝕊𝕄𝕚𝕟, 12 chars / 22 bytes


Try it here (Firefox only).


Translates to Javascript ES6 as

share|improve this answer

R 36 34 bytes


Two bytes saved removing unnecessary braces

share|improve this answer
You can save two bytes by removing the braces in the function definition. They aren't necessary since the function body consists of a single statement. – Alex A. Jan 22 at 0:33

Perl 5 - 47

Already 30 answers and no perl? Here is a naive first attempt then :-) Just the function:

sub x{($g,$h)=@_;map{$_?a:$h->[$i++]?b:c}@{$g}}


@f = (0, 0, 0, 0, 1, 0, 1, 1);
@s = (1, 0, 1, 0, 0, 0, 0, 0);

print x(\@f, \@s);

I'm pretty sure that something better could be done with regex, but I couldn't find how.

share|improve this answer

R 29 16 bytes


removed declaration of function since I saw it's common in other contests.

share|improve this answer

JavaScript ES6, 75 bytes

I went the extra mile to accept integer arguments instead of array arguments.



(a,b)=>              // input of two integers representing 8 answers (max value 255 each)
[...Array(8)]        // generates an array with 8 indices that allows .map() to work
.map((_,n)=>         // n is each index 0-7
'CBA'[...]           // reading character from string via index reference
      (...)          // grouping for division
       (a&...)       // AND operator to test if answer is A
          (s=128>>n) // calculating binary index in integer input and storing reference
       *2            // bias index in 'CBA' so truthy is 2 instead of 1
       +(b&s)        // AND operator to test if answer is B
      /s             // divide by binary index to convert AND operators to increments of 1
.join('')            // convert to string without commas

Credit to @ETHproductions for string indexing logic.

Test Here


console.log(f(0b01001001, 0b00100100));
console.log(f(0b00001011, 0b10100000));
console.log(f(0b00000000, 0b00000000));
<!-- results pane console output; see -->
<script src=""></script>


For 3 extra bytes, it can display the representation for up to 30 answers:

share|improve this answer

Retina, 46 bytes

+`%(.)(.* )(.)
[empty line]

Merges the two strings and chooses the letters according to the digit pairs.

Try it online here.

share|improve this answer

Lua, 87 Bytes

Simply testing the values in the arrays, and concatenating A, B or C.

function f(a,b)s=""for i=1,#a do s=s..(0<a[i]and"A"or 0<b[i]and"B"or"C")end print(s)end
share|improve this answer

F#, 33 bytes

Seq.map2(fun a b->67-a*2-b|>char)

That's a partially applied function that takes two int sequences - two arrays work fine - and returns a new sequence of characters representing the correct answers. =)

share|improve this answer

Seriously, 14 bytes


Try It Online

Probably due to a bug in the safe mode version of the interpreter, you must add an X to get it to work right in the online version. Download the local version to get the above program working correctly as-is.

It's too short to warrant a full explanation, so I'll just say: it uses the same algorithm as the Jelly answer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.