Deciphering XKCD colors 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 &lt;-> 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 -&gt; #de7e5d   
robin's egg blue -&gt; #98eff9 
pink/purple -&gt; #ef1de7
Perl 5 - 4212 3956 3930

use IO::Uncompress::Gunzip qw(gunzip);
gunzip 'g'=&gt;\$_;
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);
$_=&lt;&gt;;
for$i(0..(($h=y///c-1)&lt;=12?$h-1:12)){$h+=$a[(($i/2|0)==1)+ord((/./g)[$i])]if($i!=7&amp;&amp;$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