答:
BrainF**k, <s>396</s> 391 bytes

```<code>>+>>++++[-<++++++++>]->,----------[++++++++++.>>++++++++[-<++++<------>>]<.,----------]-<+[-<+]->>+[-<<<<<++++++++++.[-]>[-<+>>.<]<[->+<]>+>>>[[->+]->>+<<<+[-<+]->]>+[-<->[[->+]->+>>+<<<<+[-<+]->]<+>->+[->+]->>[->+<]>+>++++++++++>>-<<[-<-[>>]<]<->>>+[-<<<+>>>[-<->]<+++++++++>>>+]++++++++[-<++++<++++++>>]<<<[-<<<<+[-<+]-<+>>+[->+]->>>>+<]>.>.[-]<[-]<<<[->+<]<<+[-<+]>+]>>[-]<<<-<+[-<+]->>+]
</code>```

I couldn't resist the temptation to do this one. At least the triangle is pointy-side down.

Input comes in as a string of numeric characters followed by a single newline.

Output will contain a single trailing space on every line.

Examples:

```<code>$ bf sd.bf
010
0 1 0
 1 1
  2

$ bf sd.bf
123456
1 2 3 4 5 6
 3 5 7 9 1
  8 2 6 0
   0 8 6
    8 4
     2

$ bf sd.bf
9245322
9 2 4 5 3 2 2
 1 6 9 8 5 4
  7 5 7 3 9
   2 2 0 2
    4 2 2
     6 4
      0
</code>```

Explanation

Since it's rather difficult to explain the code from a functional perspective, we can instead look at it from the perspective of the state of the tape at various times. The core idea here is that the triangle we output is initialized as a tightly-packed (for BF, anyway) array that shrinks in size by 1 every iteration of a loop. Another important thought is that we use 255 to indicate a "placeholder" that we can search for on the tape.

Initialization

This is the easiest step. At the start of the program, we execute the following:

```<code>>+>>++++[-<++++++++>]->
</code>```

This forces the tape into the following state (where >N< indicates the location of the pointer on the tape)

```<code>[ 0 1 32 255 >0< 0 0 ...]
</code>```

The first number here is a "buffer" location. We're not going to use it on a long-term basis, but it's useful to make little operations simpler and for copying data around.

The second number is the number of spaces that we'll be outputting at the start of each line, starting after the first line. The first line will have no leading spaces.

The third number is the space character we output.

The fourth number is a placeholder 255, so that we can get back to this position relatively easily.

Input

From this position, we will read in all of the characters. At the end of this step, we hope to be in the following situation:

```<code>[ 0 1 32 255 a b c d e f ... >255< 0 0 ... ]
</code>```

Where a b c d e f ... indicates the string of numeric characters that was input (not the newline).

We accomplish this with the following:

```<code>,----------[++++++++++.>>++++++++[-<++++<------>>]<.,----------]-
</code>```

There are some nuances to this. First of all, we will output each character as we get them, and then output a space after it. Secondly, we don't want to copy the ASCII value to the tape, we want to copy the actual numeric digit. Third, we want to stop when we hit a newline and leave ourselves in a good place at that time.

Say our input is 6723. Then, upon reading the first 6, our tape looks like this:

```<code>[ 0 1 32 255 >54< 0 0 ...]
</code>```

We check that this value is not equal to 10 (an ASCII newline) with ,----------[++++++++++. We then print out the value and continue by simultaneously subtracting 48 from the input value and adding 32 to the value next to it (>>++++++++[-<++++<------>>]<), leaving us here:

```<code>[ 0 1 32 255 6 >32< 0 ...]
</code>```

Notice how throughout this process we can assume that all digits to the right of our input are 0--this means that we're not in danger of ruining any previous state if we use values to the right to calculate 6 * 8 and 4 * 8.

Now we output the space character we just generated, and take in a new input, deleting the space we calculated there. Eventually, the input will be terminated by a new line and the loop will exit, leaving a 255 where the newline would have been (,----------]-). This is the second placeholder character we will use to navigate the tape. At this point in our scenario, our tape is exactly this:

```<code>[ 0 1 32 255 6 7 2 3 >255< 0 0 ... ]
</code>```

Calculation

The way this works is that the list of digits between our 255 placeholders is going to shrink by one every iteration of the loop. When it only has 1 digit left in it, we're done and should halt immediately (Note that, at this point, every digit in that list has already been output, so we don't have to worry about outputting it again).

We now use this trick to navigate to the first 255 placeholder: <+[-<+]-. This effectively searches the tape to the left for a 255, changing nothing in between. Now that we've moved the pointer, we can check our exit condition: if there's only one digit in the list, then the cell two spaces to the right will hold 255. Thus, we check against that and start a loop: >>+[-<<

The first step in our loop is to output a newline. So we move to the first cell (our buffer cell), add 10 to it and output. The next step is to output all leading space characters. After outputting them, we increment our count for number of leading spaces. These steps are accomplished by the following:

```<code>-<<<<<++++++++++.[-]>[-<+>>.<]<[->+<]>+>>>
</code>```

Which leaves us in this state:

```<code>[ 0 2 32 255 >6< 7 2 3 255 0 0 0 0 0 0 ]
</code>```

Our next step is to copy the first value in the list over, past the second placeholder 255:

```<code>[[->+]->>+<<<+[-<+]->]
</code>```

We essentially do this by hopping back and forth between our placeholder 255s, leaving us here:

```<code>[ 0 2 32 255 >0< 7 2 3 255 0 6 0 0 ... ]
</code>```

We now start a loop, iterating through the rest of the list, stopping when we hit 255 : >+[-<

At this point, the digit to our immediate left is always 0. So, because we love them, we pop a placeholder 255 in there so that we can come back to our place in the list. The next step is to move the second place in the list to locations surrounding where we moved the first place to, past the second placeholder 255. These steps are accomplished by the following:

```<code>->
[[->+]->+>>+<<<<+[-<+]->]
</code>```

Leaving us here: [ 0 2 32 255 255 >0< 2 3 255 7 6 7 0 ]
Now, both the 6 and 7 have been moved to a location where the calculation can occur. We need two copies of the 7 because the next number in the list will need it as well. The 7 immediately after the 255 serves this purpose, whereas the other 7 will be consumed by the calculation.

First, we add the two digits:

```<code><+>->+[->+]->>
[->+<]>
</code>```

Leaving us here:

```<code>[ 0 2 32 255 0 255 2 3 255 7 0 >13< 0 ]
</code>```

The next combination of steps is the most complicated. We need to see if the number we're pointing to is larger than 10, and if it is, we subtract 10. In reality, what we do is we subtract 10 from it and see if it hits 0 at any point in the subtraction. If it does, we add 10 back on later. At the end of this, we should have the sum modulo 10.

```<code>Prepare a 10 to the right
+>++++++++++
Leave yet another 255 for a loop condition later
>>-<<
If the number is greater than 10 end up one space to the left
else one space to the right
[-<-[>>]<]<->
Check if the previous 255 is two spaces to the right and if it is
add 10 back to our sum--we've subtracted too much
>>+[-<<<+>>>[-<->]<+++++++++>>>+]
</code>```

At this point, we've accomplished the goal. We have the sum modulo 10!
Also, whether or not the number was greater than 10, we'll end up here:

```<code>[ 0 2 32 255 0 255 2 3 255 7 0 3 0 0 >0< ]
</code>```

Our next goals are to output this new sum, follow it with a space, and inject it back into our list. We do this all with our previous techniques of 255-hopping and adding 48 to our sum, so I won't cover it in detail.

```<code>++++++++[-<++++<++++++>>]
<<<[-<<<<+[-<+]-<+>>+[->+]->>>>+<]
>.>.
</code>```

And we're here: [ 0 2 32 255 3 255 2 3 255 7 0 0 51 >32< ]
Notice how we put an additional 255 placeholder after our newly-injected 3 so that we don't lose place in the list. At this point, we have output our sum and its space, so we need to clean up and revert to a state where the next iteration of this loop is going to work. We need to clear out our 51 and 32 cells, move the 7 once to the right, and navigate to our list placeholder so that we can start over.

```<code>[-]<[-]<<<[->+<]<<+[-<+]
</code>```

Now, we're here: [ 0 2 32 255 3 >0< 2 3 255 0 7 0 ... ]

Which is exactly where we want to be for our next iteration. So check for 255 and move on! (>+])

When we get dropped off from the loop, we're going to have a whole new list--made up of the sums from the previous list. The first time, it'll look like this:

```<code> [ 0 2 32 255 3 9 5 0 >0< ]
</code>```

Now we want to repeat that whole process on our new list, so we plop a 255 down to the left and start all over! We need to do a little bit of cleanup with >>[-]<<, and then drop our placeholder with <-. After that, we're in exactly the same place as we were after input, so we can get away with doing the same checks: <+[-<+]->>+, and boom! We've got our full loop! All we need is the closing bracket, and when it ends we've already output everything, so we're done: ].

Title: Sum It Up with a Digital Triangle

Body:
BrainF**k, <s>396</s> 391 bytes

>+>>++++[-<++++++++>]->,----------[++++++++++.>>++++++++[-<++++<------>>]<.,----------]-<+[-<+]->>+[-<<<<<++++++++++.[-]>[-<+>>.<]<[->+<]>+>>>[[->+]->>+<<<+[-<+]->]>+[-<->[[->+]->+>>+<<<<+[-<+]->]<+>->+[->+]->>[->+<]>+>++++++++++>>-<<[-<-[>>]<]<->>>+[-<<<+>>>[-<->]<+++++++++>>>+]++++++++[-<++++<++++++>>]<<<[-<<<<+[-<+]-<+>>+[->+]->>>>+<]>.>.[-]<[-]<<<[->+<]<<+[-<+]>+]>>[-]<<<-<+[-<+]->>+]

I couldn't resist the temptation to do this one. At least the triangle is pointy-side down.

Input comes in as a string of numeric characters followed by a single newline.

Output will contain a single trailing space on every line.

Examples:

$ bf sd.bf
010
0 1 0
 1 1
  2

$ bf sd.bf
123456
1 2 3 4 5 6
 3 5 7 9 1
  8 2 6 0
   0 8 6
    8 4
     2

$ bf sd.bf
9245322
9 2 4 5 3 2 2
 1 6 9 8 5 4
  7 5 7 3 9
   2 2 0 2
    4 2 2
     6 4
      0

Explanation

Since it's rather difficult to explain the code from a functional perspective, we can instead look at it from the perspective of the state of the tape at various times. The core idea here is that the triangle we output is initialized as a tightly-packed (for BF, anyway) array that shrinks in size by 1 every iteration of a loop. Another important thought is that we use 255 to indicate a "placeholder" that we can search for on the tape.

Initialization

This is the easiest step. At the start of the program, we execute the following:

>+>>++++[-<++++++++>]->

This forces the tape into the following state (where >N< indicates the location of the pointer on the tape)

[ 0 1 32 255 >0< 0 0 ...]

The first number here is a "buffer" location. We're not going to use it on a long-term basis, but it's useful to make little operations simpler and for copying data around.

The second number is the number of spaces that we'll be outputting at the start of each line, starting after the first line. The first line will have no leading spaces.

The third number is the space character we output.

The fourth number is a placeholder 255, so that we can get back to this position relatively easily.

Input

From this position, we will read in all of the characters. At the end of this step, we hope to be in the following situation:

[ 0 1 32 255 a b c d e f ... >255< 0 0 ... ]

Where a b c d e f ... indicates the string of numeric characters that was input (not the newline).

We accomplish this with the following:

,----------[++++++++++.>>++++++++[-<++++<------>>]<.,----------]-

There are some nuances to this. First of all, we will output each character as we get them, and then output a space after it. Secondly, we don't want to copy the ASCII value to the tape, we want to copy the actual numeric digit. Third, we want to stop when we hit a newline and leave ourselves in a good place at that time.

Say our input is 6723. Then, upon reading the first 6, our tape looks like this:

[ 0 1 32 255 >54< 0 0 ...]

We check that this value is not equal to 10 (an ASCII newline) with ,----------[++++++++++. We then print out the value and continue by simultaneously subtracting 48 from the input value and adding 32 to the value next to it (>>++++++++[-<++++<------>>]<), leaving us here:

[ 0 1 32 255 6 >32< 0 ...]

Notice how throughout this process we can assume that all digits to the right of our input are 0--this means that we're not in danger of ruining any previous state if we use values to the right to calculate 6 * 8 and 4 * 8.

Now we output the space character we just generated, and take in a new input, deleting the space we calculated there. Eventually, the input will be terminated by a new line and the loop will exit, leaving a 255 where the newline would have been (,----------]-). This is the second placeholder character we will use to navigate the tape. At this point in our scenario, our tape is exactly this:

[ 0 1 32 255 6 7 2 3 >255< 0 0 ... ]

Calculation

The way this works is that the list of digits between our 255 placeholders is going to shrink by one every iteration of the loop. When it only has 1 digit left in it, we're done and should halt immediately (Note that, at this point, every digit in that list has already been output, so we don't have to worry about outputting it again).

We now use this trick to navigate to the first 255 placeholder: <+[-<+]-. This effectively searches the tape to the left for a 255, changing nothing in between. Now that we've moved the pointer, we can check our exit condition: if there's only one digit in the list, then the cell two spaces to the right will hold 255. Thus, we check against that and start a loop: >>+[-<<

The first step in our loop is to output a newline. So we move to the first cell (our buffer cell), add 10 to it and output. The next step is to output all leading space characters. After outputting them, we increment our count for number of leading spaces. These steps are accomplished by the following:

-<<<<<++++++++++.[-]>[-<+>>.<]<[->+<]>+>>>

Which leaves us in this state:

[ 0 2 32 255 >6< 7 2 3 255 0 0 0 0 0 0 ]

Our next step is to copy the first value in the list over, past the second placeholder 255:

[[->+]->>+<<<+[-<+]->]

We essentially do this by hopping back and forth between our placeholder 255s, leaving us here:

[ 0 2 32 255 >0< 7 2 3 255 0 6 0 0 ... ]

We now start a loop, iterating through the rest of the list, stopping when we hit 255 : >+[-<

At this point, the digit to our immediate left is always 0. So, because we love them, we pop a placeholder 255 in there so that we can come back to our place in the list. The next step is to move the second place in the list to locations surrounding where we moved the first place to, past the second placeholder 255. These steps are accomplished by the following:

->
[[->+]->+>>+<<<<+[-<+]->]

Leaving us here: [ 0 2 32 255 255 >0< 2 3 255 7 6 7 0 ]
Now, both the 6 and 7 have been moved to a location where the calculation can occur. We need two copies of the 7 because the next number in the list will need it as well. The 7 immediately after the 255 serves this purpose, whereas the other 7 will be consumed by the calculation.

First, we add the two digits:

<+>->+[->+]->>
[->+<]>

Leaving us here:

[ 0 2 32 255 0 255 2 3 255 7 0 >13< 0 ]

The next combination of steps is the most complicated. We need to see if the number we're pointing to is larger than 10, and if it is, we subtract 10. In reality, what we do is we subtract 10 from it and see if it hits 0 at any point in the subtraction. If it does, we add 10 back on later. At the end of this, we should have the sum modulo 10.

Prepare a 10 to the right
+>++++++++++
Leave yet another 255 for a loop condition later
>>-<<
If the number is greater than 10 end up one space to the left
else one space to the right
[-<-[>>]<]<->
Check if the previous 255 is two spaces to the right and if it is
add 10 back to our sum--we've subtracted too much
>>+[-<<<+>>>[-<->]<+++++++++>>>+]

At this point, we've accomplished the goal. We have the sum modulo 10!
Also, whether or not the number was greater than 10, we'll end up here:

[ 0 2 32 255 0 255 2 3 255 7 0 3 0 0 >0< ]

Our next goals are to output this new sum, follow it with a space, and inject it back into our list. We do this all with our previous techniques of 255-hopping and adding 48 to our sum, so I won't cover it in detail.

++++++++[-<++++<++++++>>]
<<<[-<<<<+[-<+]-<+>>+[->+]->>>>+<]
>.>.

And we're here: [ 0 2 32 255 3 255 2 3 255 7 0 0 51 >32< ]
Notice how we put an additional 255 placeholder after our newly-injected 3 so that we don't lose place in the list. At this point, we have output our sum and its space, so we need to clean up and revert to a state where the next iteration of this loop is going to work. We need to clear out our 51 and 32 cells, move the 7 once to the right, and navigate to our list placeholder so that we can start over.

[-]<[-]<<<[->+<]<<+[-<+]

Now, we're here: [ 0 2 32 255 3 >0< 2 3 255 0 7 0 ... ]

Which is exactly where we want to be for our next iteration. So check for 255 and move on! (>+])

When we get dropped off from the loop, we're going to have a whole new list--made up of the sums from the previous list. The first time, it'll look like this:

 [ 0 2 32 255 3 9 5 0 >0< ]

Now we want to repeat that whole process on our new list, so we plop a 255 down to the left and start all over! We need to do a little bit of cleanup with >>[-]<<, and then drop our placeholder with <-. After that, we're in exactly the same place as we were after input, so we can get away with doing the same checks: <+[-<+]->>+, and boom! We've got our full loop! All we need is the closing bracket, and when it ends we've already output everything, so we're done: ].


问:
Same length sub arrays

Background:

Here's a little simple challenge. You want to be able to find out whether the arrays inside an array have the same length.

Input:

Your input should consist of exactly one array (this is the value passed to the function, not a user input). Your function takes exactly 1 parameter.  It could contain arrays or be empty. No error checking needed, assume only list is ever passed in. Assume a 1-D array such as [1] or [1,2,3,4,5] is never passed in.

Output:

Return true if all the list elements have the same length, false if they don't, and the parameter itself if the list is empty (or null if your language doesn't support multiple return types).

Some test cases:

```<code>List: [] - [] (or null/your language equivalent)
List: [[1], [1], [2]] - True
List: [[1]] - True
List: [[1, 2, 3, 4]] - True
List: [[1, 2, 3, 4, 5], [2], [12, 314123]] - False
List: [[1, 2, 3, 4], [1]] - False
</code>```

No std(in/out) input/output needed (however, it is allowed, just not required!), the function only needs to return boolean values true or false; or the parameter itself if the function is passed an empty list (or null/your language equivalent). Only one return value is returned.

Rules:

Shortest byte count wins, only function is necessary (full programs are allowed if you desire).

答:
Brachylog, 9 bytes

```<code>.v|:ladl1
</code>```

Returns true or false or the empty list.

Explanation

```<code>.v      Unify the output with the input if it's the empty list
|       Or
:la     Apply length to each element of the input
   d    Remove all duplicates
    l1  The length of the resulting list is 1
</code>```

ContentLicense: CC BY-SA 3.0

Title: Same length sub arrays

Body:
Brachylog, 9 bytes

.v|:ladl1

Returns true or false or the empty list.

Explanation

.v      Unify the output with the input if it's the empty list
|       Or
:la     Apply length to each element of the input
   d    Remove all duplicates
    l1  The length of the resulting list is 1


Title: Same length sub arrays

Body:
Background:

Here's a little simple challenge. You want to be able to find out whether the arrays inside an array have the same length.

Input:

Your input should consist of exactly one array (this is the value passed to the function, not a user input). Your function takes exactly 1 parameter.  It could contain arrays or be empty. No error checking needed, assume only list is ever passed in. Assume a 1-D array such as [1] or [1,2,3,4,5] is never passed in.

Output:

Return true if all the list elements have the same length, false if they don't, and the parameter itself if the list is empty (or null if your language doesn't support multiple return types).

Some test cases:

```<code>List: [] - [] (or null/your language equivalent)
List: [[1], [1], [2]] - True
List: [[1]] - True
List: [[1, 2, 3, 4]] - True
List: [[1, 2, 3, 4, 5], [2], [12, 314123]] - False
List: [[1, 2, 3, 4], [1]] - False
</code>```

No std(in/out) input/output needed (however, it is allowed, just not required!), the function only needs to return boolean values true or false; or the parameter itself if the function is passed an empty list (or null/your language equivalent). Only one return value is returned.

Rules:

Shortest byte count wins, only function is necessary (full programs are allowed if you desire).

Body:
Ruby, 27 bytes

->i{!i.map(&:size).uniq[1]}

Test:

s = ->i{!i.map(&:size).uniq[1]}
s[[[1, 2, 3, 4], [1]]]
=> false
s[[[1, 2, 3, 4]]]
=> true


答:
Java 10, <s>145</s> <s>129</s> <s>107</s> <s>106</s> <s>103</s> <s>93</s> 77 bytes

Loads of bytes saved thanks to @Frozn, and by using Object as return-type, we can comply with OP's rules of returning the input-array when the array is empty, despite Java's one-return-type-only nature regarding methods.

m->{int f=1;for(var a:m)f=m[0].length!=a.length?0:f;return m.length<1?m:f>0;}
```
<p>Try it online.</p>
<p><strong>Explanation:</strong></p>
<pre class="lang-java prettyprint-override"><code>m->{                  // Method with integer-matrix parameter and Object return-type
  int f=1;            //  Flag-integer, starting at 1
  for(var a:m)        //  Loop over the rows of the matrix
    f=m[0].length!=a.length?
                      //   If the length of the first and current row aren't the same:
       0              //    Change `f` to 0
      :               //   Else:
       f;             //    Leave `f` the same
  return m.length<1?  //  If there is only one row:
          m           //   Return the input-matrix as result
         :            //  Else:
          f>0;}       //   Return whether the flag `f` is still 1 as boolean
</code>```

Title: Same length sub arrays

Body:
Java 10, <s>145</s> <s>129</s> <s>107</s> <s>106</s> <s>103</s> <s>93</s> 77 bytes

Loads of bytes saved thanks to @Frozn, and by using Object as return-type, we can comply with OP's rules of returning the input-array when the array is empty, despite Java's one-return-type-only nature regarding methods.

m->{int f=1;for(var a:m)f=m[0].length!=a.length?0:f;return m.length<1?m:f>0;}

Try it online.

Explanation:

m->{                  // Method with integer-matrix parameter and Object return-type
  int f=1;            //  Flag-integer, starting at 1
  for(var a:m)        //  Loop over the rows of the matrix
    f=m[0].length!=a.length?
                      //   If the length of the first and current row aren't the same:
       0              //    Change `f` to 0
      :               //   Else:
       f;             //    Leave `f` the same
  return m.length<1?  //  If there is only one row:
          m           //   Return the input-matrix as result
         :            //  Else:
          f>0;}       //   Return whether the flag `f` is still 1 as boolean

ContentLicense: CC BY-SA 4.0


问:
Shortest infinite loop producing no output
Your task is to create the shortest infinite loop!

The point of this challenge is to create an infinite loop producing no output, unlike its possible duplicate. The reason to this is because the code might be shorter if no output is given.

Rules

Each submission must be a full program.

You must create the shortest infinite loop.

Even if your program runs out of memory eventually, it is still accepted as long as it is running the whole time from the start to when it runs out of memory. Also when it runs out of memory, it should still not print anything to STDERR.

The program must take no input (however, reading from a file is allowed), and should not print anything to STDOUT. Output to a file is also forbidden.

The program must not write anything to STDERR.

Feel free to use a language (or language version) even if it's newer than this challenge.
-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. :D

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

This is not about finding the language with the shortest infinite loop program. This is about finding the shortest infinite loop program in every language. Therefore, I will not accept an answer.

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 Brainf**k-derivatives like Alphuck), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

There should be a website such as Wikipedia, Esolangs, or GitHub for the language. For example, if the language is CJam, then one could link to the site in the header like #[CJam](http://sourceforge.net/p/cjam/wiki/Home/), X bytes.

Standard loopholes are not allowed.

(I have taken some of these rules from Martin Büttner's "Hello World" challenge)

Please feel free to post in the comments to tell me how this challenge could be  improved.

Catalogue

This is a Stack Snippet which generates both an alphabetical catalogue of the used languages, and an overall leaderboard. To make sure your answer shows up, please start it with this Markdown header:

```<code># Language name, X bytes
</code>```

Obviously replacing Language name and X bytes with the proper items. If you want to link to the languages' website, use this template, as posted above:

```<code>#[Language name](http://link.to/the/language), X bytes
</code>```

Now, finally, here's the snippet: (Try pressing "Full page" for a better view.)

var QUESTION_ID=59347;var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";var COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk";var OVERRIDE_USER=41805;var answers=[],answers_hash,answer_ids,answer_page=1,more_answers=true,comment_page;function answersUrl(index){return"//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"//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,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.toLowerCase()>b.lang_raw.toLowerCase())return 1;if(a.lang_raw.toLowerCase()<b.lang_raw.toLowerCase())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:500px;float:left}#language-list{padding:10px;padding-right:40px;width:500px;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

```

答:
Brachylog, 2 bytes

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

Takes no input and no output.

Explanation

= will label the input with an integer. \ is always false and will therefore trigger backtracking. Since the input has no constraints, it will unify as following, through backtracking: 0, then 1, then -1, then 2, etc. This will go on forever.

Body:
Brachylog, 2 bytes

=\

Takes no input and no output.

Explanation

= will label the input with an integer. \ is always false and will therefore trigger backtracking. Since the input has no constraints, it will unify as following, through backtracking: 0, then 1, then -1, then 2, etc. This will go on forever.


问:
Tips for golfing in Python
What general tips do you have for golfing in Python? I'm looking for ideas which can be applied to code-golf problems and which are also at least somewhat specific to Python (e.g. "remove comments" is not an answer).

Please post one tip per answer.

答: To assign to a tuple, don't use parentheses. For example, a=1,2,3 assigns a to the tuple (1, 2, 3). b=7, assigns b to the tuple (7,). This works in both Python 2 and Python 3.

Title: Tips for golfing in Python


问:
Write a program that always prints N when it is shifted N times up the ASCII alphabet
Write a program using only printable ASCII characters that takes no input. For reference, here are the 95 printable ASCII characters in order:

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

When your program is run it should print 0 (plus an optional trailing newline) to stdout, then terminate normally.

When each character in your program is replaced by the character N spaces to its right in printable ASCII, looping around from ~ to space, the resulting printable ASCII string will ideally be a program runnable in the same language that takes no input and outputs N (plus an optional trailing newline) to stdout, then terminates normally, for N = 1 to 94.

For example, if your original program was

```<code>@Cat~(88 !)
</code>```

running it should output 0 and shifting all the characters up the printable ASCII scale by one

```<code>ADbu )99!"*
</code>```

should result in another program that outputs 1. Doing so again will ideally result in another program that outputs 2

```<code>BEcv!*::"#+
</code>```

and so on with 3 and 4, etc. up to the point of shifting 94 times

```<code>?B`s}'77~ (
</code>```

which ideally is a program that outputs 94.

The relief is that this is only the ideal behavior. Your program and its 94 derivatives do not all need to work, but the more that consecutively do from the start the better. (Programs that do not work may have any behavior whatsoever.)

Scoring

Your score is the number of consecutive programs starting from the original (the one that outputs 0) that do work, i.e. correctly output their corresponding N. The answer with the highest score (a maximum of 95) wins. If there's a tie then the program with the shortest length in bytes wins.

For example, if @Cat~(88 !) output 0 and ADbu )99!"* output 1 but BEcv!*::"#+ errored, then your score would be 2. It's 2 even if ?B`s}'77~ ( accurately outputs 94 and even if all the programs for N = 30 to 40 worked. Only the consecutive number of working programs, starting at zero, are counted.

Notes

To combat potential contention and loopholes, competing answers must output their numbers in decimal with no leading zeroes or signs or decimal points (i.e. plain 0 1 2 ... 94).

Languages that use different bases or number formats are allowed but are not eligible to win.

The presence of an optional trailing newline does not need to be consistent across programs.

Functions and REPL commands are not allowed, only full programs.


问:
Sum It Up with a Digital Triangle
Well, sum it down really.

Write a program or function that takes in a nonempty list of decimal integers (0-9) and outputs a downward pointing "triangle" of digits with the input list at the top where every digit after the first line is the sum of the two digits above it modulo 10.

For example, the input [7, 5, 0, 9] has output

```<code>7 5 0 9
 2 5 9
  7 4
   1
</code>```

because 2 is (7 + 5) mod 10, 5 is (5 + 0) mod 10, 9 is (0 + 9) mod 10, etc. all the way to 1 being (7 + 4) mod 10.

If the list has only one item, then the output matches the input; e.g. an input of [4] will yield

```<code>4
</code>```

Here are some additional examples:

```<code>[0]

0

[1, 2]

1 2
 3

[8, 7]

8 7
 5

[0, 0]

0 0
 0

[1, 4, 2]

1 4 2
 5 6
  1

[0, 1, 0]

0 1 0
 1 1
  2

[1, 0, 0, 0]

1 0 0 0
 1 0 0
  1 0
   1

[1, 2, 3, 4]

1 2 3 4
 3 5 7
  8 2
   0

[1, 2, 3, 5, 8]

1 2 3 5 8
 3 5 8 3
  8 3 1
   1 4
    5

[9, 2, 4, 5, 3, 2, 2]

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

Note that in the output:

The first line does not have leading spaces.

Each subsequent line has one more leading space than the line previous.

Digits are separated by a single space.

Each line is allowed to have up to one trailing space.

There may be a single optional trailing newline.

You must use the characters for normal decimal digits (0 through 9).

The shortest code in bytes wins. Tiebreaker is earlier answer.

答:
Java 7, <s>230</s> <s>215</s> 213 bytes

```<code>int c=0;void m(int[]a){int l=a.length,j=-1,i=-1;if(l<1)return;int[]x=new int[l-1];while(++j<c)p(" ");for(;++i<l;p(a[i]+" "))if(i<l&i>0)x[i-1]=(a[i-1]+a[i])%10;p("\n");c++;m(x);}<T>void p(T s){System.out.print(s);}
</code>```

This ended up being a bit longer than I thought.. Maybe it can be golfed a bit more though, since I kinda messed up I think..

Some bytes saved thanks to @GiacomoGarabello.

Ungolfed & test code:

Try it here.

```<code>class Main{
  static int c = 0;

  static void m(int[] a){
    int l = a.length,
        j = -1,
        i = -1;
    if(l < 1){
      return;
    }
    int[] x = new int[l-1];
    while(++j < c){
      p(" ");
    }
    for(; ++i < l; p(a[i] + " ")){
      if(i < l & i > 0){
        x[i - 1] = (a[i - 1] + a[i]) % 10;
      }
    }
    p("\n");
    c++;
    m(x);
  }

  static <T> void p(T s){
    System.out.print(s);
  }

  static void printAndReset(int[] a){
    m(a);
    c = 0;
    System.out.println();
  }

  public static void main(String[] a){
    printAndReset(new int[]{ 7, 5, 0, 9 });
    printAndReset(new int[]{ 0 });
    printAndReset(new int[]{ 1, 2 });
    printAndReset(new int[]{ 8, 7 });
    printAndReset(new int[]{ 0, 0 });
    printAndReset(new int[]{ 1, 4, 2 });
    printAndReset(new int[]{ 0, 1, 0 });
    printAndReset(new int[]{ 1, 0, 0, 0 });
    printAndReset(new int[]{ 1, 2, 3, 4 });
    printAndReset(new int[]{ 1, 2, 3, 5, 8 });
    printAndReset(new int[]{ 9, 2, 4, 5, 3, 2, 2 });
  }
}
</code>```

Output:

```<code>7 5 0 9
 2 5 9
  7 4
   1

0

1 2
 3

8 7
 5

0 0
 0

1 4 2
 5 6
  1

0 1 0
 1 1
  2

1 0 0 0
 1 0 0
  1 0
   1

1 2 3 4
 3 5 7
  8 2
   0

1 2 3 5 8
 3 5 8 3
  8 3 1
   1 4
    5

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

Title: Sum It Up with a Digital Triangle

Body:
Java 7, <s>230</s> <s>215</s> 213 bytes

int c=0;void m(int[]a){int l=a.length,j=-1,i=-1;if(l<1)return;int[]x=new int[l-1];while(++j<c)p(" ");for(;++i<l;p(a[i]+" "))if(i<l&i>0)x[i-1]=(a[i-1]+a[i])%10;p("\n");c++;m(x);}<T>void p(T s){System.out.print(s);}

This ended up being a bit longer than I thought.. Maybe it can be golfed a bit more though, since I kinda messed up I think..

Some bytes saved thanks to @GiacomoGarabello.

Ungolfed & test code:

Try it here.

class Main{
  static int c = 0;

  static void m(int[] a){
    int l = a.length,
        j = -1,
        i = -1;
    if(l < 1){
      return;
    }
    int[] x = new int[l-1];
    while(++j < c){
      p(" ");
    }
    for(; ++i < l; p(a[i] + " ")){
      if(i < l & i > 0){
        x[i - 1] = (a[i - 1] + a[i]) % 10;
      }
    }
    p("\n");
    c++;
    m(x);
  }

  static <T> void p(T s){
    System.out.print(s);
  }

  static void printAndReset(int[] a){
    m(a);
    c = 0;
    System.out.println();
  }

  public static void main(String[] a){
    printAndReset(new int[]{ 7, 5, 0, 9 });
    printAndReset(new int[]{ 0 });
    printAndReset(new int[]{ 1, 2 });
    printAndReset(new int[]{ 8, 7 });
    printAndReset(new int[]{ 0, 0 });
    printAndReset(new int[]{ 1, 4, 2 });
    printAndReset(new int[]{ 0, 1, 0 });
    printAndReset(new int[]{ 1, 0, 0, 0 });
    printAndReset(new int[]{ 1, 2, 3, 4 });
    printAndReset(new int[]{ 1, 2, 3, 5, 8 });
    printAndReset(new int[]{ 9, 2, 4, 5, 3, 2, 2 });
  }
}

Output:

7 5 0 9
 2 5 9
  7 4
   1

0

1 2
 3

8 7
 5

0 0
 0

1 4 2
 5 6
  1

0 1 0
 1 1
  2

1 0 0 0
 1 0 0
  1 0
   1

1 2 3 4
 3 5 7
  8 2
   0

1 2 3 5 8
 3 5 8 3
  8 3 1
   1 4
    5

9 2 4 5 3 2 2
 1 6 9 8 5 4
  7 5 7 3 9
   2 2 0 2
    4 2 2
     6 4
      0


问:
Pseudofactorial
There is a rather curious number which shows up sometimes in math problems or riddles. The pseudofactorial(N) is the least (i.e. lowest) common multiple of the numbers 1 through N; in other words, it's the lowest number which has all numbers from 1 through N as factors.

For instance pseudofactorial(7) = 3 * 4 * 5 * 7, which is the same as 7! except that 2 and 6 have been removed because they are contained in other terms.

Write a program to calculate pseudofactorial(N) and as always, shortest code wins.

Here is a short list for your use. More test cases can be found in the OEIS under A003418.

Factorial:

1

2

6

24

120

720

5040

Pseudofactorial:

1

2

6

12

60

60

420

答:
05AB1E, 20 bytes

```<code>Lpvyi¹LÒN>¢àN>*ˆ}}¯P
</code>```

Explanation

```<code>Lpv                    # for each item in isprime(range(1,N)): N=7 -> [0,1,1,0,1,0,1]
   yi                  # if prime
     ¹LÒN>¢            # count occurrences of the prime
                         in the prime-factorization of range(1,N):
                         p=2 -> [0,1,0,2,0,1,0]
           àN>*ˆ       # add max occurrence of that prime multiplied by the prime
                         to global array: N=7 -> [4,3,5,7]
                }}     # end if/loop
                  ¯P   # get product of global array
</code>```

Try it online

Title: Pseudofactorial

Body:
05AB1E, 20 bytes

Lpvyi¹LÒN>¢àN>*ˆ}}¯P

Explanation

Lpv                    # for each item in isprime(range(1,N)): N=7 -> [0,1,1,0,1,0,1]
   yi                  # if prime
     ¹LÒN>¢            # count occurrences of the prime
                         in the prime-factorization of range(1,N):
                         p=2 -> [0,1,0,2,0,1,0]
           àN>*ˆ       # add max occurrence of that prime multiplied by the prime
                         to global array: N=7 -> [4,3,5,7]
                }}     # end if/loop
                  ¯P   # get product of global array

Try it online


答:
Actually, 43 bytes

```<code>;l;D+#"{:^%d}"%╗W;' j1╟╜f.;pXZ`i+9u@%`MdXWX
</code>```

Try it online!

This program prints a single trailing newline after the output.

Explanation:

```<code>;l;D+#"{:^%d}"%╗W;' j1╟╜f.;pXZ`i+9u@%`MdXWX
;l;D+                                        calculate the width of the field (2L-1 where L = len(input))
     #"{:^%d}"%╗                             push to a list, make a Python new-style format string for centering text, save in reg0
                W;' j1╟╜f.;pXZ`i+9u@%`MdXW   while the top of the stack is truthy:
                 ;' j1╟                        duplicate list, join with spaces, push string to a list
                       ╜f.                     center string and print
                          ;pXZ                 zip list with itself shifted forward by 1 (zip(a,a[1:]))
                              `i+9u@%`M        map: add each pair and mod by 10
                                       dX      discard the last value (which was not added with anything)
                                          X  discard the now-empty list after the loop to avoid printing it
</code>```

Title: Sum It Up with a Digital Triangle

Body:
Well, sum it down really.

Write a program or function that takes in a nonempty list of decimal integers (0-9) and outputs a downward pointing "triangle" of digits with the input list at the top where every digit after the first line is the sum of the two digits above it modulo 10.

For example, the input [7, 5, 0, 9] has output

```<code>7 5 0 9
 2 5 9
  7 4
   1
</code>```

because 2 is (7 + 5) mod 10, 5 is (5 + 0) mod 10, 9 is (0 + 9) mod 10, etc. all the way to 1 being (7 + 4) mod 10.

If the list has only one item, then the output matches the input; e.g. an input of [4] will yield

```<code>4
</code>```

Here are some additional examples:

```<code>[0]

0

[1, 2]

1 2
 3

[8, 7]

8 7
 5

[0, 0]

0 0
 0

[1, 4, 2]

1 4 2
 5 6
  1

[0, 1, 0]

0 1 0
 1 1
  2

[1, 0, 0, 0]

1 0 0 0
 1 0 0
  1 0
   1

[1, 2, 3, 4]

1 2 3 4
 3 5 7
  8 2
   0

[1, 2, 3, 5, 8]

1 2 3 5 8
 3 5 8 3
  8 3 1
   1 4
    5

[9, 2, 4, 5, 3, 2, 2]

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

Note that in the output:

The first line does not have leading spaces.

Each subsequent line has one more leading space than the line previous.

Digits are separated by a single space.

Each line is allowed to have up to one trailing space.

There may be a single optional trailing newline.

You must use the characters for normal decimal digits (0 through 9).

The shortest code in bytes wins. Tiebreaker is earlier answer.

Body:
Actually, 43 bytes

;l;D+#"{:^%d}"%╗W;' j1╟╜f.;pXZ`i+9u@%`MdXWX

Try it online!

This program prints a single trailing newline after the output.

Explanation:

;l;D+#"{:^%d}"%╗W;' j1╟╜f.;pXZ`i+9u@%`MdXWX
;l;D+                                        calculate the width of the field (2L-1 where L = len(input))
     #"{:^%d}"%╗                             push to a list, make a Python new-style format string for centering text, save in reg0
                W;' j1╟╜f.;pXZ`i+9u@%`MdXW   while the top of the stack is truthy:
                 ;' j1╟                        duplicate list, join with spaces, push string to a list
                       ╜f.                     center string and print
                          ;pXZ                 zip list with itself shifted forward by 1 (zip(a,a[1:]))
                              `i+9u@%`M        map: add each pair and mod by 10
                                       dX      discard the last value (which was not added with anything)
                                          X  discard the now-empty list after the loop to avoid printing it


答:
Pyke, 21 bytes

```<code>lVDm}R$],FsT%)od*pKDP
</code>```

Try it here!

I'd like to think this method's a little bit different.

```<code>[1, 2, 3, 5, 8] - take the input
[2, 4, 6, 10, 16] - double it
[1, 2, 3, 5, 8] - take the input again
[1, 1, 2, 3] - get the deltas
[[2,1], [4,1], [6,2], [10,3]] - transpose them together
[3, 5, 8, 13] - apply addition
[3, 5, 8, 3] - mod 10
</code>```

Title: Sum It Up with a Digital Triangle

Body:
Pyke, 21 bytes

lVDm}R$],FsT%)od*pKDP

Try it here!

I'd like to think this method's a little bit different.

[1, 2, 3, 5, 8] - take the input
[2, 4, 6, 10, 16] - double it
[1, 2, 3, 5, 8] - take the input again
[1, 1, 2, 3] - get the deltas
[[2,1], [4,1], [6,2], [10,3]] - transpose them together
[3, 5, 8, 13] - apply addition
[3, 5, 8, 3] - mod 10


答:
Actually, 18 bytes

```<code>`♂l╔l;Y"[].⌂"£n=1`
</code>```

Try it online! (calls the function with ƒ)

Explanation:

```<code>`♂l╔l;Y"[].⌂"£n=1`  push a function:
 ♂l                   map length over input
   ╔l                 uniquify
     ;Y               1 if list is empty else 0
       "[].⌂"£n       call this function that many times:
        [].             print an empty list
           ⌂            exit
               =1     1 if length of unique list equals 1 else 0
</code>```

If the function-only requirement is lifted, the equivalent program works for 15 bytes:

```<code>♂l╔l;Y`[].⌂`n=1
</code>```

Try it online!

Title: Same length sub arrays

Body:
Actually, 18 bytes

`♂l╔l;Y"[].⌂"£n=1`

Try it online! (calls the function with ƒ)

Explanation:

`♂l╔l;Y"[].⌂"£n=1`  push a function:
 ♂l                   map length over input
   ╔l                 uniquify
     ;Y               1 if list is empty else 0
       "[].⌂"£n       call this function that many times:
        [].             print an empty list
           ⌂            exit
               =1     1 if length of unique list equals 1 else 0

If the function-only requirement is lifted, the equivalent program works for 15 bytes:

♂l╔l;Y`[].⌂`n=1

Try it online!


答:
05Ab1E, 12 bytes

```<code>Dg0Qië€gÙg1Q
</code>```

Explained

```<code>Dg0Qi          # if empty list, return input
     ë         # else
      €g       # map length over list
        Ùg1Q   # check if length of uniquified list is 1
</code>```

Try it online

Title: Same length sub arrays

Body:
05Ab1E, 12 bytes

Dg0Qië€gÙg1Q

Explained

Dg0Qi          # if empty list, return input
     ë         # else
      €g       # map length over list
        Ùg1Q   # check if length of uniquified list is 1

Try it online


问:
Find the Factorial!
Create the shortest program or function that finds the factorial of a non-negative integer.

The factorial, represented with ! is defined as such

$$n!:=\begin{cases}1 & n=0\\n\cdot(n-1)!&n>0\end{cases}$$

In plain English the factorial of 0 is 1 and the factorial of n, where n is larger than 0 is n times the factorial of one less than n.

Your code should perform input and output using a standard methods.

Requirements:

Does not use any built-in libraries that can calculate the factorial (this includes any form of eval)

Can calculate factorials for numbers up to 125

Can calculate the factorial for the number 0 (equal to 1)

Completes in under a minute for numbers up to 125

The shortest submission wins, in the case of a tie the answer with the most votes at the time wins.

答:
Mathcad, tbd "bytes"

Mathcad byte-equivalence system yet to be determined.  Some operators cannot be entered as text but have keyboard "shortcuts" instead (or can be picked from a toolbar).  For example, the product operator is inserted using the key combination ctl-# ; this results in a capital Pi symbol being placed upon the Mathcad worksheet, together with 4 associated placeholders (black rectangles) which hold the iteration variable, starting value, final value and the expression for each element of the product.  Balanced parentheses can be entered (in most cases) using the quote key.  Typing : enters the assignment operator :=.

Mathcad has both a standard IEEE numerical floating point processing system and a longnum symbolic processing system that run in parallel over the same worksheet. = is the numeric evaluation operator whilst → is the symbolic evaluation operator.

Title: Find the Factorial!


问:
Generalized Birthday Problem
Tonight, my fiancée took me out to dinner to celebrate my birthday. While we were out, I heard Happy Birthday sung to 5 different guests (including myself), in a restaurant full of 50 people. This got me wondering - the original birthday problem (finding the probability that 2 people in a room of N people share the same birthday) is very simple and straightforward. But what about calculating the probability that at least k people out of N people share the same birthday?

In case you're wondering, the probability of at least 5 people out of 50 total people sharing the same birthday is about 1/10000.

The Challenge

Given two integers N and k, where N >= k > 0, output the probability that at least k people in a group of N people share the same birthday. To keep things simple, assume that there are always 365 possible birthdays, and that all days are equally likely.

For k = 2, this boils down to the original birthday problem, and the probability is 1 - P(365, N)/(365)**N (where P(n,k) is the number of k-length permutations formed from n elements). For larger values of k, this Wolfram MathWorld article may prove useful.

Rules

Output must be deterministic, and as accurate as possible for your chosen language. This means no Monte Carlo estimation or Poisson approximation.

N and k will be no larger than the largest representable integer in your chosen language. If your chosen language has no hard maximum on integers (aside from memory constraints), then N and k may be arbitrarily large.

Accuracy errors stemming from floating-point inaccuracies may be ignored - your solution should assume perfectly-accurate, infinite-precision floats.

Test Cases

Format: k, N -> exact fraction (float approximation)

```<code>2, 4 -> 795341/48627125 (0.016355912466550306)
2, 10 -> 2689423743942044098153/22996713557917153515625 (0.11694817771107766)
2, 23 -> 38093904702297390785243708291056390518886454060947061/75091883268515350125426207425223147563269805908203125 (0.5072972343239854)
3, 3 -> 1/133225 (7.5060987051979735e-06)
3, 15 -> 99202120236895898424238531990273/29796146005797507000413918212890625 (0.0033293607910766013)
3, 23 -> 4770369978858741874704938828021312421544898229270601/375459416342576750627131037126115737816349029541015625 (0.01270542106874784)
3, 88 -> 121972658600365952270507870814168157581992420315979376776734831989281511796047744560525362056937843069780281314799508374037334481686749665057776557164805212647907376598926392555810192414444095707428833039241/238663638085694198987526661236008945231785263891283516149752738222327030518604865144748956653519802030443538582564040039437134064787503711547079611163210009542953054552383296282869196147657930850982666015625 (0.5110651106247305)
4, 5 -> 1821/17748900625 (1.0259790386313012e-07)
4, 25 -> 2485259613640935164402771922618780423376797142403469821/10004116148447957520459906484225353834116619892120361328125 (0.0002484237064787077)
5, 50 -> 786993779912104445948839077141385547220875807924661029087862889286553262259306606691973696493529913926889614561937/7306010813549515310358093277059651246342214174497508156711617142094873581852472030624097938198246993124485015869140625 (0.00010771867165219201)
10, 11 -> 801/8393800448639761033203125 (9.542757239717371e-23)
10, 20 -> 7563066516919731020375145315161/4825745614492126958810682272575693836212158203125 (1.5672327389589693e-18)
10, 100 -> 122483733913713880468912433840827432571103991156207938550769934255186675421169322116627610793923974214844245486313555179552213623490113886544747626665059355613885669915058701717890707367972476863138223808168550175885417452745887418265215709/1018100624231385241853189999481940942382873878399046008966742039665259133127558338726075853312698838815389196105495212915667272376736512436519973194623721779480597820765897548554160854805712082157001360774761962446621765820964355953037738800048828125 (1.2030611807765361e-10)
10, 200 -> 46037609834855282194444796809612644889409465037669687935667461523743071657580101605348193810323944369492022110911489191609021322290505098856358912879677731966113966723477854912238177976801306968267513131490721538703324306724303400725590188016199359187262098021797557231190080930654308244474302621083905460764730976861073112110503993354926967673128790398832479866320227003479651999296010679699346931041199162583292649095888379961533947862695990956213767291953359129132526574405705744727693754517/378333041587022747413582050553902956219347236460887942751654696440740074897712544982385679244606727641966213694207954095750881417642309033313110718881314425431789802709136766451022222829015561216923212248085160525409958950556460005591372098706995468877542448525403291516015085653857006548005361106043070914396018461580475651719152455730181412523297836008507156692430467118523245584181582255037664477857149762078637248959905010608686740872875726844702607085395469621591502118462813086807727813720703125 (1.21685406174776e-07)
</code>```

答:
MATL, 16 bytes

```<code>365:Z^!tXM=s>~Ym
</code>```

First input is N, second is k.

Try it online!

This is an enumeration-based approach, like Dennis' Jelly answer, so input numbers should be kept small due to memory limitations.

```<code>365:   % Vector [1 2 ... 365]
Z^     % Take N implicitly. Cartesian power. Gives a 2D array with each
       % "combination" on a row
!      % Transpose
t      % Duplicate
XM     % Mode (most frequent element) of each column
=      % Test for equality, element-wise with broadcast. For each column, gives
       % true for elements equal to that column's mode, false for the rest
s      % Sum of each column. Gives a row vector
>~     % Take k implicitly. True for elements equal or greater than k
Ym     % Mean of each column. Implicitly display
</code>```

Title: Generalized Birthday Problem

Body:
MATL, 16 bytes

365:Z^!tXM=s>~Ym

First input is N, second is k.

Try it online!

This is an enumeration-based approach, like Dennis' Jelly answer, so input numbers should be kept small due to memory limitations.

365:   % Vector [1 2 ... 365]
Z^     % Take N implicitly. Cartesian power. Gives a 2D array with each
       % "combination" on a row
!      % Transpose
t      % Duplicate
XM     % Mode (most frequent element) of each column
=      % Test for equality, element-wise with broadcast. For each column, gives
       % true for elements equal to that column's mode, false for the rest
s      % Sum of each column. Gives a row vector
>~     % Take k implicitly. True for elements equal or greater than k
Ym     % Mean of each column. Implicitly display


答:
TSQL, <s>198</s> <s>194</s> 191 bytes

By using GOTO instead of one of the WHILE, I was able to golf 3 characters

Golfed

```<code>DECLARE @ varchar(100)= '1 2 3 4 5 6 7'

DECLARE @j INT=1,@i INT=LEN(@)a:
PRINT @
WHILE @i>@j
SELECT
@=STUFF(@,@i-1,2,RIGHT(SUBSTRING(@,@i-2,1)+SUBSTRING(@,@i,1)*1,1)+' '),@i-=2SELECT
@=STUFF(@,@j,1,' '),@j+=1,@i=LEN(@)IF @i>0GOTO a
</code>```

Try it online(using old script with 2*WHILE)

Title: Sum It Up with a Digital Triangle

Body:
TSQL, <s>198</s> <s>194</s> 191 bytes

By using GOTO instead of one of the WHILE, I was able to golf 3 characters

Golfed

DECLARE @ varchar(100)= '1 2 3 4 5 6 7'

DECLARE @j INT=1,@i INT=LEN(@)a:
PRINT @
WHILE @i>@j
SELECT
@=STUFF(@,@i-1,2,RIGHT(SUBSTRING(@,@i-2,1)+SUBSTRING(@,@i,1)*1,1)+' '),@i-=2SELECT
@=STUFF(@,@j,1,' '),@j+=1,@i=LEN(@)IF @i>0GOTO a

Try it online(using old script with 2*WHILE)


答:
Mathematica, 67 Bytes

```<code>MatrixForm@NestList[Mod[Total/@Partition[#,2,1],10]&,#,Length@#-1]&
</code>```

Example:

Title: Sum It Up with a Digital Triangle

Body:
Mathematica, 67 Bytes

MatrixForm@NestList[Mod[Total/@Partition[#,2,1],10]&,#,Length@#-1]&

Example:


Title: Sum It Up with a Digital Triangle

Body:
JavaScript (ES6), 77 bytes

a=a.map((_,i)=>(b=a,a=[a.map((e,j)=>j>i?(e+a[j-1])%10:''),b.join` `)).join`
`


答:
PowerShell v2+, 53 bytes

```<code>param($a)if($a){($a|%{$_.count}|select -u).count-eq1}
</code>```

This presumes that standard I/O methods and both programs and functions are allowed. Additionally, in PowerShell, the concept of "returning" an empty array is meaningless -- it's converted to $null as soon as it leaves scope -- and so it is the equivalent of returning nothing, which is what is done here.

We take input $a, and if it's non-empty we collect all the .counts of each sub-array. We pipe that to Select-Object with the -unique flag, take that .count and verify that it's -equal to 1. Returns Boolean $true or $false. If the input is the empty array, returns nothing (i.e., $null).

Examples

```<code>PS C:\Tools\Scripts\golfing> .\same-length-sub-arrays.ps1 ((1),(2),(3))
True

PS C:\Tools\Scripts\golfing> .\same-length-sub-arrays.ps1 ((1),(2),(3,4))
False

PS C:\Tools\Scripts\golfing> .\same-length-sub-arrays.ps1 @()

PS C:\Tools\Scripts\golfing> (.\same-length-sub-arrays.ps1 @()).GetType()
You cannot call a method on a null-valued expression.
At line:1 char:1
+ (.\same-length-sub-arrays.ps1 @()).GetType()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

PS C:\Tools\Scripts\golfing> (.\same-length-sub-arrays.ps1 @())-eq$null
True
</code>```

Title: Same length sub arrays

Body:
PowerShell v2+, 53 bytes

param($a)if($a){($a|%{$_.count}|select -u).count-eq1}

This presumes that standard I/O methods and both programs and functions are allowed. Additionally, in PowerShell, the concept of "returning" an empty array is meaningless -- it's converted to $null as soon as it leaves scope -- and so it is the equivalent of returning nothing, which is what is done here.

We take input $a, and if it's non-empty we collect all the .counts of each sub-array. We pipe that to Select-Object with the -unique flag, take that .count and verify that it's -equal to 1. Returns Boolean $true or $false. If the input is the empty array, returns nothing (i.e., $null).

Examples

PS C:\Tools\Scripts\golfing> .\same-length-sub-arrays.ps1 ((1),(2),(3))
True

PS C:\Tools\Scripts\golfing> .\same-length-sub-arrays.ps1 ((1),(2),(3,4))
False

PS C:\Tools\Scripts\golfing> .\same-length-sub-arrays.ps1 @()

PS C:\Tools\Scripts\golfing> (.\same-length-sub-arrays.ps1 @()).GetType()
You cannot call a method on a null-valued expression.
At line:1 char:1
+ (.\same-length-sub-arrays.ps1 @()).GetType()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

PS C:\Tools\Scripts\golfing> (.\same-length-sub-arrays.ps1 @())-eq$null
True


答:
Dyalog APL, 3 bytes

```<code>∧/⍳
</code>```

APL beats Jelly‽

⍳ 1 though argument

∧/ LCM across

Title: Pseudofactorial

Body:
There is a rather curious number which shows up sometimes in math problems or riddles. The pseudofactorial(N) is the least (i.e. lowest) common multiple of the numbers 1 through N; in other words, it's the lowest number which has all numbers from 1 through N as factors.

For instance pseudofactorial(7) = 3 * 4 * 5 * 7, which is the same as 7! except that 2 and 6 have been removed because they are contained in other terms.

Write a program to calculate pseudofactorial(N) and as always, shortest code wins.

Here is a short list for your use. More test cases can be found in the OEIS under A003418.

Factorial:

1

2

6

24

120

720

5040

Pseudofactorial:

1

2

6

12

60

60

420

Body:
Dyalog APL, 3 bytes

∧/⍳

APL beats Jelly‽

⍳ 1 though argument

∧/ LCM across


答:
Minkolang 0.15, 12 bytes

I have two 12-byte solutions, and have included them both.

```<code>1n[i1+4$M]N.
</code>```

Try it here!

Explanation

```<code>1               Push 1
 n              Take number from input
  [             For loop that repeats n times
   i1+          Push loop counter + 1
      4$M       Pop b, a and push lcm(a,b)
         ]      Close for loop
          N.    Output as number and stop.
</code>```

About as straightforward as it gets.

```<code>11nLd[4$M]N.
</code>```

Try it here!

Explanation

```<code>11              Push two 1s
  n             Take number from input
   L            Pop b, a and push range from a to b, inclusive
    d           Duplicate top of stack (n)
     [4$M]      Pop b, a and push lcm(a,b), n times
          N.    Output as number and stop.
</code>```

A third solution can be derived from this: remove a 1 and add a d after the current d. In both cases, the extra number is needed because the for loop runs one too many times, and making it run one less time takes two bytes (1- just before the [).

Title: Pseudofactorial

Body:
Minkolang 0.15, 12 bytes

I have two 12-byte solutions, and have included them both.

1n[i1+4$M]N.

Try it here!

Explanation

1               Push 1
 n              Take number from input
  [             For loop that repeats n times
   i1+          Push loop counter + 1
      4$M       Pop b, a and push lcm(a,b)
         ]      Close for loop
          N.    Output as number and stop.

About as straightforward as it gets.

11nLd[4$M]N.

Try it here!

Explanation

11              Push two 1s
  n             Take number from input
   L            Pop b, a and push range from a to b, inclusive
    d           Duplicate top of stack (n)
     [4$M]      Pop b, a and push lcm(a,b), n times
          N.    Output as number and stop.

A third solution can be derived from this: remove a 1 and add a d after the current d. In both cases, the extra number is needed because the for loop runs one too many times, and making it run one less time takes two bytes (1- just before the [).


问:
Return the integers with square digit-sums

Introduction and Credit

We all know and love our awesome rules to test whether a number is divisble by 11 or 3, which is just some clever sum over the digits of the number. Now this challenge takes this to a new level, by requiring you to compute the sum of the digits and then checking whether the result is a perfect integer square, neither of which operations usually can be done very short. As this property is also very hard to see when looking at a number, we want this to be done for entire lists of numbers so we can save human work. So this is your challenge now!

This was an assignment at my university functional programming course. This assignment is now closed and has been discussed in class and I have my professor's permission to post it here (I asked explicitely).

Specification

Input

Your input is a list of non-negative integers, in any standard I/O format.

You may choose the list format as your language needs it

Output

The output is a list of integers, in any standard I/O format.

What to do?

Filter out every integer from the input list for which the sum of the digits is not a a square (of an integer).

The order of the elements may not be changed, e.g. if you get [1,5,9] you may not return [9,1]

Potential corner cases

0 is a non-negative integer and thus a valid input and 0 is also a valid integer root, e.g. 0 counts as an integer square.

The empty list is a valid input and output as well.

Who wins?

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

Standard rules apply of course.

Test Cases

```<code>[1,4,9,16,25,1111] -> [1,4,9,1111]
[1431,2,0,22,999999999] -> [1431,0,22,999999999]
[22228,4,113125,22345] -> [22228,4,22345]
[] -> []
[421337,99,123456789,1133557799] -> []
</code>```

Step-by-Step Example

```<code>Example input: [1337,4444]
Handling first number:
Sum of the digits of 1337: 1+3+3+7=14
14 is not an integer square, thus will be dropped!
Handling second number:
Sum of the digits of 4444: 4+4+4+4=16
16 is an integer square because 4*4=16, can get into the output list!
Example output: [4444]
</code>```

答:
Pyke, 6 bytes

```<code>#s,DBq
</code>```

Try it here!

```<code>#      - Filter list on truthiness:
 s     -    digital_root(^)
  ,    -   sqrt(^)
    Bq -  int(^) == ^
</code>```

Body:
Pyke, 6 bytes

#s,DBq

Try it here!

#      - Filter list on truthiness:
 s     -    digital_root(^)
  ,    -   sqrt(^)
    Bq -  int(^) == ^


问:
Count up forever
Write a program that counts up forever, starting from one.

Rules:

Your program must log to STDOUT or an acceptable alternative, if STDOUT is not available.

Your program must be a full, runnable program, and not a function or snippet.

Your program must output each number with a separating character in between (a newline, space, tab or comma), but this must be consistent for all numbers.

You may print the numbers in decimal, in unary or in base 256 where each digit is represented by a byte value.

Your program must count at least as far as 2128 (inclusive) without problems and without running out of memory on a reasonable desktop PC. In particular, this means if you're using unary, you cannot store a unary representation of the current number in memory.

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

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

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

```

答:
05AB1E, 4 bytes

```<code>[¼¾,
</code>```

Explained

```<code>[           # start infinite loop
 ¼          # increase counter
  ¾         # push counter
   ,        # print with a newline
</code>```

Title: Count up forever

Body:
05AB1E, 4 bytes

[¼¾,

Explained

[           # start infinite loop
 ¼          # increase counter
  ¾         # push counter
   ,        # print with a newline


答:
Jelly, <s>8</s> 7 bytes

1 byte thanks to @Sp3000.

```<code>DSÆ²ðÐf
</code>```

Test suite.

Explanation

```<code>DSÆ²ðÐf  Main monadic chain. Argument: z

     Ðf  Filter for truthiness:
D            convert to base 10
 S           sum
  Æ²         is perfect square
</code>```

Title: Return the integers with square digit-sums

Body:
Introduction and Credit

We all know and love our awesome rules to test whether a number is divisble by 11 or 3, which is just some clever sum over the digits of the number. Now this challenge takes this to a new level, by requiring you to compute the sum of the digits and then checking whether the result is a perfect integer square, neither of which operations usually can be done very short. As this property is also very hard to see when looking at a number, we want this to be done for entire lists of numbers so we can save human work. So this is your challenge now!

This was an assignment at my university functional programming course. This assignment is now closed and has been discussed in class and I have my professor's permission to post it here (I asked explicitely).

Specification

Input

Your input is a list of non-negative integers, in any standard I/O format.

You may choose the list format as your language needs it

Output

The output is a list of integers, in any standard I/O format.

What to do?

Filter out every integer from the input list for which the sum of the digits is not a a square (of an integer).

The order of the elements may not be changed, e.g. if you get [1,5,9] you may not return [9,1]

Potential corner cases

0 is a non-negative integer and thus a valid input and 0 is also a valid integer root, e.g. 0 counts as an integer square.

The empty list is a valid input and output as well.

Who wins?

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

Standard rules apply of course.

Test Cases

```<code>[1,4,9,16,25,1111] -> [1,4,9,1111]
[1431,2,0,22,999999999] -> [1431,0,22,999999999]
[22228,4,113125,22345] -> [22228,4,22345]
[] -> []
[421337,99,123456789,1133557799] -> []
</code>```

Step-by-Step Example

```<code>Example input: [1337,4444]
Handling first number:
Sum of the digits of 1337: 1+3+3+7=14
14 is not an integer square, thus will be dropped!
Handling second number:
Sum of the digits of 4444: 4+4+4+4=16
16 is an integer square because 4*4=16, can get into the output list!
Example output: [4444]
</code>```

Body:
Jelly, <s>8</s> 7 bytes

1 byte thanks to @Sp3000.

DSÆ²ðÐf

Test suite.

Explanation

DSÆ²ðÐf  Main monadic chain. Argument: z

     Ðf  Filter for truthiness:
D            convert to base 10
 S           sum
  Æ²         is perfect square


答:
Javascript 66 bytes

```<code>a=>a.filter(b=>(e=Math.sqrt((b+"").split``.reduce((c,d)=>c-+-d)))==(e|0))
</code>```

Thanks for SergioFC for saving 7 bytes

Body:
Javascript 66 bytes

a=>a.filter(b=>(e=Math.sqrt((b+"").split``.reduce((c,d)=>c-+-d)))==(e|0))

Thanks for SergioFC for saving 7 bytes


答:
Pyth, 10 bytes

```<code>fsI@sjT;2Q
</code>```

Test suite.

Explanation

```<code>fsI@sjT;2Q

f        Q  Filter for the following in Q(input):
     jT;        convert to base 10
    s           sum
   @    2       square-root
 sI             is integer (is invariant under flooring)
</code>```

Body:
Pyth, 10 bytes

fsI@sjT;2Q

Test suite.

Explanation

fsI@sjT;2Q

f        Q  Filter for the following in Q(input):
     jT;        convert to base 10
    s           sum
   @    2       square-root
 sI             is integer (is invariant under flooring)


答:
F#, 78 bytes

```<code>function
|[]->None
|x->Seq.forall(fun y->Seq.length y=Seq.length x.[0])x|>Some
</code>```

Output is the F# Option type. If the input is empty output is None, else it's Some bool, where the bool value indicates whether all the sub-arrays are of equal length.

```<code>// F# Interactive
let f =
    function
    |[]->None
    |x->Seq.forall(fun y->Seq.length y=Seq.length x.[0])x|>Some;;

val f : _arg1:#seq<'b> list -> bool option

> f [[0;1];[2];[3]];;
val it : bool option = Some false
> f [[0;1];[2;3];];;
val it : bool option = Some true
> f [];;
val it : bool option = None
</code>```

Title: Same length sub arrays

Body:
Background:

Here's a little simple challenge. You want to be able to find out whether the arrays inside an array have the same length.

Input:

Your input should consist of exactly one array (this is the value passed to the function, not a user input). Your function takes exactly 1 parameter.  It could contain arrays or be empty. No error checking needed, assume only list is ever passed in. Assume a 1-D array such as [1] or [1,2,3,4,5] is never passed in.

Output:

Return true if all the list elements have the same length, false if they don't, and the parameter itself if the list is empty (or null if your language doesn't support multiple return types).

Some test cases:

```<code>List: [] - [] (or null/your language equivalent)
List: [[1], [1], [2]] - True
List: [[1]] - True
List: [[1, 2, 3, 4]] - True
List: [[1, 2, 3, 4, 5], [2], [12, 314123]] - False
List: [[1, 2, 3, 4], [1]] - False
</code>```

No std(in/out) input/output needed (however, it is allowed, just not required!), the function only needs to return boolean values true or false; or the parameter itself if the function is passed an empty list (or null/your language equivalent). Only one return value is returned.

Rules:

Shortest byte count wins, only function is necessary (full programs are allowed if you desire).

Body:
F#, 78 bytes

function
|[]->None
|x->Seq.forall(fun y->Seq.length y=Seq.length x.[0])x|>Some

Output is the F# Option type. If the input is empty output is None, else it's Some bool, where the bool value indicates whether all the sub-arrays are of equal length.

// F# Interactive
let f =
    function
    |[]->None
    |x->Seq.forall(fun y->Seq.length y=Seq.length x.[0])x|>Some;;

val f : _arg1:#seq<'b> list -> bool option

> f [[0;1];[2];[3]];;
val it : bool option = Some false
> f [[0;1];[2;3];];;
val it : bool option = Some true
> f [];;
val it : bool option = None


答:
CJam, 14 bytes

Thanks to @FryAmTheEggman for saving one byte!

```<code>{{Ab:+mq_i=},}
</code>```

Try it online!

This is an unnamed block that expects the input list on the stack and leaves the filtered list on it.

Explanation

```
{    e# start a new block
 Ab  e# convert to base 10 -> split number into digits
 :+  e# sum th digits
 mq  e# get the square root
 _   e# duplicate the result
 i   e# convert to integer
 =   e# check if the converted square root and the original one are equal
}    e# end block
,    e# filter the input list
```

Body:
CJam, 14 bytes

Thanks to @FryAmTheEggman for saving one byte!

{{Ab:+mq_i=},}

Try it online!

This is an unnamed block that expects the input list on the stack and leaves the filtered list on it.

Explanation

{    e# start a new block
 Ab  e# convert to base 10 -> split number into digits
 :+  e# sum th digits
 mq  e# get the square root
 _   e# duplicate the result
 i   e# convert to integer
 =   e# check if the converted square root and the original one are equal
}    e# end block
,    e# filter the input list


答:
PowerShell, <s>64</s> 54 bytes

$args|?{!([math]::Sqrt(([char[]]"$_"-join'+'|iex))%1)}
```

<p>Try it online!</p>

<p><em>-10 bytes thanks to mazzy</em></p>

<p>Takes input as command-line arguments (see examples below), which gets processed in PowerShell into the array <code>$args</code>. We pipe that to <code>?</code> an alias for <code>Where-Object</code> (functions similar to <code>filter</code>) in order to select our output. Our selection is based on the .NET call <code>[math]::Sqrt()</code> of the digit-sum of the number is an integer with <code>!(...%1)</code>. Integers will result in 0, which when <code>not</code>ed becomes <code>True</code> while non-integer roots become <code>False</code>.</p>

<p>As mentioned elsewhere "returning" an empty array is meaningless, as it's converted to <code>$null</code> as soon as it leaves scope, so the output for an empty input is nothing.</p>

<h3>Examples</h3>

<pre class="lang-powershell prettyprint-override"><code>PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1 1 4 9 16 25 1111
1
4
9
1111

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1 1431 2 0 22 999999999
1431
0
22
999999999

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1 22228 4 113125 22345
22228
4
22345

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1 1337 4444
4444
</code>```

Body:
PowerShell, <s>64</s> 54 bytes

$args|?{!([math]::Sqrt(([char[]]"$_"-join'+'|iex))%1)}

Try it online!

-10 bytes thanks to mazzy

Takes input as command-line arguments (see examples below), which gets processed in PowerShell into the array $args. We pipe that to ? an alias for Where-Object (functions similar to filter) in order to select our output. Our selection is based on the .NET call [math]::Sqrt() of the digit-sum of the number is an integer with !(...%1). Integers will result in 0, which when noted becomes True while non-integer roots become False.

As mentioned elsewhere "returning" an empty array is meaningless, as it's converted to $null as soon as it leaves scope, so the output for an empty input is nothing.

Examples

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1 1 4 9 16 25 1111
1
4
9
1111

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1 1431 2 0 22 999999999
1431
0
22
999999999

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1 22228 4 113125 22345
22228
4
22345

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1

PS C:\Tools\Scripts\golfing> .\return-integers-with-square-digit-sums.ps1 1337 4444
4444


答:
05AB1E, <s>19</s> 10 bytes

```<code>vySOtDï->—
</code>```

Explanation

```<code>vy                     # for each int in list
  SO                   # digit sum
    tDï-               # difference between sqrt() and int(sqrt())
        >              # increase by 1 giving 1 (true) when equal
         —             # print current int in list if truthy
</code>```

Try it online

Edit: Saved 9 bytes thanks to @Adnan

Body:
05AB1E, <s>19</s> 10 bytes

vySOtDï->—

Explanation

vy                     # for each int in list
  SO                   # digit sum
    tDï-               # difference between sqrt() and int(sqrt())
        >              # increase by 1 giving 1 (true) when equal
         —             # print current int in list if truthy

Try it online

Edit: Saved 9 bytes thanks to @Adnan


答:
J, <s>33</s> 27 bytes

6 bytes thanks to @miles.

```<code>#~[:(=<.)@%:+/"1@(10&#.inv)
</code>```

In online interpreters, inv is not instored. Change that to ^:_1 instead.

Usage

```<code>>> f =: #~[:(=<.)@%:+/"1@(10&#.inv)
>> f 1 4 9 16 25 1111 0
<< 1 4 9 1111 0
</code>```

Where >> is STDIN and << is STDOUT.

Slightly ungolfed

```<code>to_base_10 =: 10&#.^:_1
sum        =: +/"1
sqrt       =: %:
floor      =: <.
itself     =: ]
equals     =: =
of         =: @
is_integer =: equals floor
test       =: is_integer of sqrt
copies_of  =: #
f =: copies_of~ [: test (sum of to_base_10)
</code>```

Previous 33-byte version

```<code>(]=*:@<.@%:)@(+/"1@(10#.^:_1]))#]
</code>```

Usage

```<code>>> f =: (]=*:@<.@%:)@(+/"1@(10#.^:_1]))#]
>> f 1 4 9 16 25 1111 0
<< 1 4 9 1111 0
</code>```

Where >> is STDIN and << is STDOUT.

Slightly ungolfed

```<code>to_base_10 =: 10#.^:_1]
sum        =: +/"1
sqrt       =: %:
floor      =: <.
square     =: *:
itself     =: ]
equals     =: =
of         =: @
test       =: itself equals square of floor of sqrt
copies_of  =: #
f =: (test of (sum of to_base_10)) copies_of itself
</code>```

Body:
J, <s>33</s> 27 bytes

6 bytes thanks to @miles.

#~[:(=<.)@%:+/"1@(10&#.inv)

In online interpreters, inv is not instored. Change that to ^:_1 instead.

Usage

>> f =: #~[:(=<.)@%:+/"1@(10&#.inv)
>> f 1 4 9 16 25 1111 0
<< 1 4 9 1111 0

Where >> is STDIN and << is STDOUT.

Slightly ungolfed

to_base_10 =: 10&#.^:_1
sum        =: +/"1
sqrt       =: %:
floor      =: <.
itself     =: ]
equals     =: =
of         =: @
is_integer =: equals floor
test       =: is_integer of sqrt
copies_of  =: #
f =: copies_of~ [: test (sum of to_base_10)

Previous 33-byte version

(]=*:@<.@%:)@(+/"1@(10#.^:_1]))#]

Usage

>> f =: (]=*:@<.@%:)@(+/"1@(10#.^:_1]))#]
>> f 1 4 9 16 25 1111 0
<< 1 4 9 1111 0

Where >> is STDIN and << is STDOUT.

Slightly ungolfed

to_base_10 =: 10#.^:_1]
sum        =: +/"1
sqrt       =: %:
floor      =: <.
square     =: *:
itself     =: ]
equals     =: =
of         =: @
test       =: itself equals square of floor of sqrt
copies_of  =: #
f =: (test of (sum of to_base_10)) copies_of itself


问:
Count sum of all digits
This challenge is to write a program or script which counts the sum of all digits within the integers from 1 up to and including a given number.

Input, one positive integer.
Output, the sum of digits in that number and all smaller numbers.

Examples:

```<code>Input: 5
Integer Sequence: 1, 2, 3, 4, 5
Sum of Digits: 1 + 2 + 3 + 4 + 5 = 15

Input: 12
Integer Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12
Sum of Digits: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 0 + 1 + 1 + 1 + 2 = 51
</code>```

To be clear, this is to count a sum of the digits - not the integers. For single-digit inputs, this will be the same. However, inputs larger than 10 will have different responses. This would be an incorrect response:

```<code>Input: 12
Output: 78
</code>```

Another example, to show the difference:

```<code>Input: 10

Integer Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Sum of Integers (INCORRECT RESPONSE): 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 = 55

Digit Sequence: 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 0
Sum of Digits (CORRECT RESPONSE): 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 1 + 0 = 46
</code>```

A larger test case (CORRECT RESPONSE):

```<code>Input: 1000000
Output: 27000001
</code>```

Rules & Guidelines:

Submitted code must be a complete program or script - not just a function. If the code requires includes, imports, etc., they must be included in the posted code.

The number must be input by the user - not hard-coded. Input may be received as a command-line argument, file, stdin, or any other means by which your language can take user input.

The code must be able to properly handle inputs at least up to (2^64)-1.

The code should only output the sum.

Submitted programs & scripts should be user-friendly and not wasteful of computer resources (e.g.: they should not declare insanely-large arrays to hold every character). There is no strict bonus or penalty for this, but please be good programmers.

Scoring:

Primary scoring mechanism is by code length. Lower scores are better. The following bonuses and penalties also apply:

-25 Bonus if your code can handle all positive numbers, for example: 1234567891234567891234564789087414984894900000000

-50 Bonus if your code can handle simple expressions, for example 55*96-12. To qualify for this bonus, the code should handle + - / * (addition, subtraction, division, multiplication) operators and enforce order of operations. Division is regular integer division.

The given example (55*96-12) evaluates to 5268. Your code should return the same for either of those inputs - correct answer is 81393.

-10 Bonus if your code qualifies for the -50 bonus and can handle the ^ (exponent) operator.

-100 Bonus if your code qualifies for the -50 bonus and does not use eval or similar to handle expressions.

+300 Penalty if your code relies upon any web resources.

答:
Pyke, 4 - (50), -46 bytes, noncompeting

```<code>hmss
</code>```

Try it here!

Title: Count sum of all digits

Body:
Pyke, 4 - (50), -46 bytes, noncompeting

hmss

Try it here!


答:
MATL, <s>16</s> <s>14</s> 13 bytes

```<code>"@tV!UsX^1\?x
</code>```

Try it Online!

Explanation

```<code>        % Implicitly grab input
"       % For each number in the input
  @t    % Get this element and duplicate
  V     % Convert to it's string representation
  !     % Transpose the string so each digit is on it's own row
  U     % Convert each row to a number (separates the digits)
  s     % Compute the sum of the digits
  X^    % Compute the square root
  1\    % mod with 1 to determine if the square root is an integer
  ?x    % If there is a remainder, then remove this element from the stack
        % Implicitly display the stack contents

</code>```

Body:
MATL, <s>16</s> <s>14</s> 13 bytes

"@tV!UsX^1\?x

Try it Online!

Explanation

        % Implicitly grab input
"       % For each number in the input
  @t    % Get this element and duplicate
  V     % Convert to it's string representation
  !     % Transpose the string so each digit is on it's own row
  U     % Convert each row to a number (separates the digits)
  s     % Compute the sum of the digits
  X^    % Compute the square root
  1\    % mod with 1 to determine if the square root is an integer
  ?x    % If there is a remainder, then remove this element from the stack
        % Implicitly display the stack contents


答:
Python 2, 76 bytes

lambda l:filter(lambda n:eval(("sum(map(int,`n`))**.5==int("*2)[:-6]+")"),l)
```

Try it here!

Some abuse of eval to check for a square number, rest is pretty unspectacular.

The eval statement evaluates to sum(map(int,n))**.5==int(sum(map(int,n))**.5)

Body:
Python 2, 76 bytes

lambda l:filter(lambda n:eval(("sum(map(int,`n`))**.5==int("*2)[:-6]+")"),l)

Try it here!

Some abuse of eval to check for a square number, rest is pretty unspectacular.

The eval statement evaluates to sum(map(int,n))**.5==int(sum(map(int,n))**.5)


答:
Oracle SQL 11.2, 213 bytes

WITH v AS(SELECT a,SQRT(XMLQUERY(REGEXP_REPLACE(a,'(\d)','+\1')RETURNING CONTENT).GETNUMBERVAL())s FROM(SELECT TRIM(COLUMN_VALUE)a FROM XMLTABLE(('"'||REPLACE(:1,',','","')||'"'))))SELECT a FROM v WHERE s=CEIL(s);
```

<p>Un-golfed  </p>

<pre class="lang-sql prettyprint-override"><code>WITH v AS
(
  SELECT a,SQRT(XMLQUERY(
                   REGEXP_REPLACE(a,'(\d)','+\1')  -- Add a + in front of each digit
                   RETURNING CONTENT
               ).GETNUMBERVAL())s                  -- Evaluate the expression generated by the added +
  FROM
  (SELECT TRIM(COLUMN_VALUE)a FROM XMLTABLE(('"'||REPLACE(:1,',','","')||'"'))) -- Split string on ','
)
SELECT a FROM v WHERE s=CEIL(s) -- Is a square if square has no decimal part
</code>```

Body:
Oracle SQL 11.2, 213 bytes

WITH v AS(SELECT a,SQRT(XMLQUERY(REGEXP_REPLACE(a,'(\d)','+\1')RETURNING CONTENT).GETNUMBERVAL())s FROM(SELECT TRIM(COLUMN_VALUE)a FROM XMLTABLE(('"'||REPLACE(:1,',','","')||'"'))))SELECT a FROM v WHERE s=CEIL(s);

Un-golfed

WITH v AS
(
  SELECT a,SQRT(XMLQUERY(
                   REGEXP_REPLACE(a,'(\d)','+\1')  -- Add a + in front of each digit
                   RETURNING CONTENT
               ).GETNUMBERVAL())s                  -- Evaluate the expression generated by the added +
  FROM
  (SELECT TRIM(COLUMN_VALUE)a FROM XMLTABLE(('"'||REPLACE(:1,',','","')||'"'))) -- Split string on ','
)
SELECT a FROM v WHERE s=CEIL(s) -- Is a square if square has no decimal part


答:
Brachylog, 26 bytes

```<code>:1f.
e.(:ef+~^[X:2]h>0;.0)
</code>```

Example:

```<code>?- run_from_file('code.brachylog',[1431:2:0:22:999999999],Z).
Z = [1431, 0, 22, 999999999]
</code>```

Explanation

This is a situation where something works a bit too well... the ~^[X:2] part is true for both positive and negative X, so to avoid duplicates I have to specify that X > 0.

The ;.0 part is here due to a bug (enumerate doesn't work on the integer 0).

Main predicate

```<code>:1f.                Find all values of Input which satisfy predicate 1
</code>```

Predicate 1

```<code>e.                  Unify output with an element of the input
(
  :ef               Find all elements of Output (i.e. all digits)
     +              Sum the digits
      ~^[X:2]       True if that sum is the result of X², whatever X is
             h>0    Impose that X > 0
;                   OR
  .0                True if Output is 0
)
</code>```

Body:
Brachylog, 26 bytes

:1f.
e.(:ef+~^[X:2]h>0;.0)

Example:

?- run_from_file('code.brachylog',[1431:2:0:22:999999999],Z).
Z = [1431, 0, 22, 999999999]

Explanation

This is a situation where something works a bit too well... the ~^[X:2] part is true for both positive and negative X, so to avoid duplicates I have to specify that X > 0.

The ;.0 part is here due to a bug (enumerate doesn't work on the integer 0).

Main predicate

:1f.                Find all values of Input which satisfy predicate 1

Predicate 1

e.                  Unify output with an element of the input
(
  :ef               Find all elements of Output (i.e. all digits)
     +              Sum the digits
      ~^[X:2]       True if that sum is the result of X², whatever X is
             h>0    Impose that X > 0
;                   OR
  .0                True if Output is 0
)


问:
Don't google "google"
We all know that if you google the word "google" it will break the internet.

Your task is to create a function that accepts one string and returns its length, in the fewest possible Unicode characters.

However, if the given string is google (lowercase), it will cause an error.

For example, g('bing') will return 4 but g('google') will cause an error.

Please provide an example of usage, and the error if possible.

答:
C++, 77 Bytes

```<code>#include <string>
int G(std::string S){1/int(S!="google");return S.length();}
</code>```

Title: Don't google "google"

Body:
C++, 77 Bytes

#include <string>
int G(std::string S){1/int(S!="google");return S.length();}


答:
q - 53 characters

{x where({(sum({"J"$x}')($:)x)in((!:)x+1)*(!:)x+1}')x}

The interesting bit is the inner lambda, which casts to a string, sums the digit (by casting each of them to an int), and then checks if they are a in a list of squares.