41
9
Introduction
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:
BCAABABA
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!
Task
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
Rules
- Input can be in the any form you like, like
[1, 0, 0, 1]
or1001
. - 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 code-golf, 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]
Output: ABCABCA
Input: [0, 0, 0, 0, 1, 0, 1, 1] [1, 0, 1, 0, 0, 0, 0, 0]
Output: BCBCACAA
Input: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
Output: CCCCCCCCCC
Leaderboard
var QUESTION_ID=69770,OVERRIDE_USER=34388;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+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}}",e.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,link:e.link}});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}}",o.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;font-family:Arial}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <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>
75Here is my solution. It is written in English (interpreter freely available wherever you are), and is
Study.
. Six bytes. Beat that. – Conor O'Brien – 2016-01-20T19:01:22.87758
@CᴏɴᴏʀO'Bʀɪᴇɴ Sadly, English does not meet our standards of a programming language and is therefore not a valid submission :p
– Adnan – 2016-01-20T19:05:51.39717You 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 – 2016-01-20T23:29:15.573
4You 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 – 2016-01-21T09:23:21.660
2@Doorknob another method: give 8 bytes for A, and find that of B only if the question's answer is not A. E.g. [0,0,1,1,0,1,0,1],[1,0,0,0,1,0,1,0] becomes [0,0,1,1,0,1,0,1],[1,0,1,1], 12 bits this way, but may be any integer within [8,16], with a mean(or maybe not a mean) of 13.33333333333 – busukxuan – 2016-01-21T14:09:01.273
1How does taking input as "two numbers in binary" work with test case #3? That is, how can the program know that it's specifically the 10-bit representation of
0b0000000000
? – Tim Pederick – 2016-01-21T15:29:56.4571Now convert it to base 64 for maximum compression, and write it on your hand! – Cyoce – 2016-01-21T15:42:34.467
@TimPederick it can also be interpreted as a string. – Adnan – 2016-01-21T15:43:52.787
@Adnan How doesn't it? It's Turing-complete and fulfills all the listed requirements. – Fax – 2016-01-21T18:24:21.430
Can we take the test an arbitrary number of times before taking it for reals. – emory – 2016-01-21T19:29:31.047
5English satisfies all the criteria. The only problem is there isn't an interpreter available before this question is asked. – jimmy23013 – 2016-01-22T02:06:46.510
@jimmy23013 Then perhaps a question should be asked to write an interpreter for English in as few bytes as possible. – kasperd – 2016-01-23T09:43:37.660
@kasperd I've already written one! (31 bytes) Run
interpret ‘yourprogramhere’
(with quotes) in English to interpret an English program. – wizzwizz4 – 2016-01-23T10:00:35.233All it takes is one 'Choose all that apply' type question, and we're all screwed! – Rob P. – 2016-01-25T03:14:28.257