Deciphering XKCD colors

38

9

Randall Munroe (author of XKCD) held a survey to give names to colors. The main outcome is a list of names for the 954 most common RGB monitor colors.

For ease of programming, here is the list in plain text: http://xkcd.com/color/rgb.txt. Beware, the first line is not data, but contains the license.

Write a program or function that takes a valid color name from above list as input and outputs the associated RGB color code. Your program does not have to handle invalid inputs in any defined manner.

Standard loopholes apply. Additionally, your answer must not use pre-defined (built-in or external) color code <-> color name maps. (This includes the linked list.) Shortest code in bytes wins. If you read from a file, the file's byte count must be included.

Examples:

dark peach -> #de7e5d   
robin's egg blue -> #98eff9 
pink/purple -> #ef1de7  

orlp

Posted 2016-08-17T05:18:06.997

Reputation: 37 067

10Are we allowed to access that file online? – Leaky Nun – 2016-08-17T05:18:52.857

6@LeakyNun That's a standard loophole. On top of that it's explicitly disallowed in the 4th paragraph of my challenge. – orlp – 2016-08-17T05:19:25.560

21shit #7f5f00 – Leaky Nun – 2016-08-17T05:48:46.443

12bubble gum pink #ff69af, bubblegum pink #fe83cc – Leaky Nun – 2016-08-17T06:40:34.097

4@LeakyNun what about baby shit brown #ad900d :D. I already see our designer suggest this color to customers. – Jeroen – 2016-08-17T06:42:16.693

21@LeakyNun The first is the color of really sick swollen gums, the second is the color of a type of candy. – Adám – 2016-08-17T07:23:26.923

So I'm guessing using canvas, setting the fillStyle and checking the imageData is not allowed... – Patrick Roberts – 2016-08-17T14:10:11.253

Are packers like bzip2 and p7zip allowed? – YetiCGN – 2016-08-17T17:11:33.127

@YetiCGN Yes, they are allowed. – orlp – 2016-08-17T17:42:52.947

1Am I going crazy or are there only 949, not 954, colors in the file? – Jordan – 2016-08-17T18:02:23.043

1@Jordan you are not crazy - there are 950 lines in that file, and one of them is the license text. – corsiKa – 2016-08-17T19:30:43.167

1Funny how many colors are related to human defecation such as diarrhea #9f8303 or piss yellow #ddd618 as well as other body fluids, such as vomit yellow, vomit green or blood red and dried blood. – Tomáš Zato - Reinstate Monica – 2016-08-18T09:36:02.530

1My personal favourite is "Ugly Blue" – Jon Story – 2016-08-18T14:28:14.067

Can we output the color code with capital letters? (e.g. #DE7E5D instead of #de7e5d) – 2012rcampion – 2016-08-19T15:58:13.577

there are only 949 colors, not 954 – Display Name – 2016-08-19T17:43:26.310

caution: "bright red" in rgb.txt doesn't have a trailing tab – ngn – 2016-08-22T10:07:04.493

Can we have a leaderboard here? – YetiCGN – 2016-08-26T22:34:01.007

baby sh*t green #889717 lol – FantaC – 2017-05-31T00:06:20.730

Answers

21

Perl 5 - 4212 3956 3930

use IO::Uncompress::Gunzip qw(gunzip);
gunzip 'g'=>\$_;
while(/(\x00*)(.)(.)(.)(.)/gs){$c[$i+=ord($2)+255*length$1]=sprintf"#%02x%02x%02x\n",map{ord}$3,$4,$5}
@a[32,33,39,47,97..123]=(3,1812,3,17,82,4,1013,119,3,909,8,10,10,1827,1219,4,718,265,228,418,2347,10,3,31,3,1786,921,380,1223,1915,4);
$_=<>;
for$i(0..(($h=y///c-1)<=12?$h-1:12)){$h+=$a[(($i/2|0)==1)+ord((/./g)[$i])]if($i!=7&&$i!=10)}
print$c[$h];

407 bytes for the code and 3523 for the data file. Binary data is read from the file 'g', a hexdump of which can be found here.

This uses a perfect hash function generated using GNU gperf, which assigns each color name to a unique integer in the range 0 to 6304 that can be used to index a table. The gzipped data contains the color values in the format of 1 byte indicating the offset in the table from the previous color, then 3 bytes for the color itself (with two hex digits per byte). (A 0 byte for the offset means it's actually the next value + 255, since not every offset fit in one byte).

The code parses the data to create the table containing the color rgb string, then applies the hash function (translated to perl) to the input to select the matching output from the table.

Usage:

echo 'pale red' | perl get-color.pl
#d9544d

Edit: Further reduced the size by gzipping the data file

faubi

Posted 2016-08-17T05:18:06.997

Reputation: 2 599

Oh, right. I could've just gzipped my file probably. – Value Ink – 2016-08-17T21:25:20.660

2You can use "gunzip g; zopfli --i100 g; mv g.gz g" to reduce your data file to 3496 bytes – Glenn Randers-Pehrson – 2016-08-17T23:37:12.267

1

Would you be interested in writing a few words on how you use gperf, perhaps in this tips thread? http://codegolf.stackexchange.com/questions/59238/golfing-strings

– Jordan – 2016-08-18T15:55:20.800

1Very nice approach! You've managed to get me interested in gperf, although I tried something different in PHP that ended up about a kilobyte bigger... – YetiCGN – 2016-08-19T01:42:29.050

15

EXCEL, 18 (+ 18269)

Just to set a baseline, I will show the simplest Excel solution that I could think of:

Code

The code in Excel is very simple:

=VLOOKUP("";A:B;2)

The input should be placed between the double quotes.

Data

The data should be stored in a .csv file, looking rougly like this:

pinkish purple;#d648d7

When I click on the CSV it automatically opens excel, and places the data in columns A and B, you may need a different separator.

Dennis Jaheruddin

Posted 2016-08-17T05:18:06.997

Reputation: 1 848

13

Ruby, 5,379 88 + 9 + 5,220 = 5,317 bytes

+9 bytes for -rdigest flag.

n=$*.pop
$><<?#+$<.read.unpack("h*")[0][/^.{11}*#{Digest::MD5.hexdigest(n)[1,5]}\K.{6}/]

...plus a 5,220-byte dictionary as binary data read from STDIN (or filename argument). You'll find the dictionary in xxd format in the snippet below. The program takes a color name as an argument, so you invoke it like this:

$ cat dictionary | ruby -rdigest script.rb "purplish grey"
#7a687f

If anyone can figure out a shorter way how to both read a file and take a color name as an argument, please leave a comment. $* (ARGV) and $< (ARGF) interact in strange and occult ways, ergo $*.pop.

Dictionary (xxd format)

0000000: 9bac a5cc d289 ff60 65ea 7573 21ba 9269  .......`e.us!..i
0000010: 9ed0 ad8a ff40 6d38 67d9 48bf 70de 9854  .....@m8g.H.p..T
0000020: 58c8 237c b032 8fab 514d ffff 32e9 6aa5  X.#|.2..QM..2.j.
0000030: 7b9c 96b7 59e2 f8df 50f6 fc8c 613d 545a  {...Y...P...a=TZ
0000040: 3a19 94c1 3388 0024 c009 c409 5838 b958  :...3..$....X8.X
0000050: 9e8b 6a55 82fe 4b53 c043 d299 8be2 1509  ..jU..KS.C......
0000060: a0f5 8304 fd0d 0cf6 0737 5616 eda2 3e2e  .........7V...>.
0000070: 3277 b8bf bdec 2224 7ce3 aa54 33cc 6651  2w...."$|..T3.fQ
0000080: 0eb9 5bc3 e860 0df5 afd6 023e f136 7577  ..[..`.....>.6uw
0000090: 230a 7173 a4ae 2bc0 5b77 9117 fd0f 8729  #.qs..+.[w.....)
00000a0: 2ac4 fa8a b8bd a905 7878 2f8b 0ddd 587d  *.......xx/...X}
00000b0: 9db9 a4c6 7845 0252 7aff 5b23 8bce b207  ....xE.Rz.[#....
00000c0: d9dc 4a7e e85a ebd8 9d66 befd 6d6b ccda  ..J~.Z...f..mk..
00000d0: 064d cca2 8ca6 4851 9849 e749 54fa 9f38  .M....HQ.I.IT..8
00000e0: bf52 b29b ff36 9e10 d2b7 f2ab 45ed 9836  .R...6......E..6
00000f0: 3b56 1ba5 81ee 359f b859 7b1e 1a67 93f6  ;V....5..Y{..g..
0000100: 6f5f 1213 44db 8f3a 9db5 dab3 8653 0d2e  o_..D..:.....S..
0000110: ffcf 4c58 0a45 0345 2133 e2ff 2b0d c8c5  ..LX.E.E!3..+...
0000120: 9d79 75a0 179c da09 d03d 15c0 84fe bd3b  .yu......=.....;
0000130: 4605 b7c9 32bc 777d 01e3 7f51 ffdf 8707  F...2.w}...Q....
0000140: 4ade 4a76 ed24 6714 2000 ea21 c0d9 7129  J.Jv.$g. ..!..q)
0000150: ab70 ffaf 6895 c05f 86a4 1e84 4db6 c758  .p..h.._....M..X
0000160: 85ee 686f 0c5a 1e72 e704 172a 2d0a 9033  ..ho.Z.r...*-..3
0000170: f744 7e0d 4e92 70b1 f7ff 19b7 42af d1d5  .D~.N.p.....B...
0000180: ce16 420f 4509 4700 e95b ec80 634b 8bbf  ..B.E.G..[..cK..
0000190: 76ab d954 8cff 0b59 0af8 dd6e 4c74 5aff  v..T...Y...nLtZ.
00001a0: fd22 c7cd a7b9 7e30 bd88 8623 3ee6 54f5  ."....~0...#>.T.
00001b0: bd41 97d4 957c cad7 ab20 fdff 93da bf82  .A...|... ......
00001c0: 58e0 4031 53e4 cff0 6ee0 db04 df41 3908  X.@1S...n....A9.
00001d0: b1c6 0406 47dc d9ff 003f b633 4c41 f22f  ....G....?.3LA./
00001e0: 432f ba51 b2ca a64c 0f66 ea87 4cef 2853  C/.Q...L.f..L.(S
00001f0: c72c fc1a bfd6 36a9 2600 4986 c59a fbe7  .,....6.&.I.....
0000200: 7dd6 78f5 24fc 8138 2afe 1e4d 02df d894  }.x.$..8*..M....
0000210: 4d82 8e3b 01c3 677f bc5a 064d a767 8933  M..;..g..Z.M.g.3
0000220: a96a 87c0 cd37 c6c2 b857 02f3 fd3d f7f8  .j...7...W...=..
0000230: e43f cb2e 5683 bd3c fa36 9a05 08c1 c578  .?..V..<.6.....x
0000240: 8ff9 5bda 1bcf 99aa 4cf4 9f8a 7a24 7c6f  ..[.....L...z$|o
0000250: 86e8 bdd6 7df6 add8 670e 35ef c5ca d34b  ....}...g.5....K
0000260: fe5d e4d9 910a effb 73c2 7cfb d2ca 1aa0  .]......s.|.....
0000270: cb5f 6a07 20c7 6a0b b267 c601 a70b 1494  ._j. .j..g......
0000280: 2d31 a8ab 0a17 17f9 1987 7ff5 bd19 c561  -1.............a
0000290: 18ef cffa 3963 f0fc 76e9 d306 d120 0031  ....9c..v.... .1
00002a0: 61cc 6b48 53a1 0413 66a8 894f 2374 fa5d  a.kHS...f..O#t.]
00002b0: 28bd ffff 6bf9 d190 f0ad 7930 e168 1ad7  (...k.....y0.h..
00002c0: 93df f7dd 5c9c da24 871d 6bab 211f b3ab  ....\..$..k.!...
00002d0: 2f8d d5bf f5cf 941d 2af0 8956 0a68 ff3e  /.......*..V.h.>
00002e0: e6e1 2896 0d57 09b7 62a3 811b 5207 ccf2  ..(..W..b...R...
00002f0: 8ff9 0b4b 7d76 dad0 b479 0250 689a 08ff  ...K}v...y.Ph...
0000300: ad30 4e06 03c1 803d bb5d ca47 4306 d007  .0N....=.].GC...
0000310: 4106 0002 d799 00af c36f 0d02 666f 9b56  A........o..fo.V
0000320: e867 81c0 14d3 7186 2ff1 8d69 4b30 9ab3  .g....q./..iK0..
0000330: f5fd 6fb3 7c9a 593a 6aec 4b76 6f48 9e30  ..o.|.Y:j.KvoH.0
0000340: ca57 9137 27b3 0a98 0404 ce0b ff16 3608  .W.7'.........6.
0000350: fb57 8955 6694 c212 7416 eb02 3c7c a3e8  .W.Uf...t...<|..
0000360: 2056 abe9 88dd 2b0c 12fb e93e 0937 a456   V....+....>.7.V
0000370: d4aa 20c3 846b cc65 f8ea 2286 f2e8 f6a2  .. ..k.e..".....
0000380: 7202 6eb4 75bd 0f2a de09 6136 7a8b 1045  r.n.u..*..a6z..E
0000390: 28bf 9f97 0d12 06d0 ee27 f820 f6c1 ffef  (........'. ....
00003a0: a5dd 6b77 e450 0537 9ff3 b90c 68ab a2ff  ..kw.P.7....h...
00003b0: 70a3 a0f7 c777 8936 cb72 6dff ef34 8cf7  p....w.6.rm..4..
00003c0: 4e0b 53b1 27df 9565 c589 f9ec 61e6 49ff  N.S.'..e....a.I.
00003d0: 2b17 d3ce d711 3f4b ddcd 1c96 d9c4 93e1  +.....?K........
00003e0: 5ff6 ac22 c313 bf55 1817 4f3d 8ef2 5c02  _.."...U..O=..\.
00003f0: f90a fb61 dbff d7f6 ff1a 16c4 f437 e8b2  ...a.........7..
0000400: 10f3 bf91 1afb 74c5 b851 63e0 5fa4 6cd8  ......t..Qc._.l.
0000410: 7a89 980a 0ba3 4d77 ae70 ca87 d5b1 cf60  z.....Mw.p.....`
0000420: e62d c9fa ffab e120 6bff bb06 4ea1 570e  .-..... k...N.W.
0000430: f9f9 7c51 e2ff a2ff 845d bee7 fb7d f5e9  ..|Q.....]...}..
0000440: f8c0 a568 f3b7 f4f1 3506 6620 ea4a fd8c  ...h....5.f .J..
0000450: a67a 4d2b c800 437e cf70 8500 40d0 6dba  .zM+..C~.p..@.m.
0000460: e7c4 8fd4 0903 6744 01a9 ef68 4a9f 77d3  ......gD...hJ.w.
0000470: 1547 2e42 4cef 0dcf eb17 6008 1028 7fd9  .G.BL.....`..(..
0000480: effd 8049 a2f5 4e02 3fd7 f4f6 c700 e835  ...I..N.?......5
0000490: cd0a 4187 f29d b142 13c7 8f0b f0bb 0052  ..A....B.......R
00004a0: 97bd 8565 1fbd dbdd 1608 6e1e 14df ef37  ...e......n....7
00004b0: dec6 5f42 7eae 9d12 3cf6 08cb a209 0368  .._B~...<......h
00004c0: 0975 e601 5025 b5f5 8e82 cc6f edb4 1631  .u..P%.....o...1
00004d0: c8c4 42ad 0449 05b8 ebea a8b6 9608 33f9  ..B..I........3.
00004e0: 58ac eb8a f895 e5ae 562d d1a0 009f ef2b  X.......V-.....+
00004f0: 9065 c74b 5e81 cb19 be69 e420 7b75 81a5  .e.K^....i. {u..
0000500: b3d2 1abc ff96 fa6e f6cf f3fb 243a 7ba2  .......n....$:{.
0000510: ef7b cc52 0e50 6fca e468 c071 3947 dffd  .{.R.Po..h.q9G..
0000520: ff8f 4165 790f 38a3 6650 f0f1 332f 5543  ..Aey.8.fP..3/UC
0000530: 1b2d b7de f2fa 8c42 aa4b ff17 aa43 3f91  .-.....B.K...C?.
0000540: bac7 e942 b742 b410 10ea eea0 55e2 c631  ...B.B......U..1
0000550: 2ffa f2d0 e281 838b f888 1a8f a97f 4644  /.............FD
0000560: 50ae f6bb 527e 01ff 5c21 bad8 7505 5851  P...R~..\!..u.XQ
0000570: 703e 1ca4 901c 0bf2 2e4f 0ab0 2e20 302e  p>.......O... 0.
0000580: fec6 014a 739a da9a 5a00 553a fca7 8e0b  ...Js...Z.U:....
0000590: fca6 39df 97f8 dda5 b3af 0c15 453e e3fa  ..9.........E>..
00005a0: 678e aac0 4767 e72e 7c9b 84e4 1c11 6774  g...Gg..|.....gt
00005b0: 8d2e 6262 fbef 823e 94db 27d5 4eb2 112b  ..bb...>..'.N..+
00005c0: 7950 0bd8 6a37 3a1f 3140 8ad7 2ca9 f8f6  yP..j7:.1@..,...
00005d0: fa4e 9b1c 3e0c 20f2 b3de 028e c71c 0e8c  .N..>. .........
00005e0: d848 8608 79a1 0dd3 ae24 2fc8 ffe9 2bc6  .H..y....$/...+.
00005f0: 98a4 0c32 6ad2 4cff 7f7f 1bfe ed7e 038a  ...2j.L......~..
0000600: aa33 8b46 1c99 f0ff d940 c589 57d8 3a2f  .3.F.....@..W.:/
0000610: 7bf9 05c4 197c da77 1a5b b729 8e57 e694  {....|.w.[.).W..
0000620: 8d59 8879 71c1 47c2 727e 093c 8010 3717  .Y.yq.G.r~.<..7.
0000630: 1971 9d8f 03b3 9cc6 7f5d 0631 67b6 fdf6  .q.......].1g...
0000640: fe88 0857 8bf4 82a6 97bc 0b04 9cf3 9264  ...W...........d
0000650: b50e 696b 6900 c6aa 68da 8f20 8773 c0c1  ..iki...h.. .s..
0000660: f67c 33f1 53da b66c cbf4 ff3d d708 b24a  .|3.S..l...=...J
0000670: 240a 3906 f163 9136 9694 4977 608e 16ff  $.9..c.6..Iw`...
0000680: fff4 d266 8fe1 1976 8826 b6c5 0316 11a1  ...f...v.&......
0000690: efff f700 56c3 ffbd 7ca9 b7a0 dd80 8c27  ....V...|......'
00006a0: 8af7 0d95 3f5d e18f 67ae d67e fbcd b7e2  ....?]..g..~....
00006b0: efcb ceca 978f b9fb 099f 3a11 ba09 40a9  ..........:...@.
00006c0: 321d bf75 8a71 8400 55a5 d236 a584 a45c  2..u.q..U..6...\
00006d0: 5d7c 4c55 8088 fe37 8f92 5d4c 0c45 d844  ]|LU...7..]L.E.D
00006e0: 09ba c759 fe4b c8b1 a35e f7bf 8b0a 6197  ...Y.K...^....a.
00006f0: a59a 5078 9a22 a65b fa90 44ad 6e49 d541  ..Px.".[..D.nI.A
0000700: 15a4 482e f52f d96e f30d efd1 0af0 faaf  ..H../.n........
0000710: 26ab 2630 104b c4b4 94f7 6fbc c5bd b9b6  &.&0.K....o.....
0000720: 2474 9ae7 c2c7 013c 92d6 7bff af4b 52a4  $t.....<..{..KR.
0000730: fe6f 9e65 34ce d210 bf32 7af6 7f4b 8273  .o.e4....2z..K.s
0000740: 3700 936d 790a 0443 2852 d0fd e48c 3f78  7..my..C(R....?x
0000750: 60ce 3b0c 0855 f889 50fd 7f52 de1c afa4  `.;..U..P..R....
0000760: 579d f45f 3e66 c8f8 3ded 52ae 70d0 d033  W.._>f..=.R.p..3
0000770: 6e41 89b4 b836 4a15 7bb3 c777 aa7c 0ec4  nA...6J.{..w.|..
0000780: 3885 e445 18b9 b080 674e 4bd8 4d85 cb80  8..E....gNK.M...
0000790: dde2 27ef 1f60 521f d2ef 4520 dd0f fa0f  ..'..`R...E ....
00007a0: e295 94c9 fe34 e71f 14d8 71cb c7ad 5335  .....4....q...S5
00007b0: a00b 541b 08d5 7bc5 a926 854c c8f8 f89f  ..T...{..&.L....
00007c0: 463f c1e3 ffba f086 988d 8fec 1763 ad42  F?...........c.B
00007d0: cb8a 1f36 310f 218c 39cd bc8f f5ff 3efb  ...61.!.9.....>.
00007e0: 7f42 8cde 4682 1073 ec0c b863 ff26 dc28  .B..F..s...c.&.(
00007f0: 840c 27b3 11b1 cc7b 0a8a 3f8a 14b5 ee8d  ..'....{..?.....
0000800: 0cb6 c1d4 6f14 dc57 4886 a6f5 d17a ea0c  ....o..WH....z..
0000810: 20ff 4009 74fd 8150 8b87 9bd9 057a 74fe   .@.t..P.....zt.
0000820: 25a9 a894 a56a a5fc ff40 b203 f2ff 7ffe  %....j...@......
0000830: f033 fff7 7a60 8fe7 4f20 06f4 47c3 9929  .3..z`..O ..G..)
0000840: b18d 8b68 0816 696b 404f 98b3 d3f7 fe96  ...h..ik@O......
0000850: de9a 24fc fab7 2bb9 387b 911f 9dc5 df1c  ..$...+.8{......
0000860: 5cd4 f226 c070 23f4 82b9 f50c 64ff 0c9f  \..&.p#.....d...
0000870: 8bee 5b77 4782 2042 1790 bd29 3cd6 f84a  ..[wG. B...)<..J
0000880: fb02 8222 cf5d 09a9 48e0 da5a 787e 74b5  ...".]..H..Zx~t.
0000890: 0e31 1c6b 258b ffbe dd14 d64c 0d51 4288  .1.k%......L.QB.
00008a0: 2a56 e359 6361 832b 0773 5514 c930 788b  *V.Yca.+.sU..0x.
00008b0: b2f1 6f55 c6ce d9cb 4da3 d9fd fdfd 8e90  ..oU....M.......
00008c0: 2077 ba65 eb7a 4346 91b6 1266 9910 7406   w.e.zCF...f..t.
00008d0: 6eb0 fe7d 0360 0f23 fb48 6621 a86f 0f59  n..}.`.#.Hf!.o.Y
00008e0: 903b 0a20 c589 98fc dfb8 01c4 76f7 e4e1  .;. ........v...
00008f0: 09de b49f 0b0c 10da b63a 35c3 4afb 70e5  .........:5.J.p.
0000900: e6de 34b7 8c6f 408e 4057 9f74 37df 5ffb  ..4..o@.@W.t7._.
0000910: 3052 8ffa ffbe 26c0 aaff df47 99e1 8b59  0R....&....G...Y
0000920: 7bab be18 34b6 da60 c1dc c001 21d5 286c  {...4..`....!.(l
0000930: 8f80 e8ce ff34 06e5 abd6 201c d418 33bf  .....4.... ...3.
0000940: 520f 23f0 4da2 e791 c32b 4509 46c8 3b77  R.#.M....+E.F.;w
0000950: 3526 76f6 fb5d 0ae6 7f4a 74fc 2043 d1cc  5&v..]...Jt. C..
0000960: caa4 66b1 3f3e 79a8 483d 841d 0f59 5460  ..f.?>y.H=...YT`
0000970: ea30 10d2 59db 2dbb 7129 9bc7 3c09 b9fe  .0..Y.-.q)..<...
0000980: a2a3 66bf b551 9777 0010 aac7 9322 0bd5  ..f..Q.w....."..
0000990: 14e4 d7f7 c770 e693 094f 3bde 9ef8 3730  .....p...O;...70
00009a0: 098d c938 bc79 e54e ef9a 3938 12a2 bc0b  ...8.y.N..98....
00009b0: 4d15 5a0c 17ef f2e8 c4fc 7d6f 2235 0020  M.Z.......}o"5. 
00009c0: e2ce b28d 8243 e4c9 9aff 5cbc e69a aa1b  .....C....\.....
00009d0: 3259 8ad2 0b50 b4d9 179b c90c e41c a939  2Y...P.........9
00009e0: c700 909e 0b91 2549 fe3d fed1 7eaa 450d  ......%I.=..~.E.
00009f0: 0034 d58e 0a24 3b59 384f 975d 8753 1974  .4...$;Y8O.].S.t
0000a00: 8cca 9a94 6bc3 7806 5683 02aa 7240 199a  ....k.x.V...r@..
0000a10: e5c4 fbdf de30 af24 4247 8501 08f4 d95e  .....0.$BG.....^
0000a20: 41c5 2b00 30fe 7446 427e c9bd c6a7 e092  A.+.0.tFB~......
0000a30: bdf4 db7d ce06 caa2 1043 9e11 0944 0a15  ...}.....C...D..
0000a40: cf3a df64 95a9 8a03 7df5 e8aa d9ef 0020  .:.d....}...... 
0000a50: d50d cd9b 0dd6 2f6b bfd7 708c 5ab3 c98c  ....../k..p.Z...
0000a60: 312f 19de 8cff 3ec4 6fe1 6130 258b a88b  1/....>.o.a0%...
0000a70: ef27 b89c 024a 9eb9 2aef 202a b302 9f3a  .'...J..*. *...:
0000a80: 00c1 d58d 56ef 8036 98bb febd 9730 d21b  ....V..6.....0..
0000a90: 2716 43a3 8958 0f71 08df 20cc ef84 abcc  '.C..X.q.. .....
0000aa0: f19d c5d3 6e38 5693 59fb f92b 4913 5eee  ....n8V.Y..+I.^.
0000ab0: 487b 10e7 49bd 6623 35af 8bf7 1521 132d  H{..I.f#5....!.-
0000ac0: 56af 5002 ae7b d6de dfb7 7603 fbe9 fa22  V.P..{....v...."
0000ad0: 397c 06ff 556c f8ff cf0b 0a64 6fec cf3e  9|..Ul.....do..>
0000ae0: b71a 5580 044f 705f 50f4 435d 6f54 0473  ..U..Op_P.C]oT.s
0000af0: b6b2 a795 100f 75a7 b805 c41c ced3 9937  ......u........7
0000b00: d405 0b00 3193 61fa 679a 376b 9c23 5e8a  ....1.a.g.7k.#^.
0000b10: a847 eab0 7fd7 9d30 bc6d 4c38 9dc4 cad1  .G.....0.mL8....
0000b20: 8bf8 8a25 ab6f 9a89 2d62 7fdf 19b3 a0fe  ...%.o..-b......
0000b30: 6d4c 3523 b9f8 5520 81f4 af0d d124 686c  mL5#..U .....$hl
0000b40: c940 a9d6 fdd4 5064 c555 edd9 caef 2e01  .@....Pd.U......
0000b50: 4508 dd1e 569c ea47 4df5 6540 06cf d471  E...V..GM.e@...q
0000b60: 896f 0b0b f580 faf1 2e09 24e2 8ebb 0ad2  .o........$.....
0000b70: 1281 578d 0080 df0b 0ca3 83b1 6100 c212  ..W.........a...
0000b80: 177f 20a2 df7d d8a5 0b89 75d8 6877 f594  .. ..}....u.hw..
0000b90: 59cd 965f 39a6 2aa7 86f7 23f9 0324 6e10  Y.._9.*...#..$n.
0000ba0: fd7c 8cd8 49a0 4da7 f5db e519 72ff ef17  .|..I.M.....r...
0000bb0: fc87 6542 c1b7 9edb ffef 04bc a4d6 4349  ..eB..........CI
0000bc0: ce6e 2c89 e5b2 e40b a586 418c 92c6 ff80  .n,.......A.....
0000bd0: 8e2b 8190 7d56 919b 3bef ffac 26b3 9f58  .+..}V..;...&..X
0000be0: 86ad f0dd e900 a3fa 7c2b 783c 97af cb9b  ........|+x<....
0000bf0: 9620 cce5 b96a 78a3 c22f ff87 5506 e798  . ...jx../..U...
0000c00: b412 7c0f 415c 9c7c ce10 6016 eaee eba4  ..|.A\.|..`.....
0000c10: 1604 feed 9a93 eba5 ea30 d5b7 8540 8003  .........0...@..
0000c20: 2b67 ba93 4598 ef3b 804d b184 fc7d 1e38  +g..E..;.M...}.8
0000c30: b746 88ae 85c4 0b65 ee1e 75f3 2ba7 10d4  .F.....e..u.+...
0000c40: e306 fffe a9c0 39af a255 1c22 8a02 47a7  ......9..U."..G.
0000c50: 189f a7a6 f451 6afc 3402 dc8b 101a 9350  .....Qj.4......P
0000c60: 36cc 638f 82ba e526 5aa5 4f57 89a9 0dfa  6.c....&Z.OW....
0000c70: 1dda 2d00 5477 0865 6785 6ded 4119 acb7  ..-.Tw.eg.m.A...
0000c80: 0841 5107 5042 59cd b8b2 d543 c80a b4ff  .AQ.PBY....C....
0000c90: 21c8 c9e0 5b49 01fa 9b2d 79b6 dbb0 2c10  !...[I...-y...,.
0000ca0: 1428 e91c bd3b 3f1f 80c0 cf62 74ba e7a7  .(...;?....bt...
0000cb0: 7809 d02d 5a28 bc2b ea9b 6776 3cde d6de  x..-Z(.+..gv<...
0000cc0: ef64 5a09 24f3 8ec3 1c91 bf49 6a71 bc51  .dZ.$......Ijq.Q
0000cd0: a988 0925 328b f7f5 00aa f891 4ea3 1291  ...%2.......N...
0000ce0: f760 e230 091b 816a 4e95 0fc9 cca7 b849  .`.0...jN......I
0000cf0: 289b 0e61 1824 a1df ff83 916d c3f0 8abb  (..a.$.....m....
0000d00: 8323 eecd b507 787f be0d 6126 6cb3 b529  .#....x...a&l..)
0000d10: c7a3 0b81 982f 5a7c d3a7 dff9 a859 3fe4  ...../Z|.....Y?.
0000d20: f74d a4d6 a5fc 26f4 7584 0500 a17b 07c6  .M....&.u....{..
0000d30: 1145 4a3a 0c00 580b bebc 005f 9530 0120  .EJ:..X...._.0. 
0000d40: 0d94 1f04 56c8 bb61 bd71 9455 816e 719b  ....V..a.q.U.nq.
0000d50: ff66 7e3b 96cd 0180 be7b afee 6690 b67d  .f~;.....{..f..}
0000d60: febb a3a4 b6b7 00c2 d931 c192 a251 2db0  .........1...Q-.
0000d70: 10b7 29bc 78f4 cc00 46a5 0156 4723 8fb1  ..).x...F..VG#..
0000d80: db88 36eb 3bf8 3758 59f3 7ba4 2af3 0f98  ..6.;.7XY.{.*...
0000d90: 8b80 ff80 5328 907b 0aa1 a188 2fe9 e8f0  ....S(.{..../...
0000da0: 6b6b cf72 26ac dfff b500 2fe4 f5fd 5fe2  kk.r&...../..._.
0000db0: ce10 68f6 58be 618c ff0e 49c5 62ee fcef  ..h.X.a...I.b...
0000dc0: 0c4a 5a01 ca79 66ca f419 3523 a792 2f03  .JZ..yf...5#../.
0000dd0: d5b9 5327 6893 9738 d20e 6c12 b30b 19e6  ..S'h..8..l.....
0000de0: 99f9 33fd bf61 4d35 3bc3 d430 6a00 747f  ..3..aM5;..0j.t.
0000df0: 50e3 da51 7729 f645 db09 01cf 3cf0 e5ec  P..Qw).E....<...
0000e00: eaaf 4cec 8b9f f9eb 5665 6ccf ff00 d751  ..L.....Vel....Q
0000e10: 35c9 4cb0 9b45 e430 fcf2 0f71 7a69 65d2  5.L..E.0...qzie.
0000e20: 109f 6cdd e1c9 b900 b35c 2f29 9910 73c9  ..l......\/)..s.
0000e30: 0f5b 0579 e70c 0a40 89f5 b422 00b0 61a0  .[.y...@..."..a.
0000e40: 6d49 65c8 933d c9b2 0e1e 014b 47b8 79d7  mIe..=.....KG.y.
0000e50: 7d69 56df d132 88c9 d65a 2dfa c444 4230  }iV..2...Z-..DB0
0000e60: 5c60 2a84 7520 3388 528f 1773 a89c 46b3  \`*.u 3.R..s..F.
0000e70: 11f8 9db0 3154 fee2 1083 a693 dc22 a563  ....1T.......".c
0000e80: 9f93 f195 56d6 5a10 7ef5 6d03 c69b 12cf  ....V.Z.~.m.....
0000e90: d0b0 2753 8aa6 3dd2 71ef 6c51 ea45 ffff  ..'S..=.q.lQ.E..
0000ea0: 0d21 8fbd fd5c efc7 9bb0 6204 4012 00f7  .!...\....b.@...
0000eb0: e500 a3d6 de7e 5e1d 5373 4028 3442 7bf6  .....~^.Ss@(4B{.
0000ec0: ffdf d459 a8b3 36c8 76e8 b897 04c0 57cf  ...Y..6.v.....W.
0000ed0: 4895 e7e6 2541 1109 10d6 7ab7 3032 45d3  H...%A....z.02E.
0000ee0: 01d4 f94f d87e 66e7 c208 8ffd ebae ccd8  ...O.~f.........
0000ef0: 627d ffef dbe8 497e 9446 bf03 78c4 26e6  b}....I~.F..x.&.
0000f00: 67d6 f5ff 9fca 0228 d6c8 659f f8bf cafd  g......(..e.....
0000f10: 2206 1dff db2b 9742 84ee b4aa 5f50 74a2  "....+.B...._Pt.
0000f20: ea49 d985 961d 9a7a d370 43d6 3442 0a01  .I.....z.pC.4B..
0000f30: 50a1 4e8f 84c1 fc86 0652 093f 622e 982a  P.N......R.?b..*
0000f40: 3003 12eb 30df a81f bb5d a849 633e 71bb  0...0....].Ic>q.
0000f50: 7204 7d57 2556 52e2 06ce 49bc ae2a d4bd  r.}W%VR...I..*..
0000f60: b4ad 7c5e 9b3e 26c3 fd92 5b84 d559 3e7d  ..|^.>&...[..Y>}
0000f70: 531c 52cc 99c9 d675 eef2 0482 1f9e d9bf  S.R....u........
0000f80: 1b19 e6a2 b34d 7995 0c30 180a 54e0 2c84  .....My..0..T.,.
0000f90: 36a9 4d18 45f0 6ba6 0536 f986 fcdf 0b1e  6.M.E.k..6......
0000fa0: ba4a ebc5 dcfe c67b 27a3 2782 5096 b626  .J.....{'.'.P..&
0000fb0: 1dcc 5ead 6edb 7e8c a535 ad79 93a6 8efd  ..^.n.~..5.y....
0000fc0: 715e f17a 47fa 1273 9a07 f375 44ca 3926  q^.zG..s...uD.9&
0000fd0: 9d50 09a1 4019 18b7 9d45 d425 78ff 5aff  .P..@....E.%x.Z.
0000fe0: 07b0 8c28 accf 0502 abfc ffdc 9098 cf0b  ...(............
0000ff0: 1078 d891 0159 91c2 efef c245 b341 c578  .x...Y.....E.A.x
0001000: c594 fdf8 dc5c a0e2 affd 4d11 7e04 c8a9  .....\....M.~...
0001010: 2000 2372 b86e 0430 adfd 30a0 7afb e6ff   .#r.n.0..0.z...
0001020: 0e91 1af5 b07f 78a9 b378 8f78 9181 7994  ......x..x.x..y.
0001030: 0b10 948c 451d e291 832e f1ef b7c7 1402  ....E...........
0001040: f59f 0438 00b2 a6e6 9089 598e 2b1e 966a  ...8......Y.+..j
0001050: 6596 1621 fd38 e771 0731 758a a084 e112  e..!.8.q.1u.....
0001060: 333a 3438 07d0 b8ff 7bec 5f0e 6a7a f907  3:48....{._.jz..
0001070: 97ac d560 9e73 9838 1d0c e2e1 de28 6ad7  ...`.s.8.....(j.
0001080: 0476 ba0e 1179 c68e 9cff 72ec 2e31 370e  .v...y....r..17.
0001090: 120c 109a 65e1 9a32 c5aa f02f 9519 ac66  ....e..2.../...f
00010a0: 1421 a600 d2e8 e995 6c88 3b87 1294 9708  .!......l.;.....
00010b0: 0002 8953 bc10 26d9 4450 ac2c 6d3a 1167  ...S..&.DP.,m:.g
00010c0: 9985 643d adb2 ff0e bb24 016a 472a 6704  ..d=.....$.jG*g.
00010d0: b684 ab8a 53fa 88a4 2461 038b 8b97 d5da  ....S...$a......
00010e0: ff7a 65f5 81ac a214 e501 2751 4460 ddf4  .ze.......'QD`..
00010f0: 8a65 9778 e2fe 4310 f347 f465 23ed 693b  .e.x..C..G.e#.i;
0001100: 6fa0 88a8 d4e1 667f 3682 8815 4da6 e7b6  o.....f.6...M...
0001110: f311 4e88 cf56 4dcb 31ef 340d 7cfe c40c  ..N..VM.1.4.|...
0001120: c24e 67dc 626a d074 a466 f202 b608 10f3  .Ng.bj.t.f......
0001130: 7b88 b4d1 f19c 28e9 ffff 4e1d 240a 56f2  {.....(...N.$.V.
0001140: dffb 6040 c5a5 a6c4 5b27 c9fe 400a 60a9  ..`@....['..@.`.
0001150: 3f55 8ef9 0f00 bdde a51f c054 5312 5271  ?U.........TS.Rq
0001160: d007 284b cafb 9687 c16b 3c64 41e3 54e5  ..(K.....k<dA.T.
0001170: 18d9 db0c 6a10 fee9 f4e0 0bdd 614a 65c6  ....j.......aJe.
0001180: fd0d 92fc 41c2 f6bb abb7 c770 736a a770  ....A......psj.p
0001190: 6d4b cf35 000e 0230 7531 e707 b37e 219f  mK.5...0u1...~!.
00011a0: f43d 0cc6 bc7b 6900 6555 1248 a063 e8df  .=...{i.eU.H.c..
00011b0: 2c30 17c9 e2eb fd5c 5ae0 5da3 ffff 2ce4  ,0.....\Z.]...,.
00011c0: 8875 2f0b da3a ca0b e4f0 ecff ae30 26a3  .u/..:.......0&.
00011d0: bae9 78ea 37b7 357f 987b 5380 efff ffff  ..x.7.5..{S.....
00011e0: 5c97 97e8 ff79 0502 56b8 83bc 5851 7a9d  \....y..V...XQz.
00011f0: aabf 5a83 8053 13bf f6ff 7eca 5647 c59a  ..Z..S....~.VG..
0001200: 407f 0edc d8dc 861d 665a 5a20 9a08 d546  @.......fZZ ...F
0001210: d827 1abc 4047 59d8 b4b8 97d0 b490 fdb5  .'..@GY.........
0001220: c799 03dd 6970 8cce da30 b004 803f 07e7  ....ip...0...?..
0001230: 0ddd f93a ccc8 00f0 d65c f9ff 8f14 09df  ...:.....\......
0001240: fb09 5010 90d0 b20d da0d d3ff 74c4 5158  ..P.........t.QX
0001250: 0f84 d591 7332 fffc cda6 5d00 0472 2318  ....s2....]..r#.
0001260: e28a c390 77eb 90e0 c411 e26e 1556 273f  ....w......n.V'?
0001270: f2f5 ca02 75fa f75d 6ba0 67ab 3136 3757  ....u..]k.g.167W
0001280: 5e43 b4d5 6140 7a6b 8bab 5403 4808 9fda  ^C..a@zk..T.H...
0001290: 30f0 a575 5e52 3cb8 9a9f 174b 1dc3 5601  0..u^R<....K..V.
00012a0: 8233 b62e ac67 b27f b6f0 9fbd 28f3 f9ef  .3...g......(...
00012b0: 0b5a 0cf6 ad4a 7888 95ef 101b feae c3f1  .Z...Jx.........
00012c0: 08ba e68e 6310 f3c7 4f32 140c 62fc df9b  ....c...O2..b...
00012d0: 2a18 54d6 83ae 1bb2 49f8 a9ea 70d7 1107  *.T.....I...p...
00012e0: a22b aec9 c6a7 9fba 7edf 1f73 6e2d 8294  .+......~..sn-..
00012f0: aa6a 26b8 ab60 0120 e3d0 9a10 d4e4 5457  .j&..`. ......TW
0001300: 841f 0422 a893 b400 e60e 2450 084f 6120  ..."......$P.Oa 
0001310: 28f8 fff9 708e d1bb 04cc 4afc 2afc ef0b  (...p.....J.*...
0001320: 72cd f02b 4db8 3deb 30df e026 8404 0060  r..+M.=.0..&...`
0001330: d008 0def ef9c 9431 9f0b 3b13 d110 51e3  .......1..;...Q.
0001340: d9e8 01d4 b882 9c0f 0ce4 10a2 300f fc0f  ............0...
0001350: 1c9e 8b10 56cf dc7c cb6f 7215 163a ff1d  ....V..|.or..:..
0001360: fd3f 6bcb be03 a199 2d83 2028 c7e0 acfa  .?k.....-. (....
0001370: 3f82 d00e 35cf 1a73 b289 8ef2 ee96 94bc  ?...5..s........
0001380: 14b6 7076 6577 0a84 5906 ff0b c791 85cb  ..pvew..Y.......
0001390: f7bd a51c b7da 1805 5115 fc0f 82fd dfe9  ........Q.......
00013a0: 0000 0075 40c1 aef2 adb5 3200 1164 169b  ...u@.....2..d..
00013b0: 0f05 a4fa 5c4f 6ead 6a08 dff1 7f69 4c13  ....\On.j....iL.
00013c0: 0be6 57e0 a4d3 6a05 2041 68d3 10ff 7095  ..W...j. Ah...p.
00013d0: d13b 0536 de5e 23ea 1718 34e1 0c46 075c  .;.6.^#...4..F.\
00013e0: bc95 31ae 9c14 5103 f0ff bfd2 441d 2bf6  ..1...Q.....D.+.
00013f0: 2aa8 0500 535b f35a 7cf9 febc 3b01 c6a2  *...S[.Z|...;...
0001400: 6cd6 1330 5300 d118 930a eefa b5b9 fb77  l..0S..........w
0001410: 6fab f289 f90e a505 0029 5919 704e 77b5  o........)Y.pNw.
0001420: fb4d 78dd ffff 412c 4aca 0270 78f3 4b69  .Mx...A,J..px.Ki
0001430: 9fb7 0ed1 f679 03c6 1448 2039 6868 d290  .....y...H 9hh..
0001440: d5f0 dc9a 465e 0000 ff74 6a35 07a0 b0d0  ....F^...tj5....
0001450: ff18 0cd8 2601 43d3 ff72 1451 0ba1 7bea  ....&.C..r.Q..{.
0001460: 7d1e 9e0c                                }...

Explanation

Encoding the dictionary

The dictionary's construction is very simple. I take the hexadecimal MD5 hash of the color name and concatenate the second through sixth hex digits (which happen to be unique for each color) with the 6-digit color code. I join these into a single string of 10,439 hex digits. Then I convert this into the equivalent 5,219.5 bytes, padded with zeroes on the right for an even 5,220 bytes.

Funny thing: I tried Gzipping the dictionary and even zopfli -i100 produced a file 40 bytes larger. Just for fun I calculated the entropy of the binary dictionary and it's 99.8% (versus, for example, rgb.txt's 61.2%). Not bad!

Here's the code that generates the dictionary:

require "digest"

def hash_name(name)
  Digest::MD5.hexdigest(name)[1,5]
end

names_colors = ARGF.drop(1).map {|ln| ln.split(?#).map(&:strip) }
# => [ [ "cloudy blue", "acc2d9" ],
#      [ "dark pastel green", "56ae56" ],
#      ... ]

keys_colors = names_colors.map {|name,color| [ hash_name(name), color ] }
# => [["b9ca5", "acc2d9"], ["8ff06", "56ae57"], ...]

dict_hex = keys_colors.join
# => "b9ca5acc2d98ff0656ae57..."

STDERR.puts "dict_hex: #{dict_hex.size} bytes"

dict_bin = [dict_hex].pack("h*")
STDERR.puts "dict_bin: #{dict_bin.size} bytes"

print dict_bin

Decoding and searching the dictionary

This is the exact opposite of the above. First I convert convert the binary data to its 10,439-digit hexadecimal representation. Then I take the input string (color name) and get the second through sixth hex digits of its MD5 hash and use a regular expression to find those digits in the 10,439-digit hex string at some index divisible by 11 and return the subsequent 6 digits, which are the corresponding color code. For example, for the hash b9ca5 ("cloudy blue"), the following regular expression is constructed: /^.{11}*b9ca5\K.{6}/. The \K operator discards the match up until that point, so just the last six characters are returned.

Jordan

Posted 2016-08-17T05:18:06.997

Reputation: 5 001

This does not work: your output for pink/purple is #a6814c, but the correct answer is #ef1de7. – nneonneo – 2016-08-17T20:46:42.367

@nneonneo It does work now. Turns out I had some hash collisions. It's fatter now, but works! – Jordan – 2016-08-17T22:09:31.260

7

Perl, 7,375 bytes

Stores slightly compressed data (grey -> E, etc) as compressed binary data, expands it into a hash and returns the matching key after replacing spaces in the input with _. I don't think it's that great, and am certain others will have much more intelligent methods for compressing the data, I might play with this more later on.

use IO::Uncompress::Gunzip qw(gunzip);gunzip\'<binary data>'=>\$_;for$v(qw{A/pale B/blue D/dark E/grey G/green I/bright L/light N/brown O/orange P/pink R/red U/purple Y/yellow}){eval"s/$v/g"}print"#".{m![/\w']+!g}->{<>=~s/ /_/gr}

A reversible hexdump is available here which was generated using this script.

Usage

echo -n 'baby shit brown' | perl xkcd-colours.pl
#ad900d

Dom Hastings

Posted 2016-08-17T05:18:06.997

Reputation: 16 415

2Try compressing your input file with "zopfli --i100 " instead of gzip. It'll still be readable as a gzipped file. – Glenn Randers-Pehrson – 2016-08-17T23:40:23.547

6

Ruby, 12131 12030 + -p = 12033 bytes

Byte count is after replacing <compressed text> with the raw paste data in http://pastebin.com/xQM6EF9Q. (Make sure you get the raw data because of tabs within the file)

I really could shrink the text further but I've been at it for a few hours now and I need to sleep.

Input is a piped-in line from STDIN without a trailing newline. Adding in trailing newline requires +3 bytes by changing ($_+?\t) to (chomp+?\t).

i="<compressed text>"
%w"Bblu Ddeep_ R*ight_ N*own Yyellow Tdirt Kdark Ldull_ Sdu} Qdusk Ee]ctric_ Ffaded_ G|een Iish A|ey Hlight Oor{g Ppa]_ Upurpl Cred Vvery_ -pink %ros ~sea .pea @egg ^burnt_ &baby ,poo =tea !t{ Mmedium_ $pa}el_ ;mud `aqua ?s{d >neon_ <lavend :gold +lime |gr ]le [mon }st {an *br".map{|x|i.gsub!x[0],x[1,99]}
$_=i.tr(?_,' ').lines.find{|s|($_+?\t)[/^#{s[/[^#]+/]}/]}[/#.*/]

Value Ink

Posted 2016-08-17T05:18:06.997

Reputation: 10 608

4

BASH + bzip2, 8058 6809 6797 bytes

bunzip2 -c c|tr -d "\t"|grep -F "$1#"|cut -d "${1: -1}" -f2

Stored the original list to a file after compressing it, not sure if this is allowed.

Call with:

sh ./colors.sh "shit"

Joe

Posted 2016-08-17T05:18:06.997

Reputation: 281

This reads only the first argument. Trying to pass a color with more than one words i.e. dusty teal will fail. Read all the arguments with $* or something like that. – Master_ex – 2016-08-17T13:27:29.323

5Just need to wrap the argument in quotes. – Joe – 2016-08-17T15:02:01.560

Try xz for the win. – Joshua – 2016-08-17T15:34:06.360

1I did, xz is almost 1k larger. – Joe – 2016-08-17T15:35:46.413

Do you /need/ the .bz extension for 3 bytes? – Mark K Cowan – 2016-08-17T18:53:13.257

I guess not, I was focusing on trying to shrink the input. – Joe – 2016-08-17T19:37:19.140

1you can use bzcat c instead of bunzip2 -c c – Emmanuel – 2016-08-18T09:56:47.780

1Sorry you can use bzgrep ..... c instead – Emmanuel – 2016-08-18T09:59:36.690

4

Python, 9360 characters

Doesn't use any compression library. I'll leave it as a mystery for a little while how it works and then post a link to the technique. Of course it could be made shorter by storing the data in a binary format but that's an excercise for another time.

G=[int(x or 0) for x in "0 -949  -948 -945 3  3 -944 2 2  -936     3 -935 -929 -927 2 -923 -922    3  3  -920   2 -916 2   2  4 -915 -911 2 4 -910 -909  -906 -898 -897  -890  2 -888  -887 2 -886  -885 2 -882 -880 -878 -876 -860  4 -858 3 4 3 -857 -856 3 3 2 2 -853 3 -852 -851  -850  -849 -848 -846 2 -841 -839 -835 -834   -831   2 2  -829  -823  2 -822 2  -821 4 -819 4  2 2 -815 2 -811 -808  5  3  -807 2 -805 -802 -796 2 2 -794   2 2 -792 2   -790  -787 -784    -781 -779  -778 -777 -776 -775 3 2   -770  2 5  -768 -766   -765  -763  -762 -759 -756 5   3 -751 -748  6 3 5 -738 -737 3 2 2  -724 3 -722 5 -721  -720 4 2  -719  2 -715 -713 -704  -701  2 5 2 -697 2  4 -693  -691 -689 -687 3  -684 3  2    -683   -682 2 3 -681 2  -680 2  -675   2 -669  -665 -664 -661  4 -658 -656 4 -655  -647 3   -644  4 2  2 2   2   -642  -639 -638 2  4 5 -630 -628  2 2 -626 5 -624    -622 -618  -612  -609  2   -607 3 4 -606 8 -596 4  3  -594 2 2  2 2  -593  -590 -588 -587  -585 -583 3 -581   -580 -578 3 -577 -575 2 4  2 -574  -566 4  3 -565 -563 -558 6 -556 3 -553 -552   2 -551  -548 -545 -542 3 -541  -538 3 2  3 -537  -534    3 -525 -524 -522  2    -520 2  -518    -517   3 6   -516   3 -515 2 -511 4  -510  4  -502 -501 -500  -499  2 -498 3 3 -497 2 3  -494 -493 -487 -485 -484 -483   -480 -478 -477 -476 2 -475 -474 2 -473 2 -471  -469 -458   3 -456 -455 4 2  -451 -450 -448 3 -447 2  4 9 2   2 2 -443 5  6  -439 -438  -434 -429 2  3 3 -426  2 -425 -423 2 -419  3 -416  -402   2  3  -401  -389 -388    2 2 -387 -384 -381   -379 17 -374 -371   -365 -363  -362 2  2    -360  -358  -357     2  5 7  -351 -350 -349 -347 -340 -338  -336  -334  2 2   -332    4  -330 -328   3      4 10  3 -326  -324 2 -323 -321 5  -315  -314 -305 11 -303   -301 18 -292 2 -291  -288 5 6   -283  -281 -280 -278 -277   -275 12   3 -274 -273 6 5 -269  2 7 2 9 -261  -257 -256  -252 -248 4   -243 -240 -239 -238  -236 -232  5 -230 -228   -223 -222   -221 -219 5  2  6     -218 6  -217 -216 -206 8  2    2  -203  -201 18 -196  -195    7  -194  -192 6 4 8  -191 -189 3 -186 -185    7    2   -183  -180 2 -179  10 -176 3 -174 4 3  -172 -171  -170 8  2   7 -164   -158 -157  -155 -152 -146 5 10  5 -144  -141  9  -139 -134 5  -132  2 -130  9    -128 -127 3 -126  -125   4  3   -120 -116 -112 -105 6  10 4 2 -104   -103  7 4  -101 -100  8 8    -96    -95 -93  -92  28     -91  5  11 -90 2 -82   13   3 -76  7   6  -75 -72 -68  -67   -62 3 3 2 -61   -60 -59 -56  10  -55   -53 2   8  8       -51  -46   2  -45 6 -44 2 4   -43 -42 2  -40 9  -37 -36   10 2 4 6   -35 3 2  -31 5 14  11     -29 -24  3   -22 -19 -17 -10 -8       -6 -1".split(' ')]
V="748500 fdff52 3b638c 0b5509 71aa34 eecffe c8aca9 75bbfd b1916e fa4224 cd5909 b7e1a1 ba6873 922b05 32bf84 31668a 6b7c85 fdff38 b04e0f 875f42 699d4c 03012d 647d8e cb416b c9ae74 0bf9ea 63b365 4b006e 02590f 885f01 1fa774 a6fbb2 ff5b00 b790d4 8cff9e 6b4247 ff6f52 fce166 90fda9 c9d179 d6b4fc c94cbe 419c03 017374 ffff84 41fdfe d0fefe 889717 cb0162 a24857 0a437a a552e6 d3b683 53fca1 464196 0cb577 6832e3 ff000d 598556 6258c4 c0fb2d 1ef876 c9643b 35ad6b 1d5dec 947e94 015482 65ab7c b2713d 920a4e 59656d ffffc2 fcfc81 cba560 03719c 8b2e16 cc7a8b c5c9c7 bf9b0c 08787f 25ff29 7a6a4f 3c4142 653700 005f6a 7a5901 a90308 afa88b 06470c d1b26f 343837 c0fa8b ffffcb 9dc100 7a9703 0c1793 befdb7 4da409 f075e6 152eff c4fff7 9ffeb0 658d6d 978a84 fa2a55 070d0d b59410 8a6e45 a4be5c 4984b8 8f99fb 25a36f 3d0734 ff9a8a c6fcff ff6cb5 ae8b0c 01ff07 7e4071 fef69e 8e82fe 8d8468 fd411e c85a53 ffe36e 5539cc 76fda8 acfffc d5ffff ad0afd f9bc08 ffb19a bf9005 3d7afd ff073a fff9d0 526525 1e488f b9a281 c071fe c88d94 5729ce 5f9e8f b2996e a2bffe d0fe1d faee66 c875c4 4f9153 fddc5c d99b82 b79400 a55af4 e4cbff ec2d01 b36ff6 280137 7f5e00 8f7303 1805db a9561e f0833a 95a3a6 030764 50a747 fe7b7c fea993 d7fffe c6f808 efb435 9be5aa c1fd95 9e0168 276ab3 9900fa 0d75f8 4b5d16 fffd01 aeff6e 7bb274 c4a661 5a86ad b9cc81 0b8b87 20c073 3f012c f10c45 3c9992 ac9362 047495 042e60 a5a391 380282 0e87cc 3b5b92 94b21c c04e01 001146 638b27 7d7103 fcb001 4c9085 fc2647 667e2c fffe40 fe4b03 033500 ff474c caa0ff ff9408 ff964f 8cfd7e af884a 7f5112 4efd54 b8ffeb f6cefc 749551 23c48b 0652ff b6ffbb fed0fc b75203 96f97b 990147 5edc1f beae8a fffe7a 017a79 436bad bc13fe 985e2b 214761 004577 0ffef9 770001 475f94 b5c306 20f986 75fd63 48c072 1bfc06 bcf5a6 fb7d07 6c7a0e da467d 2a0134 8b88f8 2baf6a 516572 fe420f b1ff65 430541 26f7fd fdee73 d5174e 06b1c4 a484ac a0febf c0022f fe2c54 886806 ac1db8 ff63e9 983fb2 ff796c 90b134 10a674 26538d 856798 874c62 76cd26 ba9e88 fdff63 c8ffb0 1d0200 661aee fe019a 029386 fdb915 ef1de7 04d9ff 7ea07a fafe4b 411900 efc0fe ff028d f7879a 13eac9 a2653e bcecac 53fe5c a8415b fbdd7e 98568d 94a617 fbeeac ccad60 4e0550 0b4008 f43605 0cff0c c45508 c1f80a 9b8f55 33b864 bd6c48 ff69af b25f03 fb2943 acbb0d 85a3b2 734a65 99cc04 020035 c95efb 9f2305 21fc0d b0dd16 b0054b cbf85f 1fb57a 8fb67b 7b5804 bf77f6 0343df 044a05 bffe28 706c11 966ebd 6fc276 d0e429 2242c7 b7c9e2 ae7181 6488ea 341c02 2cfa1f 6d5acf 056eee 758da3 e50000 825f87 a6c875 a442a0 f0944d 876e4b f5054f c77986 9cbb04 6140ef 89fe05 4e7496 ccfd7f d9544d e78ea5 6e1005 40fd14 544e03 3778bf 12e193 acc2d9 be03fd 82cbb2 db5856 c7c10c 6ba353 f1da7a 4f738e fa5ff7 c7ac7d 607c8e 76ff7b 6a6e09 155084 137e6d ddd618 ffffd4 751973 789b73 db4bda fd8d49 658b38 cffdbc f97306 08ff08 bccb7a fffcc4 ef4026 703be7 01a049 8f1402 632de9 016795 6f7c00 cfaf7b 5a7d9a bff128 80013f a8ff04 c0737a ceaefa 9aae07 05696b ffc5cb 0cdc73 d767ad 3f829d acbf69 cf0234 9e003a cea2fd 34013f fffd37 a4bf20 9a6200 840000 ad8150 ff0490 b9ff66 fe02a2 ffe5ad 8ee53f bdf8a3 c1c6fc 089404 107ab0 696006 742802 c87606 e03fd8 c2b709 6a79f7 014d4e c14a09 9d5783 fb5ffc 750851 929591 42b395 7f4e1e 9dff00 21c36f 96b403 154406 ac7e04 580f41 29465b 78d1b6 735c12 d4ffff 698339 6c3461 952e8f 01889f 610023 010fcc f504c9 05472a 8f8ce7 feff7f aaa662 5ca904 c48efd 9d7651 b66325 6b8ba4 dfc5fe 11875d a66fb5 2fef10 054907 c9b003 000435 cf524e c8fd3d 02ab2e 3a18b1 fec615 ca0147 15b01a 35530a 021bf9 ff7fa7 b17261 448ee4 2000b1 719f91 cb9d06 2ee8bb ffd1df 887191 3eaf76 1b2431 002d04 86a17d aa2704 014182 c83cb9 7b002c fac205 5c8b15 d5ab09 fdde6c 5f34e7 017371 89a203 019529 7f5f00 3d1c02 fdb0c0 b26400 005249 5e9b8a ffffe4 a7ffb5 f1f33f a8b504 4b6113 ca6b02 ffff14 aaff32 1e9167 ed0dd9 b16002 040273 048243 ffa62b fc824a 363737 fb5581 2b5d34 2dfe54 fe828c 536267 916e99 ab7e4c c20078 aefd6c d46a7e 7f7053 7f2b0a bb3f3f f7022a fdaa48 cb7723 805b87 5b7c99 c2ff89 c69c04 9db92c 9a0200 0804f9 0add08 9d0759 0165fc a50055 a87900 758000 0203e2 8d5eb7 287c37 7efbb3 fdfdfe de9dac d6fffa 9c6d57 51b73b d1ffbd b66a50 8af1fe e17701 fff39a 54ac68 2976bb ad03de 673a3f de7e5d c7fdb5 5cb200 4e518b fe0002 fff4f2 ca6641 4b0101 cafffb cfff04 645403 a0025c 490648 3c73a8 60460f ff7855 ffb07c ac86a8 030aa7 960056 720058 01386a f29e8e 3f9b0b 7d7f7c 5cac2d f6688e 01f9c6 6f7632 dbb40c 7bf2da b00149 0aff02 a2cffe 8cffdb af6f09 98f6b0 b29705 c79fef 90e4c1 04f489 fdc1c5 be6400 cd7584 fffe71 61e160 fcf679 3a2efe 388004 c292a1 980002 eedc5b 0a5f38 95d0fc 9b7a01 8fae22 fd5956 f4320c 738595 769958 a2a415 677a04 c3909b ff0789 ac4f06 fedf08 6ecb3c fc86aa 63f7b4 ac7434 2bb179 045c5a ffff7e 6f6c0a 9f8303 f36196 ab1239 63a950 7bc8f6 d648d7 b1d1fc 069af3 ca9bf7 ceb301 86775f 9a0eea 533cc6 74a662 b1d27b 70b23f a87dc2 017b92 feb308 7f684e 80f9ad 548d44 9c6da5 964e02 894585 d2bd0a c3fbf4 7b0323 00555a fffd74 601ef9 a9be70 507b9c 5170d7 373e02 728639 13bbaf c69f59 58bc08 00fbb0 d3494e befd73 5684ae c44240 a88f59 8b3103 24bca8 88b378 fdb147 fe86a4 01c08d 4a0100 06b48b b5485d 9bb53c 937c00 a83c09 f2ab15 8eab12 e6daa6 a6814c ffda03 76424e cf6275 1f0954 b0ff9d 77ab56 fefcaf de0c62 cdc50a 5fa052 a0450e 990f4b 9d0216 8e7618 d725de 8c0034 d5869d c87f89 606602 ffff81 d6fffe 028f1e e6f2a2 4e5481 fd4659 730039 ffb7ce 87fd05 05480d 0504aa b5ce08 01b44c b96902 ff6163 02066f 75b84f 2138ab 0bf77d ff724c dd85d7 77a1b5 ffd8b1 56ae57 a5a502 0a481e ffffff b6c406 ffc512 c2be0e 6dedfd be013c e2ca76 06c2ac fffa86 edc8ff 7ebd01 00035b 40a368 02c14d 87a922 00022e 997570 ffab0f 748b97 fe46a5 ca7b80 000000 c760ff ab9004 866f85 f4d054 d0c101 9e43a2 c4fe82 7a687f 6241c7 f8481c be0119 947706 a8a495 820747 850e04 3c4d03 7bfdc7 fffd78 7f8f4e 000133 fe83cc c9ff27 c27e79 d1768f fc5a50 a5fbd5 82cafc fe2f4a 2afeb7 36013f 728f02 8ab8fe ce5dae 9cef43 014600 02d8e9 062e03 61de2a 39ad48 910951 84597e 3b719f 49759c ff81c0 8fff9f ffdf22 ffa756 7af9ab 680018 a9f971 5d1451 009337 ad900d 1f6357 b27a01 5d21d0 ffbacd 82a67d 96ae8d 657432 929901 3c0008 f7d560 ffad01 a0bf16 76a973 d8863b 8f9805 df4ec8 87ae73 fff917 a13905 65fe08 feb209 3e82fc 826d8c 0a888a 8ffe09 cb00f5 f5bf03 aa23ff 8756e4 6e750e 0339f8 3d9973 ffcfdc cdfd02 9af764 fd798f 410200 7ef4cc 35063e ffb16d 2c6fbb ffffb6 bfac05 a57e52 fd3c06 dc4d01 696112 01153e 1f3b4d 0c06f7 510ac9 89a0b0 7e1e9c 9dbcd4 9a3001 3ae57f 828344 b9484e b1fc99 d5b60a 380835 665fd1 2a7e19 836539 05ffa6 d94ff5 d58a94 ada587 247afd ffb2d0 bbf90f 5d06e9 ff08e8 69d84f 667c3e 0f9b8e 2e5a88 c74767 a88905 94568c 77926f 6f828a c65102 94ac02 98eff9 658cbb 4b57db 5e819d bdf6fe 040348 a75e09 650021 b7fffa 9b5fc0 cb6843 04d8b2 feffca fe01b1 00ffff af2f0d 84b701 d90166 18d17b 895b7b 02ccfe adf802 d8dcd6 a00498 a03623 fffeb6 8c000f 5a06ef 56fca2 0485d1 fcc006 9e3623 b2fba5".split()
h=lambda d,s:hash(s*d)
x=raw_input()
d=G[h(1,x)%949]
print '#'+(V[-d-1]if d<0 else V[h(d,x)%949])

Explanation:

Uses an adaptation of the code from http://stevehanov.ca/blog/index.php?id=119 to generate a minimal perfect hash lookup from color names to color codes.

Geoff Reedy

Posted 2016-08-17T05:18:06.997

Reputation: 2 828

3

Python 3, 4927

182 code + 4745 data file

from hashlib import*
def f(s):
 k,b=md5((67*s).encode('ascii')).digest()[5:7],open('X','rb').read()
 for j in range(0,4746,5):
  if b[j:j+2]==k:print(('{:2x}'*3).format(*b[j+2:j+5]))

Theory of Operation:

md5((67*s).encode('ascii')).digest()[5:7] is a perfect hash from the color names to a 2-byte value. The binary data file is simply a list of 5-byte chunks--2 byte hash and 3 byte color. The code hashes the input color name and searches through the data to find a match.

The code to generate the binary file:

ba = bytearray()
with open('./rgb.txt','rt') as f:
    next(f)  # skip header line
    for name,code in (line.strip().split('\t#') for line in f):
        key = md5((67*name).encode('ascii')).digest()[5:7]
        ba.extend(key+bytes.fromhex(code))

with open('X', 'wb') as f:
    f.write(ba)

Here's the code I used to find a perfect hash. Nothing fancy, just three nested loops: number of time to repeat the name (e.g., 'blue', 'blueblue', ...); the available hash algorithms; and the offsets in the hashes. It prints out combinations for which there are no collisions.

for i in range(1,100):
    for hashname in hashlib.algorithms_guaranteed:
        hashes = [hashlib.new(hashname,(name*i).encode('ascii')).digest() for name in names]
        for j in range(h.digest_size - 2):
            if len(set(x[j:j+2] for x in hashes)) == 949:
                print(i, hashname, j)
                break
    print(i)

RootTwo

Posted 2016-08-17T05:18:06.997

Reputation: 1 749

3

Python 3, 296 + 3960 = 4256 bytes

I didn't use gperf, because it would be too boring to simply repeat that trick. Instead I did a brute force solution from scratch and therefore the size is not optimal (but not too bad, too).

However I found how to compress colors more efficiently — they are sorted and aligned to 4 bytes, LZMA happens to take advantage of it. (the colors are compressed to 2180 bytes)

To find the color by name, a 15-bit hash function is used. Theoretically it could be found with fewer bits (numbers 0..949 can be encoded with 10 bits), but my computer could not find anything better, it's too much work.

The code takes input from stdin and prints the answer.

The code:

import codecs,hashlib as L,lzma,sys
h=L.md5(b'\x05_h'+sys.stdin.read().encode()).digest();f=open('a','rb');H=int.from_bytes(f.read(1780),'big')
for o in range(0,949):
    if H>>(o*15)&32767==(h[0]<<8|h[1])&32767:c=948-o;print('#'+codecs.encode(lzma.decompress(f.read())[c*4+1:c*4+4],'hex').decode())

Data file (binary, should be named a and placed in the same folder):

0596 61b2 005c 634a f47d 2c12 d5d2 e156
435a 1931 17a2 5f7b 547c 5a5b 8c40 0acd
fe13 3da6 21b3 bafb b79b 71ea 4af2 70e2
6195 6838 516f c5b7 e08f 6087 4665 cea9
8901 f8a2 b408 d333 1d7a 17b1 b35f 0a22
2aed 9f71 1fdc ac65 8991 2c3b 3b50 2578
c194 7990 03e6 d333 a368 7445 4992 8e1d
1b0b 882c 9614 4ec1 d71f 3ba4 b483 ce06
d3e9 7c09 ed11 2205 2a58 0fd3 f5a8 a573
3c7d fc68 9025 b0da 656a c642 cd1e d964
5197 3488 6794 cc78 df40 2818 d921 267f
c056 c554 2c35 0514 e2b9 4c81 dd95 9cfa
f2d8 dd0e 840e 2731 5530 ef3e 0b89 8320
4f88 e851 e2eb 5917 cf22 ff13 432f 5fbc
7cf9 0154 b7d7 12af 7e91 d2ed 8fad 4381
21f0 2973 ca7a 60ee b6af b2a4 1817 7fe9
6f9e 1ba3 5330 15bd 858b 8491 3436 e90b
b469 b8c3 ed4c d840 1a04 73c8 3788 1ffc
4c2e 4e9f 6f53 7668 7b26 b323 80a5 0ae3
18e6 5106 bff6 6eb5 ddf7 480d 1b3e dad4
be9a e831 9507 4675 d18a 38ef b3a5 c504
fa83 53f4 0ed0 9112 4c7b 597a ac0f e174
8546 2bda 6344 e515 5aca cb14 eeba c12d
ea91 e55c b157 c60d 635c afc8 c35a 99a0
3c54 acdd 1edb 65e8 edbc 32f3 df1c 55f9
aad0 fe4b b941 1d5b 88ac 8144 a737 ad97
73c7 b5c8 02c1 3df4 6c39 e9c5 c53f c350
135c b013 18fd 51d2 9e2c bdca 19c5 a15e
bc53 c564 f4c6 c0b7 9bb3 da22 230b db66
f36d f675 9732 1b54 3905 65cf dca9 087b
4675 cfaf c0df af8a a30a f25a 336b 4c8c
1938 0f9b ad95 12a7 60fa a29a d7f9 8d4e
61fe 9193 58b7 1af1 d836 0709 ddf9 3e1d
c5e2 4f98 3c75 bdb5 fee6 0128 a2c4 8578
ff4d 50e7 b8b3 e51f 9794 5b40 5031 a73e
313d 75c2 70da a5d8 3240 e68f 1eb3 215f
2286 ba27 5bee a32a f005 441e 18b4 6258
91c8 4190 65b1 a286 a800 8607 0a94 4e37
0578 9ad4 6f86 3509 6f1a 1e10 35cc 1d41
dafa bd43 3f1e be88 246f d896 3267 28e8
4b6c 8f25 1aa8 cdbf bb34 c436 d926 6e75
54dc e196 f7f7 f169 29af 6d38 16fb 2fff
a49c fa41 26c7 8b63 1f20 ccd9 2d92 fe40
cd0e bc75 5267 1f49 9c38 54fe 628c b06b
52c4 7c6a 97fc c63e 8491 0cc2 d242 d5cf
2e65 e740 2fa1 784a 8bf8 c28e 1a4d 6b5b
002a 7307 f7af 5908 0e37 5088 6818 d09d
5547 0a9a df0e 1169 d278 25b2 dd48 55d0
3cc8 cbf5 4315 1a3f c614 dfca 1188 13a3
969f 032d 90d2 1ef1 fd6e bd66 cdbb 73f4
c29d 3ab8 a3b4 462d 137c 1911 d5ef 9a43
2324 381b 612f 9611 35fc 7b6b 7e54 d906
f6ce 24bf dcc4 5c5b 0ebe a8ac 29d4 7378
3bc3 15f5 0c9d 77ce 9678 2985 69d7 dfee
4029 71af 427f 0c83 a3c1 d7aa 4387 bba1
eb0c a267 6755 ae83 2441 01af 8925 ec00
dc5f f711 3188 c89c 7964 e8b0 f58b 2cd3
da35 880e ac12 1554 8470 b476 27e1 a24d
ddd8 778e ff7f cf57 f374 7206 01dd 9b42
85b3 5ab8 ad09 8683 d6c3 6be6 a686 80c8
cf6e 35a8 6d15 ab85 93c3 fdd4 d0c1 654c
18f8 55e1 0962 0e23 3fe6 8c92 a4a9 e5f4
4151 3ad6 2efc 580b 6e39 6126 6b5e 4866
a2dd 58b3 fd7a af63 f876 9c12 cb3b 1bfe
3820 21a5 e2f9 e030 1848 b562 9898 cc3a
c9d1 7e93 6609 f15d 9fb1 cd79 c860 e903
7f72 b050 8e75 e997 9ebb 6b8a b81e 6b97
4cdf ac10 abdf 409b 60d7 9056 475c c4ab
1046 eb22 2529 aa8b e6e1 7e47 4bc2 3477
05ae e5ea 8dc4 ee2e 2eb1 396e face 9d8d
7430 9901 3564 0725 81f4 7175 40e5 e342
50f1 2bd2 ec8e 02bf 3609 5444 4896 b0f8
1c60 d02d e271 13ce 6420 dfbe 616c 5483
ca6d 7194 4665 9e38 7bce 0a73 5bc8 78a5
e95d fb2e eb75 80ed a5d5 9c1b 46ec f863
d042 f98d 4fac 54a2 6e60 bdf3 6b25 5abb
e8c8 1ecf 09a4 4f8e b9ea 1377 c406 8376
a7c0 1c10 e1de 8a4b 3af2 74d7 00e2 dcc6
83c0 c09f 96a2 bb70 4ba6 8d2d 1a64 d860
c021 1d19 c8c5 6148 7968 59cb 45f3 42e7
2527 1b2d 702c 77da 7dda 11f0 1c3d 8cac
9894 d615 4907 682c cbbe 55ae d68e 1719
a6ab e257 d6f9 59d9 52b9 e174 38a4 1683
1de2 989e c7fd d39e 8e65 61c9 8831 1861
7acb 83bb b2e3 41f1 0ba6 ab70 dcb8 4624
a085 ac65 dd16 1e62 73e5 53f8 fc37 3a57
ead1 a4f1 0fd0 0ae7 34c6 7650 1eea ff24
f2b5 ef97 69a7 4939 b6b4 8588 2f4a ff84
1cf6 6f39 2b41 fa07 7f4b 14b0 b797 5ff0
ab83 2eae 23d7 f295 0644 951b 9b67 f55c
42bc d7f7 41ee 6b19 58d1 8028 557c 268f
ae8d bb40 4f81 e342 2e37 3dc2 7fb9 e89c
c7cd aad9 cacf 41bd 5883 8913 0e93 d4ed
ae42 51f4 b6f4 377a 8fbf 5e05 456a c102
e454 2a81 8c05 2595 6531 0b9b 7f3f 6b79
c341 789c 1021 0c14 1189 f5e9 0c29 ef0f
73e1 5573 ddb8 371e 1be4 e4c1 979c 7486
e7b7 e736 c175 dd5c e2d5 181a ac40 3ed6
03cb c6db fb02 34b3 b4cc 3df8 797a 9ac5
f686 b1ed 7820 6a2f 34cf cc00 704f 28b0
2f81 bb66 5838 b4b0 c9c2 f386 2176 2906
f783 1e2d 9475 f98b b038 e795 dcf0 5eaa
e9e4 fa53 f38a b4c8 556c 77e4 b3e8 690b
e9d6 a42d 9786 ca76 b721 168c 1775 172f
1d7f 007b 77ad 7ce2 92f8 ea2c 7af5 ab57
0db6 b365 d9b3 21e2 29c0 613e 60e6 7aa7
b8f3 dc7c a2de dc6d f193 d279 04b8 3c3b
11b1 df6f 14aa a2cf 9561 2c64 8941 065c
f053 f218 e8bf 37ad f147 273e 9977 d818
d2e7 d1b7 67e3 6fa2 5e44 51ec c802 2828
ecbb 9b46 bf77 9cad abe6 68de 448a 390e
6665 5aca 5d00 0000 04ff ffff ffff ffff
ff00 0069 7ea0 e4ca 10fd 878f 79c1 bd67
f49f f836 a77f 61f8 4e3a bfd0 309e 8414
c871 2596 aebc 89cc 7aca e279 1fe8 7e84
271f 29d5 01ca e2b4 70b2 af51 e7dd dab2
3b6e 4a5e b512 1e84 b958 f918 75aa 8880
50d1 37ca bcc7 7308 d9c6 87b3 8a50 4f9f
7e02 f65a 7486 85a2 d114 f736 68cc 16df
a508 2a36 9a4d c276 7836 0c0d dd95 2d5b
5728 2068 e911 1541 a2fd d39b e551 d3a9
3e47 96a1 d338 e7b1 7b25 3ba8 71aa a310
d0ef 2673 5a9c c9b4 d36e bd41 9bc7 eacd
b630 2535 e65c 339c d9bf afe2 8949 505e
2286 7a66 87c5 9fe7 4410 e9c2 c7fd 705a
b0e1 28e5 339e 4d92 2684 76a3 63f4 8967
ce46 014d 7c42 1c77 8ffa a36b b0a6 44f3
5962 b6fb 70e8 c7cf 53e8 a89b 7cd1 43e0
c7d2 61e3 7620 54d0 35bb eac5 160b 01fe
521a 1487 24fb b788 ba41 7e30 73b3 ac8d
a95a b9e4 bd10 bc9a b1bf aadb 5856 c729
dc16 c52a 53b1 6004 17b0 35ca 374f 8f1e
803c a176 1043 864d b329 3a4c 6e80 fd25
aad2 5ed1 76a7 2b81 e400 04a9 6a0b c55b
eb4c 6c8b c5c8 99b3 6d3c 0d92 f61b 58a4
66d8 cd73 2862 fc81 cdbe d47f 5b9e 5dee
7d93 7ec3 5245 7cb9 05f3 809e 7e41 f848
df58 d6ca 4248 0a4d c2ed 9181 d055 9732
c15c 1091 d3e1 b880 22c0 e7dd 67a3 f1e1
e469 deef 6aa6 e50a 7c89 6ee1 1eb7 c571
4c11 863d 512e 05a4 fc31 1a79 4ba6 4420
ef4a 0e77 a925 21e8 e4d5 81fe 527e ead9
da86 c76b a785 7a53 3a2d 409c 2041 236a
7fb8 3547 ccac e82e 9bc6 db79 670f 84c0
df27 d1c4 e26a 7b4a c951 d57e 4056 e0e3
1288 dc4d 63fa 6e62 489b 0eba 728d 2232
a9ca 123c 8b15 9bdc 6317 02c8 0a3f 07aa
03db 6a1b a906 d99d c007 bbf7 872a fc1f
4459 a7cc 29e5 3111 d4e4 c834 f9de 575a
9755 bd21 bd5f 7284 df3d a131 fd32 b8fa
6b64 3ac9 9a22 2459 8740 c50b 8634 627b
80d8 35e6 535e 4ee1 4641 1d18 55fa 8b51
a8d5 9a4f fd4e 856d d325 8bcd e336 f221
a987 48e1 0c7c 53e9 b022 6b28 6556 c4bc
7df7 2ac5 1f5f bb93 ef09 8a45 2439 dd91
fc30 d602 4648 e78e 24c4 abc3 a37f 5046
d3b7 7c1d 605f ca0c 27cb 7941 1256 d147
50b4 fe76 03e1 8617 c815 d9e8 a0b8 d05d
1b05 fcba 9902 4df1 8fb1 db82 eec0 9624
795b ab0d 8c01 7911 71a6 7484 cc1d 91d2
c56b 8ed2 9ca8 1cd3 24ff d705 d62d d826
44ef f7ab 4fb9 db61 7fb5 23c3 0b92 4737
03ba 01c7 5395 160d ed29 bef7 e5d6 19d7
a6af 4131 8f12 2bf0 46c3 d986 ccb5 a055
bc3b defc 545c 6632 c2a8 52c5 8a6a 9a9a
6ef4 dbdb d6f8 0d73 0c37 7128 7926 f11f
1d15 1edf d236 d74a 74e7 1692 d81d b000
1af1 cf7a 9fc2 be3a c831 34d8 edc8 a014
56cb ee36 3bdc 4e6d 529a 7b70 ecd9 0607
bbad 1f97 f0ff 0412 6c99 f7de e720 ecac
bf33 06f4 b3b4 d2c4 ad05 4be3 c378 dd1c
1cb9 71de df25 c3c6 6540 3beb e667 e274
75b0 fe5f f1ad 5793 97ae 939d 3a7f 0c1d
3d25 ed5c 46d6 eda2 983d ba0c 852b 6075
4530 cdee 10fa 60af c929 8f24 2aab 8920
940a f61f 982e 469b a31e d7ab 9d5d d9d8
85f5 772f 84c4 c1d9 ccd7 101a f4e7 8357
2e27 2c63 0f42 c782 4bca f10b 7b79 feae
3f42 f04f ea3e a681 5e66 25cd aa6a 63fc
5ec7 65ce 639c 861a 5541 b9a1 61e5 3d8d
70de 336c 7d44 4342 cd24 6496 099f 90f1
8b1c bdfc 24d9 0664 cdf5 157d 617f 92c3
53d6 a0f7 b9ae 6e4c 3055 86bc 7625 8652
f9bd 5669 7758 f9c8 90c6 18ad 49a5 1471
06c6 fcdf 76ba 6153 bb95 d896 0d81 f084
51ec f334 179e 345e 5442 23db ee18 dd21
dc8f 4851 b71d 850b b60e e7cb 759c 317d
ce3e 6516 0e99 50de cea2 71ce ce32 1a25
7ca8 0221 20f3 858d 0d84 b5d1 10f4 4780
28e4 9cf0 c3cd a486 7640 59ff 55bd c094
4bd4 06c8 bb63 d795 4fb3 5638 e927 96b4
0620 6625 b0f7 b16a 73ac 0e3c 9e3d b686
ea96 f404 b622 6952 9747 0bf7 f499 f822
19a5 b61c ce80 900d c04c 873b 6542 6410
6889 533b 4554 52e1 c159 a410 3ddb 3ed8
7435 b330 e9dc 449e 43d8 8c55 6f67 2fb7
539f 5072 d4e5 318b 0b8b 7738 00e4 be0b
7493 bf0d f104 046a 2191 9d01 ca30 df4b
20fa 0896 aa97 ce48 9679 9566 9e2b f3cb
da81 3d90 fe67 30db a340 a6a6 9080 5fa1
f35b 8d9a a754 2f49 2d0d 58e3 e4ea 2759
e7d9 d9d8 cede 1366 31ce 19a0 8363 0fb8
b85c 66d0 281b 8528 d745 e454 a1a7 6935
bfc3 1c7c cbca 66d9 69ae b06a b6be fd51
61fa 02cc e09d 7a20 2c3e f0f9 6237 5791
6217 6b0e 6a21 fb74 f59e 66ff a666 a373
1ad3 8b19 7c88 8b38 f2b9 db02 5b6c 33d4
4cfe 22da 6562 9017 44c4 35c8 658a f47e
bdfe a4d7 ddbf 430e a633 d5d6 a473 89af
411e 9448 5a54 c0b1 0256 666c 119c c662
aa1e a953 076b a9d3 a2f5 591d 1c7c 5102
7f37 8f43 ee2a 0626 8609 2fc1 1e21 ebcd
e9e5 c6fb f19d a942 ddf2 0c84 9fa6 77fe
00bb c088 4731 6640 cc51 0a4d 62bf fb67
2856 069b 4265 c567 f20f 236d 9d11 8c70
56fd 8e56 a812 7e82 4837 0b3b d440 b0d1
73ba 65bb aa5f 0f85 5776 f621 7106 de0d
86e6 6aee 3012 b950 a545 b68e 2f20 ff6f
bd07 a4eb d352 b407 3566 a875 2e42 2bfa
bfcc 7c78 aec4 9aea 4331 4d6d 7c3a f930
78d9 9c21 59cb c996 2eaf 23a4 11ba 1de0
d647 62d5 da40 bb61 493b 6c68 b2b6 473e
35c1 fd86 8034 b515 1649 90d8 86fc 1204
63f4 83dc 72b4 9a11 5950 5f40 c70d a290
9784 3637 f826 af67 5380 0736 2888 f0a9
f99b 8012 b67e 21e6 3c0c 068e 3cb9 5266
f171 780b ca10 1546 0a16 c502 0de0 0cf8
970c fc6c ebd1 0ce5 0b8b 64e8 bedd cf24
dae9 a605 45b6 d562 ef1e ed6a 6ccd 72f8
0467 e0c7 1123 274e 5ee2 564d 5100 be4a
76ca 51d8 1e0d 65ba 4d24 4c64 8c32 0f51
7124 66f8 6daa 3b6d 90f6 46a6 16fc 7703
233f fa4b e769 a68c ec70 a4e0 0de5 ab0c
e43f 6508 936f a197 2bdb 9a69 ef2f 817c
e617 03f7 5aa8 c38e 3b9f d1d7 552d 16b0
0f96 686c 28db 2389 0146 cec1 4e65 4afa
f1ee 8dbb 9868 a356 8fc3 f8d1 17fe 3f18
f649 9070 604a 1b1c e2d0 08eb 896e 2d39
d862 084f d371 3778 a0a6 2b42 f34d ab25
9350 41d1 7432 e20b abe0 ed70 376f c13f
c4a7 da36 dd8c 5746 9409 1552 2042 f13d
9416 4075 f2d2 7e90 9366 e7bc f7e5 3d01
1947 b6a8 5ed7 040f ca1a b066 53bd b91b
8935 db90 f398 58e1 4c1f 9942 d102 a337
7bd8 d3bb 5646 082b dbac e0be 2ad2 f4ff
7952 9b56 0096 3f42 febc 8b19 2b53 4aaf
1b56 103d 6236 fa07 7ccd b51b 7a48 f24b
5830 1fff ec22 4000 

How to run:

$ echo -n 'very dark purple' | python3 code.py
#2a0134

Display Name

Posted 2016-08-17T05:18:06.997

Reputation: 654

2

C, 19,566 bytes

A miserable 19,566 bytes.

#include <stdio.h>
int main(int argc,char **argv){int m=0;char *t=argv[1];int c=0;while(c!=EOF){if(m==1){if(c==10||c==13){printf("\n");m=2;}else{if(c>32)putchar(c);}}if(m==0){if(c==*t){t++;if(*t==0){m=1;printf("%s -> ",argv[1]);}}else{t=argv[1];}}c=getchar();}}

Bog-standard C. The rgb.txt file is piped in through stdin. The colour to find is given as the first argument.

So:

./xkcd "bright sea green" < colors.txt

Gives:

bright sea green -> #05ffa6

ncke

Posted 2016-08-17T05:18:06.997

Reputation: 151

3Please read the 4th paragraph of my challenge. – orlp – 2016-08-17T11:11:00.043

7Welcome to code golf! Unfortunately the rules state that if you read from a file (or in this case, pipe it in) you need to include the byte count of the file as well. Kolmogorov Complexity questions are all about shrinking big data. – Value Ink – 2016-08-17T11:12:07.567

1Oh, I geddit. Hmm... – ncke – 2016-08-17T11:20:33.527

2

Java, 7,978 7,435 bytes

Code is 293 bytes, data is 7,142 bytes

Golfed:

Object f(String k)throws Exception{Map c=new HashMap();ObjectInputStream i=new ObjectInputStream(new GZIPInputStream(new FileInputStream("c")));for(int j=0;++j<950;){c.put(i.readInt(),i.readInt());}String s=Integer.toHexString((int)c.get(k.hashCode()));while(s.length()<6)s="0"+s;return"#"+s;}

Ungolfed:

public class DecipheringXkcdColors {

  public static void main(String[] args) {
    Map<String, String> testData = new HashMap<>();
    testData.put("light moss green", "#a6c875");
    testData.put("straw", "#fcf679");
    testData.put("dark fuchsia", "#9d0759");
    testData.put("custard", "#fffd78");
    testData.put("purple", "#7e1e9c");
    try {
      for (Map.Entry<String, String> data : testData.entrySet()) {
        System.out.println("Key -> " + data.getKey());
        System.out.println("Expected -> " + data.getValue());
        System.out.print("Actual   -> ");
        System.out.println(new DecipheringXkcdColors().f(data.getKey()));
        System.out.println();
      }
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }
  }

  // Begin golf
  Object f(String k) throws Exception {
    Map c = new HashMap();
    ObjectInputStream i = new ObjectInputStream(new GZIPInputStream(new FileInputStream("c")));
    for (int j = 0; ++j < 950;) {
      c.put(i.readInt(), i.readInt());
    }
    String s = Integer.toHexString((int) c.get(k.hashCode()));
    while (s.length() < 6)
      s = "0" + s;
    return "#" + s;
  }
  // End golf

}

The file named "c" in the program is the result of the inverse operation of this program: take the hash code of each key in the input file and store it with the integer representation of the color value. That goes into an object output stream, a GZip output stream, then a file output stream. This program reads it through the inverse input streams.

The default Java hash codes of all the colors are unique across this data set, so it makes a good 32 bit key in the hash map. The value is already an integer, so all that needs to be done is to format it correctly as a hex string, padded to six digits if necessary, with a hash mark in front.

user18932

Posted 2016-08-17T05:18:06.997

Reputation:

1I tried various compression techniques as well as custom hashes, but nothing I tried could beat the built-in functionality in Java. – None – 2016-08-19T01:31:33.997

1I'd like to thank you for giving a nice simple example how to use GZIPInputStream :-) – Tschallacka – 2016-08-19T10:07:32.760

2

Java, 4649 bytes

Java code : 497 bytes, data file : 4152 bytes

The file can be found here

import java.io.*;import java.util.*;public class A{static void main(String[] a) throws Exception{byte[]d=new byte[4864];new FileInputStream("d").read(d);long h=a[0].hashCode(),k,l,r=0;h=(h&1023)+(h&14336)/2+(h&491520)/4;BitSet b=BitSet.valueOf(d);for(int i=0,j;i<33216;i+=35){for(l=0,j=16;j>=0;){l<<=1;if(b.get(i+j--))l|=1;}r+=b.get(i+33)?1:0;r+=b.get(i+34)?2:0;if(l==h){for(k=0,j=15;j>=0;){k<<=1;if(b.get(i+17+j--))k|=1;}System.out.println("#"+String.format("%06X",(k<<8)+r).toLowerCase());}}}}

ungolfed:

import java.io.*;
import java.util.*;

public class A{
    public static void main(String[] a) throws Exception{
        byte[]d=new byte[4864];
        new FileInputStream("d").read(d);
        // compute word hashcode
        long h=a[0].hashCode(),k,l,r=0;
        h=(h&1023)+(h&14336)/2+(h&491520)/4;        
        BitSet b=BitSet.valueOf(d);
        // browse data file
        for(int i=0,j;i<33216;i+=35){       
            for(l=0,j=16;j>=0;){
                l<<=1;
                if(b.get(i+j--))l|=1;
            }
            // compute color blue component
            r+=b.get(i+33)?1:0;
            r+=b.get(i+34)?2:0;
            // do hashcode match ?
            if(l==h){
                // compute color value
                for(k=0,j=15;j>=0;){
                    k<<=1;
                    if(b.get(i+17+j--))k|=1;
                }
                System.out.println("#"+String.format("%06X",(k<<8)+r).toLowerCase());
            }
        }
    }
}

The program uses an improved version of Java hashcode that uses only 17 bits:

    long hash = s.hashCode();   
    long hash2 = hash & 0b1111111111;
    hash2 += (hash & 0b11100000000000) / 2;
    hash2 += (hash & 0b1111000000000000000) / 4;

Colors are sorted by blue component increasing. They are stored on 18 bits: 8 for red, 8 for green and 2 for delta blue.

Total file size: 949 colors * (18 + 17) = 33 215 = 4152 bytes

Arnaud

Posted 2016-08-17T05:18:06.997

Reputation: 8 231

1

JavaScript (Node.js), 10785 bytes

q=>`${require('zlib').inflateRawSync(new Buffer('<encoded data>','base64'))}`.split(';').map(x=>x.split(':')).find(([a])=>a===q)[1]

Usage:

const f = q=>`${require('zlib').inflateRawSync(new Buffer('<encoded data>','base64'))}`.split(';').map(x=>x.split(':')).find(([a])=>a===q)[1]
console.log(f('baby shit brown')) // #ad900d

Encoded data.

Michał Perłakowski

Posted 2016-08-17T05:18:06.997

Reputation: 520

1

MATLAB, 94 + 7.243 = 7.337 bytes

Generate the MAT-file "h.mat" with variable "c" containing a sorted list of the CRC32 checksums of the names ( c=java.util.zip.CRC32;c.update(uint8(x));c.getValue();) and the same sorted list of the converted hex codes of the colors ( sscanf(x(:,end),'%x') ) as "e". This should have (R2013b, v7 File format, a size of 7.243 bytes.

The function is as follows

function g(x);load h;c=java.util.zip.CRC32;c.update(int8(x));sprintf('#%x',e(h==c.getValue()))

It takes advantage of the builtin compression of the MAT-files and the support of java for the CRC32 function.

Jonas

Posted 2016-08-17T05:18:06.997

Reputation: 177

1

Go, 6709 bytes

Code is 404 bytes, data is 6305 bytes

package main
import ("bytes"
"compress/flate"
"fmt"
"os")
func main(){t:=make([]byte,6643)
i:=os.Args[1]
copy(t,i)
s:=[]byte{byte(len(i))<<4|t[0]>>1&8|t[0]&7,t[1]&6<<5|t[2]&30|t[3]>>2&1,t[3]<<7|t[4]&1<<3|t[5]&20|t[6]&6<<4|t[7]&3,t[8]&3|t[9]&1<<3|t[10]&1<<4|t[11]&1<<5|t[12]&4}
f,_:=os.Open("f")
flate.NewReader(f).Read(t)
for i:=0;;i+=7{
if bytes.Equal(s,t[i:i+4]){fmt.Printf("#%X", t[i+4:i+7])
return}}}

The Data is encoded with xxd -p. Extract into a file simply named f with xxd -r paste f. The code can be ran as go run file.go "tree green"

Abex

Posted 2016-08-17T05:18:06.997

Reputation: 151

1

C#, 6422 bytes

Code is 575 bytes, data is 5847 bytes

The data exists in an adjacent GZipped file which contains a transformed representation of the original data. Color words which appear more than once are extracted and placed in a header table at the top of the file, prefixed by a one-byte length.

Data entries (after the header) consist of a set of:

  1. Single byte entries representing a common word from the header table (value equals array offset + 16)
  2. Inline string data prefixed by a single-byte length field (max length 15)

Each entry is terminated with either 0xFF, 0xFE, 0xFD which indicates that the next one, two, or three bytes following represent the color value offset, respectively.

The table is parsed in-order and color value is accumulated until a matching string to the input is found.

Minified Decompression / Lookup Code:

using System;using System.IO;using System.IO.Compression;namespace G{partial class P{static void Main(string[]a){var f=new GZipStream(File.OpenRead("m"),CompressionMode.Decompress);var b=new BinaryReader(f,S.Encoding.GetEncoding(1252));Func<int>r=()=>f.ReadByte();var d=new string[256];int t,v=0;while(""!=(d[v++]=new string(b.ReadChars(r()))));var k="";v=0;while(0<(t=r())){if(t<0xFD)k+=(t<16?new string(b.ReadChars(t)):d[t-16])+" ";else{v+=t==0xFF?r():t==0xFE?b.ReadUInt16():(r())+(b.ReadUInt16()<<8);if(k.Trim()==a[0]){Console.WriteLine($"#{v:x6}");return;}k="";}}}}}

Data Compression Code

public static void Compress(string path)
{
    var lines = File.ReadAllLines(path);

    var grams = new Dictionary<string, int>();

    var data = new Dictionary<string, string>();

    foreach (var line in lines)
    {
        var tokens = line.Split('\t');

        data[tokens[0]] = tokens[1];

        foreach (var gram in tokens[0].Split(' '))
        {
            int count;

            if (grams.TryGetValue(gram, out count))
            {
                grams[gram] = count + 1;
            }
            else
            {
                grams[gram] = 1;
            }
        }
    }

    var dict = new Dictionary<string, byte>();
    byte codeValue = 0;
    foreach (var result in grams.OrderBy(kvp => -kvp.Value))
    {
        if (result.Value == 1)
            break;

        dict[result.Key] = codeValue;
        codeValue++;
    }

    using (var outputData = new BinaryWriter(File.OpenWrite("m.dat"), Encoding.GetEncoding(1252)))
    {
        foreach(var dictValue in dict.OrderBy(kvp => kvp.Value))
        {
            outputData.Write((byte)dictValue.Key.Length);
            outputData.Write(dictValue.Key.ToCharArray());
        }

        outputData.Write('\0');

        int currentColor = 0;

        foreach (var entry in data.OrderBy(kvp => kvp.Value))
        {
            foreach (var gram in entry.Key.Split(' '))
            {
                if (dict.ContainsKey(gram))
                {
                    outputData.Write((byte)(dict[gram] + 16));
                }
                else
                {
                    outputData.Write((byte)gram.Length);
                    outputData.Write(gram.ToCharArray());
                }
            }

            var colorValueString = entry.Value.TrimStart('#');
            var colorValueInt = int.Parse(colorValueString, System.Globalization.NumberStyles.AllowHexSpecifier);

            var colorValueDiff = colorValueInt - currentColor;

            if(colorValueDiff <= byte.MaxValue)
            {
                outputData.Write((byte)0xFF);
                outputData.Write((byte)colorValueDiff);
            }
            else if(colorValueDiff <= ushort.MaxValue)
            {
                outputData.Write((byte)0xFE);
                outputData.Write((ushort)colorValueDiff);
            }
            else
            {
                outputData.Write((byte)0xFD);
                outputData.Write(colorValueDiff);
                outputData.BaseStream.Seek(-1, SeekOrigin.Current);
            }

            currentColor = colorValueInt;
        }
    }

    var d = File.ReadAllBytes("m.dat");
    var g = new GZipStream(File.OpenWrite("m"), CompressionLevel.Optimal);

    g.Write(d, 0, d.Length);
    g.Dispose();
}

nicholas

Posted 2016-08-17T05:18:06.997

Reputation: 145

1

C# 7,209 bytes: 6,643 bytes data + 566 bytes code (878 bytes unminimized)

Github repo is here: https://github.com/nbcarey/color-map

Color names are compressed in the data file using the FNV-32-1a hash as this hash algorithm is conventiently collision-free for this set of color names. So each color name is stored as 4 bytes.

Each color is stored as 3 bytes (1 each for red, green and blue). No magic there.

Consequently, each mapping of color name to RGV value occupies 7 bytes in the compressed file.

This is a one-line version of the FNV-32-1a hash (assuming a string containing only simple ASCII characters:

uint hash = Encoding.ASCII.GetBytes("royal blue")
            .Aggregate(0x811c9dc5u, (h,b)=> h=(h^b)*0x01000193u )
            ;

This compressed data file is in the github repo at https://github.com/nbcarey/color-map/blob/master/color-map/hashed-color-map.dat

Here's the minimized code:

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;namespace A{class B{static void Main(string[]C){var D = new Dictionary<uint,uint>();var E=File.ReadAllBytes("hashed-color-map.dat");for(int i=0;i<E.Length;i+=7){uint F=BitConverter.ToUInt32(E,i);uint G =(uint)(E[i+4]<<16|E[i+5]<<8|E[i+6]);D.Add(F,G);}foreach(var H in C){uint I;var J=D.TryGetValue(Encoding.ASCII.GetBytes(H).Aggregate(0x811c9dc5u,(h,b)=>h=(h^b)*0x01000193u),out I);var c=J?String.Format("#{0:X6}",I):"NOT FOUND";Console.WriteLine("{0}: {1}",c,H);}}}}    

And here's human-readable code:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace color_map
{
  class Program
  {
    static void Main( string[] args )
    {
      var map = new Dictionary<uint,uint>();

      var data = File.ReadAllBytes("hashed-color-map.dat");
      for ( int i = 0 ; i < data.Length ; i += 7 )
      {
        uint hash = BitConverter.ToUInt32(data,i);
        uint rgb   = (uint)( data[i+4] << 16 | data[i+5] << 8 | data[i+6] << 0 );
        map.Add(hash,rgb);
      }

      foreach (var cn in args )
      {
        uint rgb;
        var hit = map.TryGetValue(Encoding.ASCII.GetBytes(cn).Aggregate(0x811c9dc5u, (h,b)=> h=(h^b)*0x01000193u ), out rgb);
        var c = hit ? String.Format("#{0:X6}",rgb) : "NOT FOUND";
        Console.WriteLine("{0}: {1}", c , cn);
      }

    }
  }
}

Nicholas Carey

Posted 2016-08-17T05:18:06.997

Reputation: 111

1

PHP, 5014 bytes

Not the best there is but it's late and I need to get some sleep. :-)

The beauty of PHP is that you can inline payload data into your script and read the file itself, so the script is self-sufficient. Just download it, run it and it will prompt for the color name.

<?$f=fopen(__FILE__,r);fseek($f,269);$m=stream_get_contents($f);while($l<4745){$d.=str_pad(dechex(ord($m{$l++})),2,0);}$h=sha1(trim(fgets(STDIN)));$k=substr($h,0,3).$h{16};for($i=0;$i<9490;$i+=10){if($k==substr($d,$i,4)){echo'#'.substr($d,$i+4,6);}};__HALT_COMPILER();
$¥¬ÂÙóûV®W}a²™nÂÀ¨ÿÄ°iØOûO‰E…&@p²? xÔÿÿuAe«|Šü•.¤üüÁÿ¥£‘F²8€?šL…8^›Šlï´5m‘Ù›‚´
[...MORE BINARY DATA...]

The basic trick here is to hash the color names and generate minimally identifying substrings of that hash. I found that 4 chars of a SHA1 hash are enough, the first 3 and the 17th to uniquely identify all those colors. The key is in binary as well as the color code, which is conveniently one byte per color channel. So every entry takes up 5 bytes, which makes for 5 x 949 = 4745 bytes payload (the magic number you see in the code).

Compression didn't help very much, bzip2, LZMA all created bigger files so without any further tricks, this is as compressed as it goes for this approach.

YetiCGN

Posted 2016-08-17T05:18:06.997

Reputation: 941

1

Bash + (coreutils,gzip,xxd,openssl,sed,grep), 4946 bytes

data: 4482 bytes, code: 464 bytes

s=$(echo $1|openssl dgst -md5 -binary|base64|cut -c3,10,19)
f=$(gzip -cd g)
a=''
function p {
q=$(grep -Eo "[$1]{[A-Za-z0-9/+]+}"<<<$f|sed -r "s/([$1]\{|\})//g")
for i in `seq 1 6 ${#q}`;do
n="$1$(cut -c$i-$((i+1))<<<$q)"
c="$(echo -n $(echo $q|cut -c$((i+2))-$((i+5)))|base64 -d|xxd -p)"
a="$n#$c,$a"
done
}
p $(echo $s|cut -c1)
s=$(sed -r 's~([+/])~[\1]~g'<<<$s)
r=$(echo $a|grep -Eo ",?$s#[a-z0-9]+")
if [ ${#r} -gt 0 ];then
echo -n '#'
echo $r|cut -d\# -f 2
fi

Data can be found in base64 here. I know that code may be more golfed. Too sleepy now :/ Any suggestions are welcome :-)

Explanation

Here are the actions I made on the original file after removing the license comment.

  1. Calculate the binary md5 of the color names and turned it in base64: openssl dgst -md5 -binary|base64
  2. Found that the characters 3, 10 and 19 may be used to represent uniquely all the entries. base64 uses a set of 64 characters to represent the data, A-Za-z0-9+/. So, I was hoping to find 2 bytes because all the entries were 494 and 64*64=4096 but I couldn't find any. I also tried to find 2-char unique entries by using sha512 in step one but without any luck. So, I stayed with these 3 bytes for the color names.
  3. I represented in base64 the color names instead of hex: (echo '0:';echo -n "$line"|cut -d '#' -f 2)|xxd -rp -l 16|base64
  4. I grouped the results by the first byte from step 2.
  5. I used zopfli -i1000 to compress the file.

So the result file before the compression would look like that:

+{wf/7FtHhPAAIgWXKwtrpFbAaS6/i9KYk7cj//bpvuy9zvOysmxxvz//6vBP+m2sZFuXG+EgcIhZY1tsTAYif5s1f//xCFS7/}/{61snE90JK69qWKBIJDy83YXXE4df1jNx+XMGQA/60B1Msf9lKaAAEzLs+1WB}0{uiBWlrhIdJVRGSMr+ERZ78D+m2Tv1USQpL5cS3wcb8Hmj/+fZMa6NTEUwrcJqRvv1z+k2VRNvy/7GavV/5qKCTlFaMk5/3lsisUWVy2lraWH3nuaKBdb/+Nu}...

I tried other compression utilities also but with worst results except from zopfli -i0000 --zlib with 4470 bytes and zopfli -i10000 --defalte with 4464 but I was not sure how to uncompress there formats.

In order to find the color code I do the reverse actions. I create the 3 character code from the given name and I reconstruct partially the original color codes. For example for adobe I create all that start with X:

Xqy#bd6c48
XL7#7ea07a
XI4#3a18b1
...

Then I grep the Xqy line and return the second part which is the color hex.

I really enjoyed this puzzle and there are many great answers here. Thanks and good job everyone!

Master_ex

Posted 2016-08-17T05:18:06.997

Reputation: 526

0

Bash + coreutils/xxd, 4064 bytes

Data 3796 bytes (hex dump of data file)

Bash 268 bytes

h=`md5sum<<<$1|xxd -r -p|xxd -b -g0 -l128 -c128|cut -c18,20,26,41,46,49,65,85,88,90,94,95,118,135`;case $1 in mud|aqua?blue)h=0${h%0};;esac;xxd -b -g4 -c4 d|while read -r x;do let b+=2#${x:23:2};case ${x:9:14} in $h)printf '#%04x%02x\n' $((2#${x:25:16})) $b;;esac;done

Ungolfed

# Set h to select 14 bits from the md5sum in base 2
h=`md5sum<<<$1 | \
   xxd -r -p|xxd -b -g0 -l128 -c128|cut -c18,20,26,41,46,49,65,85,88,90,94,95,118,135`
# Disambiguate hash collisions
case $1 in
   mud|aqua?blue)
      h=0${h%0}
      ;;
esac
# process each 32-bit record:
#   First 14 bits are hash
#   Next 2 bits are blue deltas
#   Final 16 bits rg
xxd -b -g4 -c4 d | \
   while read -r x; do
      let b+=2#${x:23:2};
      case ${x:9:14}
         in $h)
            printf '#%04x%02x\n' $((2#${x:25:16})) $b
            ;;
      esac;
   done

The overall idea is to scan through 32-bit fields, find the matching unique 14-bit hash, and print the color code at that location. The 18-bit color encoding leverages Super Chafouin's approach.

The unique 14-bit hash starts with a subset of 14 of the bits from the 128-bit md5sum. To find those bits I used a genetic algorithm coded in C++ here. The code pre-loads a fixed file called "data", which is just the md5sum's, one per line, in binary. If you need that in recipe form, this will create the data file:

(cut -f1 rgb.txt|while read x; do md5sum<<<$x | xxd -r -p | xxd -b -g16 -c16| cut -d' ' -f 2;done) > data

I find the best candidate 14 bits (that I've seen so far) from this code in generation 2, but this set has two collisions. Specifically: "mud" and "pale purple" map to the same value, and "aqua blue" and "light green" map to the same value. Since there are only two collisions and I haven't found anything better, I just disambiguate them; turns out half of each of these bucket values is unused.

I already tried compression on d; but neither bzip2, nor gzip, nor xz appears to shrink d's size.

H Walters

Posted 2016-08-17T05:18:06.997

Reputation: 1 536

0

Groovy, 153 + 10,697 = 10,850 253 + 9870 = 10,123 bytes

I decided I wanted a solution which involved only one file, so (at the obvious cost of space) I encoded a GZIPped CSV version of the data to Unicode characters 0x0020-0x007E (which I guess would be a base 95 encoding?). The code is 253 characters, the content of the String is 10123 characters.

import java.util.zip.*
t=0
'''^/3"O:<]NULAydP{|dgMn0T4;4&Y!~0=(BsILP$#KxAoQ<C6Z-.Psh/}k3&uOEa[S}R+u4=X*K`?X&zTKSQT>xdA-_XEy2/e{N$Ue:DSF- *Df1E3x)i=cq;FFq]|p,!sbQpE5F}$qr]zu'jK&A^\\Vd9"sKPgF_^uv>q)6#/"b1#gR"yvZ#<p9{T+__!fl\\\\=7P{zO0('G R+5QKuX}( ,r$V]" ;G)\\3Yooo}<)%HrxnFWLtG1Dwe!N Nz*u;Ti`TI}ly@T.zA!Lx{w#e0[:Y@feo,=^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ls\\G":*.FQ 7o,rp~s\\>s)#3G$Q~FjZHE"Xz40;Yh?5alWWX|.(3jRR|9u+I2ufN@. ,44}bzyis*.YC'r{n72VEA>kgf?~RZEdq#{jFy?(Xn>S*2;$c?@b\\nGVNzJ=^PS[i#L@>l:^qtkEv"&_3pgU^<oVF]>&GvJ|Yg!{Trhp^{_&nabRM!:Z(a}AWWz>|hn,v(fe#)3jJ_Zq|-?QLY`#uCSHA{$!$am0gel%< bM<GRi^0^s@Y`npt2/&:SEAYc'ycCiG'McJ"wna)i25\\D9YKl>vD;4QrVW\\LAN{ePJw]uhy>C;xR1?'?NN4?PU`f-.'7UbULY|%|'%!'''.eachWithIndex{c,i->t+=95g**i*(((byte)c)-32g)}
b=[]
while(t){b<<(byte)(t%256-128)
t=t.intdiv(256)}
println new GZIPInputStream(new ByteArrayInputStream((byte[])b)).readLines().collectEntries{(List)it.split(',')}[args[0]]

For readability, here's the same thing with the encoded text excluded:

import java.util.zip.*
t=0
'''^/3...'%!'''.eachWithIndex{c,i->t+=95g**i*(((byte)c)-32g)}
b=[]
while(t){b<<(byte)(t%256-128)
t=t.intdiv(256)}
println new GZIPInputStream(new ByteArrayInputStream((byte[])b)).readLines().collectEntries{(List)it.split(',')}[args[0]]

My original solution was a simpler Base 64 encoding using the built-in encoder

import java.util.zip.*
print new GZIPInputStream(new ByteArrayInputStream(Base64.decoder.decode('H4sIAAAAAAAAAGVc23LjuJJ851c44jzsy0QMAOL6Obja3JZFLyV1r+frNws30rPzNrJEAoWqrMyqQsfb/krfb+H2yn/9x8cokluSP369ffnHM9/e3o+c73/9R2mflVnS6/H86z9BOKfzkm85Po8tvt22T/qxLYXJpRz58TF+pl2ysiy37f3j+Zbf379u/o4HWCeVVcsdr/geXzUsiLUsR/a32/db+0VbVZIF/y3P7PFA5YOJyx9/fL59vY6vG/7ulMi2LN/5dtv/bHj50+N5JZZo+RLzZ6ZXeuVXx9vW3g//eIz3rtYyLJt29v2Gd9z++o+MjmF5+ML4RGUXr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dvfhvBEGggYd0Nr6Cqcj+XIdr7I0x12WVnlLAY7fZyVHoq+VqH+NPzC6gD8tPcKtSqiuZOp6EESjLt1FJSt0z/jnP31Bsz9tzpA2xWlg6sdot0y2XhIhqJv+QlDHl+tFXIaFstkmmuO0CoDeIb9oMf8BhxFZiaeyzEp2pIYJX0bJFiAmrFh6t9KXAiJw6eaptUTPl2t5xtLdsy5gBrGSHELnh0zSxngakRgTUgEYtPwYoTYQWGOp898xsBxp4bxSSLObloZu2vRp/W8ZA8fZC5zFj9kUzqVeftwHVUx6JJEmj+B9cLrlvPtmnI5LT986m6oTezVJK3jjbAPNChvdLFx+DFqsimkagGu1BuQgbkcZ7WwBSINza7KQr5mKnJ2NsfZPrtR/y4QHocvZhqkbXlVYrv15B+9arkxHR+Hj8qPhsK6qXpjtzQTPch54PB25GFP0ci2KWzy6DQvXsQqnIILOooZRIcDa10zAqVrRKQCwlpnzrk7DCg0Q7DeJCLucoQH7HtnCrfZaXKc7tvXuWxuVVvWkhwxSq6Eg6y5heR+NpK3KNZVlUmUw/NETJS7KMyjH/wGizuuGeUcAAA=='))).readLines().collectEntries{(List)it.split(',')}[args[0]]

For readability, here's the same thing with the text excluded:

new GZIPInputStream(new ByteArrayInputStream(Base64.decoder.decode(''))).readLines().collectEntries{(List)it.split(',')}[args[0]]

M. Justin

Posted 2016-08-17T05:18:06.997

Reputation: 151