答:
Actually, 18 bytes

```<code>11,`│;a%τ@-+`nk'/j
</code>```

Try it online!

This solution uses Peter's formula and is likewise 0-indexed. Thanks to Leaky Nun for a byte.

Explanation:

```<code>11,`│;a%τ@-+`nk'/j
11                  push 1, 1
  ,`│;a%τ@-+`n      do the following n times (where n is the input):
                      stack: [t s]
    │                 duplicate the entire stack ([t s t s])
     ;                dupe t ([t t s t s])
      a               invert the stack ([s t s t t])
       %              s % t ([s%t s t t])
        τ             multiply by 2 ([2*(s%t) s t t])
         @-           subtract from s ([s-2*(s%t) s t])
           +          add to t ([t+s-2*(s%t) t])
                      in effect, this is s,t = t,s+t-2*(s%t)
              k'/j  push as a list, join with "/"
</code>```

Title: Output the nth rational number according to the Stern-Brocot sequence

Body:
The Stern-Brocot sequence is a Fibonnaci-like sequence which can be constructed as follows:

Initialise the sequence with s(1) = s(2) = 1

Set counter n = 1

Append s(n) + s(n+1) to the sequence

Append s(n+1) to the sequence

Increment n, return to step 3

This is equivalent to:

Amongst other properties, the Stern-Brocot sequence can be used to generate every possible positive rational number. Every rational number will be generated exactly once, and it will always appear in its simplest terms; for example, 1/3 is the 4th rational number in the sequence, but the equivalent numbers 2/6, 3/9 etc won't appear at all.

We can define the nth rational number as r(n) = s(n) / s(n+1), where s(n) is the nth Stern-Brocot number, as described above.

Your challenge is to write a program or function which will output the nth rational number generated using the Stern-Brocot sequence.

The algorithms described above are 1-indexed; if your entry is 0-indexed, please state in your answer

The algorithms described are for illustrative purposes only, the output can be derived in any way you like (other than hard-coding)

Input can be via STDIN, function parameters, or any other reasonable input mechanism

Ouptut can be to STDOUT, console, function return value, or any other reasonable output stream

Output must be as a string in the form a/b, where a and b are the relevant entries in the Stern-Brocot sequence. Evaluating the fraction before output is not permissable. For example, for input 12, output should be 2/5, not 0.4.

Standard loopholes are disallowed

This is code-golf, so shortest answer in bytes will win.

Test cases

The test cases here are 1-indexed.

```<code>n    r(n)
--  ------
1    1/1
2    1/2
3    2/1
4    1/3
5    3/2
6    2/3
7    3/1
8    1/4
9    4/3
10   3/5
11   5/2
12   2/5
13   5/3
14   3/4
15   4/1
16   1/5
17   5/4
18   4/7
19   7/3
20   3/8
50   7/12
100  7/19
1000 11/39
</code>```

OEIS entry: A002487

Excellent Numberphile video discussing the sequence: Infinite Fractions

Body:
Actually, 18 bytes

11,`│;a%τ@-+`nk'/j

Try it online!

This solution uses Peter's formula and is likewise 0-indexed. Thanks to Leaky Nun for a byte.

Explanation:

11,`│;a%τ@-+`nk'/j
11                  push 1, 1
  ,`│;a%τ@-+`n      do the following n times (where n is the input):
                      stack: [t s]
    │                 duplicate the entire stack ([t s t s])
     ;                dupe t ([t t s t s])
      a               invert the stack ([s t s t t])
       %              s % t ([s%t s t t])
        τ             multiply by 2 ([2*(s%t) s t t])
         @-           subtract from s ([s-2*(s%t) s t])
           +          add to t ([t+s-2*(s%t) t])
                      in effect, this is s,t = t,s+t-2*(s%t)
              k'/j  push as a list, join with "/"


问:
Output the nth rational number according to the Stern-Brocot sequence
The Stern-Brocot sequence is a Fibonnaci-like sequence which can be constructed as follows:

Initialise the sequence with s(1) = s(2) = 1

Set counter n = 1

Append s(n) + s(n+1) to the sequence

Append s(n+1) to the sequence

Increment n, return to step 3

This is equivalent to:

Amongst other properties, the Stern-Brocot sequence can be used to generate every possible positive rational number. Every rational number will be generated exactly once, and it will always appear in its simplest terms; for example, 1/3 is the 4th rational number in the sequence, but the equivalent numbers 2/6, 3/9 etc won't appear at all.

We can define the nth rational number as r(n) = s(n) / s(n+1), where s(n) is the nth Stern-Brocot number, as described above.

Your challenge is to write a program or function which will output the nth rational number generated using the Stern-Brocot sequence.

The algorithms described above are 1-indexed; if your entry is 0-indexed, please state in your answer

The algorithms described are for illustrative purposes only, the output can be derived in any way you like (other than hard-coding)

Input can be via STDIN, function parameters, or any other reasonable input mechanism

Ouptut can be to STDOUT, console, function return value, or any other reasonable output stream

Output must be as a string in the form a/b, where a and b are the relevant entries in the Stern-Brocot sequence. Evaluating the fraction before output is not permissable. For example, for input 12, output should be 2/5, not 0.4.

Standard loopholes are disallowed

This is code-golf, so shortest answer in bytes will win.

Test cases

The test cases here are 1-indexed.

```<code>n    r(n)
--  ------
1    1/1
2    1/2
3    2/1
4    1/3
5    3/2
6    2/3
7    3/1
8    1/4
9    4/3
10   3/5
11   5/2
12   2/5
13   5/3
14   3/4
15   4/1
16   1/5
17   5/4
18   4/7
19   7/3
20   3/8
50   7/12
100  7/19
1000 11/39
</code>```

OEIS entry: A002487

Excellent Numberphile video discussing the sequence: Infinite Fractions

答:
Python 2, 59 bytes

s,t=1,1;exec"s,t=t,s+t-2*(s%t);"*input();print'%d/%d'%(s,t)
```

Uses Peter's formula and is similarly 0-indexed.

Try it online

ContentLicense: CC BY-SA 3.0

Body:
Python 2, 59 bytes

s,t=1,1;exec"s,t=t,s+t-2*(s%t);"*input();print'%d/%d'%(s,t)

Uses Peter's formula and is similarly 0-indexed.

Try it online


答:
Ruby, 49 bytes

This is 0-indexed and uses Peter Taylor's formula. Golfing suggestions welcome.

```<code>->n{s=t=1;n.times{s,t=t,s+t-2*(s%t)};"#{s}/#{t}"}
</code>```

Body:
Ruby, 49 bytes

This is 0-indexed and uses Peter Taylor's formula. Golfing suggestions welcome.

->n{s=t=1;n.times{s,t=t,s+t-2*(s%t)};"#{s}/#{t}"}


问:
Repetition of letters
Your task is to take an input, for example:

a,b,4,5

And produce an output, which per this example is aaaabbbbb

a,b,4,5 means: the lowercase character "a" is repeated 4 times, and is then followed by the lowercase character "b" repeated 5 times, making the total number of characters 4+5=9

Another example: the input a,B,5,4, should produce the output aaaaaBBBB, which is: the lowercase letter "a" is repeated 5 times, followed by the uppercase letter "B" repeated 4 times.

Some more examples:

```<code>Input --> Output

a,b,4,6         --> aaaabbbbbb
a,b,c,1,2,3     --> abbccc
a,e,d,f,g,1,2,3,4,5 --> aeedddffffggggg
A,b,4,5         --> AAAAbbbbb
A,b,C,1,2,3     --> AbbCCC
A,B,c,D,1,2,3,4 --> ABBcccDDDD
</code>```

Note how the output must have only the required letters, nothing else, except trailing newlines.

The format of the input should be exactly as you see in the above examples, so your code does not have to support any additional formats/styles of the input.

The output must be displayed in a format exactly as the examples show, this means no commas, spaces, etc, separating the letters. Trailing newlines are okay, if you cannot avoid them.

Standard loopholes are disallowed, and the output is case sensitive.

This is code-golf, so the shortest code in bytes wins!

答:
05AB1E, 11 bytes

```<code>',¡2äøvy`×?
</code>```

Explanation

```<code>',¡             # turn input into a list split at commas
   2ä           # divide that list in 2
       ø        # zip, turning the list into pairs of [letter, number]
        v       # for each pair
         y`×?   # print letter number of times
</code>```

Try it online

Title: Repetition of letters

Body:
05AB1E, 11 bytes

',¡2äøvy`×?

Explanation

',¡             # turn input into a list split at commas
   2ä           # divide that list in 2
       ø        # zip, turning the list into pairs of [letter, number]
        v       # for each pair
         y`×?   # print letter number of times

Try it online


问:
Smallest positive integer which is coprime to the last two predecessors and has not yet appeared; a(1)=1, a(2)=2

Definition

Two integers are coprime if they share no positive common divisors other than 1.

a(1) = 1

a(2) = 2

a(n) is the smallest positive integer which is coprime to the a(n-1) and a(n-2) and has not yet appeared, for integer n >= 3.

Task

Given positive integer n, output/print a(n).

Example

a(11) = 6 because 6 is coprime with the last two predecessors (namely, 11 and 13) and 6 has not appeared before.

Notes

Note that the sequence is not ascending, meaning that an element can be smaller than its predecessor.

Specs

You must use 1-indexed.

Testcases

```<code>n      a(n)
1      1
2      2
3      3
4      5
5      4
6      7
7      9
8      8
9      11
10     13
11     6
12     17
13     19
14     10
15     21
16     23
17     16
18     15
19     29
20     14
100    139
1000   1355
10000  13387
100000 133361
</code>```

Scoring

Since coprime means that the two numbers share only one divisor (1), and 1 is a small number, your code should be as small as possible in terms of byte-count.

References

OEIS A084937

答:
Actually, <s>38</s> <s>37</s> <s>35</s> <s>33</s> <s>31</s> 30 bytes

This is a simple implementation of the function definition. Golfing suggestions welcome. Try it online!

Edit: -3 bytes thanks to Leaky Nun.

```<code>2R#╗,;`1";2±╜tπg@╜í+Y"£╓╖`nD╜E
</code>```

Ungolfing:

```<code>2R#╗    Push [1,2] and store it in register 0
,;      Take input and duplicate
`1      Start function, push 1
  "       Start string
  ;       Duplicate i
  2±╜t    Push (list in register 0)[-2:]
  πg      gcd(i, product of list[-2:])
  @╜í     Rotate the gcd and bring up i, check for i in list (0-based, -1 if not found)
  +Y      Add the gcd and the index, negate (1 if coprime and not found in list, else 0)
  "£      End string, turn into a function
╓       Push first (1) values where f(x) is truthy, starting with f(0)
╖`      Append result to the list in register 0, end function
n       Run function (input) times
D╜E     Return (final list)[n-1]
</code>```

Body:
Actually, <s>38</s> <s>37</s> <s>35</s> <s>33</s> <s>31</s> 30 bytes

This is a simple implementation of the function definition. Golfing suggestions welcome. Try it online!

Edit: -3 bytes thanks to Leaky Nun.

2R#╗,;`1";2±╜tπg@╜í+Y"£╓╖`nD╜E

Ungolfing:

2R#╗    Push [1,2] and store it in register 0
,;      Take input and duplicate
`1      Start function, push 1
  "       Start string
  ;       Duplicate i
  2±╜t    Push (list in register 0)[-2:]
  πg      gcd(i, product of list[-2:])
  @╜í     Rotate the gcd and bring up i, check for i in list (0-based, -1 if not found)
  +Y      Add the gcd and the index, negate (1 if coprime and not found in list, else 0)
  "£      End string, turn into a function
╓       Push first (1) values where f(x) is truthy, starting with f(0)
╖`      Append result to the list in register 0, end function
n       Run function (input) times
D╜E     Return (final list)[n-1]


Body:
J, 29 bytes

([,'/',])&":&([:+/2|]!&i.-)>:

Usage

Large values of n require a suffix of x which denotes the use of extended integers.

   f =: ([,'/',])&":&([:+/2|]!&i.-)>:
   f 1
1/1
   f 10
3/5
   f 50
7/12
   f 100x
7/19
   f 1000x
11/39


问:
The Letter A without A
Your task is to display the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them, doing so in a program and/or snippet. Code that returns (instead of printing) is allowed.

Both the lowercase and uppercase versions of the letter "A" are acceptable (that is, unicode U+0061 or unicode U+0041. Other character encodings that aren't Unicode are allowed, but either way, the resulting output of your code must be the latin letter "A", and not any lookalikes or homoglyphs)

You must not use any of the below characters in your code, regardless of the character encoding that you pick:

"A", whether uppercase or lowercase.

"U", whether lowercase or uppercase.

X, whether uppercase or lowercase.

+

&

#

0

1

4

5

6

7

9

Cheating, loopholes, etc, are not allowed.

Since this is code-golf, the shortest solution, in bytes, that follows all the rules, is the winner.

Validity Checker

This Stack Snippet checks to make sure your code doesn't use the restricted characters. It might not work properly for some character encodings.

var t = prompt("Input your code.");

if (/[AaUuXx+&#0145679]/.test(t)) {
  alert("Contains a disallowed character!");
} else {
  alert("No disallowed characters");
}```
</div>
</div>
</p>

<p><em>This Stack Snippet that makes sure you don't have a disallowed character is also available on JSFiddle.</em></p>

<h3>Leaderboard</h3>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var QUESTION_ID=90349,OVERRIDE_USER=58717;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;</code>```

body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}```
<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> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table></code>```

答:
Pyke, 2 bytes

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

Try it here!

```<code>Gh - alphabet[0]
</code>```

Title: The Letter A without A

Body:
Pyke, 2 bytes

Gh

Try it here!

Gh - alphabet[0]


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

答:
Actually, 17 bytes

This uses xnor's algorithm. Golfing suggestions welcome. Try it online!

```<code>,;;φ(/u(φ*1φ(%<I≈
</code>```

Here's a 31-byte version that uses the function definition, but with the oddity that, at first, the function returns the sequence a(n)-1, so the result needs to be incremented at the end. Try it online!

```<code>[]╗,`1";#╜+;l@Σ%@╜í+uY"£╓╖`n╜Nu
</code>```

Ungolfing:

```<code>First algorithm

,;;                 Take the input, duplicate it twice
          1φ(%<I    If input mod phi less than 1
       (φ*          then input * phi
   φ(/u             else input / phi + 1
                ≈   int() the result

Second algorithm

[]╗    Push a list to register 0 (call this res from now on)
,      Take input
`1     Start function, push 1
  "      Start string
  ;      Duplicate i
  #╜+;   res + list(i), duplicate
  l      len(new list)
  @Σ     sum(new list)
  %      sum % len
  @╜í    Rotate i to top, check if i in res
  +uY    (sum%len) + (i in res) + 1, negate (1 if i fits conditions, else 0)
  "£     End string, turn into a function
╓      Push first (1) values where f(x) is truthy, starting with f(0)
╖`     Append result to the list in register 0, end function
n      Run function (input) times
╜Nu    Return res[-1]+1
</code>```

Body:
Actually, 17 bytes

This uses xnor's algorithm. Golfing suggestions welcome. Try it online!

,;;φ(/u(φ*1φ(%<I≈

Here's a 31-byte version that uses the function definition, but with the oddity that, at first, the function returns the sequence a(n)-1, so the result needs to be incremented at the end. Try it online!

[]╗,`1";#╜+;l@Σ%@╜í+uY"£╓╖`n╜Nu

Ungolfing:

First algorithm

,;;                 Take the input, duplicate it twice
          1φ(%<I    If input mod phi less than 1
       (φ*          then input * phi
   φ(/u             else input / phi + 1
                ≈   int() the result

Second algorithm

[]╗    Push a list to register 0 (call this res from now on)
,      Take input
`1     Start function, push 1
  "      Start string
  ;      Duplicate i
  #╜+;   res + list(i), duplicate
  l      len(new list)
  @Σ     sum(new list)
  %      sum % len
  @╜í    Rotate i to top, check if i in res
  +uY    (sum%len) + (i in res) + 1, negate (1 if i fits conditions, else 0)
  "£     End string, turn into a function
╓      Push first (1) values where f(x) is truthy, starting with f(0)
╖`     Append result to the list in register 0, end function
n      Run function (input) times
╜Nu    Return res[-1]+1


问:
Decompose a number!
Your task is to decompose a number using the format below.

This is similar to base conversion, except that instead of listing the digits in the base, you list the values, such that the list adds up to the input.

If the given base is \$n\$, then each number in the list must be in the form of \$k\times n^m\$, where \$0\le k<n\$ and \$m\$ is unique throughout the list.

Specs

Any reasonable input/output format. Your program/function takes 2 inputs and outputs a list.

Output list can be in any order.

0 can be excluded or included.

Leading 0s are allowed.

Built-ins are allowed.

Testcases

```<code>number base   converted list
input1 input2 output
123456 10     [100000,20000,3000,400,50,6] or [6,50,400,3000,20000,100000]
11     2      [8,2,1] or [0,0,0,0,8,0,2,1]
727    20     [400,320,7]
101    10     [100,1] or [100,0,1]
</code>```

Scoring

This is code-golf. Shortest solution in bytes wins.

答:
Ruby, <s>35</s> 34 bytes

This is a port of xnor's Python answer, but it prints n times so the test case 727 20 prints 7, 320, 400, and 724 0s. Golfing suggestions welcome.

Edit: 1 byte thanks to Jordan.

```<code>->n,b{n.times{|i|p n/b**i%b*b**i}}
</code>```

ContentLicense: CC BY-SA 4.0

Title: Decompose a number!

Body:
Ruby, <s>35</s> 34 bytes

This is a port of xnor's Python answer, but it prints n times so the test case 727 20 prints 7, 320, 400, and 724 0s. Golfing suggestions welcome.

Edit: 1 byte thanks to Jordan.

->n,b{n.times{|i|p n/b**i%b*b**i}}


问:
Number Plate Golf: Recognition
See also: Parsing

Introduction

You're working on a government programming team, who have been programming the speed cameras. However, the group of people who have programmed the speed calculator have taken up too much space, so you have to make the number plate recognition software as small as possible.

Challenge

Given an image of a number plate, return the text on the plate.

Number plates

The following are all of the characters which your program must recognise:

ABCDEFG

H1JKLMN0

PQRSTUVW

XYZ01234

56789

Note

On British number plates, the characters for I (i) and 1 (one) are the same and the characters for O (o) and 0 (zero) are the same. For that reason, always assume characters are the numbers. I.e. the following number plate is 10 (one zero):

Examples

C0D3 GLF

B3T4 DCY

M1NUS 15

YET1CGN

Other rules

Internet access and OCR libraries and functions are disallowed.

The number plates will always look identical to the ones shown above. All number plates will be roughly same size (there will be some inaccuracies due to cropping method).

If you require lossless PNG versions of any number plates, I will supply them to you.

Scoring

The shortest program in bytes wins.

All number plates are screenshots of the search bar at this site

Title: Number Plate Golf: Recognition

Body:
PHP, <s>971</s> 970 bytes

Draws heavily upon Yimin Rong's answer, which can be seriously golfed down, especially the array indices, and put into a Phar with gzip compression.

Download the phar

This is my improved base version at <s>1557</s> 1535 bytes, saved simply under the filename "o":

<?$X=[[99,92,45,45,97,96],[99,99,99,99,99,99],[56,80,84,84,99,85],[41,55,52,64,99,86],[32,50,59,99,87,23],[67,99,74,71,90,77],[92,99,64,64,86,66],[31,41,77,99,87,50],[92,96,62,62,99,90],[64,85,64,64,99,94],''=>[99,99,98,98,96,96],A=>[49,99,95,95,96,48],B=>[68,99,64,55,85,83],C=>[93,99,47,47,58,44],D=>[61,99,52,38,77,85],E=>[99,96,60,60,57,41],F=>[99,84,40,40,37,22],G=>[99,95,46,60,80,62],H=>[99,77,22,22,77,99],1=>[99,99,99,99,99,99],J=>[26,29,24,24,96,99],K=>[99,77,35,58,67,43],L=>[99,77,22,22,22,22],M=>[99,84,49,47,87,99],N=>[99,83,44,44,84,99],P=>[99,83,40,40,53,43],Q=>[93,91,55,57,95,99],R=>[99,84,45,65,86,57],S=>[68,97,78,78,99,74],T=>[25,25,99,99,25,25],U=>[93,84,24,24,83,99],V=>[46,88,82,80,99,48],W=>[84,99,76,73,97,93],X=>[61,99,65,73,94,56],Y=>[41,65,93,99,66,42],Z=>[63,87,99,98,86,62]];echo m(r($argv[1]),$X);function r($u){$a=[];$i=imagecreatefromstring(join('',file($u)));$w=imagesx($i);$h=imagesy($i);$s=[];for(;$x<$w;$x++){$s[$x]=0;for($y=0;$y<$h;$y++){$p=imagecolorsforindex($i,imagecolorat($i,$x,$y));if(3*$p[red]+6*$p[green]+$p[blue]<1280)$s[$x]++;}}$j=0;$k=[];for(;$z<$w;$z++){if($s[$z]>$h/10)for($o=0;$o<6;$o++)$k[]=$s[$z];elseif(count($k)){$a[]=$k;$j++;$k=[];}}$b=[];foreach($a as$v){$t=[];$u=array_chunk($v,~~(count($v)/6));foreach($u as$c)$t[]=array_sum($c)/count($c);$m=99/max($t);$e=[];foreach($t as$x)$e[]=~~($x*$m+.5);$b[]=$e;}return$b;}function m($A,$X){$r='';foreach($A as$a){$s=INF;$c='';foreach($X as$k=>$x){$t=0;for($i=0;$i<6;)$t+=($a[$i]-$x[$i++])**2;if($s>$t){$s=$t;$c=$k;}}$r.=$c;}return$r;}

Improvements:

1st stage

Numeric array indices removed and reordered the array, string indices as implicit constants

2nd stage

Replaced intval with ~~ (saves 8 bytes, two occurences)

for-loop initialization removed where unnecessary

file_get_contents($u) replaced with join('',file($u)) (saves 5 bytes)

and a few others

Unfortunately, all the second stage improvements only translate into 1 byte less gzipped code. :-D

And this code was used to create the Phar:

<?php
$phar = new Phar('o.phar');
$phar->addFile('o');
$phar['o']->compress(Phar::GZ);
$phar->setStub('<?Phar::mapPhar(o.phar);include"phar://o.phar/o";__HALT_COMPILER();');

Test with php ocr.phar http://i.imgur.com/i8jkCJu.png or any other of the test case images.


问:
Reinvent the For loop
For loops are used extensively in many languages, but what would you do if no languages supported them?

Create a way to execute a basic for loop without using any repetition structures (for, foreach, while, do, etc).

The basic for loop that you need to replicate is set up like this

```<code>for(i=0;i<1000;i++)
</code>```

You must be able to replicate this without using repetition structures.  It must also execute code in your language that would be in the body of the loop.  Any form of eval is allowed, though it may not execute the for loop on its own.

You can test your code by having it print i with a space 100 times, add this test case to the end of your answer to verify your code with others.

There are no restrictions on what exactly it has to be, all it needs to do is replicate the for loop.

Winner will be decided based on upvotes at the time that it is chosen.

答:
clang (152)

Tested with Apple clang version 4.0

```<code>bfor(int n,void(^b)(int)){
    __block void(^e)(int,int)=^(int l,int h){
        int m;
        h<l?:(m=(l+h)/2,e(l,m-1),b(m),e(m+1,h));
    };
    e(0,n-1);
}
</code>```

Usage:

```<code>main(){
    bfor(100,^(int i){
        printf("%d ", i);
    });
    puts("");
}
</code>```

The stack depth is log2 of the count due to the binary tree and thus it's unlikely to overflow due to recursion.

ContentLicense: CC BY-SA 2.5

Title: Reinvent the For loop

Body:
clang (152)

Tested with Apple clang version 4.0

bfor(int n,void(^b)(int)){
    __block void(^e)(int,int)=^(int l,int h){
        int m;
        h<l?:(m=(l+h)/2,e(l,m-1),b(m),e(m+1,h));
    };
    e(0,n-1);
}

Usage:

main(){
    bfor(100,^(int i){
        printf("%d ", i);
    });
    puts("");
}

The stack depth is log2 of the count due to the binary tree and thus it's unlikely to overflow due to recursion.


答:
Caker, 24 bytes

```<code>ωΩθΩθθθθθΩθΘ
</code>```

Body must be at least 30 characters; you entered 29.

Title: The Letter A without A

Body:
Your task is to display the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them, doing so in a program and/or snippet. Code that returns (instead of printing) is allowed.

Both the lowercase and uppercase versions of the letter "A" are acceptable (that is, unicode U+0061 or unicode U+0041. Other character encodings that aren't Unicode are allowed, but either way, the resulting output of your code must be the latin letter "A", and not any lookalikes or homoglyphs)

You must not use any of the below characters in your code, regardless of the character encoding that you pick:

"A", whether uppercase or lowercase.

"U", whether lowercase or uppercase.

X, whether uppercase or lowercase.

+

&

#

0

1

4

5

6

7

9

Cheating, loopholes, etc, are not allowed.

Since this is code-golf, the shortest solution, in bytes, that follows all the rules, is the winner.

Validity Checker

This Stack Snippet checks to make sure your code doesn't use the restricted characters. It might not work properly for some character encodings.

var t = prompt("Input your code.");

if (/[AaUuXx+&#0145679]/.test(t)) {
  alert("Contains a disallowed character!");
} else {
  alert("No disallowed characters");
}```
</div>
</div>
</p>

<p><em>This Stack Snippet that makes sure you don't have a disallowed character is also available on JSFiddle.</em></p>

<h3>Leaderboard</h3>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var QUESTION_ID=90349,OVERRIDE_USER=58717;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;</code>```

body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}```
<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> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table></code>```

Body:
Caker, 24 bytes

ωΩθΩθθθθθΩθΘ

Body must be at least 30 characters; you entered 29.


答:
Mathematica, 46 bytes

```<code>DiagonalMatrix@IntegerDigits@##~FromDigits~#2&
</code>```

Explanation:

```

In[1]:= IntegerDigits[123456,10]

Out[1]= {1, 2, 3, 4, 5, 6}

In[2]:= DiagonalMatrix@IntegerDigits[123456,10] // MatrixForm

Out[2]//MatrixForm= 1   0   0   0   0   0

                    0   2   0   0   0   0

                    0   0   3   0   0   0

                    0   0   0   4   0   0

                    0   0   0   0   5   0

                    0   0   0   0   0   6

In[3]:= DiagonalMatrix@IntegerDigits[123456,10]~FromDigits~10

Out[3]= {100000, 20000, 3000, 400, 50, 6}
```

Title: Decompose a number!

Body:
Your task is to decompose a number using the format below.

This is similar to base conversion, except that instead of listing the digits in the base, you list the values, such that the list adds up to the input.

If the given base is \$n\$, then each number in the list must be in the form of \$k\times n^m\$, where \$0\le k<n\$ and \$m\$ is unique throughout the list.

Specs

Any reasonable input/output format. Your program/function takes 2 inputs and outputs a list.

Output list can be in any order.

0 can be excluded or included.

Leading 0s are allowed.

Built-ins are allowed.

Testcases

```<code>number base   converted list
input1 input2 output
123456 10     [100000,20000,3000,400,50,6] or [6,50,400,3000,20000,100000]
11     2      [8,2,1] or [0,0,0,0,8,0,2,1]
727    20     [400,320,7]
101    10     [100,1] or [100,0,1]
</code>```

Scoring

This is code-golf. Shortest solution in bytes wins.

Body:
Mathematica, 46 bytes

DiagonalMatrix@IntegerDigits@##~FromDigits~#2&

Explanation:

In[1]:= IntegerDigits[123456,10]

Out[1]= {1, 2, 3, 4, 5, 6}

In[2]:= DiagonalMatrix@IntegerDigits[123456,10] // MatrixForm

Out[2]//MatrixForm= 1   0   0   0   0   0

                    0   2   0   0   0   0

                    0   0   3   0   0   0

                    0   0   0   4   0   0

                    0   0   0   0   5   0

                    0   0   0   0   0   6

In[3]:= DiagonalMatrix@IntegerDigits[123456,10]~FromDigits~10

Out[3]= {100000, 20000, 3000, 400, 50, 6}


答:
Vim, <s>16 13 11</s> 10 keystrokes

Thanks to H Walters for saving two keys

Thanks to DJMcMayhem for saving another!

```<code>:h%<cr>jvyZZp
</code>```

```<code>:h%<cr> #open help for percent
jvy     #move down one char (to the letter "a"), visual mode the character, yank
ZZ      #exit help for percent
p       #put yanked character
</code>```

Title: The Letter A without A

Body:
Vim, <s>16 13 11</s> 10 keystrokes

Thanks to H Walters for saving two keys

Thanks to DJMcMayhem for saving another!

:h%<cr>jvyZZp

:h%<cr> #open help for percent
jvy     #move down one char (to the letter "a"), visual mode the character, yank
ZZ      #exit help for percent
p       #put yanked character


答:
PHP, 84 bytes

```<code>$b=split(',',$argv[1]);while($i<$n=count($b)/2)echo str_repeat($b[+$i],$b[$n+$i++]);
</code>```

Takes the input string as the first argument as in php script.php a,B,c,3,2,6.

Title: Repetition of letters

Body:
Your task is to take an input, for example:

a,b,4,5

And produce an output, which per this example is aaaabbbbb

a,b,4,5 means: the lowercase character "a" is repeated 4 times, and is then followed by the lowercase character "b" repeated 5 times, making the total number of characters 4+5=9

Another example: the input a,B,5,4, should produce the output aaaaaBBBB, which is: the lowercase letter "a" is repeated 5 times, followed by the uppercase letter "B" repeated 4 times.

Some more examples:

```<code>Input --> Output

a,b,4,6         --> aaaabbbbbb
a,b,c,1,2,3     --> abbccc
a,e,d,f,g,1,2,3,4,5 --> aeedddffffggggg
A,b,4,5         --> AAAAbbbbb
A,b,C,1,2,3     --> AbbCCC
A,B,c,D,1,2,3,4 --> ABBcccDDDD
</code>```

Note how the output must have only the required letters, nothing else, except trailing newlines.

The format of the input should be exactly as you see in the above examples, so your code does not have to support any additional formats/styles of the input.

The output must be displayed in a format exactly as the examples show, this means no commas, spaces, etc, separating the letters. Trailing newlines are okay, if you cannot avoid them.

Standard loopholes are disallowed, and the output is case sensitive.

This is code-golf, so the shortest code in bytes wins!

Body:
PHP, 84 bytes

$b=split(',',$argv[1]);while($i<$n=count($b)/2)echo str_repeat($b[+$i],$b[$n+$i++]);

Takes the input string as the first argument as in php script.php a,B,c,3,2,6.


答:
Mathematica, <s>97</s> 90 bytes

```<code>a@1=1;a@2=2;a@n_:=SelectFirst[Range[2n],GCD[a[n-1]a[n-2],#]<2&&!MemberQ[a/@Range[n-1],#]&]
</code>```

Based on <s>my conjecture that</s> a(n) < 2n for all n.

To get a faster run, add a@n= after the original := so that the function doesn't need to recalculate previous values.

Saved 7 bytes thanks to Sherlock9 (if gcd(a,b)=1 then gcd(ab,m) = gcd(a,m)*gcd(b,m))

Title: Smallest positive integer which is coprime to the last two predecessors and has not yet appeared; a(1)=1, a(2)=2

Body:
Definition

Two integers are coprime if they share no positive common divisors other than 1.

a(1) = 1

a(2) = 2

a(n) is the smallest positive integer which is coprime to the a(n-1) and a(n-2) and has not yet appeared, for integer n >= 3.

Task

Given positive integer n, output/print a(n).

Example

a(11) = 6 because 6 is coprime with the last two predecessors (namely, 11 and 13) and 6 has not appeared before.

Notes

Note that the sequence is not ascending, meaning that an element can be smaller than its predecessor.

Specs

You must use 1-indexed.

Testcases

```<code>n      a(n)
1      1
2      2
3      3
4      5
5      4
6      7
7      9
8      8
9      11
10     13
11     6
12     17
13     19
14     10
15     21
16     23
17     16
18     15
19     29
20     14
100    139
1000   1355
10000  13387
100000 133361
</code>```

Scoring

Since coprime means that the two numbers share only one divisor (1), and 1 is a small number, your code should be as small as possible in terms of byte-count.

References

OEIS A084937

Body:
Mathematica, <s>97</s> 90 bytes

a@1=1;a@2=2;a@n_:=SelectFirst[Range[2n],GCD[a[n-1]a[n-2],#]<2&&!MemberQ[a/@Range[n-1],#]&]

Based on <s>my conjecture that</s> a(n) < 2n for all n.

To get a faster run, add a@n= after the original := so that the function doesn't need to recalculate previous values.

Saved 7 bytes thanks to Sherlock9 (if gcd(a,b)=1 then gcd(ab,m) = gcd(a,m)*gcd(b,m))


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

答:
Python 3, 296 + 3960 = 4256 bytes

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

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

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

The code takes input from stdin and prints the answer.

The code:

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

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

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

How to run:

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

Title: Deciphering XKCD colors

Body:
Python 3, 296 + 3960 = 4256 bytes

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

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

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

The code takes input from stdin and prints the answer.

The code:

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

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

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

How to run:

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


答:
Python 3, 18 17 bytes

print(chr(88-23))
```

<p>Prints the Unicode value 0x41 = 65 - credit SnoringFrog</p>

<p>Previous answers</p>

```print(str(int)[3])
```

<p>Prints index 3 (the fourth character) of the string <code>"<class 'int'>"</code>:</p>

```print(chr(33*3-2))
```

Prints the Unicode value 0x61 = 97

Title: The Letter A without A

Body:
Python 3, 18 17 bytes

print(chr(88-23))

Prints the Unicode value 0x41 = 65 - credit SnoringFrog

Previous answers

print(str(int)[3])

Prints index 3 (the fourth character) of the string "<class 'int'>":

print(chr(33*3-2))

Prints the Unicode value 0x61 = 97


问:
The Great Pyramid of ASCII

Introduction

It's 2600 BC and people are building pyramids now. They already made the basis of the pyramid but don't know how to continue. So, they called you for help.

The rules of making a pyramid is quite simple. For the layer above the previous layer, all you need to do is follow this step-by-step hand guide:

Cut the edges off the previous layer.

Above the / character, there must be a \ character and vice versa. This applies to every character except the edges.

The leftmost character is always a / and the rightmost character is always \.

Let's take an example of a basis for a pyramid:

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

We cut off the edges, leaving:

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

We change the forward slashes with backward slashes and vice versa:

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

The leftmost character is always a / and the rightmost character is always a \, so we change that:

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

We place this layer on the previous layer:

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

We continue until the top is reached (which looks like /\). So, eventually we get:

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

This is what you need to output.

The task

Given the basis of a pyramid (with a length greater than 3), output the full pyramid. You can safely assume that the leftmost character is / and the rightmost character is a \. You can also assume that the length of the basis is always even. The use of trailing spaces is allowed. The use of leading spaces is also allowed, as long as the pyramid stays in place. The use of 1 trailing and 1 leading newlines is allowed.

Test cases

```<code>Input: /\\\
Output:
 /\
/\\\

Input: //\\///\/\
Output:
    /\
   /\\\
  /\///\
 ///\\\/\
//\\///\/\

Input: /////////////\
Output:
      /\
     /\\\
    /////\
   /\\\\\\\
  /////////\
 /\\\\\\\\\\\
/////////////\
</code>```

This is code-golf, so the submission with the least amount of bytes wins!

Title: The Great Pyramid of ASCII

Body:
Retina, <s>59</s> <s>56</s> <s>54</s> 52 bytes

{`^( *)/.(.*)..
$1 /$2\¶$0
T`/\\`Ro`(?<=^ +/).+(?=.)

Try it online!

Sample output

    /\
   /\\\
  /\///\
 ///\\\/\
//\\///\/\


问:
Emulate an Intel 8086 CPU
Note: A couple of answers have arrived. Consider upvoting newer answers too.

Common Lisp from happy5214

C from luser droog

Java from NeatMonster

Javascript from crempp

C from Mike C

C++ from Darius Goad

Postscript from luser droog

C++ from
JoeFish

Javascript from entirelysubjective

C from RichTX

C++ from Dave C

Haskell from J B

Python from j-a

The 8086 is Intel's first x86 microprocessor. Your task is to write an emulator for it. Since this is relatively advanced, I want to limit  it a litte:

Only the following opcodes need to be implemented:

mov, push, pop, xchg

add, adc, sub, sbb, cmp, and, or, xor

inc, dec

call, ret, jmp

jb, jz, jbe, js, jnb, jnz, jnbe, jns

stc, clc

hlt, nop

As a result of this, you only need to calculate the carry, zero and sign flags

Don't implement segments. Assume cs = ds = ss = 0.

No prefixes

No kinds of interrupts or port IO

No string functions

No two-byte opcodes (0F..)

No floating point arithmetic

(obviously) no 32-bit things, sse, mmx, ... whatever has not yet been invented in 1979

You do not have to count cycles or do any timing

Start with ip = 0 and sp = 100h.

Input: Your emulator should take a binary program in any kind of format you like as input (read from file, predefined array, ...) and load it into memory at address 0.

Output:
The video RAM starts at address 8000h, every byte is one (ASCII-)character. Emulate a 80x25 screen to console. Treat zero bytes like spaces.

Example:

```<code>08000   2E 2E 2E 2E 2E 2E 2E 2E 2E 00 00 00 00 00 00 00   ................
08010   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
08020   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
08030   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
08040   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00   ................
08050   48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 21 00 00 00   Hello,.world!...
</code>```

Note: This is very similiar to the real video mode, which is usually at 0xB8000 and has another byte per character for colors.

Winning criteria:

All of the mentioned instructions need to be implemented

I made an uncommented test program (link, nasm source) that should run properly. It outputs

```<code>.........
Hello, world!
0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

################################################################################
##                                                                            ##
##  0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987                          ##
##                                                                            ##
##  0 1 4 9 16 25 36 49 64 81 100 121 144 169 196 225 256 289 324 361 400     ##
##                                                                            ##
##  2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97    ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
##                                                                            ##
################################################################################
</code>```

I am not quite sure if this should be codegolf; it's kind of a hard task, so any submission will win many upvotes anyway. Please comment.

Here are some links to help you on this task:

instruction format, more

opcode table

opcode descriptions

16-bit mod R/M byte decoding

registers, flags register

1979 Manual

This is my first entry to this platform. If there are any mistakes, please point them out; if I missed a detail, simply ask.

答:
C++ 1064 lines

Fantastic project. I did an Intellivision emulator many years ago, so it was great to flex my bit-banging muscles again.

After about a week's work, I could not have been more excited when this happened:

```
.........
╤╤╤╤╤╤╤╤╤╤╤╤╤╤
0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

################################################################################
########################################################################
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    0 1 4 9 ♠a ♣b ♠c    d ♦f ☺h   ` §☺b ,♦d E   f `♠i ↓♣b 8♠e Y h ↑♦b =☺f   `

    2 3 4 5 6 7 8 9  a ☺a ☻a ♥a ♦a ♣a ♠a aa     a  b ☺b ☻b ♥b ♦b ♣b ♠b bb       b
 c ☺c ☻c ♥c ♦c ♣c ♠c cc         c  d ☺d ☻d ♥d ♦d ♣d ♠d dd       d  e ☺e ☻e ♥e ♦e ♣e ♠e
 ee     e  f ☺f ☻f ♥f ♦f ♣f ♠f ff       f  g ☺g ☻g ♥g ♦g ♣g ♠g g        g  h ☺h ☻h ♥
h ♦h ♣h ♠h hh   h  i ☺i ☻i ♥i ♦i ♣i ♠i ii       i   `
```

A little debugging later and...SHAZAM!

Also, I rebuilt the original test program without the 80386 extensions, since I wanted to build my emulator true to the 8086 and not fudge in any extra instructions. Direct link to code here: Zip file.

Ok I'm having too much fun with this. I broke out memory and screen management, and now the screen updates when the screen buffer is written to. I made a video :)

http://www.youtube.com/watch?v=qnAssaTpmnA

Updates: First pass of segmenting is in. Very few instructions are actually implemented, but I tested it by moving the CS/DS and SS around, and everything still runs fine.

Also added rudimentary interrupt handling. Very rudimentary. But I did implement int 21h to print a string. Added a few lines to the test source and uploaded that as well.

```<code>start:
    sti
    mov ah, 9
    mov dx, joetext
    int 21h
...

joetext:
    db 'This was printed by int 21h$', 0
</code>```

If anyone has some fairly simple assembly code that would test the segments out, I'd love to play with it.

I'm trying to figure out how far I want to take this. Full CPU emulation? VGA mode? Now I'm writing DOSBox.

12/6: Check it out, VGA mode!

Title: Emulate an Intel 8086 CPU

Body:
C++ 1064 lines

Fantastic project. I did an Intellivision emulator many years ago, so it was great to flex my bit-banging muscles again.

After about a week's work, I could not have been more excited when this happened:

.........
╤╤╤╤╤╤╤╤╤╤╤╤╤╤
0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

################################################################################
########################################################################
    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    0 1 4 9 ♠a ♣b ♠c    d ♦f ☺h   ` §☺b ,♦d E   f `♠i ↓♣b 8♠e Y h ↑♦b =☺f   `

    2 3 4 5 6 7 8 9  a ☺a ☻a ♥a ♦a ♣a ♠a aa     a  b ☺b ☻b ♥b ♦b ♣b ♠b bb       b
 c ☺c ☻c ♥c ♦c ♣c ♠c cc         c  d ☺d ☻d ♥d ♦d ♣d ♠d dd       d  e ☺e ☻e ♥e ♦e ♣e ♠e
 ee     e  f ☺f ☻f ♥f ♦f ♣f ♠f ff       f  g ☺g ☻g ♥g ♦g ♣g ♠g g        g  h ☺h ☻h ♥
h ♦h ♣h ♠h hh   h  i ☺i ☻i ♥i ♦i ♣i ♠i ii       i   `

A little debugging later and...SHAZAM!

Also, I rebuilt the original test program without the 80386 extensions, since I wanted to build my emulator true to the 8086 and not fudge in any extra instructions. Direct link to code here: Zip file.

Ok I'm having too much fun with this. I broke out memory and screen management, and now the screen updates when the screen buffer is written to. I made a video :)

http://www.youtube.com/watch?v=qnAssaTpmnA

Updates: First pass of segmenting is in. Very few instructions are actually implemented, but I tested it by moving the CS/DS and SS around, and everything still runs fine.

Also added rudimentary interrupt handling. Very rudimentary. But I did implement int 21h to print a string. Added a few lines to the test source and uploaded that as well.

start:
    sti
    mov ah, 9
    mov dx, joetext
    int 21h
...

joetext:
    db 'This was printed by int 21h$', 0

If anyone has some fairly simple assembly code that would test the segments out, I'd love to play with it.

I'm trying to figure out how far I want to take this. Full CPU emulation? VGA mode? Now I'm writing DOSBox.

12/6: Check it out, VGA mode!


答:
Pyth - <s>27</s> 26 bytes

Reduces by the operation given in the OP until it repeats, which is the case for the blank line.

```<code>j_.e+*kdb.ujXtPtPNK"\/")_K
</code>```

Test Suite.

Title: The Great Pyramid of ASCII

Body:
Introduction

It's 2600 BC and people are building pyramids now. They already made the basis of the pyramid but don't know how to continue. So, they called you for help.

The rules of making a pyramid is quite simple. For the layer above the previous layer, all you need to do is follow this step-by-step hand guide:

Cut the edges off the previous layer.

Above the / character, there must be a \ character and vice versa. This applies to every character except the edges.

The leftmost character is always a / and the rightmost character is always \.

Let's take an example of a basis for a pyramid:

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

We cut off the edges, leaving:

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

We change the forward slashes with backward slashes and vice versa:

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

The leftmost character is always a / and the rightmost character is always a \, so we change that:

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

We place this layer on the previous layer:

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

We continue until the top is reached (which looks like /\). So, eventually we get:

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

This is what you need to output.

The task

Given the basis of a pyramid (with a length greater than 3), output the full pyramid. You can safely assume that the leftmost character is / and the rightmost character is a \. You can also assume that the length of the basis is always even. The use of trailing spaces is allowed. The use of leading spaces is also allowed, as long as the pyramid stays in place. The use of 1 trailing and 1 leading newlines is allowed.

Test cases

```<code>Input: /\\\
Output:
 /\
/\\\

Input: //\\///\/\
Output:
    /\
   /\\\
  /\///\
 ///\\\/\
//\\///\/\

Input: /////////////\
Output:
      /\
     /\\\
    /////\
   /\\\\\\\
  /////////\
 /\\\\\\\\\\\
/////////////\
</code>```

This is code-golf, so the submission with the least amount of bytes wins!

Body:
Pyth - <s>27</s> 26 bytes

Reduces by the operation given in the OP until it repeats, which is the case for the blank line.

j_.e+*kdb.ujXtPtPNK"\/")_K

Test Suite.


答:
Python 2, 66 bytes

```<code>i=input();l=len(i)/2
print''.join(s*y for s,y in zip(i[:l],i[l:]))
</code>```

Uses every Python golfer's favourite function, zip(). Takes input with letters in quotes e.g.:

```<code>'a','b',4,6
</code>```

Ideone it!

Title: Repetition of letters

Body:
Python 2, 66 bytes

i=input();l=len(i)/2
print''.join(s*y for s,y in zip(i[:l],i[l:]))

Uses every Python golfer's favourite function, zip(). Takes input with letters in quotes e.g.:

'a','b',4,6

Ideone it!


问:
Score Tarzan's Olympic Vine-Swinging Routine
Olympic vine-swingers perform their routines in standard trees.  In particular, Standard Tree n has vertices for 0 up through n-1 and edges linking each nonzero vertex a to the vertex n % a below it.  So, for example, Standard Tree 5 looks like this:

```<code>3
|
2   4
 \ /
  1
  |
  0
</code>```

because the remainder when 5 is divided by 3 is 2, the remainder when 5 is divided by 2 or by 4 is 1, and the remainder when 5 is divided by 1 is 0.

This year, Tarzan will be defending his gold with new routines, each of which begins at vertex n - 1, swings to vertex n - 2, continues to vertex n - 3, etc., until finally he dismounts to vertex 0.

The score for a routine is the sum of the scores for each swing (including the dismount), and the score for a swing is the distance within the tree between its start and end points.  Thus, Tarzan's routine on Standard Tree 5 has a score of 6:

a swing from 4 to 3 scores three points (down, up, up),

a swing from 3 to 2 scores one point (down),

a swing from 2 to 1 scores one point (down), and

a dismount from 1 to 0 scores one point (down).

Write a program or function that, given a positive integer n, computes the score of Tarzan's routine on Standard Tree n.  Sample inputs and outputs:

```<code> 1 ->  0
 2 ->  1
 3 ->  2
 4 ->  6
 5 ->  6
 6 -> 12
 7 -> 12
 8 -> 18
 9 -> 22
10 -> 32
11 -> 24
12 -> 34
13 -> 34
14 -> 36
15 -> 44
16 -> 58
17 -> 50
18 -> 64
19 -> 60
20 -> 66
21 -> 78
22 -> 88
23 -> 68
24 -> 82
</code>```

Rules and code scoring are as usual for code-golf.

答:
Python 2, 85 bytes

def f(a,i=1):h=lambda n:n and{n}|h(a%n)or{0};return iand len(h(i)^h(i-1))+f(a,i+1)
```

Body:
Python 2, 85 bytes

def f(a,i=1):h=lambda n:n and{n}|h(a%n)or{0};return i<a and len(h(i)^h(i-1))+f(a,i+1)


答:
Mathematica, 12 bytes

I wonder whether Wolfram Research created this function after seeing the OP's challenge!

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

This was introduced in version 11.0 (August, 2016).

Title: Decompose a number!

Body:
Mathematica, 12 bytes

I wonder whether Wolfram Research created this function after seeing the OP's challenge!

NumberExpand

This was introduced in version 11.0 (August, 2016).


问:
Can you outgolf me? (Cops section)

Cops section

The robbers section can be found here.

Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.

Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given n (using STDIN/function arguments/etc.), compute a(n) where a is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the longer program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform 2 × n, this could be a valid submission (in Python 2):

Python 2, 16 bytes, score = 15 / 16 = 0.9375

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

Python 2, 16 bytes, score = 15 / 16 = 0.9375, [cracked] + link

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

Offset

This can be found on every OEIS page. For example, for A005843, the offset is 0,2. We only need to use the first one, which is 0. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with n = 0. Your program needs to work for all cases given by OEIS.

More information can be found here.

Scoring

The score you get for your submission is equal to the following formula:

Score = Length (in bytes) of secret code ÷ Length (in bytes) of public code

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the lowest score wins. Only submissions that have posted their solution will be eligible for winning.

Rules

The task you need to do is an OEIS sequence of your choice.

Given n, output OEIS(n). Deviation is not allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).

Submissions that are not cracked within a period of 7 days are considered safe after the solution has been posted (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).

In your submission, you need to post the following things: language name, byte count, full code, so no pastebin links etc. (to prevent answers like Unary), OEIS sequence, score with lengths of both programs and additionally, the encoding that is used.

Note: the same sequence cannot be posted twice in the same language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)

Input and output are both in decimal (base 10)

Leaderboard

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea">

Uncracked submissions

 Language	 Score	 User

Sort by: score creation

Safe submissions

 Language	 Score	 User

```

Note

This challenge is finished. The final winner is feersum with his Seed answer. Congratulations! :).

You can still submit new cops, but be aware that they are no longer competing.

答:
M, 18 bytes, score 0.3889 (7 / 18) [cracked]

```<code>r0+c
‘Ḥc0r$×Ç:‘+\S
</code>```

This approach is based on @Sp3000's golf of my Jelly answer.

The code calculates sequence A116881 (row sums of CM(1,2)). Try it online!

Title: Can you outgolf me? (Cops section)

Body:
M, 18 bytes, score 0.3889 (7 / 18) [cracked]

r0+c
‘Ḥc0r$×Ç:‘+\S

This approach is based on @Sp3000's golf of my Jelly answer.

The code calculates sequence A116881 (row sums of CM(1,2)). Try it online!


答:
C#, 77 bytes

```<code>IEnumerable _(int n,int b){int m=1;while(n>0){yield return n%b*m;n/=b;m*=b;}}
</code>```

Title: Decompose a number!

Body:
Your task is to decompose a number using the format below.

This is similar to base conversion, except that instead of listing the digits in the base, you list the values, such that the list adds up to the input.

If the given base is \$n\$, then each number in the list must be in the form of \$k\times n^m\$, where \$0\le k<n\$ and \$m\$ is unique throughout the list.

Specs

Any reasonable input/output format. Your program/function takes 2 inputs and outputs a list.

Output list can be in any order.

0 can be excluded or included.

Leading 0s are allowed.

Built-ins are allowed.

Testcases

```<code>number base   converted list
input1 input2 output
123456 10     [100000,20000,3000,400,50,6] or [6,50,400,3000,20000,100000]
11     2      [8,2,1] or [0,0,0,0,8,0,2,1]
727    20     [400,320,7]
101    10     [100,1] or [100,0,1]
</code>```

Scoring

This is code-golf. Shortest solution in bytes wins.

Body:
C#, 77 bytes

IEnumerable _(int n,int b){int m=1;while(n>0){yield return n%b*m;n/=b;m*=b;}}


答:
Python 3, 108 104 101 94 91 89 88 bytes

b,f='\/';p=lambda t,n='\n':(t[2:]and p(f+''.join(map({f:b,b:f}.get,t[2:-2]))+b,n+' '))+n+t
```

-7 bytes thanks to xnor (letting me know we don't have to print!)

-3 bytes thanks to xnor (taking declaration outside of function declaration [d'oh])

-1 byte thanks to Dennis (replace f,b='/\\' with b,f='\/')

Test it on ideone. Note: input adjusted for double backslash (even raw strings won't work if they end in an odd number of backslashes).

Title: The Great Pyramid of ASCII

Body:
Python 3, 108 104 101 94 91 89 88 bytes

b,f='\/';p=lambda t,n='\n':(t[2:]and p(f+''.join(map({f:b,b:f}.get,t[2:-2]))+b,n+' '))+n+t

-7 bytes thanks to xnor (letting me know we don't have to print!)

-3 bytes thanks to xnor (taking declaration outside of function declaration [d'oh])

-1 byte thanks to Dennis (replace f,b='/\\' with b,f='\/')

Test it on ideone. Note: input adjusted for double backslash (even raw strings won't work if they end in an odd number of backslashes).


答:
Acc!!, 526 bytes, score = 0.5627 (296/526) (cracked)

```<code>N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60
Count i while _/27^i {
_+27^i*(_/27^i*26-18)
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3^(1+i%2)
Count k while _/3^(3*k+1+i%2)%3-1 {
_+3^(3*k+1+i%2)*26
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_+_/100^i*100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}
</code>```

Computes A000204, Lucas numbers with offset 1.

A couple of notes. Due to Acc!!'s input limitations, the program takes input as a decimal number terminated with a period (.); for example:

```<code>> python acc.py Program.txt
5.
11
</code>```

This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 14 (takes 60 seconds on my laptop). However, given enough time, the algorithm will return the correct result for any positive integer n. Thus: a crack attempt that places any size limits on the input value is invalid.

Have fun!

Title: Can you outgolf me? (Cops section)

Body:
Cops section

The robbers section can be found here.

Thanks to FryAmTheEggman, Peter Taylor, Nathan Merrill, xnor, Dennis, Laikoni and Mego for their contributions.

Challenge

Your task is to write 2 different programs (full programs/functions/etc.) in the same language and the same version (e.g. Python 3.5 ≠ Python 3.4, so that is not allowed), and when given n (using STDIN/function arguments/etc.), compute a(n) where a is an OEIS sequence of your choice. One of those programs is shorter than the other. You only need to submit the longer program of the two. The other one needs to be saved in case of not being cracked after 7 days. Your submission is cracked when your program has been outgolfed (whether it is by 1 byte or more).

For example, if the task you chose was to perform 2 × n, this could be a valid submission (in Python 2):

Python 2, 16 bytes, score = 15 / 16 = 0.9375

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

If your submission has been cracked, then you need to state that in your header like so:

Python 2, 16 bytes, score = 15 / 16 = 0.9375, [cracked] + link

```<code>print(2*input())
</code>```

Computes A005843, (offset = 0).

Offset

This can be found on every OEIS page. For example, for A005843, the offset is 0,2. We only need to use the first one, which is 0. This means that the function is defined for all numbers ≥ 0.

In other words, the function OEIS(n) starts with n = 0. Your program needs to work for all cases given by OEIS.

More information can be found here.

Scoring

The score you get for your submission is equal to the following formula:

Score = Length (in bytes) of secret code ÷ Length (in bytes) of public code

The example above has the score 15 ÷ 16 = 0.9375.

The submission with the lowest score wins. Only submissions that have posted their solution will be eligible for winning.

Rules

The task you need to do is an OEIS sequence of your choice.

Given n, output OEIS(n). Deviation is not allowed, so you need to produce the exact same sequence (when given n, you need to output OEIS(n)).

Submissions that are not cracked within a period of 7 days are considered safe after the solution has been posted (submissions older than 7 days that do not have their solution posted are still vulnerable in being cracked).

In your submission, you need to post the following things: language name, byte count, full code, so no pastebin links etc. (to prevent answers like Unary), OEIS sequence, score with lengths of both programs and additionally, the encoding that is used.

Note: the same sequence cannot be posted twice in the same language. (For example, if the sequence A005843 has been done in Pyth, you cannot use Pyth again for that same sequence.)

Input and output are both in decimal (base 10)

Leaderboard

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/Sites/codegolf/all.css?v=7509797c03ea">

Uncracked submissions

 Language	 Score	 User

Sort by: score creation

Safe submissions

 Language	 Score	 User

```

Note

This challenge is finished. The final winner is feersum with his Seed answer. Congratulations! :).

You can still submit new cops, but be aware that they are no longer competing.

Body:
Acc!!, 526 bytes, score = 0.5627 (296/526) (cracked)

N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60
Count i while _/27^i {
_+27^i*(_/27^i*26-18)
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3^(1+i%2)
Count k while _/3^(3*k+1+i%2)%3-1 {
_+3^(3*k+1+i%2)*26
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_+_/100^i*100^i*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}

Computes A000204, Lucas numbers with offset 1.

A couple of notes. Due to Acc!!'s input limitations, the program takes input as a decimal number terminated with a period (.); for example:

> python acc.py Program.txt
5.
11

This program has exponential time complexity, so I wouldn't recommend running it with input greater than about 14 (takes 60 seconds on my laptop). However, given enough time, the algorithm will return the correct result for any positive integer n. Thus: a crack attempt that places any size limits on the input value is invalid.

Have fun!


答:
Ruby, 20 Bytes

```<code>print ("c".ord-2).chr
</code>```

Subtracts 2 from the unicode-code from "c".

Title: The Letter A without A

Body:
Your task is to display the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them, doing so in a program and/or snippet. Code that returns (instead of printing) is allowed.

Both the lowercase and uppercase versions of the letter "A" are acceptable (that is, unicode U+0061 or unicode U+0041. Other character encodings that aren't Unicode are allowed, but either way, the resulting output of your code must be the latin letter "A", and not any lookalikes or homoglyphs)

You must not use any of the below characters in your code, regardless of the character encoding that you pick:

"A", whether uppercase or lowercase.

"U", whether lowercase or uppercase.

X, whether uppercase or lowercase.

+

&

#

0

1

4

5

6

7

9

Cheating, loopholes, etc, are not allowed.

Since this is code-golf, the shortest solution, in bytes, that follows all the rules, is the winner.

Validity Checker

This Stack Snippet checks to make sure your code doesn't use the restricted characters. It might not work properly for some character encodings.

var t = prompt("Input your code.");

if (/[AaUuXx+&#0145679]/.test(t)) {
  alert("Contains a disallowed character!");
} else {
  alert("No disallowed characters");
}```
</div>
</div>
</p>

<p><em>This Stack Snippet that makes sure you don't have a disallowed character is also available on JSFiddle.</em></p>

<h3>Leaderboard</h3>

<p><div class="snippet" data-lang="js" data-hide="true" data-console="false" data-babel="false">
<div class="snippet-code snippet-currently-hidden">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var QUESTION_ID=90349,OVERRIDE_USER=58717;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;</code>```

body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}```
<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> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>Link</td></tr></tbody> </table></code>```

Body:
Ruby, 20 Bytes

print ("c".ord-2).chr

Subtracts 2 from the unicode-code from "c".


问:
Can you outgolf me? (Robbers section)

Robbers section

The cops section can be found here.

Challenge

Your task is to outgolf the submissions of the cops in the same language and the same version (for example, Python 3.5 ≠ Python 3.4, so that is not allowed). A submission is outgolfed when the length in bytes is shorter than the original submission. You only need to golf off at least 1 byte in order to crack a submission. E.g. if the task was to perform 2 × n, and the submission was the following:

```<code>print(2*input())
</code>```

You could outgolf the cop by doing the following:

```<code>print 2*input()
</code>```

Or even this (since lambda's are allowed):

```<code>lambda x:2*x
</code>```

Post this with the following header:

```<code>##{language name}, <s>{prev byte count}</s> {byte count}, {cop's submission + link}
</code>```

For example:

Python 2, <s>16</s> 12 bytes, Adnan (+ link to submission)

```<code>lambda x:2*x
</code>```

Computes A005843, (offset = 0).

In that case, you have cracked the submission.

Scoring

The person with who cracked the most submissions is the winner.

Rules

The crack submission must be in the same language as the cop submission.

The same input should result into the same output (so a(2) = 4 should remain 4).

For languages such as Python, you can import libraries that are standard included within the language. (So, no numpy/sympy etc.)

Input and output are both in decimal (base 10).

Note

This challenge is finished. The winner of the Robbers section is feersum. The final scores for the CnR are shown below:

feersum: 16 cracks

Dennis: 12 cracks

Leaky Nun: 6 cracks

Lynn: 4 cracks

miles: 3 cracks

Martin Ender: 2 cracks

Emigna: 2 cracks

jimmy23013: 1 crack

Sp3000: 1 crack

randomra: 1 crack

alephalpha: 1 crack

nimi: 1 crack

Destructible Watermelon: 1 crack

Dom Hastings: 1 crack

Title: Can you outgolf me? (Robbers section)

Body:
Acc!!, <s>526</s> 525 bytes, DLosc

N
Count x while _%60-46 {
(_+_%60*5-288)*10+N
}
_/60
Count i while _/27^i {
_+27^i*(_/27^i*26-18)
}
_*3+93
Count i while _/27^i/27%3 {
_-i%2*2+1
Count j while _/3^(3*j+2-i%2)%3 {
_+3^(1+i%2)
Count k while _/3^(3*k+1+i%2)%3-1 {
_+3^(3*k+1+i%2)*26
}
}
}
Count i while _/27^i/3 {
_-_/27^i/3%27*27^i*3+_/3^(3*i+1+_%3)%3*3
}
_/3
Count i while _/100^i {
_*10-(_%100^i)*9
}
Count i while _/100^i/10 {
_+_/100^i/10%10
Count j while i+1-j {
_+(_%10-_/100^(j+1)%10)*(100^(j+1)-1)
}
}
_/100
Count j while _/100^j {
Write _/100^j%10+48
}

I have no idea how this works, but I was able to spot a tiny improvement.

24c24
< _+_/100^i*100^i*9
---
> _*10-(_%100^i)*9