猴岛:航海家的头


12

警告:此挑战包含“猴岛的秘密”中的一些轻微破坏者。

在游戏快要结束时,导航员的魔术头正带领您穿过地下墓穴:

在此处输入图片说明

您需要它的眼球项链,但头部不愿意将它提供给您。获得它的一种方法就是继续乞讨:

Guybrush:请给我那条项链吗?
负责人:不,但感谢您如此礼貌地问。
Guybrush:哦,拜托,pleeeeease?
负责人:您可以乞求一切,但不能拥有。
Guybrush:好吗?
负责人:您可以乞求一切,但不能拥有。
Guybrush:好漂亮吗?
负责人:您可以乞求一切,但不能拥有。
Guybrush:可以在上面放糖吗?
头:哦,好的,你这个大宝贝。你可以拥有它。嘿,如果没有肩膀,项链有什么用?

挑战

编写一个完整的程序,打印上述对话框。要注意的是,每次调用该程序时,它应该只打印两行(Guybrush和Head的响应恳求一遍)。例如,如果您的提交是用Python编写的,用法应如下所示:

$> python please.py
Guybrush: May I please have that necklace?
Head: No, but thanks for asking so politely.
$> python please.py
Guybrush: Oh come on, pleeeeease?
Head: You can beg all you want, but you can't have it.
$> python please.py
Guybrush: Pretty please?
Head: You can beg all you want, but you can't have it.
$> python please.py
Guybrush: Pretty PRETTY please?
Head: You can beg all you want, but you can't have it.
$> python please.py
Guybrush: Pretty please with sugar on top?
Head: Oh, all right, you big baby. You can have it. Hey, what good's a necklace if you don't have shoulders?

多次调用该程序可能会导致不确定的行为,因此您可以循环执行,继续打印最后两行,或者在第五次调用后甚至可能导致程序中断。

您可以写入工作目录中的文件,也可以修改程序本身的源代码以跟踪调用。在后一种情况下,您的程序不得依赖其自己的文件名。(在前一种情况下,您可以假定程序的文件名不会与程序所依赖的任何文件名冲突。)

您不得假定类似REPL的环境,或在两次调用之间将任何数据保留在RAM中。例如,如果您使用Mathematica回答,则必须假设我在两次调用之间退出了内核。

这是代码高尔夫球,最短的答案(以字节为单位)获胜。如果您的程序在第一次调用之前依赖于任何其他文件,请将其名称和内容添加到字节数中。


因此,没有将值放在全局变量中然后在JS中重用吗?
Optimizer

@Optimizer不,对不起。我想如果您想为此使用JS,则必须使用node。
Martin Ender 2014年

我们也可以在节点中有全局变量。您是否在建议wrt节点,我们应该能够退出该节点,并且仍然可以继续进行对话?
Optimizer

@Optimizer是的。您应该编写一个完整的程序,我可以调用5次,node please.js产生5个不同的输出。
Martin Ender 2014年

我的程序可以依靠外部文件启动吗?我将其字节数计入分数
Claudiu 2014年

Answers:


9

Python,224 + 97 + 1 = 322个字符

一个最简单的解决方案,让我们一切都开始。感谢gnibbler帮助我减少了18个字节!

n=0
print open('z','rb').read().decode('zip').split('|')[n]
open(__file__,'r+').write("n="+`n+1`)

要求文件z存在于同一目录中(文件名+1,文件大小+224):

$ hexdump z
0000000 9c78 d1ad 6e3d 30c3 050c bde0 78a7 165b
0000010 0723 92c8 48a9 b43a 8209 192c 9b29 0491
0000020 a2ab 9fa1 021a f87a 715a f46c d100 1026
0000030 1efc 1e41 5172 4721 c3b3 1527 607c 4c70
0000040 6191 87e8 0c91 7825 7b6e 2d47 dfef 4c8e
0000050 0edd d25f e540 8b54 8fbe 4bb8 c500 7ade
0000060 288d c418 c4d9 6cae 0f7f 7bab 6832 9be5
0000070 be21 7aa9 537d c2c2 24dd 25a3 c50f e41a
0000080 ca1c 1ff4 a7c9 a439 d5cc 9a4d b207 3fe9
0000090 0e7c 529c 4e79 3afc 7cef bf79 6f5e 672f
00000a0 8b9f 6d1d 8832 5359 1698 2482 92c3 3270
00000b0 43cd 560e 899b a4ad 1ab2 548a aed9 0bf1
00000c0 238f 0697 bd63 168f 36e9 b411 0a1e fef6
00000d0 eee8 1d64 1a28 aec9 10e3 7ff7 3a0b d9ab
00000e0

$ ls -l z
-rw-r--r--+ 1 Laxori mkpasswd 224 2014-09-22 22:35 z

您可以z使用以下内容生成:

>>> open('z','wb').write("""eJyt0T1uwzAMBeC9p3hbFiMHyJKpSDq0CYIsGSmbkQSroqGfGgJ6+FpxbPQA0SYQ/B5BHnJRIUez
wycVfGBwTJFh6IeRDCV4bntHLe/fjkzdDl/SQOVUi76PuEsAxd56jSgYxNnErmx/D6t7MmjlmyG+
qXp9U8LC3SSjJQ/FGuQcyvQfyac5pMzVTZoHsuk/fA6cUnlO/DrvfHm/Xm8vZ5+LHW0yiFlTmBaC
JMOScDLNQw5Wm4mtpLIailTZrvELjyOXBmO9jxbpNhG0Hgr2/ujuZB0oGsmu4xD3fws6q9k=""".decode('base64'))

输出:

$ python monkeyisland.py
Guybrush: May I please have that necklace?
Head: No, but thanks for asking so politely.
$ python monkeyisland.py
Guybrush: Oh come on, pleeeeease?
Head: You can beg all you want, but you can't have it.
$ python monkeyisland.py
Guybrush: Pretty please?
Head: You can beg all you want, but you can't have it.
$ python monkeyisland.py
Guybrush: Pretty PRETTY please?
Head: You can beg all you want, but you can't have it.
$ python monkeyisland.py
Guybrush: Pretty please with sugar on top?
Head: Oh, all right, you big baby. You can have it. Hey, what good's a necklace if you don't have shoulders?
$ python monkeyisland.py
Traceback (most recent call last):
  File "monkeyisland.py", line 2, in <module>
    print open('z','rb').read().decode('zip').split('|')[n]
IndexError: list index out of range

1
在两对线之间使用不同的定界符,例如,您line1\nline2|line3\nline4|line5\nline6|line7\nline8|line9\nline10现在可以分割|并只print D[n]
gnibbler

@gnibbler:先生很好!
Claudiu 2014年

5

通用Lisp(SBCL):659个字符

(defparameter *d*
  '#1=("~A May I please have that necklace?"
       "~A No, but thanks for asking so politely."
       "~A Oh come on, pleeeeease?"
       #2="~A You can beg all you want, but you can't have it."
       "~A Pretty please?"
       #2#
       "~A Pretty PRETTY please?"
       #2#
       "~A Pretty please with sugar on top?"
       "~A Oh, all right, you big baby. You can have it. Hey, what good's a necklace if you don't have shoulders?" . #1#))
(defun d ()
  (format t (pop *d*) "Guybrush:") (terpri)
  (format t (pop *d*) "Head:") (terpri)
  (terpri)
  (finish-output)
  (sb-ext:save-lisp-and-die "please" :toplevel 'd :executable t))
(d)

说明

  • 我在每次调用后转储lisp映像,这样可以保存当前状态。
  • 循环链表让我重新开始对话已经显示终究线(不是必须的,但至少它不会对错误format使用nil)。
  • 阅读器宏允许我重用一些相同的行。

这不是最短的提交,但是我认为这是解决问题的一种不错的方法。

优先调用

 $sbcl --noinform --noprint --load please.lisp
 Guybrush: May I please have that necklace?
 Head: No, but thanks for asking so politely.

 [undoing binding stack and other enclosing state... done]
 [saving current Lisp image into please:
 writing 5856 bytes from the read-only space at 0x0x20000000
 writing 4032 bytes from the static space at 0x0x20100000
 writing 67960832 bytes from the dynamic space at 0x0x1000000000
 done]

后续调用

$./please 
Guybrush: Oh come on, pleeeeease?
Head: You can beg all you want, but you can't have it.

[undoing binding stack and other enclosing state... done]
[saving current Lisp image into please:
writing 5856 bytes from the read-only space at 0x0x20000000
writing 4032 bytes from the static space at 0x0x20100000
writing 68091904 bytes from the dynamic space at 0x0x1000000000
done]

$./please 
Guybrush: Pretty please?
Head: You can beg all you want, but you can't have it.

[undoing binding stack and other enclosing state... done]
[saving current Lisp image into please:
writing 5856 bytes from the read-only space at 0x0x20000000
writing 4032 bytes from the static space at 0x0x20100000
writing 68091904 bytes from the dynamic space at 0x0x1000000000
done]

3

C#-593 + 1个1个字符(595)

编辑:更新了马丁的建议和其他各种优化方法

前+1是文件名。第二个+1是该文件的内容。没有删除所有空格和换行符,因此您可以阅读以下内容:

using System.IO;
using s=System.String;
class P
{
    static void Main()
    {
        s g="Guybrush: ",h="Head: ",p=" please",q="Pretty";
        s[]b=new s[]{"May I"+p+" have that necklace","No, but thanks for asking so politely.",
        "Oh come on, pleeeeease","You can beg all you want, but you can't have it.",q+p,
        "Oh, all right, you big baby. You can have it. Hey, what good's a necklace if you don't have shoulders?",
        q+" PRETTY"+p,"",q+p+" with sugar on top"};
        int a=int.Parse(File.ReadAllText("x",System.Text.Encoding.UTF8));
        System.Console.WriteLine(g+b[a]+"?\n"+h+b[(a+5)/6*2+1]);
        File.WriteAllText("x",(a+2).ToString());
    }
}

说明

依赖于目录中存在的名为“ x”的文本文件。最初应包含一个零,用于存储进度。

程序根据进度从字符串数组中删除相关元素,并在最后写入进度。一些行被重新使用以缩短长度,因此索引选择逻辑h+b[(a+5)/6*2+1]用于答案选择。

输出量

D:\Projects\Junk\MI\bin\Debug>MI
Guybrush: May I please have that necklace?
Head: No, but thanks for asking so politely.

D:\Projects\Junk\MI\bin\Debug>MI
Guybrush: Oh come on, pleeeeease?
Head: You can beg all you want, but you can't have it.

D:\Projects\Junk\MI\bin\Debug>MI
Guybrush: Pretty please?
Head: You can beg all you want, but you can't have it.

D:\Projects\Junk\MI\bin\Debug>MI
Guybrush: Pretty PRETTY please?
Head: You can beg all you want, but you can't have it.

D:\Projects\Junk\MI\bin\Debug>MI
Guybrush: Pretty please with sugar on top?
Head: Oh, all right, you big baby. You can have it. Hey, what good's a necklace
if you don't have shoulders?

D:\Projects\Junk\MI\bin\Debug>

我的第一个代码高尔夫,可能不是C#中最短的代码,但是嘿-Monkey Island,无法抗拒!

剥离代码:

using System.IO;using s=System.String;class P{static void Main(){s g="Guybrush: ",h="Head: ",p=" please",q="Pretty";s[]b=new s[]{"May I"+p+" have that necklace","No, but thanks for asking so politely.","Oh come on, pleeeeease","You can beg all you want, but you can't have it.",q+p,"Oh, all right, you big baby. You can have it. Hey, what good's a necklace if you don't have shoulders?",q+" PRETTY"+p,"",q+p+" with sugar on top"};int a=int.Parse(File.ReadAllText("x",System.Text.Encoding.UTF8));System.Console.WriteLine(g+b[a]+"?\n"+h+b[(a+5)/6*2+1]);File.WriteAllText("x",(a+2).ToString());}}

1
欢迎来到PPCG!打高尔夫球的一些技巧:我认为您可以稍微简化三元操作员。至少a<1?1:a<8?3:9,如果C#支持真实整数,则还支持a?a<8?3:9:1。但是您甚至可以利用整数除法来执行(a+5)/6*2并移动头的最后一个字符串来替换第一个空字符串(索引5)。并尝试类似的东西using s=System.String;。(哦,您也许可以省略名称空间,甚至可以使用名称空间System来避免System所有使用。)
Martin Ender 2014年

所以我可以。所有这些学习如何编写可维护性的方法实际上都使我处于劣势;)
Gareth 2014年

3

JS,488 473

刷新5次,包含此代码的页面显示5个不同的对话框。

l=localStorage;a="<p>Guybrush: ";b=a+"Pretty please";d="<br>Head: ";c=d+"You can beg all you want, but you can't have it.";document.write(a+"May I please have that necklace?"+d+"No, but thanks for asking so politely."+a+"Oh come on, pleeeeease?"+c+b+"?"+c+a+"Pretty PRETTY please?"+c+b+" with sugar on top?"+d+"Oh, all right, you big baby. You can have it. Hey, what good's a necklace if you don't have shoulders?<style>p:not(:nth-child("+(l[0]=~~l[0]+1)+")){display:none")

演示:

http://c99.nl/f/212197.html


2

Perl-356字节

2=~//;@d=qw"No6|thanks|for|asking|so|pol8ely. 5|beg72want62can't18.
Oh,7|right,2big|baby.|518.|Hey,|what|good's|a4|if2don't1shoulders?
May|I01that4 Oh|come|on,|pleeeeease 30 3|PRETTY0
30|w8h|sugar|on|top";print"Guybrush: $d[$'+print F$'+sysopen F,$0,1]?
Head: $d[$'/3]"=~s/\d/qw(|please |have| |you| Pretty |necklace You|can
,|but |all it)[$&]/ger=~y/|/ /r

一种自我修改的方法,用通用字符串代替。

样品用法:

$ perl please.pl
Guybrush: May I please have that necklace?
Head: No, but thanks for asking so politely.

$ perl please.pl
Guybrush: Oh come on, pleeeeease?
Head: You can beg all you want, but you can't have it.

$ perl please.pl
Guybrush: Pretty please?
Head: You can beg all you want, but you can't have it.

$ perl please.pl
Guybrush: Pretty PRETTY please?
Head: You can beg all you want, but you can't have it.

$ perl please.pl
Guybrush: Pretty please with sugar on top?
Head: Oh, all right, you big baby. You can have it. Hey, what good's a necklace if you don't have shoulders?
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.