C #, 2760 byte
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);}}}
La mia soluzione non usa l'hashing, in realtà esamina i singoli pixel dell'immagine e decide in base a quello. Ho scoperto che era sufficiente esaminare il componente blu dell'immagine modulo 9. L'idea è quella di dividere ripetutamente in base al valore di pixel.B% 9, in questo modo:
b.GetPixel(3,4).B % 9 < 7 ? "Russian Language" : (b.GetPixel(8,4).B % 9 < 6 ? "Project Management" : "Philosophy")
Utilizzando uno script, ho generato il seguente programma mostruoso (5197 byte) che risolve il problema utilizzando un albero decisionale binario:
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");}}
Alcune persone hanno utilizzato funzioni di compressione integrate nelle loro soluzioni. Ne ho creato uno mio, scrivendo una sceneggiatura che identifica sottostringhe comuni e le sostituisce con abbreviazioni a carattere singolo. Il codice viene compresso nella seguente stringa di bye 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$);}}
Il dizionario necessario per la decompressione è di soli 108 byte:
: & ;<%!;|ic;`,4;_#3?;^at;]er;[%$;@in;>Science;~'!;/Language;+'$;*!0,0#3?;'$:;%#7?;$\";#).B%9<;!b.GetPixel(
Il dizionario utilizza i punti e virgola come delimitatore e contiene singoli caratteri seguiti dalla loro decompressione. Quindi per decomprimere, ":" verrebbe prima sostituito da "&", quindi "<" da "%!", "|" da "ic" e così via. La decompressione di una stringa c può essere espressa in modo abbastanza conciso:
foreach (var s in "[dictionary]".Split(';')) c = c.Replace(s[0] + "", s.Substring(1));
Quindi, dopo la decompressione, utilizzo un po 'di black-reflection magica per compilare il codice al volo ed eseguirlo:
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);
}
}
}
Si noti che gli esempi utilizzati qui per la spiegazione sono leggermente diversi da quelli utilizzati nella soluzione a 2876 byte.