答:
RProgN, 142 Bytes, Non-competing

```<code>function tostack 'b' asoc stack 'a' asoc 0 'v' asoc b pop byte 'o' asoc b len while [ v o b pop byte ] 'o' asoc - + 'v' asoc b len end [ v end
</code>```

Non-competing, as the 'tostack' command was added after the discovery of this challenge (even though it has a terrible byte count)

Test Cases

```<code>Hello, World!
-39

Cool, huh?
-4
</code>```

Explanation

```<code>function                        # Push the function between this and end to the stack
    tostack 'b' asoc            # Convert the implicit input to a stack, associate it with 'b'
    0 'v' asoc                  # Push 0 to the stack, associate it with 'v'
    b pop byte 'o' asoc         # Pop the top value of b (The end of the input), get the byte value, associate it with 'o'.
    b len                       # Push the size of b to the stack
    while [                     # While the top of the stack is truthy, pop the top of the stack
        v                       # Push v to the stack
            o                   # Push o to the stack
            b pop byte          # Pop the top value of b, push the byte value of that to the stack
            ] 'o' asoc          # Push a copy of the top of the stack, associate it with 'o'
            -                   # Subtract the top of the stack from one underneith that, In this case, the old value of o and the byte.
        +                       # Sum the top of the stack and underneith that, that is, the difference of the old value and new, and the total value
        'v' asoc                # Associate it with 'v'
        b len                   # Push the size of b to the stack (which acts as the conditional for the next itteration)
    end [                       # Pop the top of the stack, which will likely be the left over size of b
    v                           # Push the value of v to the top of the stack
end                             # Implicitely returned / printed
</code>```

RProgN is an esoteric language I've been working on with Reverse Polish Notation in mind. It's currently pretty verbose, with it's variable assignment being 4 characters, and such, however I plan to in future add a bit of syntatic sugar.

Also, RProgN implicitly accesses arguments from the stack, and returns them the same way. Any string data left in the stack after the program has finished, is implicitly printed.

Title: Output a string's cumulative slope

Body:
Challenge

Given a string such as Hello World!, break it down into its character values: 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33.

Then calculate the difference between each consecutive pair of characters: 29, 7, 0, 3, -79, 55, 24, 3, -6, -8, -67.

Finally, sum them and print the final result: -39.

Rules

Standard loopholes apply

No using pre-made functions that perform this exact task

Creative solutions encouraged

Have fun

This is marked as code-golf, the shortest answer in bytes wins but will not be selected.

Body:
RProgN, 142 Bytes, Non-competing

function tostack 'b' asoc stack 'a' asoc 0 'v' asoc b pop byte 'o' asoc b len while [ v o b pop byte ] 'o' asoc - + 'v' asoc b len end [ v end

Non-competing, as the 'tostack' command was added after the discovery of this challenge (even though it has a terrible byte count)

Test Cases

Hello, World!
-39

Cool, huh?
-4

Explanation

function                        # Push the function between this and end to the stack
    tostack 'b' asoc            # Convert the implicit input to a stack, associate it with 'b'
    0 'v' asoc                  # Push 0 to the stack, associate it with 'v'
    b pop byte 'o' asoc         # Pop the top value of b (The end of the input), get the byte value, associate it with 'o'.
    b len                       # Push the size of b to the stack
    while [                     # While the top of the stack is truthy, pop the top of the stack
        v                       # Push v to the stack
            o                   # Push o to the stack
            b pop byte          # Pop the top value of b, push the byte value of that to the stack
            ] 'o' asoc          # Push a copy of the top of the stack, associate it with 'o'
            -                   # Subtract the top of the stack from one underneith that, In this case, the old value of o and the byte.
        +                       # Sum the top of the stack and underneith that, that is, the difference of the old value and new, and the total value
        'v' asoc                # Associate it with 'v'
        b len                   # Push the size of b to the stack (which acts as the conditional for the next itteration)
    end [                       # Pop the top of the stack, which will likely be the left over size of b
    v                           # Push the value of v to the top of the stack
end                             # Implicitely returned / printed

RProgN is an esoteric language I've been working on with Reverse Polish Notation in mind. It's currently pretty verbose, with it's variable assignment being 4 characters, and such, however I plan to in future add a bit of syntatic sugar.

Also, RProgN implicitly accesses arguments from the stack, and returns them the same way. Any string data left in the stack after the program has finished, is implicitly printed.


问:
Number Triangles

Credit

My thanks to Rand Al'Thor's letter-based question for the inspiration for this code-golf challenge.

Background

The nature of this challenge is based off the algorithm mentioned by Rand in his "A Triangle Formed of Three Letters":

Start with a sequence of 10 letters each of which is X, Y, or Z.

Under each row, construct the next row as follows. If two adjacent letters are the same, write the same letter beneath them; if they're different, write the third letter beneath them.

You would then repeat the previous step until you have one letter in your tenth row.

Challenge

We're going to put a mathematical spin on the above algorithm:

Let's start with a sequences of 10 digits, each separated by a space, and each of which is either 1, 2 or 3.

Under each row, construct the next row as follows. If two adjacent digits are the same, write the same digit beneath them; if they're different, write the third digit beneath them.

Repeat the previous step until you have one final number.

So, following this algorithm, if starting with the row 1 2 3 3 1 3 1 3 1 2, for example, the following triangle is generated:

```<code>Input: 1 2 3 3 1 3 1 3 1 2

Output:

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

I'm also curious to know the sum of all the digits in the number triangle, so add all these digits, and put this total in an eleventh row, right-justified to the last digit in the first row. So, our number triangle will look something like the following (spaces in my example are represented below by the . character to show formatting.)

```<code>Input: 1 2 3 3 1 3 1 3 1 2

Output:

1.2.3.3.1.3.1.3.1.2
.3.1.3.2.2.2.2.2.3.
..2.2.1.2.2.2.2.1..
...2.3.3.2.2.2.3...
....1.3.1.2.2.1....
.....2.2.3.2.3.....
......2.1.1.1......
.......3.1.1.......
........2.1........
.........3.........
................109
</code>```

Your challenge is to write code that can start with an inputted string/array/etc. of ten digits, as per my example, and then apply the algorithm to generate the ten rows that would create the number triangle, followed by an 11th row that would display the total of all digits with right-justification.

Testing

Testing of this string can be performed with a randomly generated string of ten digits of your choosing, or one generated from the snippet below...

c1=()=>('1331123221'+(Math.random()*(1<<24)|0).toString(4)).replace(/0/g, "").slice(-10).split("").join(" ");

$("#btn").click(function(){
  $("#str").val(c1());
});```
<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>
<input type="text" id="str"><button id="btn">Get numbers</button>
<br>
Please use this snippet to generate a starting row for testing your code. Alternatively, you can also use a string of your choice, so long as it's ten digits (ranging from 1 to 3), separated by single spaces.</code>```

Rules

Code-golf rules apply, so lowest number of bytes wins the challenge. In the event that there are two entries with the same low score, the winner will be awarded based on the number of up-votes.

What we're basically after is 11 rows, 19 characters long... How you render your final output is entirely up to you: array, console, file output, STDOUT, etc., so please use whatever output method you like that will work to your advantage. The only rule in the output is that we have 11 rows with 19 characters in each row in a similar format to above...

If it helps your code, use whatever separator for the digits... Just remember that legibility may be a contributing factor.

No silly loopholes.

Hard-coding of the input is not allowed. The purposes of this code is such that it can be used to produce different results each time with varying input. Hard-coding of 1 1 1 1 1 1 1 1 1 1 for example, completely negates the whole point of the algorithm.

Look forward to seeing what you all can come up with!

答:
Ruby, <s>134</S> 101 bytes

Using JHM's modulo trick.

```<code>->a{b=*a
(0..8).map{|i|[" "*i,a=a.each_cons(2).map{|x,y|b<<n=3-(x+y)%3
n}]*" "}<<"%19d"%b.reduce(:+)}
</code>```

See it on eval.in: https://eval.in/649993

ContentLicense: CC BY-SA 3.0

Title: Number Triangles

Body:
Ruby, <s>134</S> 101 bytes

Using JHM's modulo trick.

->a{b=*a
(0..8).map{|i|[" "*i,a=a.each_cons(2).map{|x,y|b<<n=3-(x+y)%3
n}]*" "}<<"%19d"%b.reduce(:+)}

See it on eval.in: https://eval.in/649993


问:
Output the next kana
Japanese kana characters correspond to a single sound in the Japanese language. With the exception of ん (n), every other kana consists of a consonant part and a vowel part. There is a natural ordering to Japanese kana, a sort of "alphabetical order", which is typically arranged in a 10 by 5 table:

```<code>   |   a    i    u    e    o
-----------------------------
*  |   a    i    u    e    o
k  |  ka   ki   ku   ke   ko
s  |  sa   si   su   se   so
t  |  ta   ti   tu   te   to
n  |  na   ni   nu   ne   no
h  |  ha   hi   hu   he   ho
m  |  ma   mi   mu   me   mo
y  |  ya        yu        yo
r  |  ra   ri   ru   re   ro
w  |  wa                  wo
</code>```

This ordering is called gojuuon, or "fifty sounds", even though some of the fifty cells in the table are in fact empty.

The challenge

Input will be any of the listed kana above, with the exception for wo. Your program or function should output the next kana along in left-to-right, top-to-bottom reading order, e.g:

```<code>Input       Output
------------------
a     ->    i
i     ->    u
o     ->    ka
ke    ->    ko
so    ->    ta
ni    ->    nu
ya    ->    yu
yu    ->    yo
wa    ->    wo
wo    ->    (undefined behaviour)
</code>```

With the exception of an optional single trailing newline, there should be no leading or trailing whitespace in the output.

This is code-golf, so the goal is to minimise program size, in bytes.

Additional notes

In order to keep things simple, this challenge uses Nihon-shiki romanisation. Hepburn romanisation is more common, but has a few kinks which make things more annoying for golf (e.g. si becomes shi, hu becomes fu).

Kana do exist for the empty spots (see Japanese SE), but they were either non-standard or are now obsolete.

Title: Output the next kana

Body:
C, <s>138</s> 135 bytes

char*s="aiueokstnhmyrw";i,j;k(*v){j=strchr(s,*v>>8)-s;i=strchr(s,*v)-s;j=i<4?i++:j<4?j-~(2520%i&3):!++i;printf("%c%c",s[i],i<5?:s[j]);}

Wandbox


问:
Is this number a prime?
Believe it or not, we do not yet have a code golf challenge for a simple primality test. While it may not be the most interesting challenge, particularly for "usual" languages, it can be nontrivial in many languages.

Rosetta code features lists by language of idiomatic approaches to primality testing, one using the Miller-Rabin test specifically and another using trial division. However, "most idiomatic" often does not coincide with "shortest." In an effort to make Programming Puzzles and Code Golf the go-to site for code golf, this challenge seeks to compile a catalog of the shortest approach in every language, similar to "Hello, World!" and Golf you a quine for great good!.

Furthermore, the capability of implementing a primality test is part of our definition of programming language, so this challenge will also serve as a directory of proven programming languages.

Task

Write a full program that, given a strictly positive integer n as input, determines whether n is prime and prints a truthy or falsy value accordingly.

For the purpose of this challenge, an integer is prime if it has exactly two strictly positive divisors. Note that this excludes 1, who is its only strictly positive divisor.

Your algorithm must be deterministic (i.e., produce the correct output with probability 1) and should, in theory, work for arbitrarily large integers. In practice, you may assume that the input can be stored in your data type, as long as the program works for integers from 1 to 255.

Input

If your language is able to read from STDIN, accept command-line arguments or any other alternative form of user input, you can read the integer as its decimal representation, unary representation (using a character of your choice), byte array (big or little endian) or single byte (if this is your languages largest data type).

If (and only if) your language is unable to accept any kind of user input, you may hardcode the input in your program.

In this case, the hardcoded integer must be easily exchangeable. In particular, it may appear only in a single place in the entire program.

For scoring purposes, submit the program that corresponds to the input 1.

Output

Output has to be written to STDOUT or closest alternative.

If possible, output should consist solely of a truthy or falsy value (or a string representation thereof), optionally followed by a single newline.

The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation.

Additional rules

This is not about finding the language with the shortest approach for prime testing, this is about finding the shortest approach in every language. Therefore, no answer will be marked as accepted.

Submissions in most languages will be scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8.

The language Piet, for example, will be scored in codels, which is the natural choice for this language.

Some languages, like Folders, are a bit tricky to score. If in doubt, please ask on Meta.

Unlike our usual rules, feel free to use a language (or language version) even if it's newer than this challenge. If anyone wants to abuse this by creating a language where the empty program performs a primality test, then congrats for paving the way for a very boring answer.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Headsecks or Unary), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

Built-in functions for testing primality are allowed. This challenge is meant to catalog the shortest possible solution in each language, so if it's shorter to use a built-in in your language, go for it.

Unless they have been overruled earlier, all standard code-golf rules apply, including the http://meta.codegolf.stackexchange.com/q/1061.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalog as complete as possible. However, do primarily upvote answers in languages where the author actually had to put effort into golfing the code.

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
RProgN, 102 Bytes

```<code> 'i' asoc true i 1 - ] 1 > while [ 'a' asoc i a / i a // = if [ [ false else [ end a 1 - ] 1 > end [ [
</code>```

Explanation

```<code> 'i' asoc           # Associate the implicit input with i
true i              # Push true to the stack, push i to the stack
1 -                 # Subtact 1 from the top of the stack
] 1 >               # Duplicate the top value of the stack, compare that it's larger than 1
while               # While the top of the stack contains a truthy value
    [               # Pop the top of the stack (The conditional in this case)
    'a' asoc        # Associate the top of the stack with a
    i a /           # Push i divided by a to the top of the stack
    i a // =        # Push i integeral divided by a to the top of the stack, compare the top and underneith the top for equality
    if              # if i/a = floor(i/a), essentially
        [ [ false   # Pop the conditional, and the 'true' we slipped in earlier, push false in in place of it
    else            #
        [           # Pop the conditional anyway
    end             #
    a 1 - ] 1 >     # Subtract 1 from a, duplicate it, and compare that it's larger than 1
end                 #
[ [                 # Pop the conditional, the value of a, which leaves only the bottom value we previously inserted, which is implicitly printed
</code>```

RProgN doesn't have any method of input as of yet, as such, Any input needs to be written in pure form at the very start of the code, such that 23 'i' asoc .... An Extra byte is added to the score, because a space is required in front of any command.

Title: Is this number a prime?

Body:
RProgN, 102 Bytes

 'i' asoc true i 1 - ] 1 > while [ 'a' asoc i a / i a // = if [ [ false else [ end a 1 - ] 1 > end [ [

Explanation

 'i' asoc           # Associate the implicit input with i
true i              # Push true to the stack, push i to the stack
1 -                 # Subtact 1 from the top of the stack
] 1 >               # Duplicate the top value of the stack, compare that it's larger than 1
while               # While the top of the stack contains a truthy value
    [               # Pop the top of the stack (The conditional in this case)
    'a' asoc        # Associate the top of the stack with a
    i a /           # Push i divided by a to the top of the stack
    i a // =        # Push i integeral divided by a to the top of the stack, compare the top and underneith the top for equality
    if              # if i/a = floor(i/a), essentially
        [ [ false   # Pop the conditional, and the 'true' we slipped in earlier, push false in in place of it
    else            #
        [           # Pop the conditional anyway
    end             #
    a 1 - ] 1 >     # Subtract 1 from a, duplicate it, and compare that it's larger than 1
end                 #
[ [                 # Pop the conditional, the value of a, which leaves only the bottom value we previously inserted, which is implicitly printed

RProgN doesn't have any method of input as of yet, as such, Any input needs to be written in pure form at the very start of the code, such that 23 'i' asoc .... An Extra byte is added to the score, because a space is required in front of any command.


问:
Output a string's cumulative slope

Challenge

Given a string such as Hello World!, break it down into its character values: 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33.

Then calculate the difference between each consecutive pair of characters: 29, 7, 0, 3, -79, 55, 24, 3, -6, -8, -67.

Finally, sum them and print the final result: -39.

Rules

Standard loopholes apply

No using pre-made functions that perform this exact task

Creative solutions encouraged

Have fun

This is marked as code-golf, the shortest answer in bytes wins but will not be selected.

答:
Haskell, 61 bytes

```<code>import Data.Char
f s=sum$g$ord<$>s
g(a:b:r)=b-a:g(b:r)
g _=[]
</code>```

Title: Output a string's cumulative slope

Body:
Haskell, 61 bytes

import Data.Char
f s=sum$g$ord<$>s
g(a:b:r)=b-a:g(b:r)
g _=[]


问:
Simple cat program
One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after the Unix shell utility cat it is of course much less powerful than the real thing, which is normally used to print (and concatenate) several files read from disc.

Task

You should write a full program which reads the contents of the standard input stream and writes them verbatim to the standard output stream. If and only if your language does not support standard input and/or output streams (as understood in most languages), you may instead take these terms to mean their closest equivalent in your language (e.g. JavaScript's prompt and alert). These are the only admissible forms of I/O, as any other interface would largely change the nature of the task and make answers much less comparable.

The output should contain exactly the input and nothing else. The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation. This also applies to trailing newlines. If the input does not contain a trailing newline, the output shouldn't include one either! (The only exception being if your language absolutely always prints a trailing newline after execution.)

Output to the standard error stream is ignored, so long as the standard output stream contains the expected output. In particular, this means your program can terminate with an error upon hitting the end of the stream (EOF), provided that doesn't pollute the standard output stream. If you do this, I encourage you to add an error-free version to your answer as well (for reference).

As this is intended as a challenge within each language and not between languages, there are a few language specific rules:

If it is at all possible in your language to distinguish null bytes in the standard input stream from the EOF, your program must support null bytes like any other bytes (that is, they have to be written to the standard output stream as well).

If it is at all possible in your language to support an arbitrary infinite input stream (i.e. if you can start printing bytes to the output before you hit EOF in the input), your program has to work correctly in this case. As an example yes | tr -d \\n | ./my_cat should print an infinite stream of ys. It is up to you how often you print and flush the standard output stream, but it must be guaranteed to happen after a finite amount of time, regardless of the stream (this means, in particular, that you cannot wait for a specific character like a linefeed before printing).

Please add a note to your answer about the exact behaviour regarding null-bytes, infinite streams, and extraneous output.

Additional rules

This is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

Submissions in most languages will be scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8.

Some languages, like Folders, are a bit tricky to score. If in doubt, please ask on Meta.

Feel free to use a language (or language version) even if it's newer than this challenge. Languages specifically written to submit a 0-byte answer to this challenge are fair game but not particularly interesting.

Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

Also note that languages do have to fulfil our usual criteria for programming languages.

If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Headsecks or Unary), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

Unless they have been overruled earlier, all standard code-golf rules apply, including the http://meta.codegolf.stackexchange.com/q/1061.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the author actually had to put effort into golfing the code.

Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Racket, 52 bytes

A classical approach.

(copy-port(current-input-port)(current-output-port))
```

In Racket, default settings are stored in parameters which are invoked to obtain their value (or invoked with an argument to set them). This mechanism is also used to access/set the default input and output ports.

Title: Simple cat program

Body:
Racket, 52 bytes

A classical approach.

(copy-port(current-input-port)(current-output-port))

In Racket, default settings are stored in parameters which are invoked to obtain their value (or invoked with an argument to set them). This mechanism is also used to access/set the default input and output ports.


问:
Draw the Union Jack

Preface

There are many "draw x flag" challenges, and upon searching it turns out there are no challenges to draw the union Jack! I feel like this would be a harder flag to draw but it should still be possible.

Challenge

Draw the Union Jack. It can be outputted to a file in any freely available graphics file format or drawn onto the screen.

Code Golf rules apply, shortest code in bytes wins.

Standard loopholes apply.

No builtins for flag drawing allowed.

Dimensions shall be as below. Minimum size 600x300 pixels (or units if your language supports only scalable graphics.) Maximum error 1 pixel.

Colours shall be red, white and blue as defined by your language or its documentation, or #CC0000, #FFFFFF and #003399 per Wikipedia page.

答:
Python 2, 265 bytes

r="D\0\0"
b="\0\x173"
w="U"*3
N=20*(270*w+60*r+270*w)
L=190*[b]+60*[w]+40*[r]+20*[w]+190*[b]
j=''.join
F=lambda p:j([j(L[150-p*100+i:150+p*150+i:p])+20*w+60*r+20*w+j(L[345-p*145-i:345+p*105-i:p])for i in range(0,200,2)])
print"P6 600 300 85 "+F(-1)+N+36000*r+N+F(1)
```

<p>Output as binary PPM, usage:</p>

<pre class="lang-python prettyprint-override"><code>python golf_unionjack.py > unionjack.ppm
</code>```

L represents a vertical slice of the diagonal parts and F uses the (sort of) symmetry to save code and calculate the indices for upper and lower part.

Title: Draw the Union Jack

Body:
Python 2, 265 bytes

r="D\0\0"
b="\0\x173"
w="U"*3
N=20*(270*w+60*r+270*w)
L=190*[b]+60*[w]+40*[r]+20*[w]+190*[b]
j=''.join
F=lambda p:j([j(L[150-p*100+i:150+p*150+i:p])+20*w+60*r+20*w+j(L[345-p*145-i:345+p*105-i:p])for i in range(0,200,2)])
print"P6 600 300 85 "+F(-1)+N+36000*r+N+F(1)

Output as binary PPM, usage:

python golf_unionjack.py > unionjack.ppm

L represents a vertical slice of the diagonal parts and F uses the (sort of) symmetry to save code and calculate the indices for upper and lower part.


问:
Pre-order + post-order to in-order

Task

Given the pre-order and post-order traversals of a full binary tree, return its in-order traversal.

The traversals will be represented as two lists, both containing n distinct positive integers, each uniquely identifying a node. Your program may take these lists, and output the resulting in-order traversal, using any reasonable I/O format.

You may assume the input is valid (that is, the lists actually represent traversals of some tree).

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

Definitions

A full binary tree is a finite structure of nodes, represented here by unique positive integers.

A full binary tree is either a leaf, consisting of a single node:

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

Or a branch, consisting of one node with two subtrees (called the left and right subtrees), each of which is, in turn, a full binary tree:

```<code>                                      1
                                    /   \
                                  …       …
</code>```

Here’s a full example of a full binary tree:

```<code>                                        6
                                      /   \
                                    3       4
                                   / \     / \
                                  1   8   5   7
                                     / \
                                    2   9
</code>```

The pre-order traversal of a full binary tree is recursively defined as follows:

The pre-order traversal of a leaf containing a node n is the list [n].

The pre-order traversal of a branch containing a node n and sub-trees (L, R) is the list [n] + preorder(L) + preorder(R), where + is the list concatenation operator.

For the above tree, that’s [6, 3, 1, 8, 2, 9, 4, 5, 7].

The post-order traversal of a full binary tree is recursively defined as follows:

The post-order traversal of a leaf containing a node n is the list [n].

The post-order traversal of a branch containing a node n and sub-trees (L, R) is the list postorder(L) + postorder(R) + [n].

For the above tree, that’s [1, 2, 9, 8, 3, 5, 7, 4, 6].

The in-order traversal of a full binary tree is recursively defined as follows:

The in-order traversal of a leaf containing a node n is the list [n].

The in-order traversal of a branch containing a node n and sub-trees (L, R) is the list inorder(L) + [n] + inorder(R).

For the above tree, that’s [1, 3, 2, 8, 9, 6, 5, 4, 7].

In conclusion: given the pair of lists [6, 3, 1, 8, 2, 9, 4, 5, 7] (pre) and [1, 2, 9, 8, 3, 5, 7, 4, 6] (post) as input, your program should output [1, 3, 2, 8, 9, 6, 5, 4, 7].

Test cases

Each test case is in the format preorder, postorder → expected output.

```<code>[8], [8] → [8]
[3,4,5], [4,5,3] → [4,3,5]
[1,2,9,8,3], [9,8,2,3,1] → [9,2,8,1,3]
[7,8,10,11,12,2,3,4,5], [11,12,10,2,8,4,5,3,7] → [11,10,12,8,2,7,4,3,5]
[1,2,3,4,5,6,7,8,9], [5,6,4,7,3,8,2,9,1] → [5,4,6,3,7,2,8,1,9]
</code>```

答:
Haskell, <s>84</s> 83 bytes

```<code>(a:b:c)#z|i<-1+length(fst$span(/=b)z),h<- \f->f i(b:c)#f i z=h take++a:h drop
a#_=a
</code>```

Title: Pre-order + post-order to in-order

Body:
Haskell, <s>84</s> 83 bytes

(a:b:c)#z|i<-1+length(fst$span(/=b)z),h<- \f->f i(b:c)#f i z=h take++a:h drop
a#_=a


问:
Introduce Your Language!
Your task is to write a program or function that takes a string as input, and prints Hello (input), I'm (language name).

Examples

Python:

Input: Oliver

Output: Hello Oliver, I'm Python

C++:

Input: Jacob

Output: Hello Jacob, I'm C++

etc.

Remember, this is code-golf, so the code with the lowest number of bytes wins.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code># Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code># Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code># Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the leaderboard snippet:

```<code># [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

var QUESTION_ID=94485,OVERRIDE_USER=12537;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+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

```

答:
sed, 22 bytes

s/.*/Hello &, I'm sed/
```

<p><strong>Try it online!</strong></p>

<p><strong>Run:</strong></p>

<pre class="lang-sh prettyprint-override"><code>sed -f hello.sed <<< "PPCG"
</code>```

Output:

```<code>Hello PPCG, I'm sed
</code>```

Title: Introduce Your Language!

Body:
sed, 22 bytes

s/.*/Hello &, I'm sed/

Try it online!

Run:

sed -f hello.sed <<< "PPCG"

Output:

Hello PPCG, I'm sed


答:
C#, 22 bytes

```<code>s=>s[s.Length-1]-s[0];
</code>```

Full source code with test case:

```<code>using System;

namespace StringCumulativeSlope
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string,int>f= s=>s[s.Length-1]-s[0];
            Console.WriteLine(f("Hello World!"));
        }
    }
}
</code>```

C# with LINQ, 17 bytes

A shorter version, using LINQ, thanks to hstde:

```<code>s=>s.Last()-s[0];
</code>```

However, an extra import is necessary:

```<code>using System.Linq;
</code>```

Title: Output a string's cumulative slope

Body:
C#, 22 bytes

s=>s[s.Length-1]-s[0];

Full source code with test case:

using System;

namespace StringCumulativeSlope
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string,int>f= s=>s[s.Length-1]-s[0];
            Console.WriteLine(f("Hello World!"));
        }
    }
}

C# with LINQ, 17 bytes

A shorter version, using LINQ, thanks to hstde:

s=>s.Last()-s[0];

However, an extra import is necessary:

using System.Linq;


答:
Brachylog, 7 bytes

```<code>@c$)@[-
</code>```

Try it online!

Explanation

```<code>@c        Convert "Hello World!" to [72,101,108,108,111,32,87,111,114,108,100,33]
  $)      Circular permute right: [33,72,101,108,108,111,32,87,111,114,108,100]
    @[    Take a prefix of the list
      -   Subtract
</code>```

Since subtract only works for an input of two integers, it will succeed once the selected prefix is [33, 72].

Title: Output a string's cumulative slope

Body:
Brachylog, 7 bytes

@c$)@[-

Try it online!

Explanation

@c        Convert "Hello World!" to [72,101,108,108,111,32,87,111,114,108,100,33]
  $)      Circular permute right: [33,72,101,108,108,111,32,87,111,114,108,100]
    @[    Take a prefix of the list
      -   Subtract

Since subtract only works for an input of two integers, it will succeed once the selected prefix is [33, 72].


答:
CJam, <s> 44 </s> 40 bytes

```<code>l~{S*\_S*\2ew{:+3%3^}%2$N@}A%_s:~:+sJSe[
</code>```

Try it online!

Explanation

```<code>l~       e# Read and evaluate input.
{        e# Map this block over i in the range [0 1 ... 9].
  S*     e#   Get a string of i spaces (the indentation).
  \_     e#   Swap with the current line of trits and duplicate it.
  S*     e#   Join the trits with spaces.
  \2ew   e#   Swap with the other copy of the trits and get all consecutive pairs.
  {      e#   Map this block over the pairs...
    :+   e#     Sum the pair.
    3%   e#     Modulo 3.
    3^   e#     XOR 3.
         e#     This expression (x+y)%3 ^ 3 computes the required mapping.
  }%     e#   Now this is the next line.
  2$     e#   Copy the indentation (to pad the lines to equal length).
  N      e#   Push a linefeed.
  @      e#   Pull up the next line.
}A%      e# The result of this is a nested array whose string representation is
         e# the required triangle.
_s       e# Duplicate and flatten into a string.
:~       e# Eval each character which gives a list of all the trits.
:+       e# Sum that.
s        e# Turn the sum into a string.
JSe[     e# Left-pad it with spaces to width 19.
</code>```

Title: Number Triangles

Body:
Credit

My thanks to Rand Al'Thor's letter-based question for the inspiration for this code-golf challenge.

Background

The nature of this challenge is based off the algorithm mentioned by Rand in his "A Triangle Formed of Three Letters":

Start with a sequence of 10 letters each of which is X, Y, or Z.

Under each row, construct the next row as follows. If two adjacent letters are the same, write the same letter beneath them; if they're different, write the third letter beneath them.

You would then repeat the previous step until you have one letter in your tenth row.

Challenge

We're going to put a mathematical spin on the above algorithm:

Let's start with a sequences of 10 digits, each separated by a space, and each of which is either 1, 2 or 3.

Under each row, construct the next row as follows. If two adjacent digits are the same, write the same digit beneath them; if they're different, write the third digit beneath them.

Repeat the previous step until you have one final number.

So, following this algorithm, if starting with the row 1 2 3 3 1 3 1 3 1 2, for example, the following triangle is generated:

```<code>Input: 1 2 3 3 1 3 1 3 1 2

Output:

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

I'm also curious to know the sum of all the digits in the number triangle, so add all these digits, and put this total in an eleventh row, right-justified to the last digit in the first row. So, our number triangle will look something like the following (spaces in my example are represented below by the . character to show formatting.)

```<code>Input: 1 2 3 3 1 3 1 3 1 2

Output:

1.2.3.3.1.3.1.3.1.2
.3.1.3.2.2.2.2.2.3.
..2.2.1.2.2.2.2.1..
...2.3.3.2.2.2.3...
....1.3.1.2.2.1....
.....2.2.3.2.3.....
......2.1.1.1......
.......3.1.1.......
........2.1........
.........3.........
................109
</code>```

Your challenge is to write code that can start with an inputted string/array/etc. of ten digits, as per my example, and then apply the algorithm to generate the ten rows that would create the number triangle, followed by an 11th row that would display the total of all digits with right-justification.

Testing

Testing of this string can be performed with a randomly generated string of ten digits of your choosing, or one generated from the snippet below...

c1=()=>('1331123221'+(Math.random()*(1<<24)|0).toString(4)).replace(/0/g, "").slice(-10).split("").join(" ");

$("#btn").click(function(){
  $("#str").val(c1());
});```
<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>
<input type="text" id="str"><button id="btn">Get numbers</button>
<br>
Please use this snippet to generate a starting row for testing your code. Alternatively, you can also use a string of your choice, so long as it's ten digits (ranging from 1 to 3), separated by single spaces.</code>```

Rules

Code-golf rules apply, so lowest number of bytes wins the challenge. In the event that there are two entries with the same low score, the winner will be awarded based on the number of up-votes.

What we're basically after is 11 rows, 19 characters long... How you render your final output is entirely up to you: array, console, file output, STDOUT, etc., so please use whatever output method you like that will work to your advantage. The only rule in the output is that we have 11 rows with 19 characters in each row in a similar format to above...

If it helps your code, use whatever separator for the digits... Just remember that legibility may be a contributing factor.

No silly loopholes.

Hard-coding of the input is not allowed. The purposes of this code is such that it can be used to produce different results each time with varying input. Hard-coding of 1 1 1 1 1 1 1 1 1 1 for example, completely negates the whole point of the algorithm.

Look forward to seeing what you all can come up with!

Body:
CJam, <s> 44 </s> 40 bytes

l~{S*\_S*\2ew{:+3%3^}%2$N@}A%_s:~:+sJSe[

Try it online!

Explanation

l~       e# Read and evaluate input.
{        e# Map this block over i in the range [0 1 ... 9].
  S*     e#   Get a string of i spaces (the indentation).
  \_     e#   Swap with the current line of trits and duplicate it.
  S*     e#   Join the trits with spaces.
  \2ew   e#   Swap with the other copy of the trits and get all consecutive pairs.
  {      e#   Map this block over the pairs...
    :+   e#     Sum the pair.
    3%   e#     Modulo 3.
    3^   e#     XOR 3.
         e#     This expression (x+y)%3 ^ 3 computes the required mapping.
  }%     e#   Now this is the next line.
  2$     e#   Copy the indentation (to pad the lines to equal length).
  N      e#   Push a linefeed.
  @      e#   Pull up the next line.
}A%      e# The result of this is a nested array whose string representation is
         e# the required triangle.
_s       e# Duplicate and flatten into a string.
:~       e# Eval each character which gives a list of all the trits.
:+       e# Sum that.
s        e# Turn the sum into a string.
JSe[     e# Left-pad it with spaces to width 19.


答:
R, 69 43 32 bytes

A very non-competing answer although I thought it'd be fun to showcase a possible solution in R.

```<code>sum(diff(strtoi(sapply(strsplit(readline(),"")[[1]],charToRaw),16L)))
</code>```

The only interesting aspect of this answer is the use of sapplyand charToRaw. First I split the string into a vector of characters that I want to convert into its ASCII integer representations. The charToRaw function is not vectorized in R and instead of looping over each value in aforementioned vector I use sapply which effectively vectorizes the function. Subsequently take 1st difference and then sum.

Edit: Turns out charToRaw transform a string into a vector where each element is the raw representation of each character, hence no need to use strsplit and sapply

```<code>sum(diff(strtoi(charToRaw(readline()),16)))
</code>```

Edit2: Turns out there is an even better way, the function utf8ToInt(x) does exactly what strtoi(charToRaw(x),16) which means we can save a few more bytes (Idea taken from @rturnbull's answer to another question):

```<code>sum(diff(utf8ToInt(readline())))
</code>```

Title: Output a string's cumulative slope

Body:
R, 69 43 32 bytes

A very non-competing answer although I thought it'd be fun to showcase a possible solution in R.

sum(diff(strtoi(sapply(strsplit(readline(),"")[[1]],charToRaw),16L)))

The only interesting aspect of this answer is the use of sapplyand charToRaw. First I split the string into a vector of characters that I want to convert into its ASCII integer representations. The charToRaw function is not vectorized in R and instead of looping over each value in aforementioned vector I use sapply which effectively vectorizes the function. Subsequently take 1st difference and then sum.

Edit: Turns out charToRaw transform a string into a vector where each element is the raw representation of each character, hence no need to use strsplit and sapply

sum(diff(strtoi(charToRaw(readline()),16)))

Edit2: Turns out there is an even better way, the function utf8ToInt(x) does exactly what strtoi(charToRaw(x),16) which means we can save a few more bytes (Idea taken from @rturnbull's answer to another question):

sum(diff(utf8ToInt(readline())))


问:
Print all integers
Write a program or function which will provably print all integers exactly once given infinite time and memory.

Possible outputs could be:

```<code>0, 1, -1, 2, -2, 3, -3, 4, -4, …

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2, -3, -4, -5, -6, -7, -8, -9, 10, 11, …
</code>```

This is not a valid output, as this would never enumerate negative numbers:

<s>```0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …```</s>

The output must be in decimal, unless your language does not support decimal integer (in that case use the natural representation of integers your language uses).

Your program has to work up to the numbers with the biggest magnitude of the standard integer type of your language.

Each integer must be separated from the next using any separator (a space, a comma, a linebreak, etc.) that is not a digit nor the negative sign of your language.

The separator must not change at any point.

The separator can consist of multiple characters, as long as none of them is a digit nor the negative sign (e.g. ,  is as valid as just ,).

Any supported integer must eventually be printed after a finite amount of time.

Scoring

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

Leaderboard

var QUESTION_ID=93441,OVERRIDE_USER=41723;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+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

```

答:
Haxe, 46 bytes

```<code>function f(){var i=0;while(0<1)trace(i++,-i);}
</code>```

Title: Print all integers

Body:
Haxe, 46 bytes

function f(){var i=0;while(0<1)trace(i++,-i);}


答:
Java 7, <s>100</s> 96 bytes

```<code>int c(String s){char[]a=s.toCharArray();int r=0,i=a.length-1;for(;i>0;r+=a[i]-a[--i]);return r;}
</code>```

Ungolfed & test code:

Try it here.

```<code>class M{
  static int c(String s){
    char[] a = s.toCharArray();
    int r = 0,
        i = a.length-1;
    for(; i > 0; r += a[i] - a[--i]);
    return r;
  }

  public static void main(String[] a){
    System.out.println(c("Hello World!"));
  }
}
</code>```

Output: -39

Title: Output a string's cumulative slope

Body:
Java 7, <s>100</s> 96 bytes

int c(String s){char[]a=s.toCharArray();int r=0,i=a.length-1;for(;i>0;r+=a[i]-a[--i]);return r;}

Ungolfed & test code:

Try it here.

class M{
  static int c(String s){
    char[] a = s.toCharArray();
    int r = 0,
        i = a.length-1;
    for(; i > 0; r += a[i] - a[--i]);
    return r;
  }

  public static void main(String[] a){
    System.out.println(c("Hello World!"));
  }
}

Output: -39


问:
String and ASCII
The Challenge

Given a non-empty string containing only lowercase or uppercase letters and no spaces:

Sum up the ASCII values for each character instance in the input string.

The sum will be converted to binary.

And, the result will be the number of ones in the binary value.

Input example:

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

Sum up the ASCII values for each character instance, so for this example: 97+98+99+68+101+70+65+97+66 = 761.

Convert the sum (761) to binary. This will give 1011111001.

The final result will be the number of ones (7).

So the output for this example is 7.

Winning Criterion

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

答:
Python3, <s>46</s> 40 bytes

```<code>lambda s:bin(sum(map(ord,s))).count("1")
</code>```

Title: String and ASCII

Body:
Python3, <s>46</s> 40 bytes

lambda s:bin(sum(map(ord,s))).count("1")


问:
Progruzzle & Colf
Ever fancied creating cool twitter hashtags such as #brexit or #brangelina? this golf is for you.

Write a program that accepts two strings A & B as input and merges them according to the following algorithm:

let n be the number of vowels groups in A (e.g. britain has 2 vowels groups : i in position 3 and ai in position 5).

if n = 1 : truncate A starting at its first vowel group position (example: bill => b)

if n > 1 : truncate A starting at its n-1th vowel group position (example: programming => progr, britain => br)

remove all consonants at the beginning of B (jennifer =>
ennifer)

concatenate the modified A & B

Vowels are aeiou; consonants are bcdfghjklmnpqrstvwxyz.

Input

You can assume the input strings are lowercase and contain at least one vowel and one consonant.

Examples

```<code>brad + angelina      => brangelina
britain + exit       => brexit
ben + jennifer       => bennifer
brangelina + exit    => brangelexit
bill + hillary       => billary
angelina + brad      => angelad
programming + puzzle => progruzzle
code + golf          => colf
out + go             => o
</code>```

答:
Retina, 35 bytes

```<code>([aeiou]+[^aeiou]*){1,2} [^aeiou]*

</code>```

Try it online! (The first line enables a linefeed-separated test suite.)

Simply removes all matches of the regex on the first line.

Title: Progruzzle & Colf

Body:
Retina, 35 bytes

([aeiou]+[^aeiou]*){1,2} [^aeiou]*

Try it online! (The first line enables a linefeed-separated test suite.)

Simply removes all matches of the regex on the first line.


答:
05AB1E, <s>6</s> 5 bytes

```<code>ÇObSO
</code>```

Explanation

```<code> Ç      # convert to list of ascii values
  O     # sum
   b    # convert to binary
    SO  # sum as a list
</code>```

Try it online!

Title: String and ASCII

Body:
The Challenge

Given a non-empty string containing only lowercase or uppercase letters and no spaces:

Sum up the ASCII values for each character instance in the input string.

The sum will be converted to binary.

And, the result will be the number of ones in the binary value.

Input example:

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

Sum up the ASCII values for each character instance, so for this example: 97+98+99+68+101+70+65+97+66 = 761.

Convert the sum (761) to binary. This will give 1011111001.

The final result will be the number of ones (7).

So the output for this example is 7.

Winning Criterion

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

Body:
05AB1E, <s>6</s> 5 bytes

ÇObSO

Explanation

 Ç      # convert to list of ascii values
  O     # sum
   b    # convert to binary
    SO  # sum as a list

Try it online!


Title: Output a string's cumulative slope

Body:
Challenge

Given a string such as Hello World!, break it down into its character values: 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33.

Then calculate the difference between each consecutive pair of characters: 29, 7, 0, 3, -79, 55, 24, 3, -6, -8, -67.

Finally, sum them and print the final result: -39.

Rules

Standard loopholes apply

No using pre-made functions that perform this exact task

Creative solutions encouraged

Have fun

This is marked as code-golf, the shortest answer in bytes wins but will not be selected.

Body:
PHP, 39 Bytes

<?=ord(substr($s=$argv[1],-1))-ord($s);


答:
Jelly, 4 bytes

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

TryItOnline

How?

```<code>OSBS - Main link: s     e.g. "abcDeFAaB"
O    - ordinal (vectorises)  [97, 98, 99, 68, 101, 70, 65, 97, 66]
 S   - sum                   761
  B  - binary                [1, 0, 1, 1, 1, 1, 1, 0, 0, 1]
   S - sum                   7
</code>```

Title: String and ASCII

Body:
Jelly, 4 bytes

OSBS

TryItOnline

How?

OSBS - Main link: s     e.g. "abcDeFAaB"
O    - ordinal (vectorises)  [97, 98, 99, 68, 101, 70, 65, 97, 66]
 S   - sum                   761
  B  - binary                [1, 0, 1, 1, 1, 1, 1, 0, 0, 1]
   S - sum                   7


答:
Java 7,80,76 bytes

Thanks to kevin for saving 4 bytes

```<code>int f(char[]a){int s=0,c=0;for(char i:a)s+=i;for(;s>0;s&=s-1,c++);return c;}
</code>```

Ungolfed

```<code>int f(char[]a){
    int s=0,c=0;
    for(char i:a)
        s+=i;
    for(;s>0;s&=s-1,c++);
        return c;
}
</code>```

Title: String and ASCII

Body:
Java 7,80,76 bytes

Thanks to kevin for saving 4 bytes

int f(char[]a){int s=0,c=0;for(char i:a)s+=i;for(;s>0;s&=s-1,c++);return c;}

Ungolfed

int f(char[]a){
    int s=0,c=0;
    for(char i:a)
        s+=i;
    for(;s>0;s&=s-1,c++);
        return c;
}


答:
R, 98 bytes

Was interested in how difficult this would be in R. Turns out you have to do a lot of conversions back and forth (in this solution at least) but I'm sure there should be a shortcut, especially if using packages (can't access any here at work).

```<code>sum(as.integer(rev(intToBits(sum(strtoi(sapply(strsplit(readline(),"")[[1]],charToRaw),16L)))))^2)
</code>```

Could add an explanation if someone is interested.

Title: String and ASCII

Body:
R, 98 bytes

Was interested in how difficult this would be in R. Turns out you have to do a lot of conversions back and forth (in this solution at least) but I'm sure there should be a shortcut, especially if using packages (can't access any here at work).

sum(as.integer(rev(intToBits(sum(strtoi(sapply(strsplit(readline(),"")[[1]],charToRaw),16L)))))^2)

Could add an explanation if someone is interested.


答:
Pyth, 8 bytes

```<code>ssM.BsCM
</code>```

Try it online!

Explanation:

```<code>      CM  (M)ap ordinals(C) over input
     s    (s)um
   .B     Binary string
 sM       map cast to integer
s         sum
</code>```

Title: String and ASCII

Body:
Pyth, 8 bytes

ssM.BsCM

Try it online!

Explanation:

      CM  (M)ap ordinals(C) over input
     s    (s)um
   .B     Binary string
 sM       map cast to integer
s         sum


Title: String and ASCII

Body:
><>, 34 bytes

01\
(?\i:@+$0
?!\:2%:}-2,r+$:
n;\~

Try it online!


问:
Build a nest
The challenge is simple: write a program or function that, when given a finite non-negative integer, outputs a nested array.

The rules

Your code must produce a unique valid nested array for every integer 0 ≤ n < 231.

Every possible nested array with up to 16 open brackets must be outputted within this range. (This does not mean that your code can never output a nested array with more than 16 open brackets.)

Your code may output a string representation of the nested array instead of an actual array (with or without commas).

One possible mapping:

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

Scoring

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

答:
Perl, <s>80</s> 79 bytes

Again uses orlp's algorithm, but this time I first checked if it works...

Includes +1 for -p

Give input number on STDIN

```<code>nest.pl <<< 8
</code>```

nest.pl:

```<code>#!/usr/bin/perl -p
($_=sprintf"%b",$_).=2x(s^.^$&or++$n-pos&&/.0/g?++$n%1:$`&&21^eg-$n);y;102;();
</code>```

Linus's solution is 64 bytes in perl:

```<code>#!/usr/bin/perl -p
$_=sprintf"%b",/.+/g;$_=10x($&&&$&+16)if!/^(1(?1)*0)+$/;y;10;()
</code>```

Dennis's solution is 59 bytes in perl (increasingly slower for large numbers):

```<code>#!/usr/bin/perl -p
1while$_-=(sprintf"%b",$n++)=~/^(1(?1)*0)+$/;$_=$&;y;10;()
</code>```

Title: Build a nest

Body:
Perl, <s>80</s> 79 bytes

Again uses orlp's algorithm, but this time I first checked if it works...

Includes +1 for -p

Give input number on STDIN

nest.pl <<< 8

nest.pl:

#!/usr/bin/perl -p
($_=sprintf"%b",$_).=2x(s^.^$&or++$n-pos&&/.0/g?++$n%1:$`&&21^eg-$n);y;102;();

Linus's solution is 64 bytes in perl:

#!/usr/bin/perl -p
$_=sprintf"%b",/.+/g;$_=10x($&&&$&+16)if!/^(1(?1)*0)+$/;y;10;()

Dennis's solution is 59 bytes in perl (increasingly slower for large numbers):

#!/usr/bin/perl -p
1while$_-=(sprintf"%b",$n++)=~/^(1(?1)*0)+$/;$_=$&;y;10;()


答:
PHP, <s>27</s> 26 bytes

Note that my answer actually outputs PHP_INT_MAX and PHP_INT_MIN, whereas others don't.

```<code>for(;;)echo+$i,_,~+$i++,_;
</code>```

Run like this:

```<code>php -d error_reporting=30709 -r 'for(;;)echo+$i,_,~+$i++,_;';echo
</code>```

This iterates from 0 to PHP_INT_MAX, obviously using post-increment to get the full range and not have an off-by-one error. Then get the negative range by <s>XOR-ing with -1</s> binary negation.

INT_MAX and INT_MIN

A signed integer actually has a 1 bigger range of negative values than positive values. In the case of 64-bit int (PHP default on 64-bit systems) it's -9223372036854775808 upto 92233720368547758087 inclusive. Many answers stop at -9223372036854775807, which is 1 short.

To see the tail of the output (with PHP_INT_MAX and PHP_INT_MIN), just do this:

```<code>php -d error_reporting=30709 -r 'for($i=PHP_INT_MAX-5;is_int($i);)echo+$i,_,~+$i++,_;';echo
</code>```

The is_int is strictly not needed, it just makes sure the loop stops when $i exceeds PHP_INT_MAX and becomes a float, outputting junk for all eternity.

Tweaks

Use binary negation instead of xor with -1. Requires another cast to int to handle the null case. Saved a byte.

Title: Print all integers

Body:
Write a program or function which will provably print all integers exactly once given infinite time and memory.

Possible outputs could be:

```<code>0, 1, -1, 2, -2, 3, -3, 4, -4, …

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -2, -3, -4, -5, -6, -7, -8, -9, 10, 11, …
</code>```

This is not a valid output, as this would never enumerate negative numbers:

<s>```0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …```</s>

The output must be in decimal, unless your language does not support decimal integer (in that case use the natural representation of integers your language uses).

Your program has to work up to the numbers with the biggest magnitude of the standard integer type of your language.

Each integer must be separated from the next using any separator (a space, a comma, a linebreak, etc.) that is not a digit nor the negative sign of your language.

The separator must not change at any point.

The separator can consist of multiple characters, as long as none of them is a digit nor the negative sign (e.g. ,  is as valid as just ,).

Any supported integer must eventually be printed after a finite amount of time.

Scoring

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

Leaderboard

var QUESTION_ID=93441,OVERRIDE_USER=41723;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+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

```

Body:
PHP, <s>27</s> 26 bytes

Note that my answer actually outputs PHP_INT_MAX and PHP_INT_MIN, whereas others don't.

for(;;)echo+$i,_,~+$i++,_;

Run like this:

php -d error_reporting=30709 -r 'for(;;)echo+$i,_,~+$i++,_;';echo

This iterates from 0 to PHP_INT_MAX, obviously using post-increment to get the full range and not have an off-by-one error. Then get the negative range by <s>XOR-ing with -1</s> binary negation.

INT_MAX and INT_MIN

A signed integer actually has a 1 bigger range of negative values than positive values. In the case of 64-bit int (PHP default on 64-bit systems) it's -9223372036854775808 upto 92233720368547758087 inclusive. Many answers stop at -9223372036854775807, which is 1 short.

To see the tail of the output (with PHP_INT_MAX and PHP_INT_MIN), just do this:

php -d error_reporting=30709 -r 'for($i=PHP_INT_MAX-5;is_int($i);)echo+$i,_,~+$i++,_;';echo

The is_int is strictly not needed, it just makes sure the loop stops when $i exceeds PHP_INT_MAX and becomes a float, outputting junk for all eternity.

Tweaks

Use binary negation instead of xor with -1. Requires another cast to int to handle the null case. Saved a byte.


答:
Haskell, 32 bytes

```<code>g=fromEnum
f t=g(last t)-g(t!!0)
</code>```

Title: Output a string's cumulative slope

Body:
Haskell, 32 bytes

g=fromEnum
f t=g(last t)-g(t!!0)


问:
Draw a Bumpy String
(Inspired by this challenge.)

Let's say we have a string ABBCBA. We can say that there is a rise between A and B, for B follows A; we can say that there is a run between B and B, for nothing changes; and finally we can say there is a fall between C and B. We can draw a graph like this:

```<code>             A   B   B   C   B   A
Rising:        o       o
Continuing:        o
Falling:                   o   o
</code>```

Without the labels, and minimizing whitespace:

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

This is the expected output for input ABBCBA.

You may use any non-whitespace character to replace o in the output. Further, each column may optionally have an extra space between them, like so:

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

The input will consist of at least three characters. The string will consist entirely of uppercase letters, but you may instead use lowercase letters.

Test cases

```<code>TEST CASE
LINE 1
LINE 2
LINE 3

HELLOWORLD
 o oo o
  o
o    o oo

TESTCASE
 oo  o

o  oo o

EXAMINATION
o o o o o

 o o o o o

ZSILENTYOUTH
  o ooo o

oo o   o oo

ABC
oo

ABCBA
oo

  oo
</code>```

答:
Java 7, <s>158</s> 156 bytes

```<code>String c(char[]z){String a,b,c=a=b="";for(char i=1,q=z[0],o=79,s=32,x;i<z.length;a+=(x=z[i])>q?o:s,b+=x==q?o:s,c+=x<q?o:s,q=z[i++]);return a+"\n"+b+"\n"+c;}
</code>```

2 bytes saved thanks to @Frozn.

Ungolfed & test cases:

Try it here.

```<code>class M{
  static String c(char[] z){
    String a,
           b,
           c = a = b = "";
    for(char i = 1,
             q = z[0],
             o = 79,
             s = 32,
             x; i < z.length; a += (x = z[i]) > q
                                     ? o
                                     : s,
                              b += x == q
                                     ? o
                                     : s,
                              c += x < q
                                     ? o
                                     : s,
                              q = z[i++]);
    return a + "\n" + b + "\n" + c;
  }

  public static void main(String[] a){
    print("HELLOWORLD");
    print("TESTCASE");
    print("EXAMINATION");
    print("ZSILENTYOUTH");
    print("ABC");
    print("ABCBA");
    print("ABBCBA");
    print("UVVWVVUVVWVVUVVW");
  }

  static void print(String s){
    System.out.println(c(s.toCharArray()));
    System.out.println("-------------------------");
  }
}
</code>```

Output:

```<code> O OO O
  O
O    O OO
-------------------------
 OO  O

O  OO O
-------------------------
O O O O O

 O O O O O
-------------------------
  O OOO O

OO O   O OO
-------------------------
OO

-------------------------
OO

  OO
-------------------------
O O
 O
   OO
-------------------------
O O   O O   O O
 O  O  O  O  O
   O O   O O
-------------------------
</code>```

Title: Draw a Bumpy String

Body:
Java 7, <s>158</s> 156 bytes

String c(char[]z){String a,b,c=a=b="";for(char i=1,q=z[0],o=79,s=32,x;i<z.length;a+=(x=z[i])>q?o:s,b+=x==q?o:s,c+=x<q?o:s,q=z[i++]);return a+"\n"+b+"\n"+c;}

2 bytes saved thanks to @Frozn.

Ungolfed & test cases:

Try it here.

class M{
  static String c(char[] z){
    String a,
           b,
           c = a = b = "";
    for(char i = 1,
             q = z[0],
             o = 79,
             s = 32,
             x; i < z.length; a += (x = z[i]) > q
                                     ? o
                                     : s,
                              b += x == q
                                     ? o
                                     : s,
                              c += x < q
                                     ? o
                                     : s,
                              q = z[i++]);
    return a + "\n" + b + "\n" + c;
  }

  public static void main(String[] a){
    print("HELLOWORLD");
    print("TESTCASE");
    print("EXAMINATION");
    print("ZSILENTYOUTH");
    print("ABC");
    print("ABCBA");
    print("ABBCBA");
    print("UVVWVVUVVWVVUVVW");
  }

  static void print(String s){
    System.out.println(c(s.toCharArray()));
    System.out.println("-------------------------");
  }
}

Output:

 O OO O
  O
O    O OO
-------------------------
 OO  O

O  OO O
-------------------------
O O O O O

 O O O O O
-------------------------
  O OOO O

OO O   O OO
-------------------------
OO

-------------------------
OO

  OO
-------------------------
O O
 O
   OO
-------------------------
O O   O O   O O
 O  O  O  O  O
   O O   O O
-------------------------


答:
Haskell, 47 bytes

```<code>g 0=0;g n=mod n 2+g(div n 2)
g.sum.map fromEnum
</code>```

Title: String and ASCII

Body:
Haskell, 47 bytes

g 0=0;g n=mod n 2+g(div n 2)
g.sum.map fromEnum


答:
JavaScript ES6, <s>42</s> 39 Bytes

f=
     s=>s[x='charCodeAt'](s.length-1)-s[x]();
;

console.log(f.toString().length);      // 39
console.log(f('Hello World!'))         // -39```

Using @Dennis observation about telescope sums.

<s>I think in this case the trivial solution is the shortest.</s>

Saved 3 bytes by getting rid of th the charCodeAt repetition as suggested by @Neil.

Title: Output a string's cumulative slope

Body:
JavaScript ES6, <s>42</s> 39 Bytes

f=
     s=>s[x='charCodeAt'](s.length-1)-s[x]();
;

console.log(f.toString().length);      // 39
console.log(f('Hello World!'))         // -39

Using @Dennis observation about telescope sums.

<s>I think in this case the trivial solution is the shortest.</s>

Saved 3 bytes by getting rid of th the charCodeAt repetition as suggested by @Neil.


答:
Emotinomicon, 73 bytes

```<code>Hello✖➕⏫, I'm Emotinomicon⏪⏬⏩
</code>```

If you go to the Interpreter you can generate an explanation

Thanks to @Oliver Ni for make me notice that bug that Emotinomicon removes whitespaces at the end of the String literal

Title: Introduce Your Language!

Body:
Your task is to write a program or function that takes a string as input, and prints Hello (input), I'm (language name).

Examples

Python:

Input: Oliver

Output: Hello Oliver, I'm Python

C++:

Input: Jacob

Output: Hello Jacob, I'm C++

etc.

Remember, this is code-golf, so the code with the lowest number of bytes wins.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code># Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code># Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code># Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the leaderboard snippet:

```<code># [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

var QUESTION_ID=94485,OVERRIDE_USER=12537;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+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

```

Body:
Emotinomicon, 73 bytes

Hello✖➕⏫, I'm Emotinomicon⏪⏬⏩

If you go to the Interpreter you can generate an explanation

Thanks to @Oliver Ni for make me notice that bug that Emotinomicon removes whitespaces at the end of the String literal


答:
PHP, <s>79</s> 76 bytes

```<code>foreach(str_split($argv[1])as$c)$s+=ord($c);echo substr_count(decbin($s),1);
</code>```

Test online

Ungolfed testing code:

```<code>$argv[1] = 'abcDeFAaB';

foreach(str_split($argv[1]) as $c){
    $s += ord($c);
}
echo substr_count(decbin($s),1);
</code>```

Test online

Title: String and ASCII

Body:
The Challenge

Given a non-empty string containing only lowercase or uppercase letters and no spaces:

Sum up the ASCII values for each character instance in the input string.

The sum will be converted to binary.

And, the result will be the number of ones in the binary value.

Input example:

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

Sum up the ASCII values for each character instance, so for this example: 97+98+99+68+101+70+65+97+66 = 761.

Convert the sum (761) to binary. This will give 1011111001.

The final result will be the number of ones (7).

So the output for this example is 7.

Winning Criterion

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

Body:
PHP, <s>79</s> 76 bytes

foreach(str_split($argv[1])as$c)$s+=ord($c);echo substr_count(decbin($s),1);

Test online

Ungolfed testing code:

$argv[1] = 'abcDeFAaB';

foreach(str_split($argv[1]) as $c){
    $s += ord($c);
}
echo substr_count(decbin($s),1);

Test online


答:
Bash + coreutils, <s>43</s> 49 bytes

Edit: corrected version based on manatwork's comments.

od -vAn -tuC|tr '\n ' +|dc -e?2op|grep -o 1|wc -l
```

<p><strong>Explanation:</strong></p>

<p>The result is printed on STDOUT, with some warnings given on STDERR which can be ignored.</p>

<pre class="lang-sh prettyprint-override"><code>od -vAn -tuC       # get the ASCII value for each string character
|tr '\n ' +        # replace each whitespace with a plus (in dc, a warning will be
                   #raised for each consecutive plus)
|dc -e?2op         # execute input, calculating the sum, then convert to binary
|grep -o 1|wc -l   # count how many ones exist
</code>```

Run:

echo -n "abcDeFAaB" | ./script.sh 2> /dev/null
```

<p><strong>Output:</strong></p>

<pre class="lang-sh prettyprint-override"><code>7
</code>```

A similar solution is presented below (51 bytes), that had the potential to be shorter, but with xxd I can't concatenate multiple flags and also dc only understands upper case hex letters.

xxd -c1 -u -p|tr \\n +|dc -e16i?2op|grep -o 1|wc -l
```

Title: String and ASCII

Body:
Bash + coreutils, <s>43</s> 49 bytes

Edit: corrected version based on manatwork's comments.

od -vAn -tuC|tr '\n ' +|dc -e?2op|grep -o 1|wc -l

Explanation:

The result is printed on STDOUT, with some warnings given on STDERR which can be ignored.

od -vAn -tuC       # get the ASCII value for each string character
|tr '\n ' +        # replace each whitespace with a plus (in dc, a warning will be
                   #raised for each consecutive plus)
|dc -e?2op         # execute input, calculating the sum, then convert to binary
|grep -o 1|wc -l   # count how many ones exist

Run:

echo -n "abcDeFAaB" | ./script.sh 2> /dev/null

Output:

7

A similar solution is presented below (51 bytes), that had the potential to be shorter, but with xxd I can't concatenate multiple flags and also dc only understands upper case hex letters.

xxd -c1 -u -p|tr \\n +|dc -e16i?2op|grep -o 1|wc -l


答:
Perl, 36 bytes

Includes +1 for -p

Run with input string without newline on STDIN:

```<code>echo -n abcDeFAaB | strsum.pl; echo
</code>```

strsum.pl:

```<code>#!/usr/bin/perl -p
$_=unpack"%b*",pack N,unpack"%32W*"
</code>```

If the sum of the ASCII values fits in a 16-bit integer you can leave out the 32 and gain 2 more bytes.

Title: String and ASCII

Body:
Perl, 36 bytes

Includes +1 for -p

Run with input string without newline on STDIN:

echo -n abcDeFAaB | strsum.pl; echo

strsum.pl:

#!/usr/bin/perl -p
$_=unpack"%b*",pack N,unpack"%32W*"

If the sum of the ASCII values fits in a 16-bit integer you can leave out the 32 and gain 2 more bytes.


答:
Julia, 56 Bytes

```<code>f(s)=length(filter(i->i=='1',bin(sum(map(Int,[s...])))))
</code>```

Convert to ascii value, sum up, filter for 1s, take length of result

Title: String and ASCII

Body:
Julia, 56 Bytes

f(s)=length(filter(i->i=='1',bin(sum(map(Int,[s...])))))

Convert to ascii value, sum up, filter for 1s, take length of result


答:
Straw, 25 bytes

```<code>(Hello b, I'm Straw!)b</>
</code>```

Try it online!

Simple regex substitution.

Title: Introduce Your Language!

Body:
Straw, 25 bytes

(Hello b, I'm Straw!)b</>

Try it online!

Simple regex substitution.


答:
R, <s>65</s> <s>53</s> <s>43</s> 42 bytes

Counting the number of 1s in a binary representation is calculating the Hamming weight of a number, a common procedure in cryptanalysis. There's an R package boolfun, described in this journal article, which handily has a function weight which computes the Hamming weight of any (base 10) integer. That makes our job a lot easier! The rest of the code just sums over the integer representation of STDIN, before sending that to weight.

```<code>boolfun::weight(sum(utf8ToInt(scan(,'')))
</code>```

As an added bonus, this code works for UTF-8 as well as ASCII. There are 7 ones in the binary representation of the sum of 高尔夫 (that's golf in Mandarin).

A note for those playing along at home: unfortunately, boolfun is no longer hosted on CRAN, so if you don't already have it installed you'll have to do it manually with install.packages("https://cran.r-project.org/src/contrib/Archive/boolfun/boolfun_0.2.8.tar.gz", repos = NULL, type = "source"), rather than install.packages(boolfun).

If you really don't want to use boolfun, you can achieve the same result with only two more bytes:

```<code>sum(intToBits(sum(utf8ToInt(scan(,''))))==1)
</code>```

Title: String and ASCII

Body:
R, <s>65</s> <s>53</s> <s>43</s> 42 bytes

Counting the number of 1s in a binary representation is calculating the Hamming weight of a number, a common procedure in cryptanalysis. There's an R package boolfun, described in this journal article, which handily has a function weight which computes the Hamming weight of any (base 10) integer. That makes our job a lot easier! The rest of the code just sums over the integer representation of STDIN, before sending that to weight.

boolfun::weight(sum(utf8ToInt(scan(,'')))

As an added bonus, this code works for UTF-8 as well as ASCII. There are 7 ones in the binary representation of the sum of 高尔夫 (that's golf in Mandarin).

A note for those playing along at home: unfortunately, boolfun is no longer hosted on CRAN, so if you don't already have it installed you'll have to do it manually with install.packages("https://cran.r-project.org/src/contrib/Archive/boolfun/boolfun_0.2.8.tar.gz", repos = NULL, type = "source"), rather than install.packages(boolfun).

If you really don't want to use boolfun, you can achieve the same result with only two more bytes:

sum(intToBits(sum(utf8ToInt(scan(,''))))==1)


答:
MATL, 3 bytes

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

Try it online!

Shortest language for this challenge, I think: sum, Binary, sum.

Title: String and ASCII

Body:
MATL, 3 bytes

sBs

Try it online!

Shortest language for this challenge, I think: sum, Binary, sum.


答:
JavaScript ES6, <s>80</s> <s>78</s> 71 Bytes

g=
    s=>[...s].map(c=>r+=c.charCodeAt(),r=0)|r.toString(2).split`1`.length-1
;

console.log(g.toString().length);    // 71
console.log(g('abcDeFAaB'))          // 7```
</div>
</div>
</p>

<p>Saved 7 Bytes thanks to @BassdropCumberwubwubwub</p>

<h3>Breakdown</h3>

``` [...s]                              // Split string into array of chars
 .map(c=>r+=c.charCodeAt(),r=0)      // Sum up ASCII values
 |
 r.toString(2)                       // Convert to binary (represented as string)
 .split`1`.length-1                  // Count occurences of 1
```

Title: String and ASCII

Body:
JavaScript ES6, <s>80</s> <s>78</s> 71 Bytes

g=
    s=>[...s].map(c=>r+=c.charCodeAt(),r=0)|r.toString(2).split`1`.length-1
;

console.log(g.toString().length);    // 71
console.log(g('abcDeFAaB'))          // 7

Saved 7 Bytes thanks to @BassdropCumberwubwubwub

Breakdown

 [...s]                              // Split string into array of chars
 .map(c=>r+=c.charCodeAt(),r=0)      // Sum up ASCII values
 |
 r.toString(2)                       // Convert to binary (represented as string)
 .split`1`.length-1                  // Count occurences of 1


问:
Cheating a multiple choice test, part 2
This is sequel to this challenge by Adnan. If you like this challenge, chances are you'll like the other one too. Check it out!

A multiple choice test with 8 questions each with 4 choices might have the answers: BCADBADA. Converted to four different arrays, with true and false if the current letter is the answer, it will look like this

```<code>Q#: 1  2  3  4  5  6  7  8
    B  C  A  D  B  A  D  A
A: [0, 0, 1, 0, 0, 1, 0, 1]
B: [1, 0, 0, 0, 1, 0, 0, 0]
C: [0, 1, 0, 0, 0, 0, 0, 0]
D: [0, 0, 0, 1, 0, 0, 1, 0]
</code>```

This can be compressed using a bit of logic. Each of the choices A, B, C and D can be represented
by two true/false values shown below:

```<code>A: 1 0
B: 0 1
C: 0 0
D: 1 1
</code>```

Using this logic, we can compress the four vectors above to just two:

```<code> 1  2  3  4  5  6  7  8
 B  C  A  D  B  A  D  A
[0, 0, 1, 1, 0, 1, 1, 1]
[1, 0, 0, 1, 1, 0, 1, 0]
</code>```

That is, the solution to your test is simply: 00110111, 10011010. By concatenating these, we get the binary number
0011011110011010, or 14234 in decimal. Use this decimal value to cheat on your test!

Challenge

Take a number N in the (inclusive) range [0, 65535], and output a string with the answer to the multiple choice test.

Test cases:

```<code>14234
BCADBADA

38513
ABBDCAAB

0
CCCCCCCC

120
CBBBBCCC

65535
DDDDDDDD

39253
ABCDABCD
</code>```

The output may be in upper or lower case letters, but you can not use other symbols.

答:
CP-1610 assembly, 24 DECLEs (30 bytes)

This code is intended to be run on an Intellivision. (1)

A CP-1610 opcode is encoded with a 10-bit value, known as a 'DECLE'. The actual function is 24 DECLEs long, starting at $4809 and ending at $4820.

The CPU registers are however 16-bit wide, so it will support any input value in 0x0000 .. 0xFFFF.

```<code>                            ROMW  10            ; use 10-bit ROM
                            ORG   $4800         ; start program at address $4800
4800 0002                   EIS                 ; enable interrupts (to enable display)

                    ;; ---- usage example
4801 0001                   SDBD                ; load parameter in R0
4802 02B8 009A 0037         MVII  #14234, R0    ;
4805 0004 0148 0009         CALL  cheat         ; call function
4808 0017                   DECR  PC            ; infinite loop

                    ;; ---- 'Cheat Your Test' function
                    cheat   PROC

4809 0082                   MOVR  R0,     R2    ; copy R0 to R2
480A 0040                   SWAP  R0            ; swap LSB/MSB in R0
480B 02BC 0214              MVII  #$214,  R4    ; R4 = pointer to 2nd row of screen memory

480D 01DB           @@loop  CLRR  R3            ; clear R3
480E 0052                   RLC   R2            ; extract highest bit of R2 to carry
480F 0053                   RLC   R3            ; inject carry into R3
4810 0050                   RLC   R0            ; extract highest bit of R0 to carry
4811 0053                   RLC   R3            ; inject carry into R3
4812 0001                   SDBD                ; add pointer to lookup table to R3
4813 02FB 001D 0048         ADDI  #@@tbl, R3    ;
4816 029B                   MVI@  R3,     R3    ; read character value
4817 0263                   MVO@  R3,     R4    ; write it to screen memory (also does R4++)
4818 037C 021C              CMPI  #$21C,  R4    ; 8 characters written? ...
481A 0225 000E              BLT   @@loop        ; ... if not, jump to @@loop

481C 00AF                   JR    R5            ; return

481D 011F 0117      @@tbl   DECLE $11F, $117    ; characters 'B', 'C', 'A' and 'D'
481F 010F 0127              DECLE $10F, $127    ; in white, using the built-in font

                            ENDP
</code>```

Output

(1) Granted that at least one compiler, several emulators and copyright-free replacement ROM files are freely available, I think that it doesn't infringe any PPCG submission rule. But please let me know if I'm wrong.

Title: Cheating a multiple choice test, part 2

Body:
CP-1610 assembly, 24 DECLEs (30 bytes)

This code is intended to be run on an Intellivision. (1)

A CP-1610 opcode is encoded with a 10-bit value, known as a 'DECLE'. The actual function is 24 DECLEs long, starting at $4809 and ending at $4820.

The CPU registers are however 16-bit wide, so it will support any input value in 0x0000 .. 0xFFFF.

                            ROMW  10            ; use 10-bit ROM
                            ORG   $4800         ; start program at address $4800
4800 0002                   EIS                 ; enable interrupts (to enable display)

                    ;; ---- usage example
4801 0001                   SDBD                ; load parameter in R0
4802 02B8 009A 0037         MVII  #14234, R0    ;
4805 0004 0148 0009         CALL  cheat         ; call function
4808 0017                   DECR  PC            ; infinite loop

                    ;; ---- 'Cheat Your Test' function
                    cheat   PROC

4809 0082                   MOVR  R0,     R2    ; copy R0 to R2
480A 0040                   SWAP  R0            ; swap LSB/MSB in R0
480B 02BC 0214              MVII  #$214,  R4    ; R4 = pointer to 2nd row of screen memory

480D 01DB           @@loop  CLRR  R3            ; clear R3
480E 0052                   RLC   R2            ; extract highest bit of R2 to carry
480F 0053                   RLC   R3            ; inject carry into R3
4810 0050                   RLC   R0            ; extract highest bit of R0 to carry
4811 0053                   RLC   R3            ; inject carry into R3
4812 0001                   SDBD                ; add pointer to lookup table to R3
4813 02FB 001D 0048         ADDI  #@@tbl, R3    ;
4816 029B                   MVI@  R3,     R3    ; read character value
4817 0263                   MVO@  R3,     R4    ; write it to screen memory (also does R4++)
4818 037C 021C              CMPI  #$21C,  R4    ; 8 characters written? ...
481A 0225 000E              BLT   @@loop        ; ... if not, jump to @@loop

481C 00AF                   JR    R5            ; return

481D 011F 0117      @@tbl   DECLE $11F, $117    ; characters 'B', 'C', 'A' and 'D'
481F 010F 0127              DECLE $10F, $127    ; in white, using the built-in font

                            ENDP

Output

(1) Granted that at least one compiler, several emulators and copyright-free replacement ROM files are freely available, I think that it doesn't infringe any PPCG submission rule. But please let me know if I'm wrong.


答:
Haskell, 36 bytes

```<code>sum.(tail>>=zipWith(-)).map fromEnum
</code>```

usage:

```<code>Prelude> (sum.(tail>>=zipWith(-)).map fromEnum)"Hello World!"
-39
</code>```

Haskell (Lambdabot), 31 bytes

```<code>sum.(tail>>=zipWith(-)).map ord
</code>```

Title: Output a string's cumulative slope

Body:
Challenge

Given a string such as Hello World!, break it down into its character values: 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33.

Then calculate the difference between each consecutive pair of characters: 29, 7, 0, 3, -79, 55, 24, 3, -6, -8, -67.

Finally, sum them and print the final result: -39.

Rules

Standard loopholes apply

No using pre-made functions that perform this exact task

Creative solutions encouraged

Have fun

This is marked as code-golf, the shortest answer in bytes wins but will not be selected.

Body:
Haskell, 36 bytes

sum.(tail>>=zipWith(-)).map fromEnum

usage:

Prelude> (sum.(tail>>=zipWith(-)).map fromEnum)"Hello World!"
-39

Haskell (Lambdabot), 31 bytes

sum.(tail>>=zipWith(-)).map ord


答:
Julia, 73 Bytes

Gives a function f taking N as input and returning the answer as string.

```<code>f(N)=(b=bin(N,16);join(["CBAD"[parse("0b$(b[i])$(b[i+8])")+1]for i=1:8]))
</code>```

Try it

Depending if a char array counts as string, one can omit the join (67 Bytes)

```<code>f(N)=(b=bin(N,16);["CBAD"[parse("0b$(b[i])$(b[i+8])")+1]for i=1:8])
</code>```

Try it

Title: Cheating a multiple choice test, part 2

Body:
This is sequel to this challenge by Adnan. If you like this challenge, chances are you'll like the other one too. Check it out!

A multiple choice test with 8 questions each with 4 choices might have the answers: BCADBADA. Converted to four different arrays, with true and false if the current letter is the answer, it will look like this

```<code>Q#: 1  2  3  4  5  6  7  8
    B  C  A  D  B  A  D  A
A: [0, 0, 1, 0, 0, 1, 0, 1]
B: [1, 0, 0, 0, 1, 0, 0, 0]
C: [0, 1, 0, 0, 0, 0, 0, 0]
D: [0, 0, 0, 1, 0, 0, 1, 0]
</code>```

This can be compressed using a bit of logic. Each of the choices A, B, C and D can be represented
by two true/false values shown below:

```<code>A: 1 0
B: 0 1
C: 0 0
D: 1 1
</code>```

Using this logic, we can compress the four vectors above to just two:

```<code> 1  2  3  4  5  6  7  8
 B  C  A  D  B  A  D  A
[0, 0, 1, 1, 0, 1, 1, 1]
[1, 0, 0, 1, 1, 0, 1, 0]
</code>```

That is, the solution to your test is simply: 00110111, 10011010. By concatenating these, we get the binary number
0011011110011010, or 14234 in decimal. Use this decimal value to cheat on your test!

Challenge

Take a number N in the (inclusive) range [0, 65535], and output a string with the answer to the multiple choice test.

Test cases:

```<code>14234
BCADBADA

38513
ABBDCAAB

0
CCCCCCCC

120
CBBBBCCC

65535
DDDDDDDD

39253
ABCDABCD
</code>```

The output may be in upper or lower case letters, but you can not use other symbols.

Body:
Julia, 73 Bytes

Gives a function f taking N as input and returning the answer as string.

f(N)=(b=bin(N,16);join(["CBAD"[parse("0b$(b[i])$(b[i+8])")+1]for i=1:8]))

Try it

Depending if a char array counts as string, one can omit the join (67 Bytes)

f(N)=(b=bin(N,16);["CBAD"[parse("0b$(b[i])$(b[i+8])")+1]for i=1:8])

Try it


答:
Common Lisp, 53

```<code>(lambda(s)(logcount(reduce'+(map'list'char-code s))))
</code>```

Title: String and ASCII

Body:
Common Lisp, 53

(lambda(s)(logcount(reduce'+(map'list'char-code s))))