解读DOGO!


9

解读DOGO

DOGO是鲜为人知的编程语言。最初的DOGO(Usenet帖子中的玩笑语言)从未实现,但已经创建了类似的语言。该语言的命令为:

+===========+================================================================+
|  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.                      |
+-----------+----------------------------------------------------------------+

操作是:

+========+=======================================================+====+
| 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.              | .  |
+--------+-------------------------------------------------------+----+

例子

你好,世界:

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瓶啤酒

规则

  • 每个提交应该是完整的程序或功能。如果它是一个函数,则只需将函数调用添加到程序底部即可使其可运行。其他任何内容(例如C中的标头)都必须包括在内。
  • 如果可能,请提供一个可以测试您的代码的在线站点的链接。
  • 您的程序无法写入任何内容STDERR(或类似内容)。
  • 您可以从STDIN(或使用您语言中最接近的替代语言)输入,也可以作为参数。
  • 禁止出现标准漏洞

计分

程序根据字节计分。默认字符集为UTF-8,如果使用其他字符集,请指定。

除此之外,这是 ,最低字节数将被视为获胜者!

意见书

为确保您的答案显示出来,请使用以下Markdown模板以标题开头。

# Language Name, N bytes

N您提交的文件大小在哪里。如果您提高了分数,则可以通过打败旧分数保持标题。例如:

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

如果要在标头中包含多个数字(例如,因为您的分数是两个文件的总和,或者您想单独列出解释器标志罚分),请确保实际分数是标头中的最后一个数字:

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

您还可以将语言名称设置为链接,然后该链接将显示在页首横幅代码段中:

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

排行榜

这是一个堆栈片段,用于按语言生成常规排行榜和获胜者概述。

更新:

抱歉,无法很好地阐明sitand stay命令。正如@ user6245072所说,它们[]BF中的一样。

更新2:

为了澄清@KennyLau的问题:

  • 默认操作是0
  • 存储器由8位单元组成。
  • 单元会在上溢/下溢时自动换行。
  • 操作4需要输入。

我们需要处理多余的输入吗?例如sit lie-down roll-over play-dead heel
值墨

1
另外,操作1说“增加下一个单元格”,但相应的BF代码是“减少当前单元格”。哪个是正确的行为?
Value Ink

@ KevinLau-notKenny谢谢,我的错。
乔治·吉布森

Answers:


1

Ruby,287个字节

在两个方向上在无限的磁带上运行。DOGO输入是命令行上的文件。如果没有命令行参数,则DOGO程序如果作为STDIN传入,则仍然可以工作,除非它使用操作3(从STDIN获取字节),在这种情况下我不知道。无论如何,文件输入是最好的。

假定程序文件中除了四个命令和空格外没有其他文本。

你好世界示范

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]

2

Python 3中,388个 398 373 371字节

假设有256个存储单元。只是简单易行的实施方式,容易打败,也许可以打更多的高尔夫。在repl.it尝试

感谢@EasterlyIrk让我意识到Python 3比Python 2短得多。

编辑:意识到我只在打印时考虑了上溢/下溢,而不是实际值。

感谢@ KevinLau-notKenney使用列表乘法和反转运算符技巧来节省25(!)字节

编辑:-3字节,将256放入变量,-4与运算符弄乱,+ 8确保其为小写

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

为什么要使用sys.stdout.write?为什么不print呢?
Rɪᴋᴇʀ

@EᴀsᴛᴇʀʟʏIʀᴋ打印会添加换行符。实际的带有arg结尾的打印功能在Python 3中
蓝色

是什么使python3成为不可能?刚刚测试,工作正常print(...,end='')
Rɪᴋᴇʀ

@EᴀsᴛᴇʀʟʏIʀᴋ我懒得安装它。我不妨更改答案,例如
Blue

然后也许尝试使用ideone或在线python解释器。或安装它。:P
Rɪᴋᴇʀ
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.