对字符串加香


48

霍多尔(Hodor)在《权力的游戏》Game of Thrones)节目中是个头脑笨拙但讨人喜欢的角色(当然,也在书中)。他曾经说过的唯一一句话是“霍多尔”

令人惊讶的是,尽管词汇量不多,但霍多尔总是用完整的句子说出正确的大写和标点符号,并且实际上传达了含义。

Hodor能够表达所有128个ASCII字符,尽管他要用一个完整的句子说每个字符。每个字符都有一个准确的句子表示形式。通过将字符串中的所有字符翻译成它们的Hodor句子等效项,然后将所有句子连接起来,对ASCII字符串进行Hodorized。由于所有字符都映射为准确的句子,因此所有ASCII字符串都具有单个唯一的Hodorized表示形式。

加香字符

霍多尔通过对代表字符的句子使用4种不同的标点符号,将他的128个可表达字符分为4组,每组32个。

句子以...结尾

  • .如果ASCII字符代码mod 4为0。
  • .[newline][newline] (对于新段落),如果代码mod 4为1。
  • ? 如果代码mod 4为2。
  • ! 如果代码mod 4为3。

例如,的ASCII字符代码为b98,而98的mod 4为2,因此Hodor的句子b肯定以结尾?

该句子的内容是仅包含单词“ hodor”的32个不同的字符串之一。特定标点类型的32个字符中的每个字符都映射到不同的句子内容字符串。因此,使用32个句子内容字符串和4种标点符号类型,所有128个ASCII字符都可以表示为不同的Hodor句子。

要确定具有ASCII码C的字符的句子内容,请计算(floor(C / 4) + 16) mod 32;该列表中该行上冒号之后的所有内容均为句子内容:

0:Hodor
1:HODOR
2:Hodor hodor
3:Hodor, hodor
4:Hodor hodor hodor
5:Hodor, hodor hodor
6:Hodor hodor hodor hodor
7:Hodor hodor, hodor hodor
8:Hodor hodor hodor hodor hodor
9:Hodor hodor, hodor hodor hodor
10:Hodor hodor hodor hodor hodor hodor
11:Hodor hodor hodor, hodor hodor hodor
12:Hodor hodor hodor hodor hodor hodor hodor
13:Hodor hodor hodor, hodor hodor hodor hodor
14:Hodor hodor hodor hodor hodor hodor hodor hodor
15:Hodor hodor hodor hodor, hodor hodor hodor hodor
16:Hodor hodor hodor hodor hodor hodor hodor hodor hodor
17:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor
18:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
19:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor
20:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
21:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor
22:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
23:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor
24:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
25:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor
26:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
27:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor
28:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
29:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor
30:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor
31:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor

可以看出,除了HODOR特殊情况外,这些字符串是通过连接越来越多的hodor's' 生成的,并且其他所有字符串在所有单词之间都有一个逗号中间(逗号的右半角是“较大的一半”)字数)。

通过标点符号连接句子内容,我们可以对所有128个字符组成霍多尔句子(左侧数字是字符代码):

0:Hodor hodor hodor hodor hodor hodor hodor hodor hodor.
1:Hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
2:Hodor hodor hodor hodor hodor hodor hodor hodor hodor?
3:Hodor hodor hodor hodor hodor hodor hodor hodor hodor!
4:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor.
5:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor.[newline][newline]
6:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor?
7:Hodor hodor hodor hodor, hodor hodor hodor hodor hodor!
8:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
9:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
10:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
11:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
12:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor.
13:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor.[newline][newline]
14:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor?
15:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor!
16:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
17:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
18:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
19:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
20:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor.
21:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor.[newline][newline]
22:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor?
23:Hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor!
24:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
25:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
26:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
27:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
28:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor.
29:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor.[newline][newline]
30:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor?
31:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor!
32:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
33:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
34:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
35:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
36:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor.
37:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
38:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor?
39:Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor!
40:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
41:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
42:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
43:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
44:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor.
45:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
46:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor?
47:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor!
48:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
49:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
50:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
51:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
52:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.
53:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
54:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor?
55:Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor!
56:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
57:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
58:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor?
59:Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor!
60:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.
61:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
62:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor?
63:Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor!
64:Hodor.
65:Hodor.[newline][newline]
66:Hodor?
67:Hodor!
68:HODOR.
69:HODOR.[newline][newline]
70:HODOR?
71:HODOR!
72:Hodor hodor.
73:Hodor hodor.[newline][newline]
74:Hodor hodor?
75:Hodor hodor!
76:Hodor, hodor.
77:Hodor, hodor.[newline][newline]
78:Hodor, hodor?
79:Hodor, hodor!
80:Hodor hodor hodor.
81:Hodor hodor hodor.[newline][newline]
82:Hodor hodor hodor?
83:Hodor hodor hodor!
84:Hodor, hodor hodor.
85:Hodor, hodor hodor.[newline][newline]
86:Hodor, hodor hodor?
87:Hodor, hodor hodor!
88:Hodor hodor hodor hodor.
89:Hodor hodor hodor hodor.[newline][newline]
90:Hodor hodor hodor hodor?
91:Hodor hodor hodor hodor!
92:Hodor hodor, hodor hodor.
93:Hodor hodor, hodor hodor.[newline][newline]
94:Hodor hodor, hodor hodor?
95:Hodor hodor, hodor hodor!
96:Hodor hodor hodor hodor hodor.
97:Hodor hodor hodor hodor hodor.[newline][newline]
98:Hodor hodor hodor hodor hodor?
99:Hodor hodor hodor hodor hodor!
100:Hodor hodor, hodor hodor hodor.
101:Hodor hodor, hodor hodor hodor.[newline][newline]
102:Hodor hodor, hodor hodor hodor?
103:Hodor hodor, hodor hodor hodor!
104:Hodor hodor hodor hodor hodor hodor.
105:Hodor hodor hodor hodor hodor hodor.[newline][newline]
106:Hodor hodor hodor hodor hodor hodor?
107:Hodor hodor hodor hodor hodor hodor!
108:Hodor hodor hodor, hodor hodor hodor.
109:Hodor hodor hodor, hodor hodor hodor.[newline][newline]
110:Hodor hodor hodor, hodor hodor hodor?
111:Hodor hodor hodor, hodor hodor hodor!
112:Hodor hodor hodor hodor hodor hodor hodor.
113:Hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
114:Hodor hodor hodor hodor hodor hodor hodor?
115:Hodor hodor hodor hodor hodor hodor hodor!
116:Hodor hodor hodor, hodor hodor hodor hodor.
117:Hodor hodor hodor, hodor hodor hodor hodor.[newline][newline]
118:Hodor hodor hodor, hodor hodor hodor hodor?
119:Hodor hodor hodor, hodor hodor hodor hodor!
120:Hodor hodor hodor hodor hodor hodor hodor hodor.
121:Hodor hodor hodor hodor hodor hodor hodor hodor.[newline][newline]
122:Hodor hodor hodor hodor hodor hodor hodor hodor?
123:Hodor hodor hodor hodor hodor hodor hodor hodor!
124:Hodor hodor hodor hodor, hodor hodor hodor hodor.
125:Hodor hodor hodor hodor, hodor hodor hodor hodor.[newline][newline]
126:Hodor hodor hodor hodor, hodor hodor hodor hodor?
127:Hodor hodor hodor hodor, hodor hodor hodor hodor!

[newline]用实际的换行符代替。)

增香线

对字符串进行修饰实际上仅涉及将字符串字符的所有字符句子串联在一起。只有几个警告:

  • .[newline][newline]标点符号和最后一个句子外,在每个句子之后插入一个空格。
  • 如果最后一个句子的标点是.[newline][newline],则标点符号变为,...因此没有尾随空白。

例子

字符串F0被加臭为

HODOR? Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor.
  • F的ASCII码为70。70mod 4为2,因此第一句以结尾?(floor(70 / 4) + 16) mod 32为1,因此内容为HODOR
  • 0的ASCII代码为48。48 mod 4为0,因此第二句以结尾.(floor(48 / 4) + 16) mod 32是28,因此内容是15 hodor的字符串,没有逗号。
  • 请注意,没有尾随空格。

字符串CEE被加臭为

Hodor! HODOR.

HODOR...
  • 请注意,最后一句之前没有空格。
  • 请注意,最后一个句子的标点符号已更改为...

字符串

Hodor's real name is Walder.
Did you know?

被臭化为

Hodor hodor. Hodor hodor hodor, hodor hodor hodor! Hodor hodor, hodor hodor hodor. Hodor hodor hodor, hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor? Hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor? Hodor hodor, hodor hodor hodor.

Hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor, hodor hodor hodor? Hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor.

Hodor hodor, hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor, hodor hodor! Hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor. Hodor hodor, hodor hodor hodor. Hodor hodor, hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor? Hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor? Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor? HODOR. Hodor hodor hodor hodor hodor hodor.

Hodor hodor, hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor hodor hodor.

Hodor hodor hodor, hodor hodor hodor! Hodor hodor hodor, hodor hodor hodor hodor.

Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor. Hodor hodor hodor hodor hodor hodor! Hodor hodor hodor, hodor hodor hodor? Hodor hodor hodor, hodor hodor hodor! Hodor hodor hodor, hodor hodor hodor hodor! Hodor hodor hodor hodor hodor hodor hodor hodor, hodor hodor hodor hodor hodor hodor hodor hodor!

(假设换行符是单个\n

挑战

编写一个程序或函数,该程序或函数接受一个ASCII字符串并对其进行Hodorize,打印或返回结果字符串。以任何标准方式(从文本文件,命令行,stdin,函数arg)进行输入。

字节最少的解决方案获胜。Tiebreaker是较早的帖子。方便的字节计数器。


1
这个挑战使我想重新观看第1-4季,并发现他的真正意思。:D
mbomb007

24
太好了,我们找到了Ook的下一个版本。
ASCIIThenANSI

8
霍多尔霍多尔。霍多尔霍多尔霍多尔,霍多尔霍多尔霍多尔!霍多尔霍多尔,霍多尔霍多尔霍多尔。霍多尔霍多尔霍多尔,霍多尔霍多尔霍多尔!霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔吗?Hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor hodor ...
亚当戴维斯

1
@AdamDavis Hodorception!
马丁·恩德

1
我会用HODOR回答这个问题,但我认为我可能会使SE崩溃。
caird coinheringaahing

Answers:


26

霍多尔!霍多尔霍多尔?霍多尔霍多尔霍多尔霍多尔霍多尔。

霍多尔霍多尔霍多尔,霍多尔霍多尔霍多尔。

Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor。Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor。霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔,霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔。

Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor。霍多尔霍多尔霍多尔霍多尔霍多尔?Hodor Hodor Hodor Hodor Hodor Hodor Hodor Hodor。

霍多尔霍多尔霍多尔,霍多尔霍多尔霍多尔霍多尔。霍多尔霍多尔,霍多尔霍多尔霍多尔。

霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔霍多尔!

那只是语言和大小标题!没关系,让我们以无聊的旧ASCII编码帖子。抱歉,如果您在理解帖子时遇到了麻烦,霍多尔。


CJam,85个字节

这是我的尝试。当我编写这些代码时,它们的某些部分显得有些笨拙,因此有可能击败它!

qW%{'@^4md('.X1$N?_++a"?!."XLS?f++=\(_)2md","*1$)"hodor":Ha*H@+@(2/\tS*0:X'HtHeu?}%W%

在线尝试。

说明

qW%             "Read and reverse the input.";
{               "Map each character c:";
  '@^4md          "Calculate (c^64)/4, which is the sentence content determiner,
                    and c%4, which is the sentence ending determiner.";
  (               "Calculate c%4-1 for later.";
  '.X1$N?_++      "Produce the sentence ending string for the case that c%4==1,
                   which is '.' followed by two copies of:
                    - '.' if this is the first processed (last actual) character
                    - or a newline otherwise.
  a"?!."XLS?f     "Produce a list of the sentence ending strings for the cases
                   that c%4 is 2, 3, or 0, which are:
                    - '?', '!', and '.' if this is the first processed character
                    - or these punctuation marks each followed by a space
                      otherwise.";
  ++=\            "Prepend the sentence ending string for the case that c%4==1
                   to the list for the other cases and select the element at the
                   index (c%4-1)%4 as the correct sentence ending string.";
  (               "Calculate (c^64)/4-1 for later.";
  _)2md           "Calculate the quotient and remainder of the sentence content
                   content determiner divided by 2.";
  ","*            "Produce a string of commas with a length of the remainder
                   calculated above (either 0 or 1).";
  1$)"hodor":Ha*  "Produce a list of copies of 'hodor' with a length of the
                   quotient calculated above plus one.";
  H@+@(2/\t       "Append the string of commas (either empty or one comma) to
                   the middle 'hodor'.";
  S*              "Join the sentence words into a string a space between each.";
  0:X             "Signal that later characters are not the first processed.";
  'Ht             "Capitalize the first letter of the sentence (always 'h').";
  Heu             "Produce the string 'HODOR'.";
  ?               "Select the correct sentence content, which is 'HODOR' if 
                   (c^64)/4-1 is zero or the full sentence produced before that
                   otherwise.";
}%
W%              "Reverse the reversed translation to obtain the forward one.";
                "Implicitly print the result.";

1
将说明发布在Hodor中以使其更具可读性。
魔术章鱼缸

102

Hodor,602个 582字节

HoDoRHoDoR HODOR! (Hodor ){r='';Hodor!? =Hodor .Hodor!? hodor? HODOR? hodor! hodor. h;HODOR{}(Hodor? =0;Hodor? <Hodor!? ;++Hodor? ){hodor =Hodor .hodor hHODOR rHodor... odhodor? hodor?!? hodor. (Hodor? );HODOR? =(0|hodor /4+16)%32;r+='H';HODOR =HHHOOODDDDOOORRR!!! hodor?!? rrHODOR HODOR!?! (0|HODOR? /2+2);HOdor!!!(HODOR? %2)HODOR [0|(HODOR? +1)/4]=',';r+=HODOR? ==1?'ODOR':HODOR .HODOR?! oHodor? HODOR? (' hodor').Hodor Hodor!? Hodor? hodor hodor? (2);r+=['. ',Hodor? ==Hodor!? -1?'....':'.\HODOR? \HODOR? ','? ','! '][hodor %4]}HODOR:: r.Hodor Hodor!? Hodor? hodor hodor? (0,-1)}

这是非公开版本,您知道...的可读性:

HoDoRHoDoR HODOR! (Hodor ){
    r='';
    Hodor!? =Hodor .Hodor!? hodor? HODOR? hodor! hodor. h;
    HODOR{}(Hodor? =0;Hodor? <Hodor!? ;++Hodor? ){
        hodor =Hodor .hodor hHODOR rHodor... odhodor? hodor?!? hodor. (Hodor? );
        HODOR? =(0|hodor /4+16)%32;
        r+='H';
        HODOR =HHHOOODDDDOOORRR!!! hodor?!? rrHODOR HODOR!?! (0|HODOR? /2+2);
        HOdor!!!(HODOR? %2)HODOR [0|(HODOR? +1)/4]=',';
        r+=HODOR? ==1?'ODOR':HODOR .HODOR?! oHodor? HODOR? (' hodor').Hodor Hodor!? Hodor? hodor hodor? (2);
        r+=['. ',Hodor? ==Hodor!? -1?'....':'.\HODOR? \HODOR? ','? ','! '][hodor %4]
    }
    HODOR:: r.Hodor Hodor!? Hodor? hodor hodor? (0,-1)
}

是的,有一种叫做Hodor的语言。(这是相当新的。)从本质上讲,它只是JavaScript的字符串替换。相应的JS看起来像这样:

function f(s){
  r='';
  l=s.length;
  for(i=0;i<l;++i){
    c=s.charCodeAt(i);
    n=(0|c/4+16)%32;
    r+='H';
    a=new Array(0|n/2+2);
    if(n%2)a[0|(n+1)/4]=',';
    r+=n==1?'ODOR':a.join(' hodor').slice(2);
    r+=['. ',i==l-1?'....':'.\n\n','? ','! '][c%4]
  }
  return r.slice(0,-1)
}

因此,我的提交是一个接受字符串并返回Hodorized等效项的函数。

不幸的是,似乎没有关于Hodor实际工作方式的任何信息(除了解释器的源代码),但是它带有JS2HD翻译脚本。

注意,Hodor的替换也适用于字符串文字。因此,尽管您可以将上述函数称为

HODOR! ("CEE")

您还可以使用以下内容:

HODOR! ("Hodor... HooodorrHodor HooodorrHodor ")

在哪里Hodor... HooodorrHodor HooodorrHodor将被替换CEE。注意,这意味着,如果你的字符串包含的一些形式的Hodor必须对它进行编码,否则将被取代。例如"Hodor. ",实际上是"m"在JavaScript中。问题是字母[dhor](不区分大小写)根本不会被替换,因此您甚至无法对此进行编码。一种解决方案是拆分文字,如"Hod"+"or. ",以使替换步骤找不到要解码的内容。


36
这让我很高兴。
Alex A.

1
@AlexA。我想你是说“霍多尔!霍多尔霍多尔霍多尔!霍多尔?”
MikeTheLiar 2015年

最后一句标点符号仅...代替换行符,而不是....
mbomb007

1
@ mbomb007第四位.可以替换为任何东西。它是通常存在的空间的占位符,该占位符随final一起删除r.slice(0,-1)
马丁·恩德

1
582字节,但使用Hodor编程语言可获得-65535的奖励,该答案的得分为-59713,并且使这个答案明显是赢家;-)
Josh

5

Python 2中,219个 198字节

在这里尝试

使用与Martin的JavaScript相同的方法,在Python中缩短了几个字节。我利用Python 2.7的便捷整数除法。感谢Sp3000打高尔夫球。

def f(s,r='',i=2):
    for j in s:c=ord(j);n=(c/4+16)%32;a=['']*(n/2+2);a[-~n/4]=','[:n%2];r+='H'+[' hodor'.join(a)[2:],'ODOR'][n==1]+['. ',['.\n\n',4*'.'][i>len(s)],'? ','! '][c%4];i+=1
    return r[:-1]

为了您自己的娱乐以及我自己的享受和好奇心...

这是一个lambda函数

Python 2,349

在此处尝试使用该程序,以及上面的较旧版本的程序。

f=lambda s:'H'.join(['']+[('ODOR'if(ord(s[i])/4+16)%32==1 else' hodor'.join((['']*(((ord(s[i])/4+16)%32)/2+2))[:((ord(s[i])/4+16)%32+1)/4]+([',']if ord(s[i])/4%2 else[''])+(['']*(((ord(s[i])/4+16)%32)/2+2))[((ord(s[i])/4+16)%32+1)/4+1*(ord(s[i])/4%2<1):])[2:])+['. ',4*'.'if i+2>len(s)else'.\n\n','? ','! '][ord(s[i])%4]for i in range(len(s))])[:-1]

创造这一过程需要越来越多的替代品以及一些额外的创造力。

  • 每个j都替换为s[i]
  • 每个c都替换为ord(s[i])
  • 每个n都替换为(ord(s[i])/4+16)%32

    • 除了我只需要的地方n%2,所以我(ord(s[i])/4%2改用了。
  • 最后,a被替换为(['']*(((ord(s[i])/4+16)%32)/2+2))[:((ord(s[i])/4+16)%32+1)/4]+([',']if ord(s[i])/4%2 else[''])+(['']*(((ord(s[i])/4+16)%32)/2+2))[((ord(s[i])/4+16)%32+1)/4+1*(ord(s[i])/4%2<1):]

    • 这是因为我们无法分配值,因此我们必须将列表分成两半,有条件地附加逗号,然后再次附加最后一半。

1
我相信会给198吗?
Sp3000

很酷,我不知道您可以[:0]像这样切成空字符串。
mbomb007

4

流行性腮腺炎284个 236字节

新版本:查看了一段时间后,我想出了一个较短的版本(236字节):

H(H) S L=$L(H) F O=1:1:L D
 .S D=$A($E(H,O)),R=D#4,P=$S('R:".",R=2:"?",R=3:"!",O=L:"...",1:"."_$C(10,10)),E=D\4+16#32,(S,Q)="hodor" F F=1:1:E\2 S Q=S_$S(E#2&(F=(E\4+1)):", ",1:" ")_Q,$E(Q)="H" S:E=1 Q="HODOR"
 .W Q_P_$S(L=O:"",1:" ")
 Q

第一版:

H(H) S L=$L(H) F O=1:1:L D
 .S S=$C(10),D=$A($E(H,O)),R=D#4,P=$S('R:".",R=2:"?",R=3:"!",O=L:"...",1:"."_S_S),E=D\4+16#32,(S,Q)="hodor ",G=6*(E+1\4) F F=1:1:E\2 S Q=S_Q
 .S Q=$E(Q,1,$L(Q)-1) S:E=1 Q="HODOR" S:E#2&(E>2) Q=$E(Q,1,G-1)_","_$E(Q,G,99) S $E(Q)="H" W Q_P_$S(L=O:"",1:" ")
 Q

该死,CJam! 也许我可以使用ObjectScript(有列表运算符)保存一些字节,但是我对此表示怀疑。

这是一个有点冗长的版本:

VH(H)
 F I=1:1:$L(H) D              ; iterate over input string H
 .S O=$E(H,I)                 ; O is a single char
 .S D=$A(O)                   ; ascii code (dec)
 .S R=D#4                     ; #: mod, $S: $SELECT(condition:result,cond...)
 .S P=$S(R=0:".",R=2:"?",R=3:"!",I=$L(H):"...",1:"."_$C(10)_$C(10))
 .S E=D\4+16#32               ; \: integer division
 .S (S,Q)="hodor "            ; hodor
 .F J=1:1:E\2 S Q=S_Q         ; build hodor -"list"
 .I E=1 S Q="HODOR"           ; HODOR
 .I E'=1 S Q=$E(Q,1,$L(Q)-1)  ; remove trailing _
 .;                           ; insert ,
 .I E#2,E>2 S Q=$E(Q,1,6*(E+1\4)-1)_","_$E(Q,6*(E+1\4),99)
 .S $E(Q)="H"                 ; ^h->^H
 .W Q_P_$S($L(H)=I:"",1:" ")  ; Write and remove trailing _
 Q

1

C#378字节

string x(string h){string[]f={". ",".\n\n","? ","! "};string[]a=new string[32];string s="";int i,j,c=0;for(i=0;i<32;i++){a[i]="hodor";if(i==1)a[i]=a[i].ToUpper();else{for(j=0;j<i/2;j++){if(i%2==1&&j==c/2)a[i]+=",";a[i]+=" hodor";}if(i%2==1)c++;a[i]=char.ToUpper(a[i][0])+a[i].Substring(1);}}foreach(char b in h){s+=a[(int)(Math.Floor((double)b/4)+16)%32]+f[(int)b%4];}return s;}

这是我第一次打高尔夫球,所以裸着我。


1
欢迎使用编程难题和代码高尔夫球堆栈交换!您可以使用单字符函数名代替来保存一些字节hodor。你可能也(后如去掉一些即使不是所有的换行,和几个空格for奥得的if)。但是,您可能应该将using指令计为System或完全合格Console
马丁·恩德

谢谢您的帮助,我将尽力改善并保存一些字节:D。
GonacFaria 2015年

打高尔夫球的C#代码时,没有必要使用特定的访问修饰符。因此您可以删除public关键字以节省一些字节。您还可以删除[]包含数组的变量之间的空格和实际名称。同样,在foreach中遍历字符串的所有char时,也不必将字符串转换为char数组。你可以简单地做foreach (char c in h)
ProgramFOX

1
编辑,谢谢。设法将其减少到378个字节,这很有趣。
GonacFaria 2015年

0

C ++,547452字节

void H(string s){string e[4]={".",".\n\n","?","!"};string r;char c,m;int n=s.size();for(int i=0;i<n;i++){r.clear();c=s.at(i);m=c%4;r.append(A(c));r.append(e[m]);if(i==n-1){int k=r.size();r.pop_back();if(m==1){r.pop_back();r.append("..");}}cout<<r.c_str();}}string A(char x){string h("Hodor");int c=((int )floor(x/4)+16)%32;int n=c;bool o=(c%2==1);if(n==1)h="HODOR";else{while(n>1){h.append("hodor");if(o&&n==(int )(c/2)){h.append(",");}n--;}}return h;}

取消高尔夫:

#include <iostream>
#include <math.h>
using namespace std;
void Hodorise(string s);
string FromAscii(char c);

void Hodorise(string s)
{
string end[4] = {". ",".\n\n","? ","! "};
string res;
char c, m;
int n = s.size();
for (int i = 0; i < n; i++)
{
res.clear();
c = s.at(i);
m = c % 4;
res.append(FromAscii(c));
res.append(end[m]);
if (i == n - 1)
{
int k = res.size();
res.pop_back();
if (m == 1)
{
res.pop_back();
res.append("..");
}

}
cout << res.c_str();
}
}

string FromAscii(char c)
{
string hodor("Hodor");
int code = ((int)floor(c / 4) + 16) % 32;
int n = code;
bool odd = (code % 2 == 1);
if (n == 1)hodor = "HODOR";
else
{
while (n > 1)
{
hodor.append(" hodor");
if (odd && n==(int)(code/2))
{
hodor.append(",");
}
n--;
}
}
return hodor;
}
#define N 3
int main()
{
string x[N] = { "F0", "CEE", "Hodor's real name is Walder.\nDid you know ?" };
for (size_t i = 0; i < N; i++)
{
cout << endl << x[i].c_str() << ":\n";
Hodorise(x[i]);
}

char c;
cin >> c;
return 0;
}

1
我只统计505个字节。您是否将换行符算作\r\n代替\n?另外,为什么您甚至根本不需要这些换行符?
马丁·恩德

2
提交需要包括#includeusing namespace std;等等
Potatoswatter

提交答案的大多数人不算#include或进口等
bacchusbeale 2015年
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.