通过图标识别堆栈交换站点


77

在Stack Exchange上花了一段时间之后,我可以通过它们的小图标(也是他们的收藏图标)来识别“热网络问题”中的大多数站点,但是当然不是全部。让我们编写一个可以的程序!给定(当前)132个图标之一,其中包括日语的Stack Overflow(仍处于私人Beta版),您将编写确定站点的代码:

学术界 Android爱好者 动漫与漫画 问不同 Arduino的 询问Ubuntu 天文学 航空 视频制作 啤酒 单车 生物学 比特币 搅拌机 棋盘游戏 葡萄牙语的堆栈溢出 乐高答案 佛教 化学 棋 中文 基督教 编程难题和代码高尔夫球 代码审查 认知科学 社区建设 经验丰富的建议 工艺CMS 密码学 计算机科学 理论计算机科学 数据科学 数据库管理员
家居装修 Drupal答案 信号处理 地球科学 电子书 经济学 电机工程 英语学习者 埃马克斯 英语语言及用法 外籍人士 ExpressionEngine答案 身体素质 自由职业 法语 游戏开发 Arqade 园艺与美化 家谱和家族史 德国的语言 地理信息系统 平面设计 业余电台 圣经诠释学 印度教 历史 自酿 科学与数学史 伊斯兰教 意大利语 日文堆栈溢出 日语 Joomla
弥耶弥 语言学 Magento 武术 数学 数学教育家 Mathematica MathOverflow 汽车维修与保养 元堆栈交换 个人理财与理财 影视 音乐,实践与理论 网络工程 公开资料 伟大的户外活动 为人父母 询问专利 宠物用品 哲学 摄影 物理 项目管理 扑克 政治 个人生产力 程式设计师 令人费解 定量金融 树莓派 逆向工程 机器人技术 角色扮演游戏
俄语 销售队伍 计算科学 科幻与幻想 信息安全 服务器故障 的SharePoint 怀疑论者 软件推荐 音效设计 太空探索 西班牙语 体育 软件质量保证与测试 堆栈应用 堆栈溢出 初创企业 交叉验证 超级用户 可持续生活 TeX-LaTeX 托尔 旅行 Tridion Unix和Linux 用户体验 网络应用 网站管理员 Windows Phone WordPress开发 工作场所 世界建设 作家

我已经将所有这些图像的ZIP文件上传为GitHub上的 PNG 。单击“原始”按钮将其下载。以上图标的顺序是zip中文件名的字母顺序。

相应的站点名称(按此顺序)是:

笔记:

  • 我已经®LEGO® Answers和中删除了ExpressionEngine® Answers,因此您不必担心Unicode。
  • 出于相同的原因,我在日语和葡萄牙语中使用英语名称表示“堆栈溢出”。
  • 地球科学西班牙语的图标是无法区分的。因此,给定这些图标之一,您的代码可能会返回(您选择的)这些站点中的任何一个。这同样适用于Magento的武术

规则

您可以编写一个程序或函数

  • 通过STDIN,命令行参数或函数参数接收图像的(本地)文件名,通过STDIN接收图像文件的内容
  • 返回或打印站点名称到STDOUT,如上所述。

您的代码必须正确识别所有132个站点(上述情况除外)。

您可能不对文件名做任何假设(例如,称为codegolf.png)。您可以假设图像的尺寸为16x16,并且确实是上面132张图像之一。上面的图像都是PNG,但是您可以使用任何其他方便的光栅图形格式,但是您必须自己转换图像。您不应对图像文件的实际字节流做出任何假设,除非它是您选择的任何格式的有效图像。特别是,如果有多种方法可以用您的格式对同一张图片进行编码(例如,通过将不相关的字段添加到标头部分),则您的代码必须适用于所有这些代码。简而言之,您的代码应仅依赖像素值本身,而不应依赖对其进行编码的文件的详细信息。

像往常一样,您可能无法从互联网上获取任何数据。您必须仅从图像确定站点。

您可以使用内置或第三方功能来读取图像文件并获取颜色值列表,但不得使用任何其他现有的图像处理功能。

这是代码高尔夫球,因此最短的答案(以字节为单位)获胜。


4
CRC32比MD5短。任何知道更短校验和算法的人都可能会获胜。
manatwork 2014年

1
@squeamishossifrage您可以根据像素值生成哈希。我不知道PNG格式有多灵活,但是无论选择哪种格式,如果有两个不同的文件对完全相同的图像进行编码,则您的程序必须同时适用于它们。因此,您可能无法对图像文件中的精确字节流做出任何假设,除非它是任意选择格式的有效图像。我应该澄清一下。
Martin Ender 2014年

1
@MartinBüttner是的,可以有两个不同的PNG对同一张图像进行编码,否则pngcrush将不存在。
kennytm 2014年

1
我认为,可以通过决策树分析图像中特定坐标处的像素来实现惊人的效果……我敢肯定,有一些简单的ML技术可以识别可用来区分图像的“关键特征” ...该抽出我的ML笔记了!
Mark K Cowan 2014年

1
@MarkKCowan看我的解决方案,我基本上做到了。对于每个像素,我都会列出所有图像中具有的不同颜色值。然后,我选择中间值,然后根据该像素中的颜色将图像分为两部分。然后递归地对两个部分进行相同的操作,直到获得单个图像为止。
Tom van der Zanden 2014年

Answers:


29

Python 3.x +枕头, 2301 1894年 1878字节

import sys,re,zlib as z,base64,PIL.Image as i
print(re.search(str(z.adler32(i.open(sys.argv[1]).tobytes()[2::6])%2003)+'(\\D+)',z.decompress(base64.b85decode(b'c${Tc%XZ>86#NyfdNqBH<%b?iLI_EpFkwO-GfQC$tcfjoB$+h*^;0s?o$g*?uzgjxs%~BKif!C3zALZEU!&?wJd#-mqgS@p<P&+)AsV|c*52*C>U&(1_4w^urvvWJU8Bj;bvv4ia;eiJLu+bsXLru`DjH|W<`|;xLq++kv5k8VWZgQe*`_u+opEF8>A6qjM%k#skzbiuJ7dL_*><K@9l6!M*H(|w)PZJ2`RYy7K2VVrv+zc)&2Fc?wvh|^#ksyymE?D!Q$3!LbFX%h%vT%1#lr486Iybw?0!`H)ZlZ#XIao2uXTr}(IBl@wRWHa#})bgV);O3HoW7+T*!5M3=^mu6Ri$`7L;uUWj~gsqR6gQR9h7^nKdBIgy>ats36%|M|8p1x;32(ZfK9R5_xK5ts=Sz70c%SIK&g3N1E|sg{n3>JSbKwwhssGcb$8uMNw=Nv;f_;rj?}kz(3-&#FQw@O;q(8nGHjbrTC(NQv=ckXT|eHr|amahCq(7T6<LBTr5Gj>fHV~3DcYINN!Qr`6Dl?jT>!4u5~bb%Zi6VTax;%vg*m325J_$nEC%yqbbYeEp!K_K7k)W-XCP`6+}N7tktMVX+{@c2L&kLAc&IvspGrzZ$F`uOBg}fA3W2neAU}tg~<+iCN=<sR^Zke+9WNhnCyy6!8nfa>33&OWiPt2s=OMTrUgilSYQxrG!gziB!Aj83zX&6S|yjIQkA?iF0n%?<+B=%_D11aoCv?@Q&eei{sqNkr7RG`#*xyzSUE6BUNnZK)3|3Wls}K$qaKv;jOO#!{3Ms)4CQ?shafnAF^zVq(`K9o2xL5JoQoGea+W1$+xmw&8OMOtN1Pid6UAcd+*_bB6IY$KjrO=ac^tPv3(8O`&(agOBbT{Va6s}Rm9&`I#yivC;MhW8=n+^^&Reho;~!~W<xgH6bVq3^=H7)sUXV2nv~DP4`CY`f55i&qH)DvPMQy>)y*Z=|68w@v=#oo5^RSh5R2F%1-vt>h=|+1n0pE^Yq-72!)1+o{hD_3<Cyxpyr6r%cei-AFQ*h1seM$MP>ovLS2k#Ci$to#do$s3MXu2lZsw~9HkbjVWM@1!{w>}LWVj#j2qC(+*Okc>=<qcV}*}+U_QK+(ZZ(x>ZMdDDWtgHiBK+7p6aHHI`u-h6z7|Xm`>D1t4uEp271y7oCI^{1^H~O7QRxTA_U&92Q8z$J2O|5Lbeg_0umd^pSU<%-ki7LtDvo&AgIt0h~6(y@Hr+kyLJ$<B#07KdGob0EW$7@f{GszaUv#tkpSyk759Khmvq-aiyM-_&x_VCTx$Vy<;$<k{T$-@{Mhc<<%KD1AHK^MKkg%pYIW}SxhV?&a{o9=rs@*+hqyoioE=TF>9S<KxY+^69^OA0jkS#0!w@kw4}KTcP9#+PVW+qB|7B`Y?eRs+7}8RSAs?i?-Cz#Wp(Iihd`nI!Q_i%R^o_;fvDQ5|{Cr;yWeirL>_l#(wn)$QenJkK6Sgw)5NleBzvo&G#@>X`7Ib*aS4LHx9epI%BXXV&y7LJ&54g}D25-Q8>DZQ5hGKyIeJkQQu08%j|<x~)q(AOVw9P~Z*c0Z@VM6n#<}tBT6+T%4mZ9f*y76xlEFM~o$xr9*SZHd^6D-C!pkkp3m(-~W3&>KY@106L+;I><MJ^Dz`f{(I3i?u`2pWjUjlwZx`B1JB#h#u3xTH*b1K?TG40|4lxF1$_Pw+t?h2')).decode()).group(1))

这个想法是对图像进行哈希处理,然后从字典中找到相应的字符串(就像其他答案一样)。

关键代码是这样的:

adler32(open(sys.argv[1]).tobytes()[2::6])%2003

我们打开文件,然后将其转换为1024字节的RGBA值字符串。经过一些试验,我们发现此字节字符串的每个第六字节的ADLER-32校验和对于这132张图像而言是唯一的。然后进一步的测试表明,取校验和的模数为2003可获得最小的字典。

原始字典如下:

{
    3: 'Programming Puzzles & Code Golf',
    6: 'Science Fiction & Fantasy',
    7: 'Bitcoin',
    8: 'Biblical Hermeneutics',
    …,
    1969: 'Unix & Linux',
    1989: 'WordPress Development',
    1993: 'Cognitive Sciences',
    2001: 'Personal Productivity',
}

我们注意到,所有站点名称都不包含数字。因此,我们可以将整个字典连接成一个字符串:

"256Software Quality Assurance & Testing3Programming Puzzles & Code Golf1284Geographic Info…"

然后使用正则表达式1969(\D+)提取站点名称。然后压缩这个巨大的字符串以节省空间(让压缩引擎注意“ Language”的多次出现),最后进行base-85编码。


由于现在也将其标记为,因此这里是一个不使用压缩的2394字节解决方案(zlib仍导入adler32)。

import sys,re,zlib,PIL.Image as i
l=' Language'
s='Science'
print(re.search(str(zlib.adler32(i.open(sys.argv[1]).tobytes()[2::6])%2003)+'(\\D+)','256Software Quality Assurance & Testing3Programming Puzzles & Code Golf1284Geographic Information Systems517Windows Phone6'+s+' Fiction & Fantasy7Bitcoin8Biblical Hermeneutics1034Writers1803Ask Different781Joomla597Islam1809Craft CMS878English'+l+' & Usage431Freelancing1565Politics32LEGO Answers289Physical Fitness1316Spanish'+l+'1830Database Administrators296Pets1066Philosophy1582Ask Patents560Cryptography1073Magento1588MathOverflow1333Salesforce1591Linguistics1844Stack Apps948Japanese'+l+'572Electrical Engineering778Genealogy & Family History735Sound Design63Open Data505Tridion328Arqade1609Hinduism588Music, Practice & Theory1101Expatriates846Network Engineering79German'+l+'1104Webmasters1208Signal Processing118Puzzling867ExpressionEngine Answers654Buddhism1593Quantitative Finance1625Parenting859Biology1117Academia1118Stack Overflow353Project Management1123Motor Vehicle Maintenance & Repair612Chinese'+l+'876Startups877Video Production110Reverse Engineering701French'+l+'677Bicycles1683Ebooks1908Blender190Physics1654Beer119History of '+s+' and Math1913Android Enthusiasts634Chemistry1252Travel1148Cross Validated1662Italian'+l+'565Sustainable Living387Programmers797Arduino1932Data '+s+'141Server Fault1422Chess109Amateur Radio147Computational '+s+'917Home Improvement1599Worldbuilding1438Mi Yodeya197Christianity1185Community Building1956Aviation1701Poker1703Mathematics Educators1704SharePoint425Meta Stack Exchange171Code Review1964Game Development1967Homebrewing944User Experience1969Unix & Linux1715Board & Card Games1716Graphic Design969Tor696Economics955Drupal Answers1213Raspberry Pi958The Great Outdoors885Mathematics1731Emacs1989WordPress Development910Photography1736Space Exploration1993Cognitive '+s+'s1227Computer '+s+'1230Mathematica207Gardening & Landscaping2001Personal Productivity1235Super User1358Information Security727Theoretical Computer '+s+'1497Earth '+s+'220Russian'+l+'1914Role-playing Games1758Movies & TV479Anime & Manga67English'+l+' Learners228Web Applications485Robotics593The Workplace232Astronomy1519Personal Finance & Money808Stack Overflow in Japanese1266Seasoned Advice467Software Recommendations1012Sports332Stack Overflow in Portuguese761History763Ask Ubuntu1957Skeptics85TeX - LaTeX').group(1))

@MartinBüttner:.tobytes()获取像素数据(16×16×4 = 1024),因此它依赖于图像。不过,该文件必须为RGBA。
kennytm 2014年

啊,太好了。我以为它将返回文件的实际字节流。据我所知,我上传的PNG图像没有Alpha通道?
Martin Ender 2014年

哦,看起来像他们一样...我想我把它搞砸了。
Martin Ender 2014年

枕头?是PIL吗?
TheDoctor 2014年

1
@TheDoctor:枕头是PIL叉子。PIL是无人维护和Python 3的不工作
kennytm

52

C#,2760字节

namespace System{class P{static void Main(){var c="us>g System;us>g System.Draw>g;class p{publ' stZ' void c(){var b=(Bitmap)Bitmap.FromFile(Console.ReadL>e());Console.Write(!1,1[3,3#2?!4,4#1?!5,5#2?!@#1?!+$SupK UsK*Salesforce%]^$< F't~_Fantasy%8,8#6?$Arqade*Ask Ubuntu%@#6?$WordPress Development%8,8#4?!9,9#2?$Phys's*UsK ExpKience%+$Travel*Craft CMS%5,5^!@#6?!]#1?$TeX - LaTeX%+$Mi Yodeya*Meta Stack Exchange%]#6?$ProgrammK|2,2#5?$Christianity*MZhemZ'a%@[]^$MZhemZ'|0,0#1?$Cross ValidZed*Theoret'al ComputK <%2,2^!]#5?$Seasoned Adv'e*Drupal AnswK|]^$Graph' Design*WebmastK|2,2^!4,4#5?!5,5#2?!@^$Ask PZents*Home Improvement%@#6?$Android Enthusiasts*Skept'|5,5#4?!@#5?$Web Appl'Z~s*English/_Usage%@#4?!]#8?$SharePo>t*B'ycle|]#1?$Electr'al Eng>eK>g*DZabase Adm>istrZor|4,4^!5,5#2?!+$Game Development*Photography%@:SKvK Fault%+$Geograph' InformZ~ Systems*Unix_L>ux%5,5^!0`Stack Apps*The Workplace%+!@[]#4?$InformZ~ Security*Ask DiffKent%]:Role-play>g Games*PKsonal F>ance_Money%3,9#8?$Academia%5,15^$& > Japanese%0,13:&*& > Portuguese%2,2:MZhOvKflow%3,3:AviZ~%4,4^$LEGO AnswK|5,5[@[][0,1:PokK*Anime_Manga%+$BlendK*H>duism%][8,8:WritK|0,1^!2`RaspbKry Pi*W>dows Phone%+$Biology*Worldbuild>g%9,9:Movies_TV%8,8[6`Trid~*Islam%0,1:Mus', Pract'e_Theory*L>guist'|][@[9,9:Ches|+!4,6:Garden>g_Landscap>g*Susta>able Liv>g%4,6:Buddhism*Startup|8,8:English/ LearnK|3,4[6,7:Network Eng>eK>g%9,5:Magento%+$Motor Veh'le Ma>tenance_Repair*MZhemZ's EducZor|4,8:GKman/%7`Joomla%7,6[+$QuantitZive F>ance*Ardu>o%9`Chemistry*Cryptography%8,8[0,1^!@[3`Tor%4,5:French/*The GreZ Outdoor|3`Project Management%3,6:Ch>ese/*Space ExplorZ~%+!2,6:Programm>g Puzzles_Code Golf%@:Cognitive <s*Signal Process>g%1,0:Ebook|@[4,5:Earth <*BeK%8,5:Emacs*ExpZriZe|1`History of < and MZh%3,4[@[+$Homebrew>g%3,6:DZa <*Video Product~%5,7:Russian/%9,4[4,8:Bibl'al HKmeneut's*Philosophy%11,6:Board_Card Games*Bitco>%3,5[@[3,8:AmZeur Radio%5,6:Genealogy_Family History%6,9:Software Quality Assurance_Test>g*Open DZa%3,6[11,7:Code Review%+$ComputK <*Community Build>g%10,6[+$Sports*Software RecommendZ~|9`Sound Design*ComputZ~al <%3,7:Japanese/%5,8[7,5:Puzzl>g%8,5:Econom's*Express~Eng>e AnswK|6,5[9,4[7`Freelanc>g*History%10,6:Italian/%6`Parent>g*Astronomy%6,7[9`RevKse Eng>eK>g*Robot'|10,8[+$Polit's*Pet|12,5:PKsonal Productivity*Phys'al Fitness$);}}";foreach(var s in "~ion;|s%;`,4:;&Stack OvKflow;_ & ;^#3?;]7,7;'ic;['!;Zat;Ker;@6,6;>in;<Science;:'$;/ Language;+0,0#3?;*$:$;'#7?;%$:!;$\";#).B%9<;!b.GetPixel(".Split(';'))c=c.Replace(s[0]+"",s.Substring(1));new Microsoft.CSharp.CSharpCodeProvider().CompileAssemblyFromSource(new CodeDom.Compiler.CompilerParameters("mscorlib.dll System.Core.dll System.Drawing.dll".Split()),c).CompiledAssembly.CreateInstance("p").GetType().GetMethod("c").Invoke(c,null);}}}

我的解决方案不使用哈希,它实际上检查图像的各个像素并根据该像素进行决策。我发现检查模9的蓝色分量就足够了。这个想法是根据pixel.B%9的值重复分割,如下所示:

b.GetPixel(3,4).B % 9 < 7 ? "Russian Language" : (b.GetPixel(8,4).B % 9 < 6 ? "Project Management" : "Philosophy")

我使用脚本生成了以下可怕的程序(5197字节),该程序使用二进制决策树解决了该问题:

using System;using System.Drawing;class p {public static void c(){var b=(Bitmap)Bitmap.FromFile(Console.ReadLine());Console.Write(b.GetPixel(4,5).B%9<6?b.GetPixel(1,1).B%9<5?b.GetPixel(1,10).B%9<1?b.GetPixel(3,4).B%9<1?b.GetPixel(2,8).B%9<2?b.GetPixel(0,0).B%9<3?b.GetPixel(3,10).B%9<8?"Super User":"Travel":b.GetPixel(0,2).B%9<3?"Salesforce":"Craft CMS":b.GetPixel(2,4).B%9<2?b.GetPixel(2,2).B%9<6?"Ask Ubuntu":"Ask Different":b.GetPixel(1,3).B%9<6?"Mathematics":"Programmers":b.GetPixel(2,7).B%9<3?b.GetPixel(2,4).B%9<1?b.GetPixel(2,8).B%9<2?"Database Administrators":"Christianity":b.GetPixel(0,1).B%9<3?"TeX - LaTeX":"Game Development":b.GetPixel(1,6).B%9<3?b.GetPixel(2,3).B%9<7?"English Language & Usage":"Skeptics":b.GetPixel(0,0).B%9<3?"StackApps":"Unix & Linux":b.GetPixel(0,6).B%9<1?b.GetPixel(1,4).B%9<2?b.GetPixel(1,5).B%9<3?b.GetPixel(0,4).B%9<1?"Arqade":"Mi Yodeya":b.GetPixel(1,6).B%9<6?"Drupal Answers":"User Experience":b.GetPixel(1,5).B%9<4?b.GetPixel(1,6).B%9<3?"SharePoint":"Bicycles":b.GetPixel(0,0).B%9<3?"Home Improvement":"Photography":b.GetPixel(0,0).B%9<3?b.GetPixel(0,7).B%9<2?b.GetPixel(0,1).B%9<1?"Science Fiction & Fantasy":"Theoretical Computer Science":b.GetPixel(0,4).B%9<2?"Android Enthusiasts":"Ask Patents":b.GetPixel(5,15).B%9<3?b.GetPixel(2,0).B%9<3?"Meta Stack Exchange":"Stack Overflow inJapanese":b.GetPixel(0,13).B%9<7?"Stack Overflow":"Stack Overflow in Portuguese":b.GetPixel(5,8).B%9<7?b.GetPixel(4,4).B%9<7?b.GetPixel(0,0).B%9<3?b.GetPixel(7,5).B%9<7?b.GetPixel(0,1).B%9<5?"German Language":"Server Fault":b.GetPixel(8,5).B%9<7?"Economics":"ExpressionEngine Answers":b.GetPixel(1,13).B%9<7?b.GetPixel(0,1).B%9<7?"Ebooks":"MathOverflow":b.GetPixel(7,5).B%9<7?"Buddhism":"Earth Science":b.GetPixel(6,6).B%9<7?b.GetPixel(4,6).B%9<7?b.GetPixel(3,6).B%9<7?"Poker":"Gardening & Landscaping":b.GetPixel(0,0).B%9<3?"Sustainable Living":"Startups":b.GetPixel(7,6).B%9<7?b.GetPixel(0,0).B%9<3?"Quantitative Finance":"Arduino":b.GetPixel(9,4).B%9<7?"Chemistry":"Cryptography":b.GetPixel(5,4).B%9<7?b.GetPixel(9,5).B%9<7?b.GetPixel(10,8).B%9<7?b.GetPixel(0,0).B%9<3?"Reverse Engineering":"Pets":b.GetPixel(12,5).B%9<7?"Personal Productivity":"Physical Fitness":b.GetPixel(6,7).B%9<7?b.GetPixel(3,4).B%9<7?"Tor":"Robotics":b.GetPixel(7,5).B%9<7?"Politics":"French Language":b.GetPixel(0,1).B%9<3?b.GetPixel(9,5).B%9<7?b.GetPixel(3,4).B%9<3?"LEGO Answers":"Magento":b.GetPixel(6,5).B%9<7?"Motor Vehicle Maintenance & Repair":"Network Engineering":b.GetPixel(2,6).B%9<7?b.GetPixel(0,0).B%9<7?"Programming Puzzles & Code Golf":"History of Science and Math":b.GetPixel(0,2).B%9<7?"Mathematics Educators":b.GetPixel(1,4).B%9<7?"Signal Processing":"Cognitive Sciences":b.GetPixel(3,6).B%9<7?b.GetPixel(4,6).B%9<5?b.GetPixel(5,8).B%9<5?b.GetPixel(6,5).B%9<7?b.GetPixel(9,8).B%9<7?b.GetPixel(1,1).B%9<7?"Geographic Information Systems":"Biblical Hermeneutics":b.GetPixel(11,6).B%9<7?"Board & Card Games":"Bitcoin":b.GetPixel(0,0).B%9<3?b.GetPixel(2,4).B%9<7?"RaspberryPi":"English Language Learners":b.GetPixel(8,5).B%9<7?"Emacs":"Expatriates":b.GetPixel(5,4).B%9<6?b.GetPixel(6,8).B%9<7?b.GetPixel(3,4).B%9<7?"Russian Language":"Amateur Radio":b.GetPixel(8,4).B%9<7?"Project Management":"Philosophy":b.GetPixel(0,7).B%9<7?b.GetPixel(1,1).B%9<7?"Cross Validated":"Homebrewing":b.GetPixel(0,1).B%9<7?"Web Applications":"Biology":b.GetPixel(3,4).B%9<7?b.GetPixel(0,2).B%9<3?b.GetPixel(1,7).B%9<6?b.GetPixel(1,6).B%9<6?"WordPress Development":"Electrical Engineering":b.GetPixel(1,1).B%9<7?"Physics":"Windows Phone":b.GetPixel(1,0).B%9<7?b.GetPixel(0,0).B%9<3?"Webmasters":"Academia":b.GetPixel(3,8).B%9<7?"Data Science":"Worldbuilding":b.GetPixel(6,6).B%9<7?b.GetPixel(5,6).B%9<7?b.GetPixel(0,1).B%9<7?"Genealogy & Family History":"Anime & Manga":b.GetPixel(6,9).B%9<7?"Software Quality Assurance & Testing":"Open Data":b.GetPixel(9,4).B%9<7?b.GetPixel(0,0).B%9<3?"Code Review":"Community Building":b.GetPixel(8,4).B%9<7?"Chinese Language":"Computer Science":b.GetPixel(5,6).B%9<6?b.GetPixel(4,4).B%9<7?b.GetPixel(9,8).B%9<7?b.GetPixel(10,6).B%9<7?b.GetPixel(0,0).B%9<3?"Sports":"Software Recommendations":b.GetPixel(1,1).B%9<7?"Information Security":"Sound Design":b.GetPixel(3,5).B%9<7?b.GetPixel(8,4).B%9<7?"Space Exploration":"Computational Science":b.GetPixel(0,0).B%9<3?"Tridion":"Puzzling":b.GetPixel(0,5).B%9<3?b.GetPixel(6,8).B%9<7?b.GetPixel(5,8).B%9<7?"Blender":"Writers":b.GetPixel(6,5).B%9<7?"Music, Practice & Theory":"Islam":b.GetPixel(0,1).B%9<3?b.GetPixel(0,4).B%9<7?"Mathematica":"The Workplace":b.GetPixel(0,0).B%9<3?"Linguistics":"Hinduism":b.GetPixel(6,4).B%9<5?b.GetPixel(9,8).B%9<7?b.GetPixel(3,7).B%9<7?b.GetPixel(0,0).B%9<3?"Japanese Language":"Aviation":b.GetPixel(7,6).B%9<7?"History":"Italian Language":b.GetPixel(9,4).B%9<7?b.GetPixel(5,3).B%9<7?"Chess":"Freelancing":b.GetPixel(0,0).B%9<3?"Parenting":"Beer":b.GetPixel(0,5).B%9<1?b.GetPixel(4,8).B%9<7?b.GetPixel(1,1).B%9<7?"Role-playing Games":"Movies & TV":b.GetPixel(6,8).B%9<7?"Astronomy":"The Great Outdoors":b.GetPixel(0,4).B%9<3?b.GetPixel(0,6).B%9<7?"SeasonedAdvice":"Personal Finance & Money":b.GetPixel(0,0).B%9<3?"Graphic Design":b.GetPixel(3,4).B%9<7?"Video Production":"Joomla");}}

有些人在其解决方案中使用了内置的压缩​​功能。我自己编写了一个脚本,该脚本可以识别常见的子字符串,并用单字符的简写形式代替它们。该代码被压缩为以下2502再见字符串:

us@g System;us@g System.Draw@g;class p {publ| st^| void c(){var b=(Bitmap)Bitmap.FromFile(Console.ReadL@e());Console.Write(!4,5#6?!1,1#5?!1,10#1?!3`#1?!2,8#2?*!3,10#8?$Sup] Us]+Travel~0,2_$Salesforce+Craft CMS~2`#2?!2,2#6?$Ask Ubuntu+Ask Diff]ent~1,3#6?$M^hem^|s+Programm]s~2,7_!2`#1?!2,8#2?$D^abase Adm@istr^ors+Christianity~0,1_$TeX - LaTeX+Game Development~1,6_!2,3[English/:Usage+Skept|s'*$StackApps+Unix:L@ux~0,6#1?!1`#2?!1,5_!0`#1?$Arqade+Mi Yodeya~1,6#6?$Drupal Answ]s+Us] Exp]ience~1,5#4?!1,6_$SharePo@t+B|ycles'*$Home Improvement+Photography'*!0,7#2?!0,1#1?$> F|tion:Fantasy+Theoret|al Comput] >~0`#2?$Android Enthusiasts+Ask P^ents~5,15_!2,0_$Meta Stack Exchange+Stack Ov]flow @Japanese~0,13[Stack Ov]flow+Stack Ov]flow @ Portuguese~5,8<4`%*!7,5<0,1#5?$G]man/+S]v] Fault~8,5[Econom|s+ExpressionEng@e Answ]s~1,13<0,1[Ebooks+M^hOv]flow~7,5[Buddhism+Earth >~6,6<4,6<3,6[Pok]+Garden@g:Landscap@g'*$Susta@able Liv@g+Startups~7,6%*$Quantit^ive F@ance+Ardu@o~9`[Chemistry+Cryptography~5`<9,5<10,8%*$Rev]se Eng@e]@g+Pets~12,5[P]sonal Productivity+Phys|al Fitness~6,7<3`[Tor+Robot|s~7,5[Polit|s+French/~0,1_!9,5<3`_$LEGO Answ]s+Magento~6,5[Motor Veh|le Ma@tenance:Repair+Network Eng@e]@g~2,6<0,0[Programm@g Puzzles:Code Golf+History of > and M^h~0,2[M^hem^|s Educ^ors~1`[Signal Process@g+Cognitive >s~3,6<4,6#5?!5,8#5?!6,5<9,8<1,1[Geograph| Inform^ion Systems+Bibl|al H]meneut|s~11,6[Board:Card Games+Bitco@'*!2`[Raspb]ryPi+English/ Learn]s~8,5[Emacs+Exp^ri^es~5`#6?!6,8<3`[Russian/+Am^eur Radio~8`[Project Management+Philosophy~0,7<1,1[Cross Valid^ed+Homebrew@g~0,1[Web Appl|^ions+Biology~3`<0,2_!1,7#6?!1,6#6?$WordPress Development+Electr|al Eng@e]@g~1,1[Phys|s+W@dows Phone~1,0%*$Webmast]s+Academia~3,8[D^a >+Worldbuild@g~6,6<5,6<0,1[Genealogy:Family History+Anime:Manga~6,9[Software Quality Assurance:Test@g+Open D^a~9`%*$Code Review+Community Build@g~8`[Ch@ese/+Comput] >~5,6#6?!4`<9,8<10,6%*$Sports+Software Recommend^ions~1,1[Inform^ion Security+Sound Design~3,5<8`[Space Explor^ion+Comput^ional >'*$Tridion+Puzzl@g~0,5_!6,8<5,8[Blend]+Writ]s~6,5[Mus|, Pract|e:Theory+Islam~0,1_!0`[M^hem^|a+The Workplace'*$L@guist|s+H@duism~6`#5?!9,8<3,7%*$Japanese/+Avi^ion~7,6[History+Italian/~9`<5,3[Chess+Freelanc@g'*$Parent@g+Be]~0,5#1?!4,8<1,1[Role-play@g Games+Movies:TV~6,8[Astronomy+The Gre^ Outdoors~0`_!0,6[SeasonedAdv|e+P]sonal F@ance:Money'*$Graph| Design~3`[Video Production+Joomla$);}}

解压缩所需的字典只有108个字节:

: & ;<%!;|ic;`,4;_#3?;^at;]er;[%$;@in;>Science;~'!;/Language;+'$;*!0,0#3?;'$:;%#7?;$\";#).B%9<;!b.GetPixel(

该词典使用分号作为分隔符,并包含单个字符,然后对其进行解压缩。因此,要解压缩,“:”将首先由“&”替换,然后将“ <”替换为“%!”,“ |” 通过“ ic”等等。字符串c的解压缩可以用非常简洁的方式表示:

foreach (var s in "[dictionary]".Split(';')) c = c.Replace(s[0] + "", s.Substring(1));

然后,在解压之后,我使用一些黑魔法来即时编译代码并运行它:

namespace System
{
    using Collections.Generic;
    using CodeDom.Compiler;
    using Microsoft.CSharp;
    using Linq;
    using Reflection;
    class P
    {
        static void Main()
        {
            var c = "us@g System;us@g System.Draw@g;class p {publ| st^| void c(){var b=(Bitmap)Bitmap.FromFile(Console.ReadL@e());Console.Write(!4,5#6?!1,1#5?!1,10#1?!3`#1?!2,8#2?*!3,10#8?$Sup] Us]+Travel~0,2_$Salesforce+Craft CMS~2`#2?!2,2#6?$Ask Ubuntu+Ask Diff]ent~1,3#6?$M^hem^|s+Programm]s~2,7_!2`#1?!2,8#2?$D^abase Adm@istr^ors+Christianity~0,1_$TeX - LaTeX+Game Development~1,6_!2,3[English/:Usage+Skept|s'*$StackApps+Unix:L@ux~0,6#1?!1`#2?!1,5_!0`#1?$Arqade+Mi Yodeya~1,6#6?$Drupal Answ]s+Us] Exp]ience~1,5#4?!1,6_$SharePo@t+B|ycles'*$Home Improvement+Photography'*!0,7#2?!0,1#1?$> F|tion:Fantasy+Theoret|al Comput] >~0`#2?$Android Enthusiasts+Ask P^ents~5,15_!2,0_$Meta Stack Exchange+Stack Ov]flow @Japanese~0,13[Stack Ov]flow+Stack Ov]flow @ Portuguese~5,8<4`%*!7,5<0,1#5?$G]man/+S]v] Fault~8,5[Econom|s+ExpressionEng@e Answ]s~1,13<0,1[Ebooks+M^hOv]flow~7,5[Buddhism+Earth >~6,6<4,6<3,6[Pok]+Garden@g:Landscap@g'*$Susta@able Liv@g+Startups~7,6%*$Quantit^ive F@ance+Ardu@o~9`[Chemistry+Cryptography~5`<9,5<10,8%*$Rev]se Eng@e]@g+Pets~12,5[P]sonal Productivity+Phys|al Fitness~6,7<3`[Tor+Robot|s~7,5[Polit|s+French/~0,1_!9,5<3`_$LEGO Answ]s+Magento~6,5[Motor Veh|le Ma@tenance:Repair+Network Eng@e]@g~2,6<0,0[Programm@g Puzzles:Code Golf+History of > and M^h~0,2[M^hem^|s Educ^ors~1`[Signal Process@g+Cognitive >s~3,6<4,6#5?!5,8#5?!6,5<9,8<1,1[Geograph| Inform^ion Systems+Bibl|al H]meneut|s~11,6[Board:Card Games+Bitco@'*!2`[Raspb]ryPi+English/ Learn]s~8,5[Emacs+Exp^ri^es~5`#6?!6,8<3`[Russian/+Am^eur Radio~8`[Project Management+Philosophy~0,7<1,1[Cross Valid^ed+Homebrew@g~0,1[Web Appl|^ions+Biology~3`<0,2_!1,7#6?!1,6#6?$WordPress Development+Electr|al Eng@e]@g~1,1[Phys|s+W@dows Phone~1,0%*$Webmast]s+Academia~3,8[D^a >+Worldbuild@g~6,6<5,6<0,1[Genealogy:Family History+Anime:Manga~6,9[Software Quality Assurance:Test@g+Open D^a~9`%*$Code Review+Community Build@g~8`[Ch@ese/+Comput] >~5,6#6?!4`<9,8<10,6%*$Sports+Software Recommend^ions~1,1[Inform^ion Security+Sound Design~3,5<8`[Space Explor^ion+Comput^ional >'*$Tridion+Puzzl@g~0,5_!6,8<5,8[Blend]+Writ]s~6,5[Mus|, Pract|e:Theory+Islam~0,1_!0`[M^hem^|a+The Workplace'*$L@guist|s+H@duism~6`#5?!9,8<3,7%*$Japanese/+Avi^ion~7,6[History+Italian/~9`<5,3[Chess+Freelanc@g'*$Parent@g+Be]~0,5#1?!4,8<1,1[Role-play@g Games+Movies:TV~6,8[Astronomy+The Gre^ Outdoors~0`_!0,6[SeasonedAdv|e+P]sonal F@ance:Money'*$Graph| Design~3`[Video Production+Joomla$);}}";
            foreach (var s in ": & ;<%!;|ic;`,4;_#3?;^at;]er;[%$;@in;>Science;~'!;/ Language;+'$;*!0,0#3?;'$:;%#7?;$\";#).B%9<;!b.GetPixel(".Split(';')) c = c.Replace(s[0] + "", s.Substring(1));

            var o = new CSharpCodeProvider().CompileAssemblyFromSource(new CompilerParameters("mscorlib.dll System.Core.dll System.Drawing.dll".Split()), c).CompiledAssembly.CreateInstance("p").GetType().GetMethod("c");
            o.Invoke(o, null);
        }
    }
}

请注意,此处用于说明的示例与2876字节解决方案中使用的示例略有不同。


2
我已将您的信息编辑为我们通常的格式,希望您不要介意!:)
Martin Ender 2014年

2
我认为,您可以删除名称空间以节省一些字节。
Qwertiy 2014年

31
有趣的是:i.imgur.com/MNnndMd.png-图片显示了在我的程序中每个图标中的哪些像素(以红色突出显示)用于标识它。
汤姆·范德赞丹2014年

2
@MartinBüttner不,那不会有所作为。非Beta站点可以被一个或两个像素识别,但是只有首先识别出其他站点后才能检查这些像素。更改比较顺序不会影响代码长度。该代码使用总共129个比较,鉴于存在130张图像,这是最佳的。
Tom van der Zanden 2014年

8
好主啊 世界需要更多像您这样的人。
拉丹2014年

15

Node.js, 3178 3130 2667 2608字节

计算每个文件的图像数据的SHA1哈希,并使用十六进制摘要的字节16到19,索引站点名称。

使用每个文件的SHA1哈希的十六进制摘要的字节12到16,索引站点名称。仅使用3个字节的十六进制摘要可能会有更短的组合。

function $(e){r=require;r("pngparse").parseFile(e,function(e,t){console.log("Academia;Android Enthusiasts;Anime & Manga;Ask Different;Arduino;Ask Ubuntu;Astronomy;Aviation;Video Production;Beer;Bicycles;Biology;Bitcoin;Blender;Board & Card Games;Stack Overflow in Portuguese;LEGO Answers;Buddhism;Chemistry;Chess;Chinese Language;Christianity;Programming Puzzles & Code Golf;Code Review;Cognitive Sciences;Community Building;Seasoned Advice;Craft CMS;Cryptography;Computer Science;Theoretical Computer Science;Data Science;Database Administrators;Home Improvement;Drupal Answers;Signal Processing;Earth Science;Ebooks;Economics;Electrical Engineering;English Language Learners;Emacs;English Language & Usage;Expatriates;ExpressionEngine Answers;Physical Fitness;Freelancing;French Language;Game Development;Arqade;Gardening & Landscaping;Genealogy & Family History;German Language;Geographic Information Systems;Graphic Design;Amateur Radio;Biblical Hermeneutics;Hinduism;History;Homebrewing;History of Science and Math;Islam;Italian Language;Stack Overflow in Japanese;Japanese Language;Joomla;Mi Yodeya;Linguistics;Magento;Martial Arts;Mathematics;Mathematics Educators;Mathematica;MathOverflow;Motor Vehicle Maintenance & Repair;Meta Stack Exchange;Personal Finance & Money;Movies & TV;Music, Practice & Theory;Network Engineering;Open Data;The Great Outdoors;Parenting;Ask Patents;Pets;Philosophy;Photography;Physics;Project Management;Poker;Politics;Personal Productivity;Programmers;Puzzling;Quantitative Finance;Raspberry Pi;Reverse Engineering;Robotics;Role-playing Games;Russian Language;Salesforce;Computational Science;Science Fiction & Fantasy;Information Security;Server Fault;SharePoint;Skeptics;Software Recommendations;Sound Design;Space Exploration;Spanish Language;Sports;Software Quality Assurance & Testing;Stack Apps;Stack Overflow;Startups;Cross Validated;Super User;Sustainable Living;TeX - LaTeX;Tor;Travel;Tridion;Unix & Linux;User Experience;Web Applications;Webmasters;Windows Phone;WordPress Development;The Workplace;Worldbuilding;Writers".split(";")[x=r("crypto").createHash("sha1").update(t.data).digest("hex").slice(16,20),x=="c7da"?27:"f38c4a899f50c7d09a0f9dde6e05bbaebb274fc59f1ba9c4b8c315490f3d887b55f27c526f6f79c7db63f12feccafebf80fde98b13f6f6dbb8e59d6b97a09fe8cb0101f6abc8c963004f2f1aafbe216457ef8210ea104d841381d529cdd2697cf809f3d5cb0f1d91d970a981c41fe617d62c01284afdbbf78588490de40a56a0c7e613480354d13a738a84fc0bf2433d2351d585039c9795f8167997d15c1b2c8144ca40223794e66864608e305d5271faddc88177ef9d44bbd4c752b9d938ec92af827550fb".match(/.{3}/g).indexOf(x.slice(0,3))])})}

“语言”一词被使用了9次。您可以为其使用变量。
manatwork 2014年

没有观察到站点名称。谢谢。
cPu1 2014年

6
您可以将表的大小减少446字节。切换为CSV格式:(h="17352368".match(/.{4}/g)将4个字符散列,分成一个数组),s="MathOverflow;StackOverflow in Portuguese".split(";")(名称之间用;分隔),然后再次将它们放在一起:(t={}h.forEach(function(k,i){t[k]=s[i]})与代码产生相同的对象)。有132个分号,因此,即使您切换为2个字节的字符(OP表示站点名称中不应包含Unicode),也可以节省空间。另外,您可以在此额外的节省之上添加@manatwork的优化。
RikkusRukkus 2014年

您可以通过保留split()s 进一步缩短它:我们使用一个字符串,例如“ 1234Site; 5678Other”。然后,假设哈希片段和站点名称之间没有冲突,那么一个人match()就能做到:function $(e){r=require;return"8d4fAcademia;3a6dAndroid Enthusiasts;5caeAnime & Manga;804cAsk Different;bef3Arduino".match(r("crypto").createHash("sha1").update(r("fs").readFileSync(e)).digest("hex").slice(12,16)+"([^;]+)")[1]}
manatwork 2014年

@MartinBüttner,最初的帖子没有提到不允许文件哈希。我正在对文件进行哈希处理,但是现在更新了我的帖子以对图像数据进行哈希处理。
cPu1 2014年

5

Python 2.7版,1906年 1889年字节

此解决方案在像素数据上使用CRC32,以创建唯一的2位以95为基数的标识符。然后,使用标识符的索引查找答案字符串。

棘手的一点是找到了哈希样式函数的组合,这些函数将导致132个(或131个)小的但唯一的标签。在解决这个问题之前,我尝试了一些选择。看起来很紧凑。

该程序使用Python PIL从文件中读取像素数据。

import sys,re,zlib as Z,base64 as B,PIL.Image as P
g=lambda p:chr(32+Z.crc32(p)%95)
D=P.open(sys.argv[1]).tostring()
print Z.decompress(B.b64decode('eJxlVc164zYMvPMpeMqp+xDexHGyX9yocX7aIyzBFmuKUPljR/v0HdCxE+9eLBiEwAEwGM1a6nhwZGahi+I6Ow+5L8lRygk+N7C9sksKW0Sknb1xmw1HDtnMYldckOp9WZeQC8wcJcgwmdneUXYSzKvrWGwTpSttdXxnjua7a6fWc4IhXrYTnrkVh1PPodMAodjh4mt9LGhA6CpTu7OPe44bLwfrgm0k5rItnNg8zBePdhbSgSOSlq7rXRrMdY/KgGlSKyX8uoBo+4ByCm0ZjohzR8HlyQDkNtIwuLC1Tfn5E/gUgXRsF+I3plpPvHd8gL3FO27PdtU6Di3wXcswFE1kvxfnO2QxK6YkgTs76/auxXWRNtleL1ewpjHrdWM/6ZtjyRxPucxzzxI5u5a8/e3whjJd/FkTSpp1wK21Uha04E4wt/thjLLnQad1E8uIbKcWrdw24C9KBvSkWOcUc3/OO1+L7JKZtzpO18Ly3OZYEc3DFm3kWN8KW+9Sf+6ofWCKQW+YD6Sv/Xp+ZV+Sdn7+PhLyUUbnYEdFIeGY+oyy6adUr7x1OegAbyOzp9Dq1bBD+5nZKEvsDe/ZyzgcCfofqA1/7DjoUK80uEstjfr+ggOTkg/+Wxqcn+wdGihgy4LjQOFLaj6OyrX2PmwEh0plu5pS5iGZxcfZDSe01cxwzCXaJ+qcgNlrX2u4Q1JcWbK2884FbA8oerpSB7aOfFBkHz4rm9M8LHBjCXNv7pOnwdxn8u4rwt+X4weNpGQ3J+Mz+IfI4Mksnf0HlJ7IPODWoosAZEtEhCx4RiwGGBOzOjNWiT4CzradY6uPhPv0UrVPUMxScG5fGQ3yjBpcyBxIa7rCMo3kolmyMrpWMH9ve8Bk02D+EuroT9FLrNKEfFhAXcznV7OETrV/gMUEbakxdXMm8yfng8TdBVUfRw5W90XXyy4iU7aPJXei8BtSTdMwlbMGAwwou2H96Z2XJLqoTS/npT1yM6lq/IvVUIlE5yrxGtlBwhrxrjbsXMpJBfdf1abyXNVGL/+rEFBkqsryUbl5ojSuOYIQjTPQH7zBF5U9yVrqTU/i+dvoaVK2H1XzqWCxLphC0DVwWOWoSkvlMtCdVv9EuVtXBbtuR8iUJnPBfW5L1DpWHIEIMcVns+rRxwZCDnPHYwW1kk0+wI1pt5BI6HvNoAcFrP5YmtVIuBNK4CUevxzwhK/SAYcoF8/50CyvcjtLqcQPjjxzqlM8smk2jr9+N/QvvhrwX0dJyb4iBwBxZ1ZlRB0vCaNblZRBVFqDsQ8YFxI+89/2G7DgaZ4lmudIUBo8XKdgX4J7V31xobwbzaGlYDq1o2+8VigqA8fK4RjwfdXRv0EI5JAsqBUQKbFrVAsvhEz5ipMdJtvWGN+tT5+YNwxB8/wPEZPMIw==')).split('\n')[re.findall('..','''<3 JlXAa}J>33:7XotUSZDHC }=c4G]wdaIwhi)Xa(h6B"jdfcQ_0^\wLo{Iyn7;XaRco&w7Ht(/]v^$u~?0:r,!?*y``7>5j%\SAq`G{v@&'#LuZn7)['#JTY d4(6mR%ljnE@/s6s6A-[&-\kR*[C$3*qgY25!vy&~>0H<TEGV.N$K_y|m5O#)nkhwg=E+CYmW<c /BQgFHgujMCm`793uA)T.&'f$vFRh zXin[3q:y\CGH.!hAw=k5v!gCd4g0]mU/'O''').index(g(D)+g(D*3))]

Python 2.7 2150字节

这是一个不使用压缩或编码库的版本。堆栈交换列表通过一种简单的交换方法进行压缩。文本中未使用的字符:

`~!@#$%^*()_+=[]{}:;"<>?/0123456789

用于保存常见的字符串段。文本未用for k,v in [(v[0],v[1:]) for v in K.split('|')]:T=T.replace(k,v)行压缩。两个字符的索引表与上述程序中的相同。

import sys,re,zlib as Z,PIL.Image as P
g=lambda p:chr(32+Z.crc32(p)%95)
D=P.open(sys.argv[1]).tostring()
K='~ Engineer?|%]ematic|^*{|)Computer @|[ Develop3|" Answ7|! Language|@Science|#Software|$ Design|*Stack |(Japanese|_History|+Programm|=English|` & |<tion|>raph|?ing|/Ask |]Math|{Overflow|}tics|:logy|;ian|0Data|1Game|2ance|3ment|4Home|5ard|6ity|7ers|8Exp|9The'
T='Academia|Android Enthusiasts|Anime`Manga|/Different|Arduino|/Ubuntu|Astronomy|Avia<|Video Produc<|Beer|Bicycles|Bio:|Bitcoin|Blender|Bo5`C5 1s|^ in Portuguese|LEGO"|Buddhism|Chemistry|Chess|Chinese!|Christ;6|+? Puzzles`Code Golf|Code Review|Cognitive @s|Commun6 Build?|Seasoned Advice|Craft CMS|Cryptog>y|)|9oretical )|0 @|0base Administrators|4 Improve3|Drupal"|Signal Process?|Earth @|Ebooks|Economics|Electrical~|=! Learn7|Emacs|=!`Usage|8atriates|8ressionEngine"|Physical Fitness|Freelanc?|French!|1[|Arqade|G5en?`Landscap?|Genea:`Family _|German!|Geog>ic Informa< Systems|G>ic$|Amateur Radio|Biblical Hermeneu}|Hinduism|_|4brew?|_ of @ and ]|Islam|Ital;!|^ in (|(!|Joomla|Mi Yodeya|L?uis}|Magento|Martial Arts|%s|%s Educators|%a|]{|Motor Vehicle Mainten2`Repair|Meta *Exchange|P7onal Fin2`Money|Movies`TV|Music, Practice`9ory|Network~|Open 0|9 Great Outdoors|Parent?|/Patents|Pets|Philosophy|Photog>y|Physics|Project Manage3|Poker|Poli}|P7onal Productiv6|+7|Puzzl?|Quantitative Fin2|Raspberry Pi|Rev7e~|Robo}|Role-play? 1s|Russ;!|Salesforce|Computa<al @|@ Fic<`Fantasy|Informa< Secur6|Server Fault|SharePoint|Skep}|# Recommenda<s|Sound$|Space 8lora<|Spanish!|Sports|# Qual6 Assur2`Test?|*Apps|^|Startups|Cross Validated|Super User|Sustainable Liv?|TeX - LaTeX|Tor|Travel|Tridion|Unix`Linux|User 8erience|Web Applica<s|Webmast7|Windows Phone|WordPress[|9 Workplace|Worldbuild?|Writ7|'
for k,v in [(v[0],v[1:]) for v in K.split('|')]:T=T.replace(k,v)
print T.split('|')[re.findall('..','''<3 JlXAa}J>33:7XotUSZDHC }=c4G]wdaIwhi)Xa(h6B"jdfcQ_0^\wLo{Iyn7;XaRco&w7Ht(/]v^$u~?0:r,!?*y``7>5j%\SAq`G{v@&'#LuZn7)['#JTY d4(6mR%ljnE@/s6s6A-[&-\kR*[C$3*qgY25!vy&~>0H<TEGV.N$K_y|m5O#)nkhwg=E+CYmW<c /BQgFHgujMCm`793uA)T.&'f$vFRh zXin[3q:y\CGH.!hAw=k5v!gCd4g0]mU/'O''').index(g(D)+g(D*3))]

0

C#,2672字节

using System.IO;using System.IO.Compression;using System.Security.Cryptography;using System.Text;namespace l
{internal class Program
{private static void Main(string[]args)
{string m="H4sIAAAAAAAEAGVWy3bbNhT8Fayyas8hxTd2IAk66bEa1XKSdgmRsISaBFgAtKN8fQeU5dgnKxHAxcV9zMxVmXasF4OclKBpkzE9 WKMGwrU/LU4J5x1t8phpNUnygWyFPgrKupS5R9KqhwdppfY0iltmh0VpQ+OyDWdfDov2C43h3XlrtJnONOo69qSEV0bTbBN/VYM0 ZGfNsPSXPdbVUloaNUWt+nM/SkfLNK+VGc3xTOu2qpXvjdK02hT1KPUA46ZsaiPsgOCa8HMjJlyra7b3on8kn5+kfRjNM1Ga7Iz1 y3GRTtIky275zWfCtHuW1tEs6eplGE7KTbSo4+aEeiDuM23jBgvnaJSXzUlpXCa3KMIijhJJ4NDCUAmt/JkmmxjpHK2YJqWPZLf8 +IEcQmRmkOTGjA+0ZZt1cSeflHymXVk35ojL6kmSfa+k7hF9lWSNmaYlOCX1osYB7mgeJXspnNFyIGx4Ur2kXdE0Vjx40mz3cB01 9jz7EMB8OlO4hpd58dJeXdO8iu5P0ljpVS9G8st5G8et8OJ1nURFWB8E0mYDsgpVEd6gZG1efTQAxadptuZJTgEHLE5au8zwfC1s xLO9OmrsoDLIzYVMSs65sP70+kxVb/jBmEdHGWO8D3BRPboSx3yUvbdrsFwfUX9pg4d0w7AclTu9doPcSmF1eJNXJZ8E7hdZ9ovV B/LFhd6lPOffZwHfwgectRxLGwI0+vLSaw5dl+xOZ7cG0SmvAxx4XXdWylHoPsSTtQWWuv/5EIAZByySVj7J0cxrfaKyZvY/sI12 PLoBXKUOQPkQbg2uF3PwFSfljdRSBNDjqBOTGs/kIypvAEjO+I20k9A/X0pKbF26rnryST8YnAdGkf3ZeTmhC5vo5uW4lQ79oG3X MBjJxZI7MShDU1bW6jCuSX7EA4hg8aEJRcc+Kg1ygxoo2jWOKstC+w9WPq8NafjLCTEP174SZAXJ8KeQ+Cc3iolGrPzkxajexl9v 4l/J+oeYRWAb5WV7/X5zJU/+MGYaoVlRtFXkH3DqLGjeFbeIZgmU7INw1VtYa28unxZEBTQtNC2L8hCYDIWCZVpUb5aEQ5IuKM9Y /PNA0Kwsw/IaKM052xoYkq8SxR0lslXaSy1C9h/A8lkoi8eSrQysWrPk3/sT8kDfWLMDvoxecXW9swXBoZVVszWQiKAe919Bo24L Oe5/A40E1HK1XJl8pqzc/Cn9s7GP7yjS8fjzLDUJ/KUNq2BNbqwUnnxe/GBCclXNdyIIeLBP8iwI9w6g0ChQ3eU7GQpVxbuTGo0z QVMYr3Yn8yoxLIovzIBdmoHh/4KtYUig6ivgNyXfmUfINE/znRnVS7Hj17yv8v8U9LPM2qt+Bt61cbZK6Cp+dffXIhCpF6tWvtSL Vml2J9x8kBbI2yla5DWkFbflu2LEXXZnDmZ9PmniO4NW/U7mUZwD/15mRlHcLeD/W2jmbbwX0HBQalXH5KKYK7sQ/VW/eFxdId+p dZitxNVeuDC32neclP1iQ7Y17/bSIlZYLqOnaZrvT2jHDhPO06qr9o9yXiOuKr43D/4Zh4BUj9GA2bd6Q5Gidm8W8OyF2AXL97NA IJCz0djLtG0ajk39Vggp26T72QQucJ6+ukeRxzB1mHOLfUHkvXQrQuq4vSCYzTMeTpL3rKVdyrGDGYvTkrPGGufIV/hDrHKgeVLv lxnpfnEAxCZL94vzoIs4oBm3QMCqffxe/o3W3Ar8QpWre2MhVu29FZBRWhTFvVVDyKmrmi9afQ/iqfTyPSAhOA55o+drWzLefpOH EG7QtUu92CbG3oQ/NuuoaJtvEDfz7AhwrcNIz74ZO+zCJHgn3W2dBAbh8BGwgfMy5liMw+E6n7Ok+obGwu3/ajKqV1QJAAA=";string f=BitConverter.ToString(new SHA1Managed().ComputeHash(File.OpenRead(Console.ReadLine()))).Replace("-","").Substring(0,3);foreach(string n in d(m).Split(':'))
{if(f==n.Substring(0,3))
{Console.WriteLine(n.Substring(3,n.Length-3));break;}}}
public static String d(String c)
{byte[]d=Convert.FromBase64String(c);using(MemoryStream i=new MemoryStream(d))
using(GZipStream z=new GZipStream(i,CompressionMode.Decompress))
using(MemoryStream o=new MemoryStream())
{z.CopyTo(o);StringBuilder sb=new StringBuilder();return Encoding.UTF8.GetString(o.ToArray());}}}}

标签表和部分SHA哈希表(字符串)经过压缩以节省一些字节。原始字典如下:

84FAcademia:4C5Android Enthusiasts:C61Anime & Manga:AF4Ask Different:01DArduino:18DAsk Ubuntu:14FAstronomy:0FFAviation:521Video Production:5AFBeer:0C7Bicycles:846Biology:BD9Bitcoin:927Blender:C8CBoard & Card Games:BBAStack Overflow in Portuguese:355LEGO Answers:53FBuddhism:7B1Chemistry:D1CChess:068Chinese Language:52CChristianity:321Programming Puzzles & Code Golf:DA2Code Review:F8BCognitive Sciences:935Community Building:603Seasoned Advice:F7CCraft CMS:DA0Cryptography:8BCComputer Science:690Theoretical Computer Science:D11Data Science:307Database Administrators:D69Home Improvement:A13Drupal Answers:0E5Signal Processing:8EEEarth Science:9B2Ebooks:AAAEconomics:511Electrical Engineering:42AEnglish Language Learners:E98Emacs:755English Language & Usage:4E6Expatriates:8DEExpressionEngine Answers:FF3Physical Fitness:EBBFreelancing:5D7French Language:C81Game Development:08BArqade:FE0Gardening & Landscaping:138Genealogy & Family History:EAEGerman Language:38EGeographic Information Systems:020Graphic Design:DFCAmateur Radio:4A8Biblical Hermeneutics:7FAHinduism:4E6History:955Homebrewing:4CEHistory of Science and Math:08BIslam:0A8Italian Language:B21Stack Overflow in Japanese:E8DJapanese Language:B63Joomla:400Mi Yodeya:6F7Linguistics:C6BMagento:C6BMartial Arts:506Mathematics:479Mathematics Educators:5A1Mathematica:588MathOverflow:6EAMotor Vehicle Maintenance & Repair:503Meta Stack Exchange:3ACPersonal Finance & Money:09CMovies & TV:0EFMusic, Practice & Theory:A82Network Engineering:FE1Open Data:CA9The Great Outdoors:9BEParenting:365Ask Patents:BF6Pets:591Philosophy:AE9Photography:A01Physics:545Project Management:28EPoker:E46Politics:471Personal Productivity:85DProgrammers:D15Puzzling:6BFQuantitative Finance:945Raspberry Pi:76BReverse Engineering:1F5Robotics:3C1Role - playing Games:B77Russian Language:6D1Salesforce:D13Computational Science:E19Science Fiction & Fantasy:BDDInformation Security:BEFServer Fault:446SharePoint:9F9Skeptics:99ESoftware Recommendations:D0DSound Design:7A6Space Exploration:CCESpanish Language:A24Sports:EE4Software Quality Assurance & Testing:B1DStack Apps:D33Stack Overflow:F4EStartups:8EACross Validated:63BSuper User:254Sustainable Living:13ETeX - LaTeX:8D9Tor:DFDTravel:777Tridion:F9CUnix & Linux:945User Experience:5EDWeb Applications:A21Webmasters:EDCWindows Phone:525WordPress Development:DB3The Workplace:81EWorldbuilding:539Writers

15
看起来您正在获取文件的哈希,而不是实际图像数据的哈希。因此,如果我在不更改图像的情况下向文件中添加了一些元数据,这不会破坏代码吗?
Martin Ender 2014年

1
1)var应该安全几个字节。2)stringbuilder是什么?我看不到用过。3)StreamReader.ReadToEnd可能也会有所帮助。
CodesInChaos
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.