答:
Perl 6, 25 bytes

{.sum*3-.[0]-(.[*-1]//0)}    # generates warning
{+$_&&.sum*3-.[0]-.[*-1]}
```

<h2>Expanded:</h2>

<pre class="lang-perl6 prettyprint-override"><code># bare block lambda with implicit parameter ｢$_｣
{
  +$_        # the number of elements

  &&         # if that is 0 return 0, otherwise return the following

  .sum * 3   # sum them up and multiply by 3
  - .[ 0 ]   # subtract the first value
  - .[*-1]   # subtract the last value
}
</code>```

Test:

use v6.c;
use Test;

my &code = {+$_&&.sum*3-.[0]-.[*-1]}

my @tests = (
  []            => 0,
  [1]           => 1,
  [1,4]         => 10,
  [1,4,7]       => 28,
  [1,4,7,10]    => 55,
  [-1,-2,-3]    => -14,
  [0.1,0.2,0.3] => 1.4,
  [1,-20,300,-4000,50000,-600000,7000000] => 12338842,
);

plan +@tests;

for @tests -> $_ ( :key(@input), :value($expected) ) {
  is code(@input), $expected, .gist;
}
```

Title: Sum of neighbours

Body:
This should be a fairly simple challenge.

For an array of numbers, generate an array where for every element all neighbouring elements are added to itself, and return the sum of that array.

Here is the transformation which occurs on the input array [1,2,3,4,5]

```<code>[1,2,3,4,5] => [1+2, 2+1+3, 3+2+4, 4+3+5, 5+4] => [3,6,9,12,9] => 39
 0          => neighbours of item 0, including item 0
[1,2]       => 1 + 2      => 3
   1
[1,2,3]     => 1 + 2 + 3  => 6
     2
  [2,3,4]   => 2 + 3 + 4  => 9
       3
    [3,4,5] => 3 + 4 + 5  => 12
         4
      [4,5] => 4 + 5      => 9

               3+6+9+12+9 => 39
</code>```

Test cases

```<code>[]            => 0 (or falsy)
[1]           => 1
[1,4]         => 10 (1+4 + 4+1)
[1,4,7]       => 28
[1,4,7,10]    => 55
[-1,-2,-3]    => -14
[0.1,0.2,0.3] => 1.4
[1,-20,300,-4000,50000,-600000,7000000] => 12338842
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Perl 6, 25 bytes

{.sum*3-.[0]-(.[*-1]//0)}    # generates warning
{+$_&&.sum*3-.[0]-.[*-1]}

Expanded:

# bare block lambda with implicit parameter ｢$_｣
{
  +$_        # the number of elements

  &&         # if that is 0 return 0, otherwise return the following

  .sum * 3   # sum them up and multiply by 3
  - .[ 0 ]   # subtract the first value
  - .[*-1]   # subtract the last value
}

Test:

use v6.c;
use Test;

my &code = {+$_&&.sum*3-.[0]-.[*-1]}

my @tests = (
  []            => 0,
  [1]           => 1,
  [1,4]         => 10,
  [1,4,7]       => 28,
  [1,4,7,10]    => 55,
  [-1,-2,-3]    => -14,
  [0.1,0.2,0.3] => 1.4,
  [1,-20,300,-4000,50000,-600000,7000000] => 12338842,
);

plan +@tests;

for @tests -> $_ ( :key(@input), :value($expected) ) {
  is code(@input), $expected, .gist;
}


问:
Determine if a coin system is Canonical
The Cashier's Algorithm is an algorithm for making change in the minimal number of coins that works quite well for most currency systems.  However like most greedy algorithms it is not without its flaws.  If a currency system is set up just right (or just wrong) there are certain values in which the Cashier's Algorithm will fail to find the optimal change.

Take the following example:

We have 4¢, 3¢, and 1¢ coins.  We want to make 6¢.

The Cashier's Algorithm will first select as many of the largest coin (one 4¢ to start) and subtract and repeat.  This will result in one 4¢ coin and two 1¢ coins, for a total of 3 coins.

Unfortunately for the Algorithm there is a way to make 6¢ with only two coins (two 3¢ coins).

A system of change will be considered canonical iff for all integer values the Cashier's Algorithm will find the optimal number of coins.

Task

You task will be to take a system as a either an unordered container or sorted ordered container of integers representing coin values and output a truthy value if the system input is canonical and falsy otherwise.

Your program should work for all systems that can create any value.  (i.e. all systems will have a 1¢ coin)

This is code golf least bytes wins.

Test cases

This list is by no means exhaustive, your program should work for all valid input

```<code>1, 3, 4       -> 0
1, 5, 10, 25  -> 1
1, 6, 10, 25  -> 0
1, 2, 3       -> 1
1, 8, 17, 30  -> 0
1, 3, 8, 12   -> 0
1, 2, 8, 13   -> 0
1, 2, 4, 6, 8 -> 1
</code>```

答:
Jelly (fork), <s>15</s> 14 bytes

```<code>SRæFµS€Ṃ=$Ṫµ€Ȧ
</code>```

This solution uses the bounds for counter-examples from this paper. There, the author uses a tight bound for the counter-example, but in the interests of golfing, the range of the sum of coin denominations is used which is larger and contains that bound.

This program computes all test cases in less than a second on my machine.

Unfortunately, this relies on a branch of Jelly where I was working on implementing a Frobenius solve atom so you cannot try it online.

Usage

```<code>$ ./jelly eun 'SRæFµS€Ṃ=$Ṫµ€Ȧ' '1,2,4,6,8'
1
</code>```

The performance is good and can solve all test cases at once in less than a second.

```<code>$ time ./jelly eun 'SRæFµS€Ṃ=$Ṫµ€Ȧ¶Ç€' '[[1,3,4],[1,5,10,25],[1,6,10,25],[1,2,3],[1,8,17,30],[1,3,8,12],[1,2,8,13],[1,2,4,6,8]]'
[0, 1, 0, 1, 0, 0, 0, 1]

real    0m0.793s
user    0m0.748s
sys     0m0.045s
</code>```

Explanation

```<code>SRæFµS€Ṃ=$Ṫµ€Ȧ  Input: list of integers C
    µ           Start a new monadic chain
S                 Sum
 R                Range, [1, 2, ..., sum(C)]
  æF              Frobenius solve for each X in the range using coefficients from C
                  This generates all vectors where the dot product of a
                  vector with C equals X, ordered by using values from the
                  start to end of C
           µ€   Start a new monadic chain that operates on each list of vectors
     S€           Sum each vector
         $        Monadic hook on the sums
       Ṃ            Minimum (This is the optimal solution)
        =           Vectorized equals, 1 if true else 0
          Ṫ       Tail (This is at the index of the greedy solution)
             Ȧ  All, returns 0 if it contains a falsey value, else 1
</code>```

ContentLicense: CC BY-SA 3.0

Title: Determine if a coin system is Canonical

Body:
Jelly (fork), <s>15</s> 14 bytes

SRæFµS€Ṃ=$Ṫµ€Ȧ

This solution uses the bounds for counter-examples from this paper. There, the author uses a tight bound for the counter-example, but in the interests of golfing, the range of the sum of coin denominations is used which is larger and contains that bound.

This program computes all test cases in less than a second on my machine.

Unfortunately, this relies on a branch of Jelly where I was working on implementing a Frobenius solve atom so you cannot try it online.

Usage

$ ./jelly eun 'SRæFµS€Ṃ=$Ṫµ€Ȧ' '1,2,4,6,8'
1

The performance is good and can solve all test cases at once in less than a second.

$ time ./jelly eun 'SRæFµS€Ṃ=$Ṫµ€Ȧ¶Ç€' '[[1,3,4],[1,5,10,25],[1,6,10,25],[1,2,3],[1,8,17,30],[1,3,8,12],[1,2,8,13],[1,2,4,6,8]]'
[0, 1, 0, 1, 0, 0, 0, 1]

real    0m0.793s
user    0m0.748s
sys     0m0.045s

Explanation

SRæFµS€Ṃ=$Ṫµ€Ȧ  Input: list of integers C
    µ           Start a new monadic chain
S                 Sum
 R                Range, [1, 2, ..., sum(C)]
  æF              Frobenius solve for each X in the range using coefficients from C
                  This generates all vectors where the dot product of a
                  vector with C equals X, ordered by using values from the
                  start to end of C
           µ€   Start a new monadic chain that operates on each list of vectors
     S€           Sum each vector
         $        Monadic hook on the sums
       Ṃ            Minimum (This is the optimal solution)
        =           Vectorized equals, 1 if true else 0
          Ṫ       Tail (This is at the index of the greedy solution)
             Ȧ  All, returns 0 if it contains a falsey value, else 1


问:
Digital Diversity
A positive integer may be represented in an integer base \$1 \le b < \infty\$.

When converted to that base it has some number of distinct digits.

Any positive integer in base \$1\$ has \$1\$ distinct digit.

Most positive integers in base \$2\$ have \$2\$ distinct digits, the exceptions being those of the form \$2^n - 1\$, which only have \$1\$.

So the first positive integer that may be represented in an integer base with \$1\$ unique digit is \$1\$ and the first that may be represented with \$2\$ distinct digits is \$2\$.

We can say that \$1\$ is the first integer with digital diversity \$1\$ and \$2\$ is the first integer with digital diversity \$2\$.

Challenge:

Given a positive integer \$n\$ return the first positive integer (in base ten*) that has a digital diversity of \$n\$.

* if your language only supports a specific base (e.g. unary or binary) then you may output in that base.

Your algorithm must work in theory for any positive integer input: it may fail because the precision of your language's integer is too small for the output; but may not fail because base conversion is only defined up to some limit.

Test cases

```<code>input  output
   1     1
   2     2
   3     11
   4     75
   5     694
   6     8345
   7     123717
  17     49030176097150555672
  20     5271200265927977839335179
  35     31553934355853606735562426636407089783813301667210139
  63     3625251781415299613726919161860178255907794200133329465833974783321623703779312895623049180230543882191649073441
 257     87678437238928144977867204156371666030574491195943247606217411725999221158137320290311206746021269051905957869964398955543865645836750532964676103309118517901711628268617642190891105089936701834562621017362909185346834491214407969530898724148629372941508591337423558645926764610261822387781382563338079572769909101879401794746607730261119588219922573912353523976018472514396317057486257150092160745928604277707892487794747938484196105308022626085969393774316283689089561353458798878282422725100360693093282006215082783023264045094700028196975508236300153490495688610733745982183150355962887110565055971546946484175232
</code>```

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

OEIS: A049363 - also smallest pandigital number in base n.

答:
05AB1E, 9 bytes

```<code>DL¦¨v¹*y+
</code>```

Try it online!

Explanation

n = 4 used for example.

```<code>D           # duplicate input
            # STACK: 4, 4
 L          # range(1, a)
            # STACK: 4, [1,2,3,4]
  ¦¨        # remove first and last element of list
            # STACK: 4, [2,3]
    v       # for each y in list
     ¹*     # multiply current stack with input
       y+   # and add y
            # STACK, first pass: 4*4+2 = 18
            # STACK, second pass: 18*4+3 = 75
</code>```

ContentLicense: CC BY-SA 4.0

Title: Digital Diversity

Body:
05AB1E, 9 bytes

DL¦¨v¹*y+

Try it online!

Explanation

n = 4 used for example.

D           # duplicate input
            # STACK: 4, 4
 L          # range(1, a)
            # STACK: 4, [1,2,3,4]
  ¦¨        # remove first and last element of list
            # STACK: 4, [2,3]
    v       # for each y in list
     ¹*     # multiply current stack with input
       y+   # and add y
            # STACK, first pass: 4*4+2 = 18
            # STACK, second pass: 18*4+3 = 75


问:
Appease Your Google Overlords: Draw the "G" Logo
Write a program or function that takes in a positive integer N, and outputs an N×N pixel image of Google's "G" logo according to this* construction:

For example, if N is 400, a 400×400 pixel logo should be output, with correct dimensions and colors:

It should look accurate regardless of how large or small N is. e.g. here is N = 13:

Your code should not need to connect to the internet. For example, scaling an externally hosted svg is not allowed. (Scaling an svg encoded in your code would be fine though.)

Anti-aliasing may be used or not. It's up to you.

Notice that the horizontal bar of the "G" does not extend all the way to the right edge of the image. The circle curves normally inward on the right edge before it is cut off.

The shortest code in bytes wins.

* The construction of the logo has been simplified for this challenge. The correct construction can be seen here and here.

答:
Java, 568 bytes

Not the strongest language for golfing, but here is my earnest attempt:

import java.awt.image.*;class G{public static void main(String[]b)throws Exception{int n=Integer.parseInt(b[0]),x,y,a,c;BufferedImage p=new BufferedImage(n,n,BufferedImage.TYPE_INT_RGB);for(y=0;y<n;y++){for(x=0;x<n;x++){double u=(x+.5)/n-.5,v=.5-(y+.5)/n,r=Math.hypot(u,v);a=(int)(Math.atan2(v,u)*4/Math.PI);c=0xFFFFFF;if(0<u&u<.4&-.1<v&v<.1)c=0x4285F4;else if(r<.3|r>.5);else if(a==0&v<.1)c=0x4285F4;else if(a==1|a==2)c=0xEA4335;else if(a==-1|a==-2)c=0x34A853;else if(a!=0)c=0xFBBC05;p.setRGB(x,y,c);}}javax.imageio.ImageIO.write(p,"png",new java.io.File("G.png"));}}
```

<p>Usage:</p>

```> javac G.java
--> Compiles to G.class
> java G 400
--> Writes G.png in current working directory
```

<p>Un-golfed version - the basic idea is to work in the coordinate system u, v ∈ [−0.5, 0.5] and calculate the distance and angle of each pixel from the image center:</p>

<pre class="lang-java prettyprint-override"><code>import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Google {

    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(args[0]);
        int[] pixels = new int[n * n];

        for (int y = 0; y < n; y++) {
            for (int x = 0; x < n; x++) {
                double u = (x + 0.5) / n - 0.5;
                double v = 0.5 - (y + 0.5) / n;
                double r = Math.hypot(u, v);
                int a = (int)(Math.atan2(v, u) * 4 / Math.PI);
                int c = 0xFFFFFF;
                if (0 < u && u < 0.4 && Math.abs(v) < 0.1)
                    c = 0x4285F4;
                else if (r < 0.3 || r > 0.5)
                    /*empty*/;
                else if (a == 0 && v < 0.1)
                    c = 0x4285F4;
                else if (a == 1 || a == 2)
                    c = 0xEA4335;
                else if (a == -1 || a == -2)
                    c = 0x34A853;
                else if (a != 0)
                    c = 0xFBBC05;
                pixels[y * n + x] = c;
            }
        }

        BufferedImage image = new BufferedImage(n, n, BufferedImage.TYPE_INT_RGB);
        image.setRGB(0, 0, n, n, pixels, 0, n);
        ImageIO.write(image, "png", new File("G.png"));
    }

}
</code>```

My implementation computes and draws raw pixels. It is possible to create an alternative implementation that uses high-level graphics routines like Graphics2D and Arc2D to do the drawing, especially with anti-aliasing.

Body:
Java, 568 bytes

Not the strongest language for golfing, but here is my earnest attempt:

import java.awt.image.*;class G{public static void main(String[]b)throws Exception{int n=Integer.parseInt(b[0]),x,y,a,c;BufferedImage p=new BufferedImage(n,n,BufferedImage.TYPE_INT_RGB);for(y=0;y<n;y++){for(x=0;x<n;x++){double u=(x+.5)/n-.5,v=.5-(y+.5)/n,r=Math.hypot(u,v);a=(int)(Math.atan2(v,u)*4/Math.PI);c=0xFFFFFF;if(0<u&u<.4&-.1<v&v<.1)c=0x4285F4;else if(r<.3|r>.5);else if(a==0&v<.1)c=0x4285F4;else if(a==1|a==2)c=0xEA4335;else if(a==-1|a==-2)c=0x34A853;else if(a!=0)c=0xFBBC05;p.setRGB(x,y,c);}}javax.imageio.ImageIO.write(p,"png",new java.io.File("G.png"));}}

Usage:

> javac G.java
--> Compiles to G.class
> java G 400
--> Writes G.png in current working directory

Un-golfed version - the basic idea is to work in the coordinate system u, v ∈ [−0.5, 0.5] and calculate the distance and angle of each pixel from the image center:

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Google {

    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(args[0]);
        int[] pixels = new int[n * n];

        for (int y = 0; y < n; y++) {
            for (int x = 0; x < n; x++) {
                double u = (x + 0.5) / n - 0.5;
                double v = 0.5 - (y + 0.5) / n;
                double r = Math.hypot(u, v);
                int a = (int)(Math.atan2(v, u) * 4 / Math.PI);
                int c = 0xFFFFFF;
                if (0 < u && u < 0.4 && Math.abs(v) < 0.1)
                    c = 0x4285F4;
                else if (r < 0.3 || r > 0.5)
                    /*empty*/;
                else if (a == 0 && v < 0.1)
                    c = 0x4285F4;
                else if (a == 1 || a == 2)
                    c = 0xEA4335;
                else if (a == -1 || a == -2)
                    c = 0x34A853;
                else if (a != 0)
                    c = 0xFBBC05;
                pixels[y * n + x] = c;
            }
        }

        BufferedImage image = new BufferedImage(n, n, BufferedImage.TYPE_INT_RGB);
        image.setRGB(0, 0, n, n, pixels, 0, n);
        ImageIO.write(image, "png", new File("G.png"));
    }

}

My implementation computes and draws raw pixels. It is possible to create an alternative implementation that uses high-level graphics routines like Graphics2D and Arc2D to do the drawing, especially with anti-aliasing.


问:
Sum of neighbours
This should be a fairly simple challenge.

For an array of numbers, generate an array where for every element all neighbouring elements are added to itself, and return the sum of that array.

Here is the transformation which occurs on the input array [1,2,3,4,5]

```<code>[1,2,3,4,5] => [1+2, 2+1+3, 3+2+4, 4+3+5, 5+4] => [3,6,9,12,9] => 39
 0          => neighbours of item 0, including item 0
[1,2]       => 1 + 2      => 3
   1
[1,2,3]     => 1 + 2 + 3  => 6
     2
  [2,3,4]   => 2 + 3 + 4  => 9
       3
    [3,4,5] => 3 + 4 + 5  => 12
         4
      [4,5] => 4 + 5      => 9

               3+6+9+12+9 => 39
</code>```

Test cases

```<code>[]            => 0 (or falsy)
[1]           => 1
[1,4]         => 10 (1+4 + 4+1)
[1,4,7]       => 28
[1,4,7,10]    => 55
[-1,-2,-3]    => -14
[0.1,0.2,0.3] => 1.4
[1,-20,300,-4000,50000,-600000,7000000] => 12338842
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Haskell, 25 bytes

From fastest

```<code>sum.sequence[(0-).head,(3*).sum,(0-).last]$[1..5]
</code>```

via prettiest

```<code>sum.sequence[sum.init,sum,sum.tail]$[1..5]
</code>```

down to ugliest but shortest

```<code>let y x=sum$init x++x++tail x in y[1..5]
--  1234567890123456789012345
</code>```

Title: Sum of neighbours

Body:
Haskell, 25 bytes

From fastest

sum.sequence[(0-).head,(3*).sum,(0-).last]$[1..5]

via prettiest

sum.sequence[sum.init,sum,sum.tail]$[1..5]

down to ugliest but shortest

let y x=sum$init x++x++tail x in y[1..5]
--  1234567890123456789012345


问:
Exploded Suffixes
Given an ASCII string, output the exploded suffixes of it. For example, if the string was abcde, there are 5 suffixes, ordered longest to shortest:

```<code>abcde
bcde
cde
de
e
</code>```

Each suffix is then exploded, meaning each character is copied as many times as its one-indexed location in that suffix. For example, exploding the suffixes of abcde,

```<code>abcde
12345
abbcccddddeeeee

bcde
1234
bccdddeeee

cde
123
cddeee

de
12
dee

e
1
e
</code>```

Altogether, the exploded suffixes of abcde are

```<code>abbcccddddeeeee
bccdddeeee
cddeee
dee
e
</code>```

Rules

This is code-golf so the shortest code wins.

The input will consist of the printable ASCII characters. (This excludes newlines but includes spaces.)

The output will have each string on a separate line.

Trailing spaces are allowed on each line and there may be an extra newline at the end.

Test Cases

```<code>''

'a'
a

'bc'
bcc
c

'xyz'
xyyzzz
yzz
z

'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f

's p a c e'
s  ppp    aaaaa      ccccccc        eeeeeeeee
 pp   aaaa     cccccc       eeeeeeee
p  aaa    ccccc      eeeeeee
 aa   cccc     eeeeee
a  ccc    eeeee
 cc   eeee
c  eee
 ee
e
</code>```

答:
Jelly, 5 bytes

```<code>ṫJxJY
</code>```

Try it online! or verify all test cases.

How it works

```<code>ṫJxJY  Main link. Argument: s (string)

 J     Indices; yield I := [1, ..., len(s)].
ṫ      Tail; get the suffixes of s starting at indices [1, ..., len(s)].
   J   Indices; yield I again.
  x    Repeat. The atom 'x' vectorizes at depth 1 (1D arrays of numbers/characters)
       in its arguments. This way, each suffix t gets repeated I times, meaning
       that the first character of t is repeated once, the second twice, etc.
       If left and right argument have different lengths, the longer one is
       truncated, so I can safely be applied to all suffixes.
    Y  Join, separating by linefeeds.
</code>```

Title: Exploded Suffixes

Body:
Jelly, 5 bytes

ṫJxJY

Try it online! or verify all test cases.

How it works

ṫJxJY  Main link. Argument: s (string)

 J     Indices; yield I := [1, ..., len(s)].
ṫ      Tail; get the suffixes of s starting at indices [1, ..., len(s)].
   J   Indices; yield I again.
  x    Repeat. The atom 'x' vectorizes at depth 1 (1D arrays of numbers/characters)
       in its arguments. This way, each suffix t gets repeated I times, meaning
       that the first character of t is repeated once, the second twice, etc.
       If left and right argument have different lengths, the longer one is
       truncated, so I can safely be applied to all suffixes.
    Y  Join, separating by linefeeds.


问:
Help me with my Halloween decoration
The Halloween is upon us, and I haven't decorated my house yet, so I gonna need your help to do this task

Input

The input will be a list of 4 digits numbers, where each digit represent a portion of decoration:

```<code>EMBU
||||
|||+-upper decoration
||+-bottom decoration
|+-mouth/nose
+-eyes
</code>```

Eyes:

0 - °

1 - ¯

2 - -

3 - ^

4 - '

Mouth/Nose

0 - v

1 - w

2 - o

3 - _

4 - -

Bottom decoration

0 - nothing

1 - skeleton

2 - pumpkin

Upper decoration

0 - nothing

1 - flying bat

2 - resting bat

3 - spider

Output

Skeleton:

(EME)

 _|_

/[|]\

  |

 / \

Pumpkin

  ,

(EME)

Flying bat

 ^"^

Resting bat

  ()

  ´`

Spider

  |

 .|.

 :":

Each decoration has a 5 character width

Upper decorations start from the top

Lower decorations start from the bottom

If the spider is over the pumpkin or there is no bottom decoration the web length will be 3, if it's over the skeleton, the web length will be 1

When the bottom decoration is 0 the first 2 digits are irrelevant

Between each decoration there will be an empty column

Example

Input

3123 ??02 1021 0310

Output

```<code>   |     ()
   |     ´`   ^"^
  .|.              (°_°)
  :":               _|_
                   /[|]\
   ,           ,     |
 (^w^)       (¯v¯)  / \
</code>```

Trailing spaces at the end of each line are optional

Trailing newline at the end of the entire output is allowed

Winning criteria

This is code-golf so the shortest answer wins

答:
Ruby 2.3.1, 777 752 bytes

Edit_0: I totally missed out on some golfable variable usage and some other stuff.

```<code>@o=Array.new;$*.each_with_index do|j,i|a,e,n,b,u,q,r,z,y=0,j[0].to_i,j[1].to_i,j[2].to_i,j[3].to_i,['°','¯','-','^',"'"],['v','w','o','_',"-"],Array.new(7," "),"     ";g,h=[z,["(#{q[e]}#{r[n]}#{q[e]})"," _|_ ","/[|]\\","  |  "," / \\ "],["     ","  ,  ","(#{q[e]}#{r[n]}#{q[e]})"]],[z,["     "," ^\"^ "],["  () ", "  ´` "],[" .|. "," :\": "]];2.times{h[3].unshift("  |  ")}unless b==1;if b<1 && u<1;@o.push(z);elsif b<1;u<3 ? (a=5):(a=3);a.times{h[u].push(y)};@o.push(h[u]);elsif u<1;b==1 ? (a=2):(a=4);a.times{g[b].unshift(y)};@o.push(g[b]);elsif u>0;2.times{h[u].push(y)}if u<3&&b>1;@o.push(h[u]+g[b]);end;@o.push(z);end;@o.transpose.each do|v|;v.each do |w|;print w;end;print"\n";end
</code>```

Takes in N number of variables of decorations. There's certainly some more golfing that can be done with this. I'm not that familiar with a lot of Ruby's tricks, but here's a shot at it! I'm also happy at being able to solve it.

Un-golfed

```<code>@output = Array.new
$*.each_with_index do |j, i|
  # output decoration combo
  s = 0

  # set up vars for decoration input
  e = j[0].to_i
  n = j[1].to_i
  b = j[2].to_i
  u = j[3].to_i

  # Setup decorations/misc
  eyes = ['°','¯','-','^',"'"]
  nose = ['v','w','o','_',"-"]
  nothing = Array.new(7, " ")
  skeleton = ["(#{eyes[e]}#{nose[n]}#{eyes[e]})", " _|_ ", "/[|]\\", "  |  ", " / \\ "]
  pumpkin = ["     ", "  ,  ", "(#{eyes[e]}#{nose[n]}#{eyes[e]})"]
  fbat = ["     ", " ^\"^ "]
  rbat = ["  () ", "  ´` "]
  spider = ["  |  ", " .|. ", " :\": "]
  spider.unshift("  |  ") unless b == 1
  a = "     "
  bot = [nothing, skeleton, pumpkin]
  top = [nothing, fbat, rbat, spider]

  # if bottom and upper are empty
  if b < 1 && u < 1
    @output.push(nothing)
  # if bottom is empty
  elsif b < 1
    u < 2 ? (s = 3) : (s = 5)
    s.times {top[u].push(a)}
    @output.push(top[u])
  # if upper is empty
  elsif u < 1
    # put in white space before the decorations
    b == 1 ? (s = 2) : (s = 5)
    s.times {bot[b].unshift(a)}
    @output.push(bot[b])
  # if there's an upper decoration
  elsif u > 0
    # put in the top deco
    2.times {top[u].push(a)} if u < 3 && b > 1
    @output.push(top[u] + bot[b])
  end
  # Input the empty column
  @output.push(nothing)
end

# Transpose the array of arrays so that
# instead of outputting each line of a single each decoration
# what's output is each line of each decoration.
# Example:
# [[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, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4], [5, 5, 5, 5, 5]]
@output.transpose.each do |data|
   data.each do |data1|
     print data1
   end
   print "\n"
end
</code>```

The following:

```<code>ruby deco_g.rb 0000 0001 0002 0003 1110 1111 1112 1113 2220 2221 2222 2223 3310 3312 3321 3323
</code>```

Outputs this:

```<code>          ()    |                 ()   .|.                ()    |           ()          |
   ^"^    ´`    |          ^"^    ´`   :":         ^"^    ´`    |           ´`   ^"^    |
               .|.  (¯w¯) (¯w¯) (¯w¯) (¯w¯)                    .|.  (^_^) (^_^)        .|.
               :":   _|_   _|_   _|_   _|_                     :":   _|_   _|_         :":
                    /[|]\ /[|]\ /[|]\ /[|]\                         /[|]\ /[|]\
                      |     |     |     |     ,     ,     ,     ,     |     |     ,     ,
                     / \   / \   / \   / \  (-o-) (-o-) (-o-) (-o-)  / \   / \  (^_^) (^_^)
</code>```

Title: Help me with my Halloween decoration

Body:
Ruby 2.3.1, 777 752 bytes

Edit_0: I totally missed out on some golfable variable usage and some other stuff.

@o=Array.new;$*.each_with_index do|j,i|a,e,n,b,u,q,r,z,y=0,j[0].to_i,j[1].to_i,j[2].to_i,j[3].to_i,['°','¯','-','^',"'"],['v','w','o','_',"-"],Array.new(7," "),"     ";g,h=[z,["(#{q[e]}#{r[n]}#{q[e]})"," _|_ ","/[|]\\","  |  "," / \\ "],["     ","  ,  ","(#{q[e]}#{r[n]}#{q[e]})"]],[z,["     "," ^\"^ "],["  () ", "  ´` "],[" .|. "," :\": "]];2.times{h[3].unshift("  |  ")}unless b==1;if b<1 && u<1;@o.push(z);elsif b<1;u<3 ? (a=5):(a=3);a.times{h[u].push(y)};@o.push(h[u]);elsif u<1;b==1 ? (a=2):(a=4);a.times{g[b].unshift(y)};@o.push(g[b]);elsif u>0;2.times{h[u].push(y)}if u<3&&b>1;@o.push(h[u]+g[b]);end;@o.push(z);end;@o.transpose.each do|v|;v.each do |w|;print w;end;print"\n";end

Takes in N number of variables of decorations. There's certainly some more golfing that can be done with this. I'm not that familiar with a lot of Ruby's tricks, but here's a shot at it! I'm also happy at being able to solve it.

Un-golfed

@output = Array.new
$*.each_with_index do |j, i|
  # output decoration combo
  s = 0

  # set up vars for decoration input
  e = j[0].to_i
  n = j[1].to_i
  b = j[2].to_i
  u = j[3].to_i

  # Setup decorations/misc
  eyes = ['°','¯','-','^',"'"]
  nose = ['v','w','o','_',"-"]
  nothing = Array.new(7, " ")
  skeleton = ["(#{eyes[e]}#{nose[n]}#{eyes[e]})", " _|_ ", "/[|]\\", "  |  ", " / \\ "]
  pumpkin = ["     ", "  ,  ", "(#{eyes[e]}#{nose[n]}#{eyes[e]})"]
  fbat = ["     ", " ^\"^ "]
  rbat = ["  () ", "  ´` "]
  spider = ["  |  ", " .|. ", " :\": "]
  spider.unshift("  |  ") unless b == 1
  a = "     "
  bot = [nothing, skeleton, pumpkin]
  top = [nothing, fbat, rbat, spider]

  # if bottom and upper are empty
  if b < 1 && u < 1
    @output.push(nothing)
  # if bottom is empty
  elsif b < 1
    u < 2 ? (s = 3) : (s = 5)
    s.times {top[u].push(a)}
    @output.push(top[u])
  # if upper is empty
  elsif u < 1
    # put in white space before the decorations
    b == 1 ? (s = 2) : (s = 5)
    s.times {bot[b].unshift(a)}
    @output.push(bot[b])
  # if there's an upper decoration
  elsif u > 0
    # put in the top deco
    2.times {top[u].push(a)} if u < 3 && b > 1
    @output.push(top[u] + bot[b])
  end
  # Input the empty column
  @output.push(nothing)
end

# Transpose the array of arrays so that
# instead of outputting each line of a single each decoration
# what's output is each line of each decoration.
# Example:
# [[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, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4], [5, 5, 5, 5, 5]]
@output.transpose.each do |data|
   data.each do |data1|
     print data1
   end
   print "\n"
end

The following:

ruby deco_g.rb 0000 0001 0002 0003 1110 1111 1112 1113 2220 2221 2222 2223 3310 3312 3321 3323

Outputs this:

          ()    |                 ()   .|.                ()    |           ()          |
   ^"^    ´`    |          ^"^    ´`   :":         ^"^    ´`    |           ´`   ^"^    |
               .|.  (¯w¯) (¯w¯) (¯w¯) (¯w¯)                    .|.  (^_^) (^_^)        .|.
               :":   _|_   _|_   _|_   _|_                     :":   _|_   _|_         :":
                    /[|]\ /[|]\ /[|]\ /[|]\                         /[|]\ /[|]\
                      |     |     |     |     ,     ,     ,     ,     |     |     ,     ,
                     / \   / \   / \   / \  (-o-) (-o-) (-o-) (-o-)  / \   / \  (^_^) (^_^)


答:
J, <s>22</s> <s>12</s> 8 bytes

Thanks to miles for saving 14 bytes!

```<code>(#~#\)\.
</code>```

Now this is a really nice solution. Pretty succinct, too.

This is the hook #~#\ applied to the suffixes (\.) of the input. The hook, when called on input y, is decomposed as thus:

```<code>(#~#\) y
y #~ #\ y
</code>```

Here are some intermediate results:

```<code>   ]s =: 's p a c e'
s p a c e
   #\ s
1 2 3 4 5 6 7 8 9
   (quote) s
's p a c e'
   (quote;#)\ s
+-----------+-+
|'s'        |1|
+-----------+-+
|'s '       |2|
+-----------+-+
|'s p'      |3|
+-----------+-+
|'s p '     |4|
+-----------+-+
|'s p a'    |5|
+-----------+-+
|'s p a '   |6|
+-----------+-+
|'s p a c'  |7|
+-----------+-+
|'s p a c ' |8|
+-----------+-+
|'s p a c e'|9|
+-----------+-+
   1 2 3 # '123'
122333
   3 3 3 # '123'
111222333
   ]\. s
s p a c e
 p a c e
p a c e
 a c e
a c e
 c e
c e
 e
e
   quote\. s
's p a c e'
' p a c e'
'p a c e'
' a c e'
'a c e'
' c e'
'c e'
' e'
'e'
   (#~#\) s
s  ppp    aaaaa      ccccccc        eeeeeeeee
   (#~#\)\. s
s  ppp    aaaaa      ccccccc        eeeeeeeee
 pp   aaaa     cccccc       eeeeeeee
p  aaa    ccccc      eeeeeee
 aa   cccc     eeeeee
a  ccc    eeeee
 cc   eeee
c  eee
 ee
e
</code>```

Test cases

```<code>   f =: (#~#\)\.
   f
(#~ #\)\.
   f ''
   f 'a'
a
   f 'bc'
bcc
c
   f 'xyz'
xyyzzz
yzz
z
   f 'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f
   f 's p a c e'
s  ppp    aaaaa      ccccccc        eeeeeeeee
 pp   aaaa     cccccc       eeeeeeee
p  aaa    ccccc      eeeeeee
 aa   cccc     eeeeee
a  ccc    eeeee
 cc   eeee
c  eee
 ee
e

   ]tc =: <;._1 '|' , '|a|bc|xyz|code-golf|s p a c e'
++-+--+---+---------+---------+
||a|bc|xyz|code-golf|s p a c e|
++-+--+---+---------+---------+
   ,. f &. > tc
+---------------------------------------------+
+---------------------------------------------+
|a                                            |
+---------------------------------------------+
|bcc                                          |
|c                                            |
+---------------------------------------------+
|xyyzzz                                       |
|yzz                                          |
|z                                            |
+---------------------------------------------+
|coodddeeee-----ggggggooooooollllllllfffffffff|
|oddeee----gggggoooooolllllllffffffff         |
|dee---ggggooooollllllfffffff                 |
|e--gggoooolllllffffff                        |
|-ggooollllfffff                              |
|goolllffff                                   |
|ollfff                                       |
|lff                                          |
|f                                            |
+---------------------------------------------+
|s  ppp    aaaaa      ccccccc        eeeeeeeee|
| pp   aaaa     cccccc       eeeeeeee         |
|p  aaa    ccccc      eeeeeee                 |
| aa   cccc     eeeeee                        |
|a  ccc    eeeee                              |
| cc   eeee                                   |
|c  eee                                       |
| ee                                          |
|e                                            |
+---------------------------------------------+
</code>```

Title: Exploded Suffixes

Body:
Given an ASCII string, output the exploded suffixes of it. For example, if the string was abcde, there are 5 suffixes, ordered longest to shortest:

```<code>abcde
bcde
cde
de
e
</code>```

Each suffix is then exploded, meaning each character is copied as many times as its one-indexed location in that suffix. For example, exploding the suffixes of abcde,

```<code>abcde
12345
abbcccddddeeeee

bcde
1234
bccdddeeee

cde
123
cddeee

de
12
dee

e
1
e
</code>```

Altogether, the exploded suffixes of abcde are

```<code>abbcccddddeeeee
bccdddeeee
cddeee
dee
e
</code>```

Rules

This is code-golf so the shortest code wins.

The input will consist of the printable ASCII characters. (This excludes newlines but includes spaces.)

The output will have each string on a separate line.

Trailing spaces are allowed on each line and there may be an extra newline at the end.

Test Cases

```<code>''

'a'
a

'bc'
bcc
c

'xyz'
xyyzzz
yzz
z

'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f

's p a c e'
s  ppp    aaaaa      ccccccc        eeeeeeeee
 pp   aaaa     cccccc       eeeeeeee
p  aaa    ccccc      eeeeeee
 aa   cccc     eeeeee
a  ccc    eeeee
 cc   eeee
c  eee
 ee
e
</code>```

Body:
J, <s>22</s> <s>12</s> 8 bytes

Thanks to miles for saving 14 bytes!

(#~#\)\.

Now this is a really nice solution. Pretty succinct, too.

This is the hook #~#\ applied to the suffixes (\.) of the input. The hook, when called on input y, is decomposed as thus:

(#~#\) y
y #~ #\ y

Here are some intermediate results:

   ]s =: 's p a c e'
s p a c e
   #\ s
1 2 3 4 5 6 7 8 9
   (quote) s
's p a c e'
   (quote;#)\ s
+-----------+-+
|'s'        |1|
+-----------+-+
|'s '       |2|
+-----------+-+
|'s p'      |3|
+-----------+-+
|'s p '     |4|
+-----------+-+
|'s p a'    |5|
+-----------+-+
|'s p a '   |6|
+-----------+-+
|'s p a c'  |7|
+-----------+-+
|'s p a c ' |8|
+-----------+-+
|'s p a c e'|9|
+-----------+-+
   1 2 3 # '123'
122333
   3 3 3 # '123'
111222333
   ]\. s
s p a c e
 p a c e
p a c e
 a c e
a c e
 c e
c e
 e
e
   quote\. s
's p a c e'
' p a c e'
'p a c e'
' a c e'
'a c e'
' c e'
'c e'
' e'
'e'
   (#~#\) s
s  ppp    aaaaa      ccccccc        eeeeeeeee
   (#~#\)\. s
s  ppp    aaaaa      ccccccc        eeeeeeeee
 pp   aaaa     cccccc       eeeeeeee
p  aaa    ccccc      eeeeeee
 aa   cccc     eeeeee
a  ccc    eeeee
 cc   eeee
c  eee
 ee
e

Test cases

   f =: (#~#\)\.
   f
(#~ #\)\.
   f ''
   f 'a'
a
   f 'bc'
bcc
c
   f 'xyz'
xyyzzz
yzz
z
   f 'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f
   f 's p a c e'
s  ppp    aaaaa      ccccccc        eeeeeeeee
 pp   aaaa     cccccc       eeeeeeee
p  aaa    ccccc      eeeeeee
 aa   cccc     eeeeee
a  ccc    eeeee
 cc   eeee
c  eee
 ee
e

   ]tc =: <;._1 '|' , '|a|bc|xyz|code-golf|s p a c e'
++-+--+---+---------+---------+
||a|bc|xyz|code-golf|s p a c e|
++-+--+---+---------+---------+
   ,. f &. > tc
+---------------------------------------------+
+---------------------------------------------+
|a                                            |
+---------------------------------------------+
|bcc                                          |
|c                                            |
+---------------------------------------------+
|xyyzzz                                       |
|yzz                                          |
|z                                            |
+---------------------------------------------+
|coodddeeee-----ggggggooooooollllllllfffffffff|
|oddeee----gggggoooooolllllllffffffff         |
|dee---ggggooooollllllfffffff                 |
|e--gggoooolllllffffff                        |
|-ggooollllfffff                              |
|goolllffff                                   |
|ollfff                                       |
|lff                                          |
|f                                            |
+---------------------------------------------+
|s  ppp    aaaaa      ccccccc        eeeeeeeee|
| pp   aaaa     cccccc       eeeeeeee         |
|p  aaa    ccccc      eeeeeee                 |
| aa   cccc     eeeeee                        |
|a  ccc    eeeee                              |
| cc   eeee                                   |
|c  eee                                       |
| ee                                          |
|e                                            |
+---------------------------------------------+


答:
Python 3, <s>91</s> <s>68</s> 65 bytes

def f(s):f(s[1:print(''.join(i*c for i,c in enumerate(s[0]+s)))])
```

Terminates with an error after printing the desired output. Test it on Ideone.

How it works

Before f can call itself recursively, the indices of s[1:...] have to be computed.

First enumerate(s[0]+s) yields all pairs (i, c) of characters c of s – with its first character duplicated – and the corresponding indices i. Prepending s[0] serves two purposes here.

The first character of s has to be repeated once, but the first index is 0.

Once all characters have been processed, s[0] will raise an IndexError, causing f to terminate with an error rather than printing newlines until the recursion limit is reached.

''.join(i*c for i,c in ...) builds a flat string of each c repeated i times, which print echoes to STDOUT.

Finally, since print returns None and s[1:None] is simply s[1:], the recursive call f(s[1:...]) repeats the above process for s without its first character.

Title: Exploded Suffixes

Body:
Python 3, <s>91</s> <s>68</s> 65 bytes

def f(s):f(s[1:print(''.join(i*c for i,c in enumerate(s[0]+s)))])

Terminates with an error after printing the desired output. Test it on Ideone.

How it works

Before f can call itself recursively, the indices of s[1:...] have to be computed.

First enumerate(s[0]+s) yields all pairs (i, c) of characters c of s – with its first character duplicated – and the corresponding indices i. Prepending s[0] serves two purposes here.

The first character of s has to be repeated once, but the first index is 0.

Once all characters have been processed, s[0] will raise an IndexError, causing f to terminate with an error rather than printing newlines until the recursion limit is reached.

''.join(i*c for i,c in ...) builds a flat string of each c repeated i times, which print echoes to STDOUT.

Finally, since print returns None and s[1:None] is simply s[1:], the recursive call f(s[1:...]) repeats the above process for s without its first character.


答:
C#, <s>49</s> 45 bytes

(27 if you don't count the using statement)

```<code>using System.Linq;v=>v.Sum()*3-v[0]-v.Last();
</code>```

Title: Sum of neighbours

Body:
C#, <s>49</s> 45 bytes

(27 if you don't count the using statement)

using System.Linq;v=>v.Sum()*3-v[0]-v.Last();


答:
Python, 61 bytes

f=lambda s,i=0:s[i:]and-~i*s[i]+f(s,i+1)or s and'\n'+f(s[1:])
```

<p>Alternative 63:</p>

<pre class="lang-python prettyprint-override"><code>f=lambda s,b=1:s and f(s[:-1],0)+s[-1]*len(s)+b*('\n'+f(s[1:]))
</code>```

Title: Exploded Suffixes

Body:
Python, 61 bytes

f=lambda s,i=0:s[i:]and-~i*s[i]+f(s,i+1)or s and'\n'+f(s[1:])

Alternative 63:

f=lambda s,b=1:s and f(s[:-1],0)+s[-1]*len(s)+b*('\n'+f(s[1:]))


问:
(KevinC's) Triangular DeciDigits Sequence
Input:

A positive integer n which is 1 <= n <= 25000.

Output:

In this sequence we start with the decimal number 1/n.

Then we take the sum of digits up until the n'th digit after the comma (1-indexed); followed by the sum of digits up until the (n-1)'th, then (n-2)'th, etc. Continue until n is 1.

The output is the sum of all these combined.

For example:

```<code>n = 7
1/7 = 0.1428571428...
7th digit-sum = 1+4+2+8+5+7+1 = 28
6th digit-sum = 1+4+2+8+5+7 = 27
5th digit-sum = 1+4+2+8+5 = 20
4th digit-sum = 1+4+2+8 = 15
3rd digit-sum = 1+4+2 = 7
2nd digit-sum = 1+4 = 5
1st digit     = 1
Output = 28+27+20+15+7+5+1 = 103
</code>```

Challenge rules:

If the decimal of 1/n doesn't have n digits after the comma, the missing ones will be counted as 0 (i.e. 1/2 = 0.50 => (5+0) + (5) = 10).

You take the digits without rounding (i.e. the digits of 1/6 are 166666 and not 166667)

General rules:

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

First 1 - 50 in the sequence:

```<code>0, 10, 18, 23, 10, 96, 103, 52, 45, 10, 270, 253, 402, 403, 630, 183, 660, 765, 819, 95, 975, 1034, 1221, 1500, 96, 1479, 1197, 1658, 1953, 1305, 1674, 321, 816, 2490, 2704, 4235, 2022, 3242, 2295, 268, 2944, 3787, 3874, 4097, 1980, 4380, 4968, 3424, 4854, 98
</code>```

Last 24990 - 25000 in the sequence:

```<code>1405098782, 1417995426, 1364392256, 1404501980, 1408005544, 1377273489, 1395684561, 1405849947, 1406216741, 1142066735, 99984
</code>```

答:
JavaScript (ES6), 47 bytes

```<code>f=(b,a=1%b,c=b+1)=>c&&(a/b|0)*c+f(b,a%b*10,c-1)
</code>```

How it works

This answer demonstrates a technique for calculating c decimal digits of a/b:

```<code>f=(a,b,c,d=".")=>~c?(a/b|0)+d+f(a%b*10,b,c-1,""):d
</code>```

This will make an excellent starting point for this challenge. First we can change it slightly so that it calculates b decimal digits of 1/b, by reordering the parameters and setting defaults:

```<code>f=(b,a=1,c=b,d=".")=>~c?(a/b|0)+d+f(b,a%b*10,c-1,""):d
</code>```

Next we can change this so that it calculates the sum of of the first b decimal digits, instead of concatenating them (this does away with the d parameter):

```<code>f=(b,a=1,c=b)=>~c?(a/b|0)+f(b,a%b*10,c-1):0
</code>```

We're almost to a solution; now we just need to make it multiply each digit by c+1:

```<code>f=(b,a=1,c=b)=>~c?(a/b|0)*-~c+f(b,a%b*10,c-1):0
</code>```

Hmm, this seems a little long. What if we incremented c by 1 to begin with?

```<code>f=(b,a=1,c=b+1)=>c?(a/b|0)*c+f(b,a%b*10,c-1):0
</code>```

That saves one byte. And here's a way to save one more:

```<code>f=(b,a=1,c=b+1)=>c&&(a/b|0)*c+f(b,a%b*10,c-1)
</code>```

And now we have our answer. f(7) is 103, f(11) is 270, f(1) is... 2? Oh, we forgot to account for the case where a/b is 1 on the first iteration (i.e. b is 1). Let's do something about this:

```<code>f=(b,a=1%b,c=b+1)=>c&&(a/b|0)*c+f(b,a%b*10,c-1)
</code>```

1 mod b is always 1, unless b is 1, in which case it will be 0. Our program is now correct for all inputs, at 47 bytes.

Body:
JavaScript (ES6), 47 bytes

f=(b,a=1%b,c=b+1)=>c&&(a/b|0)*c+f(b,a%b*10,c-1)

How it works

This answer demonstrates a technique for calculating c decimal digits of a/b:

f=(a,b,c,d=".")=>~c?(a/b|0)+d+f(a%b*10,b,c-1,""):d

This will make an excellent starting point for this challenge. First we can change it slightly so that it calculates b decimal digits of 1/b, by reordering the parameters and setting defaults:

f=(b,a=1,c=b,d=".")=>~c?(a/b|0)+d+f(b,a%b*10,c-1,""):d

Next we can change this so that it calculates the sum of of the first b decimal digits, instead of concatenating them (this does away with the d parameter):

f=(b,a=1,c=b)=>~c?(a/b|0)+f(b,a%b*10,c-1):0

We're almost to a solution; now we just need to make it multiply each digit by c+1:

f=(b,a=1,c=b)=>~c?(a/b|0)*-~c+f(b,a%b*10,c-1):0

Hmm, this seems a little long. What if we incremented c by 1 to begin with?

f=(b,a=1,c=b+1)=>c?(a/b|0)*c+f(b,a%b*10,c-1):0

That saves one byte. And here's a way to save one more:

f=(b,a=1,c=b+1)=>c&&(a/b|0)*c+f(b,a%b*10,c-1)

And now we have our answer. f(7) is 103, f(11) is 270, f(1) is... 2? Oh, we forgot to account for the case where a/b is 1 on the first iteration (i.e. b is 1). Let's do something about this:

f=(b,a=1%b,c=b+1)=>c&&(a/b|0)*c+f(b,a%b*10,c-1)

1 mod b is always 1, unless b is 1, in which case it will be 0. Our program is now correct for all inputs, at 47 bytes.


答:
Haskell, 48 bytes

```<code>e=map(concat.zipWith replicate[1..]).scanr(:)[]
</code>```

is interfaced by any of

```<code>ghc exploded_suffixes.hs -e 'e"abcde"'
ghc exploded_suffixes.hs -e 'mapM_ putStrLn.e=<<getLine' <<<code-golf
ghc exploded_suffixes.hs -e 'Control.Monad.forever$putStr.unlines.e=<<getLine'
</code>```

Title: Exploded Suffixes

Body:
Haskell, 48 bytes

e=map(concat.zipWith replicate[1..]).scanr(:)[]

is interfaced by any of

ghc exploded_suffixes.hs -e 'e"abcde"'
ghc exploded_suffixes.hs -e 'mapM_ putStrLn.e=<<getLine' <<<code-golf
ghc exploded_suffixes.hs -e 'Control.Monad.forever$putStr.unlines.e=<<getLine'


答:
Perl 6, 38 bytes

m:ex/.+$/.map:{put [~] .comb Zx 1..*}
```

<p>37 bytes + 1 for <code>-n</code> command line switch</p>

<h2>Example:</h2>

<pre class="lang-sh prettyprint-override"><code>$ perl6 -ne 'm:ex/.+$/.map:{put [~] .comb Zx 1..*}' <<< 'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f
</code>```

Expanded:

# -n command line switch takes each input line and places it in ｢$_｣

# You can think of it as surrounding the whole program with a for loop
# like this:
for lines() {

  # match
  m
  :exhaustive # every possible way
  / .+ $/     # at least one character, followed by the end of the string

  .map:

  {
    put           # print with newline
      [~]         # reduce using string concatenation ( don't add spaces between elements )
        .comb     # split into individual chars
        Z[x]      # zip using string repetition operator
        1 .. *    # 1,2,3,4 ... Inf
  }

}
```

Title: Exploded Suffixes

Body:
Perl 6, 38 bytes

m:ex/.+$/.map:{put [~] .comb Zx 1..*}

37 bytes + 1 for -n command line switch

Example:

$ perl6 -ne 'm:ex/.+$/.map:{put [~] .comb Zx 1..*}' <<< 'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f

Expanded:

# -n command line switch takes each input line and places it in ｢$_｣

# You can think of it as surrounding the whole program with a for loop
# like this:
for lines() {

  # match
  m
  :exhaustive # every possible way
  / .+ $/     # at least one character, followed by the end of the string

  .map:

  {
    put           # print with newline
      [~]         # reduce using string concatenation ( don't add spaces between elements )
        .comb     # split into individual chars
        Z[x]      # zip using string repetition operator
        1 .. *    # 1,2,3,4 ... Inf
  }

}


答:
Julia, 26 bytes

\(n,k=n)=k<3?n:n\~-k*n+~-k
```

Try it online!

Title: Digital Diversity

Body:
A positive integer may be represented in an integer base \$1 \le b < \infty\$.

When converted to that base it has some number of distinct digits.

Any positive integer in base \$1\$ has \$1\$ distinct digit.

Most positive integers in base \$2\$ have \$2\$ distinct digits, the exceptions being those of the form \$2^n - 1\$, which only have \$1\$.

So the first positive integer that may be represented in an integer base with \$1\$ unique digit is \$1\$ and the first that may be represented with \$2\$ distinct digits is \$2\$.

We can say that \$1\$ is the first integer with digital diversity \$1\$ and \$2\$ is the first integer with digital diversity \$2\$.

Challenge:

Given a positive integer \$n\$ return the first positive integer (in base ten*) that has a digital diversity of \$n\$.

* if your language only supports a specific base (e.g. unary or binary) then you may output in that base.

Your algorithm must work in theory for any positive integer input: it may fail because the precision of your language's integer is too small for the output; but may not fail because base conversion is only defined up to some limit.

Test cases

```<code>input  output
   1     1
   2     2
   3     11
   4     75
   5     694
   6     8345
   7     123717
  17     49030176097150555672
  20     5271200265927977839335179
  35     31553934355853606735562426636407089783813301667210139
  63     3625251781415299613726919161860178255907794200133329465833974783321623703779312895623049180230543882191649073441
 257     87678437238928144977867204156371666030574491195943247606217411725999221158137320290311206746021269051905957869964398955543865645836750532964676103309118517901711628268617642190891105089936701834562621017362909185346834491214407969530898724148629372941508591337423558645926764610261822387781382563338079572769909101879401794746607730261119588219922573912353523976018472514396317057486257150092160745928604277707892487794747938484196105308022626085969393774316283689089561353458798878282422725100360693093282006215082783023264045094700028196975508236300153490495688610733745982183150355962887110565055971546946484175232
</code>```

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

OEIS: A049363 - also smallest pandigital number in base n.

Body:
Julia, 26 bytes

\(n,k=n)=k<3?n:n\~-k*n+~-k

Try it online!


答:
Jelly, 10 bytes

```<code>⁵*:⁸D+\_ỊS
</code>```

Not the shortest approach, but fairly efficient. Try it online! or verify all test cases.

How it works

```<code>⁵*:⁸D+\_ỊS  Main link. Argument: n (integer)

⁵*          Yield 10**n.
  :⁸        Divide 10**n by n (integer division).
    D       Convert the quotient to base 10.
     +\     Take the cumulative sum of the digits.
        Ị   Insignificant; yield (abs(n) <= 1).
       _    Subtract the resulting Boolean from each decimal digit.
            This takes care of edge case n = 1, which would return 2 otherwise.
         S  Take the sum.
</code>```

Title: (KevinC's) Triangular DeciDigits Sequence

Body:
Input:

A positive integer n which is 1 <= n <= 25000.

Output:

In this sequence we start with the decimal number 1/n.

Then we take the sum of digits up until the n'th digit after the comma (1-indexed); followed by the sum of digits up until the (n-1)'th, then (n-2)'th, etc. Continue until n is 1.

The output is the sum of all these combined.

For example:

```<code>n = 7
1/7 = 0.1428571428...
7th digit-sum = 1+4+2+8+5+7+1 = 28
6th digit-sum = 1+4+2+8+5+7 = 27
5th digit-sum = 1+4+2+8+5 = 20
4th digit-sum = 1+4+2+8 = 15
3rd digit-sum = 1+4+2 = 7
2nd digit-sum = 1+4 = 5
1st digit     = 1
Output = 28+27+20+15+7+5+1 = 103
</code>```

Challenge rules:

If the decimal of 1/n doesn't have n digits after the comma, the missing ones will be counted as 0 (i.e. 1/2 = 0.50 => (5+0) + (5) = 10).

You take the digits without rounding (i.e. the digits of 1/6 are 166666 and not 166667)

General rules:

Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters, full programs. Your call.

Default Loopholes are forbidden.

If possible, please add a link with a test for your code.

Also, please add an explanation if necessary.

First 1 - 50 in the sequence:

```<code>0, 10, 18, 23, 10, 96, 103, 52, 45, 10, 270, 253, 402, 403, 630, 183, 660, 765, 819, 95, 975, 1034, 1221, 1500, 96, 1479, 1197, 1658, 1953, 1305, 1674, 321, 816, 2490, 2704, 4235, 2022, 3242, 2295, 268, 2944, 3787, 3874, 4097, 1980, 4380, 4968, 3424, 4854, 98
</code>```

Last 24990 - 25000 in the sequence:

```<code>1405098782, 1417995426, 1364392256, 1404501980, 1408005544, 1377273489, 1395684561, 1405849947, 1406216741, 1142066735, 99984
</code>```

Body:
Jelly, 10 bytes

⁵*:⁸D+\_ỊS

Not the shortest approach, but fairly efficient. Try it online! or verify all test cases.

How it works

⁵*:⁸D+\_ỊS  Main link. Argument: n (integer)

⁵*          Yield 10**n.
  :⁸        Divide 10**n by n (integer division).
    D       Convert the quotient to base 10.
     +\     Take the cumulative sum of the digits.
        Ị   Insignificant; yield (abs(n) <= 1).
       _    Subtract the resulting Boolean from each decimal digit.
            This takes care of edge case n = 1, which would return 2 otherwise.
         S  Take the sum.


答:
Jelly, 9 bytes

```<code>R⁵*:%⁵+\S
</code>```

Rather slow, but short. Try it online! or verify the first 50 test cases.

How it works

```<code>R⁵*:%⁵+\S  Main link. Argument: n

R          Range; yield [1, ..., n].
 ⁵*        10 power; yield [10**1, ..., 10**n].
   :       Divide each power by n.
    %⁵     Take each quotient modulo 10.
           This yields all desired decimal digits.
      +\   Take the cumulative sum of the digits.
        S  Take the sum.
</code>```

Body:
Jelly, 9 bytes

R⁵*:%⁵+\S

Rather slow, but short. Try it online! or verify the first 50 test cases.

How it works

R⁵*:%⁵+\S  Main link. Argument: n

R          Range; yield [1, ..., n].
 ⁵*        10 power; yield [10**1, ..., 10**n].
   :       Divide each power by n.
    %⁵     Take each quotient modulo 10.
           This yields all desired decimal digits.
      +\   Take the cumulative sum of the digits.
        S  Take the sum.


答:
Python 2, 49 bytes

lambda n:sum(10**-~k/n%10*(n-k)for k in range(n))
```

Test it on Ideone.

Body:
Python 2, 49 bytes

lambda n:sum(10**-~k/n%10*(n-k)for k in range(n))

Test it on Ideone.


答:
Java, <s>150</s> 127 bytes

Edit:

-23 bytes off. Thanks to @Kevin Cruijssen

Snipet:

```<code>f->{String s[]=f.split(""),o="";int i=-1,j,l=s.length;for(;++i<l;)for(j=-2;++j<i;o+=s[i]);return l<1?"":o+"\n"+f.substring(1);}
</code>```

Ungolfed:

```<code>public static String explodeSuff(String suff){
  char [] s = suff.toCharArray();
  String out = "";
  if(s.length==0)return "";
  for(int i=-1;++i<s.length;){
    for(int j=-2;++j<i;){
      out+=s[i];
    }
  }
  return out+"\n"+suff.subString(1);
}
</code>```

Title: Exploded Suffixes

Body:
Java, <s>150</s> 127 bytes

Edit:

-23 bytes off. Thanks to @Kevin Cruijssen

Snipet:

f->{String s[]=f.split(""),o="";int i=-1,j,l=s.length;for(;++i<l;)for(j=-2;++j<i;o+=s[i]);return l<1?"":o+"\n"+f.substring(1);}

Ungolfed:

public static String explodeSuff(String suff){
  char [] s = suff.toCharArray();
  String out = "";
  if(s.length==0)return "";
  for(int i=-1;++i<s.length;){
    for(int j=-2;++j<i;){
      out+=s[i];
    }
  }
  return out+"\n"+suff.subString(1);
}


Title: Fibonacci-orial

Body:
Definition

Fibonacci sequence F(n), on the positive integers, are defined as such:

```<code>1. F(1) = 1
2. F(2) = 1
3. F(n) = F(n-1) + F(n-2), where n is an integer and n > 2
</code>```

The Fibonacci-orial of a positive integer is the product of [F(1), F(2), ..., F(n)].

Task

Given positive integer n, find the Fibonacci-orial of n.

Specs

The fibonacci-orial of 100 must compute in under 5 seconds on a reasonable computer.

Testcases

```<code>n   Fibonacci-orial of n
1   1
2   1
3   2
4   6
5   30
6   240
7   3120
8   65520
9   2227680
10  122522400
11  10904493600
12  1570247078400
13  365867569267200
14  137932073613734400
15  84138564904377984000
16  83044763560621070208000
17  132622487406311849122176000
18  342696507457909818131702784000
19  1432814097681520949608649339904000
20  9692987370815489224102512784450560000
100 3371601853146468125386964065447576689828006172937411310662486977801540671138589868616500834190029067583665182291701553172011082574587431382310099030394306877775647395167143332483560925112960024644459715300507481235056111434293619038347456390454209587101225261757371666449068625033999573552165524529725467628060170886602001077137613803027158648329335507728698605769992818756765633305318529965186184043999696650407246193257877568825245646129366994079739720698147440310773871269639752334356493678913424390564535389212240038895626811627949132978086070255082668392290037141141291484839596694182152062726390364094447642643912371532491388089634845995941928089653751672688740718152064107169357399466473375804972260594768969952507346694189050233823596316467570584434128052398891223730335019092974935617029638919358286124350711360361279157416837428904150054292406756317837582840596331363581207781793070936765786629772999832857257349696094416616259974304208756997835360702840912518532683324936435856348020736000000000000000000000000
</code>```

References

Obligatory OEIS A003266

OEIS A000045 - Fibonacci sequence

Body:
Racket 130 bytes

(define(fb n)(cond[(or(= n 1)(= n 2))1][(+(fb(- n 1))(fb(- n 2)))]))
(define(fo n)(for/product((i(range 1(+ 1 n))))(fb i)))(fo n))

Ungolfed:

(define (f n)
  (define (fibonacci n)
    (cond
      [(or (= n 1)(= n 2)) 1]
      [else (+ (fibonacci (- n 1)) (fibonacci(- n 2)))] ))
  (define (f_orial n)
    (for/product ((i (range 1 (add1 n))))
      (fibonacci i)))
  (f_orial n))

Testing:

(f 1)
(f 2)
(f 3)
(f 4)
(f 5)
(f 6)
(f 7)
(f 8)
(f 9)
(f 10)
(f 11)
(f 12)
(f 20)
(f 30)

Output:

1
1
2
6
30
240
3120
65520
2227680
122522400
10904493600
1570247078400
9692987370815489224102512784450560000
607373569868916007005878071331449502263924414704952629297115029592606043656028160000000


问:
Give the smallest number that has N divisors

Your function takes a natural number and returns the smallest natural number that has exactly that amount of divisors, including itself.

Examples:

f(1) =  1 [1]
f(2) =  2 [1, 2]
f(3) =  4 [1, 2, 4]
f(4) =  6 [1, 2, 3, 6]
f(5) = 16 [1, 2, 4, 8, 16]
f(6) = 12 [1, 2, 3, 4, 6, 12]
 ...```

The function doesn't have to return the list of divisors, they are only here for the examples.

答:
Jelly, 6 bytes

```<code>2*RÆdi
</code>```

Try it online! or verify all test cases.

How it works

```<code>2*RÆdi  Main link. Argument: n (integer)

2*      Compute 2**n.
  R     Range; yield [1, ..., 2**n]. Note that 2**(n-1) has n divisors, so this
        range contains the number we are searching for.
   Æd   Divisor count; compute the number of divisors of each integer in the range.
     i  Index; return the first (1-based) index of n.
</code>```

Body:
Jelly, 6 bytes

2*RÆdi

Try it online! or verify all test cases.

How it works

2*RÆdi  Main link. Argument: n (integer)

2*      Compute 2**n.
  R     Range; yield [1, ..., 2**n]. Note that 2**(n-1) has n divisors, so this
        range contains the number we are searching for.
   Æd   Divisor count; compute the number of divisors of each integer in the range.
     i  Index; return the first (1-based) index of n.


问:
Square, diamond, square, diamond

Task

Given a non-empty string of lowercase ASCII letters a-z, take its first character, and:

Surround it with a square of copies of the second character,

Surround that with a diamond of copies of the third character,

Surround that with a square of copies of the fourth character…

…alternating between square and diamond borders until the end of the string. Empty space between the borders should be represented by ASCII spaces ().

To add a square border, draw a square exactly around the entire current “working array”:

```<code>                                               sssssssssss
                                t              s    t    s
                               t t             s   t t   s
                              t   t            s  t   t  s
                             t aaa t           s t aaa t s
                            t  aca  t    =>    st  aca  ts
                             t aaa t           s t aaa t s
                              t   t            s  t   t  s
                               t t             s   t t   s
                                t              s    t    s
                                               sssssssssss
</code>```

To add a diamond border, draw a centered diamond shape that touches the outermost square diagonally, but not orthogonally:

```<code>                                                     s
                                                    s s
                                                   s   s
                                                  s     s
                                                 s       s
                                                s         s
                                               s           s
                    wwwwwwwwwww               s wwwwwwwwwww s
                    w    o    w              s  w    o    w  s
                    w   o o   w             s   w   o o   w   s
                    w  o   o  w            s    w  o   o  w    s
                    w o eee o w           s     w o eee o w     s
                    wo  eme  ow    =>    s      wo  eme  ow      s
                    w o eee o w           s     w o eee o w     s
                    w  o   o  w            s    w  o   o  w    s
                    w   o o   w             s   w   o o   w   s
                    w    o    w              s  w    o    w  s
                    wwwwwwwwwww               s wwwwwwwwwww s
                                               s           s
                                                s         s
                                                 s       s
                                                  s     s
                                                   s   s
                                                    s s
                                                     s
</code>```

Your program must output the final array.

Each line may contain any amount of trailing spaces.

You may output a list of strings representing lines, or a single newline-separated string with an optional trailing newline.

Leading/trailing blank lines are disallowed.

Leading columns of spaces are also disallowed.

This is code-golf. The shortest code in bytes wins.

Test cases

The above examples are expected outputs for cat, cats, meow, and meows, in reading order. Some other cases worth handling:

For the input a, your program should output:

```<code>a
</code>```

For the input ab, your program should output:

```<code>bbb
bab
bbb
</code>```

For the input codegolf, your program should output:

```<code>fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
f                            l                            f
f                           l l                           f
f                          l   l                          f
f                         l     l                         f
f                        l       l                        f
f                       l         l                       f
f                      l           l                      f
f                     l             l                     f
f                    l               l                    f
f                   l                 l                   f
f                  l                   l                  f
f                 l                     l                 f
f                l                       l                f
f               l                         l               f
f              l                           l              f
f             l ooooooooooooooooooooooooooo l             f
f            l  o            g            o  l            f
f           l   o           g g           o   l           f
f          l    o          g   g          o    l          f
f         l     o         g     g         o     l         f
f        l      o        g       g        o      l        f
f       l       o       g         g       o       l       f
f      l        o      g           g      o        l      f
f     l         o     g eeeeeeeeeee g     o         l     f
f    l          o    g  e    d    e  g    o          l    f
f   l           o   g   e   d d   e   g   o           l   f
f  l            o  g    e  d   d  e    g  o            l  f
f l             o g     e d ooo d e     g o             l f
fl              og      ed  oco  de      go              lf
f l             o g     e d ooo d e     g o             l f
f  l            o  g    e  d   d  e    g  o            l  f
f   l           o   g   e   d d   e   g   o           l   f
f    l          o    g  e    d    e  g    o          l    f
f     l         o     g eeeeeeeeeee g     o         l     f
f      l        o      g           g      o        l      f
f       l       o       g         g       o       l       f
f        l      o        g       g        o      l        f
f         l     o         g     g         o     l         f
f          l    o          g   g          o    l          f
f           l   o           g g           o   l           f
f            l  o            g            o  l            f
f             l ooooooooooooooooooooooooooo l             f
f              l                           l              f
f               l                         l               f
f                l                       l                f
f                 l                     l                 f
f                  l                   l                  f
f                   l                 l                   f
f                    l               l                    f
f                     l             l                     f
f                      l           l                      f
f                       l         l                       f
f                        l       l                        f
f                         l     l                         f
f                          l   l                          f
f                           l l                           f
f                            l                            f
fffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
</code>```

Reference implementation

I wrote some Julia code that your program’s output should match (at least visually). Try it online!

答:
Java - 429 417 bytes

```<code>int r,l;int D(int n){return Math.abs(n-r);}int R(int n){return n=(n!=0)?((n%2!=0)?(R(n-1)+1):(2*R(n-1))+2):n;}char[][]C(String a){char[]c=a.toCharArray();l=a.length();r=R(l-1);int s=r*2+1,i,j,k;char[][]x=new char[s][s];for(i=0;i<s;i++){for(j=0;j<s;j++){x[i][j]=' ';for(k=0;k<l;k++){if(D(i)<=R(k)&&D(j)<=R(k)){if(k%2!=0){if(D(i)==R(k)||D(j)==R(k)){x[i][j]=c[k];}}else{if(D(i)+D(j)==R(k)){x[i][j]=c[k];}}}}}}return x;}
</code>```

Credit goes to @Anedar as it was an influence on the structure of this answer

Ungolfed:

```<code>int r, l;

int D(int n) {
    return Math.abs(n - r);
}

int R(int n) {
    return n = (n != 0) ? ((n % 2 != 0) ? (R(n - 1) + 1) : (2 * R(n - 1)) + 2) : n;
}

char[][] C(String a) {
    char[] c = a.toCharArray();
    l = a.length();
    r = R(l - 1);
    int s = r * 2 + 1, i, j, k;
    char[][] x = new char[s][s];
    for (i = 0; i < s; i++) {
        for (j = 0; j < s; j++) {
            x[i][j] = ' ';
            for (k = 0; k < l; k++) {
                if (D(i) <= R(k) && D(j) <= R(k)) {
                    if (k % 2 != 0) {
                        if (D(i) == R(k) || D(j) == R(k)) {
                            x[i][j] = c[k];
                        }
                    } else if (D(i) + D(j) == R(k)) {
                        x[i][j] = c[k];
                    }
                }
            }
        }
    }
    return x;
}
</code>```

Title: Square, diamond, square, diamond

Body:
Java - 429 417 bytes

int r,l;int D(int n){return Math.abs(n-r);}int R(int n){return n=(n!=0)?((n%2!=0)?(R(n-1)+1):(2*R(n-1))+2):n;}char[][]C(String a){char[]c=a.toCharArray();l=a.length();r=R(l-1);int s=r*2+1,i,j,k;char[][]x=new char[s][s];for(i=0;i<s;i++){for(j=0;j<s;j++){x[i][j]=' ';for(k=0;k<l;k++){if(D(i)<=R(k)&&D(j)<=R(k)){if(k%2!=0){if(D(i)==R(k)||D(j)==R(k)){x[i][j]=c[k];}}else{if(D(i)+D(j)==R(k)){x[i][j]=c[k];}}}}}}return x;}

Credit goes to @Anedar as it was an influence on the structure of this answer

Ungolfed:

int r, l;

int D(int n) {
    return Math.abs(n - r);
}

int R(int n) {
    return n = (n != 0) ? ((n % 2 != 0) ? (R(n - 1) + 1) : (2 * R(n - 1)) + 2) : n;
}

char[][] C(String a) {
    char[] c = a.toCharArray();
    l = a.length();
    r = R(l - 1);
    int s = r * 2 + 1, i, j, k;
    char[][] x = new char[s][s];
    for (i = 0; i < s; i++) {
        for (j = 0; j < s; j++) {
            x[i][j] = ' ';
            for (k = 0; k < l; k++) {
                if (D(i) <= R(k) && D(j) <= R(k)) {
                    if (k % 2 != 0) {
                        if (D(i) == R(k) || D(j) == R(k)) {
                            x[i][j] = c[k];
                        }
                    } else if (D(i) + D(j) == R(k)) {
                        x[i][j] = c[k];
                    }
                }
            }
        }
    }
    return x;
}


问:
Compute the Mertens function
Given a positive integer n, compute the value of the Mertens function \$M(n)\$ where:

$$M(n) = \Sigma_{k=1}^{n}\mu(k)$$

and \$\mu(k)\$ is the Möbius function where \$μ(k) = 1\$ if \$k\$ has an even number of distinct prime factors, \$-1\$ if \$k\$ has an odd number of distinct prime factors, and \$0\$ if the prime factors are not distinct.

This is code-golf so create the shortest code for a function or program that computes the Mertens function for an input integer n > 0.

This is the OEIS sequence A002321.

Test Cases

```<code>n M(n)
1 1
2 0
3 -1
4 -1
5 -2
6 -1
7 -2
8 -2
9 -2
10 -1
117 -5
5525 5
7044 -25
8888 4
10000 -23
</code>```

答:
J, 19 bytes

```<code>1#.1*/@:-@~:@q:@+i.
</code>```

Computes the Mertens function on n using the sum of the Möbius function over the range [1, n].

Usage

```<code>   f =: 1#.1*/@:-@~:@q:@+i.
   (,.f"0) 1 2 3 4 5 6 7 8 9 10 117 5525 7044 8888 10000
    1   1
    2   0
    3  _1
    4  _1
    5  _2
    6  _1
    7  _2
    8  _2
    9  _2
   10  _1
  117  _5
 5525   5
 7044 _25
 8888   4
10000 _23
</code>```

Explanation

```<code>1#.1*/@:-@~:@q:@+i.  Input: integer n
                 i.  Range [0, 1, ..., n-1]
   1            +    Add 1 to each
             q:@     Get the prime factors of each
          ~:@        Sieve mask of each, 1s at the first occurrence
                     of a value and 0 elsewhere
        -@           Negate
    */@:             Reduce each using multiplication to get the product
1#.                  Convert that to decimal from a list of base-1 digits
                     Equivalent to getting the sum
</code>```

Title: Compute the Mertens function

Body:
J, 19 bytes

1#.1*/@:-@~:@q:@+i.

Computes the Mertens function on n using the sum of the Möbius function over the range [1, n].

Usage

   f =: 1#.1*/@:-@~:@q:@+i.
   (,.f"0) 1 2 3 4 5 6 7 8 9 10 117 5525 7044 8888 10000
    1   1
    2   0
    3  _1
    4  _1
    5  _2
    6  _1
    7  _2
    8  _2
    9  _2
   10  _1
  117  _5
 5525   5
 7044 _25
 8888   4
10000 _23

Explanation

1#.1*/@:-@~:@q:@+i.  Input: integer n
                 i.  Range [0, 1, ..., n-1]
   1            +    Add 1 to each
             q:@     Get the prime factors of each
          ~:@        Sieve mask of each, 1s at the first occurrence
                     of a value and 0 elsewhere
        -@           Negate
    */@:             Reduce each using multiplication to get the product
1#.                  Convert that to decimal from a list of base-1 digits
                     Equivalent to getting the sum


答:
Brachylog, 17 bytes

```<code>@]Elyk:Erz:jac@w\
</code>```

Try it online!

Explanation

```<code>@]E                 E is a suffix of the Input
   lyk              The list [0, ..., length(E) - 1]
      :Erz          The list [[0th char of E, 0], ..., [Last char of E, length(E) - 1]]
          :ja       For all elements of that list, concatenate the Ith char I times to itself
             c      Concatenate the list into a string
              @w    Write followed by a line break
                \   False: backtrack to another suffix of the Input
</code>```

Title: Exploded Suffixes

Body:
Given an ASCII string, output the exploded suffixes of it. For example, if the string was abcde, there are 5 suffixes, ordered longest to shortest:

```<code>abcde
bcde
cde
de
e
</code>```

Each suffix is then exploded, meaning each character is copied as many times as its one-indexed location in that suffix. For example, exploding the suffixes of abcde,

```<code>abcde
12345
abbcccddddeeeee

bcde
1234
bccdddeeee

cde
123
cddeee

de
12
dee

e
1
e
</code>```

Altogether, the exploded suffixes of abcde are

```<code>abbcccddddeeeee
bccdddeeee
cddeee
dee
e
</code>```

Rules

This is code-golf so the shortest code wins.

The input will consist of the printable ASCII characters. (This excludes newlines but includes spaces.)

The output will have each string on a separate line.

Trailing spaces are allowed on each line and there may be an extra newline at the end.

Test Cases

```<code>''

'a'
a

'bc'
bcc
c

'xyz'
xyyzzz
yzz
z

'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f

's p a c e'
s  ppp    aaaaa      ccccccc        eeeeeeeee
 pp   aaaa     cccccc       eeeeeeee
p  aaa    ccccc      eeeeeee
 aa   cccc     eeeeee
a  ccc    eeeee
 cc   eeee
c  eee
 ee
e
</code>```

Body:
Brachylog, 17 bytes

@]Elyk:Erz:jac@w\

Try it online!

Explanation

@]E                 E is a suffix of the Input
   lyk              The list [0, ..., length(E) - 1]
      :Erz          The list [[0th char of E, 0], ..., [Last char of E, length(E) - 1]]
          :ja       For all elements of that list, concatenate the Ith char I times to itself
             c      Concatenate the list into a string
              @w    Write followed by a line break
                \   False: backtrack to another suffix of the Input


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

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

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

The challenge

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

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

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

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

Additional notes

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

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

答:
Python 2, 107 bytes

L=[(x+y).lstrip()for x in' kstnhmyrw'for y in'aiueo'if x+y not in'yiyewiwuwe']
print L[L.index(input())+1]
```

Expects input enclosed in quotes, 'he' for example

Title: Output the next kana

Body:
Python 2, 107 bytes

L=[(x+y).lstrip()for x in' kstnhmyrw'for y in'aiueo'if x+y not in'yiyewiwuwe']
print L[L.index(input())+1]

Expects input enclosed in quotes, 'he' for example


答:
Racket 151 bytes

```<code>(second(member s '(a i u e o ka ki ku ke ko sa si su se so ta ti tu te to na
ni nu ne no ha hi hu he ho ma mi mu me mo ya yu yo ra ri ru re ro wa wo)))
</code>```

Ungolfed:

```<code>(define (f s)
  (second
   (member s
           '(a i u e o ka ki ku ke ko sa si su se so ta ti tu te to na ni nu ne
               no ha hi hu he ho ma mi mu me mo ya yu yo ra ri ru re ro wa wo))))
</code>```

Testing:

```<code>(f 'a)
(f 'i)
(f 'o)
(f 'ke)
(f 'so)
(f 'ni)
(f 'ya)
(f 'yu)
(f 'wa)
</code>```

Output:

```<code>'i
'u
'ka
'ko
'ta
'nu
'yu
'yo
'wo
</code>```

There is an error message if 'wo is sent.

Title: Output the next kana

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

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

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

The challenge

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

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

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

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

Additional notes

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

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

Body:
Racket 151 bytes

(second(member s '(a i u e o ka ki ku ke ko sa si su se so ta ti tu te to na
ni nu ne no ha hi hu he ho ma mi mu me mo ya yu yo ra ri ru re ro wa wo)))

Ungolfed:

(define (f s)
  (second
   (member s
           '(a i u e o ka ki ku ke ko sa si su se so ta ti tu te to na ni nu ne
               no ha hi hu he ho ma mi mu me mo ya yu yo ra ri ru re ro wa wo))))

Testing:

(f 'a)
(f 'i)
(f 'o)
(f 'ke)
(f 'so)
(f 'ni)
(f 'ya)
(f 'yu)
(f 'wa)

Output:

'i
'u
'ka
'ko
'ta
'nu
'yu
'yo
'wo

There is an error message if 'wo is sent.


答:
Python 3, 95 bytes

```<code>def f(s):return'\n'.join(''.join(s[j:][i]*(i+1)for i in range(len(s)-j))for j in range(len(s)))
</code>```

This was surprisingly harder than I expected it to be. I redid my whole function maybe 4 times.

Title: Exploded Suffixes

Body:
Python 3, 95 bytes

def f(s):return'\n'.join(''.join(s[j:][i]*(i+1)for i in range(len(s)-j))for j in range(len(s)))

This was surprisingly harder than I expected it to be. I redid my whole function maybe 4 times.


答:
Racket 184 bytes

```<code>(let p((l(string->list s))(ol'()))(cond[(null? l)(display(list->string(flatten ol)))]
[else(p(cdr l)(append ol(list #\newline)(for/list((i l)(n(length l)))(for/list((j(+ 1 n)))i))))]))
</code>```

Ungolfed:

```<code>(define(f s)
 (let loop((l(string->list s))
             (outl '()))
    (cond
      [(null? l)
       (display
        (list->string
         (flatten outl)))]
      [else
       (loop
        (rest l)
        (append outl
                (list #\newline)
                (for/list ((i l)
                           (n (length l)))
                  (for/list ((j (add1 n)))
                    i
                    ))))]  )))

(f "abcde")
(f "xyz")
</code>```

Output:

```<code>abbcccddddeeeee
bccdddeeee
cddeee
dee
e

xyyzzz
yzz
z
</code>```

Title: Exploded Suffixes

Body:
Racket 184 bytes

(let p((l(string->list s))(ol'()))(cond[(null? l)(display(list->string(flatten ol)))]
[else(p(cdr l)(append ol(list #\newline)(for/list((i l)(n(length l)))(for/list((j(+ 1 n)))i))))]))

Ungolfed:

(define(f s)
 (let loop((l(string->list s))
             (outl '()))
    (cond
      [(null? l)
       (display
        (list->string
         (flatten outl)))]
      [else
       (loop
        (rest l)
        (append outl
                (list #\newline)
                (for/list ((i l)
                           (n (length l)))
                  (for/list ((j (add1 n)))
                    i
                    ))))]  )))

(f "abcde")
(f "xyz")

Output:

abbcccddddeeeee
bccdddeeee
cddeee
dee
e

xyyzzz
yzz
z


答:
Perl, 36 + 1 (-n) = 37 bytes

/.+$(?{$.=say$&=~s%.%$&x$.++%rge})^/
```
<p>Needs <code>-n</code> and <code>-E</code> (or <code>-M5.010</code>) to run :</p>
```perl -nE '/.+$(?{$.=say$&=~s%.%$&x$.++%rge})^/' <<< "code-golf"
```

Note that it works on only one instance each time you run it (because it uses the variable $. which is incremented every time a line is read, so it hold 1 only the first time a line is read). (But no problem here, just ^D and re-run it!)

Title: Exploded Suffixes

Body:
Perl, 36 + 1 (-n) = 37 bytes

/.+$(?{$.=say$&=~s%.%$&x$.++%rge})^/

Needs -n and -E (or -M5.010) to run :

perl -nE '/.+$(?{$.=say$&=~s%.%$&x$.++%rge})^/' <<< "code-golf"

Note that it works on only one instance each time you run it (because it uses the variable $. which is incremented every time a line is read, so it hold 1 only the first time a line is read). (But no problem here, just ^D and re-run it!)


问:
How many answers does this question have?
Write a program or a function that outputs the integer number of answers this question has. Your solution should still work as more answers are added.

Languages that run in a browser may be run from the js console while on this page. Otherwise, you'd probably have to download this page. Multi-language solutions, e.g. wgeting the page and parsing it using grep is ok. Just sum up the command line and all source used.

This is code golf; shortest answer in bytes wins.

EDIT:

Let's allow at most one occourance of the url of this page to not count, either as input or in the source. No url shorteners, no data stored as get parameters etc. Quotes around url, if needed, still count. Taking the url as input is also fine. If you want to remove some part of the url, e.g. /how-many-answers..., you can, but it probably doesn't help you.

答:
Javascript, 67 bytes

```<code>alert($(".answers-subheader").children().first().children().html())
</code>```

This look way too long

Body:
Javascript, 67 bytes

alert($(".answers-subheader").children().first().children().html())

This look way too long


问:
Random dice tipping
In a standard dice (die) the numbers are arranged so that opposite faces add to seven.
Write the shortest possible program in your preferred language which outputs a random throw followed by 9 random tippings. A tipping is a quarter turn of the dice, e.g. if the dice is facing 5, all possible tippings are 1,3,4 and 6.

Example of desired output:

1532131356

答:
Bash

```<code>#/!bin/bash
f=`expr $RANDOM % 6`
f=`expr $f + 1`
printf "$f"
for ((i=0; i<9; i++))
do
   ((bad=7-$f))
   next=`expr $RANDOM % 6`
   next=`expr $next + 1`
   while [ $next -eq $bad ] || [ $next -eq $f ]
   do
      next=`expr $RANDOM % 6`
      next=`expr $next + 1`
   done
printf "$next"
f=$next
done
</code>```

sample code: http://ideone.com/CCfro

ContentLicense: CC BY-SA 2.5

Title: Random dice tipping

Body:
Bash

#/!bin/bash
f=`expr $RANDOM % 6`
f=`expr $f + 1`
printf "$f"
for ((i=0; i<9; i++))
do
   ((bad=7-$f))
   next=`expr $RANDOM % 6`
   next=`expr $next + 1`
   while [ $next -eq $bad ] || [ $next -eq $f ]
   do
      next=`expr $RANDOM % 6`
      next=`expr $next + 1`
   done
printf "$next"
f=$next
done

sample code: http://ideone.com/CCfro


答:
Javascript (ES5), <s>46</s> <s>44</s> <s>40</s> <s>38</s> 33 bytes

```<code>_=>parseInt($('#answers').text())
</code>```

5 bytes saved thanks to Ismael Miguel

Note: This is pretty slow, and won't work if you have the PPCG-Design userscript.

Title: How many answers does this question have?

Body:
Write a program or a function that outputs the integer number of answers this question has. Your solution should still work as more answers are added.

Languages that run in a browser may be run from the js console while on this page. Otherwise, you'd probably have to download this page. Multi-language solutions, e.g. wgeting the page and parsing it using grep is ok. Just sum up the command line and all source used.

This is code golf; shortest answer in bytes wins.

EDIT:

Let's allow at most one occourance of the url of this page to not count, either as input or in the source. No url shorteners, no data stored as get parameters etc. Quotes around url, if needed, still count. Taking the url as input is also fine. If you want to remove some part of the url, e.g. /how-many-answers..., you can, but it probably doesn't help you.

Body:
Javascript (ES5), <s>46</s> <s>44</s> <s>40</s> <s>38</s> 33 bytes

_=>parseInt($('#answers').text())

5 bytes saved thanks to Ismael Miguel

Note: This is pretty slow, and won't work if you have the PPCG-Design userscript.


答:
JavaScript (ES6), 65 bytes

f=s=>s?[s.replace(/./g,(c,i)=>c.repeat(i+1)),...f(s.slice(1))]:[]```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input oninput=o.textContent=f(this.value).join`\n`><pre id=o></code>```

Previous attempts:

```<code>67: s=>[...s].map((_,i)=>s.slice(i).replace(/./g,(c,i)=>c.repeat(i+1)))
84: s=>s.replace(/./g,`$&$'
    `).match(/.+/g).map(s=>s.replace(/./g,(c,i)=>c.repeat(i+1)))
89: f=(s,t=s.replace(/./g,(c,i)=>c.repeat(i+1)))=>t?[]:[t,...f(s,t.replace(/(.)(?=\1)/g,''))]
</code>```

Title: Exploded Suffixes

Body:
JavaScript (ES6), 65 bytes

f=s=>s?[s.replace(/./g,(c,i)=>c.repeat(i+1)),...f(s.slice(1))]:[]

<input oninput=o.textContent=f(this.value).join`\n`><pre id=o>

Previous attempts:

67: s=>[...s].map((_,i)=>s.slice(i).replace(/./g,(c,i)=>c.repeat(i+1)))
84: s=>s.replace(/./g,`$&$'
    `).match(/.+/g).map(s=>s.replace(/./g,(c,i)=>c.repeat(i+1)))
89: f=(s,t=s.replace(/./g,(c,i)=>c.repeat(i+1)))=>t?[]:[t,...f(s,t.replace(/(.)(?=\1)/g,''))]


答:
Javascript + jQuery, 23 bytes

```<code>_=>+$("h2>span").text()
</code>```

Body:
Javascript + jQuery, 23 bytes

_=>+$("h2>span").text()


答:
C#, 101 bytes

```<code>f=s=>{var r="\n";for(int i=0;i<s.Length;)r+=new string(s[i],++i);return""==s?r:r+f(s.Substring(1));};
</code>```

Recursive anonymous function, which also prints a leading newline. If the leading newline is not allowed, 3 extra bytes turn it into a trailing newline:

```<code>f=s=>{var r="";for(int i=0;i<s.Length;)r+=new string(s[i],++i);return""==s?r:r+"\n"+f(s.Substring(1));};
</code>```

Full program with ungolfed method and test cases:

```<code>using System;

namespace ExplodedSuffixes
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string, string> f = null;
            f = s =>
            {
                var r = "\n";
                for (int i = 0; i < s.Length; )
                    r += new string(s[i], ++i);
                return "" == s ? r : r + f(s.Substring(1));
            };

            // test cases:
            string x = "abcde";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "a";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "bc";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "xyz";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "code-golf";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "s p a c e";
            Console.WriteLine("\'" + x + "\'" + f(x));
        }
    }
}
</code>```

Title: Exploded Suffixes

Body:
C#, 101 bytes

f=s=>{var r="\n";for(int i=0;i<s.Length;)r+=new string(s[i],++i);return""==s?r:r+f(s.Substring(1));};

Recursive anonymous function, which also prints a leading newline. If the leading newline is not allowed, 3 extra bytes turn it into a trailing newline:

f=s=>{var r="";for(int i=0;i<s.Length;)r+=new string(s[i],++i);return""==s?r:r+"\n"+f(s.Substring(1));};

Full program with ungolfed method and test cases:

using System;

namespace ExplodedSuffixes
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string, string> f = null;
            f = s =>
            {
                var r = "\n";
                for (int i = 0; i < s.Length; )
                    r += new string(s[i], ++i);
                return "" == s ? r : r + f(s.Substring(1));
            };

            // test cases:
            string x = "abcde";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "a";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "bc";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "xyz";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "code-golf";
            Console.WriteLine("\'" + x + "\'" + f(x));
            x = "s p a c e";
            Console.WriteLine("\'" + x + "\'" + f(x));
        }
    }
}


答:
05AB1E, 13 bytes

```<code>.sRvyvyN>×}J,
</code>```

Try it online!

Explanation

```<code>.s              # push list of suffixes of input
  R             # reverse the list
   vy           # for each string
     vy   }     # for each char in string
       N>×      # repeat it index+1 times
           J,   # join and print with newline
</code>```

Title: Exploded Suffixes

Body:
05AB1E, 13 bytes

.sRvyvyN>×}J,

Try it online!

Explanation

.s              # push list of suffixes of input
  R             # reverse the list
   vy           # for each string
     vy   }     # for each char in string
       N>×      # repeat it index+1 times
           J,   # join and print with newline


答:
Retina, 31 bytes

Byte count assumes ISO 8859-1 encoding.

```<code>M&!`.+

$.%`$*»
%+r`»($|.)
$1$1
</code>```

Try it online!

Title: Exploded Suffixes

Body:
Retina, 31 bytes

Byte count assumes ISO 8859-1 encoding.

M&!`.+

$.%`$*»
%+r`»($|.)
$1$1

Try it online!


答:
CJam, 14 bytes

```<code>Sl+{_eee~n1>}h
</code>```

Try it online!

Explanation

```<code>Sl+   e# Read input and prepend a space.
{     e# While the string is non-empty...
  _   e#   Make a copy.
  ee  e#   Enumerate. Gives, e.g. [[0 ' ] [1 'a] [2 'b] [3 'c]].
  e~  e#   Run-length decode. Gives "abbccc".
  n   e#   Print with trailing linefeed.
  1>  e#   Discard first character.
}h
</code>```

Title: Exploded Suffixes

Body:
Given an ASCII string, output the exploded suffixes of it. For example, if the string was abcde, there are 5 suffixes, ordered longest to shortest:

```<code>abcde
bcde
cde
de
e
</code>```

Each suffix is then exploded, meaning each character is copied as many times as its one-indexed location in that suffix. For example, exploding the suffixes of abcde,

```<code>abcde
12345
abbcccddddeeeee

bcde
1234
bccdddeeee

cde
123
cddeee

de
12
dee

e
1
e
</code>```

Altogether, the exploded suffixes of abcde are

```<code>abbcccddddeeeee
bccdddeeee
cddeee
dee
e
</code>```

Rules

This is code-golf so the shortest code wins.

The input will consist of the printable ASCII characters. (This excludes newlines but includes spaces.)

The output will have each string on a separate line.

Trailing spaces are allowed on each line and there may be an extra newline at the end.

Test Cases

```<code>''

'a'
a

'bc'
bcc
c

'xyz'
xyyzzz
yzz
z

'code-golf'
coodddeeee-----ggggggooooooollllllllfffffffff
oddeee----gggggoooooolllllllffffffff
dee---ggggooooollllllfffffff
e--gggoooolllllffffff
-ggooollllfffff
goolllffff
ollfff
lff
f

's p a c e'
s  ppp    aaaaa      ccccccc        eeeeeeeee
 pp   aaaa     cccccc       eeeeeeee
p  aaa    ccccc      eeeeeee
 aa   cccc     eeeeee
a  ccc    eeeee
 cc   eeee
c  eee
 ee
e
</code>```

Body:
CJam, 14 bytes

Sl+{_eee~n1>}h

Try it online!

Explanation

Sl+   e# Read input and prepend a space.
{     e# While the string is non-empty...
  _   e#   Make a copy.
  ee  e#   Enumerate. Gives, e.g. [[0 ' ] [1 'a] [2 'b] [3 'c]].
  e~  e#   Run-length decode. Gives "abbccc".
  n   e#   Print with trailing linefeed.
  1>  e#   Discard first character.
}h