Python 2,14508 11700 11088 10164 9486 9746 7860 145字节* 36唯一= 5220
我看到了标题,并认为这对于相当冗长的Python来说是一个有趣的挑战。这些是我解决此问题时的注意事项。
我的第一次尝试将唯一性减少到31:
print''.join(chr([69,108,105,122,97,98,101,116,104,32,111,98,110,111,120,105,111,117,115,108,121,32,113,117,111,116,101,100,32,40,106,117,115,116,32,116,111,111,32,114,111,119,100,121,32,102,111,114,32,109,121,32,112,101,97,99,101,41,58,32,34,84,72,69,32,81,85,73,67,75,32,66,82,79,87,78,32,70,79,88,32,74,85,77,80,83,32,79,86,69,82,32,84,72,69,32,76,65,90,89,32,68,79,71,44,34,32,103,105,118,105,110,103,32,109,101,32,97,32,108,111,111,107,46][r])for r in range(124))
我以为我可以做得更好。通过使用map
,唯一性降至26:
print''.join(map(chr,(69,108,105,122,97,98,101,116,104,32,111,98,110,111,120,105,111,117,115,108,121,32,113,117,111,116,101,100,32,40,106,117,115,116,32,116,111,111,32,114,111,119,100,121,32,102,111,114,32,109,121,32,112,101,97,99,101,41,58,32,34,84,72,69,32,81,85,73,67,75,32,66,82,79,87,78,32,70,79,88,32,74,85,77,80,83,32,79,86,69,82,32,84,72,69,32,76,65,90,89,32,68,79,71,44,34,32,103,105,118,105,110,103,32,109,101,32,97,32,108,111,111,107,46)))
大约在这个时候,我在问题文本中注意到分数是uniques * bytes
,而不仅仅是唯一性!那意味着我的上述得分分别是14508和11700。现在,我通过将文本存储为十六进制字符串来减少字节:
# 308*36 = 11088
print''.join(chr(int('456c697a6162657468206f626e6f78696f75736c792071756f74656420286a75737420746f6f20726f77647920666f72206d79207065616365293a202254484520515549434b2042524f574e20464f58204a554d5053204f56455220544845204c415a5920444f472c2220676976696e67206d652061206c6f6f6b2e'[i*2:i*2+2],16)) for i in range(124))
尺寸减小了,但字符更加独特。但是,如果我使用带32偏移量的压缩2位十进制字符串:
# 308*33 = 10164
print''.join(chr(int('37767390656669847200796678798873798583768900818579846968000874858384008479790082798768890070798200778900806965676909260002524037004953413543003450475546003847560042534548510047543750005240370044335857003647391202007173867378710077690065007679797514'[i*2:i*2+2])+32) for i in range(124))
它具有相同的字节数,但保存3个唯一性。
我制定了一个新计划。如果我将Python长整数打包成7位字符,则可以通过以下方式提取每个整数:
# 306*31 = 9486
h=1073974643401006528619595312441225198653732186368270382545648881135648217524502741093886285232362673460172159947573049818819511630304840724474679255867143965214892747087773876949021986013520804726327302180335979259392708372721217579101211940864406962137554744750
w=''
while h:w=chr(h&127)+w;h>>=7
print w
好吧,该分数降低到了9486。这是一个有趣的实验,但远远不够。现在,如果我摆脱了函数名称并依靠字符串格式怎么办?
# 443 * 22 = 9746
print('%c'*124)%(69,108,105,122,97,98,101,116,104,32,111,98,110,111,120,105,111,117,115,108,121,32,113,117,111,116,101,100,32,40,106,117,115,116,32,116,111,111,32,114,111,119,100,121,32,102,111,114,32,109,121,32,112,101,97,99,101,41,58,32,34,84,72,69,32,81,85,73,67,75,32,66,82,79,87,78,32,70,79,88,32,74,85,77,80,83,32,79,86,69,82,32,84,72,69,32,76,65,90,89,32,68,79,71,44,34,32,103,105,118,105,110,103,32,109,101,32,97,32,108,111,111,107,46)
我现在只有22个唯一身份,但得分并没有提高。
好吧,如果我采用明显的方式并只打印了字符串怎么办:
# 131*60 = 7860
print'Elizabeth obnoxiously quoted (just too rowdy for my peace): "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG," giving me a look.'
得分7860。我应该首先这样做。但是我不会学到太多。
我想如果动态生成大写部分,我可以将唯一性减少26个,因此:
# 145*36 = 5220
print'Elizabeth obnoxiously quoted (just too rowdy for my peace): '+'"the quick brown fox jumps over the lazy dog,"'.upper()+' giving me a look.'
我认为Python不会比5220更好。最小化Python中唯一字符的任务当然很有启发性。
更新:mbomb007有一个更好的Python解决方案,得分5005。