答:
C++11, 355 Bytes

Takes input string as command line arguments

```<code>#include <iostream>
#define A(n,i) int n=atoi(a[i]);
int main(int,char**a) {
A(w,1)A(h,2)A(x,3)A(y,4)A(n,5)
int d=1,r=1;
auto b=new int64_t[h];
while(--n>1){
b[y]|=1<<x;
if(r)x++;else x--;
if(d)y++;else y--;
if(x==0||x==w-1)r=!r;
if(y==0||y==h-1)d=!d;
}
for(int i=0;i<h;++i){
for(int j=0;j<w;++j){
std::cout<<(x==j&&y==i?'x':b[i]&(1<<j)?'o':' ');
}
std::cout<<'\n';
}
}
</code>```

Don't worry about the newlines, they are already removed from the count.

Storing the rows as 64-Bit integer is okay since maximum width is 50.

Title: Collide against walls

Body:
Statement

Given an input like this 35 15 0 0 10 that matches the following constrains:

Width in characters of the grid (5-50)

Height in characters of the grid (5-25)

Initial X position of the ball (0-(Width-1)

Initial Y position of the ball (0-(Height-1)

Number of movements to simulate

Generate a grid that shows the trajectory of the ball, knowing it's direction is initially DR (down-right) and that colliding with a wall will reverse the increment being applied to that axis. In other words, if we are going DR and hit the bottom we will now be going UR until we collide again.

The trajectory is not affected by passing twice over the same point since it's not the game snake, it's the trajectory of an object in 2d.

The input will be a string such as the one above and the output should be similar to this, not caring about which characters represent the wall, trajectory or ball, as long as they're consistent.

Points

Your score is the length of your submission, in characters.

Winners by language

var QUESTION_ID=81035,OVERRIDE_USER=19121;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
C++11, 355 Bytes

Takes input string as command line arguments

#include <iostream>
#define A(n,i) int n=atoi(a[i]);
int main(int,char**a) {
A(w,1)A(h,2)A(x,3)A(y,4)A(n,5)
int d=1,r=1;
auto b=new int64_t[h];
while(--n>1){
b[y]|=1<<x;
if(r)x++;else x--;
if(d)y++;else y--;
if(x==0||x==w-1)r=!r;
if(y==0||y==h-1)d=!d;
}
for(int i=0;i<h;++i){
for(int j=0;j<w;++j){
std::cout<<(x==j&&y==i?'x':b[i]&(1<<j)?'o':' ');
}
std::cout<<'\n';
}
}

Don't worry about the newlines, they are already removed from the count.

Storing the rows as 64-Bit integer is okay since maximum width is 50.


问:
Stack Exchanging

Problem

Say you have N stacks named S1 through SN, where each Sk (k = 1 to N) contains N copies of the number k.

For example, when N = 3 the stacks looks like this:

```<code>1  2  3  <- top of stack
1  2  3
1  2  3  <- bottom of stack
=======
1  2  3  <- stack index
</code>```

Here there are 3 stacks indexed as 1, 2, and 3, and each one contains N instances of its own index.

The goal is to rearrange the N stacks such that each of them identically contains the numbers 1 through N in order from top to bottom.

e.g. for N = 3 the goal is to rearrange the stacks into:

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

The only action you can perform with the stacks is taking the top number from one of the stacks (popping) then immediately placing it on top of a different stack (pushing). This is subject to these stipulations:

A number can only be pushed onto a stack if it is less than or equal to the top number on that stack.

e.g. a 1 can be pushed onto a stack with a 1, 2, or 3 at the top, but a 2 can only be pushed onto a stack with a 2 or 3 (or higher) at the top.

This has the effect that stacks are always monotonically increasing from top to bottom.

Any nonempty stack may be popped from, and, assuming the previous bullet is satisfied, any stack may be pushed to.

Any number may be pushed onto an empty stack.

Stacks have no maximum height limit.

Stacks cannot be created or destroyed, there are always N of them.

This challenge is about deciding which pops and pushes to do in order to complete the stack exchange, not necessarily in the fewest moves, but in a surefire way.

(Practicing with a deck of cards is a good way to get a feel for the problem.)

Challenge

Write a program or function that takes in a positive integer N, guaranteed to be 3 or above. Print or return a string that denotes all the pop-push actions required to rearrange the stacks from the initial state:

```<code>1  2  3  4  5
1  2  3  4  5
1  2  3  4  5
1  2  3  4  5
1  2  3  4  5
=============
1  2  3  4  5
</code>```

(N = 5 case)

To the final state:

```<code>1  1  1  1  1
2  2  2  2  2
3  3  3  3  3
4  4  4  4  4
5  5  5  5  5
=============
1  2  3  4  5
</code>```

Every line in your output must contain two numbers separated by a space. The first number is the index of the stack to pop from and the second number is the index of the stack to push to. Performing the actions of all the lines in order should arrange the stacks correctly without breaking any rules.

For example, here is a potential valid output for the N = 3 case:

```<code>1 2  [move the top number on stack 1 to the top of stack 2]
1 2  [repeat]
1 2  [repeat]
3 1  [move the top number on stack 3 to the top of stack 1]
2 3  [etc.]
2 3
2 3
2 1
2 1
2 1
3 1
3 1
3 1
3 2
1 2
1 2
1 2
1 3
2 3
2 3
2 3
1 2
3 2
3 1
</code>```

Notes

Your output does not need to be optimal, only correct. i.e. you do not need to minimize the number of pops and pushes.

So it would be alright if, say, some move were repeatedly made and immediately reversed.

Popping and pushing to the same stack in one move, e.g. 2 2, is allowed as well (though of course pointless).

Your output does need to be deterministic and finite.

Remember that stacks have 1-based indexing. 0-based indexing is not allowed.

N greater than 9 should of course work just as well as single digit N.

If desired you may use any two distinct, non-digit printable ASCII characters in place of spaces and newlines. A trailing newline (or newline substitute) in the output is fine.

Scoring

The shortest code in bytes wins. Tiebreaker is higher voted answer.

Valueless brownie points if you can show your algorithm is optimal.

答:
Pyth <s>96</s> 94 bytes

```<code>Mt*Q+++bGdHM|%+y_GHQQg1 2++Qd1g2 3g2 1g3 1++Qd2Vr3QgNtN++QdN;g1QVStQVStQI<NHgnNHnNtH)++nN0dnNH
</code>```

Try it here

How does it work?

This explanation will be using N=5.

Part 1: Create the bottom layer on every stack

The reason why this is needs a separate piece of code is because every stack needs to be used: the first 4 need a 5 to be put beneath them, and the last stack must provide the 5s. This means that we can't just move all the 4s somewhere, put a 5 there, and move the 4s back.

Visualization: (parentheses mean what will be moved)

```<code>     _
11111 |
22222 |_ Can't move 4s here, not monotonically increasing
33333_|
(44444)------------??? Where to put the 4s?
55555 <- Must supply the 5 that will be moved
</code>```

Instead, to do this first exchange, we will first move all the 1s over to to the second stack, move a 5 to the first stack (which is now empty), move the 1s to the third stack, move the 2s to the first stack, move the 1s back to the first stack, and finally move a 5 to the second stack.

```<code>(11111)-----.
2222211111<-'
===============================
5<---------.
2222211111 : (from stack 5)
===============================
5
22222(11111)-.
3333311111<--'
===============================
522222<-.
(22222)-'
3333311111
===============================
52222211111<-.
             |
33333(11111)-'
===============================
52222211111
5<-----.
33333  |
44444  |
555(5)-'
</code>```

Now that we have a free space to move stacks into (stack 2, which only contains a 5 that is placed in the right spot), we can move all the 3s to stack 2 and place a 5 in stack 3. We can then repeat the same thing for stack 4, and now we get all the 5s in the right place! And just one more thing: we will move all the 1s to stack 5 so that we get a nice setup for the next stack exchange.

```<code>522222(11111)-.
533333        |
544444        |
5             |
511111<-------'
</code>```

Part 2: Do everything else :)

This is much easier now, because now we will always have a free stack to move other numbers we need to juggle around into. So, first we figure out where the 4 is. A bit of examination will show that it will always be 1 up from where it started, or 2 above the last stack. Now, we just keep going down the stacks, placing a 4 in the stack if it's free, or moving the other numbers up 1 stack if it's not. Now we have all the 4s in place.

```<code>522222<------.
533333<----. |
544444-.-.-'-'
5<-----' |
511111<--'
===============================
5433333
54
54
5411111
5422222
</code>```

Now, we realize that the 3s are 2 stacks above where the 4s where. This means that we can do the exact same thing we did with the 4s! And as it turns out, we can keep doing this as long as we wrap the stack index around to the other side.

```<code>5433333-'wrap around 543
54                   543
54                   54311111
5411111 .----------->54322222
5422222 |2 stacks up 543
</code>```

And so, we can keep doing this until we have exchanged all the stacks.

Code explanation:

First of all: The (important) predefined variables.

```<code>Q: Evaluated input.
b: The newline character, '\n'
d: A space, ' '
</code>```

There are 2 lambda definitions.

```<code>M           | g(G)(H), used for moving Q numbers at a time.
            | We will call these Q numbers a "(number) block"
 t          | Tail, used to remove beginning newline
  *Q        | Repeat the following Q times
    +++bGdH | '\n' + G + ' ' + H. Just a whole bunch of concatenating.
            |
M           | n(G)(H), used for figuring out which stacks to move from
 |       Q  | If the following code is 0 (false), then use Q instead
  %     Q   | Mod Q
   +   H    | Add H
    y       | Multiply by 2
     _G     | Negate (remember in the explanation part 2? Always 2 stacks above?)
</code>```

The stack exchanging: part 1

```<code>g1 2                       | Move the 1 block to stack 2
    ++Qd1                  | Move a Q to stack 1
         g2 3              | Move the 1 block to stack 3
             g2 1          | Move the 2 block to stack 1
                 g3 1      | Move the 1 block back to stack 1
                     ++Qd2 | Move a Q to stack 2
 v---Code-continuation---' |I don't have enough room!!!
Vr3Q                       | For N in range(3, Q)
    gNtN                   | Move the number block in stack N up 1
        ++QdN              | Move a Q to stack N
             ;g1Q          | End for loop; move the 1 block to the last stack
</code>```

The stack exchanging: part 2

```<code>VStQ                           | For N in [1, 2, ..., Q - 1]
    VStQ                       | For H in [1, 2, ..., Q - 1]
        I<NH                   | If N < H
            g                  | Number block move
             nNH               |  (find number block)
                nNtH           |  (find the previous stack)
                    )          | End "For H"
                     ++nN0dnNH | Find start, move number to next location down
</code>```

I already know I'm not getting brownie points, cuz I can see many more efficient and more complicated methods :(

ContentLicense: CC BY-SA 3.0

Title: Stack Exchanging

Body:
Pyth <s>96</s> 94 bytes

Mt*Q+++bGdHM|%+y_GHQQg1 2++Qd1g2 3g2 1g3 1++Qd2Vr3QgNtN++QdN;g1QVStQVStQI<NHgnNHnNtH)++nN0dnNH

Try it here

How does it work?

This explanation will be using N=5.

Part 1: Create the bottom layer on every stack

The reason why this is needs a separate piece of code is because every stack needs to be used: the first 4 need a 5 to be put beneath them, and the last stack must provide the 5s. This means that we can't just move all the 4s somewhere, put a 5 there, and move the 4s back.

Visualization: (parentheses mean what will be moved)

     _
11111 |
22222 |_ Can't move 4s here, not monotonically increasing
33333_|
(44444)------------??? Where to put the 4s?
55555 <- Must supply the 5 that will be moved

Instead, to do this first exchange, we will first move all the 1s over to to the second stack, move a 5 to the first stack (which is now empty), move the 1s to the third stack, move the 2s to the first stack, move the 1s back to the first stack, and finally move a 5 to the second stack.

(11111)-----.
2222211111<-'
===============================
5<---------.
2222211111 : (from stack 5)
===============================
5
22222(11111)-.
3333311111<--'
===============================
522222<-.
(22222)-'
3333311111
===============================
52222211111<-.
             |
33333(11111)-'
===============================
52222211111
5<-----.
33333  |
44444  |
555(5)-'

Now that we have a free space to move stacks into (stack 2, which only contains a 5 that is placed in the right spot), we can move all the 3s to stack 2 and place a 5 in stack 3. We can then repeat the same thing for stack 4, and now we get all the 5s in the right place! And just one more thing: we will move all the 1s to stack 5 so that we get a nice setup for the next stack exchange.

522222(11111)-.
533333        |
544444        |
5             |
511111<-------'

Part 2: Do everything else :)

This is much easier now, because now we will always have a free stack to move other numbers we need to juggle around into. So, first we figure out where the 4 is. A bit of examination will show that it will always be 1 up from where it started, or 2 above the last stack. Now, we just keep going down the stacks, placing a 4 in the stack if it's free, or moving the other numbers up 1 stack if it's not. Now we have all the 4s in place.

522222<------.
533333<----. |
544444-.-.-'-'
5<-----' |
511111<--'
===============================
5433333
54
54
5411111
5422222

Now, we realize that the 3s are 2 stacks above where the 4s where. This means that we can do the exact same thing we did with the 4s! And as it turns out, we can keep doing this as long as we wrap the stack index around to the other side.

5433333-'wrap around 543
54                   543
54                   54311111
5411111 .----------->54322222
5422222 |2 stacks up 543

And so, we can keep doing this until we have exchanged all the stacks.

Code explanation:

First of all: The (important) predefined variables.

Q: Evaluated input.
b: The newline character, '\n'
d: A space, ' '

There are 2 lambda definitions.

M           | g(G)(H), used for moving Q numbers at a time.
            | We will call these Q numbers a "(number) block"
 t          | Tail, used to remove beginning newline
  *Q        | Repeat the following Q times
    +++bGdH | '\n' + G + ' ' + H. Just a whole bunch of concatenating.
            |
M           | n(G)(H), used for figuring out which stacks to move from
 |       Q  | If the following code is 0 (false), then use Q instead
  %     Q   | Mod Q
   +   H    | Add H
    y       | Multiply by 2
     _G     | Negate (remember in the explanation part 2? Always 2 stacks above?)

The stack exchanging: part 1

g1 2                       | Move the 1 block to stack 2
    ++Qd1                  | Move a Q to stack 1
         g2 3              | Move the 1 block to stack 3
             g2 1          | Move the 2 block to stack 1
                 g3 1      | Move the 1 block back to stack 1
                     ++Qd2 | Move a Q to stack 2
 v---Code-continuation---' |I don't have enough room!!!
Vr3Q                       | For N in range(3, Q)
    gNtN                   | Move the number block in stack N up 1
        ++QdN              | Move a Q to stack N
             ;g1Q          | End for loop; move the 1 block to the last stack

The stack exchanging: part 2

VStQ                           | For N in [1, 2, ..., Q - 1]
    VStQ                       | For H in [1, 2, ..., Q - 1]
        I<NH                   | If N < H
            g                  | Number block move
             nNH               |  (find number block)
                nNtH           |  (find the previous stack)
                    )          | End "For H"
                     ++nN0dnNH | Find start, move number to next location down

I already know I'm not getting brownie points, cuz I can see many more efficient and more complicated methods :(


问:
Alternating Sign Sequence

Introduction

The sign of a number is either a +, or a - for every non-zero integer. Zero itself is signless (+0 is the same as -0). In the following sequence, we are going to alternate between the positive sign, the zero and the negative sign. The sequence starts with 1, so we write 1 with a positive sign, with zero (this one is weird, but we just multiply the number by 0) and the negative sign:

```<code>1, 0, -1
</code>```

The next number is 2, and we do the same thing again:

```<code>2, 0, -2
</code>```

The sequence eventually is:

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

Or a more readable form:

```<code>a(0) = 1
a(1) = 0
a(2) = -1
a(3) = 2
a(4) = 0
a(5) = -2
a(6) = 3
a(7) = 0
a(8) = -3
a(9) = 4
...
</code>```

The Task

Given a non-negative integer n, output the nth term of the above sequence. You can choose if you use the zero-indexed or one-indexed version.

Test cases:

Zero-indexed:

```<code>a(0) = 1
a(11) = -4
a(76) = 0
a(134) = -45
a(296) = -99
</code>```

Or if you prefer one-indexed:

```<code>a(1) = 1
a(12) = -4
a(77) = 0
a(135) = -45
a(297) = -99
</code>```

This is code-golf, so the submission with the smallest number of bytes wins!

答:
Cubix, 30 bytes

```<code>1..-.w>?^I3%?;,)O@...o-'.<u;;;
</code>```

Try it here.  You will need to replace the current code with the above and enter an input number.

This wraps onto a cube with an edge length of 3.  I'm hoping to reduce this a bit more, but at the moment it's not to bad.  It would be nice to have some of the planned features for the stack, but oh well.

```<code>      1 . .
      - . w
      > ? ^
I 3 % ? ; , ) O @ . . .
o - ' . < u ; ; ; . . .
. . . . . . . . . . . .
      . . .
      . . .
      . . .
</code>```

Explanation:

I 3 % ? Take a number from input, push a literal 3, mod on TOS and do a check.  The ? redirects right for negative and left for positive.  Pass through for zero

For zero value ; , ) O @ Pop, integer divide TOS, increment TOS, output number and terminate

For positive value 1 - > ? Push literal 1, subtract TOS, change direction and check

For zero value ^ w O @ Redirect up, sidestep left (ends up on another face), output number (zero in this case) and terminate

For positive value ; < ' - o ; ; ; u , ) O @ pop, redirect, push character -, output character, pop, pop, pop, u-turn to left, integer divide TOS, increment TOS, output number and terminate

Title: Alternating Sign Sequence

Body:
Cubix, 30 bytes

1..-.w>?^I3%?;,)O@...o-'.<u;;;

Try it here.  You will need to replace the current code with the above and enter an input number.

This wraps onto a cube with an edge length of 3.  I'm hoping to reduce this a bit more, but at the moment it's not to bad.  It would be nice to have some of the planned features for the stack, but oh well.

      1 . .
      - . w
      > ? ^
I 3 % ? ; , ) O @ . . .
o - ' . < u ; ; ; . . .
. . . . . . . . . . . .
      . . .
      . . .
      . . .

Explanation:

I 3 % ? Take a number from input, push a literal 3, mod on TOS and do a check.  The ? redirects right for negative and left for positive.  Pass through for zero

For zero value ; , ) O @ Pop, integer divide TOS, increment TOS, output number and terminate

For positive value 1 - > ? Push literal 1, subtract TOS, change direction and check

For zero value ^ w O @ Redirect up, sidestep left (ends up on another face), output number (zero in this case) and terminate

For positive value ; < ' - o ; ; ; u , ) O @ pop, redirect, push character -, output character, pop, pop, pop, u-turn to left, integer divide TOS, increment TOS, output number and terminate


问:
Generate The SUDSI Sequence
The SUDSI sequence (sum, difference, swap, increment) is a curious integer sequence that appears to exhibit rather chaotic behavior. It can be generated as follows:

Let S be an infinite list of the natural numbers: 1 2 3 4 5 6 .... Let Si denote the one-indexed ith element of S. So initially,  S1 is 1, S2 is 2, etc. (there is no S0).

Starting with S1 and S2 ...

Compute their sum: sum = S1 + S2

Compute their absolute difference (the larger one minus the smaller one): diff = |S1 - S2|

Swap the two values in S at the indices of the sum and difference: swap(Ssum, Sdiff)

Increment the indices of S you are working with. So next time you will compute the sum and difference of S2 and S3, and the time after that it will be S3 and S4, etc.

Repeat this process indefinitely.

Here are the first few stages of S as this process is applied. The brackets [] surround the two values that are about to be summed and differenced.

Original S:

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

After S3 (3 = 1 + 2) and S1 (1 = |1 - 2|) are swapped:

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

After S3 and S1 are swapped:

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

After S7 and S1 are swapped:

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

After S9 and S1 are swapped:

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

After S11 and S1 are swapped:

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

After S7 and S5 are swapped:

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

etc.

The SUDSI sequence is defined as the sequence of the first elements in each of these lists. So the first few terms of the SUDSI sequence are 1 3 1 7 9 11 11.

Here are the first 200 terms of the SUDSI sequence (20 per line):

```<code>1 3 1 7 9 11 11 11 15 15 19 19 19 19 19 19 19 19 19 19
19 19 19 19 19 19 19 19 57 59 59 59 59 59 59 59 59 59 77 79
81 83 85 87 89 91 91 91 91 91 91 91 91 91 91 91 91 91 115 115
121 123 125 127 127 127 127 127 137 139 141 143 145 147 147 147 147 147 147 147
147 147 147 147 167 167 167 167 167 167 167 167 167 167 167 167 167 167 167 167
167 167 167 167 209 211 211 211 211 211 221 223 223 223 223 223 223 223 223 223
223 223 243 243 243 243 243 243 257 259 261 263 263 263 263 263 263 263 263 263
263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263
263 263 325 327 329 331 331 331 331 331 331 331 331 331 349 351 351 351 351 351
361 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363
</code>```

It is unclear (to me at least) how one might predict future terms. It only feels safe to say that that the terms are always odd, non-decreasing (after the second term), and that some numbers are repeated lots of times.

Challenge

Write a program or function that takes in a positive integer n and prints or returns the nth term of the SUDSI sequence. For example, if n is 1, the output is 1, if n is 2, the output is 3, if n is 200, the output is 363.

Take input in any usual way (stdin/command line/function arg).

The shortest answer in bytes wins.

(That site encodes things in UTF-8, but you may use any darn existing encoding you want.)

Mathy bonus: (potentially eligible for bounty)

Tell me more about the SUDSI sequence. What's the underlying pattern to what numbers are part of it and how many of them there are (and stuff like that)? (I couldn't find SUDSI on OEIS by the way.)

答:
dc, 134 132 131 bytes

```<code>[_1*]sOdsn2*ddslsSsa[ladd:S1-dsa0<P]dsPx1d0rsN:N[la1+dsad;SdS@r1+;SdS@rL@L@r+Ss-d0>Od;SrLsdSsrLs;Sr:S:S1;SladsN:Nlaln>G]dsGxln1-;Nf
</code>```

Use echo $n $code | dc, where $n is n and $code is...the code (gasp). Quote to taste.

Edit: Unless you pester me for an explanation, I  will never get around to it.

Title: Generate The SUDSI Sequence

Body:
dc, 134 132 131 bytes

[_1*]sOdsn2*ddslsSsa[ladd:S1-dsa0<P]dsPx1d0rsN:N[la1+dsad;SdS@r1+;SdS@rL@L@r+Ss-d0>Od;SrLsdSsrLs;Sr:S:S1;SladsN:Nlaln>G]dsGxln1-;Nf

Use echo $n $code | dc, where $n is n and $code is...the code (gasp). Quote to taste.

Edit: Unless you pester me for an explanation, I  will never get around to it.


问:
Jam don't add like that

Background

Jelly's arithmetic atoms vectorize automatically. In fact, x + y is well-defined whenever x and y are numbers or ragged arrays of numbers. Jelly's source code implements this behavior using a generic vectorizer, but for this challenge, we'll only consider addition of integers and nested integer arrays.

Definitions

Define the depth of x as 0 if x is an integer, as 1 if it is a (possibly empty) flat array of integers, and as n + 1 if it contains at least one element of depth n and no elements of depth k > n.

This way, 1 has depth 0, [] and [1] and [1, 1] have depth 1, [[], []] and [[1], [1]] and [[1]] and [1, []] have depth 2, [1, [1, [1]]] has depth 3, etc.

The operation x + y is defined as follows.

If x and y have depth 0, return their sum.

If x and y have equal but positive depths, recursively apply + to all items of x and the corresponding items of y.

If x and y have different lengths, append the tail of the longer array to the array of sums.

Return the result.

If x's depth is strictly smaller than y's depth, recursively apply + to x and all items of y, and return the result.

Do the opposite if y's depth is strictly smaller than x's.

For example, consider the operation [1, [2, 3], [4]] + [[[10, 20], [30], 40, 50], 60].

The depth of the left argument is 2, while the depth of the right argument is 3, so we compute [1, [2, 3], [4]] + [[10, 20], [30], 40, 50] and [1, [2, 3], [4]] + 60.

[1, [2, 3], [4]] and [[10, 20], [30], 40, 50] both have depth 2, so we compute 1 + [10, 20], [2, 3] + [30] and [4] + 40.

1 + [10, 20] = [1 + 10, 1 + 20] = [11, 21]

[2, 3] + [30] = [2 + 30, 3] = [32, 3]

Note that 3 remains untouched, since it doesn't have a matching element.

[4] + 40 = [4 + 40] = [44]

50 doesn't have a matching element, so the result is [[[11, 21], [32, 3], [44], 50]].

[1, [2, 3], [4]] + 60 = [1 + 60, [2, 3] + 60, [4] + 60] = [61, [2 + 60, 3 + 60], [4 + 60]], resulting in [61, [62, 63], [64]].

The final result is [[[11, 21], [32, 3], [44], 50], [61, [62, 63], [64]]].

Task

Write a program or a function that takes two integers, two nested arrays of integers or a combination thereof as input and returns their sum, as defined above.

If your language has multiple array-like types (lists, tuples, vectors, etc.) you may choose any of them for your answer. The return type must match the argument type.

To prevent boring and unbeatable solutions, if a language has this exact operation as a built-in, you may not use that language.

All built-ins of all other languages are allowed. If your language of choice permits this, you may overload and/or redefine the built-in addition.

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

Test cases

```<code>0 + 0                           = 0
[-1, 0, -1] + [1]               = [0, 0, -1]
[] + [0]                        = [0]
[] + 0                          = []
[] + []                         = []
[[], 0] + []                    = [[], []]
[1, 2, 3] + 10                  = [11, 12, 13]
[1, 2, 3] + [10]                = [11, 2, 3]
[1, 2, 3] + [10, [20]]          = [[11, 12, 13], [21, 2, 3]]
[1, 2, 3, []] + [10, [20]]      = [11, [22], 3, []]
[1, [2, [3, [4]]]] + [10, [20]] = [[11, [21]], [[12, [22]], [13, [24]]]]
</code>```

To generate more test cases, you can use this Jelly program.

答:
Python 2.7, <s>261</s> <s>209</s> <s>202</s> <s>198</s> <s>191</s> <s>185</s> <s>197</s> 181 bytes

FGITW trivial solution

EDIT: Of course @Dennis beats it

Thanks to @LeakyNun for saving 57 bytes with tips on lambda expressions, and 2 bytes from unneeded brackets.

Thanks to @Adnan for 4 bytes due to suggestion to use type instead of isinstance

Thanks to @Lynn for 7 bytes with -~ and map

Thanks to @FryAmTheEggman for z>=[] instead of type

+12 bytes to convert lambda to if else and fix a major bug

-16 bytes thanks to @Kevin Lau - not Kenny

Try it online

```<code>d=lambda z:z==[]or z>[]and-~max(map(d,z))
p=lambda x,y:p(y,x)if d(x)>d(y)else(x+y if d(x)<1 else[p(a,b)for a,b in zip(x,y)]+x[len(y):]+y[len(x):])if d(x)==d(y)else[p(a,x)for a in y]
</code>```

Title: Jam don't add like that

Body:
Python 2.7, <s>261</s> <s>209</s> <s>202</s> <s>198</s> <s>191</s> <s>185</s> <s>197</s> 181 bytes

FGITW trivial solution

EDIT: Of course @Dennis beats it

Thanks to @LeakyNun for saving 57 bytes with tips on lambda expressions, and 2 bytes from unneeded brackets.

Thanks to @Adnan for 4 bytes due to suggestion to use type instead of isinstance

Thanks to @Lynn for 7 bytes with -~ and map

Thanks to @FryAmTheEggman for z>=[] instead of type

+12 bytes to convert lambda to if else and fix a major bug

-16 bytes thanks to @Kevin Lau - not Kenny

Try it online

d=lambda z:z==[]or z>[]and-~max(map(d,z))
p=lambda x,y:p(y,x)if d(x)>d(y)else(x+y if d(x)<1 else[p(a,b)for a,b in zip(x,y)]+x[len(y):]+y[len(x):])if d(x)==d(y)else[p(a,x)for a in y]


问:
Stack Overflowing
(Inspired by this question)

Objective

Your task is to write a program or function to print an ASCII version of the Stack Overflow logo to STDOUT

```<code> \|/
(-)
(-)
(-)
(-)
</code>```

Your program should take two inputs, referred to here as H and N.
The height of the stack "container" (the parentheses) is determined by H. The number of items in the stack is determined by N. If N>H, the stack will "overflow".

Input/Output

H will determine the height of the containers

For example:

H=1:

```<code>( )
</code>```

H=2:

```<code>( )
( )
</code>```

H=3:

```<code>( )
( )
( )
</code>```

H will always be at least 1

N will determine how many items are in the stack. The following examples are all H = 2:

N=0

```<code>( )
( )
</code>```

N=1

```<code>( )
(-)
</code>```

N=2

```<code>(-)
(-)
</code>```

N=3

```<code> \
(-)
(-)
</code>```

N=4

```<code> \|
(-)
(-)
</code>```

N=5

```<code> \|/
(-)
(-)
</code>```

N=6

```<code>( )
</code>```0

N=7

```<code>( )
</code>```1

N will never be more than 2H+3 (In other words, the stack will never go through the ground).

Rules

No Standard Loopholes.

Your program must not produce any errors.

All test cases must pass.

You can input H and N any way you want.

I seriously doubt that your language has a built-in for this.

Each line may optionally have an extra space at the end. A blank line above a stack where N <= H is optional, as is a trailing newline.

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

Test Cases

In addition to all of the H=2 test cases from the Input/Output section, all of the following test cases must pass:

H=1, N=1

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

H=1, N=5

```<code> \|/
(-)-
</code>```

H=4, N=7

```<code> \|/
(-)
(-)
(-)
(-)
</code>```

H=5, N=0

```<code>( )
( )
( )
( )
( )
</code>```

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=81167,OVERRIDE_USER=41505;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

```

答:
JavaScript (ES6), <s>126</s> <s>122</s> 112 bytes

```<code>h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )`[r='repeat'](0>-o?0:-o)+`
(-)-`[r](o=0>o-3?0:o-3)+`
(-)`[r](n<h-o?n:h-o)
</code>```

Test

f=h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )`[r='repeat'](0>-o?0:-o)+`
(-)-`[r](o=0>o-3?0:o-3)+`
(-)`[r](n<h-o?n:h-o)
document.write(````${[[2,0],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[1,1],[1,5],[4,7],[5,0]].map(a=>f(a.shift())(a.shift())).join`

`}````)```
</div>
</div>
</p>

<h2>Alternate Test (if your browser does not support ES6)</h2>

<p>See the test on Babeljs.io and check "evaluate".</p>

<h2>Interesting alternate approach at 136 bytes</h2>

```h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )${0>-o?0:-o}
(-)-${o=0>o-3?0:o-3}
(-)${n<h-o?n:h-o}`.replace(/(\n.*)(\d+)/g,(_,s,r)=>s.repeat(r))
```

This moves the repeat amounts into the template string and uses a regexp and replace to inject the repeating groups. Unfortunately the signature for .replace() is just too long.

Title: Stack Overflowing

Body:
JavaScript (ES6), <s>126</s> <s>122</s> 112 bytes

h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )`[r='repeat'](0>-o?0:-o)+`
(-)-`[r](o=0>o-3?0:o-3)+`
(-)`[r](n<h-o?n:h-o)

Test

f=h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )`[r='repeat'](0>-o?0:-o)+`
(-)-`[r](o=0>o-3?0:o-3)+`
(-)`[r](n<h-o?n:h-o)
document.write(`<pre>${[[2,0],[2,1],[2,2],[2,3],[2,4],[2,5],[2,6],[2,7],[1,1],[1,5],[4,7],[5,0]].map(a=>f(a.shift())(a.shift())).join`

`}</pre>`)

Alternate Test (if your browser does not support ES6)

See the test on <a href="https://babeljs.io/repl/#?evaluate=false&presets=es2015-loose&code=f%3Dh%3D%3En%3D%3E'%20%5C%5C%7C%2F'.substr(0%2C(o%3Dn-h)%2B1)%2B%60%0D%0A(%20)%60%5Br%3D'repeat'%5D(0%3E-o%3F0%3A-o)%2B%60%0D%0A(-)-%60%5Br%5D(o%3D0%3Eo-3%3F0%3Ao-3)%2B%60%0D%0A(-)%60%5Br%5D(n%3Ch-o%3Fn%3Ah-o)%0D%0Adocument.write(%60%3Cpre%3E%24%7B%5B%5B2%2C0%5D%2C%5B2%2C1%5D%2C%5B2%2C2%5D%2C%5B2%2C3%5D%2C%5B2%2C4%5D%2C%5B2%2C5%5D%2C%5B2%2C6%5D%2C%5B2%2C7%5D%2C%5B1%2C1%5D%2C%5B1%2C5%5D%2C%5B4%2C7%5D%2C%5B5%2C0%5D%5D.map(a%3D%3Ef(a.shift())(a.shift())).join%60%0D%0A%0D%0A%60%7D%3C%2Fpre%3E%60)">Babeljs.io and check "evaluate".

Interesting alternate approach at 136 bytes

h=>n=>' \\|/'.substr(0,(o=n-h)+1)+`
( )${0>-o?0:-o}
(-)-${o=0>o-3?0:o-3}
(-)${n<h-o?n:h-o}`.replace(/(\n.*)(\d+)/g,(_,s,r)=>s.repeat(r))

This moves the repeat amounts into the template string and uses a regexp and replace to inject the repeating groups. Unfortunately the signature for .replace() is just too long.


答:
Pyth, <s>43</s> <s>41</s> 40 bytes

```<code><" \|/"g#0hK-QJEVJs[\(?<N_Kd\-\)*<N-K3\-
</code>```

Try it online. Test suite.

First pass, quick and dirty. Input to STDIN as N\nH.

Explanation

Save the second input (height) to J (JE), and subtract it from the first input (the number of items). (-QJE)

Save the difference (number of overflowing items) to K. (K-QJE)

Add 1 to the number. (hK-QJE)

Take max(0, previous). This is required as negative numbers would break the next step. (g#0hK-QJE)

Take at most that many letters from the string " \|/" to get the first line and print. (<" \|/"g#0hK-QJE)

Loop N over range(0, J). (VJ) For each N print the concatenation of the following: (s[)

"(" (\()

" " if there are at least N+1 free spaces in the stack (<N_K), "-" otherwise. (?<N_Kd\-)

")" (\))

"-" if there are at least N+4 overflowing pieces in the stack (<N-K3), "" otherwise. (*<N-K3\-)

Title: Stack Overflowing

Body:
(Inspired by this question)

Objective

Your task is to write a program or function to print an ASCII version of the Stack Overflow logo to STDOUT

```<code> \|/
(-)
(-)
(-)
(-)
</code>```

Your program should take two inputs, referred to here as H and N.
The height of the stack "container" (the parentheses) is determined by H. The number of items in the stack is determined by N. If N>H, the stack will "overflow".

Input/Output

H will determine the height of the containers

For example:

H=1:

```<code>( )
</code>```

H=2:

```<code>( )
( )
</code>```

H=3:

```<code>( )
( )
( )
</code>```

H will always be at least 1

N will determine how many items are in the stack. The following examples are all H = 2:

N=0

```<code>( )
( )
</code>```

N=1

```<code>( )
(-)
</code>```

N=2

```<code>(-)
(-)
</code>```

N=3

```<code> \
(-)
(-)
</code>```

N=4

```<code> \|
(-)
(-)
</code>```

N=5

```<code> \|/
(-)
(-)
</code>```

N=6

```<code>( )
</code>```0

N=7

```<code>( )
</code>```1

N will never be more than 2H+3 (In other words, the stack will never go through the ground).

Rules

No Standard Loopholes.

Your program must not produce any errors.

All test cases must pass.

You can input H and N any way you want.

I seriously doubt that your language has a built-in for this.

Each line may optionally have an extra space at the end. A blank line above a stack where N <= H is optional, as is a trailing newline.

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

Test Cases

In addition to all of the H=2 test cases from the Input/Output section, all of the following test cases must pass:

H=1, N=1

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

H=1, N=5

```<code> \|/
(-)-
</code>```

H=4, N=7

```<code> \|/
(-)
(-)
(-)
(-)
</code>```

H=5, N=0

```<code>( )
( )
( )
( )
( )
</code>```

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=81167,OVERRIDE_USER=41505;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Pyth, <s>43</s> <s>41</s> 40 bytes

<" \|/"g#0hK-QJEVJs[\(?<N_Kd\-\)*<N-K3\-

Try it online. Test suite.

First pass, quick and dirty. Input to STDIN as N\nH.

Explanation

Save the second input (height) to J (JE), and subtract it from the first input (the number of items). (-QJE)

Save the difference (number of overflowing items) to K. (K-QJE)

Add 1 to the number. (hK-QJE)

Take max(0, previous). This is required as negative numbers would break the next step. (g#0hK-QJE)

Take at most that many letters from the string " \|/" to get the first line and print. (<" \|/"g#0hK-QJE)

Loop N over range(0, J). (VJ) For each N print the concatenation of the following: (s[)

"(" (\()

" " if there are at least N+1 free spaces in the stack (<N_K), "-" otherwise. (?<N_Kd\-)

")" (\))

"-" if there are at least N+4 overflowing pieces in the stack (<N-K3), "" otherwise. (*<N-K3\-)


答:
Perl 5, 131

A naive solution (i.e. a direct implementation of the definition). A subroutine, it takes input as a list of 1s of the desired length.

```<code>{map$a[$_]=$_,1..3*@_;($a[$a[$_-1]+$a[$_]],$a[abs($a[$_-1]-$a[$_])])=($a[abs($a[$_-1]-$a[$_])],$a[$a[$_-1]+$a[$_]])for 2..@_;$a[1]}
</code>```

Visualize its output by e.g. print sub...->(1,1,1,1,1).

Explanation:

map$a[$_]=$_,1..3*@_ builds the array @a, indexing each integer by itself from 1 to 3 times the size of @_ (the input).

($a[$a[$_-1]+$a[$_]],$a[abs($a[$_-1]-$a[$_])])=($a[abs($a[$_-1]-$a[$_])],$a[$a[$_-1]+$a[$_]])for 2..@_ repeats the switcheroo repeatedly (one fewer times than the size of @_), switching $a[$a[$_-1]+$a[$_]] with $a[abs($a[$_-1]-$a[$_])] as $_ ranges from 2 to the size of @_.

And then the subroutine returns $a[1].

Title: Generate The SUDSI Sequence

Body:
The SUDSI sequence (sum, difference, swap, increment) is a curious integer sequence that appears to exhibit rather chaotic behavior. It can be generated as follows:

Let S be an infinite list of the natural numbers: 1 2 3 4 5 6 .... Let Si denote the one-indexed ith element of S. So initially,  S1 is 1, S2 is 2, etc. (there is no S0).

Starting with S1 and S2 ...

Compute their sum: sum = S1 + S2

Compute their absolute difference (the larger one minus the smaller one): diff = |S1 - S2|

Swap the two values in S at the indices of the sum and difference: swap(Ssum, Sdiff)

Increment the indices of S you are working with. So next time you will compute the sum and difference of S2 and S3, and the time after that it will be S3 and S4, etc.

Repeat this process indefinitely.

Here are the first few stages of S as this process is applied. The brackets [] surround the two values that are about to be summed and differenced.

Original S:

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

After S3 (3 = 1 + 2) and S1 (1 = |1 - 2|) are swapped:

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

After S3 and S1 are swapped:

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

After S7 and S1 are swapped:

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

After S9 and S1 are swapped:

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

After S11 and S1 are swapped:

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

After S7 and S5 are swapped:

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

etc.

The SUDSI sequence is defined as the sequence of the first elements in each of these lists. So the first few terms of the SUDSI sequence are 1 3 1 7 9 11 11.

Here are the first 200 terms of the SUDSI sequence (20 per line):

```<code>1 3 1 7 9 11 11 11 15 15 19 19 19 19 19 19 19 19 19 19
19 19 19 19 19 19 19 19 57 59 59 59 59 59 59 59 59 59 77 79
81 83 85 87 89 91 91 91 91 91 91 91 91 91 91 91 91 91 115 115
121 123 125 127 127 127 127 127 137 139 141 143 145 147 147 147 147 147 147 147
147 147 147 147 167 167 167 167 167 167 167 167 167 167 167 167 167 167 167 167
167 167 167 167 209 211 211 211 211 211 221 223 223 223 223 223 223 223 223 223
223 223 243 243 243 243 243 243 257 259 261 263 263 263 263 263 263 263 263 263
263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263 263
263 263 325 327 329 331 331 331 331 331 331 331 331 331 349 351 351 351 351 351
361 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363 363
</code>```

It is unclear (to me at least) how one might predict future terms. It only feels safe to say that that the terms are always odd, non-decreasing (after the second term), and that some numbers are repeated lots of times.

Challenge

Write a program or function that takes in a positive integer n and prints or returns the nth term of the SUDSI sequence. For example, if n is 1, the output is 1, if n is 2, the output is 3, if n is 200, the output is 363.

Take input in any usual way (stdin/command line/function arg).

The shortest answer in bytes wins.

(That site encodes things in UTF-8, but you may use any darn existing encoding you want.)

Mathy bonus: (potentially eligible for bounty)

Tell me more about the SUDSI sequence. What's the underlying pattern to what numbers are part of it and how many of them there are (and stuff like that)? (I couldn't find SUDSI on OEIS by the way.)

Body:
Perl 5, 131

A naive solution (i.e. a direct implementation of the definition). A subroutine, it takes input as a list of 1s of the desired length.

{map$a[$_]=$_,1..3*@_;($a[$a[$_-1]+$a[$_]],$a[abs($a[$_-1]-$a[$_])])=($a[abs($a[$_-1]-$a[$_])],$a[$a[$_-1]+$a[$_]])for 2..@_;$a[1]}

Visualize its output by e.g. print sub...->(1,1,1,1,1).

Explanation:

map$a[$_]=$_,1..3*@_ builds the array @a, indexing each integer by itself from 1 to 3 times the size of @_ (the input).

($a[$a[$_-1]+$a[$_]],$a[abs($a[$_-1]-$a[$_])])=($a[abs($a[$_-1]-$a[$_])],$a[$a[$_-1]+$a[$_]])for 2..@_ repeats the switcheroo repeatedly (one fewer times than the size of @_), switching $a[$a[$_-1]+$a[$_]] with $a[abs($a[$_-1]-$a[$_])] as $_ ranges from 2 to the size of @_.

And then the subroutine returns $a[1].


答:
C++14 (lambda function), 196

Saved 1 byte thanks to Quentin.

Saved 2 bytes thanks to Adam Martin.

#include<iostream>
using namespace std;[](int h,int n){auto s=" \\|/( ) (-) (-)-"s;int t=max(min(n-h,3),0);n-=t;cout<<s.substr(0,t+1)+'\n';for(;h;h--)n-=t=n>h?2:h<=n,cout<<s.substr(4+4*t,4)+'\n';}
```
<p>The function itself takes 157 bytes.</p>
<p>See it in action here.</p>
<p>Ungolfed version:</p>
<pre class="lang-cpp prettyprint-override"><code>[](int h, int n) {
    auto s = " \\|/( ) (-) (-)-"s;
    int t = max(min(n - h, 3), 0);
    n -= t;
    cout << s.substr(0, t + 1) + '\n';
    for(; h; h--) {
        if (n > h) t = 2;
        else if (h > n) t = 0;
        else t = 1;
        n -= t;
        cout << s.substr(4 + 4 * t, 4) + '\n';
    }
};
</code>```

Title: Stack Overflowing

Body:
C++14 (lambda function), 196

Saved 1 byte thanks to Quentin.

Saved 2 bytes thanks to Adam Martin.

#include<iostream>
using namespace std;[](int h,int n){auto s=" \\|/( ) (-) (-)-"s;int t=max(min(n-h,3),0);n-=t;cout<<s.substr(0,t+1)+'\n';for(;h;h--)n-=t=n>h?2:h<=n,cout<<s.substr(4+4*t,4)+'\n';}

The function itself takes 157 bytes.

See it in action here.

Ungolfed version:

[](int h, int n) {
    auto s = " \\|/( ) (-) (-)-"s;
    int t = max(min(n - h, 3), 0);
    n -= t;
    cout << s.substr(0, t + 1) + '\n';
    for(; h; h--) {
        if (n > h) t = 2;
        else if (h > n) t = 0;
        else t = 1;
        n -= t;
        cout << s.substr(4 + 4 * t, 4) + '\n';
    }
};


问:
Mode (most common element) of a list
Write a snippet to calculate the mode (most common number) of a list of positive integers.

For example, the mode of

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

is 1, because it occurs the maximum of 5 times.

You may assume that the list is stored in a variable such as d and has a unique mode.

e.g.: Python, 49

```<code>max(((i,d.count(i))for i in set(d)), key=lambda x:x[1])
</code>```

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

答:
PHP, <s>53</s> 50 bytes

```<code><?=array_flip($c=array_count_values($d))[max($c)];
</code>```

Run like this:

```<code>echo '<?php $d=$argv;?><?=array_flip($c=array_count_values($d))[max($c)]; echo"\n";' | php -- 4 3 1 0 6 1 6 4 4 0 3 1 7 7 3 4 1 1 2 8
</code>```

Tweaks

Saved 3 bytes by making use of the freedom to assume the input is assigned to a variable d

Title: Mode (most common element) of a list

Body:
PHP, <s>53</s> 50 bytes

<?=array_flip($c=array_count_values($d))[max($c)];

Run like this:

echo '<?php $d=$argv;?><?=array_flip($c=array_count_values($d))[max($c)]; echo"\n";' | php -- 4 3 1 0 6 1 6 4 4 0 3 1 7 7 3 4 1 1 2 8

Tweaks

Saved 3 bytes by making use of the freedom to assume the input is assigned to a variable d


问:
Why was 6 afraid of 7?

Why was 6 afraid of 7? Because 7 8 9!

Given a string apply the following transformations:

If there is a 6 next to a 7 remove the 6 (6 is afraid of 7)

If the sequence "789" appears remove the 8 and the 9 (7 ate 9)

(If I'm not mistaken it doesn't matter what order you do the transformations in)

Keep applying these transformations until you can no longer.

Example:

78966

First we see "789", so the string becomes "766". Then we see "76", so we take out the 6, and the string becomes "76". Then we see "76" again, so we are left with "7".

Test Cases:

987 => 987 (Not in the right order. Does nothing.)

6 7 => 6 7 (The whitespace acts as a buffer between 6 and 7. Nothing happens)

676 => 7

7896789 => 77

7689 => 7

abcd => abcd

答:
///, 19 bytes

```<code>/67/7//76/7//789/7/
</code>```

You can't actually provide input in this language, so the supposed input goes to the right of the code, which is allowed by recent rules.

Title: Why was 6 afraid of 7?

Body:
///, 19 bytes

/67/7//76/7//789/7/

You can't actually provide input in this language, so the supposed input goes to the right of the code, which is allowed by recent rules.

ContentLicense: CC BY-SA 4.0


答:
CJam, 57 bytes

```<code>Sri:X'(*+X),W%X)X')*+X),X))f+]zN*X5*,X'-*_"\|/"\++ri<S+er
</code>```

Test it here.

Could definitely use some improvement. The idea is to build a grid where the -\|/- cells are replaced with consecutive integers, e.g.

```<code> 345
(2)6
(1)7
(0)8
</code>```

And then to replace them with the correct characters (potentially spaces) at the end.

Title: Stack Overflowing

Body:
CJam, 57 bytes

Sri:X'(*+X),W%X)X')*+X),X))f+]zN*X5*,X'-*_"\|/"\++ri<S+er

Test it here.

Could definitely use some improvement. The idea is to build a grid where the -\|/- cells are replaced with consecutive integers, e.g.

 345
(2)6
(1)7
(0)8

And then to replace them with the correct characters (potentially spaces) at the end.


问:
Find the smallest number bigger than the input whose digital sum is the input
"Digital sum" refers to the sum of all the digits in a number.

For example, the digital sum of 1324 is 10, because 1+3+2+4 = 10.

The challenge is to write a program/function to calculate the smallest number bigger than the input whose digital sum is the input.

Example with walkthrough

As an example, take the number 9 as the input:

```<code>9 = 1+8 -> 18
9 = 2+7 -> 27
9 = 3+6 -> 36
...
9 = 8+1 -> 81
9 = 9+0 -> 90
</code>```

The valid output would be the smallest number above, which is 18.

Specs

Note that 9 is not the valid output for this example, because the reversed number must be greater than the original number.

Note that the input will be positive.

Test-Cases:

```<code> 2 => 11      (2 = 1 + 1)
 8 => 17      (8 = 1 + 7)
12 => 39     (12 = 3 + 9)
16 => 79     (16 = 7 + 9)
18 => 99     (18 = 9 + 9)
24 => 699    (24 = 6 + 9 + 9)
32 => 5999   (32 = 5 + 9 + 9 + 9)
</code>```

References:

This is OEIS A161561.

Edit: Added an additional Testcase (18)

Thanks to Martin Ender for the Leaderboard Snippet

var QUESTION_ID=81047,OVERRIDE_USER=31373;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

```

答:
PHP, 77 characters

```<code>$n=$argv[1];$m=$n+1;while(1){if(array_sum(str_split($m))==$n)die("$m");$m++;}
</code>```

Body:
PHP, 77 characters

$n=$argv[1];$m=$n+1;while(1){if(array_sum(str_split($m))==$n)die("$m");$m++;}


问:
Simulate a 'battle' in the playing card game 'Oorlog'
Let's build a simulation for an aspect in the card game, which I personally know by the Dutch name 'Oorlog' (translates to 'War').

How does 'Oorlog' work?

Two decks of cards (each including two Jokers) are equally divided between the amount of players playing. Each player shuffles their own stock, put it upside down in front of them, and all players open up the first card of the stock at the same time.

The winner of that 'battle' is determined by the values of the cards following these rules: Joker/Ace defeats King; King defeats Queen; Queen defeats Jack; Jack defeats 10; 10 defeats 9; .... In addition, both 2 and 3 defeat Ace/Joker. The last rule may lead to a cycle where 2 or 3 beats Ace or Joker, Ace or Joker beats some other card, which in turn beats the 2 or 3. In this case, the 2 or 3 wins the battle.

(Suit is irrelevant in this card game.)

When two or more players have the equal highest cards, they have a 'war'. This means they put one card upside down, and then each opens up a new card from their stock, again looking who has the highest card. This continues until a single player wins the entire battle.

(All cards of that battle go to the discard pile of the player that won the battle. Then everyone opens up a new card. When a player's stock is out of cards, they turn their discard pile upside down and continue with this new stock. This continues until a player is out of all his/her cards and then the player with the highest amount of cards wins.)

Example 'battles' with three players:

4, 8, Jack:

Jack wins.

7, Ace, Queen:

Ace wins.

10, 10, King:

King wins.

3, Joker, 2:

3 wins.

Ace, Joker, 2:

2 wins.

3, Queen, Ace:

3 wins.

Queen, Queen, 9:

Queen & Queen are having a 'war', so it continues with two new cards: 4, 8;

8 wins.

4, 4, 4:

All are having a 'war', so it continues with three new cards: 8, Ace, 2;

2 wins.

Jack, 5, Jack:

Jack & Jack are having a 'war', so it continues with two new cards: 5, 5;

5 & 5 are also equal, so the 'war' continues again with two new cards: 10, King;

King wins.

Joker, Joker, Ace:

All are having a 'war', so it continue with three new cards: 9, 7, 9;

9 & 9 are also equal, so the 'war' continues with two new cards: Jack, 3;

Jack wins.

So, onto the code challenge:

Input:

STDIN with an array, or a string simulating an array (your call - even if your language does support arrays). This array contains the cards of a battle in chronological order (see test cases for a clearer understanding of this).

Output:

STDOUT the index of the player that won the battle.

You can choose whether you want a zero-indexed (i.e. 0, 1, or 2) or one-indexed output (i.e. 1, 2, 3).

Challenge rules:

The input will be a single array / string representing an array. So you can't have an array of arrays to simplify it. You also can't have surrogate items for cards not participating in the war.

We use number notations for the face-cards instead of letter notation. So Ace/Joker = 1; Jack = 11; Queen = 12; and King = 13.

In this challenge we can assume we are always playing with 3 players.

The first three indicate the start of the 'battle'. When two or more players have a 'war' the continuing cards in the array indicate their battle (see test cases for a clearer understanding of this).

General rules:

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

This doesn't mean non code-golfing languages shouldn't enter. Try to come up with an as short as possible code-golf answer for 'every' programming language.

Please mention which indexing (zero- or one-indexed) you've used for the output.

Test cases:

```<code>Test case 1:  [4, 8, 11]                 ->  2 (or 3)
Test case 2:  [7, 1, 12]                 ->  1 (or 2)
Test case 3:  [10, 10, 13]               ->  2 (or 3)
Test case 4:  [3, 1, 2]                  ->  0 (or 1)
Test case 5:  [1, 1, 2]                  ->  2 (or 3)
Test case 6:  [3, 12, 1]                 ->  0 (or 1)
Test case 7:  [12, 12, 9, 4, 8]          ->  1 (or 2)
Test case 8:  [4, 4, 4, 8, 1, 2]         ->  2 (or 3)
Test case 9:  [11, 5, 11, 5, 5, 10, 13]  ->  2 (or 3)
Test case 10: [1, 1, 1, 9, 7, 9, 11, 3]  ->  0 (or 1)
Test case 11: [13, 13, 4, 1, 3]          ->  1 (or 2)
Test case 12: [13, 4, 13, 2, 3]          ->  2 (or 3)
</code>```

答:
q - 142 characters

```<code>{p:til 3;while[1<(#:)p;h:(n:(#:)p)#x;x:n _x;$[1~min h;p:$[max a:h in(2;3);$[1<(#:)(?:)h(&:)a;p(&:)h=3;p(&:)a];p(&:)h=1];p:p(&:)h=max h]];(*:)p}
</code>```

Note: zero indexed.

There is no notion of reading stdin in q, so you should call it as a function:
{p:til 3;while[1<(#:)p;h:(n:(#:)p)#x;x:n _x;$[1~min h;p:$[max a:h in(2;3);$[1<(#:)(?:)h(&:)a;p(&:)h=3;p(&:)a];p(&:)h=1];p:p(&:)h=max h]];(*:)p}[1,2,3]

Pretty long, actually, but there are plenty of corner cases. It keeps a roster of active players, and consumes the list of cards in a loop. The most problematic thing is to detect the correct winner in hands like [13, 2, 3], since 3 beats 2, as normal, but it had to be duplicated to be put into the corner case.

Body:
q - 142 characters

{p:til 3;while[1<(#:)p;h:(n:(#:)p)#x;x:n _x;$[1~min h;p:$[max a:h in(2;3);$[1<(#:)(?:)h(&:)a;p(&:)h=3;p(&:)a];p(&:)h=1];p:p(&:)h=max h]];(*:)p}

Note: zero indexed.

There is no notion of reading stdin in q, so you should call it as a function:
{p:til 3;while[1<(#:)p;h:(n:(#:)p)#x;x:n _x;$[1~min h;p:$[max a:h in(2;3);$[1<(#:)(?:)h(&:)a;p(&:)h=3;p(&:)a];p(&:)h=1];p:p(&:)h=max h]];(*:)p}[1,2,3]

Pretty long, actually, but there are plenty of corner cases. It keeps a roster of active players, and consumes the list of cards in a loop. The most problematic thing is to detect the correct winner in hands like [13, 2, 3], since 3 beats 2, as normal, but it had to be duplicated to be put into the corner case.


Title: Jam don't add like that

Body:
Background

Jelly's arithmetic atoms vectorize automatically. In fact, x + y is well-defined whenever x and y are numbers or ragged arrays of numbers. Jelly's source code implements this behavior using a generic vectorizer, but for this challenge, we'll only consider addition of integers and nested integer arrays.

Definitions

Define the depth of x as 0 if x is an integer, as 1 if it is a (possibly empty) flat array of integers, and as n + 1 if it contains at least one element of depth n and no elements of depth k > n.

This way, 1 has depth 0, [] and [1] and [1, 1] have depth 1, [[], []] and [[1], [1]] and [[1]] and [1, []] have depth 2, [1, [1, [1]]] has depth 3, etc.

The operation x + y is defined as follows.

If x and y have depth 0, return their sum.

If x and y have equal but positive depths, recursively apply + to all items of x and the corresponding items of y.

If x and y have different lengths, append the tail of the longer array to the array of sums.

Return the result.

If x's depth is strictly smaller than y's depth, recursively apply + to x and all items of y, and return the result.

Do the opposite if y's depth is strictly smaller than x's.

For example, consider the operation [1, [2, 3], [4]] + [[[10, 20], [30], 40, 50], 60].

The depth of the left argument is 2, while the depth of the right argument is 3, so we compute [1, [2, 3], [4]] + [[10, 20], [30], 40, 50] and [1, [2, 3], [4]] + 60.

[1, [2, 3], [4]] and [[10, 20], [30], 40, 50] both have depth 2, so we compute 1 + [10, 20], [2, 3] + [30] and [4] + 40.

1 + [10, 20] = [1 + 10, 1 + 20] = [11, 21]

[2, 3] + [30] = [2 + 30, 3] = [32, 3]

Note that 3 remains untouched, since it doesn't have a matching element.

[4] + 40 = [4 + 40] = [44]

50 doesn't have a matching element, so the result is [[[11, 21], [32, 3], [44], 50]].

[1, [2, 3], [4]] + 60 = [1 + 60, [2, 3] + 60, [4] + 60] = [61, [2 + 60, 3 + 60], [4 + 60]], resulting in [61, [62, 63], [64]].

The final result is [[[11, 21], [32, 3], [44], 50], [61, [62, 63], [64]]].

Task

Write a program or a function that takes two integers, two nested arrays of integers or a combination thereof as input and returns their sum, as defined above.

If your language has multiple array-like types (lists, tuples, vectors, etc.) you may choose any of them for your answer. The return type must match the argument type.

To prevent boring and unbeatable solutions, if a language has this exact operation as a built-in, you may not use that language.

All built-ins of all other languages are allowed. If your language of choice permits this, you may overload and/or redefine the built-in addition.

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

Test cases

```<code>0 + 0                           = 0
[-1, 0, -1] + [1]               = [0, 0, -1]
[] + [0]                        = [0]
[] + 0                          = []
[] + []                         = []
[[], 0] + []                    = [[], []]
[1, 2, 3] + 10                  = [11, 12, 13]
[1, 2, 3] + [10]                = [11, 2, 3]
[1, 2, 3] + [10, [20]]          = [[11, 12, 13], [21, 2, 3]]
[1, 2, 3, []] + [10, [20]]      = [11, [22], 3, []]
[1, [2, [3, [4]]]] + [10, [20]] = [[11, [21]], [[12, [22]], [13, [24]]]]
</code>```

To generate more test cases, you can use this Jelly program.

Body:
JavaScript (ES6), 152 bytes

f=(a,b,g=a=>a.map?1+Math.max(0,...a.map(g)):0)=>g(a)<g(b)?f(b,a):g(b)<g(a)?a.map(e=>f(e,b)):g(a)?a.length<b.length?f(b,a):a.map((e,i)=>f(e,b[i]||0)):a+b
;t=(x,y,z)=>o.textContent+=`
${JSON.stringify(x)}
${JSON.stringify(y)}
${JSON.stringify(z)}
${JSON.stringify(f(x,y))}
`;`
0 + 0                           = 0
[-1, 0, -1] + [1]               = [0, 0, -1]
[] + [0]                        = [0]
[] + 0                          = []
[] + []                         = []
[[], 0] + []                    = [[], []]
[1, 2, 3] + 10                  = [11, 12, 13]
[1, 2, 3] + [10]                = [11, 2, 3]
[1, 2, 3] + [10, [20]]          = [[11, 12, 13], [21, 2, 3]]
[1, 2, 3, []] + [10, [20]]      = [11, [22], 3, []]
[1, [2, [3, [4]]]] + [10, [20]] = [[11, [21]], [[12, [22]], [13, [24]]]]`.slice(1).split`
`.map(l=>t(...l.split(/ [+=] /).map(a=>JSON.parse(a))));

<pre id=o></pre>


问:
"99 Bottles of Beer"
Write a program that outputs the lyrics to 99 Bottles of Beer, in as few bytes as possible.

Lyrics:

```<code>99 bottles of beer on the wall, 99 bottles of beer.
Take one down and pass it around, 98 bottles of beer on the wall.

98 bottles of beer on the wall, 98 bottles of beer.
Take one down and pass it around, 97 bottles of beer on the wall.

97 bottles of beer on the wall, 97 bottles of beer.
Take one down and pass it around, 96 bottles of beer on the wall.

96 bottles of beer on the wall, 96 bottles of beer.
Take one down and pass it around, 95 bottles of beer on the wall.

95 bottles of beer on the wall, 95 bottles of beer.
Take one down and pass it around, 94 bottles of beer on the wall.

....

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall.

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Go to the store and buy some more, 99 bottles of beer on the wall.
</code>```

Rules:

Your program must log to STDOUT or an acceptable alternative, or be returned from a function (with or without a trailing newline).

Your program must be a full, runnable program or function.

Languages specifically written to submit a 0-byte answer to this challenge are allowed, just not particularly interesting.

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

This is different from the output by HQ9+ or 99. Any answers written in these languages will be deleted.

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

Catalogue

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

Title: "99 Bottles of Beer"

Body:
///, 341 bytes

/-/\/\///+/ bottle-)/\/&\/<\/
-(/\/\/?\/ ->/+s of beer-^/> on the wall-!/^,-$/>.
-@/$Take one down and pass it around,-#/^.
-*/?1@?0#<0!?0@-%/99!?9@?8#<8!?8@?7#<7!?7@?6#<6!?6@?5#<5!?5@?4#<4!?4@?3#<3!?3@?2#<2!?2@?1#<1!-&/?9#
%*-</
9(9/%*/</
8(8)7(7)6(6)5(5)4(4)3(3)2(2)1(1)0(0-
0/
- 0/ /#/1+s/1+/
% 01$Go to the store and buy some more, 099^.

It would need 99 years to write a proper explanation of this code.

I would probably just include the result of every stage...

Basically, this compresses the lyrics repeatedly (as is every answer in ///).

<a href="http://slashes.tryitonline.net/#code=Ly0vXC9cLy8vKy8gYm90dGxlLSkvXC8mXC88XC8KLSgvXC9cLz9cLyAtPi8rcyBvZiBiZWVyLV4vPiBvbiB0aGUgd2FsbC0hL14sLSQvPi4KLUAvJFRha2Ugb25lIGRvd24gYW5kIHBhc3MgaXQgYXJvdW5kLC0jL14uCi0qLz8xQD8wIzwwIT8wQC0lLzk5IT85QD84Izw4IT84QD83Izw3IT83QD82Izw2IT82QD81Izw1IT81QD80Izw0IT80QD8zIzwzIT8zQD8yIzwyIT8yQD8xIzwxIS0mLz85IwolKi08Lwo5KDkvJSovPC8KOCg4KTcoNyk2KDYpNSg1KTQoNCkzKDMpMigyKTEoMSkwKDAtCjAvCi0gMC8gLyMvMStzLzErLwolIDAxJEdvIHRvIHRoZSBzdG9yZSBhbmQgYnV5IHNvbWUgbW9yZSwgMDk5Xi4&input=" rel="nofollow">Try it online!

Each step of decompression

Since replacements followed by replacements will have the string //, it will appear often.

It appears often enough that I decided to compress // into -.

When this is decompressed, the result is as follows:

/+/ bottle//)/\/&\/<\/
//(/\/\/?\/ //>/+s of beer//^/> on the wall//!/^,//$/>.
//@/$Take one down and pass it around,//#/^.
//*/?1@?0#<0!?0@//%/99!?9@?8#<8!?8@?7#<7!?7@?6#<6!?6@?5#<5!?5@?4#<4!?4@?3#<3!?3@?2#<2!?2@?1#<1!//&/?9#
%*//</
9(9/%*/</
8(8)7(7)6(6)5(5)4(4)3(3)2(2)1(1)0(0//
0/
// 0/ /#/1+s/1+/
% 01$Go to the store and buy some more, 099^.

The string  bottle only appeared three times, but I compressed it to + anyways:

/)/\/&\/<\/
//(/\/\/?\/ //>/ bottles of beer//^/> on the wall//!/^,//$/>.
//@/$Take one down and pass it around,//#/^.
//*/?1@?0#<0!?0@//%/99!?9@?8#<8!?8@?7#<7!?7@?6#<6!?6@?5#<5!?5@?4#<4!?4@?3#<3!?3@?2#<2!?2@?1#<1!//&/?9#
%*//</
9(9/%*/</
8(8)7(7)6(6)5(5)4(4)3(3)2(2)1(1)0(0//
0/
// 0/ /#/1 bottles/1 bottle/
% 01$Go to the store and buy some more, 099^.

Then, ) corresponds to /&/</ followed by a newline, and ( corresponds to //?/ , which are patterns that will be often used later:

/>/ bottles of beer//^/> on the wall//!/^,//$/>.
//@/$Take one down and pass it around,//#/^.
//*/?1@?0#<0!?0@//%/99!?9@?8#<8!?8@?7#<7!?7@?6#<6!?6@?5#<5!?5@?4#<4!?4@?3#<3!?3@?2#<2!?2@?1#<1!//&/?9#
%*//</
9//?/ 9/%*/</
8//?/ 8/&/</
7//?/ 7/&/</
6//?/ 6/&/</
5//?/ 5/&/</
4//?/ 4/&/</
3//?/ 3/&/</
2//?/ 2/&/</
1//?/ 1/&/</
0//?/ 0//
0/
// 0/ /#/1 bottles/1 bottle/
% 01$Go to the store and buy some more, 099^.

Now, we would decompress some useful strings:

> decompresses to  bottles of beer

^ decompresses to  bottles of beer on the wall

! decompresses to ^,, where ^ is the one above.

$ decompresses to >.\n, where > is the first rule and \n is a newline.

@ decompresses to $ followed by Take one down and pass it around,, where $ is the rule above.

The decompressed code now becomes:

/*/?1 bottles of beer.
Take one down and pass it around,?0 bottles of beer on the wall.
<0 bottles of beer on the wall,?0 bottles of beer.
Take one down and pass it around,//%/99 bottles of beer on the wall,?9 bottles of beer.
Take one down and pass it around,?8 bottles of beer on the wall.
<8 bottles of beer on the wall,?8 bottles of beer.
Take one down and pass it around,?7 bottles of beer on the wall.
<7 bottles of beer on the wall,?7 bottles of beer.
Take one down and pass it around,?6 bottles of beer on the wall.
<6 bottles of beer on the wall,?6 bottles of beer.
Take one down and pass it around,?5 bottles of beer on the wall.
<5 bottles of beer on the wall,?5 bottles of beer.
Take one down and pass it around,?4 bottles of beer on the wall.
<4 bottles of beer on the wall,?4 bottles of beer.
Take one down and pass it around,?3 bottles of beer on the wall.
<3 bottles of beer on the wall,?3 bottles of beer.
Take one down and pass it around,?2 bottles of beer on the wall.
<2 bottles of beer on the wall,?2 bottles of beer.
Take one down and pass it around,?1 bottles of beer on the wall.
<1 bottles of beer on the wall,//&/?9 bottles of beer on the wall.

%*//</
9//?/ 9/%*/</
8//?/ 8/&/</
7//?/ 7/&/</
6//?/ 6/&/</
5//?/ 5/&/</
4//?/ 4/&/</
3//?/ 3/&/</
2//?/ 2/&/</
1//?/ 1/&/</
0//?/ 0//
0/
// 0/ / bottles of beer on the wall.
/1 bottles/1 bottle/
% 01 bottles of beer.
Go to the store and buy some more, 099 bottles of beer on the wall.


答:
JavaScript (ES6), <s>105</s> 102 bytes

@Edit: Saved 3 bytes thanks to @PatrickRoberts.

f=
(n,h)=>` \\|/`.substr(0,n+1-h)+[...Array(h)].map((_,i)=>`
(${i+n<h?` `:`-`})${i+h+3<n?`-`:``}`).join``
;```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div oninput=o.textContent=f(+n.value,+h.value)>n<input id=n type=number min=0 value=0>h<input id=h type=number min=0 value=0><pre id=o></code>```

Title: Stack Overflowing

Body:
JavaScript (ES6), <s>105</s> 102 bytes

@Edit: Saved 3 bytes thanks to @PatrickRoberts.

f=
(n,h)=>` \\|/`.substr(0,n+1-h)+[...Array(h)].map((_,i)=>`
(${i+n<h?` `:`-`})${i+h+3<n?`-`:``}`).join``
;

<div oninput=o.textContent=f(+n.value,+h.value)>n<input id=n type=number min=0 value=0>h<input id=h type=number min=0 value=0><pre id=o>


答:
Oracle SQL 11.2, <s>165</s> bytes

SELECT l FROM(SELECT LEVEL l,TO_NUMBER(XMLQUERY(REGEXP_REPLACE(LEVEL,'(\d)','+\1')RETURNING CONTENT)) s FROM DUAL CONNECT BY 1=1)WHERE s=:1 AND l!=s AND rownum=1;
```

<p>Un-golfed</p>

<pre class="lang-sql prettyprint-override"><code>SELECT l
FROM   (
         SELECT LEVEL l, -- Number to evaluate
                XMLQUERY(
                          REGEXP_REPLACE(LEVEL,'(\d)','+\1')  -- Add a + in front of each digit
                          RETURNING CONTENT
                        ).GETNUMBERVAL()s                     -- Evaluate le expression generated by the added +
                FROM DUAL
                CONNECT BY 1=1 -- Run forever
       )
WHERE s=:1      -- The sum must be equal to the input
  AND l!=s      -- The sum must not be the input
  AND rownum=1  -- Keep only the first result
</code>```

Title: Find the smallest number bigger than the input whose digital sum is the input

Body:
"Digital sum" refers to the sum of all the digits in a number.

For example, the digital sum of 1324 is 10, because 1+3+2+4 = 10.

The challenge is to write a program/function to calculate the smallest number bigger than the input whose digital sum is the input.

Example with walkthrough

As an example, take the number 9 as the input:

```<code>9 = 1+8 -> 18
9 = 2+7 -> 27
9 = 3+6 -> 36
...
9 = 8+1 -> 81
9 = 9+0 -> 90
</code>```

The valid output would be the smallest number above, which is 18.

Specs

Note that 9 is not the valid output for this example, because the reversed number must be greater than the original number.

Note that the input will be positive.

Test-Cases:

```<code> 2 => 11      (2 = 1 + 1)
 8 => 17      (8 = 1 + 7)
12 => 39     (12 = 3 + 9)
16 => 79     (16 = 7 + 9)
18 => 99     (18 = 9 + 9)
24 => 699    (24 = 6 + 9 + 9)
32 => 5999   (32 = 5 + 9 + 9 + 9)
</code>```

References:

This is OEIS A161561.

Edit: Added an additional Testcase (18)

Thanks to Martin Ender for the Leaderboard Snippet

var QUESTION_ID=81047,OVERRIDE_USER=31373;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Oracle SQL 11.2, <s>165</s> bytes

SELECT l FROM(SELECT LEVEL l,TO_NUMBER(XMLQUERY(REGEXP_REPLACE(LEVEL,'(\d)','+\1')RETURNING CONTENT)) s FROM DUAL CONNECT BY 1=1)WHERE s=:1 AND l!=s AND rownum=1;

Un-golfed

SELECT l
FROM   (
         SELECT LEVEL l, -- Number to evaluate
                XMLQUERY(
                          REGEXP_REPLACE(LEVEL,'(\d)','+\1')  -- Add a + in front of each digit
                          RETURNING CONTENT
                        ).GETNUMBERVAL()s                     -- Evaluate le expression generated by the added +
                FROM DUAL
                CONNECT BY 1=1 -- Run forever
       )
WHERE s=:1      -- The sum must be equal to the input
  AND l!=s      -- The sum must not be the input
  AND rownum=1  -- Keep only the first result


答:
Mathematica, 122 bytes

```<code>d=Depth
x_~f~y_/;d@x>d@y:=y~f~x
x_~f~y_/;d@x<d@y:=x~f~#&/@y
x_List~f~y_:=MapThread[f,{x,y}~PadRight~Automatic]
x_~f~y_=x+y
</code>```

Defines a recursive function f which computes the sum. Making use of Mathematica's pattern matching, this function is made up of four separate definitions:

```<code>x_~f~y_/;d@x>d@y:=y~f~x
</code>```

If the depth of x is greater than that of y, swap the arguments so that we only have to handle distribution in one direction (which we can do, since addition is commutative).

```<code>x_~f~y_/;d@x<d@y:=x~f~#&/@y
</code>```

If the depth of x is less thann that of y, replace each value # in y with f[x,#], which takes care of the distribution for arguments of unequal depth.

```<code>x_List~f~y_:=MapThread[f,{x,y}~PadRight~Automatic]
</code>```

Otherwise, if one argument is a list (which implies that the other also is a list, since we know they have the same depth), we put both arguments in a list, pad them to the same length with PadRight[..., Automatic] (which simply fills up a ragged array with zeros to make it rectangular), and then use MapThread to apply f to corresponding pairs from the two lists.

And finally, the base case:

```<code>x_~f~y_=x+y
</code>```

If none of the other patterns match, we must be trying to add two numbers, so we just do that.

Title: Jam don't add like that

Body:
Mathematica, 122 bytes

d=Depth
x_~f~y_/;d@x>d@y:=y~f~x
x_~f~y_/;d@x<d@y:=x~f~#&/@y
x_List~f~y_:=MapThread[f,{x,y}~PadRight~Automatic]
x_~f~y_=x+y

Defines a recursive function f which computes the sum. Making use of Mathematica's pattern matching, this function is made up of four separate definitions:

x_~f~y_/;d@x>d@y:=y~f~x

If the depth of x is greater than that of y, swap the arguments so that we only have to handle distribution in one direction (which we can do, since addition is commutative).

x_~f~y_/;d@x<d@y:=x~f~#&/@y

If the depth of x is less thann that of y, replace each value # in y with f[x,#], which takes care of the distribution for arguments of unequal depth.

x_List~f~y_:=MapThread[f,{x,y}~PadRight~Automatic]

Otherwise, if one argument is a list (which implies that the other also is a list, since we know they have the same depth), we put both arguments in a list, pad them to the same length with PadRight[..., Automatic] (which simply fills up a ragged array with zeros to make it rectangular), and then use MapThread to apply f to corresponding pairs from the two lists.

And finally, the base case:

x_~f~y_=x+y

If none of the other patterns match, we must be trying to add two numbers, so we just do that.


答:
Racket 70 characters, 71 bytes

Same algorithm as most of the others pretty much. Pretty sad about not having % for modulo, or ** for expt, or integer division by default, otherwise this could be a lot shorter and I could've outgolfed C and Java. Still love the language though

```<code>(λ(x)(if(> x 9)(-(*(+(modulo x 9)1)(expt 10(floor(/ x 9))))1)(+ x 9)))
</code>```

Body:
Racket 70 characters, 71 bytes

Same algorithm as most of the others pretty much. Pretty sad about not having % for modulo, or ** for expt, or integer division by default, otherwise this could be a lot shorter and I could've outgolfed C and Java. Still love the language though

(λ(x)(if(> x 9)(-(*(+(modulo x 9)1)(expt 10(floor(/ x 9))))1)(+ x 9)))


问:
Shortest way to reverse a number
Write a function (or equivalent subprogram) to accept a single integer valued argument and return a (similarly typed) value found by reversing the order of the base-10 digits of the argument.

For example given 76543 return 34567

答:
Python 2, 26 bytes

```<code>print int(`input()`[::-1])
</code>```

OwnerDisplayName: eltond

Title: Shortest way to reverse a number

Body:
Python 2, 26 bytes

print int(`input()`[::-1])


问:
1, 2, Fizz, 4, Buzz

Introduction

In our recent effort to collect catalogues of shortest solutions for standard programming exercises, here is PPCG's first ever vanilla FizzBuzz challenge. If you wish to see other catalogue challenges, there is "Hello World!" and "Is this number a prime?".

Challenge

Write a program that prints the decimal numbers from 1 to 100 inclusive. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.

Output

The output will be a list of numbers (and Fizzes, Buzzes and FizzBuzzes) separated by a newline (either \n or \r\n). A trailing newline is acceptable, but a leading newline is not.  Apart from your choice of newline, the output should look exactly like this:

```<code>1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
</code>```

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

Further Rules

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

Submissions are scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8. Some languages, like Folders, are a bit tricky to score--if in doubt, please ask on Meta.

Nothing can be printed to STDERR.

Feel free to use a language (or language version) even if it's newer than this challenge. If anyone wants to abuse this by creating a language where the empty program generates FizzBuzz output, then congrats for paving the way for a very boring answer.

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

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

Because the output is fixed, you may hardcode the output (but this may not be the shortest option).

You may use preexisting solutions, as long as you credit the original author of the program.

Standard loopholes are otherwise disallowed.

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

Catalogue

var QUESTION_ID=58615;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=30525;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(index,answers){return"https://api.stackexchange.com/2.2/answers/"+answers.join(';')+"/comments?page="+index+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){answers.push.apply(answers,data.items);answers_hash=[];answer_ids=[];data.items.forEach(function(a){a.comments=[];var id=+a.share_link.match(/\d+/);answer_ids.push(id);answers_hash[id]=a});if(!data.has_more)more_answers=false;comment_page=1;getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:true,success:function(data){data.items.forEach(function(c){if(c.owner.user_id===OVERRIDE_USER)answers_hash[c.post_id].comments.push(c)});if(data.has_more)getComments();else if(more_answers)getAnswers();else process()}})}getAnswers();var SCORE_REG=/<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;var OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(a){return a.owner.display_name}function process(){var valid=[];answers.forEach(function(a){var body=a.body;a.comments.forEach(function(c){if(OVERRIDE_REG.test(c.body))body='
'+c.body.replace(OVERRIDE_REG,'')+'
'});var match=body.match(SCORE_REG);if(match)valid.push({user:getAuthorName(a),size:+match[2],language:match[1],link:a.share_link,});else console.log(body)});valid.sort(function(a,b){var aB=a.size,bB=b.size;return aB-bB});var languages={};var place=1;var lastSize=null;var lastPlace=1;valid.forEach(function(a){if(a.size!=lastSize)lastPlace=place;lastSize=a.size;++place;var answer=jQuery("#answer-template").html();answer=answer.replace("{{PLACE}}",lastPlace+".").replace("{{NAME}}",a.user).replace("{{LANGUAGE}}",a.language).replace("{{SIZE}}",a.size).replace("{{LINK}}",a.link);answer=jQuery(answer);jQuery("#answers").append(answer);var lang=a.language;lang=jQuery(''+lang+'').text();languages[lang]=languages[lang]||{lang:a.language,lang_raw:lang.toLowerCase(),user:a.user,size:a.size,link:a.link}});var langs=[];for(var lang in languages)if(languages.hasOwnProperty(lang))langs.push(languages[lang]);langs.sort(function(a,b){if(a.lang_raw>b.lang_raw)return 1;if(a.lang_raw<b.lang_raw)return-1;return 0});for(var i=0;i<langs.length;++i){var language=jQuery("#language-template").html();var lang=langs[i];language=language.replace("{{LANGUAGE}}",lang.lang).replace("{{NAME}}",lang.user).replace("{{SIZE}}",lang.size).replace("{{LINK}}",lang.link);language=jQuery(language);jQuery("#languages").append(language)}}```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list{padding:10px;width:290px;float:left}#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">

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

Title: 1, 2, Fizz, 4, Buzz

Body:
///, 229 bytes

/x/Buzz//b/
x//f/
Fizz/1
2f
4bf
7
8fb
11f
13
14fx
16
17f
19bf
22
23fb
26f
28
29fx
31
32f
34bf
37
38fb
41f
43
44fx
46
47f
49bf
52
53fb
56f
58
59fi
61
62f
64bf
67
68fb
71f
73
74fx
76
77f
79bf
82
83fb
86f
88
89fx
91
92f
94bf
97
98fb


答:
Python 3, 33 bytes

I decided to make a function instead of hardcoding it.

```<code>def r(n):print(int(str(n)[::-1]))
</code>```

The code is pretty self-explanatory.

Usage: r(12345)

Title: Shortest way to reverse a number

Body:
Write a function (or equivalent subprogram) to accept a single integer valued argument and return a (similarly typed) value found by reversing the order of the base-10 digits of the argument.

For example given 76543 return 34567

Body:
Python 3, 33 bytes

I decided to make a function instead of hardcoding it.

def r(n):print(int(str(n)[::-1]))

The code is pretty self-explanatory.

Usage: r(12345)


答:
Oracle SQL 11.2, <s>35</s> 34 bytes

SELECT 0+REVERSE(:1||'')FROM DUAL;
```

Title: Shortest way to reverse a number