答:
Java 8, 57 bytes

Uses a lambda to save bytes, performs the calculation and substrings to return the answer.

(v,a)->"**********".substring(Math.max(0,(700*a-v)/70/a))
```

<hr>

<p>Here is my class for testing it.</p>

<pre class="lang-java prettyprint-override"><code>public class DifficultyCalculator{
    static interface h{ String f(int v, int a);}
    static void g(h H){
        System.out.print(H.f(163,2));System.out.println("\t**");
        System.out.print(H.f(548,22));System.out.println("\t*");
        System.out.print(H.f(1452,24));System.out.println("\t*");
        System.out.print(H.f(1713,37));System.out.println("\t*");
        System.out.print(H.f(4162,32));System.out.println("\t**");
        System.out.print(H.f(3067,15));System.out.println("\t***");
        System.out.print(H.f(22421,19));System.out.println("\t**********");
    }
    public static void main(String[] args) {
        g( // 70
            (v,a)->"**********".substring(java.lang.Math.max(0,(int)(10-v/70d/a)))
        );
    }
}
</code>```

Update

-3 [16-08-19] Utilized integer division

-10 [16-08-18] Removed unnecessary import, thanks to @OlivierGrégoire!

-18 [16-08-17] Return string instead of print

Body:
Briefing

The difficulty of a Code Golf question can be calculated as such:

$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$

Where \$v\$ is the number of views a question has

and \$a\$ is the number of answers a question has

and \$⌈x⌉\$ is the ceiling operator.

Also:

$$\text{clamp}(x, min, max) = \begin{cases}
min & x < min \\
x   & min \le x \le max \\
max & max < x
\end{cases}$$

This question's current difficulty: ***

Task

Write a program that will take two integers (v and a) and output the difficulty in asterisks (*).

The input can be in the form of an array, a separated string or as separate function arguments

Test Data

```<code>Views   Answers Difficulty  Program Output
163     2       2           **
548     22      1           *
1452    24      1           *
1713    37      1           *
4162    32      2           **
3067    15      3           ***
22421   19      10          **********
</code>```

Example with pseudocode

```<code>v: 1713
a: 37
out = clamp(ceil(((v/a)/700)*10), 0, 10); // evaluates to 1
//program will output '*'
</code>```

The shortest code in bytes wins! Trailing/ leading spaces are allowed.

Body:
Java 8, 57 bytes

Uses a lambda to save bytes, performs the calculation and substrings to return the answer.

(v,a)->"**********".substring(Math.max(0,(700*a-v)/70/a))

Here is my class for testing it.

public class DifficultyCalculator{
    static interface h{ String f(int v, int a);}
    static void g(h H){
        System.out.print(H.f(163,2));System.out.println("\t**");
        System.out.print(H.f(548,22));System.out.println("\t*");
        System.out.print(H.f(1452,24));System.out.println("\t*");
        System.out.print(H.f(1713,37));System.out.println("\t*");
        System.out.print(H.f(4162,32));System.out.println("\t**");
        System.out.print(H.f(3067,15));System.out.println("\t***");
        System.out.print(H.f(22421,19));System.out.println("\t**********");
    }
    public static void main(String[] args) {
        g( // 70
            (v,a)->"**********".substring(java.lang.Math.max(0,(int)(10-v/70d/a)))
        );
    }
}

Update

-3 [16-08-19] Utilized integer division

-10 [16-08-18] Removed unnecessary import, thanks to @OlivierGrégoire!

-18 [16-08-17] Return string instead of print


问:
Calculate the difficulty of a Code Golf question

Briefing

The difficulty of a Code Golf question can be calculated as such:

$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$

Where \$v\$ is the number of views a question has

and \$a\$ is the number of answers a question has

and \$⌈x⌉\$ is the ceiling operator.

Also:

$$\text{clamp}(x, min, max) = \begin{cases}
min & x < min \\
x   & min \le x \le max \\
max & max < x
\end{cases}$$

This question's current difficulty: ***

Task

Write a program that will take two integers (v and a) and output the difficulty in asterisks (*).

The input can be in the form of an array, a separated string or as separate function arguments

Test Data

```<code>Views   Answers Difficulty  Program Output
163     2       2           **
548     22      1           *
1452    24      1           *
1713    37      1           *
4162    32      2           **
3067    15      3           ***
22421   19      10          **********
</code>```

Example with pseudocode

```<code>v: 1713
a: 37
out = clamp(ceil(((v/a)/700)*10), 0, 10); // evaluates to 1
//program will output '*'
</code>```

The shortest code in bytes wins! Trailing/ leading spaces are allowed.

答:
m4, <s>136</s> 135 bytes

```<code>define(r,`ifelse($1,0,,eval($1>9),1,*`r(9)',*`r(decr($1))')')define(f,`r(ifelse(eval($1%($2*70)),0,eval($1/$2/70),eval($1/$2/70+1)))')
</code>```

Defines a macro f which takes v and a, and expands to the correct output. Most of the program is an implementation of ceiling.

ContentLicense: CC BY-SA 4.0

Body:
m4, <s>136</s> 135 bytes

define(r,`ifelse($1,0,,eval($1>9),1,*`r(9)',*`r(decr($1))')')define(f,`r(ifelse(eval($1%($2*70)),0,eval($1/$2/70),eval($1/$2/70+1)))')

Defines a macro f which takes v and a, and expands to the correct output. Most of the program is an implementation of ceiling.

ContentLicense: CC BY-SA 3.0


问:
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 <-> 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:

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

Title: Deciphering XKCD colors

Body:
Ruby, <s>5,379</s> 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.


答:
I've been wanting to do this for a while...

HTML + CSS <s>491</s> <s>487</s> 485 bytes

-4 bytes thanks to Conor O'Brien

-2 bytes thanks to Releasing Helium Nuclei

Input is taken as the width and height of the page window; width being the number of Views, and height being the number of Answers.

```<code><style>p{overflow:hidden;width:1ch}@media(max-aspect-ratio:70/2){p{width:1ch}}@media(max-aspect-ratio:70/3){p{width:2ch}}@media(max-aspect-ratio:70/4){p{width:3ch}}@media(max-aspect-ratio:70/5){p{width:4ch}}@media(max-aspect-ratio:70/6){p{width:5ch}}@media(max-aspect-ratio:70/7){p{width:6ch}}@media(max-aspect-ratio:70/8){p{width:7ch}}@media(max-aspect-ratio:70/9){p{width:8ch}}@media(max-aspect-ratio:7/1){p{width:9ch}}@media(max-aspect-ratio:70/11){p{width:10ch</style><p>**********
</code>```

You can try it in your browser by entering

```<code>data:text/html,<style>p{overflow:hidden;width:1ch}@media(max-aspect-ratio:70/2){p{width:1ch}}@media(max-aspect-ratio:70/3){p{width:2ch}}@media(max-aspect-ratio:70/4){p{width:3ch}}@media(max-aspect-ratio:70/5){p{width:4ch}}@media(max-aspect-ratio:70/6){p{width:5ch}}@media(max-aspect-ratio:70/7){p{width:6ch}}@media(max-aspect-ratio:70/8){p{width:7ch}}@media(max-aspect-ratio:70/9){p{width:8ch}}@media(max-aspect-ratio:7/1){p{width:9ch}}@media(max-aspect-ratio:70/11){p{width:10ch</style><p>**********
</code>```

as a url in a new tab.

Title: Calculate the difficulty of a Code Golf question

Body:
I've been wanting to do this for a while...

HTML + CSS <s>491</s> <s>487</s> 485 bytes

-4 bytes thanks to Conor O'Brien

-2 bytes thanks to Releasing Helium Nuclei

Input is taken as the width and height of the page window; width being the number of Views, and height being the number of Answers.

<style>p{overflow:hidden;width:1ch}@media(max-aspect-ratio:70/2){p{width:1ch}}@media(max-aspect-ratio:70/3){p{width:2ch}}@media(max-aspect-ratio:70/4){p{width:3ch}}@media(max-aspect-ratio:70/5){p{width:4ch}}@media(max-aspect-ratio:70/6){p{width:5ch}}@media(max-aspect-ratio:70/7){p{width:6ch}}@media(max-aspect-ratio:70/8){p{width:7ch}}@media(max-aspect-ratio:70/9){p{width:8ch}}@media(max-aspect-ratio:7/1){p{width:9ch}}@media(max-aspect-ratio:70/11){p{width:10ch</style><p>**********

You can try it in your browser by entering

data:text/html,<style>p{overflow:hidden;width:1ch}@media(max-aspect-ratio:70/2){p{width:1ch}}@media(max-aspect-ratio:70/3){p{width:2ch}}@media(max-aspect-ratio:70/4){p{width:3ch}}@media(max-aspect-ratio:70/5){p{width:4ch}}@media(max-aspect-ratio:70/6){p{width:5ch}}@media(max-aspect-ratio:70/7){p{width:6ch}}@media(max-aspect-ratio:70/8){p{width:7ch}}@media(max-aspect-ratio:70/9){p{width:8ch}}@media(max-aspect-ratio:7/1){p{width:9ch}}@media(max-aspect-ratio:70/11){p{width:10ch</style><p>**********

as a url in a new tab.


答:
Fourier, 46 bytes

All division in Fourier is integer division, so I just add one after division.

```<code>I*10/I/700^~X<0{1}{0~X}X>10{1}{10~X}X(42ai^~i)
</code>```

Try it online!

Body:
Fourier, 46 bytes

All division in Fourier is integer division, so I just add one after division.

I*10/I/700^~X<0{1}{0~X}X>10{1}{10~X}X(42ai^~i)

Try it online!


问:
Showcase of Languages

Notes

This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not create additional showcase questions.

This is no longer a popularity-contest, nor are snippet lengths limited by the vote tally. If you know this thread from before, please make sure you familiarize yourself with the changes.

This thread is dedicated to showing off interesting, useful, obscure, and/or unique features your favorite programming languages have to offer. This is neither a challenge nor a competition, but a collaboration effort to showcase as many programming languages as possible as well as possible.

How this works

All answers should include the name of the programming language at the top of the post, prefixed by a #.

Answers may contain one (and only one) factoid, i.e., a couple of sentences without code that describe the language.

Aside from the factoid, answers should consist of snippets of code, which can (but don't have to be) programs or functions.

The snippets do not need to be related. In fact, snippets that are too related may be redundant.

Since this is not a contest, all programming languages are welcome, whenever they were created.

Answers that contain more than a handful of code snippets should use a Stack Snippet to collapse everything except the factoid and one of the snippets.

Whenever possible, there should be only one answer per programming language. This is a community wiki, so feel free to add snippets to any answer, even if you haven't created it yourself. There is a Stack Snippet for compressing posts, which should mitigate the effect of the 30,000 character limit.

Answers that predate these guidelines should be edited. Please help updating them as needed.

Current answers, sorted alphabetically by language name

$.ajax({type:"GET",url:"https://api.stackexchange.com/2.2/questions/44680/answers?site=codegolf&filter=withbody",success:function(data){for(var i=0;i<data.items.length;i++){var temp=document.createElement('p');temp.innerHTML = data.items[i].body.split("\n")[0];$('#list').append('
' + temp.innerText || temp.textContent + '');}}})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><base href="http://codegolf.stackexchange.com"><ul id="list"></ul></code>```

答:
Fourier

Factoid

I originally intended this to be a golfing version of Brainfuck... Alas, due to the simplicity of the language structure, this language is in no way good for golfing.

Snippets

Length 0 Snippet:

```<code>         </code>```

An empty program does nothing. No input, no output, no change to the accumulator.

Try it online!

Length 1 Snippet:

```<code>o
</code>```

o outputs the value of the accumulator. Since the value of the accumulator is 0 at the start of the program, 0 is outputted.

Try it online!

Length 2 Snippet:

```<code>^o
</code>```

^ increases the value of the accumulator by one. The o then outputs the value of the accumulator, printing the number 1.

Try it online!

Length 3 Snippet:

```<code>9ro
</code>```

r generates a random number between 0 and the value pf the accumulator. Here, it generates a random number between 0 and nine and then o outputs the number.

Try it online!

Length 4 Snippet:

```<code>4^do
</code>```

Uses the fifth function of the date function: outputting the current year. The other functions of the date function are:

0: current second

1: current minute

2: current hour

3: current day

4: current month

5: current year

Try it online!

Length 5 snippet:

```<code>I*10o
</code>```

Sets the value of the accumulator the user's input, multiplies it by ten and outputs the number. It's a basic program but demonstrates how user input works.

Try it online!

Length 6 snippet:

```<code>2(5ro)
</code>```

This program prints random numbers until the random number is 2. It is an example of looping:

```<code>x(code here)
</code>```

Repeats the code within the brackets until the resulting value of the accumulator within the brackets is equal to the value of the accumulator at position x.

Try it online!

Length 7 snippet:

```<code>|7o|GGG
</code>```

This is an example of a function. It works like so:

```<code>|code here|x
</code>```

You contain the function code within the pipes and store the function in the variable x (can be any variable name). To run the code within the pipes, just write the function name.

The function here prints the number 7 twice because g (the function name) is called twice.

Try it on FourIDE!

Length 8 snippet:

```<code>o
</code>```0

This is a simple program which takes an input of a single number and tells you if the number is even (1) or not (0).

It is an example of how Fourier uses 1 and 0 as truthy and falsey values.

Try it online!

Title: Showcase of Languages

Body:
Fourier

Factoid

I originally intended this to be a golfing version of Brainfuck... Alas, due to the simplicity of the language structure, this language is in no way good for golfing.

Snippets

Length 0 Snippet:

An empty program does nothing. No input, no output, no change to the accumulator.

Try it online!

Length 1 Snippet:

o

o outputs the value of the accumulator. Since the value of the accumulator is 0 at the start of the program, 0 is outputted.

Try it online!

Length 2 Snippet:

^o

^ increases the value of the accumulator by one. The o then outputs the value of the accumulator, printing the number 1.

Try it online!

Length 3 Snippet:

9ro

r generates a random number between 0 and the value pf the accumulator. Here, it generates a random number between 0 and nine and then o outputs the number.

Try it online!

Length 4 Snippet:

4^do

Uses the fifth function of the date function: outputting the current year. The other functions of the date function are:

0: current second

1: current minute

2: current hour

3: current day

4: current month

5: current year

Try it online!

Length 5 snippet:

I*10o

Sets the value of the accumulator the user's input, multiplies it by ten and outputs the number. It's a basic program but demonstrates how user input works.

Try it online!

Length 6 snippet:

2(5ro)

This program prints random numbers until the random number is 2. It is an example of looping:

x(code here)

Repeats the code within the brackets until the resulting value of the accumulator within the brackets is equal to the value of the accumulator at position x.

Try it online!

Length 7 snippet:

|7o|GGG

This is an example of a function. It works like so:

|code here|x

You contain the function code within the pipes and store the function in the variable x (can be any variable name). To run the code within the pipes, just write the function name.

The function here prints the number 7 twice because g (the function name) is called twice.

Try it on FourIDE!

Length 8 snippet:

I^~NN%2o

This is a simple program which takes an input of a single number and tells you if the number is even (1) or not (0).

It is an example of how Fourier uses 1 and 0 as truthy and falsey values.

Try it online!


答:
Perl 5 - <s>4212</s> <s>3956</s> 3930

```<code>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];
</code>```

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:

```<code>echo 'pale red' | perl get-color.pl
#d9544d
</code>```

Edit: Further reduced the size by gzipping the data file

Title: Deciphering XKCD colors

Body:
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:

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

Body:
Perl 5 - <s>4212</s> <s>3956</s> 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


Body:
Pyke, <s>13</s> 9 bytes

/70/\**T<

Try it here!

Explanation:

/         -    num_1 / num_2
 70/      -   ^ / 70
    \**   -  "*" * ^
       T< - ^[:10]


Title: Deciphering XKCD colors

Body:
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.


答:
JavaScript (Node.js), 10785 bytes

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

Usage:

```<code>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
</code>```

Encoded data.

Title: Deciphering XKCD colors

Body:
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.


问:
Golf a Brain-Flak Integer
Integers are tedious to represent in Brain-Flak. There are 8 operators:

```<code>()      Evaluates to 1, but does not push anything on any stack
[]      Evaluates to an indeterminate value for the purposes of this question
{}      Removes the top of the stack and evaluates to it
<>      Switches to or back from the alternate stack and evaluates to zero
(foo)   Pushes the value of the expression foo to the stack and evaluates to it
[foo]   Evaluates to the negation of foo
{foo}   Evaluates the expression foo until the top of the stack is zero
<foo>   Evaluates to zero but executes foo anyway
</code>```

foo may consist of multiple operators, in which case they are evaluated and summed. For example (()()) pushes 2 to the stack (and evaluates to 2 too).

Obviously, the (()...()) mechanism is not useful in Code Golf as large numbers would take n*2+2 bytes to represent. Your challenge is therefore to write a program or function that will output in as few bytes as possible a Brain-Flak program that will push a given positive integer n to the active stack. This program must not make any assumptions about the existing contents of the stacks, so it must not leave the stacks exchanged or add or remove extra values from the stacks.

Although your program or function must be capable of returning a working Brain-Flak program for all inputs from 1 to 1,000,000 the winner will be the program or function that generates the smallest set of appropriate Brain-Flak programs for all 1061 prime numbers between 1,000 and 10,000. You should note the total size of your outputs for those 1061 inputs as part of your submission. Your program or function may accept the integer and return the (string) Brain-Flak program in any of the usual acceptable I/O formats. Ties will be broken using the size of your program or function.

答:
Python, 64014 characters

I didn't know anything about brainflak before this challenge and only fiddled around with it a bit on tryitonline, so there could be obvious shortcuts I missed. This is a quite boring solution, just splits the input into x=x/2+x%2 or x=x/3+x%3, whichever is shorter.

k=lambda x:"(("+o(x/3)+")){}{}"+(x%3)*"()"if x>3else"()"*x
m=lambda x:"("+o(x/2)+"){}"+(x%2)*"()"if x>6else"()"*x
o=lambda x:min(k(x),m(x),key=len)
b=lambda x:"("+o(x)+")"
```

Call it like so: b(42)

output on pastebin

Title: Golf a Brain-Flak Integer

Body:
Python, 64014 characters

I didn't know anything about brainflak before this challenge and only fiddled around with it a bit on tryitonline, so there could be obvious shortcuts I missed. This is a quite boring solution, just splits the input into x=x/2+x%2 or x=x/3+x%3, whichever is shorter.

k=lambda x:"(("+o(x/3)+")){}{}"+(x%3)*"()"if x>3else"()"*x
m=lambda x:"("+o(x/2)+"){}"+(x%2)*"()"if x>6else"()"*x
o=lambda x:min(k(x),m(x),key=len)
b=lambda x:"("+o(x)+")"

Call it like so: b(42)

output on pastebin


问:
Complexity-free Kolmogorov(-Smirnov)
In statistics, sometimes it's useful to know whether two data samples come from the same underlying distribution. One way to do this is to use the two-sample Kolmogorov-Smirnov test.

Your task will be to write a program that reads in two unsorted nonnegative integer arrays and calculates the main statistic used in the test.

Given an array A and a real number x, define the distribution function F by

```<code>F(A,x) = (#number of elements in A less than or equal to x)/(#number of elements in A)
</code>```

Given two arrays A1 and A2, define

```<code>D(x) = |F(A1, x) - F(A2, x)|
</code>```

The two-sample Kolmogorov-Smirnov statistic is the maximum value of D over all real x.

Example

```<code>A1 = [1, 2, 1, 4, 3, 6]
A2 = [3, 4, 5, 4]
</code>```

Then:

```<code>D(1) = |2/6 - 0| = 1/3
D(2) = |3/6 - 0| = 1/2
D(3) = |4/6 - 1/4| = 5/12
D(4) = |5/6 - 3/4| = 1/12
D(5) = |5/6 - 4/4| = 1/6
D(6) = |6/6 - 4/4| = 0
</code>```

The KS-statistic for the two arrays is 1/2, the maximum value of D.

Test cases

```<code>[0] [0] -> 0.0
[0] [1] -> 1.0
[1, 2, 3, 4, 5] [2, 3, 4, 5, 6] -> 0.2
[3, 3, 3, 3, 3] [5, 4, 3, 2, 1] -> 0.4
[1, 2, 1, 4, 3, 6] [3, 4, 5, 4] -> 0.5
[8, 9, 9, 5, 5, 0, 3] [4, 9, 0, 5, 5, 0, 4, 6, 9, 10, 4, 0, 9] -> 0.175824
[2, 10, 10, 10, 1, 6, 7, 2, 10, 4, 7] [7, 7, 9, 9, 6, 6, 5, 2, 7, 2, 8] -> 0.363636
</code>```

Rules

You may write a function or a full program. Input may be via STDIN or function argument, and output may be via STDOUT or return value.

You may assume any unambiguous list or string format for the input, as long as it is consistent for both arrays

On the off-chance that your language has a builtin for this, you may not use it.

Answers need to be correct to at least 3 significant figures

This is code-golf, so the program in the fewest bytes wins

答:
R, 65 bytes

```<code>f=function(a,b){d=c(a,b);e=ecdf(a);g=ecdf(b);max(abs(e(d)-g(d)))}
</code>```

This function takes two vectors as arguments and returns the maximum difference of their empirical cumulative distribution functions.

If built-ins were allowed, it would reduce to mere 12 bytes:

```<code>ks.test(a,b)
</code>```

Title: Complexity-free Kolmogorov(-Smirnov)

Body:
R, 65 bytes

f=function(a,b){d=c(a,b);e=ecdf(a);g=ecdf(b);max(abs(e(d)-g(d)))}

This function takes two vectors as arguments and returns the maximum difference of their empirical cumulative distribution functions.

If built-ins were allowed, it would reduce to mere 12 bytes:

ks.test(a,b)


问:
Scale from key and mode
Most of you probably know the C major scale:

```<code>C D E F G A B C
</code>```

The major scale is characterised by the intervals between adjacent notes, which measured in semitones are:

```<code>2 2 1 2 2 2 1
</code>```

From these intervales, we can construct any major scale starting in any note (the key of the scale). The 12 notes in our 12-tone equal temperament tuning system are:

```<code>C C♯ D D♯ E F F♯ G G♯ A A♯ B
</code>```

equivalently (substituting some enharmonic equivalents):

```<code>C D♭ D E♭ E F G♭ G Ab A B♭ B
</code>```

with a semitone between each pair of adjacent notes.

Each scale has to have the seven notes in order, starting from the key. Otherwise, you could have two notes in the same line of the pentagram, which would be confusing. So, in G# major/ionian, you have F## instead of G; musicians will just look at where in the pentagram is the note, they already have learned the accidentals for each scale. Indeed, in G# major, F## is represented in the line of F## without accidentals, the accidentals are in the key signature - but since that key signature would require 2 sharps for F, usually this is notated as Ab major.

Shifting the 2 2 1 2 2 2 1 intervals, we arrive at seven different modes of the diatonic scale:

Ionian: 2 2 1 2 2 2 1 - corresponds to the major scale

Dorian: 2 1 2 2 2 1 2

Phrygian: 1 2 2 2 1 2 2

Lydian: 2 2 2 1 2 2 1

Mixolydian: 2 2 1 2 2 1 2

Aeolian: 2 1 2 2 1 2 2 - corresponds to the natural minor scale, and to the melodic minor scale when descending (when ascending, the melodic minor scale has raised 6th and 7th degrees. There is also a harmonic minor scale, with a raised 7th degree compared to the natural minor).

Locrian: 1 2 2 1 2 2 2

So, the challenge is to write a program that takes as input (via stdin) a key and a mode and outputs (via stdout) the corresponding scale. Some test cases (stdin(key mode) => stdout(scale)):

```<code>Input:              Output:
C mixolydian   =>   C D E F G A Bb
F mixolydian   =>   F G A Bb C D Eb
G mixolydian   =>   G A B C D E F
G# ionian      =>   G# A# B# C# D# E# F##
Bb aeolian     =>   Bb C Db Eb F Gb Ab
</code>```

Further references:

How many (major and minor) keys are there? Why?

答:
GolfScript, 96 characters

```<code>" "/~5<{+}*7%"v]nwm[{"=2*2base(;\(" #"@?]{.1>))["b""""#"..+]=+\[~@(@+@(7%65+\1$7%4%0>-]}7*;]" "*
</code>```

Golfscript solution which can be tested online.

Note: As in the examples the key has to be upper case while mode has to be given in lower case.

Examples:

```<code>>C lydian
C D E F# G A B

>C mixolydian
C D E F G A Bb
</code>```

Title: Scale from key and mode

Body:
GolfScript, 96 characters

" "/~5<{+}*7%"v]nwm[{"=2*2base(;\(" #"@?]{.1>))["b""""#"..+]=+\[~@(@+@(7%65+\1$7%4%0>-]}7*;]" "*

Golfscript solution which can be tested online.

Note: As in the examples the key has to be upper case while mode has to be given in lower case.

Examples:

>C lydian
C D E F# G A B

>C mixolydian
C D E F G A Bb


答:
Java, <s>7,978</s> 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;}
```

<p>Ungolfed:</p>

<pre class="lang-java prettyprint-override"><code>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

}
</code>```

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.

Title: Deciphering XKCD colors

Body:
Java, <s>7,978</s> 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.


问:
Output "Fit" numbers

"Fit Numbers"

Sam has a "brilliant" idea for compression! Can you help?

Here is a rundown of Sam's compression scheme. First take in a base 10 representation of any natural number strictly smaller than 2^16, and write it as a binary string without any leading zeros.

```
1 -> 1
9 -> 1001
15 ->1111
13 ->1101
16 -> 10000
17 -> 10001
65535 -> 111111111111111
```

Now replace any group of one or more zeros with a single zero. This is because the number has gotten leaner. Your binary string now will look like this.

```
1 -> 1 -> 1
9 -> 1001 -> 101
15 ->1111 -> 1111
13 ->1101 -> 1101
16 -> 10000 -> 10
17 -> 10001 -> 101
65535 -> 111111111111111 -> 111111111111111
```

Now you convert the binary string back to a base 10 representation, and output it in any acceptable format. Here are your test cases. The first integer represents an input, and the last integer represents an output. Note that some numbers do not change, and thus can be called "fit"

```
1 -> 1 -> 1 -> 1
9 -> 1001 -> 101 -> 5
15 ->1111 -> 1111 -> 15
13 ->1101 -> 1101 -> 13
16 -> 10000 -> 10 -> 2
17 -> 10001 -> 101 -> 5
65535 -> 1111111111111111 -> 1111111111111111 -> 65535
65000 -> 1111110111101000 -> 11111101111010 -> 16250
```

You may use any language, but please note that Sam hates standard loopholes. This is code golf so the code can be as short as possible to make room for the "compressed" numbers".

Note:This is NOT an acceptable compression scheme. Using this will promptly get you fired.

Citation-Needed: I do not take credit for this concept. This comes from @Conor O' Brien's blog here see this OEIS of fit numbers. https://oeis.org/A090078

答:
Python 2, 36 bytes

f=lambda n:n and f(n/2)<<(n%4>0)|n%2
```

<p>A direct recursive implementation with no base conversion built-ins or string operations. Less golfed:</p>

<pre class="lang-python prettyprint-override"><code>f=lambda n:n and[f(n/2),n%2+2*f(n/2)][n%4>0]
</code>```

When n is a multiple of 4, it ends in two 0's in binary, so we cut one by floor-dividing by 2. Otherwise, we split n into (n%2) + 2*(n/2), leave the last binary digit n%2 alone, and recurse on the other digits n/2.

Title: Output "Fit" numbers

Body:
Python 2, 36 bytes

f=lambda n:n and f(n/2)<<(n%4>0)|n%2

A direct recursive implementation with no base conversion built-ins or string operations. Less golfed:

f=lambda n:n and[f(n/2),n%2+2*f(n/2)][n%4>0]

When n is a multiple of 4, it ends in two 0's in binary, so we cut one by floor-dividing by 2. Otherwise, we split n into (n%2) + 2*(n/2), leave the last binary digit n%2 alone, and recurse on the other digits n/2.


问:
Curiosity killed the cat?
Some people say curiosity killed the cat. Other say it was the box and poison. The RSPCA say Erwin Schrödinger needs to lose the right to own pets.

With animal rights activists outside his house. The <s>cat murderer</s> scientist Schrödinger has finally come up with his greatest invention. A special, radioactive mix of unobtanium and handwavium that can have any half life, and a single gram of the product is capable of killing any living creature. Unfortunately, when he tried to test it on his final cat: Bob, he forgot that cats have 9 lives, and so would need 9 grams to kill. With some water but no food, poor Bob will live exactly 1 week (7 days) if the product doesn't kill him first.

The task:
Given an input of a mass in milligrams and a half-life in milliseconds -  both integers which can exceed 2^31, write a program that outputs whether or not the mystery super product kills the cat, or if it's 1 week time limit expires first. Assume true/yes/1/anything specified in the answer is for when he does not die from starvation.

For the product to kill him, a total of 9 grams must decay. So out of a sample of 18 grams, 1 half-life must pass. If the sample contains less than or equal to 9 grams, this will never be achieved, and so it can be immediately assumed 1 week will pass before 9 grams decays.

You may assume:

Bob dies the microsecond 9 grams has decayed.

The change is mass due to decay does not matter.

All days and times follow generally accepted earth time.

The box Bob is sealed in is unbreakable and unopenable, so there is no chance of death from other causes.

Oxygen is also no issue.

If both happen at the exact same time either output is acceptable.

All inputs should be below 2^63-1

Test cases:

Example:

```<code>18000 604800001
</code>```

For 9 grams to decay, exactly 1 half life must pass (18000/2 = 9000 milligrams or 9 grams). 1 half life is 604800001 milliseconds, or 168 hours and 1 millisecond, or exactly 1 week and 1 millisecond. Since Bob dies of hunger at exactly 1 week, the output is false as he died from hunger just before the 9 gram product limit was reached

```<code>8000 40000 false

70000 800 true

18000 604800000 either

18000 604800001 false

18000 604799999 true

1 1 false

100000 1 true

1000000000 1000000000 true
</code>```

Scoring:
Naturally we want Bob's suffering to end quickly, and so a shorter half-life is best. Half-life and byte both end in E, so clearly the shortest byte count wins.

答:
Python 3, 33 bytes

lambda a,b:a-a*.5**(6048e5/b)>9e3
```

<p>Explanation:</p>

```         6048e5         # number of milliseconds in 1 week
               /b       # half-lifes per week
  a*.5**(        )      # mgs of substance remaining after 1 week
a-                      # mgs of substance decayed after one week
                  >9e3  # return true if more than 9000mgs has decayed in 1 week
```

Try here

Title: Curiosity killed the cat?

Body:
Python 3, 33 bytes

lambda a,b:a-a*.5**(6048e5/b)>9e3

Explanation:

         6048e5         # number of milliseconds in 1 week
               /b       # half-lifes per week
  a*.5**(        )      # mgs of substance remaining after 1 week
a-                      # mgs of substance decayed after one week
                  >9e3  # return true if more than 9000mgs has decayed in 1 week

Try here


答:
Batch, 81 bytes

```<code>@set/an=(700*%2-%1)/%2/70,n*=!(n^>^>31)
@set s=**********
@call echo %%s:~%n%%%
</code>```

Port of my JavaScript answer, except that Batch uses integer arithmetic, so I wrote the formula as (700*a-v)/a/70 which will truncate towards zero, and then the n*=!(n^>^>31) clears n if it is negative.

Body:
Briefing

The difficulty of a Code Golf question can be calculated as such:

$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$

Where \$v\$ is the number of views a question has

and \$a\$ is the number of answers a question has

and \$⌈x⌉\$ is the ceiling operator.

Also:

$$\text{clamp}(x, min, max) = \begin{cases}
min & x < min \\
x   & min \le x \le max \\
max & max < x
\end{cases}$$

This question's current difficulty: ***

Task

Write a program that will take two integers (v and a) and output the difficulty in asterisks (*).

The input can be in the form of an array, a separated string or as separate function arguments

Test Data

```<code>Views   Answers Difficulty  Program Output
163     2       2           **
548     22      1           *
1452    24      1           *
1713    37      1           *
4162    32      2           **
3067    15      3           ***
22421   19      10          **********
</code>```

Example with pseudocode

```<code>v: 1713
a: 37
out = clamp(ceil(((v/a)/700)*10), 0, 10); // evaluates to 1
//program will output '*'
</code>```

The shortest code in bytes wins! Trailing/ leading spaces are allowed.

Body:
Batch, 81 bytes

@set/an=(700*%2-%1)/%2/70,n*=!(n^>^>31)
@set s=**********
@call echo %%s:~%n%%%

Port of my JavaScript answer, except that Batch uses integer arithmetic, so I wrote the formula as (700*a-v)/a/70 which will truncate towards zero, and then the n*=!(n^>^>31) clears n if it is negative.


答:
Fourier, 51 bytes

I have to admit that I don't fully understand this program... Mainly just a translation of TheNumberOne's Python code.

```<code>oI~M~NI~H604800000~G>H{1}{G/H^(M/2~Mi^~i)N-M>9000@o}
</code>```

Note this is the first program that I've written for PPCG which uses @, the clear output function.

Try it online!

Title: Curiosity killed the cat?

Body:
Some people say curiosity killed the cat. Other say it was the box and poison. The RSPCA say Erwin Schrödinger needs to lose the right to own pets.

With animal rights activists outside his house. The <s>cat murderer</s> scientist Schrödinger has finally come up with his greatest invention. A special, radioactive mix of unobtanium and handwavium that can have any half life, and a single gram of the product is capable of killing any living creature. Unfortunately, when he tried to test it on his final cat: Bob, he forgot that cats have 9 lives, and so would need 9 grams to kill. With some water but no food, poor Bob will live exactly 1 week (7 days) if the product doesn't kill him first.

The task:
Given an input of a mass in milligrams and a half-life in milliseconds -  both integers which can exceed 2^31, write a program that outputs whether or not the mystery super product kills the cat, or if it's 1 week time limit expires first. Assume true/yes/1/anything specified in the answer is for when he does not die from starvation.

For the product to kill him, a total of 9 grams must decay. So out of a sample of 18 grams, 1 half-life must pass. If the sample contains less than or equal to 9 grams, this will never be achieved, and so it can be immediately assumed 1 week will pass before 9 grams decays.

You may assume:

Bob dies the microsecond 9 grams has decayed.

The change is mass due to decay does not matter.

All days and times follow generally accepted earth time.

The box Bob is sealed in is unbreakable and unopenable, so there is no chance of death from other causes.

Oxygen is also no issue.

If both happen at the exact same time either output is acceptable.

All inputs should be below 2^63-1

Test cases:

Example:

```<code>18000 604800001
</code>```

For 9 grams to decay, exactly 1 half life must pass (18000/2 = 9000 milligrams or 9 grams). 1 half life is 604800001 milliseconds, or 168 hours and 1 millisecond, or exactly 1 week and 1 millisecond. Since Bob dies of hunger at exactly 1 week, the output is false as he died from hunger just before the 9 gram product limit was reached

```<code>8000 40000 false

70000 800 true

18000 604800000 either

18000 604800001 false

18000 604799999 true

1 1 false

100000 1 true

1000000000 1000000000 true
</code>```

Scoring:
Naturally we want Bob's suffering to end quickly, and so a shorter half-life is best. Half-life and byte both end in E, so clearly the shortest byte count wins.

Body:
Fourier, 51 bytes

I have to admit that I don't fully understand this program... Mainly just a translation of TheNumberOne's Python code.

oI~M~NI~H604800000~G>H{1}{G/H^(M/2~Mi^~i)N-M>9000@o}

Note this is the first program that I've written for PPCG which uses @, the clear output function.

Try it online!


答:
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

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

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

Title: Deciphering XKCD colors

Body:
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.


问:
Smallest positive integer not yet appeared so that the sum of the first n elements is divisible by n

Task

Given positive integer n, output a(n) where a is the sequence defined below:

a(n) is the smallest positive integer not yet appeared so that the sum of the first n elements in the sequence is divisible by n.

Example

a(1) is 1 because it is the smallest positive integer that has not appeared in the sequence, and 1 is divisible by 1.

a(10) is 16 because look at the first nine elements: 1,3,2,6,8,4,11,5,14. They sum up to 54, so for the first ten elements to sum up to a multiple of 10, a(10) would need to have a remainder of 6 when divided by 10. 6 has already appeared, so a(10) is 16 instead.

Testcases

```<code>n     a(n)
1     1
2     3
3     2
4     6
5     8
6     4
7     11
8     5
9     14
10    16
11    7
12    19
13    21
14    9
15    24
16    10
17    27
18    29
19    12
20    32
100   62
1000  1618
10000 16180
</code>```

a(n) from n=1 to n=10000

References

OEIS A019444

答:
Python 3, 102 bytes

Definitely not the shortest solution (not familiar with code golf) but I was bored so here it is in Python. I'm sure you could make it smaller with lambdas/filter.

def a(n,s=[]):
    for j in range(1,n+1):
        i=1
        while i in s or(sum(s)+i)%j:i+=1
        s+=[i]
    return s[-1]
```


答:
Haskell, 35 bytes

This solution is as completely different from Laikonis answer as it gets for something this trivial. Yet the score (for now) is exactly the same.

v%a=take(ceiling$v/a/70)[0..9]>>"*"
```

<p>This produces ten stars, then shaves off some. Easy to extend to arbitrary difficulty with an infinite list.</p>

<p>I did manage to shave off one more byte. But while all test cases work, this shouldn't be correct in general.</p>

<pre class="lang-haskell prettyprint-override"><code>v%a=take(1+div v(a*70))[0..9]>>"*"
</code>```

Body:
Haskell, 35 bytes

This solution is as completely different from Laikonis answer as it gets for something this trivial. Yet the score (for now) is exactly the same.

v%a=take(ceiling$v/a/70)[0..9]>>"*"

This produces ten stars, then shaves off some. Easy to extend to arbitrary difficulty with an infinite list.

I did manage to shave off one more byte. But while all test cases work, this shouldn't be correct in general.

v%a=take(1+div v(a*70))[0..9]>>"*"


问:
Crossword grid verification
Validate a proposed crossword grid.

Entries should be full programs that simply test a proposed grid
to determine if it meets a set of conditions for making crossword
solvers happy.

Input

The input will be the name of a file representing the crossword
grid. The input filename may be passed as an argument, on the
standard input, or by other conventional means other than
hardcoding.

Grid file format: The first line consists of two white-space
separated integer constants M and N. Following that line are M
lines each consisting of N characters (plus a new line) selected
from [#A-Z ]. These characters are interpreted such that '#'
indicates a blocked square, ' ' a open square in the puzzle
with no known contents and any letter an open square whose
containing that letter.

Output

The program should produce no output on valid grids and exit with
normal termination state. If the proposed grid fails, the program
should produce a diagnostic error message and exit with a
abnormal termination state (i.e. not 0 on unix) if this is
supported by your execution environment. The error message should
indicate both which condition for validity is violated and the
location of the offending square; you are free to chose the means
of conveying these facts.

Conditions for validity

Valid grids will have no answers (across or down) that are only 1
character long (extra credit for making the minimum length a
input parameter), and will exhibit the usual symmetry. The usual
symmetry means the crossword remains the same after (three
equivalent descriptions of the same operation):

reflection through it's own center

reflection both vertically and horizontally

180 degree rotation

Test input and expected output

Passes:

```<code>5   5
#  ##
#
  #
    #
##  #
</code>```

Fails on short answer:

```<code>5   5
## ##
#
  #
    #
## ##
</code>```

Fails on symmetry:

```<code>5   5
#  ##
#
  #
#   #
##  #
</code>```

Aside

This is the second of several crossword related challenges. I
plan to use a consistent set of file-formats throughout and to
build up a respectable suite of crossword related utilities in
the process. For instance a subsequent puzzle will call for
printing a ASCII version of the crossword based on the input and
output of this puzzle.

Previous challenges in this series:

Crossword numbering

答:
Reference implementation

c99

```<code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void readgrid(FILE *f, int m, int n, char grid[m][n]){
  int i = 0;
  int j = 0;
  int c = 0;
  while ( (c = fgetc(f)) != EOF) {
    if (c == '\n') {
      if (j != n) fprintf(stderr,"Short input line (%d)\n",i);
      i++;
      j=0;
    } else {
      grid[i][j++] = c;
    }
  }
}

int isSymmetric(int m, int n, char g[m][n]){
  for (int i=0; i<m; ++i)
    for (int j=0; j<n; ++j)
      if ( (g[i][j]=='#') != (g[m-i-1][n-j-1]=='#') )
    return j*m+i;
  return -1;
}

int isLongEnough(int m, int n, char g[m][n], int min){
  /* Check the rows */
  for (int i=0; i<m; ++i) {
    int lo=-(min+1); /* last open square */
    int lb=-1;       /* last blocked square */
    for (int j=0; j<n; ++j) {
      if ( g[i][j] == '#' ) {
    /* blocked square */
    if ( (lo == j-1) && (j-lb <= min+1) ) return lo*m+i;
    lb=j;
      } else {
    /* In-play square */
    lo=j;
      }
    }
  }

  /* Check the columns */
  for (int j=0; j<n; ++j) {
    int lo=-(min+1); /* last open square */
    int lb=-1;       /* last blocked square */
    for (int i=0; i<m; ++i) {
      if ( g[i][j] == '#' ) {
    /* blocked square */
    if ( (lo == i-1) && (i-lb <= min+1) ) return lo*m+i;
    lb=i;
      } else {
    /* In-play square */
    lo=i;
      }
    }
  }

  /* Passed */
  return -1;
}

int main(int argc, char** argv){
  const char *infname;
  FILE *inf=NULL;
  FILE *outf=stdout;
  int min=1;

  /* deal with the command line */
  switch (argc) {
  case 3: /* two or more arguments. Take the second to be the minium
         answer length */
    if ( (min=atoi(argv[2]))<1 ) {
      fprintf(stderr,"%s: Minimum length '%s' too short. Exiting.",
          argv[0],argv[2]);
      return 2;
    }
    /* FALLTHROUGH */
  case 2: /* exactly one argument */
    infname = argv[1];
    if (!(inf = fopen(infname,"r"))) {
      fprintf(stderr,"%s: Couldn't open file '%s'. Exiting.",
          argv[0],argv[1]);
      return 1;
    };
    break;
  default:
    printf("%s: Verify crossword grid.\n\t%s <grid file> [<minimum length>]\n",
       argv[0],argv[0]);
    return 0;
  }

  /* Read the grid size from the first line */
  int m=0,n=0,e=-1;
  char lbuf[81];
  fgets(lbuf,81,inf);
  sscanf(lbuf,"%d %d",&m,&n);

  /* Intialize the grid */
  char grid[m][n];
  for(int i=0; i<m; ++i) {
    for(int j=0; j<n; ++j) {
      grid[i][j]='#';
    }
  }

  readgrid(inf,m,n,grid);

  if ((e=isSymmetric(m,n,grid))>=0) {
    fprintf(stderr,"Symmetry violation at %d,%d.\n",e/m+1,e%m+1);
    return 4;
  } else if ((e=isLongEnough(m,n,grid,min))>=0) {
    fprintf(stderr,"Short answer at %d,%d.\n",e/m+1,e%m+1);
    return 8;
  }
  return 0;
}
</code>```

ContentLicense: CC BY-SA 2.5

Title: Crossword grid verification

Body:
Reference implementation

c99

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void readgrid(FILE *f, int m, int n, char grid[m][n]){
  int i = 0;
  int j = 0;
  int c = 0;
  while ( (c = fgetc(f)) != EOF) {
    if (c == '\n') {
      if (j != n) fprintf(stderr,"Short input line (%d)\n",i);
      i++;
      j=0;
    } else {
      grid[i][j++] = c;
    }
  }
}

int isSymmetric(int m, int n, char g[m][n]){
  for (int i=0; i<m; ++i)
    for (int j=0; j<n; ++j)
      if ( (g[i][j]=='#') != (g[m-i-1][n-j-1]=='#') )
    return j*m+i;
  return -1;
}

int isLongEnough(int m, int n, char g[m][n], int min){
  /* Check the rows */
  for (int i=0; i<m; ++i) {
    int lo=-(min+1); /* last open square */
    int lb=-1;       /* last blocked square */
    for (int j=0; j<n; ++j) {
      if ( g[i][j] == '#' ) {
    /* blocked square */
    if ( (lo == j-1) && (j-lb <= min+1) ) return lo*m+i;
    lb=j;
      } else {
    /* In-play square */
    lo=j;
      }
    }
  }

  /* Check the columns */
  for (int j=0; j<n; ++j) {
    int lo=-(min+1); /* last open square */
    int lb=-1;       /* last blocked square */
    for (int i=0; i<m; ++i) {
      if ( g[i][j] == '#' ) {
    /* blocked square */
    if ( (lo == i-1) && (i-lb <= min+1) ) return lo*m+i;
    lb=i;
      } else {
    /* In-play square */
    lo=i;
      }
    }
  }

  /* Passed */
  return -1;
}

int main(int argc, char** argv){
  const char *infname;
  FILE *inf=NULL;
  FILE *outf=stdout;
  int min=1;

  /* deal with the command line */
  switch (argc) {
  case 3: /* two or more arguments. Take the second to be the minium
         answer length */
    if ( (min=atoi(argv[2]))<1 ) {
      fprintf(stderr,"%s: Minimum length '%s' too short. Exiting.",
          argv[0],argv[2]);
      return 2;
    }
    /* FALLTHROUGH */
  case 2: /* exactly one argument */
    infname = argv[1];
    if (!(inf = fopen(infname,"r"))) {
      fprintf(stderr,"%s: Couldn't open file '%s'. Exiting.",
          argv[0],argv[1]);
      return 1;
    };
    break;
  default:
    printf("%s: Verify crossword grid.\n\t%s <grid file> [<minimum length>]\n",
       argv[0],argv[0]);
    return 0;
  }

  /* Read the grid size from the first line */
  int m=0,n=0,e=-1;
  char lbuf[81];
  fgets(lbuf,81,inf);
  sscanf(lbuf,"%d %d",&m,&n);

  /* Intialize the grid */
  char grid[m][n];
  for(int i=0; i<m; ++i) {
    for(int j=0; j<n; ++j) {
      grid[i][j]='#';
    }
  }

  readgrid(inf,m,n,grid);

  if ((e=isSymmetric(m,n,grid))>=0) {
    fprintf(stderr,"Symmetry violation at %d,%d.\n",e/m+1,e%m+1);
    return 4;
  } else if ((e=isLongEnough(m,n,grid,min))>=0) {
    fprintf(stderr,"Short answer at %d,%d.\n",e/m+1,e%m+1);
    return 8;
  }
  return 0;
}


答:
Python 3, 96 bytes

n=int(input())
a=[]
for L in range(1,n+1):
 t=L-sum(a)%L
 while t in a:t+=L
 a+=[t]
print(a[-1])
```

Ideone it!

Title: Smallest positive integer not yet appeared so that the sum of the first n elements is divisible by n

Body:
Task

Given positive integer n, output a(n) where a is the sequence defined below:

a(n) is the smallest positive integer not yet appeared so that the sum of the first n elements in the sequence is divisible by n.

Example

a(1) is 1 because it is the smallest positive integer that has not appeared in the sequence, and 1 is divisible by 1.

a(10) is 16 because look at the first nine elements: 1,3,2,6,8,4,11,5,14. They sum up to 54, so for the first ten elements to sum up to a multiple of 10, a(10) would need to have a remainder of 6 when divided by 10. 6 has already appeared, so a(10) is 16 instead.

Testcases

```<code>n     a(n)
1     1
2     3
3     2
4     6
5     8
6     4
7     11
8     5
9     14
10    16
11    7
12    19
13    21
14    9
15    24
16    10
17    27
18    29
19    12
20    32
100   62
1000  1618
10000 16180
</code>```

a(n) from n=1 to n=10000

References

OEIS A019444

Body:
Python 3, 96 bytes

n=int(input())
a=[]
for L in range(1,n+1):
 t=L-sum(a)%L
 while t in a:t+=L
 a+=[t]
print(a[-1])

Ideone it!


问:
Compute the polyomino capacity of a rectangle
Write a program or function that takes as input three positive integers x, y, and a and returns or outputs the maximum number of whole a✕1 rectangles that can be packed (axis-aligned) into an x✕y rectangle.  Although the result will always be an integer, the program need not give the result using an integer type; in particular, floating-point outputs are acceptable.  Use of standard loopholes is forbidden.  Answers are scored in bytes including the cost of non-standard compiler flags or other marks.

Sample inputs and outputs:

```<code> x,  y,  a -> result
--------------------
 1,  1,  3 ->      0
 2,  2,  3 ->      0
 1,  6,  4 ->      1
 6,  1,  4 ->      1
 1,  6,  3 ->      2
 6,  1,  3 ->      2
 2,  5,  3 ->      2
 5,  2,  3 ->      2
 3,  3,  3 ->      3
 3,  4,  3 ->      4
 4,  3,  3 ->      4
 4,  4,  3 ->      5
 6,  6,  4 ->      8
 5,  7,  4 ->      8
 7,  5,  4 ->      8
 6,  7,  4 ->     10
 7,  6,  4 ->     10
 5,  8,  3 ->     13
 8,  5,  3 ->     13
12, 12,  8 ->     16
12, 13,  8 ->     18
13, 12,  8 ->     18
 8,  8,  3 ->     21
12, 12,  5 ->     28
13, 13,  5 ->     33
</code>```

In response to a question in the comments, note that some optimal packings may not be obvious at first glance.  For instance, the case x=8, y=8, and a=3 has solutions that look like this:

```<code>||||||||
||||||||
||||||||
---||---
---||---
|| ||---
||------
||------
</code>```

(8 + 2 + 2 = 12 vertical placements and 2 + 3 + 4 = 9 horizontal placements gives 12 + 9 = 21 placements in total.)

答:
Python 2, 53 bytes

lambda p,q,n:p/n*q+q/n*(p%n)-min(0,n-p%n-q%n)*(p>n<q)
```
<p>Adapts the formula given in this paper, which is:</p>
```def f(p,q,n):a=p%n;b=q%n;return(p*q-[a*b,(n-a)*(n-b)][a+b>=n and p>=n and q>=n])/n
```

Body:
Python 2, 53 bytes

lambda p,q,n:p/n*q+q/n*(p%n)-min(0,n-p%n-q%n)*(p>n<q)

Adapts the formula given in this paper, which is:

def f(p,q,n):a=p%n;b=q%n;return(p*q-[a*b,(n-a)*(n-b)][a+b>=n and p>=n and q>=n])/n


答:
Python 2, 43 bytes

r=.5+5**.5/2
lambda n:[n/r+1,n*r][n%r<1]//1
```

Outputs floats. Uses the relation

a(n) = A002251(n-1) + 1

to Wythoff pairs. Takes from the upper or lower Beatty sequence by multiplying or dividing by the golden ratio and converting to an integer.

Body:
Python 2, 43 bytes

r=.5+5**.5/2
lambda n:[n/r+1,n*r][n%r<1]//1

Outputs floats. Uses the relation

a(n) = A002251(n-1) + 1

to Wythoff pairs. Takes from the upper or lower Beatty sequence by multiplying or dividing by the golden ratio and converting to an integer.


问:
Show off your tree analysing toolbox
As a programmer or computer scientist one might encounter quite a lot of trees - of course not the woody growing-in-the-wrong-direction kind, but the nice, pure mathematical kind:

```<code>  *<- root (also a node)
 /|\<- edge
* * *<- inner node
|  / \
* *   *<- leaf (also a node)
  |
  *
</code>```

Naturally over time we all have put together our own small handy toolbox to analyse such trees as we encounter them, right?
Now is the time to show it off!

Task

The toolbox must include the following functions:

size: The number of nodes in the tree.

depth: The number of edges on the longest path from the root to any leaf.

breadth: The number of leaves.

degree: The maximum number of child nodes for any node.

You have to submit a program or function for each of the tools, however they might share subroutines (e.g. parsing) which then have to be submitted only once. Note that those subroutines need to be full programs or functions too.

Input Format

The trees can be given in any reasonable format capturing the structure, e.g. the tree

```<code>  *
 / \
*   *
</code>```

could be represented through parentheses (()()), lists of lists [[],[]], or data structures with a constructor T[T[],T[]].
However not through linearisation [2,0,0] or a format like (size, depth, breath, degree, whatever-else-is-needed-to-make-this-format-unique-for-every-tree).
Generally speaking, your tree format should not contain numbers.

Output Format

A natural number for each of the properties described above.

Scoring

Lowest code in bytes for the 4 functions in every language wins, thus I will not accept an answer.

Feel free to provide additional tree tools like fold, isBinaryTree, preLinearise, postLinearize, or whatever you like. Of course those don't have to be included in the byte count.

Examples

First the tree is given in the sample formats from above, then the results of the functions as (size, depth, breadth, degree).

```<code>()
[]
T[]
(1,0,1,0)

(()())
[[],[]]
T[T[],T[]]
(3,1,2,2)

((())()((())()))
[[[]],[],[[[]],[]]]
T[T[T[]],T[],T[T[T[]],T[]]]
(8,3,4,3)

((()())((())()((())()))(()())(()))
[[[],[]],[[[]],[],[[[]],[]]],[[],[]],[[]]]
T[T[T[],T[]],T[T[T[]],T[],T[T[T[]],T[]]],T[T[],T[]],T[T[]]]
(17,4,9,4)

((((((((()))))))))
[[[[[[[[[]]]]]]]]]
T[T[T[T[T[T[T[T[T[]]]]]]]]]
(9,8,1,1)

(((((((()()))((()()))))((((()()))((()()))))))((((((()()))((()()))))((((()()))((()())))))))
[[[[[[[[],[]]],[[[],[]]]]],[[[[[],[]]],[[[],[]]]]]]],[[[[[[[],[]]],[[[],[]]]]],[[[[[],[]]],[[[],[]]]]]]]]
T[T[T[T[T[T[T[T[],T[]]],T[T[T[],T[]]]]],T[T[T[T[T[],T[]]],T[T[T[],T[]]]]]]],T[T[T[T[T[T[T[],T[]]],T[T[T[],T[]]]]],T[T[T[T[T[],T[]]],T[T[T[],T[]]]]]]]]
(45,7,16,2)
</code>```

答:
Python, 136 bytes

```<code>f=lambda z,c:lambda t:eval(t,{'T':lambda*a:a and eval(z)or c})
s,d,b,g=map(f,['sum(a)+1','max(a)+1','sum(a)','max(len(a),*a)'],[1,0]*2)
</code>```

The input format is the 'T[]' format but with parens instead of brackets and passed as a string. It's the longest submission so far, but I thought the approach is pretty cute.

Title: Show off your tree analysing toolbox

Body:
Python, 136 bytes

f=lambda z,c:lambda t:eval(t,{'T':lambda*a:a and eval(z)or c})
s,d,b,g=map(f,['sum(a)+1','max(a)+1','sum(a)','max(len(a),*a)'],[1,0]*2)

The input format is the 'T[]' format but with parens instead of brackets and passed as a string. It's the longest submission so far, but I thought the approach is pretty cute.


答:
OCaml, 163 bytes

open List
let a x=let rec h m s=let rec n m s c=if fold_left(+)c(s)mod m<>0||mem c s then n m s(c+1)else c in if m=x then hd s else h(m+1)((n(m+1)s 2)::s) in h 1[1]
```

<p>Online interpreter</p>

<h3>Usage</h3>

<pre class="lang-ocaml prettyprint-override"><code>>> open List
>> let a x=let rec h m s=let rec n m s c=if fold_left(+)c(s)mod m<>0||mem c s then n m s(c+1)else c in if m=x then hd s else h(m+1)((n(m+1)s 2)::s)in h 1[1];;
<< val a : int -> int = <fun>
>> a(100);;
<< int = 62
</code>```

where >> is STDIN and << is STDOUT.

Body:
OCaml, 163 bytes

open List
let a x=let rec h m s=let rec n m s c=if fold_left(+)c(s)mod m<>0||mem c s then n m s(c+1)else c in if m=x then hd s else h(m+1)((n(m+1)s 2)::s) in h 1[1]

Online interpreter

Usage

>> open List
>> let a x=let rec h m s=let rec n m s c=if fold_left(+)c(s)mod m<>0||mem c s then n m s(c+1)else c in if m=x then hd s else h(m+1)((n(m+1)s 2)::s)in h 1[1];;
<< val a : int -> int = <fun>
>> a(100);;
<< int = 62

where >> is STDIN and << is STDOUT.