标识是表示字符串的哈希值的几何图案的小图像。Stack Exchange 使用Gravatar中的标识作为每个用户的默认头像图像。
在此挑战中,我们还将使用Gravatar identicons生成一些文本以供打高尔夫球。
挑战
这个堆栈片段(此JSFiddle的简化版本)使您可以输入字符串,并返回该字符串的identicon的100×100像素黑白版本,以及1
用于黑色和0
白色的文本版本:
<!-- Click "Run code snippet" --> <div style='text-align:center;'> <input id='str' type='text' size='32' value='Python'> <button type='button' onclick='go()'>Go</button><br><br><input id='type1' name='type' type='radio' value='identicon' checked> <label for='type1'>Identicon</label> <input id='type2' name='type' type='radio' value='monsterid'> <label for='type2'>Monster</label> <input id='type3' name='type' type='radio' value='wavatar'> <label for='type3'>Wavatar</label> <input id='type4' name='type' type='radio' value='retro'> <label for='type4'>Retro</label> <br><br><a id='origLink'>original</a><br><canvas id='original' style='border:1px solid gray;'> Your browser does not support the canvas tag. </canvas> <br><br>binary<br><canvas id='binary' style='border:1px solid gray;'> </canvas> <br><br>text</br> <textarea id='text' style='background-color:#eee' readonly></textarea> <br><br>your text</br> <textarea id='userText'></textarea><br><button type='button' onclick='markDiffs()'>Mark Differences With X</button><br><br><span id='diffCount'></span> <br><br><small>(this snippet has only been tested in Chrome and Firefox)</small></div><script src='https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script><script>function rgbDist(t,n){return Math.sqrt((Math.pow((t[0]-n[0])/255,2)+Math.pow((t[1]-n[1])/255,2)+Math.pow((t[2]-n[2])/255,2))/3)}function toBinImg(t,n){for(var r=0;r<t.data.length;r+=4){var e=rgbDist([t.data[r],t.data[r+1],t.data[r+2]],[255,255,255])<n;t.data[r]=t.data[r+1]=t.data[r+2]=e?255:0}}function getText(t){for(var n="",r=0,e=0;SIZE>e;e++){for(var o=0;SIZE>o;o++)n+=t.data[r]?"0":"1",r+=4;e!=SIZE-1&&(n+="\n")}return n}function markDiffs(){var t=0,n=$("#text").val().split("\n"),r=$("#userText").val(),e=new RegExp("(?:[01]{"+SIZE+"}\n){"+(SIZE-1)+"}(?:[01]{"+SIZE+"})\n?");if(!r.match(e))return void $("#diffCount").text("bad input");r=r.split("\n");for(var o="",a=0;SIZE>a;a++){for(var i=0;SIZE>i;i++)r[a][i]!==n[a][i]?(o+="X",t++):o+=r[a][i];o+="\n"}r[r.length-1].length&&(o=o.substring(0,o.length-1)),$("#diffCount").text(t+" differences found"),$("#userText").val(o)}function go(){var t=new Image;t.crossOrigin="anonymous",t.src="https://www.gravatar.com/avatar/"+md5($("#str").val())+"?&s="+SIZE+"&d="+$("input:radio[name=type]:checked").val(),$("#origLink").attr("href",t.src),t.onload=function(){ctxOrig.drawImage(t,0,0);var n=ctxOrig.getImageData(0,0,SIZE,SIZE);toBinImg(n,.05),$("#text").val(getText(n)),ctxBin.putImageData(n,0,0)}}var SIZE=100;$("#str").keyup(function(t){13==t.keyCode&&go()}),$("input[name=type]:radio").change(go),$(function(){var t=$("#original"),n=$("#binary");t.prop({width:SIZE,height:SIZE}),n.prop({width:SIZE,height:SIZE}),$("#text").prop({rows:SIZE+5,cols:SIZE+5}),$("#userText").prop({rows:SIZE+5,cols:SIZE+5}),ctxOrig=t[0].getContext("2d"),ctxBin=n[0].getContext("2d"),go()}),!function(t){"use strict";function n(t,n){var r=(65535&t)+(65535&n),e=(t>>16)+(n>>16)+(r>>16);return e<<16|65535&r}function r(t,n){return t<<n|t>>>32-n}function e(t,e,o,a,i,u){return n(r(n(n(e,t),n(a,u)),i),o)}function o(t,n,r,o,a,i,u){return e(n&r|~n&o,t,n,a,i,u)}function a(t,n,r,o,a,i,u){return e(n&o|r&~o,t,n,a,i,u)}function i(t,n,r,o,a,i,u){return e(n^r^o,t,n,a,i,u)}function u(t,n,r,o,a,i,u){return e(r^(n|~o),t,n,a,i,u)}function c(t,r){t[r>>5]|=128<<r%32,t[(r+64>>>9<<4)+14]=r;var e,c,f,g,d,h=1732584193,s=-271733879,v=-1732584194,I=271733878;for(e=0;e<t.length;e+=16)c=h,f=s,g=v,d=I,h=o(h,s,v,I,t[e],7,-680876936),I=o(I,h,s,v,t[e+1],12,-389564586),v=o(v,I,h,s,t[e+2],17,606105819),s=o(s,v,I,h,t[e+3],22,-1044525330),h=o(h,s,v,I,t[e+4],7,-176418897),I=o(I,h,s,v,t[e+5],12,1200080426),v=o(v,I,h,s,t[e+6],17,-1473231341),s=o(s,v,I,h,t[e+7],22,-45705983),h=o(h,s,v,I,t[e+8],7,1770035416),I=o(I,h,s,v,t[e+9],12,-1958414417),v=o(v,I,h,s,t[e+10],17,-42063),s=o(s,v,I,h,t[e+11],22,-1990404162),h=o(h,s,v,I,t[e+12],7,1804603682),I=o(I,h,s,v,t[e+13],12,-40341101),v=o(v,I,h,s,t[e+14],17,-1502002290),s=o(s,v,I,h,t[e+15],22,1236535329),h=a(h,s,v,I,t[e+1],5,-165796510),I=a(I,h,s,v,t[e+6],9,-1069501632),v=a(v,I,h,s,t[e+11],14,643717713),s=a(s,v,I,h,t[e],20,-373897302),h=a(h,s,v,I,t[e+5],5,-701558691),I=a(I,h,s,v,t[e+10],9,38016083),v=a(v,I,h,s,t[e+15],14,-660478335),s=a(s,v,I,h,t[e+4],20,-405537848),h=a(h,s,v,I,t[e+9],5,568446438),I=a(I,h,s,v,t[e+14],9,-1019803690),v=a(v,I,h,s,t[e+3],14,-187363961),s=a(s,v,I,h,t[e+8],20,1163531501),h=a(h,s,v,I,t[e+13],5,-1444681467),I=a(I,h,s,v,t[e+2],9,-51403784),v=a(v,I,h,s,t[e+7],14,1735328473),s=a(s,v,I,h,t[e+12],20,-1926607734),h=i(h,s,v,I,t[e+5],4,-378558),I=i(I,h,s,v,t[e+8],11,-2022574463),v=i(v,I,h,s,t[e+11],16,1839030562),s=i(s,v,I,h,t[e+14],23,-35309556),h=i(h,s,v,I,t[e+1],4,-1530992060),I=i(I,h,s,v,t[e+4],11,1272893353),v=i(v,I,h,s,t[e+7],16,-155497632),s=i(s,v,I,h,t[e+10],23,-1094730640),h=i(h,s,v,I,t[e+13],4,681279174),I=i(I,h,s,v,t[e],11,-358537222),v=i(v,I,h,s,t[e+3],16,-722521979),s=i(s,v,I,h,t[e+6],23,76029189),h=i(h,s,v,I,t[e+9],4,-640364487),I=i(I,h,s,v,t[e+12],11,-421815835),v=i(v,I,h,s,t[e+15],16,530742520),s=i(s,v,I,h,t[e+2],23,-995338651),h=u(h,s,v,I,t[e],6,-198630844),I=u(I,h,s,v,t[e+7],10,1126891415),v=u(v,I,h,s,t[e+14],15,-1416354905),s=u(s,v,I,h,t[e+5],21,-57434055),h=u(h,s,v,I,t[e+12],6,1700485571),I=u(I,h,s,v,t[e+3],10,-1894986606),v=u(v,I,h,s,t[e+10],15,-1051523),s=u(s,v,I,h,t[e+1],21,-2054922799),h=u(h,s,v,I,t[e+8],6,1873313359),I=u(I,h,s,v,t[e+15],10,-30611744),v=u(v,I,h,s,t[e+6],15,-1560198380),s=u(s,v,I,h,t[e+13],21,1309151649),h=u(h,s,v,I,t[e+4],6,-145523070),I=u(I,h,s,v,t[e+11],10,-1120210379),v=u(v,I,h,s,t[e+2],15,718787259),s=u(s,v,I,h,t[e+9],21,-343485551),h=n(h,c),s=n(s,f),v=n(v,g),I=n(I,d);return[h,s,v,I]}function f(t){var n,r="";for(n=0;n<32*t.length;n+=8)r+=String.fromCharCode(t[n>>5]>>>n%32&255);return r}function g(t){var n,r=[];for(r[(t.length>>2)-1]=void 0,n=0;n<r.length;n+=1)r[n]=0;for(n=0;n<8*t.length;n+=8)r[n>>5]|=(255&t.charCodeAt(n/8))<<n%32;return r}function d(t){return f(c(g(t),8*t.length))}function h(t,n){var r,e,o=g(t),a=[],i=[];for(a[15]=i[15]=void 0,o.length>16&&(o=c(o,8*t.length)),r=0;16>r;r+=1)a[r]=909522486^o[r],i[r]=1549556828^o[r];return e=c(a.concat(g(n)),512+8*n.length),f(c(i.concat(e),640))}function s(t){var n,r,e="0123456789abcdef",o="";for(r=0;r<t.length;r+=1)n=t.charCodeAt(r),o+=e.charAt(n>>>4&15)+e.charAt(15&n);return o}function v(t){return unescape(encodeURIComponent(t))}function I(t){return d(v(t))}function l(t){return s(I(t))}function p(t,n){return h(v(t),v(n))}function E(t,n){return s(p(t,n))}function S(t,n,r){return n?r?p(n,t):E(n,t):r?I(t):l(t)}"function"==typeof define&&define.amd?define(function(){return S}):t.md5=S}(this);//thanks https://github.com/blueimp/JavaScript-MD5/blob/master/js/md5.min.js</script>
(它还允许您加载Monster,Wavatar和Retro Gravatar样式,但是这些只是为了娱乐而已,并不意味着可以用于此挑战。不幸的是,由于XSS限制,缺少了Unicornicons。:/)
您的任务是编写一个程序,该程序输出在将您的编程语言的名称放入代码段输入框中时生成的100×100个字符0
的s和1
的文本块。
例如,如果您的提交是用Python编写的,则可以输入Python
堆栈片段并查看
是Python的identicon,并且
是黑白(二进制)版本,并且
0000000000000000000000011111111111111111111111111100000000000000000000000010000000000000000000000000
0000000000000000000001111011111111111111111111111100000000000000000000011110000000000000000000000000
0000000000000000000111111011111111111111111111111100000000000000000001111110000000000000000000000000
0000000000000000011111111011111111111111111111111100000000000000000111111110000000000000000000000000
0000000000000001111111111001111111111111111111111100000000000000001111111110000000000000000000000000
0000000000000111111111111001111111111111111111111100000000000000111111111110000000000000000000000000
0000000000001111111111111000111111111111111111111100000000000111111111111110000000000000000000000000
0000000000000011111111111000111111111111111111111100000000011111111111111110000000000000000000000000
0000000000000000111111111000011111111111111111111100000001111111111111111110000000000000000000000000
0000000000000000001111111000001111111111111111111100000011111111111111111110000000000000000000000000
0000000000000000000011111000001111111111111111111100001111111111111111111110000000000000000000000000
0000000000000000000000111000000111111111111111111101111111111111111111111110000000000000000000000000
0000000000000000000000001000000111111111111111111111111111111111111111111110000001000000000001000000
0000000000000000000000111000000111111111111111111111111111111111111111111110000011000000000001100000
0000000000000000000011111000000011111111111111111111111111111111111111111110000011100000000011100000
0000000000000000001111111000000011111111111111111111111111111111111111111110000111100000000011110000
0000000000000000111111111000000001111111111111111111111111111111111111111110000111110000000111110000
0000000000000011111111111000000001111111111111111111111111111111111111111110001111110000000111111000
0000000000001111111111111000000000111111111111111111111111111111111111111110001111111000001111111000
0000000000000111111111111000000000011111111111111111111111111111111111111110011111111000001111111100
0000000000000001111111111000000000011111111111111111111111111111111111111110011111111100011111111100
0000000000000000011111111000000000001111111111111111111111111111111111111110111111111100011111111110
0000000000000000000111111000000000001111111111111111111111111111111111111110111111111110111111111110
0000000000000000000001111000000000001111111111111111111111111111111111111111111111111110111111111111
0000000000000000000000011000000000000111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000000001
0111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000001111
0111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000000111111
0111111111111111111111111000000000000000000000000000000000000000000000000000000000000000000011111111
0011111111111111111111111000000000000000000000000000000000000000000000000000000000000000000111111111
0011111111111111111111111000000000000000000000000000000000000000000000000000000000000000011111111111
0001111111111111111111111000000000000000000000000000000000000000000000000000000000000011111111111111
0001111111111111111111111000000000000000000000000000000000000000000000000000000000001111111111111111
0000111111111111111111111000000000000000000000000000000000000000000000000000000000111111111111111111
0000011111111111111111111000000000000000000000000000000000000000000000000000000001111111111111111111
0000011111111111111111111000000000000000000000000000000000000000000000000000000111111111111111111111
0000001111111111111111111000000000000000000000000000000000000000000000000000111111111111111111111111
0000001111111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000001111111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000111111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000111111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000011111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000011111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000001111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000000111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000000111111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000000011111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000000011111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000000011111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
0000000000001111111111111000000000000000000000000000000000000000000000000001111111111111111111111111
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111000000000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111100000000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111100000000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111110000000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111110000000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111111000000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111111000000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111111100000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111111100000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111111110000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111111110000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111111111000000
1111111111111111111111111000000000000000000000000000000000000000000000000001111111111111111111000000
1111111111111111111111110000000000000000000000000000000000000000000000000001111111111111111111100000
1111111111111111111111000000000000000000000000000000000000000000000000000001111111111111111111100000
1111111111111111111100000000000000000000000000000000000000000000000000000001111111111111111111110000
1111111111111111110000000000000000000000000000000000000000000000000000000001111111111111111111110000
1111111111111111000000000000000000000000000000000000000000000000000000000001111111111111111111111000
1111111111111100000000000000000000000000000000000000000000000000000000000001111111111111111111111000
1111111111110000000000000000000000000000000000000000000000000000000000000001111111111111111111111100
1111111111000000000000000000000000000000000000000000000000000000000000000001111111111111111111111100
1111111100000000000000000000000000000000000000000000000000000000000000000001111111111111111111111110
1111110000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111110
1111000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111
1100000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111110000000000001100000000000000000000000
1111111111111111111111111111111111111111111111111111111111111111000000000001111000000000000000000000
0111111111110111111111111111111111111111111111111111111111111111000000000001111110000000000000000000
0111111111110011111111110111111111111111111111111111111111111111100000000001111111100000000000000000
0011111111100011111111110111111111111111111111111111111111111111100000000001111111111000000000000000
0011111111000001111111100111111111111111111111111111111111111111110000000001111111111110000000000000
0001111111000001111111100111111111111111111111111111111111111111110000000001111111111111000000000000
0001111111000000111111000111111111111111111111111111111111111111111000000001111111111100000000000000
0000111110000000111111000111111111111111111111111111111111111111111000000001111111110000000000000000
0000111110000000011110000111111111111111111111111111111111111111111100000001111111000000000000000000
0000011100000000011100000111111111111111111111111111111111111111111100000001111100000000000000000000
0000011100000000001100000111111111111111111111111111111111111111111110000001110000000000000000000000
0000001000000000001100000111111111111111111111111111111111111111111110000001000000000000000000000000
0000000000000000000000000111111111111111111111111011111111111111111111000001110000000000000000000000
0000000000000000000000000111111111111111111111100011111111111111111111000001111100000000000000000000
0000000000000000000000000111111111111111111110000011111111111111111111100001111111000000000000000000
0000000000000000000000000111111111111111111000000011111111111111111111100001111111110000000000000000
0000000000000000000000000111111111111111100000000011111111111111111111110001111111111100000000000000
0000000000000000000000000111111111111110000000000011111111111111111111110001111111111111000000000000
0000000000000000000000000111111111111000000000000011111111111111111111111001111111111110000000000000
0000000000000000000000000111111111100000000000000011111111111111111111111001111111111000000000000000
0000000000000000000000000111111110000000000000000011111111111111111111111101111111100000000000000000
0000000000000000000000000111111000000000000000000011111111111111111111111101111110000000000000000000
0000000000000000000000000111100000000000000000000011111111111111111111111111111000000000000000000000
0000000000000000000000000110000000000000000000000011111111111111111111111111100000000000000000000000
是您的Python程序必须产生的相应文本输出。
但是,由于identicon可能有很多笨拙的角度,并且由于其黑白图像的光栅化可能会留下锯齿,因此您的输出最多可以有300个0
或1
多个与它们应有的相反。(这是10000 0
和1
的总数的3%。)
在摘要的底部附近,您可以粘贴程序的输出,并检查多少个0
或1
多个与应有的不同。任何等于或小于300的差异均有效。
计分
字节最少的提交将获胜。(方便的字节计数器。)
Tiebreaker将提交的错误数0
和错误数减至最少1
。
如果仍然有平局,则较早的提交将获胜。
细节
- 如果您的语言没有stdout,输出将输出到stdout或类似的替代项。
- 输出可以选择包含尾随换行符。
- 请在您的帖子中包括颜色identicon图片以及生成它的确切字符串。无需浪费空间并发布整个文本输出。
- 您的程序应在没有Internet连接的情况下运行。您需要在代码中生成文本,而不是从Gravatar网站查询文本。
- “命名”语言时,请使用常识。使用您通常在此站点上使用的语言名称。不要烦人,不要制造一个容易使identicon易于打高尔夫球的名称。例如
Python 2
,对于Python来说很好,但是python 2.7.2
正在扩展它,python 2.7.2 by Guido van Rossum
这很荒谬。 - 我意识到某些语言在本质上比其他语言容易,因为它们的identicon形状更简单。那就是它的样子,不要对此感到太不满或竞争。;)