问:
Convert number to comma separated number
Given a number, say, -2982342342363.23425785 convert it to -2,982,342,342,363.23425785.

Extra points for not using look-behind

Extra points for not using regular expressions.

答:
C 89/90/ANSI

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

int main(int i, char* a[]) {

    char * p;

    p    = strtok(a[1], ".");    /* Get argument value; up to decimal point. */
    a[1] = strtok(0,    ".");    /* Overwrite original value with fractional part. */

    /* If the first char is a negative sign then print it and advance the string pointer: */
    if(*p == '-') printf("%c", *p++);

    /* Get remainder of integer part divided by 3 and load it into a digit-group iterator: */
    i = strlen(p) % 3;

    if(i == 0) i = 3;    /* If iterator is empty then fill it. */

    while(1) {
        /* Nested loop through 3-digit group; printing each char: */
        while(i-- > 0) printf("%c", *p++);

        /* If string pointer is at null (end of string) char then exit loop: */
        if(*p == 0) break;
        else printf(",");    /* Otherwise print a comma */

        i = 3;    /* and reload the digit-group iterator. */
    }

    /* If there is a fractional part then print it after a decimal point: */
    if(a[1] != 0) printf(".%s", a[1]);

    return 0;
}
</code>```

Body:
C 89/90/ANSI

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

int main(int i, char* a[]) {

    char * p;

    p    = strtok(a[1], ".");    /* Get argument value; up to decimal point. */
    a[1] = strtok(0,    ".");    /* Overwrite original value with fractional part. */

    /* If the first char is a negative sign then print it and advance the string pointer: */
    if(*p == '-') printf("%c", *p++);

    /* Get remainder of integer part divided by 3 and load it into a digit-group iterator: */
    i = strlen(p) % 3;

    if(i == 0) i = 3;    /* If iterator is empty then fill it. */

    while(1) {
        /* Nested loop through 3-digit group; printing each char: */
        while(i-- > 0) printf("%c", *p++);

        /* If string pointer is at null (end of string) char then exit loop: */
        if(*p == 0) break;
        else printf(",");    /* Otherwise print a comma */

        i = 3;    /* and reload the digit-group iterator. */
    }

    /* If there is a fractional part then print it after a decimal point: */
    if(a[1] != 0) printf(".%s", a[1]);

    return 0;
}


问:
hackertyper.net

Introduction

hackertyper.net is a website that simulates "hacking" (as the media portrays it) by outputting complicated code from the crypto section of the Linux kernel onto the screen as you type at a rate of 3 characters per one inputted.

Challenge

Your program/function should either accept a file as a command-line argument, have the file path hard-coded, or accept the text [that would be in the file] as a command-line or function argument, and mimic hackertyper.net by outputting 3 characters onto the screen (STDOUT or equivalent) from the file for each one received through STDIN or equivalent.

Once EOF is reached, the program should start outputting characters from the beginning of the file again (wrap).

Specs

For the purposes of simplicity, you can assume that STDIN has already been set to no buffer and no echo mode, that is not waiting until the user presses enter before passing input to your program and not displaying the characters you type.

The file can contain newlines, while the input will not contain newlines.

For a small example written in C (not golfed) that demonstrates how this works, see this.

Green text and a black background are not required.

Example input and output

The file:

```<code>#include <stdio.h>
int main() { }

</code>```

Input:

```<code>hello world
</code>```

Output:

```<code>#include <stdio.h>
int main() { }
</code>```

The file:

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

Input:

```<code>hello world
</code>```

Output:

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

答:
Python 3.5, 77 65 63 bytes:

```<code>lambda g,f:''.join((g*len(f))[i:i+3]for i in range(0,len(f)*3,3))
</code>```

Simple enough. An anonymous function which takes in two arguments, the first one being the "file" (g), and the second being the characters typed in by the user (f). Then this creates a generator containing every three characters in g, which are found by indexing for every i and then i+3 characters in g, where i is in the range of 0=>(length of f)*3. Finally, it returns each object in the generator joined into one big string. You call this function by assigning a variable to it, and then calling the variable wrapped inside a print() expression. So if the function's name was q, it would be executed like print(q(<byte array here>)).

Try it online! (repl.it)

ContentLicense: CC BY-SA 3.0

Title: hackertyper.net

Body:
Python 3.5, 77 65 63 bytes:

lambda g,f:''.join((g*len(f))[i:i+3]for i in range(0,len(f)*3,3))

Simple enough. An anonymous function which takes in two arguments, the first one being the "file" (g), and the second being the characters typed in by the user (f). Then this creates a generator containing every three characters in g, which are found by indexing for every i and then i+3 characters in g, where i is in the range of 0=>(length of f)*3. Finally, it returns each object in the generator joined into one big string. You call this function by assigning a variable to it, and then calling the variable wrapped inside a print() expression. So if the function's name was q, it would be executed like print(q(<byte array here>)).

Try it online! (repl.it)


答:
J, 7 bytes

```<code>$~(3*#)
</code>```

Takes two arguments, the text to be repeated and the user's input text.

Usage

The input text is formatted where , means to join and LF is the newline character.

```<code>   f =: $~(3*#)
   ('#include <stdio.h>', LF, 'int main() { }') f 'hello world'
#include <stdio.h>
int main() { }
   'hello' f 'hello world'
hellohellohellohellohellohellohel
</code>```

Try it online. (tryj.tk)

Title: hackertyper.net

Body:
Introduction

hackertyper.net is a website that simulates "hacking" (as the media portrays it) by outputting complicated code from the crypto section of the Linux kernel onto the screen as you type at a rate of 3 characters per one inputted.

Challenge

Your program/function should either accept a file as a command-line argument, have the file path hard-coded, or accept the text [that would be in the file] as a command-line or function argument, and mimic hackertyper.net by outputting 3 characters onto the screen (STDOUT or equivalent) from the file for each one received through STDIN or equivalent.

Once EOF is reached, the program should start outputting characters from the beginning of the file again (wrap).

Specs

For the purposes of simplicity, you can assume that STDIN has already been set to no buffer and no echo mode, that is not waiting until the user presses enter before passing input to your program and not displaying the characters you type.

The file can contain newlines, while the input will not contain newlines.

For a small example written in C (not golfed) that demonstrates how this works, see this.

Green text and a black background are not required.

Example input and output

The file:

```<code>#include <stdio.h>
int main() { }

</code>```

Input:

```<code>hello world
</code>```

Output:

```<code>#include <stdio.h>
int main() { }
</code>```

The file:

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

Input:

```<code>hello world
</code>```

Output:

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

Body:
J, 7 bytes

$~(3*#)

Takes two arguments, the text to be repeated and the user's input text.

Usage

The input text is formatted where , means to join and LF is the newline character.

   f =: $~(3*#)
   ('#include <stdio.h>', LF, 'int main() { }') f 'hello world'
#include <stdio.h>
int main() { }
   'hello' f 'hello world'
hellohellohellohellohellohellohel

Try it online. (tryj.tk)


答:
Pyth, 10 bytes

```<code>s@Ljb.z*3l
</code>```

Try it online!

Title: hackertyper.net

Body:
Pyth, 10 bytes

s@Ljb.z*3l

Try it online!


答:
Jelly, 9 bytes

```<code>⁴L×3
ẋ¢ḣ¢
</code>```

Try it online!

```<code>⁴L×3     Define nilad as ¢:

 L       length of
⁴        second argument
  ×3     tripled

ẋ¢ḣ¢     Main chain:

         the first argument (implicit)
ẋ        repeated
 ¢       ¢ many times
  ḣ¢     then get the first ¢ characters of it.
</code>```

Title: hackertyper.net

Body:
Jelly, 9 bytes

⁴L×3
ẋ¢ḣ¢

Try it online!

⁴L×3     Define nilad as ¢:

 L       length of
⁴        second argument
  ×3     tripled

ẋ¢ḣ¢     Main chain:

         the first argument (implicit)
ẋ        repeated
 ¢       ¢ many times
  ḣ¢     then get the first ¢ characters of it.


答:
Jelly, 4 bytes

```<code>ẋ3ṁ@
</code>```

Try it online!

How it works

```<code>ẋ3ṁ@    Main link. Arguments: s (input string), t (file string)

ẋ3      Repeat s three times.
  ṁ@    Mold; reshape t like the previous result.
        This repeats the elements of t over and over until the length matches that
        of s repeated thrice.
</code>```

Title: hackertyper.net

Body:
Jelly, 4 bytes

ẋ3ṁ@

Try it online!

How it works

ẋ3ṁ@    Main link. Arguments: s (input string), t (file string)

ẋ3      Repeat s three times.
  ṁ@    Mold; reshape t like the previous result.
        This repeats the elements of t over and over until the length matches that
        of s repeated thrice.


问:
Showcase of Languages

Notes

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

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

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

How this works

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

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

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

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

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

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

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

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

Current answers, sorted alphabetically by language name

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

答:
Cy

Cy is a postfix language that operates on a stack. Cy is meant to be somewhat-practical, meaning I do things like use actual words and have insignificant white space, in sharp contrast with my previous languages.

If I explain things poorly or you want to try it yourself, feel free to install the Ruby interpreter

I will be using the following format in examples (this is the format used by the Ruby interpreter's REPL (accessible via the -r parameter (ooh nested parentheticals! I should try lisp next!))):

>>>
:: [initial stack]

>>> some code
:: [resulting stack]

>>> some more code
:: [resulting stack]
```

<hr>

<h2>Factoid</h2>

<p>The order  in which operands are expected on the stack is based not on what makes sense, but the order in which it would be most convenient to pass on arguments in a tacit style, i.e. taking arguments in the same order as they would most likely be passed to a user-defined function. More on this later.</p>

<h2>Length 1 Snippet</h2>

<pre class="lang-ruby prettyprint-override"><code>1
</code>```

This pushes the number 1 to the stack.

Example:

>>>
:: []

>>> 1
:: [1]
```

<h2>Length 2 Snippet</h2>

<pre class="lang-ruby prettyprint-override"><code>$x
</code>```

This pushes the value stored in the variable x to the stack. Assigning values to variables is covered below.

Length 3 Snippet

"a"
```

<p>This pushes the string <code>"a"</code> to the stack. Pretty self-explanatory. Note that single quotes <code>'</code> cannot be used for this purpose.</p>

<p>Example:</p>

<pre class="lang-ruby prettyprint-override"><code>>>> "a" # string
:: ["a"]

>>> 'a' # error
Error
  @ `'a'`
</code>```

Length 4 Snippet

tran
```

<p><code>tran</code> is an incredibly useful built-in I just implemented. This operator is used to define a stack <code>tran</code>sformation. It takes two arrays describing the old and new state of the stack. The second array should be a shuffled version of the first, and the stack will be modified accordingly.</p>

<p>Example:</p>

<pre class="lang-ruby prettyprint-override"><code>>>>
:: [1, 2, 3, 4]

>>> [.a, .b] [.b, .a] tran
:: [1, 2, 4, 3]

>>> [1, 2] [2, 1, 2] tran
:: [1, 2, 3, 4, 3]
</code>```

Length 5 Snippet

10 =x
```

<p>This is the syntax for setting variable <code>x</code>. Note that the <code>=</code> sign has to be <em>touching</em> the identifier; <code>10 = x</code> would do something different.</p>

<h2>Length 6 Snippet</h2>

<pre class="lang-ruby prettyprint-override"><code>&print
</code>```

Now we get into the interesting stuff. print is a function that pops something from the stack and outputs it. & is a prefix that makes its function peek from the stack instead of popping it. This means that the top of the stack will be outputted, but still left on the stack.

Length 7 Snippet

{10} if
```

<p>This showcases two things - blocks and if-statements. A block holds a piece of code. The block <code>{10}</code> is a block that pushes <code>10</code> to the stack. The <code>if</code> command pops a value from the stack, and if it is truthy, executes the given block. In this case, it would push <code>10</code> to the stack.</p>

<p>Example</p>

<pre class="lang-ruby prettyprint-override"><code>>>>
:: [0]

>>> {10} if
:: []
</code>```

>>>
:: [1]

>>> {10} if
:: [10]
```

<h1>Length 8 Snippet</h1>

<pre class="lang-ruby prettyprint-override"><code>{3 2 ^-}
</code>```

This demonstrates another modifier, related to &. Without the ^, the block {3 2 -} would just push the difference of 3 and 2 (1). However, the ^ in front of - makes it do something special. If the block is called with an &, it will execute &- (peek for operands); if not, it will execute - (pop the operands).

Example

>>> {3 2 ^-} =f
:: []

>>> f
:: [1]

>>> &f
:: [1, 3, 2, 1]
```

Title: Showcase of Languages

Body:
Cy

Cy is a postfix language that operates on a stack. Cy is meant to be somewhat-practical, meaning I do things like use actual words and have insignificant white space, in sharp contrast with my previous languages.

If I explain things poorly or you want to try it yourself, feel free to install the Ruby interpreter

I will be using the following format in examples (this is the format used by the Ruby interpreter's REPL (accessible via the -r parameter (ooh nested parentheticals! I should try lisp next!))):

>>>
:: [initial stack]

>>> some code
:: [resulting stack]

>>> some more code
:: [resulting stack]

Factoid

The order  in which operands are expected on the stack is based not on what makes sense, but the order in which it would be most convenient to pass on arguments in a tacit style, i.e. taking arguments in the same order as they would most likely be passed to a user-defined function. More on this later.

Length 1 Snippet

1

This pushes the number 1 to the stack.

Example:

>>>
:: []

>>> 1
:: [1]

Length 2 Snippet

$x

This pushes the value stored in the variable x to the stack. Assigning values to variables is covered below.

Length 3 Snippet

"a"

This pushes the string "a" to the stack. Pretty self-explanatory. Note that single quotes ' cannot be used for this purpose.

Example:

>>> "a" # string
:: ["a"]

>>> 'a' # error
Error
  @ `'a'`

Length 4 Snippet

tran

tran is an incredibly useful built-in I just implemented. This operator is used to define a stack transformation. It takes two arrays describing the old and new state of the stack. The second array should be a shuffled version of the first, and the stack will be modified accordingly.

Example:

>>>
:: [1, 2, 3, 4]

>>> [.a, .b] [.b, .a] tran
:: [1, 2, 4, 3]

>>> [1, 2] [2, 1, 2] tran
:: [1, 2, 3, 4, 3]

Length 5 Snippet

10 =x

This is the syntax for setting variable x. Note that the = sign has to be touching the identifier; 10 = x would do something different.

Length 6 Snippet

&print

Now we get into the interesting stuff. print is a function that pops something from the stack and outputs it. & is a prefix that makes its function peek from the stack instead of popping it. This means that the top of the stack will be outputted, but still left on the stack.

Length 7 Snippet

{10} if

This showcases two things - blocks and if-statements. A block holds a piece of code. The block {10} is a block that pushes 10 to the stack. The if command pops a value from the stack, and if it is truthy, executes the given block. In this case, it would push 10 to the stack.

Example

>>>
:: [0]

>>> {10} if
:: []

>>>
:: [1]

>>> {10} if
:: [10]

Length 8 Snippet

{3 2 ^-}

This demonstrates another modifier, related to &. Without the ^, the block {3 2 -} would just push the difference of 3 and 2 (1). However, the ^ in front of - makes it do something special. If the block is called with an &, it will execute &- (peek for operands); if not, it will execute - (pop the operands).

Example

>>> {3 2 ^-} =f
:: []

>>> f
:: [1]

>>> &f
:: [1, 3, 2, 1]


问:
Compute the Adler-32 checksum

Background

Adler-32 is a 32-bit checksum invented by Mark Adler in 1995 which is part of the widely used zlib library (also developed by Adler). Adler-32 is not as reliable as a 32-bit cyclic redundancy check, but – at least in software  – it is much faster and easier to implement.

Definition

Let B = [b1, ⋯, bn] be a byte array.

The Adler-32 checksum of B is defined as the result of low + 65536 × high, where:

low := ((1 + b1 + ⋯ + bn) mod 65521)

high := (((1 + b1) + (1 + b1 + b2) + ⋯ (1 + b1 + ⋯ + bn)) mod 65521)

Task

Given a byte array as input, compute and return its Adler-32 checksum, abiding to the following.

You can take the input as an array of bytes or integers, or as a string.

In both cases, only bytes corresponding to printable ASCII characters will occur in the input.

You may assume that the length of the input will satisfy 0 < length ≤ 4096.

If you choose to print the output, you may use any positive base up to and including 256.

If you choose unary, make sure interpreter can handle up to 232 - 983056 bytes of output on a machine with 16 GiB of RAM.

Built-ins that compute the Adler-32 checksum are forbidden.

Standard code-golf rules apply.

Test cases

```<code>String:     "Eagles are great!"
Byte array: [69, 97, 103, 108, 101, 115, 32, 97, 114, 101, 32, 103, 114, 101, 97, 116, 33]
Checksum:   918816254

String:     "Programming Puzzles & Code Golf"
Byte array: [80, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 32, 80, 117, 122, 122, 108, 101, 115, 32, 38, 32, 67, 111, 100, 101, 32, 71, 111, 108, 102]
Checksum:   3133147946

String:     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Byte array: [126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126]
Checksum:   68095937

String:     <1040 question marks>
Byte array: <1040 copies of 63>
Checksum:   2181038080
</code>```

答:
Julia, <s>73</s> 46 bytes

x->[sum(x)+1;sum(cumsum(x)+1)]%65521⋅[1;4^8]
```

This is an anonymous function that accepts an array and returns an integer. To call it, assign it to a variable.

We combine sum(x) + 1 and sum(cumsum(x) + 1) into an array, where x is the input array, and take each modulo 65521. We then compute the dot product with 1 and 48, which gives us (sum(x) + 1) + 4^8 * sum(cumsum(x) + 1), which is exactly the Adler-32 formula.

Try it online! (Includes all test cases)

Saved 27 bytes thanks to Sp3000 and Dennis!

Title: Compute the Adler-32 checksum

Body:
Julia, <s>73</s> 46 bytes

x->[sum(x)+1;sum(cumsum(x)+1)]%65521⋅[1;4^8]

This is an anonymous function that accepts an array and returns an integer. To call it, assign it to a variable.

We combine sum(x) + 1 and sum(cumsum(x) + 1) into an array, where x is the input array, and take each modulo 65521. We then compute the dot product with 1 and 48, which gives us (sum(x) + 1) + 4^8 * sum(cumsum(x) + 1), which is exactly the Adler-32 formula.

Try it online! (Includes all test cases)

Saved 27 bytes thanks to Sp3000 and Dennis!


答:
Jelly, <s>19</s> 17 bytes

```<code>+\,S‘S€%65521ḅ⁹²¤
</code>```

Try it online!

```<code>+\,S‘S€%65521ḅ⁹²¤    Main monadic chain. Takes array as only argument.

                     The array is shown here as [b1 b2 ... bn].
+\                   Reduce by addition (+) while returning immediate results.
                         yields [b1 b1+b2 ... b1+b2+...+bn].

  ,                  Concatenate with...
   S                 the sum of the argument.
                         yields [[b1 b1+b2 ... b1+b2+...+bn] b1+b2+...+bn].

    ‘                Increment [each].
                         yields [[1+b1 1+b1+b2 ... 1+b1+b2+...+bn] 1+b1+b2+...+bn].

     S€              Sum each list.
                         yields [[1+b1+1+b1+b2+...+1+b1+b2+...+bn] 1+b1+b2+...+bn].

       %65521        Modulo [each] by 65521.

             ḅ⁹²¤    Convert from base    65536    to integer.
              ⁹                        256
               ²                           squared
</code>```

Title: Compute the Adler-32 checksum

Body:
Background

Adler-32 is a 32-bit checksum invented by Mark Adler in 1995 which is part of the widely used zlib library (also developed by Adler). Adler-32 is not as reliable as a 32-bit cyclic redundancy check, but – at least in software  – it is much faster and easier to implement.

Definition

Let B = [b1, ⋯, bn] be a byte array.

The Adler-32 checksum of B is defined as the result of low + 65536 × high, where:

low := ((1 + b1 + ⋯ + bn) mod 65521)

high := (((1 + b1) + (1 + b1 + b2) + ⋯ (1 + b1 + ⋯ + bn)) mod 65521)

Task

Given a byte array as input, compute and return its Adler-32 checksum, abiding to the following.

You can take the input as an array of bytes or integers, or as a string.

In both cases, only bytes corresponding to printable ASCII characters will occur in the input.

You may assume that the length of the input will satisfy 0 < length ≤ 4096.

If you choose to print the output, you may use any positive base up to and including 256.

If you choose unary, make sure interpreter can handle up to 232 - 983056 bytes of output on a machine with 16 GiB of RAM.

Built-ins that compute the Adler-32 checksum are forbidden.

Standard code-golf rules apply.

Test cases

```<code>String:     "Eagles are great!"
Byte array: [69, 97, 103, 108, 101, 115, 32, 97, 114, 101, 32, 103, 114, 101, 97, 116, 33]
Checksum:   918816254

String:     "Programming Puzzles & Code Golf"
Byte array: [80, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 32, 80, 117, 122, 122, 108, 101, 115, 32, 38, 32, 67, 111, 100, 101, 32, 71, 111, 108, 102]
Checksum:   3133147946

String:     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Byte array: [126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126]
Checksum:   68095937

String:     <1040 question marks>
Byte array: <1040 copies of 63>
Checksum:   2181038080
</code>```

Body:
Jelly, <s>19</s> 17 bytes

+\,S‘S€%65521ḅ⁹²¤

Try it online!

+\,S‘S€%65521ḅ⁹²¤    Main monadic chain. Takes array as only argument.

                     The array is shown here as [b1 b2 ... bn].
+\                   Reduce by addition (+) while returning immediate results.
                         yields [b1 b1+b2 ... b1+b2+...+bn].

  ,                  Concatenate with...
   S                 the sum of the argument.
                         yields [[b1 b1+b2 ... b1+b2+...+bn] b1+b2+...+bn].

    ‘                Increment [each].
                         yields [[1+b1 1+b1+b2 ... 1+b1+b2+...+bn] 1+b1+b2+...+bn].

     S€              Sum each list.
                         yields [[1+b1+1+b1+b2+...+1+b1+b2+...+bn] 1+b1+b2+...+bn].

       %65521        Modulo [each] by 65521.

             ḅ⁹²¤    Convert from base    65536    to integer.
              ⁹                        256
               ²                           squared


问:
Find the repetend of the decimal representation!
In this challenge 2 years ago, we found the period of a unit fraction (1/n where n is a natural number).

Now, your task is to write a program/function to find the repetend of a unit fraction.

The repetend is the part of the decimal expansion which repeats infinitely, like:

The decimal representation of 1/6 is 0.16666..., then the repetend is 6.

The decimal representation of 1/11 is 0.090909..., then the repetend is 09.

The decimal representation of 1/28 is 0.0357142857142857142857..., then the repetend is 571428.

Specs

Input in any reasonable format.

Output the repetend in decimal, string or list.

For 1/7 (0.142857142857...), you must output 142857 instead of 428571.

For 1/13 (0.076923076923076923...), you must output 076923 instead of 76923.

No brute force, please.

Testcases

```<code>Input    Output
1        0
2        0
3        3
7        142857
13       076923
17       0588235294117647
28       571428
70       142857
98       102040816326530612244897959183673469387755
9899     000101020305081321345590463683200323264976260228305889483786241034447924032730578846348115971310233356904737852308313971108192746742095161127386604707546216789574704515607637135064147893726639054449944438832205273259925244974239822204263056874431760783917567431053641781998181634508536215779371653702394181230427315890493989291847661379937367410849580765733912516415799575714718658450348520052530558642287099707041115264168097787655318719062531568845337912920497019901
</code>```

Scoring

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

No answer would be accepted, because the goal is not to find the language capable of producing the shortest solution, but the shortest solution in each language.

Leaderboard

var QUESTION_ID=78850,OVERRIDE_USER=42854;function answersUrl(e){return"http://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"http://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="
"+e.body.replace(OVERRIDE_REG,"")+"
")});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;/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;```
<pre class="snippet-code-css lang-css prettyprint-override"><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}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

```

答:
Java, 122

String f(int n){String r="";int x=1,a[]=new
int[n*10];while(a[x]++<1)x=x%n*10;do{r+=x/n;x=x%n*10;}while(a[x]<2);return r;}
```

Similar to my CJam solution.

Body:
Java, 122

String f(int n){String r="";int x=1,a[]=new
int[n*10];while(a[x]++<1)x=x%n*10;do{r+=x/n;x=x%n*10;}while(a[x]<2);return r;}

Similar to my CJam solution.


问:
Perfect powers in more than one way?

Challenge

Your task is to write a program or function which, given a positive integer \$N\$, finds all positive integers less than or equal to \$N\$ that can be expressed as a perfect power in more than one way.

Definition

A perfect power is defined as a number \$i\$ found by \$m^k\$, where:

\$m\$ and \$i\$ are positive integers

\$m \ne k\$

Test Cases

```
input -> output
1000 ->  16, 64, 81, 256, 512, 625, 729
56 -> 16
999 -> 16, 64, 81, 256, 512, 625, 729
81 -> 16, 64, 81
1500 -> 16, 64, 81, 256, 512, 625, 729, 1024, 1296
```

Please provided a readable, commented version as well.

ContentLicense: CC BY-SA 4.0

Title: Perfect powers in more than one way?

Body:
Ruby - 101 chars (without whitespace)

f=->l{c=Hash.new{0}
2.upto(1E4){|i|2.upto(20){|j|c[i**j]+=1}}
c.map{|k,v|v>1&&k<=l&&k||p}.compact.sort}

Works for 1 <= limit <= 100,000,000 within 5 seconds.

Test

> f[10000]
[16, 64, 81, 256, 512, 625, 729, 1024, 1296, 2401, 4096, 6561, 10000]

ContentLicense: CC BY-SA 2.5


答:
Actually, 36 bytes

```<code>;Σu@;╗lR`╜HΣu`MΣk`:65521@%`M1#84ⁿ@q*
</code>```

Try it online!

Explanation:

```<code>;Σu@;╗lR`╜HΣu`MΣk`:65521@%`M1#84ⁿ@q*
;Σu                                   sum(input)+1
   @;╗lR                              push a copy of input to reg0, push range(1, len(input)+1)
        `╜HΣu`M                       map over range: sum(head(reg0,n))+1
               Σk                     sum, combine lower and upper into a list
                 `:65521@%`M          modulo each by 65521
                            1#84ⁿ@q*  dot product with [1,4**8]
</code>```

Title: Compute the Adler-32 checksum

Body:
Actually, 36 bytes

;Σu@;╗lR`╜HΣu`MΣk`:65521@%`M1#84ⁿ@q*

Try it online!

Explanation:

;Σu@;╗lR`╜HΣu`MΣk`:65521@%`M1#84ⁿ@q*
;Σu                                   sum(input)+1
   @;╗lR                              push a copy of input to reg0, push range(1, len(input)+1)
        `╜HΣu`M                       map over range: sum(head(reg0,n))+1
               Σk                     sum, combine lower and upper into a list
                 `:65521@%`M          modulo each by 65521
                            1#84ⁿ@q*  dot product with [1,4**8]


答:
Mathematica, 46 bytes

```<code>{1,4^8}.Fold[##+{0,#&@@#}&,{1,0},#]~Mod~65521&
</code>```

An anonymous function that takes an integer array and returns the Adler-32, with some improvements from miles and Martin (see comments).

miles' is also 46 bytes, but faster:

```<code>{1,4^8}.{Tr@#+1,Tr[Accumulate@#+1]}~Mod~65521&
</code>```

Title: Compute the Adler-32 checksum

Body:
Mathematica, 46 bytes

{1,4^8}.Fold[##+{0,#&@@#}&,{1,0},#]~Mod~65521&

An anonymous function that takes an integer array and returns the Adler-32, with some improvements from miles and Martin (see comments).

miles' is also 46 bytes, but faster:

{1,4^8}.{Tr@#+1,Tr[Accumulate@#+1]}~Mod~65521&


答:
C89, 70 bytes

```<code>h,l,m=65521;A(char*B){h=0;l=1;while(*B)h+=l+=*B++;return h%m<<16|l%m;}
</code>```

To test (compile with gcc -std=c89 -lm golf.c):

```<code>#include <stdio.h>
int main(int argc, char** argv) {
    printf("%u\n", A("Eagles are great!"));
    printf("%u\n", A("Programming Puzzles & Code Golf"));
    printf("%u\n", A("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"));
    return 0;
}
</code>```

Title: Compute the Adler-32 checksum

Body:
C89, 70 bytes

h,l,m=65521;A(char*B){h=0;l=1;while(*B)h+=l+=*B++;return h%m<<16|l%m;}

To test (compile with gcc -std=c89 -lm golf.c):

#include <stdio.h>
int main(int argc, char** argv) {
    printf("%u\n", A("Eagles are great!"));
    printf("%u\n", A("Programming Puzzles & Code Golf"));
    printf("%u\n", A("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"));
    return 0;
}


答:
05AB1E, 7 bytes

Code:

```<code>3×g©×®£
</code>```

Explanation:

```<code>3×        # Multiply the input string three times.
  g       # Take the length.
   ©      # Copy that to the register.
    ×     # Multiply by the second input.
     ®    # Retrieve the length from the register.
      £   # Only keep [0:length * 3] from the new string.
</code>```

Try it online!.

Title: hackertyper.net

Body:
05AB1E, 7 bytes

Code:

3×g©×®£

Explanation:

3×        # Multiply the input string three times.
  g       # Take the length.
   ©      # Copy that to the register.
    ×     # Multiply by the second input.
     ®    # Retrieve the length from the register.
      £   # Only keep [0:length * 3] from the new string.

Try it online!.


答:
Python 3.5, 82 bytes:

(-1 byte thanks to Neil!)

(-1 byte thanks to mathmandan!)

(-4 bytes thanks to Dennis!)

```<code>lambda w:((1+sum(w))%65521)+4**8*(sum(1+sum(w[:i+1])for i in range(len(w)))%65521)
</code>```

An anonymous lambda function. Accepts a byte array, applies the entire algorithm to the array, and outputs the result. Has successfully worked for all the test cases. You call this by assigning a variable to it, and then calling that variable just like you would call a normal function. If you are using the shell, then this should output without a print function. However, if you are not, then you must wrap the function call in the print() function to actually see the output.

Try it online! (Ideone)

Title: Compute the Adler-32 checksum

Body:
Python 3.5, 82 bytes:

(-1 byte thanks to Neil!)

(-1 byte thanks to mathmandan!)

(-4 bytes thanks to Dennis!)

lambda w:((1+sum(w))%65521)+4**8*(sum(1+sum(w[:i+1])for i in range(len(w)))%65521)

An anonymous lambda function. Accepts a byte array, applies the entire algorithm to the array, and outputs the result. Has successfully worked for all the test cases. You call this by assigning a variable to it, and then calling that variable just like you would call a normal function. If you are using the shell, then this should output without a print function. However, if you are not, then you must wrap the function call in the print() function to actually see the output.

Try it online! (Ideone)


答:
JavaScript (ES7), <s>52</s> 50 bytes

```<code>a=>a.map(b=>h+=l+=b,h=0,l=1)&&l%65521+h%65521*4**8
</code>```

ES6 takes 51 bytes (replace 4**8 with 65536). If you want a string version, then for 69 bytes:

```<code>s=>[...s].map(c=>h+=l+=c.charCodeAt(),h=0,l=1)&&l%65521+h%65521*65536
</code>```

Edit: Saved 2 bytes thanks to @user81655.

Title: Compute the Adler-32 checksum

Body:
JavaScript (ES7), <s>52</s> 50 bytes

a=>a.map(b=>h+=l+=b,h=0,l=1)&&l%65521+h%65521*4**8

ES6 takes 51 bytes (replace 4**8 with 65536). If you want a string version, then for 69 bytes:

s=>[...s].map(c=>h+=l+=c.charCodeAt(),h=0,l=1)&&l%65521+h%65521*65536

Edit: Saved 2 bytes thanks to @user81655.


答:
JavaScript (ES6), 40 bytes

```<code>(s,t)=>s.repeat(l=t.length*3).slice(0,l)
</code>```

Where s is the data string and t is the user string. Assumes s is nonempty and repeats it l times to ensure that its length is at least l so that it can return the first l characters, where l is three times the length of t.

Title: hackertyper.net

Body:
Introduction

hackertyper.net is a website that simulates "hacking" (as the media portrays it) by outputting complicated code from the crypto section of the Linux kernel onto the screen as you type at a rate of 3 characters per one inputted.

Challenge

Your program/function should either accept a file as a command-line argument, have the file path hard-coded, or accept the text [that would be in the file] as a command-line or function argument, and mimic hackertyper.net by outputting 3 characters onto the screen (STDOUT or equivalent) from the file for each one received through STDIN or equivalent.

Once EOF is reached, the program should start outputting characters from the beginning of the file again (wrap).

Specs

For the purposes of simplicity, you can assume that STDIN has already been set to no buffer and no echo mode, that is not waiting until the user presses enter before passing input to your program and not displaying the characters you type.

The file can contain newlines, while the input will not contain newlines.

For a small example written in C (not golfed) that demonstrates how this works, see this.

Green text and a black background are not required.

Example input and output

The file:

```<code>#include <stdio.h>
int main() { }

</code>```

Input:

```<code>hello world
</code>```

Output:

```<code>#include <stdio.h>
int main() { }
</code>```

The file:

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

Input:

```<code>hello world
</code>```

Output:

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

Body:
JavaScript (ES6), 40 bytes

(s,t)=>s.repeat(l=t.length*3).slice(0,l)

Where s is the data string and t is the user string. Assumes s is nonempty and repeats it l times to ensure that its length is at least l so that it can return the first l characters, where l is three times the length of t.


问:
Shortest Unique Substring
Given (on STDIN, as command line arguments, or as function arguments) two distinct non-empty strings, find and return the shortest substring of the first string which is not a substring of the second. If no such substring exists, you may return the empty string, return any string which isn't a substring of the original string, or throw an exception. If you are returning from a function, you may also return null (or undefined, None, etc.) in this case. If multiple such substrings are tied for the shortest, you may return any one of them.

Strings can consist of any printable ascii characters.

Input given on STDIN will be given with one string on each line. At your request, a single empty line may be added at the end of the input.

This is code golf, so the shortest valid program wins.

SOME TEST CASES

INPUT:

```<code>STRING ONE
STRING TWO
</code>```

OUTPUT:

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

INPUT:

```<code>A&&C
A&$C
</code>```

VALID OUTPUTS:

```<code>&&
&C
</code>```

INPUT:

(Two randomly-generated 80-letter strings)

```<code>QIJYXPYWIWESWBRFWUHEERVQFJROYIXNKPKVDDFFZBUNBRZVUEYKLURBJCZJYMINCZNQEYKRADRYSWMH
HAXUDFLYFSLABUCXUWNHPSGQUXMQUIQYRWVIXGNKJGYUTWMLLPRIZDRLFXWKXOBOOEFESKNCUIFHNLFE
</code>```

ALL VALID OUTPUTS:

```<code>AD
BJ
BR
CZ
DD
EE
ER
EY
EY
FF
FJ
FW
FZ
HE
IJ
IN
IW
JC
JR
JY
KL
KP
KR
KV
LU
MH
MI
NB
NQ
OY
PK
PY
QE
QF
QI
RA
RB
RF
RO
RV
RY
RZ
SW
UE
UH
UN
UR
VD
VQ
VU
WB
WE
WI
WU
XN
XP
YI
YK
YK
YM
YS
YW
YX
ZB
ZJ
ZN
ZV
</code>```

答:
Perl, 87 85

```<code>sub{(grep{$_[1]!~/\Q$_/}map{$}=$_;map{substr($_[0],$_,$})}@}}(@}=0..length$_[0]))[0]}
</code>```

This is an anonymous function which returns the first (by position) of the shortest substrings of $_[0] that do not occur in $_[1], or undef if no such substring exists.

Test program with strings taken from @iAmMortos's answer, tested with Perl 5.22.1:

```<code>#!/usr/bin/perl -l
use strict;
use warnings;

my $f = <see above>;
print $f->('abcd', 'abc');
print $f->('abcd', 'dabc');
print $f->('abcd', 'dcbabbccd');
print $f->('abcdf', 'abcdebcdf');
print $f->('abc', 'abc');
</code>```

Title: Shortest Unique Substring

Body:
Perl, 87 85

sub{(grep{$_[1]!~/\Q$_/}map{$}=$_;map{substr($_[0],$_,$})}@}}(@}=0..length$_[0]))[0]}

This is an anonymous function which returns the first (by position) of the shortest substrings of $_[0] that do not occur in $_[1], or undef if no such substring exists.

Test program with strings taken from @iAmMortos's answer, tested with Perl 5.22.1:

#!/usr/bin/perl -l
use strict;
use warnings;

my $f = <see above>;
print $f->('abcd', 'abc');
print $f->('abcd', 'dabc');
print $f->('abcd', 'dcbabbccd');
print $f->('abcdf', 'abcdebcdf');
print $f->('abc', 'abc');


答:
Haskell, <s>54</s> 50 bytes

```<code>m=(`mod`65521).sum
g x=m(-1:scanl(+)1x)*4^8+m(1:x)
</code>```

Usage example: g [69,97,103,108,101,115,32,97,114,101,32,103,114,101,97,116,33]-> 918816254.

scanl includes the starting value (-> 1) in the list (-> [1,1+b1,1+b1+b2,..]), so the sum is off by 1, which is fixed by prepending -1 to the list before summing.

Edit: Thanks @xnor for 4 bytes.

Title: Compute the Adler-32 checksum

Body:
Haskell, <s>54</s> 50 bytes

m=(`mod`65521).sum
g x=m(-1:scanl(+)1x)*4^8+m(1:x)

Usage example: g [69,97,103,108,101,115,32,97,114,101,32,103,114,101,97,116,33]-> 918816254.

scanl includes the starting value (-> 1) in the list (-> [1,1+b1,1+b1+b2,..]), so the sum is off by 1, which is fixed by prepending -1 to the list before summing.

Edit: Thanks @xnor for 4 bytes.


问:
Quickly express a number with only 0-9 and the four operations, plus one more extra

Explanation

Befunge is a two-dimensional program that uses stacks.

That means, to do 5 + 6, you write 56+, meaning:

```<code>56+
5    push 5 into stack
 6   push 6 into stack
  +  pop the first two items in the stack and add them up, and push the result into stack

(to those of you who do not know stacks, "push" just means add and "pop" just means take off)
</code>```

However, we cannot push the number 56 directly into the stack.

To do so, we must write 78* instead, which multiplies 7 and 8 and pushes the product into the stack.

Details

For each number from 1 to n, find a string consisting of only these characters: 0123456789+-*/: (I would not use % modulo.)

The goal is to find the shortest string that can represent the number, using the format described above.

For example, if the input is 123, then the output would be 67*9:*+. The output should be evaluated from left to right.

If there are more than one acceptable outputs (e.g. 99*67*+ is also acceptable), any one can be printed (no bonus for printing all of them).

Further Explanation

If you still do not understand how 67*9:*+ evaluates to 123, here is a detailed explanation.

```<code>stack    |operation|explanation
          67*9:*+
[6]       6         push 6 to stack
[6,7]      7        push 7 to stack
[42]        *       pop two from stack and multiply, then put result to stack
[42,9]       9      push 9 to stack
[42,9,9]      :     duplicate the top of stack
[42,81]        *    pop two from stack and multiply, then put result to stack
[123]           +   pop two from stack and add, then put result to stack
</code>```

TL;DR

The program needs to find the shortest string that can represent the input (number), using the format specified above.

SCORING

We have already done it in the shortest amount of code. This time, size does not matter.

Your language of choice has to have a free compiler/interpreter for my operating system (Windows 7 Enterprise).

Bonus if you include the link to the compiler/interpreter (I am too lazy).

If possible, please include a timer for my convenience. The output from the timer is valid.

The score will be the largest n in 1 minute.

That means, the program needs to print the required representation from 1 onward.

No hard-coding, except 0 to 9.

(more) SPECIFICS

The program is invalid if it outputs a string longer than needed for any number.

1/0=ERROR

5/2=2, (-5)/2=-2, (-5)/(-2)=2, 5/(-2)=-2

Disambiguation

The - is second-top minus top, meaning that 92- returns 7.

Likewise, the / is second-top divide top, meaning that 92/ returns 4.

Sample program

Lua

Uses depth-first search.

```<code>local function div(a,b)
    if b == 0 then
        return "error"
    end
    local result = a/b
    if result > 0 then
        return math.floor(result)
    else
        return math.ceil(result)
    end
end

local function eval(expr)
    local stack = {}
    for i=1,#expr do
        local c = expr:sub(i,i)
        if c:match('[0-9]') then
            table.insert(stack, tonumber(c))
        elseif c == ':' then
            local a = table.remove(stack)
            if a then
                table.insert(stack,a)
                table.insert(stack,a)
            else
                return -1
            end
        else
            local a = table.remove(stack)
            local b = table.remove(stack)
            if a and b then
                if c == '+' then
                    table.insert(stack, a+b)
                elseif c == '-' then
                    table.insert(stack, b-a)
                elseif c == '*' then
                    table.insert(stack, a*b)
                elseif c == '/' then
                    local test = div(b,a)
                    if test == "error" then
                        return -1
                    else
                        table.insert(stack, test)
                    end
                end
            else
                return -1
            end
        end
    end
    return table.remove(stack) or -1
end

local samples, temp = {""}, {}

while true do
    temp = {}
    for i=1,#samples do
        local s = samples[i]
        if eval(s) ~= -1 or s == "" then for n in ("9876543210+-*/:"):gmatch(".") do
            table.insert(temp, s..n)
        end end
    end
    for i=1,#temp do
        local test = eval(temp[i])
        if input == test then
            print(temp[i])
            return
        end
    end
    samples = temp
end
</code>```

答:
JavaScript

Whant can be done with a JS snippet? In my machine, Firefox 64 bit, 416 in 60 seconds

function go() {
    B.disabled=true
    O.textContent = '...wait...'
    setTimeout(run, 100)
}

function run()
{
 var o=[0],
 t0=performance.now(),
 te=t0+T.value*1000,
 k=[],t=[...'0123456789'],i=0,n=0,e,v,j,l,x,h
 MainLoop:
 for(;;)
 {
   for(;!k[n] && (e=t[i++]);)
   {
     if(performance.now()>te)break MainLoop

     for(v=[],j=0;x=e[j++];l=x)
       1/x?h=v.push(+x):(b=v.pop(),x>'9'?h=v.push(b,b):(a=v.pop(),h=v.push(x<'+'?a*b:x<'-'?a+b:x<'/'?a-b:a/b|0)))
     if(!k[v])
     {
       k[v]=e
       //if(!e[10])
       {
         if (l==':')
           t.push(e+'+',e+'*')
         else if (h>1)
         {
           if (l == '1') t.push(e+'+',e+'-')
           else if (l != '0') t.push(e+'+',e+'-',e+'*',e+'/')
         }
         if (h<4)
         {
           if (l<'0'|l>'9') t.push(e+':');
           [...'0123456789'].forEach(x => t.push(e+x))
         }
       }
     }
   }
   o.push([n,k[n]])
    ++n;
 }
 o[0]='Run time sec '+(performance.now()-t0)/1000+'\nTried '+t.length+'\nRange 0..'+(n-1)+'\nTop '+k.pop()+' '+k.length
 O.textContent=o.join`\n`
    B.disabled=false
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code>Time limit sec:<input id=T type=number value=60><button id=B onclick='go()'>GO</button>
<pre id=O>``````

Body:
JavaScript

Whant can be done with a JS snippet? In my machine, Firefox 64 bit, 416 in 60 seconds

function go() {
    B.disabled=true
    O.textContent = '...wait...'
    setTimeout(run, 100)
}

function run()
{
 var o=[0],
 t0=performance.now(),
 te=t0+T.value*1000,
 k=[],t=[...'0123456789'],i=0,n=0,e,v,j,l,x,h
 MainLoop:
 for(;;)
 {
   for(;!k[n] && (e=t[i++]);)
   {
     if(performance.now()>te)break MainLoop

     for(v=[],j=0;x=e[j++];l=x)
       1/x?h=v.push(+x):(b=v.pop(),x>'9'?h=v.push(b,b):(a=v.pop(),h=v.push(x<'+'?a*b:x<'-'?a+b:x<'/'?a-b:a/b|0)))
     if(!k[v])
     {
       k[v]=e
       //if(!e[10])
       {
         if (l==':')
           t.push(e+'+',e+'*')
         else if (h>1)
         {
           if (l == '1') t.push(e+'+',e+'-')
           else if (l != '0') t.push(e+'+',e+'-',e+'*',e+'/')
         }
         if (h<4)
         {
           if (l<'0'|l>'9') t.push(e+':');
           [...'0123456789'].forEach(x => t.push(e+x))
         }
       }
     }
   }
   o.push([n,k[n]])
    ++n;
 }
 o[0]='Run time sec '+(performance.now()-t0)/1000+'\nTried '+t.length+'\nRange 0..'+(n-1)+'\nTop '+k.pop()+' '+k.length
 O.textContent=o.join`\n`
    B.disabled=false
}

Time limit sec:<input id=T type=number value=60><button id=B onclick='go()'>GO</button>
<pre id=O></pre>


答:
MATL, 22 bytes

```<code>tsQwYsQsh16W15-\l8Mh*s
</code>```

Input can be an array of numbers or the corresponding ASCII string.

Try it online!

Explanation

```<code>t       % Take array or string as input. Duplicate
sQ      % Sum all its values, and add 1
wYsQs   % Swap. Cumulative sum, add 1, sum
h       % Concatenate horizontally
16W     % 2^16: gives 65536
15-     % Subtract 15: gives 65521
\       % Element-wise modulo operation
l       % Push 1
8M      % Push 65536 again
h       % Concatenate horizontally: gives array [1, 65535]
*s      % Element-wise multiplication and sum. Display
</code>```

Title: Compute the Adler-32 checksum

Body:
MATL, 22 bytes

tsQwYsQsh16W15-\l8Mh*s

Input can be an array of numbers or the corresponding ASCII string.

Try it online!

Explanation

t       % Take array or string as input. Duplicate
sQ      % Sum all its values, and add 1
wYsQs   % Swap. Cumulative sum, add 1, sum
h       % Concatenate horizontally
16W     % 2^16: gives 65536
15-     % Subtract 15: gives 65521
\       % Element-wise modulo operation
l       % Push 1
8M      % Push 65536 again
h       % Concatenate horizontally: gives array [1, 65535]
*s      % Element-wise multiplication and sum. Display


问:
exponential without exponential
Your goal is to calculate the exponential of a float (e**x) up to 2 decimal places for any float within 1 to 10. The accepted error range is 0.01.

However, you must not use the built-in exponential function or the logarithm function.

In fact, attempts to circumvent this by (2**x)**(1/ln(2)) are prohibited, even if you hardcode the ln(2).

Basically, the power function is fine, as long as the index is not derived from the input.

Shortest solution in bytes wins.

(You may include an extra solution which uses the built-in, but which does not affect the score in any way.)

Specs

Program or function

Any reasonable input/output format

Testcases

```<code>1 -> 2.71 or 2.72 or 2.73
</code>```

Title: exponential without exponential

Body:
Matlab, 17 bytes

@(x)(1+x/1e9)^1e9


答:
Haskell, 19 bytes

```<code>(**1e9).(1+).(/1e9)
</code>```

or alternatively a named function:

```<code>f x=(1+x/1e9)**1e9
</code>```

Title: exponential without exponential

Body:
Your goal is to calculate the exponential of a float (e**x) up to 2 decimal places for any float within 1 to 10. The accepted error range is 0.01.

However, you must not use the built-in exponential function or the logarithm function.

In fact, attempts to circumvent this by (2**x)**(1/ln(2)) are prohibited, even if you hardcode the ln(2).

Basically, the power function is fine, as long as the index is not derived from the input.

Shortest solution in bytes wins.

(You may include an extra solution which uses the built-in, but which does not affect the score in any way.)

Specs

Program or function

Any reasonable input/output format

Testcases

```<code>1 -> 2.71 or 2.72 or 2.73
</code>```

Body:
Haskell, 19 bytes

(**1e9).(1+).(/1e9)

or alternatively a named function:

f x=(1+x/1e9)**1e9


答:
AppleScript, 204 bytes

```<code>set x to(display dialog""default answer"")'s text returned
set r to 1
set i to 1
repeat 29
set r to r+(x^i)/f(i)
set i to i+1
end
return r
on f(a)
set x to a
repeat x-1
set a to a-1
set x to a*x
end
x
end</code>```

Yeah, it's kinda long. This uses the 30th term Taylor polynomial representation for e^x.

How this works:

The Taylor series expansion for ex is:

Now, according to the Lagrange error bound, I know that any given Taylor polynomial can get a precision to the first unused term of the Taylor series.

In more mathematical terms, I know that:

where I will have a precision to ex of ak+1.

Since the OP specified that I must have a precision of 2 decimal places or better, ak+1 must be less than or equal to 1/100. I need to work out the point at which the maximum error of the function possible, located at 10 in this case is less than said error. After a little trial and error, I found that:

Which means that:

For as far as our precision is concerned. The code reflects this in that I will calculate:

Title: exponential without exponential

Body:
AppleScript, 204 bytes

set x to(display dialog""default answer"")'s text returned
set r to 1
set i to 1
repeat 29
set r to r+(x^i)/f(i)
set i to i+1
end
return r
on f(a)
set x to a
repeat x-1
set a to a-1
set x to a*x
end
x
end

Yeah, it's kinda long. This uses the 30th term Taylor polynomial representation for e^x.

How this works:

The Taylor series expansion for ex is:

Now, according to the Lagrange error bound, I know that any given Taylor polynomial can get a precision to the first unused term of the Taylor series.

In more mathematical terms, I know that:

where I will have a precision to ex of ak+1.

Since the OP specified that I must have a precision of 2 decimal places or better, ak+1 must be less than or equal to 1/100. I need to work out the point at which the maximum error of the function possible, located at 10 in this case is less than said error. After a little trial and error, I found that:

Which means that:

For as far as our precision is concerned. The code reflects this in that I will calculate:


答:
AppleScript, 62 bytes

Okay, limit approximation of ex is better. ;P Thanks, flawr.

```<code>(1+(display dialog""default answer"")'s text returned/1e9)^1e9</code>```

Title: exponential without exponential

Body:
AppleScript, 62 bytes

Okay, limit approximation of ex is better. ;P Thanks, flawr.

(1+(display dialog""default answer"")'s text returned/1e9)^1e9


问:
Evolution of OEIS
In this challenge, the goal is to recreate the On-Line Encyclopedia of Integer Sequences one sequence at a time.  Similar to the Evolution of Hello World, each answer depends on a previous answer.

Over time, this challenge will create a "family tree" of the OEIS sequences.  It is simple to add on to this tree.

Find a previous answer, which can be at any depth N of the tree.

Determine the first N numbers generated by that answer's sequence.

Find a sequence in OEIS which starts with those same numbers and which hasn't been used before.

Write a program to generate this new sequence you just found.

Submit your answer as depth N+1

Since the level of your answer influences scoring, you should always add your answer onto the tree at the deepest level possible.  If you cannot fit your answer anywhere on the tree, you can start a new branch of the tree and put your answer as depth 1.

Answer Requirements

There are a few ways to output a sequence.

The first option is to write a program or function that inputs a number (from STDIN or as an argument) and returns the Nth number in your chosen sequence.  You can assume that the sequence will be defined for N and that N and S_N are "reasonably sized" (so it won't cause overflows).  You can also use any reasonable indexing, such as 0 indexing, 1 indexing, or the indexing listed under "offset" on the sequence's OEIS page, that doesn't matter.  The term produced by the first index must match the first term of the OEIS entry.

The second option is to write a program or function that inputs a number and returns the first N terms of the sequence.  The first terms of the output must be the first terms of the OEIS entry (you can't leave off the first few terms).  Consecutive terms must be delimited by arbitrary strings of non-digit characters, so 0,1  1.2/3,5;8,11 works but 011235811 does not count.

The third option is to create a program that outputs a continuous stream of numbers.  Similarly to the second option, there must be delimiters between consecutive terms.

Your answer should contain a header like this to aid Stack Snippet parsing:

```<code> # [language], [number] bytes, depth [number], A[new sequence] from A[old sequence]
</code>```

Your answer should contain the code to generate the sequence, along with the first few terms that any descendants will need to contain.  These few terms should be preceded by the exact word terms: so that the controller can use them as part of the tree diagram.  It is also recommended to write a description of the sequence you chose.

If your post is a depth 1 answer and thus has no ancestor, you should simply omit the from A[number] in your header.

Here is an example answer:

```<code># Perl, 26 bytes, depth 3, A026305 from A084912

    various code here
    and here

The next answer should match the following terms:

    1, 4, 20

This sequence is .... and does ....
</code>```

Chaining Requirements

In order to make this challenge more fair, there are restrictions on which answers you can chain yours to. These rules are mostly to prevent a single person from creating a whole branch of the tree by themselves or owning a lot of "root" nodes.

You cannot chain to yourself.

You cannot directly chain two of your answers to the same ancestor.

You cannot make more than one "Level 1" answer.

Also, if the ancestor was of depth N, your post must have depth N+1, even if more than the required number of terms agree.

Scoring

Your score as a user is the sum of the scores of all of your answers.  The score of a single answer is determined by the following formula:

```<code>Answer Score = Sqrt(Depth) * 1024 / (Length + 256)
</code>```

This scoring system should encourage users to submit a large number of deeper answers.  Shorter answers are preferred over longer answers, but depth has a much larger influence.

Below is a stack snippet that generates a leaderboard as well as a tree diagram of all of the answers.  I would like to thank Martin Büttner and d3noob as the sources for a lot of this code.  You should click "Full screen" to see the complete results.

function answersUrl(t){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+t+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(t){answers.push.apply(answers,t.items),t.has_more?getAnswers():process()}})}function shouldHaveHeading(t){var e=!1,r=t.body_markdown.split("\n");try{e|=/^#/.test(t.body_markdown),e|=["-","="].indexOf(r[1][0])>-1,e&=LANGUAGE_REG.test(t.body_markdown)}catch(a){}return e}function shouldHaveScore(t){var e=!1;try{e|=SIZE_REG.test(t.body_markdown.split("\n")[0])}catch(r){}return e}function getAuthorName(t){return t.owner.display_name}function decodeEntities(t){return $("<textarea>").html(t).text()}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading),answers.reverse();var t={},e=[],r=1,a=null,n=1,s=[];answers.forEach(function(t){var r=t.body_markdown.split("\n")[0],a=getAuthorName(t),n=r.match(SEQUENCE_REG)[0];n=n.trim();var o="from A000000";PARENT_REG.test(r)&&(o=r.match(PARENT_REG)[0]),o=o.substring(5).trim(),"A000000"==o&&(o="OEIS");var i="";SEQDATA_REG.test(t.body_markdown)&&(i=t.body_markdown.match(SEQDATA_REG)[1]);for(var u=!0,c=0;c<e.length;++c)u=u&&!(e[c]===n);for(var l=!0,c=0;c<e.length;++c)l=!(!l||e[c]===n||e[c]===n+a||e[c]===o+a);e.push(n),e.push(n+a),e.push(o+a),u&&data.push({name:n,parent:o,term:i+" : ",author:decodeEntities(a),URL:t.share_link}),l&&s.push(t)}),answers.sort(function(t,e){var r=t.body_markdown.split("\n")[0].match(SEQUENCE_REG),a=e.body_markdown.split("\n")[0].match(SEQUENCE_REG);return a>r?-1:r>a?1:void 0}),answers.forEach(function(e){var o=e.body_markdown.split("\n")[0],i=(o.match(NUMBER_REG)[0],(o.match(SIZE_REG)||[0])[0]),u=parseInt((o.match(DEPTH_REG)||[0])[0]).toString(),c=o.match(SEQUENCE_REG)[0],l="from A000000";PARENT_REG.test(o)&&(l=o.match(PARENT_REG)[0]),l=l.substring(5);var d=o.match(LANGUAGE_REG)[1];d.indexOf("]")>0&&(d=d.substring(1,d.indexOf("]")));for(var p=getAuthorName(e),E=!1,h=0;h<s.length;++h)E=E||s[h]===e;if(E){var f=jQuery("#answer-template").html();i!=a&&(n=r),a=i,++r;var m=1024*Math.pow(parseInt(u),.5)/(parseInt(i)+256);f=f.replace("{{SEQUENCE}}",c).replace("{{SEQUENCE}}",c).replace("{{NAME}}",p).replace("{{LANGUAGE}}",d).replace("{{SIZE}}",i).replace("{{DEPTH}}",u).replace("{{LINK}}",e.share_link),f=jQuery(f),jQuery("#answers").append(f),t[p]=t[p]||{lang:d,user:p,size:"0",numanswers:"0",link:e.share_link},t[p].size=(parseFloat(t[p].size)+m).toString(),t[p].numanswers=(parseInt(t[p].numanswers)+1).toString()}});var o=[];for(var i in t)t.hasOwnProperty(i)&&o.push(t[i]);o.sort(function(t,e){return parseFloat(t.size)>parseFloat(e.size)?-1:parseFloat(t.size)<parseFloat(e.size)?1:0});for(var u=0;u<o.length;++u){var c=jQuery("#language-template").html(),i=o[u];c=c.replace("{{RANK}}",u+1+".").replace("{{NAME}}",i.user).replace("{{NUMANSWERS}}",i.numanswers).replace("{{SIZE}}",i.size),c=jQuery(c),jQuery("#languages").append(c)}createTree()}function createTree(){function t(){var t=i.nodes(root).reverse(),e=i.links(t);t.forEach(function(t){t.y=180*t.depth});var r=c.selectAll("g.node").data(t,function(t){return t.id||(t.id=++o)}),a=r.enter().append("g").attr("class","node").attr("transform",function(t){return"translate("+t.y+","+t.x+")"});a.append("a").attr("xlink:href",function(t){return t.URL}).append("circle").attr("r",10).style("fill","#fff"),a.append("text").attr("x",function(){return 0}).attr("y",function(){return 20}).attr("dy",".35em").attr("text-anchor",function(){return"middle"}).text(function(t){return t.term+t.name}).style("fill-opacity",1),a.append("text").attr("x",function(){return 0}).attr("y",function(){return 35}).attr("dy",".35em").attr("text-anchor",function(){return"middle"}).text(function(t){return t.author}).style("fill-opacity",1);var n=c.selectAll("path.link").data(e,function(t){return t.target.id});n.enter().insert("path","g").attr("class","link").attr("d",u)}var e=data.reduce(function(t,e){return t[e.name]=e,t},{}),r=[];data.forEach(function(t){var a=e[t.parent];a?(a.children||(a.children=[])).push(t):r.push(t)});var a={top:20,right:120,bottom:20,left:120},n=3203-a.right-a.left,s=4003-a.top-a.bottom,o=0,i=d3.layout.tree().size([s,n]),u=d3.svg.diagonal().projection(function(t){return[t.y,t.x]}),c=d3.select("body").append("svg").attr("width",n+a.right+a.left).attr("height",s+a.top+a.bottom).append("g").attr("transform","translate("+a.left+","+a.top+")");root=r[0],t(root)}var QUESTION_ID=49223,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",data=[{name:"OEIS",parent:"null",term:"",author:"",URL:"https://oeis.org/"}],answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:<(?:s>[^&]*<\/s>|[^&]+>)[^\d&]*)*,)/,DEPTH_REG=/\d+, A/,NUMBER_REG=/\d+/,LANGUAGE_REG=/^#*\s*([^,]+)/,SEQUENCE_REG=/A\d+/,PARENT_REG=/from\s*A\d+/,SEQDATA_REG=/terms:\s*(?:(?:-)?\d+,\s*)*((?:-)?\d+)/;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align: left !important}#answer-list{padding: 10px; width: 550px; float: left;}#language-list{padding: 10px; width: 290px; float: left;}table thead{font-weight: bold;}table td{padding: 5px;}.node circle{fill: #fff; stroke: steelblue; stroke-width: 3px;}.node text{font: 12px sans-serif;}.link{fill: none; stroke: #ccc; stroke-width: 2px;}</code>```

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

Sequence List

 Sequence	Author	Language	Size	Depth

Leaderboard

 Rank	User	Answers	Score

 {{SEQUENCE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	{{DEPTH}}	Link

 {{RANK}}	{{NAME}}	{{NUMANSWERS}}	{{SIZE}}

```

答:
Mathematica, 48 bytes, depth 9, A025640 from A022336

```<code>SortBy[0~Range~#~Tuples~2,3^# 4^#2&@@#&][[#,1]]&
</code>```

Exponent of 3 (value of i) in nth number of form 3i∙4j. The next answer should start with the terms:

```<code>0, 1, 0, 2, 1, 0, 3, 2, 1
</code>```

Title: Evolution of OEIS

Body:
Mathematica, 48 bytes, depth 9, A025640 from A022336

SortBy[0~Range~#~Tuples~2,3^# 4^#2&@@#&][[#,1]]&

Exponent of 3 (value of i) in nth number of form 3i∙4j. The next answer should start with the terms:

0, 1, 0, 2, 1, 0, 3, 2, 1


答:
MATL, 9 bytes

```<code>1e9/Q1e9^
</code>```

Based upon @flawr's answers.

Try it Online

Explanation

```<code>        % Implicitly grab input as a number
1e9     % Number literal
/       % Divide the input by 1e9
Q       % Add one
1e9     % Number literal
^       % Exponent
        % Implicitly display result
</code>```

Title: exponential without exponential

Body:
MATL, 9 bytes

1e9/Q1e9^

Based upon @flawr's answers.

Try it Online

Explanation

        % Implicitly grab input as a number
1e9     % Number literal
/       % Divide the input by 1e9
Q       % Add one
1e9     % Number literal
^       % Exponent
        % Implicitly display result


答:
J, 30 bytes

```<code>+/(+65536&*)&(65521|+/)&:>:+/\
</code>```

This could probably be condensed more with a different train.

Usage

Here x $ y creates a list with x copies of y.

```<code>   f =: +/(+65536&*)&(65521|+/)&:>:+/\
   f 69 97 103 108 101 115 32 97 114 101 32 103 114 101 97 116 33
918816254
   f 80 114 111 103 114 97 109 109 105 110 103 32 80 117 122 122 108 101 115 32 38 32 67 111 100 101 32 71 111 108 102
3133147946
   f (32 $ 126)
68095937
   f (1040 $ 63)
2181038080
   f (4096 $ 255)
2170679522
</code>```

Explanation

```<code>+/(+65536&*)&(65521|+/)&:>:+/\
f (           g           ) h     Monad train (f g h) y = (f y) g (h y)
+/                                Sum the input list
                           +/\    Sum each prefix of the input, forms a list
x     f   &   g   &:   h    y     Composed verbs, makes (g (h x)) f (g (h y))
                         >:       Increment the sum and increment each prefix sum
               (m f g) y          Hook, makes m f (g y)
                    +/            Sum the prefix sums
              65521|              Take the sum and prefix total mod 65521
    (f g) y                       Hook again
    65536&*                       Multiply the prefix total by 65536
                                  This is a bonded verb, it will only multiply
                                  using a fixed value now
   +                              Add the sum and scaled prefix total
</code>```

Title: Compute the Adler-32 checksum

Body:
Background

Adler-32 is a 32-bit checksum invented by Mark Adler in 1995 which is part of the widely used zlib library (also developed by Adler). Adler-32 is not as reliable as a 32-bit cyclic redundancy check, but – at least in software  – it is much faster and easier to implement.

Definition

Let B = [b1, ⋯, bn] be a byte array.

The Adler-32 checksum of B is defined as the result of low + 65536 × high, where:

low := ((1 + b1 + ⋯ + bn) mod 65521)

high := (((1 + b1) + (1 + b1 + b2) + ⋯ (1 + b1 + ⋯ + bn)) mod 65521)

Task

Given a byte array as input, compute and return its Adler-32 checksum, abiding to the following.

You can take the input as an array of bytes or integers, or as a string.

In both cases, only bytes corresponding to printable ASCII characters will occur in the input.

You may assume that the length of the input will satisfy 0 < length ≤ 4096.

If you choose to print the output, you may use any positive base up to and including 256.

If you choose unary, make sure interpreter can handle up to 232 - 983056 bytes of output on a machine with 16 GiB of RAM.

Built-ins that compute the Adler-32 checksum are forbidden.

Standard code-golf rules apply.

Test cases

```<code>String:     "Eagles are great!"
Byte array: [69, 97, 103, 108, 101, 115, 32, 97, 114, 101, 32, 103, 114, 101, 97, 116, 33]
Checksum:   918816254

String:     "Programming Puzzles & Code Golf"
Byte array: [80, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 32, 80, 117, 122, 122, 108, 101, 115, 32, 38, 32, 67, 111, 100, 101, 32, 71, 111, 108, 102]
Checksum:   3133147946

String:     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Byte array: [126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126]
Checksum:   68095937

String:     <1040 question marks>
Byte array: <1040 copies of 63>
Checksum:   2181038080
</code>```

Body:
J, 30 bytes

+/(+65536&*)&(65521|+/)&:>:+/\

This could probably be condensed more with a different train.

Usage

Here x $ y creates a list with x copies of y.

   f =: +/(+65536&*)&(65521|+/)&:>:+/\
   f 69 97 103 108 101 115 32 97 114 101 32 103 114 101 97 116 33
918816254
   f 80 114 111 103 114 97 109 109 105 110 103 32 80 117 122 122 108 101 115 32 38 32 67 111 100 101 32 71 111 108 102
3133147946
   f (32 $ 126)
68095937
   f (1040 $ 63)
2181038080
   f (4096 $ 255)
2170679522

Explanation

+/(+65536&*)&(65521|+/)&:>:+/\
f (           g           ) h     Monad train (f g h) y = (f y) g (h y)
+/                                Sum the input list
                           +/\    Sum each prefix of the input, forms a list
x     f   &   g   &:   h    y     Composed verbs, makes (g (h x)) f (g (h y))
                         >:       Increment the sum and increment each prefix sum
               (m f g) y          Hook, makes m f (g y)
                    +/            Sum the prefix sums
              65521|              Take the sum and prefix total mod 65521
    (f g) y                       Hook again
    65536&*                       Multiply the prefix total by 65536
                                  This is a bonded verb, it will only multiply
                                  using a fixed value now
   +                              Add the sum and scaled prefix total


答:
CJam, <s>30</s> 29 bytes

```<code>q~{1$+}*]:)_W>]1fb65521f%2G#b
</code>```

Input as a list of integers.

Test it here.

Explanation

```<code>q~       e# Read and evaluate input.
{        e# Fold this block over the list, computing prefix sums.
  1$+    e#   Copy the last prefix and add the current element.
}*
]        e# Wrap the prefix sums in an array.
:)       e# Increment each. This will sum to HIGH.
_W>      e# Copy the list and truncate to only the last element, i.e.
         e# the sum of the entire input plus 1. This is LOW.
]        e# Wrap both of those lists in an array.
1fb      e# Sum each, by treating it as base 1 digits.
65521f%  e# Take each modulo 65521.
2G#b     e# Treat the list as base 65536 digits, computing 65536*HIGH + LOW.
</code>```

Title: Compute the Adler-32 checksum

Body:
CJam, <s>30</s> 29 bytes

q~{1$+}*]:)_W>]1fb65521f%2G#b

Input as a list of integers.

Test it here.

Explanation

q~       e# Read and evaluate input.
{        e# Fold this block over the list, computing prefix sums.
  1$+    e#   Copy the last prefix and add the current element.
}*
]        e# Wrap the prefix sums in an array.
:)       e# Increment each. This will sum to HIGH.
_W>      e# Copy the list and truncate to only the last element, i.e.
         e# the sum of the entire input plus 1. This is LOW.
]        e# Wrap both of those lists in an array.
1fb      e# Sum each, by treating it as base 1 digits.
65521f%  e# Take each modulo 65521.
2G#b     e# Treat the list as base 65536 digits, computing 65536*HIGH + LOW.


问:
Period of the decimal representation
Write a function which takes a single positive integer n and returns the period of the decimal representation of 1/n.

Test cases:

```<code>1 -> 1               # 1/1 = 1.0000...... = 1._0
2 -> 1               # 1/2 = 0.5000...... = 0.5_0
3 -> 1               # 1/3 = 0.3333...... = 0._3
7 -> 6               # 1/7 = 0.14285714.. = 0._142857
13 -> 6
14 -> 6
123 -> 5
345 -> 22
654 -> 108
12345 -> 822
67890 -> 120
</code>```

This is code-golf. Built-ins or libraries which return the period directly are not permitted. Numbers up to at least 100000 should work within reasonable time (at most several minutes).

答:
Pyth, 13 bytes

```<code>fq.^;yTQ.^;TQ
</code>```

Uses turtle-and-hare algorithm (more information).

Watch it pass every test.

Title: Period of the decimal representation

Body:
Pyth, 13 bytes

fq.^;yTQ.^;TQ

Uses turtle-and-hare algorithm (more information).

Watch it pass every test.


答:
Haskell, 72 bytes

```<code>import Data.Lists
a#b=argmin length[x|x<-powerslice a,not$isInfixOf x b]
</code>```

Usage example: "abcd" # "dabc"-> "cd".

A straightforward implementation: build all substrings of a and keep those which do not appear in b. argmin returns an element of a list which minimizes the function given a the 2nd argument, here: length.

Title: Shortest Unique Substring

Body:
Given (on STDIN, as command line arguments, or as function arguments) two distinct non-empty strings, find and return the shortest substring of the first string which is not a substring of the second. If no such substring exists, you may return the empty string, return any string which isn't a substring of the original string, or throw an exception. If you are returning from a function, you may also return null (or undefined, None, etc.) in this case. If multiple such substrings are tied for the shortest, you may return any one of them.

Strings can consist of any printable ascii characters.

Input given on STDIN will be given with one string on each line. At your request, a single empty line may be added at the end of the input.

This is code golf, so the shortest valid program wins.

SOME TEST CASES

INPUT:

```<code>STRING ONE
STRING TWO
</code>```

OUTPUT:

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

INPUT:

```<code>A&&C
A&$C
</code>```

VALID OUTPUTS:

```<code>&&
&C
</code>```

INPUT:

(Two randomly-generated 80-letter strings)

```<code>QIJYXPYWIWESWBRFWUHEERVQFJROYIXNKPKVDDFFZBUNBRZVUEYKLURBJCZJYMINCZNQEYKRADRYSWMH
HAXUDFLYFSLABUCXUWNHPSGQUXMQUIQYRWVIXGNKJGYUTWMLLPRIZDRLFXWKXOBOOEFESKNCUIFHNLFE
</code>```

ALL VALID OUTPUTS:

```<code>AD
BJ
BR
CZ
DD
EE
ER
EY
EY
FF
FJ
FW
FZ
HE
IJ
IN
IW
JC
JR
JY
KL
KP
KR
KV
LU
MH
MI
NB
NQ
OY
PK
PY
QE
QF
QI
RA
RB
RF
RO
RV
RY
RZ
SW
UE
UH
UN
UR
VD
VQ
VU
WB
WE
WI
WU
XN
XP
YI
YK
YK
YM
YS
YW
YX
ZB
ZJ
ZN
ZV
</code>```

Body:
Haskell, 72 bytes

import Data.Lists
a#b=argmin length[x|x<-powerslice a,not$isInfixOf x b]

Usage example: "abcd" # "dabc"-> "cd".

A straightforward implementation: build all substrings of a and keep those which do not appear in b. argmin returns an element of a list which minimizes the function given a the 2nd argument, here: length.


答:
Factor, <s>112</s> <s>109</s> 103 bytes

Now, this is a literal translation of the algorithm in the question... now that I actually made it, y'know, correct.

```<code>[ [ sum 1 + ] [ [ dup length [1,b] reverse v. ] [ length ] bi + ] bi [ 65521 mod ] bi@ 16 shift bitor ]
</code>```

Ungolfed:

```<code>: adler-32 ( seq -- n )
  [ sum 1 + ]
  [
    [ dup length [1,b] reverse v. ]
    [ length ] bi +
  ] bi
  [ 65521 mod ] bi@
  16 shift bitor
  ;
</code>```

Expects any sequence of numbers or a string (not much difference, though they aren't technically the same).

I don't know how this will perform for the given limit on a version of Factor compiled with 32-bit word-size, but on my 6GB 64-bit 2.2GHz machine:

```<code>IN: scratchpad 1040 63 <array>

--- Data stack:
{ 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ~1026 more~ }
IN: scratchpad [ adler-32 ] time
Running time: 7.326900000000001e-05 seconds

--- Data stack:
2181038080
IN: scratchpad 10,000 63 <array>

--- Data stack:
2181038080
{ 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ~9986 more~ }
IN: scratchpad [ adler-32 ] time
Running time: 0.000531669 seconds
</code>```

Title: Compute the Adler-32 checksum

Body:
Factor, <s>112</s> <s>109</s> 103 bytes

Now, this is a literal translation of the algorithm in the question... now that I actually made it, y'know, correct.

[ [ sum 1 + ] [ [ dup length [1,b] reverse v. ] [ length ] bi + ] bi [ 65521 mod ] bi@ 16 shift bitor ]

Ungolfed:

: adler-32 ( seq -- n )
  [ sum 1 + ]
  [
    [ dup length [1,b] reverse v. ]
    [ length ] bi +
  ] bi
  [ 65521 mod ] bi@
  16 shift bitor
  ;

Expects any sequence of numbers or a string (not much difference, though they aren't technically the same).

I don't know how this will perform for the given limit on a version of Factor compiled with 32-bit word-size, but on my 6GB 64-bit 2.2GHz machine:

IN: scratchpad 1040 63 <array>

--- Data stack:
{ 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ~1026 more~ }
IN: scratchpad [ adler-32 ] time
Running time: 7.326900000000001e-05 seconds

--- Data stack:
2181038080
IN: scratchpad 10,000 63 <array>

--- Data stack:
2181038080
{ 63 63 63 63 63 63 63 63 63 63 63 63 63 63 ~9986 more~ }
IN: scratchpad [ adler-32 ] time
Running time: 0.000531669 seconds


Title: Compute the Adler-32 checksum

Body:
Java, 84 bytes

long a(int[]i){long a=1,b=0;for(int p:i)b=(b+(a=(a+p)%(p=65521)))%p;return b<<16|a;}

If Java solutions are always supposed to be complete compilable code please let me know.

Ungolfed

long a(int[] i) {
    long a = 1, b = 0;
    for (int p : i) b = (b + (a = (a + p) % (p = 65521))) % p;
    return b << 16 | a;
}

Note

You will have to convert the input String to int[] (int[] is one byte shorter than byte[] or char[]).

Output

String:     "Eagles are great!"
Byte Array: [69, 97, 103, 108, 101, 115, 32, 97, 114, 101, 32, 103, 114, 101, 97, 116, 33]
Checksum:   918816254
Expected:   918816254

String:     "Programming Puzzles & Code Golf"
Byte Array: [80, 114, 111, 103, 114, 97, 109, 109, 105, 110, 103, 32, 80, 117, 122, 122, 108, 101, 115, 32, 38, 32, 67, 111, 100, 101, 32, 71, 111, 108, 102]
Checksum:   3133147946
Expected:   3133147946

String:     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
Byte Array: [126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126, 126]
Checksum:   68095937
Expected:   68095937

String:     "?????????...?"
Byte Array: [63, 63, 63, 63, 63, 63, 63, 63, 63, ...,63]
Checksum:   2181038080
Expected:   2181038080


答:
Mathematica, 30 bytes, depth 9, A038668 from A057359

```<code>Floor[#/LucasL@a]~Sum~{a,#}-#&
</code>```

An = ⌊n/L(2)⌋ + ⌊n/L(3)⌋ + ⌊n/L(4)⌋ + ⌊n/L(5)⌋ + ⋯, where L(n) denotes the nth term in the Lucas sequence. The next answer should start with the terms:

```<code>0, 0, 1, 2, 2, 3, 4, 5, 6
</code>```

Title: Evolution of OEIS

Body:
In this challenge, the goal is to recreate the On-Line Encyclopedia of Integer Sequences one sequence at a time.  Similar to the Evolution of Hello World, each answer depends on a previous answer.

Over time, this challenge will create a "family tree" of the OEIS sequences.  It is simple to add on to this tree.

Find a previous answer, which can be at any depth N of the tree.

Determine the first N numbers generated by that answer's sequence.

Find a sequence in OEIS which starts with those same numbers and which hasn't been used before.

Write a program to generate this new sequence you just found.

Submit your answer as depth N+1

Since the level of your answer influences scoring, you should always add your answer onto the tree at the deepest level possible.  If you cannot fit your answer anywhere on the tree, you can start a new branch of the tree and put your answer as depth 1.

Answer Requirements

There are a few ways to output a sequence.

The first option is to write a program or function that inputs a number (from STDIN or as an argument) and returns the Nth number in your chosen sequence.  You can assume that the sequence will be defined for N and that N and S_N are "reasonably sized" (so it won't cause overflows).  You can also use any reasonable indexing, such as 0 indexing, 1 indexing, or the indexing listed under "offset" on the sequence's OEIS page, that doesn't matter.  The term produced by the first index must match the first term of the OEIS entry.

The second option is to write a program or function that inputs a number and returns the first N terms of the sequence.  The first terms of the output must be the first terms of the OEIS entry (you can't leave off the first few terms).  Consecutive terms must be delimited by arbitrary strings of non-digit characters, so 0,1  1.2/3,5;8,11 works but 011235811 does not count.

The third option is to create a program that outputs a continuous stream of numbers.  Similarly to the second option, there must be delimiters between consecutive terms.

Your answer should contain a header like this to aid Stack Snippet parsing:

```<code> # [language], [number] bytes, depth [number], A[new sequence] from A[old sequence]
</code>```

Your answer should contain the code to generate the sequence, along with the first few terms that any descendants will need to contain.  These few terms should be preceded by the exact word terms: so that the controller can use them as part of the tree diagram.  It is also recommended to write a description of the sequence you chose.

If your post is a depth 1 answer and thus has no ancestor, you should simply omit the from A[number] in your header.

Here is an example answer:

```<code># Perl, 26 bytes, depth 3, A026305 from A084912

    various code here
    and here

The next answer should match the following terms:

    1, 4, 20

This sequence is .... and does ....
</code>```

Chaining Requirements

In order to make this challenge more fair, there are restrictions on which answers you can chain yours to. These rules are mostly to prevent a single person from creating a whole branch of the tree by themselves or owning a lot of "root" nodes.

You cannot chain to yourself.

You cannot directly chain two of your answers to the same ancestor.

You cannot make more than one "Level 1" answer.

Also, if the ancestor was of depth N, your post must have depth N+1, even if more than the required number of terms agree.

Scoring

Your score as a user is the sum of the scores of all of your answers.  The score of a single answer is determined by the following formula:

```<code>Answer Score = Sqrt(Depth) * 1024 / (Length + 256)
</code>```

This scoring system should encourage users to submit a large number of deeper answers.  Shorter answers are preferred over longer answers, but depth has a much larger influence.

Below is a stack snippet that generates a leaderboard as well as a tree diagram of all of the answers.  I would like to thank Martin Büttner and d3noob as the sources for a lot of this code.  You should click "Full screen" to see the complete results.

function answersUrl(t){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+t+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(t){answers.push.apply(answers,t.items),t.has_more?getAnswers():process()}})}function shouldHaveHeading(t){var e=!1,r=t.body_markdown.split("\n");try{e|=/^#/.test(t.body_markdown),e|=["-","="].indexOf(r[1][0])>-1,e&=LANGUAGE_REG.test(t.body_markdown)}catch(a){}return e}function shouldHaveScore(t){var e=!1;try{e|=SIZE_REG.test(t.body_markdown.split("\n")[0])}catch(r){}return e}function getAuthorName(t){return t.owner.display_name}function decodeEntities(t){return $("<textarea>").html(t).text()}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading),answers.reverse();var t={},e=[],r=1,a=null,n=1,s=[];answers.forEach(function(t){var r=t.body_markdown.split("\n")[0],a=getAuthorName(t),n=r.match(SEQUENCE_REG)[0];n=n.trim();var o="from A000000";PARENT_REG.test(r)&&(o=r.match(PARENT_REG)[0]),o=o.substring(5).trim(),"A000000"==o&&(o="OEIS");var i="";SEQDATA_REG.test(t.body_markdown)&&(i=t.body_markdown.match(SEQDATA_REG)[1]);for(var u=!0,c=0;c<e.length;++c)u=u&&!(e[c]===n);for(var l=!0,c=0;c<e.length;++c)l=!(!l||e[c]===n||e[c]===n+a||e[c]===o+a);e.push(n),e.push(n+a),e.push(o+a),u&&data.push({name:n,parent:o,term:i+" : ",author:decodeEntities(a),URL:t.share_link}),l&&s.push(t)}),answers.sort(function(t,e){var r=t.body_markdown.split("\n")[0].match(SEQUENCE_REG),a=e.body_markdown.split("\n")[0].match(SEQUENCE_REG);return a>r?-1:r>a?1:void 0}),answers.forEach(function(e){var o=e.body_markdown.split("\n")[0],i=(o.match(NUMBER_REG)[0],(o.match(SIZE_REG)||[0])[0]),u=parseInt((o.match(DEPTH_REG)||[0])[0]).toString(),c=o.match(SEQUENCE_REG)[0],l="from A000000";PARENT_REG.test(o)&&(l=o.match(PARENT_REG)[0]),l=l.substring(5);var d=o.match(LANGUAGE_REG)[1];d.indexOf("]")>0&&(d=d.substring(1,d.indexOf("]")));for(var p=getAuthorName(e),E=!1,h=0;h<s.length;++h)E=E||s[h]===e;if(E){var f=jQuery("#answer-template").html();i!=a&&(n=r),a=i,++r;var m=1024*Math.pow(parseInt(u),.5)/(parseInt(i)+256);f=f.replace("{{SEQUENCE}}",c).replace("{{SEQUENCE}}",c).replace("{{NAME}}",p).replace("{{LANGUAGE}}",d).replace("{{SIZE}}",i).replace("{{DEPTH}}",u).replace("{{LINK}}",e.share_link),f=jQuery(f),jQuery("#answers").append(f),t[p]=t[p]||{lang:d,user:p,size:"0",numanswers:"0",link:e.share_link},t[p].size=(parseFloat(t[p].size)+m).toString(),t[p].numanswers=(parseInt(t[p].numanswers)+1).toString()}});var o=[];for(var i in t)t.hasOwnProperty(i)&&o.push(t[i]);o.sort(function(t,e){return parseFloat(t.size)>parseFloat(e.size)?-1:parseFloat(t.size)<parseFloat(e.size)?1:0});for(var u=0;u<o.length;++u){var c=jQuery("#language-template").html(),i=o[u];c=c.replace("{{RANK}}",u+1+".").replace("{{NAME}}",i.user).replace("{{NUMANSWERS}}",i.numanswers).replace("{{SIZE}}",i.size),c=jQuery(c),jQuery("#languages").append(c)}createTree()}function createTree(){function t(){var t=i.nodes(root).reverse(),e=i.links(t);t.forEach(function(t){t.y=180*t.depth});var r=c.selectAll("g.node").data(t,function(t){return t.id||(t.id=++o)}),a=r.enter().append("g").attr("class","node").attr("transform",function(t){return"translate("+t.y+","+t.x+")"});a.append("a").attr("xlink:href",function(t){return t.URL}).append("circle").attr("r",10).style("fill","#fff"),a.append("text").attr("x",function(){return 0}).attr("y",function(){return 20}).attr("dy",".35em").attr("text-anchor",function(){return"middle"}).text(function(t){return t.term+t.name}).style("fill-opacity",1),a.append("text").attr("x",function(){return 0}).attr("y",function(){return 35}).attr("dy",".35em").attr("text-anchor",function(){return"middle"}).text(function(t){return t.author}).style("fill-opacity",1);var n=c.selectAll("path.link").data(e,function(t){return t.target.id});n.enter().insert("path","g").attr("class","link").attr("d",u)}var e=data.reduce(function(t,e){return t[e.name]=e,t},{}),r=[];data.forEach(function(t){var a=e[t.parent];a?(a.children||(a.children=[])).push(t):r.push(t)});var a={top:20,right:120,bottom:20,left:120},n=3203-a.right-a.left,s=4003-a.top-a.bottom,o=0,i=d3.layout.tree().size([s,n]),u=d3.svg.diagonal().projection(function(t){return[t.y,t.x]}),c=d3.select("body").append("svg").attr("width",n+a.right+a.left).attr("height",s+a.top+a.bottom).append("g").attr("transform","translate("+a.left+","+a.top+")");root=r[0],t(root)}var QUESTION_ID=49223,ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",data=[{name:"OEIS",parent:"null",term:"",author:"",URL:"https://oeis.org/"}],answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:<(?:s>[^&]*<\/s>|[^&]+>)[^\d&]*)*,)/,DEPTH_REG=/\d+, A/,NUMBER_REG=/\d+/,LANGUAGE_REG=/^#*\s*([^,]+)/,SEQUENCE_REG=/A\d+/,PARENT_REG=/from\s*A\d+/,SEQDATA_REG=/terms:\s*(?:(?:-)?\d+,\s*)*((?:-)?\d+)/;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align: left !important}#answer-list{padding: 10px; width: 550px; float: left;}#language-list{padding: 10px; width: 290px; float: left;}table thead{font-weight: bold;}table td{padding: 5px;}.node circle{fill: #fff; stroke: steelblue; stroke-width: 3px;}.node text{font: 12px sans-serif;}.link{fill: none; stroke: #ccc; stroke-width: 2px;}</code>```

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

Sequence List

 Sequence	Author	Language	Size	Depth

Leaderboard

 Rank	User	Answers	Score

 {{SEQUENCE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	{{DEPTH}}	Link

 {{RANK}}	{{NAME}}	{{NUMANSWERS}}	{{SIZE}}

```

Body:
Mathematica, 30 bytes, depth 9, A038668 from A057359

Floor[#/LucasL@a]~Sum~{a,#}-#&

An = ⌊n/L(2)⌋ + ⌊n/L(3)⌋ + ⌊n/L(4)⌋ + ⌊n/L(5)⌋ + ⋯, where L(n) denotes the nth term in the Lucas sequence. The next answer should start with the terms:

0, 0, 1, 2, 2, 3, 4, 5, 6


答:
Pyth, <s>25</s> <s>24</s> 23 bytes

1 byte thanks to @Jakube.

1 more byte thanks to @Jakube.

```<code>i%R65521sMeBhMsM._Q^4 8
</code>```

Try it online!

Translation of my answer in Jelly.

Title: Compute the Adler-32 checksum

Body:
Pyth, <s>25</s> <s>24</s> 23 bytes

1 byte thanks to @Jakube.

1 more byte thanks to @Jakube.

i%R65521sMeBhMsM._Q^4 8

Try it online!

Translation of my answer in Jelly.


问:
Run through an array
We all often hear the idiom "walk through the array" to mean "map the function over the following array". However, I need it done (now!), so I want you to run through the array.

How do I run?

Imagine there's a wild pack of wolves behind you

Running through an array is like walking through one, except you  can skip over elements. Yes, it's sometimes messy, but it (generally) works. "Which elements are skipped?", you may ask. Well, this is done at random. Let's walk through running through the array!

Let e be the current element.

Let random generate a random float in [0,1). If random() < 0.5, then you go the next element and then to step 1. (You may generate a number by other means, so long as their is an (ideally) equal chance of skipping and remaining. E.g., you can use choose an element from a two-member set and perform the action based on the result.)

Otherwise, you perform function f on e.

Objective

Given an array/list/string like either A and a number K, run through the array, adding K to each member accessed. Output/return this array. A will only contain non-negative integers, and K will only ever be a non-negative integers. This is a code-golf, so the shortest program in bytes wins.

Test cases (examples)

```<code>K, A => possible K'
[1, 2, 3, 4], 0 => [1, 2, 3, 4]
[1, 2, 3, 4], 1 => [1, 3, 3, 5]
[0, 0, 0, 0], 2 => [2, 0, 0, 2]
</code>```

答:
Java, 84 bytes

```<code>int[]r(int[]A,int K){for(int i=0;i<A.length;A[i++]+=Math.random()>.5?0:K);return A;}
</code>```

Ungolfed

```<code>int[] r(int[] A, int K) {
    for (int i = 0;
         i < A.length;
         A[i++] += Math.random() > .5 ? 0 : K);
    return A;
}
</code>```

Notes

The afterthought of the loop could also be it's body, there is no difference in size.

The input array is modified but the statement does not contain a restriction regarding this issue. If you would count the modified array as a form of "Output/return", you could shave off another 9 bytes by removing return A;. The return type would need to be changed from int[] to void. This however does not save additional bytes since an additional space is needed between void and r.

Shorter version (As mentioned in the note), 75 bytes

```<code>void r(int[]A,int K){for(int i=0;i<A.length;)A[i++]+=Math.random()>.5?0:K;}
</code>```

Output

```<code>[1, 2, 3, 4], 0 => [1, 2, 3, 4]
[1, 2, 3, 4], 1 => [1, 3, 3, 4]
[1, 2, 3, 4], 2 => [3, 2, 3, 4]
[1, 2, 3, 4], 3 => [4, 5, 3, 7]
[1, 2, 3, 4], 4 => [5, 2, 3, 8]
[1, 2, 3, 4], 5 => [6, 2, 8, 9]
</code>```

Title: Run through an array

Body:
Java, 84 bytes

int[]r(int[]A,int K){for(int i=0;i<A.length;A[i++]+=Math.random()>.5?0:K);return A;}

Ungolfed

int[] r(int[] A, int K) {
    for (int i = 0;
         i < A.length;
         A[i++] += Math.random() > .5 ? 0 : K);
    return A;
}

Notes

The afterthought of the loop could also be it's body, there is no difference in size.

The input array is modified but the statement does not contain a restriction regarding this issue. If you would count the modified array as a form of "Output/return", you could shave off another 9 bytes by removing return A;. The return type would need to be changed from int[] to void. This however does not save additional bytes since an additional space is needed between void and r.

Shorter version (As mentioned in the note), 75 bytes

void r(int[]A,int K){for(int i=0;i<A.length;)A[i++]+=Math.random()>.5?0:K;}

Output

[1, 2, 3, 4], 0 => [1, 2, 3, 4]
[1, 2, 3, 4], 1 => [1, 3, 3, 4]
[1, 2, 3, 4], 2 => [3, 2, 3, 4]
[1, 2, 3, 4], 3 => [4, 5, 3, 7]
[1, 2, 3, 4], 4 => [5, 2, 3, 8]
[1, 2, 3, 4], 5 => [6, 2, 8, 9]


问:
Print the character names
Every Unicode character has a name, like "LATIN CAPITAL LETTER A". A Unicode character name may contain only uppercase letters, white spaces, and the minus sign.

Write a program that reads a text and outputs the names of each character on a new line. For example, if the input were "Hello, World!", the output would be

```<code>LATIN CAPITAL LETTER H
LATIN SMALL LETTER E
LATIN SMALL LETTER L
LATIN SMALL LETTER L
LATIN SMALL LETTER O
COMMA
SPACE
LATIN CAPITAL LETTER W
LATIN SMALL LETTER O
LATIN SMALL LETTER R
LATIN SMALL LETTER L
LATIN SMALL LETTER D
EXCLAMATION MARK
</code>```

Input should come from a file or from user input, not just a string in code.

Output should be written to a file or stdout or printed to the screen.

Internet and external libraries are not allowed, all necessary data should be in the code.

Assume that the input only contains printable ASCII characters in the Basic Latin code range 32-126. You can ignore a trailing newline.

All programming languages allowed. Shortest code in bytes wins.

The official Unicode character names can be found here. Other sources:

http://www.w3schools.com/charsets/ref_utf_basic_latin.asp

http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000

This is my first question so I'd appreciate any suggestion if this can be improved.

For the purpose of this challenge the list below shall be normative.

```<code>    32  0020        SPACE
!   33  0021        EXCLAMATION MARK
"   34  0022        QUOTATION MARK
#   35  0023        NUMBER SIGN
$   36  0024        DOLLAR SIGN
%   37  0025        PERCENT SIGN
&   38  0026        AMPERSAND
'   39  0027        APOSTROPHE
(   40  0028        LEFT PARENTHESIS
)   41  0029        RIGHT PARENTHESIS
*   42  002A        ASTERISK
+   43  002B        PLUS SIGN
,   44  002C        COMMA
-   45  002D        HYPHEN-MINUS
.   46  002E        FULL STOP
/   47  002F        SOLIDUS
0   48  0030        DIGIT ZERO
1   49  0031        DIGIT ONE
2   50  0032        DIGIT TWO
3   51  0033        DIGIT THREE
4   52  0034        DIGIT FOUR
5   53  0035        DIGIT FIVE
6   54  0036        DIGIT SIX
7   55  0037        DIGIT SEVEN
8   56  0038        DIGIT EIGHT
9   57  0039        DIGIT NINE
:   58  003A        COLON
;   59  003B        SEMICOLON
<   60  003C        LESS-THAN SIGN
=   61  003D        EQUALS SIGN
>   62  003E        GREATER-THAN SIGN
?   63  003F        QUESTION MARK
@   64  0040        COMMERCIAL AT
A   65  0041        LATIN CAPITAL LETTER A
B   66  0042        LATIN CAPITAL LETTER B
C   67  0043        LATIN CAPITAL LETTER C
D   68  0044        LATIN CAPITAL LETTER D
E   69  0045        LATIN CAPITAL LETTER E
F   70  0046        LATIN CAPITAL LETTER F
G   71  0047        LATIN CAPITAL LETTER G
H   72  0048        LATIN CAPITAL LETTER H
I   73  0049        LATIN CAPITAL LETTER I
J   74  004A        LATIN CAPITAL LETTER J
K   75  004B        LATIN CAPITAL LETTER K
L   76  004C        LATIN CAPITAL LETTER L
M   77  004D        LATIN CAPITAL LETTER M
N   78  004E        LATIN CAPITAL LETTER N
O   79  004F        LATIN CAPITAL LETTER O
P   80  0050        LATIN CAPITAL LETTER P
Q   81  0051        LATIN CAPITAL LETTER Q
R   82  0052        LATIN CAPITAL LETTER R
S   83  0053        LATIN CAPITAL LETTER S
T   84  0054        LATIN CAPITAL LETTER T
U   85  0055        LATIN CAPITAL LETTER U
V   86  0056        LATIN CAPITAL LETTER V
W   87  0057        LATIN CAPITAL LETTER W
X   88  0058        LATIN CAPITAL LETTER X
Y   89  0059        LATIN CAPITAL LETTER Y
Z   90  005A        LATIN CAPITAL LETTER Z
[   91  005B        LEFT SQUARE BRACKET
\   92  005C        REVERSE SOLIDUS
]   93  005D        RIGHT SQUARE BRACKET
^   94  005E        CIRCUMFLEX ACCENT
_   95  005F        LOW LINE
`   96  0060        GRAVE ACCENT
a   97  0061        LATIN SMALL LETTER A
b   98  0062        LATIN SMALL LETTER B
c   99  0063        LATIN SMALL LETTER C
d   100 0064        LATIN SMALL LETTER D
e   101 0065        LATIN SMALL LETTER E
f   102 0066        LATIN SMALL LETTER F
g   103 0067        LATIN SMALL LETTER G
h   104 0068        LATIN SMALL LETTER H
i   105 0069        LATIN SMALL LETTER I
j   106 006A        LATIN SMALL LETTER J
k   107 006B        LATIN SMALL LETTER K
l   108 006C        LATIN SMALL LETTER L
m   109 006D        LATIN SMALL LETTER M
n   110 006E        LATIN SMALL LETTER N
o   111 006F        LATIN SMALL LETTER O
p   112 0070        LATIN SMALL LETTER P
q   113 0071        LATIN SMALL LETTER Q
r   114 0072        LATIN SMALL LETTER R
s   115 0073        LATIN SMALL LETTER S
t   116 0074        LATIN SMALL LETTER T
u   117 0075        LATIN SMALL LETTER U
v   118 0076        LATIN SMALL LETTER V
w   119 0077        LATIN SMALL LETTER W
x   120 0078        LATIN SMALL LETTER X
y   121 0079        LATIN SMALL LETTER Y
z   122 007A        LATIN SMALL LETTER Z
{   123 007B        LEFT CURLY BRACKET
|   124 007C        VERTICAL LINE
}   125 007D        RIGHT CURLY BRACKET
~   126 007E        TILDE
</code>```

答:
Factor, 58 bytes

```<code>[ readln [ char>name "-"" " replace >upper print ] each ]
</code>```

Pretty simple; does the exact same thing as the Java and Perl 6 answers.

Title: Print the character names

Body:
Factor, 58 bytes

[ readln [ char>name "-"" " replace >upper print ] each ]

Pretty simple; does the exact same thing as the Java and Perl 6 answers.