Interpret DOGO!

9

1

Interpret DOGO

DOGO is a lesser known programming language. While the original DOGO (a joke language from a Usenet post) has never been implemented, a language resembling it has been created. The commands for the language are:

+===========+================================================================+
|  Command  |                          Description                           |
+===========+================================================================+
| SIT       | If the value of the current memory cell is 0, jump to STAY.    |
+-----------+----------------------------------------------------------------+
| STAY      | If the value of the current memory cell is not 0, jump to SIT. |
+-----------+----------------------------------------------------------------+
| ROLL-OVER | Select the next operation from the operation list.             |
+-----------+----------------------------------------------------------------+
| HEEL      | Execute the currently selected operation.                      |
+-----------+----------------------------------------------------------------+

The operations are:

+========+=======================================================+====+
| Number |                      Description                      | BF |
+========+=======================================================+====+
|      0 | Increment current memory cell.                        | +  |
+--------+-------------------------------------------------------+----+
|      1 | Decrement current memory cell.                        | -  |
+--------+-------------------------------------------------------+----+
|      2 | Move to next memory cell.                             | >  |
+--------+-------------------------------------------------------+----+
|      3 | Move to previous memory cell.                         | <  |
+--------+-------------------------------------------------------+----+
|      4 | Input a byte and store it in the current memory cell. | ,  |
+--------+-------------------------------------------------------+----+
|      5 | Output the current memory cell as ASCII.              | .  |
+--------+-------------------------------------------------------+----+

Examples

Hello World:

roll-over roll-over heel roll-over roll-over roll-over roll-over heel heel heel 
heel heel heel heel heel heel sit roll-over roll-over roll-over heel roll-over 
roll-over roll-over heel heel heel heel heel heel heel heel roll-over roll-over 
heel roll-over roll-over roll-over roll-over roll-over heel roll-over roll-over 
roll-over roll-over roll-over stay roll-over roll-over roll-over heel roll-over 
roll-over heel roll-over roll-over roll-over heel roll-over roll-over roll-over 
roll-over heel heel heel heel heel heel heel sit roll-over roll-over roll-over 
heel roll-over roll-over roll-over heel heel heel heel roll-over roll-over heel 
roll-over roll-over roll-over roll-over roll-over heel roll-over roll-over 
roll-over roll-over roll-over stay roll-over roll-over roll-over heel roll-over  
roll-over roll-over heel roll-over roll-over roll-over roll-over roll-over heel 
roll-over heel heel heel heel heel heel heel roll-over roll-over roll-over 
roll-over roll-over heel heel roll-over heel heel heel roll-over roll-over 
roll-over roll-over roll-over heel roll-over roll-over roll-over heel heel heel 
roll-over roll-over roll-over roll-over heel heel heel heel heel heel heel heel 
sit roll-over roll-over roll-over heel roll-over roll-over roll-over heel heel 
heel heel roll-over roll-over heel roll-over roll-over roll-over roll-over 
roll-over heel roll-over roll-over roll-over roll-over roll-over stay roll-over 
roll-over roll-over heel roll-over roll-over heel roll-over roll-over roll-over 
heel heel heel roll-over roll-over roll-over roll-over heel heel heel heel heel 
heel heel heel heel heel sit roll-over roll-over roll-over heel roll-over 
roll-over roll-over heel heel heel heel heel heel heel heel heel roll-over 
roll-over heel roll-over roll-over roll-over roll-over roll-over heel roll-over 
roll-over roll-over roll-over roll-over stay roll-over roll-over roll-over heel 
roll-over roll-over roll-over roll-over heel heel heel roll-over roll-over 
roll-over roll-over heel roll-over roll-over roll-over roll-over heel heel heel 
heel roll-over roll-over heel roll-over heel heel heel roll-over roll-over 
roll-over roll-over roll-over heel roll-over roll-over heel heel heel heel heel 
heel roll-over roll-over roll-over roll-over heel roll-over roll-over heel heel 
heel heel heel heel heel heel roll-over roll-over roll-over roll-over heel 
roll-over roll-over roll-over heel heel roll-over roll-over roll-over roll-over 
heel roll-over roll-over roll-over roll-over roll-over heel

99 bottles of beer

Rules

  • Each submission should be either a full program or function. If it is a function, it must be runnable by only needing to add the function call to the bottom of the program. Anything else (e.g. headers in C), must be included.
  • If it is possible, please provide a link to an online site where your code can be tested.
  • Your program cannot write anything to STDERR (or something similar).
  • You can take input from STDIN (or the closest alternative in your language), or as an argument.
  • Standard loopholes are forbidden.

Scoring

Programs are scored according to bytes. The default character set is UTF-8, if you are using a different one, please specify.

That aside, this is , and the lowest byte count will be deemed the winner!

Submissions

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

Leaderboard

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

/* Configuration */

var QUESTION_ID = 79350; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 53406; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });  
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];
  
  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
    });
    
    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });
    
  });
  
  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;
    
    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/<a/.test(lang)) lang = jQuery(lang).text();
    
    languages[lang] = languages[lang] || {lang: a.language, user: a.user, size: a.size, link: a.link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

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>

Update:

Sorry for not clarifying the sit and stay commands very well. They are, as @user6245072 said, like [ and ] in BF.

Update 2:

To clarify @KennyLau's questions:

  • The default operation is 0.
  • Memory consists of 8-bit cells.
  • Cells wrap on overflow/underflow.
  • Input is required for operation 4.

George Gibson

Posted 2016-05-04T07:00:32.300

Reputation: 2 369

Do we need to handle extraneous input? Such as an input of sit lie-down roll-over play-dead heel – Value Ink – 2016-05-05T04:01:14.163

1Also, operation 1 says "increment next cell`, but the corresponding BF code is "decrement current cell". Which one is correct behavior? – Value Ink – 2016-05-05T05:03:25.000

@KevinLau-notKenny Thanks, my fault. – George Gibson – 2016-05-05T06:12:57.810

Answers

1

Ruby, 287 bytes

Runs on an infinite tape in both directions. DOGO input is a file on the command line. If there is no command line argument, a DOGO program will still work if passed in as STDIN, unless it uses operation 3 (get a byte from STDIN) in which case I have no idea. At any rate, file input is best.

Assumes no other text other than the four commands and whitespace exist in the program file.

Hello World Demonstration

i=k=o=0;m={}
c=$<.read.upcase.split.map{|e|%w{SIT STAY ROLL-OVER HEEL}.index e}.join
(m[k]||=0
e=c[i].to_i
e>2?o>4?$><<m[k].chr:
o>3?m[k]=STDIN.getc.ord:
o>1?k+=o>2?-1:1:
m[k]=o<1?-~m[k]%256:~-m[k]%256:
e>1?o=-~o%6:
e>0?m[k]>0?i=c.rindex(?0,i):0:
m[k]<1?i=c.index(?1,i):0
i+=1)while c[i]

Value Ink

Posted 2016-05-04T07:00:32.300

Reputation: 10 608

2

Python 3, 388 398 373 371 bytes

Assumes 256 memory cells. Just a straightforward implementation, easily beatable, probably can be golfed more. Try it on repl.it.

Thanks to @EasterlyIrk for having me realize that Python 3 is much shorter that Python 2.

EDIT: Realized I only accounted for over/underflow while printing, not in actual value.

Thanks to @KevinLau-notKenney for saving 25 (!) bytes with list multiplication and inversion operator tricks

EDIT: -3 bytes by putting 256 into a variable, -4 messing with operators, +8 making sure it is lowercase

def p(s):
 b=256
 l,m=[w[-1]for w in s.lower().split()],[0]*b
 i=p=x=0
 while x<len(l):
  c=l[x]
  if'm'>c:
   if 1>i:m[p]=-~m[p]%b
   if 1==i:m[p]=~-m[p]%b
   if 2==i:p=-~p%b
   if 3==i:p=~-p%b
   if 4==i:m[p]=ord(input()[0])
   if 4<i:print(chr(m[p]),end="")
  if'r'==c:i=-~i%6
  if't'==c and m[p]<1:x+=l[:x].index('y')
  if'x'<c and m[p]>0:x-=l[x::-1].index('t')
  x+=1

Blue

Posted 2016-05-04T07:00:32.300

Reputation: 1 986

Why use sys.stdout.write? Why not print? – Rɪᴋᴇʀ – 2016-05-05T02:33:38.757

@EᴀsᴛᴇʀʟʏIʀᴋ print adds newlines. the actual print function with the end arg is in Python 3 – Blue – 2016-05-05T02:34:33.787

What makes python3 out of the question? Just tested, works fine with print(...,end='') – Rɪᴋᴇʀ – 2016-05-05T02:34:56.687

@EᴀsᴛᴇʀʟʏIʀᴋ I was too lazy to install it. I might as well change the answer, tho – Blue – 2016-05-05T02:35:59.857

Then maybe try ideone or a online python interpreter for that. Or install it. :P – Rɪᴋᴇʀ – 2016-05-05T02:36:27.210

[0]*256 generates the tape in much fewer bytes than your range trick. Also, -~p%256 saves 2 bytes over (p+1)%256, and same with ~-p%256 for (p-1)%256 – Value Ink – 2016-05-05T05:32:28.773

@KevinLau-notKenny wow, I had no idea the inversion operator could do that! Thanks! – Blue – 2016-05-05T10:14:17.580