答:
Perl, <s>69</s> <s>66</s> <s>62</s> <s>56</s> 53 bytes

Includes +1 for -p

Takes postorder followed by preorder as one line separated by space on STDIN (notice the order of pre and post). Nodes are represented as unique letters (any character that is not space or newline is OK).

```<code>inpost.pl <<< "98231 12983"
</code>```

inpost.pl:

```<code>#!/usr/bin/perl -p
s%(.)(.)+\K(.)(.+)\3(\1.*)\2%$4$5$3$2%&&redo;s;.+ ;;
</code>```

Using the original purely numeric format needs a lot more care to exactly identify a single number and comes in at 73 bytes

```<code>#!/usr/bin/perl -p
s%\b(\d+)(,\d+)+\K,(\d+\b)(.+)\b\3,(\1\b.*)\2\b%$4$5,$3$2%&&redo;s;.+ ;;
</code>```

Use as

```<code>inpostnum.pl <<< "11,12,10,2,8,4,5,3,7 7,8,10,11,12,2,3,4,5"
</code>```

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

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

Body:
Perl, <s>69</s> <s>66</s> <s>62</s> <s>56</s> 53 bytes

Includes +1 for -p

Takes postorder followed by preorder as one line separated by space on STDIN (notice the order of pre and post). Nodes are represented as unique letters (any character that is not space or newline is OK).

inpost.pl <<< "98231 12983"

inpost.pl:

#!/usr/bin/perl -p
s%(.)(.)+\K(.)(.+)\3(\1.*)\2%$4$5$3$2%&&redo;s;.+ ;;

Using the original purely numeric format needs a lot more care to exactly identify a single number and comes in at 73 bytes

#!/usr/bin/perl -p
s%\b(\d+)(,\d+)+\K,(\d+\b)(.+)\b\3,(\1\b.*)\2\b%$4$5,$3$2%&&redo;s;.+ ;;

Use as

inpostnum.pl <<< "11,12,10,2,8,4,5,3,7 7,8,10,11,12,2,3,4,5"


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

答:
Clojure, 31 bytes

```<code>#(-(int(last %))(int(first %)))
</code>```

Someone reduced the task already to a single operation.

ContentLicense: CC BY-SA 3.0

Title: Output a string's cumulative slope

Body:
Clojure, 31 bytes

#(-(int(last %))(int(first %)))

Someone reduced the task already to a single operation.


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

答:
PHP, 73 bytes

```<code><?=substr_count(decbin(array_sum(array_map(ord,str_split($_GET[s])))),1);
</code>```

save to file, call in browser with

Title: String and ASCII

Body:
PHP, 73 bytes

<?=substr_count(decbin(array_sum(array_map(ord,str_split($_GET[s])))),1);

save to file, call in browser with <scriptpath>?s=<string>

or

<?=substr_count(decbin(array_sum(array_map(ord,str_split($argv[1])))),1);

save to file, run with php <scriptpath> <string>

To run without a file, replace <?= with echo<space> in the second version

and run with php -r '<code>' <string>.


问:
Program that outputs a program that outputs a program ... that outputs "Hello!"

Challenge

Write the shortest program P such that

P takes any positive integer n as input, and outputs a program string P1

executing P1 (with no input) outputs a program string P2,

executing P2 (with no input) outputs a program string P3,

...

executing Pn (with no input) outputs exactly "Hello!" (without the quotes).

Schematically:

                P(n) → P1 → P2 → ... → Pn → Hello!

Criteria

I/O is via stdin/stdout.

Program length is measured in bytes.

Programs consist only of ASCII printable characters.

There must be no duplicates among the programs P, P1,...,Pn.

EDIT: Programs P, P1,...,Pn are meant to be source code, and "executing the program" refers to whatever processing produces the output (i.e., interpretation, compilation & execution, etc.).

答:
Clojure, 36 bytes

```<code>(str(apply str(repeat 5\'))"Hello!")
</code>```

Symbol

```<code>'something
</code>```

evaluates to

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

Build up a symbol with 5 single quotes and run the result until no quotes left.

Body:
Clojure, 36 bytes

(str(apply str(repeat 5\'))"Hello!")

Symbol

'something

evaluates to

something

Build up a symbol with 5 single quotes and run the result until no quotes left.


问:
Shortest way to strip the commas from column n given a .csv file/input
Ok, so the input here is going to be a .csv file and so is the output. Now, given a .csv file/input like so

```<code>"apple","banana","apple,banana","orange"
"grape","orange","grape,orange","sprout"
# 0       1        2              3
</code>```

strip out all commas for a given nth column's entries (index starts at 0). So, for the input above, the program would output a .csv file like so for n = 2:

```<code>"apple","banana","applebanana","orange"
"grape","orange","grapeorange","sprout"
</code>```

If the particular column's entries do not have commas, then it does nothing. Could have any allowable/manageable number of columns, and if you somehow find that creating a program that takes more than one argument, say, a, b, c, ..., z like this

```<code>program(a=1,b=4,c=65, ..., z=0, mycsv.csv)
</code>```

for respective columns 2, 5, and 66, which all strip out commas for each, to be shorter, then do that.

Shortest code measured in bytes wins, and it doesn't have to be a file that is output/input.

答:
Haskell, 56 bytes

```<code>n!x=Math.FFT.Base.adjust(filter(/=','))n.read$'[':x++"]"
</code>```

Without adjust you'd have to do something crazy like this:

```<code>n#(a,b)|a==n|filter(/=',')b|1<2=b; .. (n#)=<<zip ..
</code>```

Body:
Haskell, 56 bytes

n!x=Math.FFT.Base.adjust(filter(/=','))n.read$'[':x++"]"

Without adjust you'd have to do something crazy like this:

n#(a,b)|a==n|filter(/=',')b|1<2=b; .. (n#)=<<zip ..


答:
Javascript (ES6), <s>72</s> 70 bytes

Saved 2 bytes thanks to ETHproductions:

f=
  (s,p=([c,...d])=>c?c.charCodeAt()+p(d):0,q=n=>n&&n%2+q(n>>1))=>q(p(s))
;
console.log(f('abcDeFAaB'));```
</div>
</div>
</p>
<p><strong>Explanation:</strong></p>
<pre class="lang-js prettyprint-override"><code>(s,                                        //Input string
    p=([c,...d])=>c?c.charCodeAt()+p(d):0, //Recursive method to sum up the ASCII values
    q=n=>n&&n%2+q(n>>1)                    //Recursive method to count 1s in the binary form
)=>q(p(s))
</code>```

Previous solution (72 bytes):

(s,p=([c,...d])=>c?c.charCodeAt()+p(d):0,q=n=>n&&(n&1)+q(n>>1))=>q(p(s))
```

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:
Javascript (ES6), <s>72</s> 70 bytes

Saved 2 bytes thanks to ETHproductions:

f=
  (s,p=([c,...d])=>c?c.charCodeAt()+p(d):0,q=n=>n&&n%2+q(n>>1))=>q(p(s))
;
console.log(f('abcDeFAaB'));

Explanation:

(s,                                        //Input string
    p=([c,...d])=>c?c.charCodeAt()+p(d):0, //Recursive method to sum up the ASCII values
    q=n=>n&&n%2+q(n>>1)                    //Recursive method to count 1s in the binary form
)=>q(p(s))

Previous solution (72 bytes):

(s,p=([c,...d])=>c?c.charCodeAt()+p(d):0,q=n=>n&&(n&1)+q(n>>1))=>q(p(s))


答:
PHP, 36 bytes

```<code><?=ord(strrev($s=$argv[1]))-ord($s);
</code>```

Every character but the first and the last are added and substracted once each.

→ sum of differences == difference between first and last character

ord() in PHP operates on the first character of a string

→ no need to explicitly reduce it to a single character

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, 36 bytes

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

Every character but the first and the last are added and substracted once each.

→ sum of differences == difference between first and last character

ord() in PHP operates on the first character of a string

→ no need to explicitly reduce it to a single character


答:
R, 59 bytes

```<code> function(f,n){x=read.csv(f,h=0);x[,n]=gsub(",","",x[,n]);x}
</code>```

A simple function that takes f, the location of the csv file, and n, the column number to replace. Reads in the file, removes all commas from the nth column, returns the resulting data frame. R indexes from 1, not from 0.

Title: Shortest way to strip the commas from column n given a .csv file/input

Body:
Ok, so the input here is going to be a .csv file and so is the output. Now, given a .csv file/input like so

```<code>"apple","banana","apple,banana","orange"
"grape","orange","grape,orange","sprout"
# 0       1        2              3
</code>```

strip out all commas for a given nth column's entries (index starts at 0). So, for the input above, the program would output a .csv file like so for n = 2:

```<code>"apple","banana","applebanana","orange"
"grape","orange","grapeorange","sprout"
</code>```

If the particular column's entries do not have commas, then it does nothing. Could have any allowable/manageable number of columns, and if you somehow find that creating a program that takes more than one argument, say, a, b, c, ..., z like this

```<code>program(a=1,b=4,c=65, ..., z=0, mycsv.csv)
</code>```

for respective columns 2, 5, and 66, which all strip out commas for each, to be shorter, then do that.

Shortest code measured in bytes wins, and it doesn't have to be a file that is output/input.

Body:
R, 59 bytes

 function(f,n){x=read.csv(f,h=0);x[,n]=gsub(",","",x[,n]);x}

A simple function that takes f, the location of the csv file, and n, the column number to replace. Reads in the file, removes all commas from the nth column, returns the resulting data frame. R indexes from 1, not from 0.


答:
PHP 7.1, <s>33</s> 31 bytes

Uses negative string offsets implemented in PHP 7.1.

```<code>echo ord($argn[-1])-ord($argn);
</code>```

Run like this:

```<code>echo 'Hello World!' | php -nR 'echo ord($argn[-1])-ord($argn);';echo
</code>```

Tweaks

Saved 2 bytes by using $argn

Title: Output a string's cumulative slope

Body:
PHP 7.1, <s>33</s> 31 bytes

Uses negative string offsets implemented in PHP 7.1.

echo ord($argn[-1])-ord($argn);

Run like this:

echo 'Hello World!' | php -nR 'echo ord($argn[-1])-ord($argn);';echo

Tweaks

Saved 2 bytes by using $argn


答:
Perl, 19 bytes

Includes +1 for -p

Give input on STDIN without final newline

```<code>echo -n "Hello World!" | slope.pl; echo
</code>```

slope.pl:

```<code>#!/usr/bin/perl -p
$_=-ord()+ord chop
</code>```

If you are sure the input string has at least 2 characters this 17 byte version works too:

```<code>#!/usr/bin/perl -p
$_=ord(chop)-ord
</code>```

Title: Output a string's cumulative slope

Body:
Perl, 19 bytes

Includes +1 for -p

Give input on STDIN without final newline

echo -n "Hello World!" | slope.pl; echo

slope.pl:

#!/usr/bin/perl -p
$_=-ord()+ord chop

If you are sure the input string has at least 2 characters this 17 byte version works too:

#!/usr/bin/perl -p
$_=ord(chop)-ord


问:
Prime factors buddies
Given an integer N > 1, output all other numbers which prime decompositions have the same digits as the prime decomposition of N.

For example, if N = 117, then the output must be [279, 939, 993, 3313, 3331], because

```<code>117 = 3 × 3 × 13
</code>```

therefore, the available digits are 1, 3, 3 and 3 and we have

```<code>279  = 3 × 3 × 31
939  = 3 × 313
993  = 3 × 331
3313 = 3313
3331 = 3331
</code>```

Those are the only other possible numbers, because other combination of these digits yield non-prime integers, which can't be the result of prime factorization.

If N is any of 117, 279, 939, 993, 3313 or 3331, then the output will contain the five other numbers: they are prime factors buddies.

You cannot use leading zeroes to get primes, e.g. for N = 107, its only buddy is 701 (017 is not considered).

Input and Outputs

The input and output buddies must be taken and returned in the decimal base.

N will always be strictly greater than 1.

The output can be formatted rather freely, as long as it only contains the buddies and separators/list syntactic elements.

The ordering of the output is unimportant.

You may take the input through STDIN, as a function argument or anything similar.

You may print the output to STDOUT, return it from a function, or anything similar.

Test cases

Your program should solve any of the test cases below in less than a minute.

```<code>N        Buddies
2        []
4        []
8        []
15       [53]
16       []
23       [6]
42       [74, 146, 161]
126      [222, 438, 483, 674, 746, 851, 1466, 1631, 1679]
204      [364,548,692,762,782,852,868,1268,1626,2474,2654,2921,2951,3266,3446,3791,4274,4742,5426,5462,6233,6434,6542,7037,8561,14426,14642,15491,15833,22547]
</code>```

Scoring

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

答:
Actually, 27 bytes

This uses the same algorithm that Martin, Adnan, FryAmTheEggman, and Dennis have been using. Golfing suggestions welcome. Try it online!

```<code>`w"i$n"£MΣSR≈`╗╜ƒ;╝R`╜ƒ╛=`░
</code>```

Ungolfing

```<code>          Implicit input n.
`...`╗    Define a function and store it in register 0. Call the function f(x).
  w         Get the prime factorization of x.
  "..."£M   Begin another function and map over the [prime, exponent] lists of w.
    i         Flatten the list. Stack: prime, exponent.
    $n        Push str(prime) to the stack, exponent times.
               The purpose of this function is to get w's prime factors to multiplicity.
  Σ         sum() the result of the map.
             On a list of strings, this has the same effect as "".join()
  SR≈       Sort that string, reverse it and convert to int.
╜ƒ        Now push the function stored in register 0 and call it immediately.
           This gives the upper bound for any possible prime factor buddy.
;╝        Duplicate this upper bound and save a copy to register 1.
R         Push the range [0..u]
`...`░    Filter the range for values where the following function returns a truthy.
           Variable k.
  ╜ƒ        Push the function in register 0 and call it on k.
  ╛=        Check if f(k) == f(n).
          Implicit return every value that is a prime factor buddy with n, including n.
</code>```

Title: Prime factors buddies

Body:
Actually, 27 bytes

This uses the same algorithm that Martin, Adnan, FryAmTheEggman, and Dennis have been using. Golfing suggestions welcome. Try it online!

`w"i$n"£MΣSR≈`╗╜ƒ;╝R`╜ƒ╛=`░

Ungolfing

          Implicit input n.
`...`╗    Define a function and store it in register 0. Call the function f(x).
  w         Get the prime factorization of x.
  "..."£M   Begin another function and map over the [prime, exponent] lists of w.
    i         Flatten the list. Stack: prime, exponent.
    $n        Push str(prime) to the stack, exponent times.
               The purpose of this function is to get w's prime factors to multiplicity.
  Σ         sum() the result of the map.
             On a list of strings, this has the same effect as "".join()
  SR≈       Sort that string, reverse it and convert to int.
╜ƒ        Now push the function stored in register 0 and call it immediately.
           This gives the upper bound for any possible prime factor buddy.
;╝        Duplicate this upper bound and save a copy to register 1.
R         Push the range [0..u]
`...`░    Filter the range for values where the following function returns a truthy.
           Variable k.
  ╜ƒ        Push the function in register 0 and call it on k.
  ╛=        Check if f(k) == f(n).
          Implicit return every value that is a prime factor buddy with n, including n.


问:
IPv4 Integer Conversion Function
Write the shortest function to convert an IP address into it's integer representation and output it as an integer.

To change an IPv4 address to it's integer representation, the following calculation is required:

Break the IP address into it's four octets.

(Octet1 * 16777216) + (Octet2 * 65536) + (Octet3 * 256) + (Octet4)

Sample Input

```<code>192.168.1.1           10.10.104.36           8.8.8.8
</code>```

Sample Output

```<code>3232235777            168454180              134744072
</code>```

ContentLicense: CC BY-SA 2.5

Title: IPv4 Integer Conversion Function

Body:
Ruby (no builtins/eval) - 47

s=->s{s.split(".").inject(0){|a,b|a<<8|b.to_i}}

Test:

s["192.168.1.1"]
3232235777


答:
PHP, 81 bytes

```<code>while($r=fgetcsv(STDIN)){$r[$n=argv[1]]=strtr($r[$n],",","");fputcsv(STDOUT,$r);}
</code>```

Run with php -r '' <n> < <csvsource> > <csvtarget>.

Body:
PHP, 81 bytes

while($r=fgetcsv(STDIN)){$r[$n=argv[1]]=strtr($r[$n],",","");fputcsv(STDOUT,$r);}

Run with php -r '<code>' <n> < <csvsource> > <csvtarget>.


答:
C#, 51 50 bytes

```<code>s=>Convert.ToString(s.Sum(x=>x),2).Count(x=>x>48);
</code>```

can be used like this:

```<code>Func<string, int> f=s=>Convert.ToString(s.Sum(x=>x),2).Count(x=>x>48);
f("abcDeFAaB") // == 7
</code>```

would be so much shorter if Int32.ToString() had a to binary flag.

Edit: saved one byte by converting '0' to int

Title: String and ASCII

Body:
C#, 51 50 bytes

s=>Convert.ToString(s.Sum(x=>x),2).Count(x=>x>48);

can be used like this:

Func<string, int> f=s=>Convert.ToString(s.Sum(x=>x),2).Count(x=>x>48);
f("abcDeFAaB") // == 7

would be so much shorter if Int32.ToString() had a to binary flag.

Edit: saved one byte by converting '0' to int


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

答:
Python 2.7, <s>172 149 124</s> 118 bytes

```<code>x=input();y="";z=0
for b in bin(x)[2+(x<1):]:y+="[]"[b<"1"];z+=b>"0"or-1;z+=99*(z<0)
print"["+(y,"[]"*(x+16))[z>0]+"]"
</code>```

Explanation:

Define a bijection by [↔1 and ]↔0. Any arrangement of brackets can then be written as a binary number and vice versa, for instance [][]↔1010(10) and [[][]]↔110100(52). All valid arrangements of up to 15 open brackets (30 brackets in total) are covered by numbers with up to 30 bits (ignoring leading zeros), which are precisely the numbers less than 231.

The first for-loop gives the inverse of this bijection, converting a number to an arrangement of brackets, while checking that the arrangement is valid.

Invalid arrangements are replaced within the print statement by long sequences of brackets to avoid collisions. For instance 11(3)↔[[ is not valid so we concatenate 3+16 brackets instead. This ensures all arrangements are unique.

The resultant arrangement is placed within a pair of brackets to make a nested array, so that 1010(10) becomes [[][]] and 110100(52) becomes [[[][]]]. The extra open bracket means we've now covered all arrays with 16 open brackets.

The following program can be used to figure out the number for a given array with up to 16 brackets.

```<code>s=raw_input();o="";
for c in s[1:-1]:
 if c=="[":o+="1"
 if c=="]":o+="0"
print int(o,2)
</code>```

Title: Build a nest

Body:
Python 2.7, <s>172 149 124</s> 118 bytes

x=input();y="";z=0
for b in bin(x)[2+(x<1):]:y+="[]"[b<"1"];z+=b>"0"or-1;z+=99*(z<0)
print"["+(y,"[]"*(x+16))[z>0]+"]"

Explanation:

Define a bijection by [↔1 and ]↔0. Any arrangement of brackets can then be written as a binary number and vice versa, for instance [][]↔1010(10) and [[][]]↔110100(52). All valid arrangements of up to 15 open brackets (30 brackets in total) are covered by numbers with up to 30 bits (ignoring leading zeros), which are precisely the numbers less than 231.

The first for-loop gives the inverse of this bijection, converting a number to an arrangement of brackets, while checking that the arrangement is valid.

Invalid arrangements are replaced within the print statement by long sequences of brackets to avoid collisions. For instance 11(3)↔[[ is not valid so we concatenate 3+16 brackets instead. This ensures all arrangements are unique.

The resultant arrangement is placed within a pair of brackets to make a nested array, so that 1010(10) becomes [[][]] and 110100(52) becomes [[[][]]]. The extra open bracket means we've now covered all arrays with 16 open brackets.

The following program can be used to figure out the number for a given array with up to 16 brackets.

s=raw_input();o="";
for c in s[1:-1]:
 if c=="[":o+="1"
 if c=="]":o+="0"
print int(o,2)


问:
Is this a Smith number?

Challenge description

A Smith number is a composite number whose sum of digits is equal to the sum of sums of digits of its prime factors. Given an integer N, determine if it's a Smith number or not.

The first few Smith numbers are 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438 (sequence A006753 in OEIS).

Sample input / output

```<code>18: False (sum of digits: 1 + 8 = 9; factors: 2, 3, 3; sum of digits of factors: 2 + 3 + 3 = 8)
22: True
13: False (meets the digit requirement, but is prime)
666: True (sum of digits: 6 + 6 + 6 = 18; factors: 2, 3, 3, 37; sum of digits of factors: 2 + 3 + 3 + 3 + 7 = 18)
-265: False (negative numbers can't be composite)
0: False (not composite)
1: False (not composite)
4937775: True
</code>```

Notes

Your code can be a function (method) or a full working program,

Instead of words like True and False, you can use any truthy and falsy values, as long as it's clear what they are,

This is a code-golf challenge, so make your code as short as possible!

答:
Actually, 18 bytes

Unfortunately, Actually doesn't have a factorization builtin that gives a number's prime factors to multiplicity, so I had to hack one together. Golfing suggestions welcome. Try it online!

```<code>;w`i$n`MΣ♂≈Σ@$♂≈Σ=
</code>```

Ungolfing

```<code>         Implicit input n.
;w       Duplicate n and get the prime factorization of a copy of n.
`...`M   Map the following function over the [prime, exponent] lists of w.
  i        Flatten the list. Stack: prime, exponent.
  $n       Push str(prime) to the stack, exponent times.
            The purpose of this function is to get w's prime factors to multiplicity.
Σ        sum() the result of the map.
          On a list of strings, this has the same effect as "".join()
♂≈Σ      Convert every digit to an int and sum().
@        Swap the top two elements, bringing other copy of n to TOS.
$♂≈Σ     Push str(n), convert every digit to an int, and sum().
=        Check if the sum() of n's digits is equal
          to the sum of the sum of the digits of n's prime factors to multiplicity.
         Implicit return.
</code>```

Title: Is this a Smith number?

Body:
Actually, 18 bytes

Unfortunately, Actually doesn't have a factorization builtin that gives a number's prime factors to multiplicity, so I had to hack one together. Golfing suggestions welcome. Try it online!

;w`i$n`MΣ♂≈Σ@$♂≈Σ=

Ungolfing

         Implicit input n.
;w       Duplicate n and get the prime factorization of a copy of n.
`...`M   Map the following function over the [prime, exponent] lists of w.
  i        Flatten the list. Stack: prime, exponent.
  $n       Push str(prime) to the stack, exponent times.
            The purpose of this function is to get w's prime factors to multiplicity.
Σ        sum() the result of the map.
          On a list of strings, this has the same effect as "".join()
♂≈Σ      Convert every digit to an int and sum().
@        Swap the top two elements, bringing other copy of n to TOS.
$♂≈Σ     Push str(n), convert every digit to an int, and sum().
=        Check if the sum() of n's digits is equal
          to the sum of the sum of the digits of n's prime factors to multiplicity.
         Implicit return.


问:
List all ordered partitions of n
The challenge is to list all ordered partitions (composition (combinatorics)) of a given positive integer n. These are the lists of numbers from 1 to n whose sum is n. For example, given input n = 4, the result should be:

4

  1, 3

  3, 1

  2, 2

  2, 1, 1

  1, 2, 1

  1, 1, 2

  1, 1, 1, 1

The result can be in any order, but must contain each ordered partition once. This means that for n = 4, [1, 1, 2], [1, 2, 1] and [2, 1, 1] must all be part of the result.

Here's my own JavaScript code which achieves this:

```<code>function range(n) {
    for (var range = [], i = 0; i < n; range.push(++i));
    return range;
}

function composition(n) {
    return n < 1 ? [[]] : range(n).map(function(i) {
        return composition(n - i).map(function(j) {
            return [i].concat(j);
        });
    }).reduce(function(a, b) {
        return a.concat(b);
    });
}
</code>```

Golfed, ES6 (<s>169</s> <s>167</s> <s>119</s> <s>109</s> <s>105</s> <s>89</s> 85 bytes):

```<code>n=>n?[].concat(...[...Array(n)].map((x,i)=>i+1).map(b=>m(n-b).map(a=>[b,...a]))):[[]]
</code>```

答:
Prolog, 81 bytes + 6 bytes to call

```<code>L*L.
[H|T]*L:-H>1,M is H-1,[M,1|T]*L.
[H,K|T]*L:-H>1,M is H-1,N is K+1,[M,N|T]*L.
</code>```

Try it online!

Call with [4]*L., repeat with ; until all solutions have been presented.

Alternatively, if repeatedly pressing ; is not okay (or should be added to the byte count), call with bagof(L,[4]*L,M). which adds 17 bytes for the call.

Title: List all ordered partitions of n

Body:
Prolog, 81 bytes + 6 bytes to call

L*L.
[H|T]*L:-H>1,M is H-1,[M,1|T]*L.
[H,K|T]*L:-H>1,M is H-1,N is K+1,[M,N|T]*L.

Try it online!

Call with [4]*L., repeat with ; until all solutions have been presented.

Alternatively, if repeatedly pressing ; is not okay (or should be added to the byte count), call with bagof(L,[4]*L,M). which adds 17 bytes for the call.


问:
Produce the number 2014 without any numbers in your source code

Note to challenge writers as per meta consensus:
This question was well-received when it was posted, but challenges
like this, asking answerers to Do X without using
Y
are likely to be poorly received. Try using the
sandbox
to get feedback on if you want to post a similar challenge.

It's <s>2017</s> <s>2018</s> <s>2019</s> <s>2020</s> <s>2021</s> <s>2022</s> 2023 already, folks, go home.

So, now that it's 2014, it's time for a code question involving the number 2014.

Your task is to make a program that prints the number 2014, without using any of the characters 0123456789 in your code, and independently of any external variables such as the date or time or a random seed.

The shortest code (counting in bytes) to do so in any language in which numbers are valid tokens wins.

Leaderboard:

var QUESTION_ID=17005,OVERRIDE_USER=7110;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

```

答:
Emotinomicon, 14 bytes

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

Try it online!

Explanation:

```<code>  ߞ       explanation
              begin quote string
    ߞ
              end quote string
              pop N and output as a number
</code>```

ߞ is U+7DE. 0x7DE is 2014.

ContentLicense: CC BY-SA 4.0

Body:
Emotinomicon, 14 bytes

ߞ

Try it online!

Explanation:

  ߞ       explanation
              begin quote string
    ߞ
              end quote string
              pop N and output as a number

ߞ is U+7DE. 0x7DE is 2014.


答:
Python, 153 128 bytes

```<code>s=l=0;r="";n=input()
for d in bin(n)[2:]*(n>0):c=d<"1";l=[l,s>1][c];r+="]"*c+(1-l*c)*"[";s+=1-c-l*c
print"["+r+"["*l+"]"*(s+l+1)
</code>```

We map a number n to a nested list by looking at its binary digits left-to-right. This algorithm works for any number, not just under 232.

If the current binary digit is an 1, output [.

Otherwise, if the sequence of brackets we've output so far would get balanced by a single closing bracket, output ][.

Otherwise, if this is the last 0 in the binary number, output ][.

Otherwise output ].

Finally, we close any opened brackets.

Title: Build a nest

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

Body:
Python, 153 128 bytes

s=l=0;r="";n=input()
for d in bin(n)[2:]*(n>0):c=d<"1";l=[l,s>1][c];r+="]"*c+(1-l*c)*"[";s+=1-c-l*c
print"["+r+"["*l+"]"*(s+l+1)

We map a number n to a nested list by looking at its binary digits left-to-right. This algorithm works for any number, not just under 232.

If the current binary digit is an 1, output [.

Otherwise, if the sequence of brackets we've output so far would get balanced by a single closing bracket, output ][.

Otherwise, if this is the last 0 in the binary number, output ][.

Otherwise output ].

Finally, we close any opened brackets.


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

答:
PHP 7, <s>81</s> <s>80</s> 77 bytes

Note: uses Windows-1252 encoding

```<code>for($x=2;~$x--;print~õ)for($a=$argn;$c=$a[$$x+1];)echo$c<=>$a[$$x++]^$x?~ß:o;
</code>```

Run like this:

```<code>echo HELLOWORLD | php -nR 'for($x=2;~$x--;print"\n")for($a=$argn;$c=$a[$$x+1];)echo$c<=>$a[$$x++]^$x?" ":o;';echo
</code>```

Explanation

Iterates over lines (numbered 1, 0, -1). Then iterates over the input string for every line. When the result of spaceship comparison equals the line number, output an o, otherwise, output a space. After every line, print a newline.

Tweaks

Stop iterating when $x is -1, which we can find by binary negation (result 0). Saves a byte compared to adding 1 (or 2 with pre-increment).

Saved 3 bytes by using $argn

Title: Draw a Bumpy String

Body:
PHP 7, <s>81</s> <s>80</s> 77 bytes

Note: uses Windows-1252 encoding

for($x=2;~$x--;print~õ)for($a=$argn;$c=$a[$$x+1];)echo$c<=>$a[$$x++]^$x?~ß:o;

Run like this:

echo HELLOWORLD | php -nR 'for($x=2;~$x--;print"\n")for($a=$argn;$c=$a[$$x+1];)echo$c<=>$a[$$x++]^$x?" ":o;';echo

Explanation

Iterates over lines (numbered 1, 0, -1). Then iterates over the input string for every line. When the result of spaceship comparison equals the line number, output an o, otherwise, output a space. After every line, print a newline.

Tweaks

Stop iterating when $x is -1, which we can find by binary negation (result 0). Saves a byte compared to adding 1 (or 2 with pre-increment).

Saved 3 bytes by using $argn


问:
The shortest code to invert bit-wise a binary string
Me thinks there aren't enough easy questions on here that beginners can attempt!

The challenge: Given a random input string of 1's and 0's such as:

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

Write the shortest code that outputs the bit-wise inverse like so:

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

答:
Java, 97 bytes

Inspired by a comment from 2 years ago @hdante ...

Golfed version:

```<code>String d(String s){String r="";for(int i=0;i<s.length();)r(s.charAt(i++)=='0')?"1":"0";return r;}
</code>```

Ungolfed version:

```<code>String d(String s)
{
    String r = "";
    for (int i = 0; i < s.length();)
        r += (s.charAt(i++) == '0') ? "1" : "0";
    return r;
}
</code>```

Nothing too fancy ...

Body:
Java, 97 bytes

Inspired by a comment from 2 years ago @hdante ...

Golfed version:

String d(String s){String r="";for(int i=0;i<s.length();)r(s.charAt(i++)=='0')?"1":"0";return r;}

Ungolfed version:

String d(String s)
{
    String r = "";
    for (int i = 0; i < s.length();)
        r += (s.charAt(i++) == '0') ? "1" : "0";
    return r;
}

Nothing too fancy ...


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

答:
JavaScript (ES6), 100 bytes

```<code>f=(s,t,l=t.search(s[1]))=>s[1]?f(s.slice(1,++l+1),t.slice(0,l))+s[0]+f(s.slice(l+1),t.slice(l)):s[0]
</code>```

I/O is in strings of "safe" characters (e.g. letters or digits). Alternative approach, also 100 bytes:

```<code>f=(s,t,a=0,b=0,c=s.length-1,l=t.search(s[a+1])-b)=>c?f(s,t,a+1,b,l)+s[a]+f(s,t,l+2+a,l+1,c-l-2):s[a]
</code>```

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

Body:
JavaScript (ES6), 100 bytes

f=(s,t,l=t.search(s[1]))=>s[1]?f(s.slice(1,++l+1),t.slice(0,l))+s[0]+f(s.slice(l+1),t.slice(l)):s[0]

I/O is in strings of "safe" characters (e.g. letters or digits). Alternative approach, also 100 bytes:

f=(s,t,a=0,b=0,c=s.length-1,l=t.search(s[a+1])-b)=>c?f(s,t,a+1,b,l)+s[a]+f(s,t,l+2+a,l+1,c-l-2):s[a]


答:
Mathematica, <s>53</s> 37 bytes

not the best solution but hey...built-in's ftw

Shortened. Thanks to Martin Ender

```<code>DigitCount[Tr@ToCharacterCode@#,2,1]&
</code>```

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:
Mathematica, <s>53</s> 37 bytes

not the best solution but hey...built-in's ftw

Shortened. Thanks to Martin Ender

DigitCount[Tr@ToCharacterCode@#,2,1]&


问:
Convert infix expressions to postfix notation
When I saw the title of this closed question, I thought it looked like an interesting code golf challenge.  So let me present it as such:

Challenge:

Write a program, expression or subroutine which, given an arithmetical expression in infix notation, like 1 + 2, outputs the same expression in postfix notation, i.e. 1 2 +.

(Note: A similar challenge was posted earlier in January.  However, I do feel the two tasks are sufficiently different in detail to justify this separate challenge.  Also, I only noticed the other thread after typing up everything below, and I'd rather not just throw it all away.)

Input:

The input consists of a valid infix arithmetical expression consisting of numbers (non-negative integers represented as sequences of one or more decimal digits), balanced parentheses to indicate a grouped subexpression, and the four infix binary operators +, -, * and /.  Any of these may be separated (and the entire expression surrounded) by an arbitrary number of space characters, which should be ignored.1

For those who like formal grammars, here's a simple BNF-like grammar that defines valid inputs.  For brevity and clarity, the grammar does not include the optional spaces, which may occur between any two tokens (other than digits within a number):

```<code>expression     := number | subexpression | expression operator expression
subexpression  := "(" expression ")"
operator       := "+" | "-" | "*" | "/"
number         := digit | digit number
digit          := "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
</code>```

1 The only case where the presence of spaces may affect the parsing is when they separate two consecutive numbers; however, since two numbers not separated by an operator cannot occur in a valid infix expression, this case can never happen in valid input.

Output:

The output should be a postfix expression equivalent to the input.  The output expression should consist only of numbers and operators, with a single space character between each pair of adjacent tokens, as in the following grammar (which does include the spaces)2:

```<code>expression  := number | expression sp expression sp operator
operator    := "+" | "-" | "*" | "/"
number      := digit | digit number
digit       := "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
sp          := " "
</code>```

2 Again for simplicity, the number production in this grammar admits numbers with leading zeros, even though they're forbidden in the output by the rules below.

Operator precedence:

In the absence of parentheses, the following precedence rules apply:

The operators * and / have higher precedence than + and -.

The operators * and / have equal precedence to each other.

The operators + and - have equal precedence to each other.

All operators are left-associative.

For example, the following two expressions are equivalent:

```<code>1 + 2 / 3 * 4 - 5 + 6 * 7
((1 + ((2 / 3) * 4)) - 5) + (6 * 7)
</code>```

and they should both yield the following output:

```<code>1 2 3 / 4 * + 5 - 6 7 * +
</code>```

(These are the same precedence rules as in the C language and in most languages derived from it.  They probably resemble the rules you were taught in elementary school, except possibly for the relative precedence of * and /.)

Miscellaneous rules:

If the solution given is an expression or a subroutine, the input should be supplied and the output returned as a single string.  If the solution is a complete program, it should read a line containing the infix expression from standard input and print a line containing the postfix version to standard output.

Numbers in the input may include leading zeros.  Numbers in the output must not have leading zeros (except for the number 0, which shall be output as 0).

You are not expected to evaluate or optimize the expression in any way.  In particular, you should not assume that the operators necessarily satisfy any associative, commutative or other algebraic identities.  That is, you should not assume that e.g. 1 + 2 equals 2 + 1 or that 1 + (2 + 3) equals (1 + 2) + 3.

You may assume that numbers in the input do not exceed 231 − 1 = 2147483647.

These rules are intended to ensure that the correct output is uniquely defined by the input.

Examples:

Here are some valid input expressions and the corresponding outputs, presented in the form "input" -> "output":

```<code>"1"                  ->  "1"
"1 + 2"              ->  "1 2 +"
" 001  +  02 "       ->  "1 2 +"
"(((((1))) + (2)))"  ->  "1 2 +"
"1+2"                ->  "1 2 +"
"1 + 2 + 3"          ->  "1 2 + 3 +"
"1 + (2 + 3)"        ->  "1 2 3 + +"
"1 + 2 * 3"          ->  "1 2 3 * +"
"1 / 2 * 3"          ->  "1 2 / 3 *"
"0102 + 0000"        ->  "102 0 +"
"0-1+(2-3)*4-5*(6-(7+8)/9+10)" -> "0 1 - 2 3 - 4 * + 5 6 7 8 + 9 / - 10 + * -"
</code>```

(At least, I hope all these are correct; I did the conversion by hand, so mistakes might have crept in.)

Just to be clear, the following inputs are all invalid; it does not matter what your solution does if given them (although, of course, e.g. returning an error message is nicer than, say, consuming an infinite amount of memory):

```<code>""
"x"
"1 2"
"1 + + 2"
"-1"
"3.141592653589793"
"10,000,000,001"
"(1 + 2"
"(1 + 2)) * (3 / (4)"
</code>```

答:
R, 142 bytes

R is able to parse itself, so rather than re-invent the wheel, we just put the parser to work, which outputs prefix notation, and use a recursive function to switch it to postfix notation.

```<code>f=function(x,p=1){
if(p)x=match.call()[[2]]
if((l=length(x))>1){
f(x[[2]],0)
if(l>2)f(x[[3]],0)
if((z=x[[1]])!="(")cat(z,"")
}else cat(x,"")
}
</code>```

The p argument is to control the use of non-standard evaluation (the bane of R programmers everywhere), and there are a few extra ifs in there to control the outputting of brackets (which we want to avoid).

Input: (0-1+(2-3)*4-5*(6-(7+8)/9+10))

Output: 0 1 - 2 3 - 4 * + 5 6 7 8 + 9 / - 10 + * -

Input: (((((1))) + (2)))

Output: 1 2 +

As a bonus, it works with arbitrary symbols, and any pre-defined functions with up to two arguments:

Euler's identity

Input: e^(i*pi)-1

Output: e i pi * ^ 1 -

Dividends of 13 between 1 and 100

Input: which(1:100 %% 13 == 0)

Output: 1 100 : 13 %% 0 == which

Linear regression of baby chicken weight as a function of time

Input: summary(lm(weight~Time, data=ChickWeight))

Output: weight Time ~ ChickWeight lm summary

The last example is perhaps a little outside the scope of the OP, but it does use postfix notation, so...

Body:
R, 142 bytes

R is able to parse itself, so rather than re-invent the wheel, we just put the parser to work, which outputs prefix notation, and use a recursive function to switch it to postfix notation.

f=function(x,p=1){
if(p)x=match.call()[[2]]
if((l=length(x))>1){
f(x[[2]],0)
if(l>2)f(x[[3]],0)
if((z=x[[1]])!="(")cat(z,"")
}else cat(x,"")
}

The p argument is to control the use of non-standard evaluation (the bane of R programmers everywhere), and there are a few extra ifs in there to control the outputting of brackets (which we want to avoid).

Input: (0-1+(2-3)*4-5*(6-(7+8)/9+10))

Output: 0 1 - 2 3 - 4 * + 5 6 7 8 + 9 / - 10 + * -

Input: (((((1))) + (2)))

Output: 1 2 +

As a bonus, it works with arbitrary symbols, and any pre-defined functions with up to two arguments:

Euler's identity

Input: e^(i*pi)-1

Output: e i pi * ^ 1 -

Dividends of 13 between 1 and 100

Input: which(1:100 %% 13 == 0)

Output: 1 100 : 13 %% 0 == which

Linear regression of baby chicken weight as a function of time

Input: summary(lm(weight~Time, data=ChickWeight))

Output: weight Time ~ ChickWeight lm summary

The last example is perhaps a little outside the scope of the OP, but it does use postfix notation, so...


问:
Outputting x to y

Challenge

You must choose one number x (y = x + 9) and create ten unique programs which each print out one of the numbers in the range x to y inclusive. However, there are three twists:

Each program's score is the difference between length of your program in bytes and n (where n is the number that the program outputs). i.e. If a program is 12 bytes long and it outputs the number 15, its score is 3 (|15-12| = 3).

You must not use comments to achieve this byte count.

Your program must not contain any number which is contained within the number which the program outputs. i.e. If a program outputs 1659, the program cannot contain 1, 6, 5 or 9

Your program must not contain any of the characters which are the first letters of the number which the program outpts. i.e. If the program outputs 1659, the program cannot contain o, s, f or n (one, six, five and nine)

Rules

If any number is impossible, this is counted as a DNP. You should declare all DNPs in your range.

The following is a list of numbers and their spellings. The disallowed characters for each are highlighted in bold:

0: Zero

1: One

2: Two

3: Three

4: Four

5: Five

6: Six

7: Seven

8: Eight

9: Nine

Scoring

Your overall score is the sum of all your programs' scores.

Winning

The person with the lowest score with the fewest DNPs wins.

In the event of a tie, the person whose last edit was earliest wins.

答:
Emotinomicon, 205 bytes

x = 16

```<code>
71 ⏬⏬
81 ⏬ ⏬
91⏪⏬⏩
02⏬⏬ ℹ
 12⏬⏬ ℹ
22⏪⏬⏬⏩
32 ⏪⏬⏬⏩
42⏬⏬
ℹℹ➕
</code>```

Pro tip: Prepend a  before each snippet to clean the output.

Title: Outputting x to y

Body:
Emotinomicon, 205 bytes

x = 16

71 ⏬⏬
81 ⏬ ⏬
91⏪⏬⏩
02⏬⏬ ℹ
 12⏬⏬ ℹ
22⏪⏬⏬⏩
32 ⏪⏬⏬⏩
42⏬⏬
ℹℹ➕

Pro tip: Prepend a  before each snippet to clean the output.


答:
Forth, 28 bytes

```<code>: f depth 1- roll swap - . ;
</code>```

Takes a list of characters on the stack (Forth's standard method of taking parameters.) The characters are taken such that the top of the stack is the first character of the string. I move the bottom of the stack to the top, swap, then subtract and print. Garbage is left on the stack, and output is printed to stdout.

If each character were pushed to the stack in order instead of reverse order, the program would be 2 bytes shorter. Not sure if that's allowed, though, because normally you push arguments in reverse order.

Try it online

Called like this:

```<code>33 100 108 114 111 87 32 111 108 108 101 72 f
</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:
Forth, 28 bytes

: f depth 1- roll swap - . ;

Takes a list of characters on the stack (Forth's standard method of taking parameters.) The characters are taken such that the top of the stack is the first character of the string. I move the bottom of the stack to the top, swap, then subtract and print. Garbage is left on the stack, and output is printed to stdout.

If each character were pushed to the stack in order instead of reverse order, the program would be 2 bytes shorter. Not sure if that's allowed, though, because normally you push arguments in reverse order.

Try it online

Called like this:

33 100 108 114 111 87 32 111 108 108 101 72 f


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

答:
PowerShell v2+, 76 bytes

```<code>param($n,$m)($n-replace'([aeiou]+[^aeiou]*){1,2}$')+($m-replace'^[^aeiou]*')
</code>```

Apparently this is a popular regex ... ;-)

Uses the -replace operator to pull off the appropriate pieces, then string-concatenates the results together. Adds on a $ to the first to ensure we pull the end of the string, and adds a ^ to the second to ensure we pull off the front of the string.

Title: Progruzzle & Colf

Body:
PowerShell v2+, 76 bytes

param($n,$m)($n-replace'([aeiou]+[^aeiou]*){1,2}$')+($m-replace'^[^aeiou]*')

Apparently this is a popular regex ... ;-)

Uses the -replace operator to pull off the appropriate pieces, then string-concatenates the results together. Adds on a $ to the first to ensure we pull the end of the string, and adds a ^ to the second to ensure we pull off the front of the string.


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

答:
R, 110 bytes

Came up with a vectorized solution in R. This should probably by golfable by coming up with a smarter conversion int to binary conversion.

```<code>x=as.integer(intToBits(scan()));cat(LETTERS[1:4][match(paste0(x[16:9],x[8:1]),c("10","01","00","11"))],sep="")
</code>```

Title: Cheating a multiple choice test, part 2

Body:
R, 110 bytes

Came up with a vectorized solution in R. This should probably by golfable by coming up with a smarter conversion int to binary conversion.

x=as.integer(intToBits(scan()));cat(LETTERS[1:4][match(paste0(x[16:9],x[8:1]),c("10","01","00","11"))],sep="")


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

答:
Brain-Flak, <s>34</s> 32 + 3 = 35 bytes

+3 because of the -a flag required for ascii mode.

Try it online

```<code>(([][()]){[{}{}]({})([][()])}<>)
</code>```

Strangely it is more efficient to actually use the definition used in the specs rather than the "trick" of subtracting first from last.

This works by doing exactly that.

```<code>(                           )  Push
 ([][()]){[{}]...([][()])}     While the stack has more than one item
  [{}]({})                     Subtract the top from a copy of the second
                          <>   Switch
</code>```

Title: Output a string's cumulative slope

Body:
Brain-Flak, <s>34</s> 32 + 3 = 35 bytes

+3 because of the -a flag required for ascii mode.

Try it online

(([][()]){[{}{}]({})([][()])}<>)

Strangely it is more efficient to actually use the definition used in the specs rather than the "trick" of subtracting first from last.

This works by doing exactly that.

(                           )  Push
 ([][()]){[{}]...([][()])}     While the stack has more than one item
  [{}]({})                     Subtract the top from a copy of the second
                          <>   Switch


答:
Cubix, 13 bytes

Cubix is a 2-dimensional language wrapped around a cube.

```<code>i?u//O-t#;/.@
</code>```

Test it online! This maps to the following cube net:

```<code>    i ?
    u /
/ O - t # ; / .
@ . . . . . . .
    . .
    . .
</code>```

Where the IP (instruction pointer) starts at the top-left of the far-left face.

How it works

First, the IP hits the mirror / which redirects it onto the i on the top face. The top face is a loop which continually inputs charcodes until EOF is reached. When the input is empty, the result of i is -1; the IP turns left from the ?, hitting the / on the far right face and going through the following commands:

; - Pop the top item (-1).

# - Push the length of the stack.

t - Pop the top item and get the item at that index in the stack. This pulls up the bottom item.

- - Subtract.

O - Output as an integer.

/ - Deflects the IP to the @, which ends the program.

Title: Output a string's cumulative slope

Body:
Cubix, 13 bytes

Cubix is a 2-dimensional language wrapped around a cube.

i?u//O-t#;/.@

Test it online! This maps to the following cube net:

    i ?
    u /
/ O - t # ; / .
@ . . . . . . .
    . .
    . .

Where the IP (instruction pointer) starts at the top-left of the far-left face.

How it works

First, the IP hits the mirror / which redirects it onto the i on the top face. The top face is a loop which continually inputs charcodes until EOF is reached. When the input is empty, the result of i is -1; the IP turns left from the ?, hitting the / on the far right face and going through the following commands:

; - Pop the top item (-1).

# - Push the length of the stack.

t - Pop the top item and get the item at that index in the stack. This pulls up the bottom item.

- - Subtract.

O - Output as an integer.

/ - Deflects the IP to the @, which ends the program.


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

答:
05AB1E, <s>32</s> 26 bytes

```<code>DvÐOˆðýðN×.ø,ü+3%3^}\¯O19j
</code>```

Explanation

```<code>D                 # duplicate input
v                 # for y,N in input,len(input): (10 times do)
 Ð                # triplicate current list
 Oˆ               # sum one copy and add it to global array
 ðý               # merge one copy on spaces
   ðN×.ø          # surround it with N spaces
        ,         # and print it
 ü+               # reduce one copy by addition
   3%             # modulus 3
     3^           # XOR 3
                  # this is the list sent to the next iteration
}                 # end loop
\                 # drop empty list left over from last iteration of loop
 ¯O               # sum the global array giving the triangles total sum
   19j            # join with spaces up to 19 chars
</code>```

Try it online!

Title: Number Triangles

Body:
05AB1E, <s>32</s> 26 bytes

DvÐOˆðýðN×.ø,ü+3%3^}\¯O19j

Explanation

D                 # duplicate input
v                 # for y,N in input,len(input): (10 times do)
 Ð                # triplicate current list
 Oˆ               # sum one copy and add it to global array
 ðý               # merge one copy on spaces
   ðN×.ø          # surround it with N spaces
        ,         # and print it
 ü+               # reduce one copy by addition
   3%             # modulus 3
     3^           # XOR 3
                  # this is the list sent to the next iteration
}                 # end loop
\                 # drop empty list left over from last iteration of loop
 ¯O               # sum the global array giving the triangles total sum
   19j            # join with spaces up to 19 chars

Try it online!


答:
Cinnamon Gum, 23 bytes

```<code>0000000: 64d3 884e 4ccd cc2f 8dd5 8e8e 8330 b434  d..NL../.....0.4
0000010: b108 d92b c0d9 00                        ...+...
</code>```

Try it online.

Explanation

This decompresses to d([aeiou]+[^aeiou]*)([aeiou]+[^aeiou]*)? [^aeiou]*, which deletes anything matching that regex. (Note that Jordan's golfier d([aeiou]+[^aeiou]*){,2} [^aeiou]* compresses to 24 bytes due to the lack of repeated elements to compress.)

Title: Progruzzle & Colf

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

Body:
Cinnamon Gum, 23 bytes

0000000: 64d3 884e 4ccd cc2f 8dd5 8e8e 8330 b434  d..NL../.....0.4
0000010: b108 d92b c0d9 00                        ...+...

Try it online.

Explanation

This decompresses to d([aeiou]+[^aeiou]*)([aeiou]+[^aeiou]*)? [^aeiou]*, which deletes anything matching that regex. (Note that Jordan's golfier d([aeiou]+[^aeiou]*){,2} [^aeiou]* compresses to 24 bytes due to the lack of repeated elements to compress.)


答:
Jelly, <s>23</s> 22 bytes

```<code>e€ØcT
Çµḟ‘-ị’
Ç⁸ḣ⁹ÑḢ⁹ṫ
</code>```

TryItOnline

How?

```<code>e€ØcT    - Link 1, vowel indexes: s   e.g. "colouring"
  Øc     - yield vowels, "AEIOUaeiou"
e€       - in for each                     [0,1,0,1,1,0,1,0,0]
    T    - truthy indexes (1-based)        [2,4,5,7]

Çµḟ‘-ị’  - Link 2, n-1th or only vowel group index start - 1: s
 µ       - monadic chain separation
Ç        - call last link (1) as a monad   [2,4,5,7]
   ‘     - increment                       [3,5,6,8]
  ḟ      - filter out                      [2,4,7]
    -    - -1
     ị   - index value                     [4]
               (Jelly is 1-based and has modular indexing,
                so the last but one item is at index -1,
                and when there is only 1 item in the list it is also at index -1)
      ’  - decrement                       [3]

Ç⁸ḣ⁹ÑḢ⁹ṫ - Main link: a, b                      e.g. "colouring", "pencils"
Ç        - call last link (2) as a monad with a      [3]
 ⁸       - link's left argument, a
  ḣ      - head a[:y]                                "col"
   ⁹  ⁹  - link's right argument, b
    Ñ    - call next link (1) as a monad                          [2,5]
     Ḣ   - pop head                                               [2]
       ṫ - tail b[y-1:]                                           "encils"
         - implicit print                            "colencils"
</code>```

Title: Progruzzle & Colf

Body:
Jelly, <s>23</s> 22 bytes

e€ØcT
Çµḟ‘-ị’
Ç⁸ḣ⁹ÑḢ⁹ṫ

TryItOnline

How?

e€ØcT    - Link 1, vowel indexes: s   e.g. "colouring"
  Øc     - yield vowels, "AEIOUaeiou"
e€       - in for each                     [0,1,0,1,1,0,1,0,0]
    T    - truthy indexes (1-based)        [2,4,5,7]

Çµḟ‘-ị’  - Link 2, n-1th or only vowel group index start - 1: s
 µ       - monadic chain separation
Ç        - call last link (1) as a monad   [2,4,5,7]
   ‘     - increment                       [3,5,6,8]
  ḟ      - filter out                      [2,4,7]
    -    - -1
     ị   - index value                     [4]
               (Jelly is 1-based and has modular indexing,
                so the last but one item is at index -1,
                and when there is only 1 item in the list it is also at index -1)
      ’  - decrement                       [3]

Ç⁸ḣ⁹ÑḢ⁹ṫ - Main link: a, b                      e.g. "colouring", "pencils"
Ç        - call last link (2) as a monad with a      [3]
 ⁸       - link's left argument, a
  ḣ      - head a[:y]                                "col"
   ⁹  ⁹  - link's right argument, b
    Ñ    - call next link (1) as a monad                          [2,5]
     Ḣ   - pop head                                               [2]
       ṫ - tail b[y-1:]                                           "encils"
         - implicit print                            "colencils"


Title: Progruzzle & Colf

Body:
PHP, 95 Bytes

$t="aeiou]";echo($p=preg_filter)("#([$t+[^$t*){1,2}$#","",$argv[1]).$p("#^[^$t*#","",$argv[2]);

with preg_match instead of preg_filter 110 Bytes

$t="aeiou]";($p=preg_match)("#(.*?)([$t+[^$t*){1,2}$#",$argv[1],$m);$p("#[$t.*#",$argv[2],$n);echo$m[1].$n[0];


答:
Perl 5, 39 bytes

38, plus 1 for -pe instead of -e

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

Hat tip.

Title: Progruzzle & Colf

Body:
Perl 5, 39 bytes

38, plus 1 for -pe instead of -e

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

Hat tip.


答:
JavaScript (ES6), <s>112</s> <s>100</s> 96 bytes

Takes an array as input and recursively builds a comma-separated triangle.

f=(s,p=`
`,S=0)=>p+(s[0]?s+f(s.map((v,i)=>(S+=v,v^s[i-1]||v)).slice(1),p+' ',S):(p+S).slice(-9))

console.log(f([1,2,3,3,1,3,1,3,1,2])); // reference example
console.log(f([3,3,2,1,3,1,2,1,2,1])); // random example
console.log(f([1,1,1,1,1,1,1,1,1,1])); // all ones (test case for sum < 100)```

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!


问:
Is it a balanced number?
A number is balanced if the sum of the digits on each half of the number is equal, so: 1423 is balanced because 1+4 = 2+3, so is: 42615 because 4+2=1+5. Note that the middle digit is not included on either side (or it's included on both sides) if there's an odd number of digits.

Challenge:

Take a positive integer as input, and output a truthy value if it's balanced and a falsy value if it's unbalanced.

Test cases (true)

```<code>1
6
11
141
1221
23281453796004414
523428121656666655655556655656502809745249552466339089702361716477983610754966885128041975406005088
</code>```

Test cases (false)

```<code>10
12
110
15421
5234095123508321
6240911314399072459493765661191058613491863144152352262897351988250431140546660035648795316740212454
</code>```

There will not be numbers starting with zero, for instance 00032 instead of 32. You must support numbers up to at least 100 digits (so larger than 2^64-1). As always, optional input format, so you may surround the number with apostrophes if desired.

答:
Groovy - 74 69 bytes

Represented as a Groovy closure.  Please note that the parameter passed in (i) is a String, as with the Java version.

```{i->e=i.size();k=0;s=0;for(;s<e;){k+=i.charAt(s++)-i.charAt(--e)};!k}```

Title: Is it a balanced number?

Body:
Groovy - 74 69 bytes

Represented as a Groovy closure.  Please note that the parameter passed in (i) is a String, as with the Java version.

{i->e=i.size();k=0;s=0;for(;s<e;){k+=i.charAt(s++)-i.charAt(--e)};!k}


问:
Translate number pairs to guitar notes
A guitar fretboard diagram looks like this:

```<code>  0  1  2  3  4  5  6  7  8  9 10 11 12   <- Fret number (0 means it's open)
|-E--F--F#-G--G#-A--A#-B--C--C#-D--D#-E
|-B--C--C#-D--D#-E--F--F#-G--G#-A--A#-B
|-G--G#-A--A#-B--C--C#-D--D#-E--F--F#-G
|-D--D#-E--F--F#-G--G#-A--A#-B--C--C#-D
|-A--A#-B--C--C#-D--D#-E--F--F#-G--G#-A
|-E--F--F#-G--G#-A--A#-B--C--C#-D--D#-E
</code>```

As you can see, the first string (from the top) open is an E. The first fret on the first string is an F. The fourth fret on the third string is a B. Note that the first note is the zeroth fret, not the first.

This can be written with numbers on the format string, fret. The strings are numbered from 1 to 6 from top to bottom.
The frets are numbered from 0 to 12 from left to right. The first E is therefore 1, 0. Some other examples:

```<code>1, 0 --> E
1, 1 --> F
3, 5 --> C
5, 1 --> A#
6, 6 --> A#
</code>```

Challenge:

Take N pairs of numbers (s and f), and output a delimited note succession.

The input may be on any suitable format. tuples, 2D-matrix, two separate lists, an interweaved list (string,fret,string,fret...) etc.

The output tone should be separated, but the delimiter is optional (comma, space, dash...). The output can be in either upper or lower case.

s (for string) will be in the range [1, 6] (you may choose to have i 0-indexed)

f (for fret) will be in the range [0, 12]

Test cases and examples:

```<code>1 4 5 2 1 3   <- String
4 2 6 3 5 1   <- Fret
G# E D# D A G#

6 2 3 1 4 2 3 2 2 2 6 5 2
0 1 2 3 4 5 6 7 8 9 10 11 12
E C A G F# E C# F# G G# D G# B

3 3 3 3 3 3 3 3 3 3 3 3 3   <- String
0 3 5 0 3 6 5 0 3 5 3 0 0   <- Fret
G A# C G A# C# C G A# C A# G G

// The same test case, but different input and output format:
(3,0)(3,3)(3,5)(3,3)(3,6)(3,5)(3,0)(3,3)(3,5)(3,3)(3,0)(3,0)
G,A#,C,G,A#,C#,C,G,A#,C,A#,G,G
</code>```

Good luck, and happy golfing!

答:
JavaScript (ES6), <s>79</s> 70 bytes

a=>a.map(([s,f])=>"AA#BCC#DD#EFF#GG#".match(/.#?/g)[(s*7+(s>2)+f)%12])
```

Requires 1-based strings. Edit: Saved 9 bytes by directly calculating the string to fret conversion, based on @nimi's old answer.

Title: Translate number pairs to guitar notes

Body:
JavaScript (ES6), <s>79</s> 70 bytes

a=>a.map(([s,f])=>"AA#BCC#DD#EFF#GG#".match(/.#?/g)[(s*7+(s>2)+f)%12])

Requires 1-based strings. Edit: Saved 9 bytes by directly calculating the string to fret conversion, based on @nimi's old answer.


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

```

答:
Scala, 25 bytes

```<code>n=>s"Hello $n, I'm Scala"
</code>```

To use it, assign this function to a variable.

```<code>val greeting = n=>s"Hello $n, I'm Scala"
greeting("Jacob")
</code>```

I didn't expect that you can drop the type annotation if the parameter is of type Any.

Title: Introduce Your Language!

Body:
Scala, 25 bytes

n=>s"Hello $n, I'm Scala"

To use it, assign this function to a variable.

val greeting = n=>s"Hello $n, I'm Scala"
greeting("Jacob")

I didn't expect that you can drop the type annotation if the parameter is of type Any.


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

```<code>zipWith$(!!).(`drop`cycle(words"A# B C C# D D# E F F# G G# A")).([6,1,9,4,11,6]!!)
</code>```

Takes a list of strings and a list of frets, both 0-indexed. Usage example:

```<code>Prelude >  ( zipWith$(!!).(`drop`cycle$words"A# B C C# D D# E F F# G G# A").([6,1,9,4,11,6]!!) ) [0,1,2,3,4,5] [0,0,0,0,0,0]
["E","B","G","D","A","E"]
</code>```

From the infinite list of notes starting with A#, drop the number of notes given by the list [6,1,9,4,11,6] at index of the string and pick the note at index of the fret from the remaining list.

Title: Translate number pairs to guitar notes

Body:
A guitar fretboard diagram looks like this:

```<code>  0  1  2  3  4  5  6  7  8  9 10 11 12   <- Fret number (0 means it's open)
|-E--F--F#-G--G#-A--A#-B--C--C#-D--D#-E
|-B--C--C#-D--D#-E--F--F#-G--G#-A--A#-B
|-G--G#-A--A#-B--C--C#-D--D#-E--F--F#-G
|-D--D#-E--F--F#-G--G#-A--A#-B--C--C#-D
|-A--A#-B--C--C#-D--D#-E--F--F#-G--G#-A
|-E--F--F#-G--G#-A--A#-B--C--C#-D--D#-E
</code>```

As you can see, the first string (from the top) open is an E. The first fret on the first string is an F. The fourth fret on the third string is a B. Note that the first note is the zeroth fret, not the first.

This can be written with numbers on the format string, fret. The strings are numbered from 1 to 6 from top to bottom.
The frets are numbered from 0 to 12 from left to right. The first E is therefore 1, 0. Some other examples:

```<code>1, 0 --> E
1, 1 --> F
3, 5 --> C
5, 1 --> A#
6, 6 --> A#
</code>```

Challenge:

Take N pairs of numbers (s and f), and output a delimited note succession.

The input may be on any suitable format. tuples, 2D-matrix, two separate lists, an interweaved list (string,fret,string,fret...) etc.

The output tone should be separated, but the delimiter is optional (comma, space, dash...). The output can be in either upper or lower case.

s (for string) will be in the range [1, 6] (you may choose to have i 0-indexed)

f (for fret) will be in the range [0, 12]

Test cases and examples:

```<code>1 4 5 2 1 3   <- String
4 2 6 3 5 1   <- Fret
G# E D# D A G#

6 2 3 1 4 2 3 2 2 2 6 5 2
0 1 2 3 4 5 6 7 8 9 10 11 12
E C A G F# E C# F# G G# D G# B

3 3 3 3 3 3 3 3 3 3 3 3 3   <- String
0 3 5 0 3 6 5 0 3 5 3 0 0   <- Fret
G A# C G A# C# C G A# C A# G G

// The same test case, but different input and output format:
(3,0)(3,3)(3,5)(3,3)(3,6)(3,5)(3,0)(3,3)(3,5)(3,3)(3,0)(3,0)
G,A#,C,G,A#,C#,C,G,A#,C,A#,G,G
</code>```

Good luck, and happy golfing!

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

zipWith$(!!).(`drop`cycle(words"A# B C C# D D# E F F# G G# A")).([6,1,9,4,11,6]!!)

Takes a list of strings and a list of frets, both 0-indexed. Usage example:

Prelude >  ( zipWith$(!!).(`drop`cycle$words"A# B C C# D D# E F F# G G# A").([6,1,9,4,11,6]!!) ) [0,1,2,3,4,5] [0,0,0,0,0,0]
["E","B","G","D","A","E"]

From the infinite list of notes starting with A#, drop the number of notes given by the list [6,1,9,4,11,6] at index of the string and pick the note at index of the fret from the remaining list.


答:
C, 104 103 bytes

```<code>main(s,f){for(;~scanf("%d%d",&s,&f);printf("%.2s\n",
"E F F#G G#A A#B C C#D D#"+(f+7*~-s+(s>2))%12*2));}
</code>```

Takes numbers as string fret pairs on stdin, and outputs the note after every pair. E.g.:

```<code>1 4
G#
4 2
E
5 6
D#
2 3
D
</code>```

Title: Translate number pairs to guitar notes

Body:
C, 104 103 bytes

main(s,f){for(;~scanf("%d%d",&s,&f);printf("%.2s\n",
"E F F#G G#A A#B C C#D D#"+(f+7*~-s+(s>2))%12*2));}

Takes numbers as string fret pairs on stdin, and outputs the note after every pair. E.g.:

1 4
G#
4 2
E
5 6
D#
2 3
D


答:
Mathematica, 30 bytes

```<code>Tr@Differences@ToCharacterCode
</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:
Mathematica, 30 bytes

Tr@Differences@ToCharacterCode


答:
Clora (20 bytes)

<IN?o ;=IN?o ;>IN?o

Explanation:

There are 3 Clora programs, one for each output line.

First program, <IN?o

Check if current input char I is smaller < than the next char N. Save the result in a global flag. Check the flag result ? and if is true, output o, else a blank space (yes, there is a blank space there.

All other programs, follow the same rule and are separated by ;, every program is executed and receives the input as argument.

You can test it by yourself including clora.js and executing it with

```<code>(function() {
  var x = new Clora('<IN?o ;=IN?o ;>IN?o ');
  x.execute('EXAMINATION', function(r) {
    console.log(r)
  })
})();
</code>```

Title: Draw a Bumpy String

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

Body:
Clora (20 bytes)

<IN?o ;=IN?o ;>IN?o

Explanation:

There are 3 Clora programs, one for each output line.

First program, <IN?o

Check if current input char I is smaller < than the next char N. Save the result in a global flag. Check the flag result ? and if is true, output o, else a blank space (yes, there is a blank space there.

All other programs, follow the same rule and are separated by ;, every program is executed and receives the input as argument.

You can test it by yourself including clora.js and executing it with

(function() {
  var x = new Clora('<IN?o ;=IN?o ;>IN?o ');
  x.execute('EXAMINATION', function(r) {
    console.log(r)
  })
})();


答:
CJam, <s>8</s> 5 bytes

Big thanks to Dennis for two suggestions that removed 3 bytes

```<code>l)\c-
</code>```

Try it online!

Explanation

Computes last value minus first value.

```<code>l        e# Read line as a string
 )       e# Push original string except last char, then last char
  \      e# Swap
   c     e# Convert to char: gives the first element of the string
    -    e# Subtract. Implicitly display
</code>```

Title: Output a string's cumulative slope

Body:
CJam, <s>8</s> 5 bytes

Big thanks to Dennis for two suggestions that removed 3 bytes

l)\c-

Try it online!

Explanation

Computes last value minus first value.

l        e# Read line as a string
 )       e# Push original string except last char, then last char
  \      e# Swap
   c     e# Convert to char: gives the first element of the string
    -    e# Subtract. Implicitly display


Title: Translate number pairs to guitar notes

Body:
JavaScript (ES6), <s>82</s> 81 bytes

a=>a.map(b=>(q=(b[0]+.3+b[1]*7.3|0)%12/1.7+10.3).toString(17)[0]+(q%1>.5?"#":""))

I wanted to try an all-math answer, but it turned out a little long. Maybe there's a way to golf it...

Test snippet

f=a=>a.map(b=>(q=(b[0]+.3+b[1]*7.3|0)%12/1.7+10.3).toString(17)[0]+(q%1>.5?"#":""))
console.log(f([[4,1],[2,4],[6,5],[3,2],[5,1],[1,3]]))


答:
Mathematica, 62 bytes (non-competing)

```<code><<Music`;MusicScale[100(#2+{24,19,15,10,5,0}[[#]])&@@@#,E2,9]&
</code>```

The {24,19,15,10,5,0} and the E2 represent the open-string tones of the six guitar strings (for example, the top string is 24 semitones above the note E2). Non-competing because it doesn't print the names of the notes—it plays the sequence of notes! (only if you have Mathematica, unfortunately) For example,

```<code><<Music`;MusicScale[100(#2+{24,19,15,10,5,0}[[#]])&@@@#,E2,9]&@
 {{4,0},{3,2},{2,3},{1,2},{5,0},{4,2},{3,2},{2,2},
  {5,2},{4,4},{2,0},{2,3},{6,2},{4,4},{3,2},{2,2},
  {6,3},{4,0},{3,0},{2,0},{4,0},{4,4},{3,2},{2,3},
  {6,3},{3,0},{2,0},{2,3},{5,0},{4,2},{3,2},{2,2},{4,0}}
</code>```

plays the opening 4 bars or so from Pachelbel's Canon. (which is about as much of Pachelbel's Canon as I can stand)

Title: Translate number pairs to guitar notes

Body:
Mathematica, 62 bytes (non-competing)

<<Music`;MusicScale[100(#2+{24,19,15,10,5,0}[[#]])&@@@#,E2,9]&

The {24,19,15,10,5,0} and the E2 represent the open-string tones of the six guitar strings (for example, the top string is 24 semitones above the note E2). Non-competing because it doesn't print the names of the notes—it plays the sequence of notes! (only if you have Mathematica, unfortunately) For example,

<<Music`;MusicScale[100(#2+{24,19,15,10,5,0}[[#]])&@@@#,E2,9]&@
 {{4,0},{3,2},{2,3},{1,2},{5,0},{4,2},{3,2},{2,2},
  {5,2},{4,4},{2,0},{2,3},{6,2},{4,4},{3,2},{2,2},
  {6,3},{4,0},{3,0},{2,0},{4,0},{4,4},{3,2},{2,3},
  {6,3},{3,0},{2,0},{2,3},{5,0},{4,2},{3,2},{2,2},{4,0}}

plays the opening 4 bars or so from Pachelbel's Canon. (which is about as much of Pachelbel's Canon as I can stand)