Talk interpreterHalloween Golf: The 2spooky4me Challenge!Make a 3var interpreter!Calculate Phi (not Pi)Product over a rangeInterpret DOGO!StringgnirtSStringgnirtSStringgnirtSPrime or highest factorInterpret Volatile

What does Ambassador Taylor have to do with the Trump impeachment inquiry?

Was it possible for a message from Paris to reach London within 48 hours in 1782?

40 amp range outlet as extension cord source

NP-hard problems but only for n≥3

What definition takes up more memory, def or chardef (considering def contains a single character)?

Are we sinners because we sin or do we sin because we are sinners?

What is :>filename.txt Doing?

What is White's motivation to give up the Queen?

Why would prey creatures not hate predator creatures?

What exactly is "Japanese" Salt and Pepper?

Does a resurrected wizard remember their prepared spells?

Can a website incur liability for linking to a funding campaign for a lawsuit against it?

Is the genre 'fantasy' still fantasy without magic?

What is the "two-drive trick" that can read Amiga disks on a PC?

Who was the first human to sleep - perchance to dream - on the Moon?

Where does the budget surplus of a conference go?

Outlining the climax made me lose interest in writing the actual story

TSP with revenue maximization

Can the treble clef be used instead of the bass clef in piano music?

How developed is Huttese?

Why telnet is considered to be a protocol? Isn't it just a simple TCP send/echo program?

Why has no one requested the tape of the Trump/Ukraine call?

If you discard Immortal Phoenix, does it return to your hand?

Getting into new PhD after failing comps



Talk interpreter


Halloween Golf: The 2spooky4me Challenge!Make a 3var interpreter!Calculate Phi (not Pi)Product over a rangeInterpret DOGO!StringgnirtSStringgnirtSStringgnirtSPrime or highest factorInterpret Volatile






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;









9















$begingroup$


"Talk" is a baroquified accumulator-based language that is created in response to Dennis's quote on talk.tryitonline.net.



Waiting for someone to create an esolang called talk. 


. The "Talk" language has 4 commands:




  • 00 If the accumulator is 0, set the accumulator to 0.


  • 01 If the accumulator is 0, set the accumulator to 1.


  • 10 If the accumulator is 1, set the accumulator to 0.


  • 11 If the accumulator is 1, set the accumulator to 1.

Input:



  • The input can be taken via any acceptable input method by our standard I/O rules.


  • There are two inputs, the initial accumulator value and the program. You can merge these two inputs into one input or split your input into valid commands (e.g. taking them as a list; e.g. [00, 01, 00]) if you like.


Output:



  • On the end of a command execution, the accumulator is outputted implicitly.

Rules:



  • The input can be a single string or character list.

  • As this is code-golf, the shortest answer, in bytes, wins.

  • We take digits or strings/characters.

    Test cases:



0 0001111101 -> 1
0 000100 -> 1
0 11001000 -> 0


Leaderboards



Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.



To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:



# Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:



# Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:



# Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the leaderboard snippet:



# [><>](http://esolangs.org/wiki/Fish), 121 bytes





var QUESTION_ID=190819;
var OVERRIDE_USER=8478;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d)return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTERfunction commentUrl(d,e)return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTERfunction getAnswers()jQuery.ajax(url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d))function getComments()jQuery.ajax(url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d)d.items.forEach(function(e)e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)),d.has_more?getComments():more_answers?getAnswers():process())getAnswers();var SCORE_REG=function()var d=String.raw`hd`,e=String.raw`-?d+.?d*`,f=String.raw`[^n<>]*`,g=String.raw`<s>$f</s>(),OVERRIDE_REG=/^Overrides*header:s*/i;function getAuthorName(d)return d.owner.display_namefunction process()var d=[];answers.forEach(function(n)var o=n.body;n.comments.forEach(function(q)OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>"));var p=o.match(SCORE_REG);p&&d.push(user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link)),d.sort(function(n,o)var p=n.size,q=o.size;return p-q);var e=,f=1,g=null,h=1;d.forEach(function(n)lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p);var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o)return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0);for(var l=0;l<j.length;++l)var m=jQuery("#language-template").html(),k=j[l];m=m.replace("LANGUAGE",k.lang).replace("NAME",k.user).replace("SIZE",k.size).replace("LINK",k.link),m=jQuery(m),jQuery("#languages").append(m)

bodytext-align:left!important#answer-listpadding:10px;float:left#language-listpadding:10px;float:lefttable theadfont-weight:700table tdpadding:5px

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <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><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><table style="display: none"> <tbody id="answer-template"> <tr><td>PLACE</td><td>NAME</td><td>LANGUAGE</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>LANGUAGE</td><td>NAME</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> 












share|improve this question











$endgroup$










  • 3




    $begingroup$
    So there's two inputs, the sequence of commands and the initial accumulator value?
    $endgroup$
    – xnor
    Aug 25 at 6:15






  • 4




    $begingroup$
    Some test cases that don't change the accumulator, start with 1 in the accumulator or have no instructions would be good
    $endgroup$
    – Jo King
    Aug 25 at 8:04






  • 8




    $begingroup$
    Can Talk really be considered a programming language?
    $endgroup$
    – Luis Mendo
    Aug 25 at 10:05







  • 8




    $begingroup$
    @A_ That comment was probably meant as a joke. Back in the day, a language called Lang would have a URL lang.tryitonline.net (now it's tio.run/#lang). So a language called Talk would cause confusion with the URL for the then-recently created chatroom, which is talk.tryitonline.net
    $endgroup$
    – Luis Mendo
    Aug 25 at 10:26







  • 7




    $begingroup$
    In the future, please refrain from changing I/O after a number of answers have been posted. I came back today and having mapped inputs allowed makes this an entirely different challenge from what I answered.
    $endgroup$
    – GammaFunction
    Aug 25 at 13:20

















9















$begingroup$


"Talk" is a baroquified accumulator-based language that is created in response to Dennis's quote on talk.tryitonline.net.



Waiting for someone to create an esolang called talk. 


. The "Talk" language has 4 commands:




  • 00 If the accumulator is 0, set the accumulator to 0.


  • 01 If the accumulator is 0, set the accumulator to 1.


  • 10 If the accumulator is 1, set the accumulator to 0.


  • 11 If the accumulator is 1, set the accumulator to 1.

Input:



  • The input can be taken via any acceptable input method by our standard I/O rules.


  • There are two inputs, the initial accumulator value and the program. You can merge these two inputs into one input or split your input into valid commands (e.g. taking them as a list; e.g. [00, 01, 00]) if you like.


Output:



  • On the end of a command execution, the accumulator is outputted implicitly.

Rules:



  • The input can be a single string or character list.

  • As this is code-golf, the shortest answer, in bytes, wins.

  • We take digits or strings/characters.

    Test cases:



0 0001111101 -> 1
0 000100 -> 1
0 11001000 -> 0


Leaderboards



Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.



To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:



# Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:



# Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:



# Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the leaderboard snippet:



# [><>](http://esolangs.org/wiki/Fish), 121 bytes





var QUESTION_ID=190819;
var OVERRIDE_USER=8478;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d)return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTERfunction commentUrl(d,e)return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTERfunction getAnswers()jQuery.ajax(url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d))function getComments()jQuery.ajax(url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d)d.items.forEach(function(e)e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)),d.has_more?getComments():more_answers?getAnswers():process())getAnswers();var SCORE_REG=function()var d=String.raw`hd`,e=String.raw`-?d+.?d*`,f=String.raw`[^n<>]*`,g=String.raw`<s>$f</s>(),OVERRIDE_REG=/^Overrides*header:s*/i;function getAuthorName(d)return d.owner.display_namefunction process()var d=[];answers.forEach(function(n)var o=n.body;n.comments.forEach(function(q)OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>"));var p=o.match(SCORE_REG);p&&d.push(user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link)),d.sort(function(n,o)var p=n.size,q=o.size;return p-q);var e=,f=1,g=null,h=1;d.forEach(function(n)lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p);var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o)return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0);for(var l=0;l<j.length;++l)var m=jQuery("#language-template").html(),k=j[l];m=m.replace("LANGUAGE",k.lang).replace("NAME",k.user).replace("SIZE",k.size).replace("LINK",k.link),m=jQuery(m),jQuery("#languages").append(m)

bodytext-align:left!important#answer-listpadding:10px;float:left#language-listpadding:10px;float:lefttable theadfont-weight:700table tdpadding:5px

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <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><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><table style="display: none"> <tbody id="answer-template"> <tr><td>PLACE</td><td>NAME</td><td>LANGUAGE</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>LANGUAGE</td><td>NAME</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> 












share|improve this question











$endgroup$










  • 3




    $begingroup$
    So there's two inputs, the sequence of commands and the initial accumulator value?
    $endgroup$
    – xnor
    Aug 25 at 6:15






  • 4




    $begingroup$
    Some test cases that don't change the accumulator, start with 1 in the accumulator or have no instructions would be good
    $endgroup$
    – Jo King
    Aug 25 at 8:04






  • 8




    $begingroup$
    Can Talk really be considered a programming language?
    $endgroup$
    – Luis Mendo
    Aug 25 at 10:05







  • 8




    $begingroup$
    @A_ That comment was probably meant as a joke. Back in the day, a language called Lang would have a URL lang.tryitonline.net (now it's tio.run/#lang). So a language called Talk would cause confusion with the URL for the then-recently created chatroom, which is talk.tryitonline.net
    $endgroup$
    – Luis Mendo
    Aug 25 at 10:26







  • 7




    $begingroup$
    In the future, please refrain from changing I/O after a number of answers have been posted. I came back today and having mapped inputs allowed makes this an entirely different challenge from what I answered.
    $endgroup$
    – GammaFunction
    Aug 25 at 13:20













9













9









9


2



$begingroup$


"Talk" is a baroquified accumulator-based language that is created in response to Dennis's quote on talk.tryitonline.net.



Waiting for someone to create an esolang called talk. 


. The "Talk" language has 4 commands:




  • 00 If the accumulator is 0, set the accumulator to 0.


  • 01 If the accumulator is 0, set the accumulator to 1.


  • 10 If the accumulator is 1, set the accumulator to 0.


  • 11 If the accumulator is 1, set the accumulator to 1.

Input:



  • The input can be taken via any acceptable input method by our standard I/O rules.


  • There are two inputs, the initial accumulator value and the program. You can merge these two inputs into one input or split your input into valid commands (e.g. taking them as a list; e.g. [00, 01, 00]) if you like.


Output:



  • On the end of a command execution, the accumulator is outputted implicitly.

Rules:



  • The input can be a single string or character list.

  • As this is code-golf, the shortest answer, in bytes, wins.

  • We take digits or strings/characters.

    Test cases:



0 0001111101 -> 1
0 000100 -> 1
0 11001000 -> 0


Leaderboards



Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.



To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:



# Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:



# Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:



# Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the leaderboard snippet:



# [><>](http://esolangs.org/wiki/Fish), 121 bytes





var QUESTION_ID=190819;
var OVERRIDE_USER=8478;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d)return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTERfunction commentUrl(d,e)return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTERfunction getAnswers()jQuery.ajax(url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d))function getComments()jQuery.ajax(url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d)d.items.forEach(function(e)e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)),d.has_more?getComments():more_answers?getAnswers():process())getAnswers();var SCORE_REG=function()var d=String.raw`hd`,e=String.raw`-?d+.?d*`,f=String.raw`[^n<>]*`,g=String.raw`<s>$f</s>(),OVERRIDE_REG=/^Overrides*header:s*/i;function getAuthorName(d)return d.owner.display_namefunction process()var d=[];answers.forEach(function(n)var o=n.body;n.comments.forEach(function(q)OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>"));var p=o.match(SCORE_REG);p&&d.push(user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link)),d.sort(function(n,o)var p=n.size,q=o.size;return p-q);var e=,f=1,g=null,h=1;d.forEach(function(n)lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p);var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o)return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0);for(var l=0;l<j.length;++l)var m=jQuery("#language-template").html(),k=j[l];m=m.replace("LANGUAGE",k.lang).replace("NAME",k.user).replace("SIZE",k.size).replace("LINK",k.link),m=jQuery(m),jQuery("#languages").append(m)

bodytext-align:left!important#answer-listpadding:10px;float:left#language-listpadding:10px;float:lefttable theadfont-weight:700table tdpadding:5px

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <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><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><table style="display: none"> <tbody id="answer-template"> <tr><td>PLACE</td><td>NAME</td><td>LANGUAGE</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>LANGUAGE</td><td>NAME</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> 












share|improve this question











$endgroup$




"Talk" is a baroquified accumulator-based language that is created in response to Dennis's quote on talk.tryitonline.net.



Waiting for someone to create an esolang called talk. 


. The "Talk" language has 4 commands:




  • 00 If the accumulator is 0, set the accumulator to 0.


  • 01 If the accumulator is 0, set the accumulator to 1.


  • 10 If the accumulator is 1, set the accumulator to 0.


  • 11 If the accumulator is 1, set the accumulator to 1.

Input:



  • The input can be taken via any acceptable input method by our standard I/O rules.


  • There are two inputs, the initial accumulator value and the program. You can merge these two inputs into one input or split your input into valid commands (e.g. taking them as a list; e.g. [00, 01, 00]) if you like.


Output:



  • On the end of a command execution, the accumulator is outputted implicitly.

Rules:



  • The input can be a single string or character list.

  • As this is code-golf, the shortest answer, in bytes, wins.

  • We take digits or strings/characters.

    Test cases:



0 0001111101 -> 1
0 000100 -> 1
0 11001000 -> 0


Leaderboards



Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.



To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:



# Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:



# Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:



# Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the leaderboard snippet:



# [><>](http://esolangs.org/wiki/Fish), 121 bytes





var QUESTION_ID=190819;
var OVERRIDE_USER=8478;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d)return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTERfunction commentUrl(d,e)return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTERfunction getAnswers()jQuery.ajax(url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d))function getComments()jQuery.ajax(url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d)d.items.forEach(function(e)e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)),d.has_more?getComments():more_answers?getAnswers():process())getAnswers();var SCORE_REG=function()var d=String.raw`hd`,e=String.raw`-?d+.?d*`,f=String.raw`[^n<>]*`,g=String.raw`<s>$f</s>(),OVERRIDE_REG=/^Overrides*header:s*/i;function getAuthorName(d)return d.owner.display_namefunction process()var d=[];answers.forEach(function(n)var o=n.body;n.comments.forEach(function(q)OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>"));var p=o.match(SCORE_REG);p&&d.push(user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link)),d.sort(function(n,o)var p=n.size,q=o.size;return p-q);var e=,f=1,g=null,h=1;d.forEach(function(n)lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p);var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o)return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0);for(var l=0;l<j.length;++l)var m=jQuery("#language-template").html(),k=j[l];m=m.replace("LANGUAGE",k.lang).replace("NAME",k.user).replace("SIZE",k.size).replace("LINK",k.link),m=jQuery(m),jQuery("#languages").append(m)

bodytext-align:left!important#answer-listpadding:10px;float:left#language-listpadding:10px;float:lefttable theadfont-weight:700table tdpadding:5px

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <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><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><table style="display: none"> <tbody id="answer-template"> <tr><td>PLACE</td><td>NAME</td><td>LANGUAGE</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>LANGUAGE</td><td>NAME</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> 








var QUESTION_ID=190819;
var OVERRIDE_USER=8478;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d)return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTERfunction commentUrl(d,e)return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTERfunction getAnswers()jQuery.ajax(url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d))function getComments()jQuery.ajax(url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d)d.items.forEach(function(e)e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)),d.has_more?getComments():more_answers?getAnswers():process())getAnswers();var SCORE_REG=function()var d=String.raw`hd`,e=String.raw`-?d+.?d*`,f=String.raw`[^n<>]*`,g=String.raw`<s>$f</s>(),OVERRIDE_REG=/^Overrides*header:s*/i;function getAuthorName(d)return d.owner.display_namefunction process()var d=[];answers.forEach(function(n)var o=n.body;n.comments.forEach(function(q)OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>"));var p=o.match(SCORE_REG);p&&d.push(user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link)),d.sort(function(n,o)var p=n.size,q=o.size;return p-q);var e=,f=1,g=null,h=1;d.forEach(function(n)lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p);var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o)return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0);for(var l=0;l<j.length;++l)var m=jQuery("#language-template").html(),k=j[l];m=m.replace("LANGUAGE",k.lang).replace("NAME",k.user).replace("SIZE",k.size).replace("LINK",k.link),m=jQuery(m),jQuery("#languages").append(m)

bodytext-align:left!important#answer-listpadding:10px;float:left#language-listpadding:10px;float:lefttable theadfont-weight:700table tdpadding:5px

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <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><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><table style="display: none"> <tbody id="answer-template"> <tr><td>PLACE</td><td>NAME</td><td>LANGUAGE</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>LANGUAGE</td><td>NAME</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> 





var QUESTION_ID=190819;
var OVERRIDE_USER=8478;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d)return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTERfunction commentUrl(d,e)return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTERfunction getAnswers()jQuery.ajax(url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d))function getComments()jQuery.ajax(url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d)d.items.forEach(function(e)e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)),d.has_more?getComments():more_answers?getAnswers():process())getAnswers();var SCORE_REG=function()var d=String.raw`hd`,e=String.raw`-?d+.?d*`,f=String.raw`[^n<>]*`,g=String.raw`<s>$f</s>(),OVERRIDE_REG=/^Overrides*header:s*/i;function getAuthorName(d)return d.owner.display_namefunction process()var d=[];answers.forEach(function(n)var o=n.body;n.comments.forEach(function(q)OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>"));var p=o.match(SCORE_REG);p&&d.push(user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link)),d.sort(function(n,o)var p=n.size,q=o.size;return p-q);var e=,f=1,g=null,h=1;d.forEach(function(n)lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p);var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o)return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0);for(var l=0;l<j.length;++l)var m=jQuery("#language-template").html(),k=j[l];m=m.replace("LANGUAGE",k.lang).replace("NAME",k.user).replace("SIZE",k.size).replace("LINK",k.link),m=jQuery(m),jQuery("#languages").append(m)

bodytext-align:left!important#answer-listpadding:10px;float:left#language-listpadding:10px;float:lefttable theadfont-weight:700table tdpadding:5px

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <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><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><table style="display: none"> <tbody id="answer-template"> <tr><td>PLACE</td><td>NAME</td><td>LANGUAGE</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>LANGUAGE</td><td>NAME</td><td><a href="LINK">SIZE</a></td></tr></tbody> </table> 






code-golf interpreter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 25 at 13:30







A _

















asked Aug 25 at 5:41









A _A _

4,7671 gold badge10 silver badges39 bronze badges




4,7671 gold badge10 silver badges39 bronze badges










  • 3




    $begingroup$
    So there's two inputs, the sequence of commands and the initial accumulator value?
    $endgroup$
    – xnor
    Aug 25 at 6:15






  • 4




    $begingroup$
    Some test cases that don't change the accumulator, start with 1 in the accumulator or have no instructions would be good
    $endgroup$
    – Jo King
    Aug 25 at 8:04






  • 8




    $begingroup$
    Can Talk really be considered a programming language?
    $endgroup$
    – Luis Mendo
    Aug 25 at 10:05







  • 8




    $begingroup$
    @A_ That comment was probably meant as a joke. Back in the day, a language called Lang would have a URL lang.tryitonline.net (now it's tio.run/#lang). So a language called Talk would cause confusion with the URL for the then-recently created chatroom, which is talk.tryitonline.net
    $endgroup$
    – Luis Mendo
    Aug 25 at 10:26







  • 7




    $begingroup$
    In the future, please refrain from changing I/O after a number of answers have been posted. I came back today and having mapped inputs allowed makes this an entirely different challenge from what I answered.
    $endgroup$
    – GammaFunction
    Aug 25 at 13:20












  • 3




    $begingroup$
    So there's two inputs, the sequence of commands and the initial accumulator value?
    $endgroup$
    – xnor
    Aug 25 at 6:15






  • 4




    $begingroup$
    Some test cases that don't change the accumulator, start with 1 in the accumulator or have no instructions would be good
    $endgroup$
    – Jo King
    Aug 25 at 8:04






  • 8




    $begingroup$
    Can Talk really be considered a programming language?
    $endgroup$
    – Luis Mendo
    Aug 25 at 10:05







  • 8




    $begingroup$
    @A_ That comment was probably meant as a joke. Back in the day, a language called Lang would have a URL lang.tryitonline.net (now it's tio.run/#lang). So a language called Talk would cause confusion with the URL for the then-recently created chatroom, which is talk.tryitonline.net
    $endgroup$
    – Luis Mendo
    Aug 25 at 10:26







  • 7




    $begingroup$
    In the future, please refrain from changing I/O after a number of answers have been posted. I came back today and having mapped inputs allowed makes this an entirely different challenge from what I answered.
    $endgroup$
    – GammaFunction
    Aug 25 at 13:20







3




3




$begingroup$
So there's two inputs, the sequence of commands and the initial accumulator value?
$endgroup$
– xnor
Aug 25 at 6:15




$begingroup$
So there's two inputs, the sequence of commands and the initial accumulator value?
$endgroup$
– xnor
Aug 25 at 6:15




4




4




$begingroup$
Some test cases that don't change the accumulator, start with 1 in the accumulator or have no instructions would be good
$endgroup$
– Jo King
Aug 25 at 8:04




$begingroup$
Some test cases that don't change the accumulator, start with 1 in the accumulator or have no instructions would be good
$endgroup$
– Jo King
Aug 25 at 8:04




8




8




$begingroup$
Can Talk really be considered a programming language?
$endgroup$
– Luis Mendo
Aug 25 at 10:05





$begingroup$
Can Talk really be considered a programming language?
$endgroup$
– Luis Mendo
Aug 25 at 10:05





8




8




$begingroup$
@A_ That comment was probably meant as a joke. Back in the day, a language called Lang would have a URL lang.tryitonline.net (now it's tio.run/#lang). So a language called Talk would cause confusion with the URL for the then-recently created chatroom, which is talk.tryitonline.net
$endgroup$
– Luis Mendo
Aug 25 at 10:26





$begingroup$
@A_ That comment was probably meant as a joke. Back in the day, a language called Lang would have a URL lang.tryitonline.net (now it's tio.run/#lang). So a language called Talk would cause confusion with the URL for the then-recently created chatroom, which is talk.tryitonline.net
$endgroup$
– Luis Mendo
Aug 25 at 10:26





7




7




$begingroup$
In the future, please refrain from changing I/O after a number of answers have been posted. I came back today and having mapped inputs allowed makes this an entirely different challenge from what I answered.
$endgroup$
– GammaFunction
Aug 25 at 13:20




$begingroup$
In the future, please refrain from changing I/O after a number of answers have been posted. I came back today and having mapped inputs allowed makes this an entirely different challenge from what I answered.
$endgroup$
– GammaFunction
Aug 25 at 13:20










31 Answers
31






active

oldest

votes













1 2
next












19

















$begingroup$


Jelly, 3 bytes



y@/


Input is a single list: the accumulator, followed by the pairs.



Try it online!



How it works



The y atom performs transliteration; [a,b]yc replaces a with b, so it returns b if a=c and c if a≠c.



y@/ folds/reduces the input by y with swapped arguments, performing one transliteration per pair.






share|improve this answer










$endgroup$










  • 12




    $begingroup$
    This is the only Jelly answer that I have seen so far that only uses ASCII characters.
    $endgroup$
    – A _
    Aug 26 at 0:38






  • 1




    $begingroup$
    There were a few. Look ma, no Unicode!
    $endgroup$
    – Dennis
    Aug 28 at 12:47


















21

















$begingroup$


Python 3, 43 bytes





lambda s:re.sub("00|11","",s)[-1]
import re


Try it online!



The function takes a single string as input, where the first character is the initial state and the rest of the string represents the commands. This solution can be easily ported to other languages that have better support for regular expressions.



The difficult part is to prove the solution yields the correct outcome. To see this, we need a deep analysis of the commands. Firstly, we can see the commands have the following properties:




  • Property (1): commands 00 and 11 retain the accumulator state.


  • Property (2): commands 01 and 10 make the accumulator state the same as the second bit regardless of its original state.

Therefore, the final accumulator state is:




  • Case 1: If no 01 or 10 command exists, the final state is the same as the initial state.


  • Case 2: Otherwise, the last bit of the last 10 or 01 command.

Next we will show the solution yields the correct outcome in both cases. We will prove the statement for the final state 0 and the final state of 1 can be proved analogously. If the final state is 0 the input is in either of the following forms:




  • ^02k+111(11|00)*



    For Case 1, the input string s must start with 2k+1 0s, followed by 11 and 00 commands. Eliminating 00s and 11s yields a single 0, which is the final state.




  • .+102k+111(11|00)*



    For Case 2, the input string ends with a 10 command, followed by zero or more 00 and 11 s. This pattern is equivalent to a 1 followed by 2k+1 0s, and then zero or more 11s and 00s. Eliminating 00s and 11s leaves behind the last one of the 2k+1 0s at the end of the string, which represents the final state.



Based on all the above, after eliminating 00s and 11s simultaneously in one single pass (01001 is a counter-example if 00 is eliminated in one pass and then 11 in another pass) from the input s, the last character is the final state. Hence the correctness of the solution is proved.






share|improve this answer












$endgroup$














  • $begingroup$
    Welcome to PPCG! Excellent answer, and a nice formal proof to go with it!
    $endgroup$
    – GammaFunction
    Aug 25 at 10:21






  • 3




    $begingroup$
    Thanks. I feel that people may doubt such a simple solution yields the correct outcome at the first glance. So there is a need to provide a proof for that.
    $endgroup$
    – Joel
    Aug 25 at 10:24


















9

















$begingroup$


Perl 6, 17 bytes





m/.)>[(.)$0]*$/


Try it online!



Takes advantage of "You can merge these two inputs into one input if you like" by taking input as the accumulator value concatenated with the commands e.g. 1,[00,11] is 10011. If this isn't okay, than it's only 5 extra bytes to take it as f(accumulator, commands). Returns a match object that can be coerced to a string.



Explanation:



 # Anonymous code block
m/ / # Find the first match from the input
.)> # Capture a number
[ ]* # Followed by any number of
(.)$0 # Pairs of identical characters
$ # Ending the string


Basically this works because the 00 and 11 commands do literally nothing, while the 01 and 10 commands just set the accumulator to the second digit of the command. If there are no commands, then it takes the initial value of the accumulator instead.






share|improve this answer












$endgroup$






















    6

















    $begingroup$


    Zsh, 33 bytes



    The character list is passed as arguments, the initial value of the accumulator is passed as stdin.





    read a
    for x y;a=$[x^a?a:y]
    <<<$a


    Try it online!




    39 bytes: If the commands must be a single string



    Input is accumulator commands as arguments.



    for x y ($(s::)2)1=$[x^$1?$1:y]
    <<<$1


    Try it online!




    For fun, here's a 50 byte recursive one-liner (TIO):





    <<<$$2+`f $[$1^$2[1]?$1:$2[2]] $2:2`:-$1





    share|improve this answer












    $endgroup$






















      6

















      $begingroup$


      Python 3, 52 bytes





      f=lambda a,s:s and f([s[1],a][s[0]==s[1]],s[2:])or a


      Try it online!



      Fixed inconsistent return type thanks to Chas Brown



      Takes input as two strings; the accumulator and the code.






      share|improve this answer












      $endgroup$














      • $begingroup$
        Oh no, that was fast.
        $endgroup$
        – HighlyRadioactive
        Aug 25 at 7:19






      • 1




        $begingroup$
        Nice but it has this potential problem - f(1,'11')==f(1,'01') is False; it sometimes returns an int and sometimes a str. So maybe specify it takes acc input as a string?
        $endgroup$
        – Chas Brown
        Aug 25 at 7:42











      • $begingroup$
        @ChasBrown Good call, that's much simpler than what I was thinking about.
        $endgroup$
        – negative seven
        Aug 25 at 7:48










      • $begingroup$
        Nice, but since your function is recursive, it cannot be anonymous. It should be 52 bytes.
        $endgroup$
        – Jitse
        Aug 26 at 9:48


















      5

















      $begingroup$


      Brachylog, 11 9 bytes



      tġ₂≠ˢtt|h


      Try it online!



      Since it's been long enough that I've been able to forget the notion of printing the accumulator after each command, I've formulated a significantly less naïve solution with some inspiration from Jo King's Perl answer.



       | The output is
      tt the last element of the last element of
      t the last element of the input
      ġ₂ split into length-2 slices
      ≠ˢ with equal pairs removed.
      | If there is no such element, the input
      h 's first element is the output.


      Old solution:




      Brachylog, 18 16 bytes



      ġ₂ᵗcth~h?ttˡ


      Try it online!



      -2 bytes from changing the input format.






      share|improve this answer












      $endgroup$






















        5

















        $begingroup$

        JavaScript (ES6), 27 bytes



        Takes input as (a)(code), where code is a is list of 2-bit integers.



        a=>c=>c.map(x=>a^=x==a+1)|a


        Try it online!




        JavaScript (ES6),  47  40 bytes



        Takes input as (a)(code), where code is a string.



        a=>c=>c.replace(/../g,x=>a^=x%4==a+1)&&a


        Try it online!



        How?



        All possible cases are summarized below. The only two cases where we need to toggle the accumulator are $(a=0,x=01_2)$ and $(a=1,x=10_2)$.



         a | x (bin) | int(x) % 4 | a + 1 | equal?
        ----+---------+------------+-------+--------
        0 | "00" | 0 % 4 = 0 | 1 | N
        1 | "00" | 0 % 4 = 0 | 2 | N
        0 | "01" | 1 % 4 = 1 | 1 | Y
        1 | "01" | 1 % 4 = 1 | 2 | N
        0 | "10" | 10 % 4 = 2 | 1 | N
        1 | "10" | 10 % 4 = 2 | 2 | Y
        0 | "11" | 11 % 4 = 3 | 1 | N
        1 | "11" | 11 % 4 = 3 | 2 | N





        share|improve this answer












        $endgroup$






















          4

















          $begingroup$


          sed -E, 26 19 bytes



          A whopping -7 bytes from @Cowsquack by realizing removing all pairs works as well.



          s/(.)1//g
          s/.*B//


          Takes input concatenated together on stdin. Inspired by Jo King's Perl answer.
          Strip trailing pairs Remove all pairs, then get last digit.



          Try it online!
          Try it online!






          share|improve this answer












          $endgroup$










          • 1




            $begingroup$
            The last line can be simply s/.*B//, but anyways changing the approach slightly gives an even shorter 19 bytes Try it online!
            $endgroup$
            – Kritixi Lithos
            Aug 25 at 10:54






          • 1




            $begingroup$
            Huh, I didn't think that s/(.)1//g would work, since it could remove the end of one pair and the start of the next, but it still works out. Excellent!
            $endgroup$
            – GammaFunction
            Aug 25 at 12:35










          • $begingroup$
            @GammaFunction s/(.)1//g is equivalent to s/00|11//g as shown in my solution.
            $endgroup$
            – Joel
            Aug 25 at 15:26


















          4

















          $begingroup$


          Retina 0.8.2, 18 11 bytes



          (.)1

          !`.$


          Try it online! Link includes test cases. Takes input concatenated. Saved 6 bytes thanks to @CowsQuack for pointing out that removing all doubled characters and then taking the last remaining character works, although in fact the port of @JoKing's original answer could have been golfed by 3 bytes even without that trick.






          share|improve this answer












          $endgroup$














          • $begingroup$
            12 bytes Try it online!
            $endgroup$
            – Kritixi Lithos
            Aug 25 at 10:52










          • $begingroup$
            @Cowsquack D'oh, once you think about separating the stages, that's a 2-byte saving already, then another byte saved because you can use !`.$, and then another 4 bytes because you don't have to limit to trailing pairs...
            $endgroup$
            – Neil
            Aug 25 at 15:12


















          3

















          $begingroup$


          Perl 5 -p, 37 33 bytes





          $=<>;s/(.)(.)/$=$2if$==$1/ge}improve this answer










          $endgroup$













            share 









            3















            3











            3







            $begingroup$


            Perl 5 -p, 37 33 bytes





            $=<>;s/(.)(.)/$=$2if$==$1/geimprove this answer












            $endgroup$




            Perl 5 -p, 37 33 bytes





            $=<>;s/(.)(.)/$=$2if$==$1/ge 











            1

















            $begingroup$


            Keg + Reg, 17 bytes



            "(!;2/i 











            1

















            $begingroup$


            Runic Enchantments, 28 bytes



            /~@/i~/i<
            /=?/~iR:liimprove this answer










            $endgroup$



















              $endgroup$




              Runic Enchantments, 28 bytes



              /~@/i~/i<
              /=?/~iR:li{l1-=?!


              Try it online!



              Takes input as a series of space separated bytes (Runic does not understand lists). The first byte is the initial state and every other byte is the program. No validation is performed (i.e. it assumes only valid programs are given as input and it doesn't care what value is used to represent 0 and 1).







              share|improve this answer













              share|improve this answer




              share|improve this answer










              answered Aug 25 at 21:57









              Draco18sDraco18s

              2,7637 silver badges24 bronze badges




              2,7637 silver badges24 bronze badges
























                  1

















                  $begingroup$

                  x86 Assembly, 33 Bytes



                  Takes the initial accumulator state in CL (integer 0 or 1) and the address of the commands as a zero-terminated ASCII String in ESI. Leaves the final accumulator state in CL.



                  Point the call instruction at offset 0x1B (label interpret in the Explanation).



                  3C 30 74 03 B0 01 C3 30 C0 C3 E8 F1 FF FF FF 38
                  C8 AC 75 07 E8 E7 FF FF FF 88 C1 AC 84 C0 75 EA
                  C3


                  Explanation (Using Intel Syntax):



                  ; function to convert ASCII '1'/'0' into 0 or 1 int values (from AL to AL)
                  ctob:
                  CMP AL, 0x30 ; '0'
                  JE .zero
                  MOV AL, 1
                  RET
                  .zero:
                  XOR AL, AL
                  RET

                  ; interpreting function
                  interp_lp:
                  CALL ctob ; convert to number
                  CMP AL, CL ; compare to current accumulator
                  LODSB ; read the next character of the string
                  ; this doesn't affect any flags and we need to do
                  ; it in both cases anyway
                  JNE interpret ; if AL != CL (from above, not the new value of AL), skip forward
                  CALL ctob ; convert AL to number
                  MOV CL, AL ; store AL in CL
                  interpret: LODSB ; read the next character of the string
                  TEST AL, AL ; check if it is a zero byte
                  JNZ interp_lp ; if not, jump back into the loop
                  RET






                  share|improve this answer












                  $endgroup$



















                    1

















                    $begingroup$

                    x86 Assembly, 33 Bytes



                    Takes the initial accumulator state in CL (integer 0 or 1) and the address of the commands as a zero-terminated ASCII String in ESI. Leaves the final accumulator state in CL.



                    Point the call instruction at offset 0x1B (label interpret in the Explanation).



                    3C 30 74 03 B0 01 C3 30 C0 C3 E8 F1 FF FF FF 38
                    C8 AC 75 07 E8 E7 FF FF FF 88 C1 AC 84 C0 75 EA
                    C3


                    Explanation (Using Intel Syntax):



                    ; function to convert ASCII '1'/'0' into 0 or 1 int values (from AL to AL)
                    ctob:
                    CMP AL, 0x30 ; '0'
                    JE .zero
                    MOV AL, 1
                    RET
                    .zero:
                    XOR AL, AL
                    RET

                    ; interpreting function
                    interp_lp:
                    CALL ctob ; convert to number
                    CMP AL, CL ; compare to current accumulator
                    LODSB ; read the next character of the string
                    ; this doesn't affect any flags and we need to do
                    ; it in both cases anyway
                    JNE interpret ; if AL != CL (from above, not the new value of AL), skip forward
                    CALL ctob ; convert AL to number
                    MOV CL, AL ; store AL in CL
                    interpret: LODSB ; read the next character of the string
                    TEST AL, AL ; check if it is a zero byte
                    JNZ interp_lp ; if not, jump back into the loop
                    RET






                    share|improve this answer












                    $endgroup$

















                      1















                      1











                      1







                      $begingroup$

                      x86 Assembly, 33 Bytes



                      Takes the initial accumulator state in CL (integer 0 or 1) and the address of the commands as a zero-terminated ASCII String in ESI. Leaves the final accumulator state in CL.



                      Point the call instruction at offset 0x1B (label interpret in the Explanation).



                      3C 30 74 03 B0 01 C3 30 C0 C3 E8 F1 FF FF FF 38
                      C8 AC 75 07 E8 E7 FF FF FF 88 C1 AC 84 C0 75 EA
                      C3


                      Explanation (Using Intel Syntax):



                      ; function to convert ASCII '1'/'0' into 0 or 1 int values (from AL to AL)
                      ctob:
                      CMP AL, 0x30 ; '0'
                      JE .zero
                      MOV AL, 1
                      RET
                      .zero:
                      XOR AL, AL
                      RET

                      ; interpreting function
                      interp_lp:
                      CALL ctob ; convert to number
                      CMP AL, CL ; compare to current accumulator
                      LODSB ; read the next character of the string
                      ; this doesn't affect any flags and we need to do
                      ; it in both cases anyway
                      JNE interpret ; if AL != CL (from above, not the new value of AL), skip forward
                      CALL ctob ; convert AL to number
                      MOV CL, AL ; store AL in CL
                      interpret: LODSB ; read the next character of the string
                      TEST AL, AL ; check if it is a zero byte
                      JNZ interp_lp ; if not, jump back into the loop
                      RET






                      share|improve this answer












                      $endgroup$



                      x86 Assembly, 33 Bytes



                      Takes the initial accumulator state in CL (integer 0 or 1) and the address of the commands as a zero-terminated ASCII String in ESI. Leaves the final accumulator state in CL.



                      Point the call instruction at offset 0x1B (label interpret in the Explanation).



                      3C 30 74 03 B0 01 C3 30 C0 C3 E8 F1 FF FF FF 38
                      C8 AC 75 07 E8 E7 FF FF FF 88 C1 AC 84 C0 75 EA
                      C3


                      Explanation (Using Intel Syntax):



                      ; function to convert ASCII '1'/'0' into 0 or 1 int values (from AL to AL)
                      ctob:
                      CMP AL, 0x30 ; '0'
                      JE .zero
                      MOV AL, 1
                      RET
                      .zero:
                      XOR AL, AL
                      RET

                      ; interpreting function
                      interp_lp:
                      CALL ctob ; convert to number
                      CMP AL, CL ; compare to current accumulator
                      LODSB ; read the next character of the string
                      ; this doesn't affect any flags and we need to do
                      ; it in both cases anyway
                      JNE interpret ; if AL != CL (from above, not the new value of AL), skip forward
                      CALL ctob ; convert AL to number
                      MOV CL, AL ; store AL in CL
                      interpret: LODSB ; read the next character of the string
                      TEST AL, AL ; check if it is a zero byte
                      JNZ interp_lp ; if not, jump back into the loop
                      RET







                      share|improve this answer















                      share|improve this answer




                      share|improve this answer








                      edited Aug 28 at 15:37

























                      answered Aug 28 at 14:25









                      Fayti1703Fayti1703

                      713 bronze badges




                      713 bronze badges
























                          1

















                          $begingroup$


                          C (gcc), 45 41 bytes





                          f(a,i)char*i;a=*i?f(a^*i?a:i[1],i+2):a;


                          Try it online!



                          4 bytes shaved off thanks to @ErikF!






                          share|improve this answer












                          $endgroup$










                          • 1




                            $begingroup$
                            You can save 4 bytes by using the usual trick of storing the return value in the first parameter: Try it online!
                            $endgroup$
                            – ErikF
                            Aug 26 at 2:58















                          1

















                          $begingroup$


                          C (gcc), 45 41 bytes





                          f(a,i)char*i;a=*i?f(a^*i?a:i[1],i+2):a;


                          Try it online!



                          4 bytes shaved off thanks to @ErikF!






                          share|improve this answer












                          $endgroup$










                          • 1




                            $begingroup$
                            You can save 4 bytes by using the usual trick of storing the return value in the first parameter: Try it online!
                            $endgroup$
                            – ErikF
                            Aug 26 at 2:58













                          1















                          1











                          1







                          $begingroup$


                          C (gcc), 45 41 bytes





                          f(a,i)char*i;a=*i?f(a^*i?a:i[1],i+2):a;


                          Try it online!



                          4 bytes shaved off thanks to @ErikF!






                          share|improve this answer












                          $endgroup$




                          C (gcc), 45 41 bytes





                          f(a,i)char*i;a=*i?f(a^*i?a:i[1],i+2):a;


                          Try it online!



                          4 bytes shaved off thanks to @ErikF!







                          share|improve this answer















                          share|improve this answer




                          share|improve this answer








                          edited Aug 28 at 18:30

























                          answered Aug 25 at 12:38









                          G. SliepenG. Sliepen

                          5702 silver badges6 bronze badges




                          5702 silver badges6 bronze badges










                          • 1




                            $begingroup$
                            You can save 4 bytes by using the usual trick of storing the return value in the first parameter: Try it online!
                            $endgroup$
                            – ErikF
                            Aug 26 at 2:58












                          • 1




                            $begingroup$
                            You can save 4 bytes by using the usual trick of storing the return value in the first parameter: Try it online!
                            $endgroup$
                            – ErikF
                            Aug 26 at 2:58







                          1




                          1




                          $begingroup$
                          You can save 4 bytes by using the usual trick of storing the return value in the first parameter: Try it online!
                          $endgroup$
                          – ErikF
                          Aug 26 at 2:58




                          $begingroup$
                          You can save 4 bytes by using the usual trick of storing the return value in the first parameter: Try it online!
                          $endgroup$
                          – ErikF
                          Aug 26 at 2:58











                          0

















                          $begingroup$


                          Crystal, 46 bytes



                          With commands in an Array(Tuple(Int32,Int32)), such as [0,0, 0,1, 0,0].



                          def f(s,i);i.mapc,v;s;end



                          Try it online!



                          It's pretty simple to understand in a more readable form:



                          def f(state, instructions)
                          instructions.map do |check, value|
                          state += ~(state ^ check) & (state ^ value) % 2
                          end
                          state
                          end


                          The function loops through each command, automatically unpacking the tuple values into c and v. It then sets the state by the formula



                          state = state + NOT(state XOR check) AND (state XOR value) mod 2


                          which I arrived at mostly by trial and error. Once all commands have been processed, it returns the state value.






                          share|improve this answer










                          $endgroup$



















                            0

















                            $begingroup$


                            Crystal, 46 bytes



                            With commands in an Array(Tuple(Int32,Int32)), such as [0,0, 0,1, 0,0].



                            def f(s,i);i.mapc,v;s;end



                            Try it online!



                            It's pretty simple to understand in a more readable form:



                            def f(state, instructions)
                            instructions.map do |check, value|
                            state += ~(state ^ check) & (state ^ value) % 2
                            end
                            state
                            end


                            The function loops through each command, automatically unpacking the tuple values into c and v. It then sets the state by the formula



                            state = state + NOT(state XOR check) AND (state XOR value) mod 2


                            which I arrived at mostly by trial and error. Once all commands have been processed, it returns the state value.






                            share|improve this answer










                            $endgroup$

















                              0















                              0











                              0







                              $begingroup$


                              Crystal, 46 bytes



                              With commands in an Array(Tuple(Int32,Int32)), such as [0,0, 0,1, 0,0].



                              def f(s,i);i.mapc,v;s;end



                              Try it online!



                              It's pretty simple to understand in a more readable form:



                              def f(state, instructions)
                              instructions.map do |check, value|
                              state += ~(state ^ check) & (state ^ value) % 2
                              end
                              state
                              end


                              The function loops through each command, automatically unpacking the tuple values into c and v. It then sets the state by the formula



                              state = state + NOT(state XOR check) AND (state XOR value) mod 2


                              which I arrived at mostly by trial and error. Once all commands have been processed, it returns the state value.






                              share|improve this answer










                              $endgroup$




                              Crystal, 46 bytes



                              With commands in an Array(Tuple(Int32,Int32)), such as [0,0, 0,1, 0,0].



                              def f(s,i);i.mapc,v;s;end



                              Try it online!



                              It's pretty simple to understand in a more readable form:



                              def f(state, instructions)
                              instructions.map do |check, value|
                              state += ~(state ^ check) & (state ^ value) % 2
                              end
                              state
                              end


                              The function loops through each command, automatically unpacking the tuple values into c and v. It then sets the state by the formula



                              state = state + NOT(state XOR check) AND (state XOR value) mod 2


                              which I arrived at mostly by trial and error. Once all commands have been processed, it returns the state value.







                              share|improve this answer













                              share|improve this answer




                              share|improve this answer










                              answered Aug 26 at 20:14









                              KinxerKinxer

                              212 bronze badges




                              212 bronze badges
























                                  0

















                                  $begingroup$


                                  C (clang), 68 62 bytes





                                  t(s,e,a)char*s,*e;for(;s<e;++s)a=*s++-48^a?a:*s-48;puts(&a);


                                  Try it online!



                                  Takes a pointer to the start of the source string, a pointer to the end of the source string (start + strlen(start)), and the initial accumulator value.



                                  Old version (prints ASCII 48/49 for 0/1):



                                  t(s,e,a)char*s,*e;for(;s<e;++s)a=*s++-48^a?a:*s-48;putchar(a+48);





                                  share|improve this answer












                                  $endgroup$



















                                    0

















                                    $begingroup$


                                    C (clang), 68 62 bytes





                                    t(s,e,a)char*s,*e;for(;s<e;++s)a=*s++-48^a?a:*s-48;puts(&a);


                                    Try it online!



                                    Takes a pointer to the start of the source string, a pointer to the end of the source string (start + strlen(start)), and the initial accumulator value.



                                    Old version (prints ASCII 48/49 for 0/1):



                                    t(s,e,a)char*s,*e;for(;s<e;++s)a=*s++-48^a?a:*s-48;putchar(a+48);





                                    share|improve this answer












                                    $endgroup$

















                                      0















                                      0











                                      0







                                      $begingroup$


                                      C (clang), 68 62 bytes





                                      t(s,e,a)char*s,*e;for(;s<e;++s)a=*s++-48^a?a:*s-48;puts(&a);


                                      Try it online!



                                      Takes a pointer to the start of the source string, a pointer to the end of the source string (start + strlen(start)), and the initial accumulator value.



                                      Old version (prints ASCII 48/49 for 0/1):



                                      t(s,e,a)char*s,*e;for(;s<e;++s)a=*s++-48^a?a:*s-48;putchar(a+48);





                                      share|improve this answer












                                      $endgroup$




                                      C (clang), 68 62 bytes





                                      t(s,e,a)char*s,*e;for(;s<e;++s)a=*s++-48^a?a:*s-48;puts(&a);


                                      Try it online!



                                      Takes a pointer to the start of the source string, a pointer to the end of the source string (start + strlen(start)), and the initial accumulator value.



                                      Old version (prints ASCII 48/49 for 0/1):



                                      t(s,e,a)char*s,*e;for(;s<e;++s)a=*s++-48^a?a:*s-48;putchar(a+48);






                                      share|improve this answer















                                      share|improve this answer




                                      share|improve this answer








                                      edited Aug 27 at 14:35

























                                      answered Aug 26 at 18:00









                                      osuka_osuka_

                                      3611 silver badge9 bronze badges




                                      3611 silver badge9 bronze badges
























                                          0

















                                          $begingroup$


                                          Java (JDK), 38 bytes





                                          a->p->p.reduce(a,(s,c)->c<1|c>2?s:c%2)


                                          Try it online!



                                          The inputs are an int and an IntStream of 0, 1, 2 or 3, which correspond to 00, 01, 10, 11 from binary.






                                          share|improve this answer










                                          $endgroup$



















                                            0

















                                            $begingroup$


                                            Java (JDK), 38 bytes





                                            a->p->p.reduce(a,(s,c)->c<1|c>2?s:c%2)


                                            Try it online!



                                            The inputs are an int and an IntStream of 0, 1, 2 or 3, which correspond to 00, 01, 10, 11 from binary.






                                            share|improve this answer










                                            $endgroup$

















                                              0















                                              0











                                              0







                                              $begingroup$


                                              Java (JDK), 38 bytes





                                              a->p->p.reduce(a,(s,c)->c<1|c>2?s:c%2)


                                              Try it online!



                                              The inputs are an int and an IntStream of 0, 1, 2 or 3, which correspond to 00, 01, 10, 11 from binary.






                                              share|improve this answer










                                              $endgroup$




                                              Java (JDK), 38 bytes





                                              a->p->p.reduce(a,(s,c)->c<1|c>2?s:c%2)


                                              Try it online!



                                              The inputs are an int and an IntStream of 0, 1, 2 or 3, which correspond to 00, 01, 10, 11 from binary.







                                              share|improve this answer













                                              share|improve this answer




                                              share|improve this answer










                                              answered Aug 28 at 10:23









                                              Olivier GrégoireOlivier Grégoire

                                              10.3k2 gold badges19 silver badges45 bronze badges




                                              10.3k2 gold badges19 silver badges45 bronze badges























                                                  1 2
                                                  next

















                                                  draft saved

                                                  draft discarded















































                                                  If this is an answer to a challenge…



                                                  • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                                  • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                                    Explanations of your answer make it more interesting to read and are very much encouraged.


                                                  • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                                  More generally…



                                                  • …Please make sure to answer the question and provide sufficient detail.


                                                  • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f190819%2ftalk-interpreter%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown









                                                  Popular posts from this blog

                                                  Tamil (spriik) Luke uk diar | Nawigatjuun

                                                  Align equal signs while including text over equalitiesAMS align: left aligned text/math plus multicolumn alignmentMultiple alignmentsAligning equations in multiple placesNumbering and aligning an equation with multiple columnsHow to align one equation with another multline equationUsing \ in environments inside the begintabularxNumber equations and preserving alignment of equal signsHow can I align equations to the left and to the right?Double equation alignment problem within align enviromentAligned within align: Why are they right-aligned?

                                                  Where does the image of a data connector as a sharp metal spike originate from?Where does the concept of infected people turning into zombies only after death originate from?Where does the motif of a reanimated human head originate?Where did the notion that Dragons could speak originate?Where does the archetypal image of the 'Grey' alien come from?Where did the suffix '-Man' originate?Where does the notion of being injured or killed by an illusion originate?Where did the term “sophont” originate?Where does the trope of magic spells being driven by advanced technology originate from?Where did the term “the living impaired” originate?