Identicons sind kleine Bilder von geometrischen Mustern, die den Hashwert einer Zeichenfolge darstellen. Stack Exchange verwendet die Identicons von Gravatar als Standard- Avatarbild jedes Benutzers.
In dieser Herausforderung werden wir auch die Gravatar-Identicons verwenden, um Text zum Golfen zu generieren.
Herausforderung
Mit diesem Stack-Snippet (einer verkleinerten Version von JSFiddle ) können Sie eine Zeichenfolge eingeben und eine 100 × 100-Pixel-Schwarzweiß- Version des Identicons dieser Zeichenfolge sowie eine Textversion zurückgeben, in der 1
für Schwarz und 0
Weiß steht:
<!-- 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>
(Sie können damit auch die Stile Monster, Wavatar und Retro Gravatar laden, diese dienen jedoch nur zum Spaß und sind nicht für diese Herausforderung vorgesehen. Unicornicons fehlen aufgrund von XSS Einschränkungen.: /)
Ihre Aufgabe ist es, ein Programm zu schreiben, das den Textblock mit 100 × 100 Zeichen von 0
's und' s ausgibt1
' s generiert wird, wenn Sie den Namen Ihrer Programmiersprache in das Snippet-Eingabefeld eingeben.
Wenn Ihre Übermittlung beispielsweise in Python geschrieben ist , geben Sie Python
den Stack-Snippet ein und sehen, dass
ist das Identicon für Python und
ist die Schwarz-Weiß-Version (binär) und
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
ist die entsprechende Textausgabe, die Ihr Python-Programm erzeugen muss.
Da Identicons jedoch viele unangenehme Winkel aufweisen können und ihre Rasterung als Schwarzweißbild zu Unregelmäßigkeiten führen kann , darf Ihre Ausgabe bis zu 300 0
oder mehr 1
Punkte enthalten, die dem Gegenteil von dem entsprechen, was sie sein sollen. (Das sind 3% der 10000 Gesamt 0
's und 1
' s.)
Am unteren Rand des Snippets können Sie in der Ausgabe Ihres Programms einfügen und überprüfen , wie viele 0
's oder 1
ist anders als das, was sie sein sollten. Eine beliebige Anzahl von Differenzen bei oder unter 300 ist gültig.
Wertung
Die Einsendung mit den wenigsten Bytes gewinnt. ( Handlicher Bytezähler. )
Tiebreaker geht zur Einreichung mit den wenigsten Fehlern 0
und 1
Fehlern.
Wenn es immer noch ein Unentschieden gibt, gewinnt die frühere Einreichung.
Einzelheiten
- Die Ausgabe erfolgt nach stdout oder einer ähnlichen Alternative, wenn Ihre Sprache nicht über stdout verfügt.
- Die Ausgabe kann optional eine nachgestellte Newline enthalten.
- Bitte fügen Sie das Farbidenticon-Bild zusammen mit der genauen Zeichenfolge, die es generiert, in Ihren Beitrag ein. Es ist nicht erforderlich, Speicherplatz zu verschwenden und Ihre gesamte Textausgabe zu veröffentlichen.
- Ihr Programm sollte ohne Internetverbindung ausgeführt werden. Sie müssen den Text in Ihrem Code generieren und dürfen ihn nicht von der Gravatar-Site aus abfragen.
- Verwenden Sie gesunden Menschenverstand, wenn Sie Ihre Sprache "benennen". Verwenden Sie den Namen der Sprache, die Sie normalerweise auf dieser Site verwenden würden. Ärgern Sie sich nicht und erfinden Sie einen Namen, der das Golfspiel mit dem Identicon einfacher macht. zB
Python 2
ist in Ordnung für Python, aber espython 2.7.2
wird gedehnt undpython 2.7.2 by Guido van Rossum
wäre lächerlich. - Mir ist klar, dass einige Sprachen von Natur aus einfacher sind als andere, weil ihre Identicon-Formen einfacher sind. So wird es auch sein, sei nicht zu verärgert oder konkurrierend. ;)