问:
Dennis numbers 2.0
PPCG user and elected mod, @Dennis just became the second ever user to earn over 100k rep!

This is a totally original idea, that I did not get from anybody else, but let's make a challenge based off of his user ID, 12012 as a tribute!

Looking at it, you'll notice that there are two distinct "sections" to his ID.

12

and

012

Both of these sections add up to a 3. That's a pretty interesting property.

Let's define a "Dennis 2.0 number" as any positive integer where every maximal subsequence of strictly increasing digits sums to the same number. For example,

```<code>123
</code>```

is a Dennis 2.0 number because there is only one maximal sublist of strictly increasing digits, and it sums to 6. Additionally, 2,846,145 is also a Dennis 2.0 number because the three maximal sublists of increasing digits, namely

```<code>28
46
145
</code>```

All sum to 10. Additionally, numbers that just repeat the same digit must be Dennis 2.0 numbers because, for example, 777 can be broken down into

```<code>7
7
7
</code>```

which clearly all sum to seven.

A number such as 42 is not a Dennis 2.0 number, since it is broken down into

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

which clearly do not sum to the same number.

The challenge

You must write a program or function to determine if a given number is a Dennis 2.0 number or not. You can take input and output in any reasonable input format, e.g. as a string, as a number, from a file, funtion arguments/return, from STDIN/STDOUT, etc. and then return a truthy value if this number is a Dennis 2.0 number, and a falsy value if it is not. For reference, here is every Dennis 2.0 number up to 1,000:

```<code>1
2
3
4
5
6
7
8
9
11
12
13
14
15
16
17
18
19
22
23
24
25
26
27
28
29
33
34
35
36
37
38
39
44
45
46
47
48
49
55
56
57
58
59
66
67
68
69
77
78
79
88
89
99
101
111
123
124
125
126
127
128
129
134
135
136
137
138
139
145
146
147
148
149
156
157
158
159
167
168
169
178
179
189
202
222
234
235
236
237
238
239
245
246
247
248
249
256
257
258
259
267
268
269
278
279
289
303
312
333
345
346
347
348
349
356
357
358
359
367
368
369
378
379
389
404
413
444
456
457
458
459
467
468
469
478
479
489
505
514
523
555
567
568
569
578
579
589
606
615
624
666
678
679
689
707
716
725
734
777
789
808
817
826
835
888
909
918
927
936
945
999
</code>```

Standard loopholes apply, and the shortest answer measured in bytes wins!

答:
Python, 50 bytes

r='0'
for d in input():r=d+'=+'[r<d]*2+r
1/eval(r)
```

Expects input() to evaluate to a string, so the input  needs surrounding quotes in Python 2. Output is via exit code, where 0 indicates success (truthy) and 1 indicates failure (falsy).

Test it on Ideone.

How it works

We initialize r to the string 0 and iterate over all digits d in the input.

If d is larger than the first digit of r (initially 0, then equal to the previous value of d), r<d evaluates to True and '=+'[r<d]*2 yields ++.

If d is smaller than the first digit of r, '=+'[r<d]*2 yields ==.

If d is equal to the first digit of r, r will be longer than the singleton string d, so '=+'[r<d]*2 yields once again ==.

In all cases, the digit d and the two generated characters get prepended to r.

Once all input digits have been processed, eval(r) evaluates the generated expression.

If the input consists of a single strictly increasing sequence of (positive) digits, the expression evaluates to their sum.

For example, the integer 12345 results in the expression 5++4++3++2++1++0, which yields 15 when evaluated. Note that each second + is a unary plus, so it doesn't affect the result. Dividing 1 by 15 is valid (the result is not important); the program exits normally.

If the input consists of two strictly increasing sequences of digits, the expression consists of a simple comparison.

For example, the integer 12012 results in the expression 2++1++0==2++1++0, which yields True when evaluated since both terms have sum 3. Dividing 1 by True (1) is valid (the result is not important); the program exits normally.

On the other hand, the integer 12366 results in the expression 6==6++3++2++1++0, which yields False when evaluated since the terms have sums 6 and 12. Dividing 1 by False (0) raises a ZeroDivisionError; the program exits with an error.

If the input consists of three or more strictly increasing sequences of digits, the expression consists of a chained comparison, which returns True if and only if all involved comparisons return True.

For example, the integer 94536 results in the expression 6++3==5++4==9++0, which yields True when evaluated since all terms have sum 9. As before, the program exits normally.

On the other hand, the integer 17263 results in the expression 3==6++2==7++1++0, which yields False when evaluated since the terms have sums 3, 8, and 8. As before, the program exits with an error.

Title: Dennis numbers 2.0

Body:
Python, 50 bytes

r='0'
for d in input():r=d+'=+'[r<d]*2+r
1/eval(r)

Expects input() to evaluate to a string, so the input  needs surrounding quotes in Python 2. Output is via exit code, where 0 indicates success (truthy) and 1 indicates failure (falsy).

Test it on Ideone.

How it works

We initialize r to the string 0 and iterate over all digits d in the input.

If d is larger than the first digit of r (initially 0, then equal to the previous value of d), r<d evaluates to True and '=+'[r<d]*2 yields ++.

If d is smaller than the first digit of r, '=+'[r<d]*2 yields ==.

If d is equal to the first digit of r, r will be longer than the singleton string d, so '=+'[r<d]*2 yields once again ==.

In all cases, the digit d and the two generated characters get prepended to r.

Once all input digits have been processed, eval(r) evaluates the generated expression.

If the input consists of a single strictly increasing sequence of (positive) digits, the expression evaluates to their sum.

For example, the integer 12345 results in the expression 5++4++3++2++1++0, which yields 15 when evaluated. Note that each second + is a unary plus, so it doesn't affect the result. Dividing 1 by 15 is valid (the result is not important); the program exits normally.

If the input consists of two strictly increasing sequences of digits, the expression consists of a simple comparison.

For example, the integer 12012 results in the expression 2++1++0==2++1++0, which yields True when evaluated since both terms have sum 3. Dividing 1 by True (1) is valid (the result is not important); the program exits normally.

On the other hand, the integer 12366 results in the expression 6==6++3++2++1++0, which yields False when evaluated since the terms have sums 6 and 12. Dividing 1 by False (0) raises a ZeroDivisionError; the program exits with an error.

If the input consists of three or more strictly increasing sequences of digits, the expression consists of a chained comparison, which returns True if and only if all involved comparisons return True.

For example, the integer 94536 results in the expression 6++3==5++4==9++0, which yields True when evaluated since all terms have sum 9. As before, the program exits normally.

On the other hand, the integer 17263 results in the expression 3==6++2==7++1++0, which yields False when evaluated since the terms have sums 3, 8, and 8. As before, the program exits with an error.


问:
A sign showing grouped opening hours of a cafe
You have probably seen these signs on the doors of various shops:

OPENING HOURS

mon-fri 0900-1800

  sat-sun 1100-1530

The task here is to generate a sign like that, grouping consecutive days with the same opening hours, from a list of opening hours for the whole week. Note that the week "wraps around" for what is considered consecutive.

Input:

7 elements, representing the opening hours for each day in a week, starting with Monday.

Each element is a string, on the form XXXX-XXXX

Example input:

```<code>0900-1800 0900-1800 0930-1730 0930-1730 0900-1500 1100-1500 1100-1500
</code>```

It's ok to send the input as an array (for instance as input to a function if you don't read from stdin)

Output:

A list of opening hours, where consecutive days with the same opening hours are shown as a range. Note that sunday (the last day) and monday (the first day) also are consecutive days.

A day where the day doesn't have similar opening hours to the days before or after is printed by itself

Days are specified as three lowercase letters: mon tue wed thu fri sat sun

Remember that first element in the input corresponds to mon, next to tue etc.

Opening hours are shown as in the input

Two examples

```<code>mon-fri 0900-1800, sat-sun 1100-1500
mon-wed 1030-1530, thu 100-1800, fri-sun 1200-1630
</code>```

The output should be sorted, so ranges appear in the order the days do in the week. Monday is preferred to be first, but it may happen it is not first in a group because the week wraps. So in this case tue is the first range.

```<code>tue-fri 0900-1800, sat-mon 1100-1500
</code>```

Don't group unless consecutive, here wednesday and friday have same opening hours but are separated by a Thursday with different opening hours so they are listed by themselves.

```<code>mon-tue 1000-1200, wed 0900-1500, thu 1000-1800, fri 0900-1500, sat-sun 1000-1500
</code>```

The output can be either comma-separated as the examples here, or separated by a newline as in the example on top.

Test cases

First line is input, second line is expected output

```<code>0900-1800 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500 1100-1500
mon-fri 0900-1800, sat-sun 1100-1500

0900-1800 0900-1800 0900-1800 0930-1700 0900-1800 1100-1500 1100-1500
mon-wed 0900-1800, thu 0930-1700, fri 0900-1800, sat-sun 1100-1500

1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500 1100-1500
tue-fri 0900-1800, sat-mon 1100-1500

1100-1500 1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500
wed-sat 0900-1800, sun-tue 1100-1500

1200-1500 1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500
mon 1200-1500, tue 1100-1500, wed-sat 0900-1800, sun 1100-1500
</code>```

Rules

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

答:
JavaScript (ES6), <s>182</s> <s>173</s> <s>170</s> <s>163</s> 157 bytes

Saved 6 bytes with the help of edc65

Takes input as an array of strings and directly prints the result to the console:

h=>{for(D="montuewedthufrisatsun".match(/.../g),d=c=i=j=0;j<8;y=d)h[i]==h[6]?i++:(v=h[d=(i+j++)%7])!=c&&(j>1&&console.log(D[x]+(x-y?'-'+D[y]:''),c),x=d,c=v)}
```

<h3>Formatted and commented</h3>

<pre class="lang-js prettyprint-override"><code>h => {                               // input = list h of opening hours
  for(                               //
    D = "montuewedthufrisatsun"      // D = list of abbreviated names of days
        .match(/.../g),              //
    d =                              // d = current day of week
    c =                              // c = current opening hours
    i =                              // i = first day of week to process
    j = 0;                           // j = day counter
    j < 8;                           // stop when 7 days have been processed
    y = d                            // update y = last day of current day range
  )                                  //
  h[i] == h[6] ?                     // while the opening hours of day #i equal the opening
    i++                              // hours of sunday: increment i
  : (v = h[d = (i + j++) % 7]) != c  // else, if the new opening hours (v) of the current
    && (                             // day (d) doesn't match the current opening hours (c):
      j > 1 &&                       //   if this is not the first iteration:
        console.log(                 //     print:
          D[x] +                     //     - the first day of the current day range (x)
          (x - y ?                   //     - followed by either an empty string
            '-' + D[y]               //       or a '-' and the last day of the range
          : ''),                     //       (if they differ)
          c                          //     - the corresponding opening hours
        ),                           //   (endif)
      x = d,                         //   update x = first day of current day range
      c = v                          //   update c = current opening hours
    )                                // (endif)
}                                    // (end)
</code>```

Test cases

let f =

h=>{for(D="montuewedthufrisatsun".match(/.../g),d=c=i=j=0;j<8;y=d)h[i]==h[6]?i++:(v=h[d=(i+j++)%7])!=c&&(j>1&&console.log(D[x]+(x-y?'-'+D[y]:''),c),x=d,c=v)}

f(["0900-1800", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["0900-1800", "0900-1800", "0900-1800", "0930-1700", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["1100-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500"]);
console.log('-');
f(["1200-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500"]);```

ContentLicense: CC BY-SA 3.0

Body:
JavaScript (ES6), <s>182</s> <s>173</s> <s>170</s> <s>163</s> 157 bytes

Saved 6 bytes with the help of edc65

Takes input as an array of strings and directly prints the result to the console:

h=>{for(D="montuewedthufrisatsun".match(/.../g),d=c=i=j=0;j<8;y=d)h[i]==h[6]?i++:(v=h[d=(i+j++)%7])!=c&&(j>1&&console.log(D[x]+(x-y?'-'+D[y]:''),c),x=d,c=v)}

Formatted and commented

h => {                               // input = list h of opening hours
  for(                               //
    D = "montuewedthufrisatsun"      // D = list of abbreviated names of days
        .match(/.../g),              //
    d =                              // d = current day of week
    c =                              // c = current opening hours
    i =                              // i = first day of week to process
    j = 0;                           // j = day counter
    j < 8;                           // stop when 7 days have been processed
    y = d                            // update y = last day of current day range
  )                                  //
  h[i] == h[6] ?                     // while the opening hours of day #i equal the opening
    i++                              // hours of sunday: increment i
  : (v = h[d = (i + j++) % 7]) != c  // else, if the new opening hours (v) of the current
    && (                             // day (d) doesn't match the current opening hours (c):
      j > 1 &&                       //   if this is not the first iteration:
        console.log(                 //     print:
          D[x] +                     //     - the first day of the current day range (x)
          (x - y ?                   //     - followed by either an empty string
            '-' + D[y]               //       or a '-' and the last day of the range
          : ''),                     //       (if they differ)
          c                          //     - the corresponding opening hours
        ),                           //   (endif)
      x = d,                         //   update x = first day of current day range
      c = v                          //   update c = current opening hours
    )                                // (endif)
}                                    // (end)

Test cases

let f =

h=>{for(D="montuewedthufrisatsun".match(/.../g),d=c=i=j=0;j<8;y=d)h[i]==h[6]?i++:(v=h[d=(i+j++)%7])!=c&&(j>1&&console.log(D[x]+(x-y?'-'+D[y]:''),c),x=d,c=v)}

f(["0900-1800", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["0900-1800", "0900-1800", "0900-1800", "0930-1700", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500"]);
console.log('-');
f(["1100-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500"]);
console.log('-');
f(["1200-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500"]);


答:
Batch, 334 bytes

```<code>@echo off
set/af=l=w=0
set h=%7
call:l mon %1
call:l tue %2
call:l wed %3
call:l thu %4
call:l fri %5
call:l sat %6
call:l sun %7
if not %w%==0 set l=%w%
if %f%==0 set f=mon
call:l 0 0
exit/b
:l
if not %h%==%2 (
if %f%==0 (set w=%l%)else if %f%==%l% (echo %f% %h%)else echo %f%-%l% %h%
set f=%1
set h=%2
)
set l=%1
</code>```

Takes input as command-line parameters, outputs each group on a separate line. Works by comparing each day's hours to the previous day, tracking f as the first day in the group, h as the hours for that group, l as the last day in the group and w for when the last group wraps back to the start of the week. When a mismatch is found the previous group is printed unless week wrapping is in effect. Finally when all the days are processed the last group is adjusted for any week wrapping and whether all the hours turned out to be the same before being output. 0 is used as a placeholder because empty strings cost more bytes to compare in Batch.

Title: A sign showing grouped opening hours of a cafe

Body:
You have probably seen these signs on the doors of various shops:

OPENING HOURS

mon-fri 0900-1800

  sat-sun 1100-1530

The task here is to generate a sign like that, grouping consecutive days with the same opening hours, from a list of opening hours for the whole week. Note that the week "wraps around" for what is considered consecutive.

Input:

7 elements, representing the opening hours for each day in a week, starting with Monday.

Each element is a string, on the form XXXX-XXXX

Example input:

```<code>0900-1800 0900-1800 0930-1730 0930-1730 0900-1500 1100-1500 1100-1500
</code>```

It's ok to send the input as an array (for instance as input to a function if you don't read from stdin)

Output:

A list of opening hours, where consecutive days with the same opening hours are shown as a range. Note that sunday (the last day) and monday (the first day) also are consecutive days.

A day where the day doesn't have similar opening hours to the days before or after is printed by itself

Days are specified as three lowercase letters: mon tue wed thu fri sat sun

Remember that first element in the input corresponds to mon, next to tue etc.

Opening hours are shown as in the input

Two examples

```<code>mon-fri 0900-1800, sat-sun 1100-1500
mon-wed 1030-1530, thu 100-1800, fri-sun 1200-1630
</code>```

The output should be sorted, so ranges appear in the order the days do in the week. Monday is preferred to be first, but it may happen it is not first in a group because the week wraps. So in this case tue is the first range.

```<code>tue-fri 0900-1800, sat-mon 1100-1500
</code>```

Don't group unless consecutive, here wednesday and friday have same opening hours but are separated by a Thursday with different opening hours so they are listed by themselves.

```<code>mon-tue 1000-1200, wed 0900-1500, thu 1000-1800, fri 0900-1500, sat-sun 1000-1500
</code>```

The output can be either comma-separated as the examples here, or separated by a newline as in the example on top.

Test cases

First line is input, second line is expected output

```<code>0900-1800 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500 1100-1500
mon-fri 0900-1800, sat-sun 1100-1500

0900-1800 0900-1800 0900-1800 0930-1700 0900-1800 1100-1500 1100-1500
mon-wed 0900-1800, thu 0930-1700, fri 0900-1800, sat-sun 1100-1500

1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500 1100-1500
tue-fri 0900-1800, sat-mon 1100-1500

1100-1500 1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500
wed-sat 0900-1800, sun-tue 1100-1500

1200-1500 1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500
mon 1200-1500, tue 1100-1500, wed-sat 0900-1800, sun 1100-1500
</code>```

Rules

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

Body:
Batch, 334 bytes

@echo off
set/af=l=w=0
set h=%7
call:l mon %1
call:l tue %2
call:l wed %3
call:l thu %4
call:l fri %5
call:l sat %6
call:l sun %7
if not %w%==0 set l=%w%
if %f%==0 set f=mon
call:l 0 0
exit/b
:l
if not %h%==%2 (
if %f%==0 (set w=%l%)else if %f%==%l% (echo %f% %h%)else echo %f%-%l% %h%
set f=%1
set h=%2
)
set l=%1

Takes input as command-line parameters, outputs each group on a separate line. Works by comparing each day's hours to the previous day, tracking f as the first day in the group, h as the hours for that group, l as the last day in the group and w for when the last group wraps back to the start of the week. When a mismatch is found the previous group is printed unless week wrapping is in effect. Finally when all the days are processed the last group is adjusted for any week wrapping and whether all the hours turned out to be the same before being output. 0 is used as a placeholder because empty strings cost more bytes to compare in Batch.


问:
Surround a string with hashes
I've already made this in Python, but it seems that it could be shortened a lot:

```<code>txt = input("Type something.. ")
c = "#"
b = " "
print(c * (len(txt) + 4))
print(c, b * len(txt), c)
print(c, txt, c)
print(c, b * len(txt), c)
print(c * (len(txt) + 4))
</code>```

So if the user types:

```<code>Hello World
</code>```

The program prints:

```<code>###############
#             #
# Hello World #
#             #
###############
</code>```

Fewest bytes wins—and of course, the answer can be written in any language.

答:
Pyke (noncompetitive), 6 bytes

```<code>.X".X#
</code>```

Try it here!

Pyke was written after the challenge and is therefore noncompetitive.

```<code>.X"    - surround string in spaces
   .X# - surround string in hashes
</code>```

.X takes a string and a string constant arg and surrounds a string with that group of characters. The constant arg can be up to 8 characters and have different effects on how the string is surrounded.

Title: Surround a string with hashes

Body:
Pyke (noncompetitive), 6 bytes

.X".X#

Try it here!

Pyke was written after the challenge and is therefore noncompetitive.

.X"    - surround string in spaces
   .X# - surround string in hashes

.X takes a string and a string constant arg and surrounds a string with that group of characters. The constant arg can be up to 8 characters and have different effects on how the string is surrounded.


答:
JavaScript (ES6), <s>171</s> 169 bytes

```<code>a=>a.map((e,d)=>(d='montuewedthufrisatsun'.substr(d*3,3),e!=h&&(f?o(f):w=l,f=d,h=e),l=d),f='',l=w='sun',h=a[6],o=f=>console.log((f==l?l:f+'-'+l)+' '+h))&&o(f||'mon',l=w)
</code>```

Takes input as an array and outputs to the console on separate lines. This is almost exactly a port of my Batch answer; f now defaults to an empty string of course, while I can also default l and w to 'sun' (using a sentinel value saved me 3 bytes in Batch because I was able to merge the initialisation into the set/a).

Body:
JavaScript (ES6), <s>171</s> 169 bytes

a=>a.map((e,d)=>(d='montuewedthufrisatsun'.substr(d*3,3),e!=h&&(f?o(f):w=l,f=d,h=e),l=d),f='',l=w='sun',h=a[6],o=f=>console.log((f==l?l:f+'-'+l)+' '+h))&&o(f||'mon',l=w)

Takes input as an array and outputs to the console on separate lines. This is almost exactly a port of my Batch answer; f now defaults to an empty string of course, while I can also default l and w to 'sun' (using a sentinel value saved me 3 bytes in Batch because I was able to merge the initialisation into the set/a).


问:
Let's do the Wave!
Input:

A string (the wave-snippet) with a length >= 2.

A positive integer n >= 1.

Output:

We output a single-line wave. We do this by repeating the input string n times.

Challenge rules:

If the first and last character of the input string matches, we only output it once in the total output (i.e. ^_^ of length 2 becomes ^_^_^ and not ^_^^_^).

The input string won't contain any whitespaces/tabs/new-lines/etc.

If your language doesn't support non-ASCII characters, then that's fine. As long as it still complies to the challenge with ASCII-only wave-input.

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

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.

Test cases:

```<code>_.~"(              length 12
_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(

'°º¤o,¸¸,o¤º°'     length 3
'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'

-__                length 1
-__

-__                length 8
-__-__-__-__-__-__-__-__

-__-               length 8
-__-__-__-__-__-__-__-__-

¯`·.¸¸.·´¯         length 24
¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯

**                 length 6
*******

String & length of your own choice (be creative!)
</code>```

答:
Haskell, 59 bytes

```<code>a%b=concat$replicate a b
a@(s:z)#n|s/=last z=n%a|1<2=s:n%z
</code>```

Ungolfed version:

```<code>-- Helper: Appends str to itself n times
n % str = concat (replicate n str)

-- Wave creating function
(x:xs) # n
 -- If start and end of wave differ,
 | x /= last xs = n%(x:xs)
 | otherwise   = x:(n%xs)
</code>```

Title: Let's do the Wave!

Body:
Haskell, 59 bytes

a%b=concat$replicate a b
a@(s:z)#n|s/=last z=n%a|1<2=s:n%z

Ungolfed version:

-- Helper: Appends str to itself n times
n % str = concat (replicate n str)

-- Wave creating function
(x:xs) # n
 -- If start and end of wave differ,
 | x /= last xs = n%(x:xs)
 | otherwise   = x:(n%xs)


问:
Implement a Truth-Machine
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
Zephyr, 41 bytes

```<code>input n
print n
while"1"=n
print n
repeat
</code>```

Try it online!

A main design goal of Zephyr was that code should be readable and understandable. Looks like this holds true even when the code is maximally golfed. Mission accomplished.

Title: Implement a Truth-Machine

Body:
Zephyr, 41 bytes

input n
print n
while"1"=n
print n
repeat

Try it online!

A main design goal of Zephyr was that code should be readable and understandable. Looks like this holds true even when the code is maximally golfed. Mission accomplished.


答:
SpecBAS - 68 bytes

```<code>1 INPUT a$,n: l=LEN a$: ?IIF$(a$(1)<>a$(l),a$*n,a$( TO l-1)*n+a$(l))
</code>```

Uses inline-IF to check if first and last characters are the same.
If not, print string n number of times.
Otherwise, splice the string to length-1, repeat that and put last character at end.

Can only accept ASCII characters (or characters built into SpecBAS IDE)

Title: Let's do the Wave!

Body:
Input:

A string (the wave-snippet) with a length >= 2.

A positive integer n >= 1.

Output:

We output a single-line wave. We do this by repeating the input string n times.

Challenge rules:

If the first and last character of the input string matches, we only output it once in the total output (i.e. ^_^ of length 2 becomes ^_^_^ and not ^_^^_^).

The input string won't contain any whitespaces/tabs/new-lines/etc.

If your language doesn't support non-ASCII characters, then that's fine. As long as it still complies to the challenge with ASCII-only wave-input.

General rules:

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

Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.

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.

Test cases:

```<code>_.~"(              length 12
_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(_.~"(

'°º¤o,¸¸,o¤º°'     length 3
'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'°º¤o,¸¸,o¤º°'

-__                length 1
-__

-__                length 8
-__-__-__-__-__-__-__-__

-__-               length 8
-__-__-__-__-__-__-__-__-

¯`·.¸¸.·´¯         length 24
¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯`·.¸¸.·´¯

**                 length 6
*******

String & length of your own choice (be creative!)
</code>```

Body:
SpecBAS - 68 bytes

1 INPUT a$,n: l=LEN a$: ?IIF$(a$(1)<>a$(l),a$*n,a$( TO l-1)*n+a$(l))

Uses inline-IF to check if first and last characters are the same.
If not, print string n number of times.
Otherwise, splice the string to length-1, repeat that and put last character at end.

Can only accept ASCII characters (or characters built into SpecBAS IDE)


问:
Show off your tree analysing toolbox
As a programmer or computer scientist one might encounter quite a lot of trees - of course not the woody growing-in-the-wrong-direction kind, but the nice, pure mathematical kind:

```<code>  *<- root (also a node)
 /|\<- edge
* * *<- inner node
|  / \
* *   *<- leaf (also a node)
  |
  *
</code>```

Naturally over time we all have put together our own small handy toolbox to analyse such trees as we encounter them, right?
Now is the time to show it off!

Task

The toolbox must include the following functions:

size: The number of nodes in the tree.

depth: The number of edges on the longest path from the root to any leaf.

breadth: The number of leaves.

degree: The maximum number of child nodes for any node.

You have to submit a program or function for each of the tools, however they might share subroutines (e.g. parsing) which then have to be submitted only once. Note that those subroutines need to be full programs or functions too.

Input Format

The trees can be given in any reasonable format capturing the structure, e.g. the tree

```<code>  *
 / \
*   *
</code>```

could be represented through parentheses (()()), lists of lists [[],[]], or data structures with a constructor T[T[],T[]].
However not through linearisation [2,0,0] or a format like (size, depth, breath, degree, whatever-else-is-needed-to-make-this-format-unique-for-every-tree).
Generally speaking, your tree format should not contain numbers.

Output Format

A natural number for each of the properties described above.

Scoring

Lowest code in bytes for the 4 functions in every language wins, thus I will not accept an answer.

Feel free to provide additional tree tools like fold, isBinaryTree, preLinearise, postLinearize, or whatever you like. Of course those don't have to be included in the byte count.

Examples

First the tree is given in the sample formats from above, then the results of the functions as (size, depth, breadth, degree).

```<code>()
[]
T[]
(1,0,1,0)

(()())
[[],[]]
T[T[],T[]]
(3,1,2,2)

((())()((())()))
[[[]],[],[[[]],[]]]
T[T[T[]],T[],T[T[T[]],T[]]]
(8,3,4,3)

((()())((())()((())()))(()())(()))
[[[],[]],[[[]],[],[[[]],[]]],[[],[]],[[]]]
T[T[T[],T[]],T[T[T[]],T[],T[T[T[]],T[]]],T[T[],T[]],T[T[]]]
(17,4,9,4)

((((((((()))))))))
[[[[[[[[[]]]]]]]]]
T[T[T[T[T[T[T[T[T[]]]]]]]]]
(9,8,1,1)

(((((((()()))((()()))))((((()()))((()()))))))((((((()()))((()()))))((((()()))((()())))))))
[[[[[[[[],[]]],[[[],[]]]]],[[[[[],[]]],[[[],[]]]]]]],[[[[[[[],[]]],[[[],[]]]]],[[[[[],[]]],[[[],[]]]]]]]]
T[T[T[T[T[T[T[T[],T[]]],T[T[T[],T[]]]]],T[T[T[T[T[],T[]]],T[T[T[],T[]]]]]]],T[T[T[T[T[T[T[],T[]]],T[T[T[],T[]]]]],T[T[T[T[T[],T[]]],T[T[T[],T[]]]]]]]]
(45,7,16,2)
</code>```

答:
Standard ML, 149 bytes

```<code>val m=Int.max
val% =foldl
fun f?(T%)= ?(map(f?)%)
val s=f(%op+1)
val d=f(fn t=>1+ %m~1t)
val b=f(fn[]=>1|t=> %op+0t)
val g=f(fn t=>m(length t,%m 0t))
</code>```

Try it on Tutorialspoint. Uses the constructor notation (e.g. T[T[],T[]]) with the following data structure declaration: datatype tree = T of tree list

Ungolfed:

```<code>fun fold f (T xs) = f (map (fold f) xs)

val size    = fold (foldl op+ 1)
val depth   = fold (fn t => 1 + foldl Int.max ~1 t)
val breadth = fold (fn nil => 1 | t => foldl op+ 0 t)
val degree  = fold (fn t => Int.max(length t, foldl Int.max 0 t))
</code>```

Title: Show off your tree analysing toolbox

Body:
Standard ML, 149 bytes

val m=Int.max
val% =foldl
fun f?(T%)= ?(map(f?)%)
val s=f(%op+1)
val d=f(fn t=>1+ %m~1t)
val b=f(fn[]=>1|t=> %op+0t)
val g=f(fn t=>m(length t,%m 0t))

Try it on Tutorialspoint. Uses the constructor notation (e.g. T[T[],T[]]) with the following data structure declaration: datatype tree = T of tree list

Ungolfed:

fun fold f (T xs) = f (map (fold f) xs)

val size    = fold (foldl op+ 1)
val depth   = fold (fn t => 1 + foldl Int.max ~1 t)
val breadth = fold (fn nil => 1 | t => foldl op+ 0 t)
val degree  = fold (fn t => Int.max(length t, foldl Int.max 0 t))


问:
pssssssssssssst
Introduction

This is one is pretty straightforward. We will be drawing a snake in ascii. This was inspired by that old snake game where you have to collect the fruit and you continuously grow.

Definition

Given a positive integer N that represents the snake's length, draw a snake so that it has a body of n plus a head and a tail.

Parts:

head:     <, >, ^, v

tail:     @

vertical: |

horizonal: -

All corners should be satisfied with a \ or / respectively. Unless the head ends on a corner in which case the head <, >, ^, v takes priority in the direction the snake is curled. i.e. for the length 1 example, it is turned counter clockwise and so the head is turned that way. For a clockwise solution it would be to the right >.

The snake must start in the middle with its tail but it may go outwards in any direction you choose either clockwise or counter-clockwise. It must also wrap tightly around itself as it expands outwards in a circular fashion.

Example

```<code>/--\
|/\|
||@|
|\-/
\--->
</code>```

Where the @ is the tail and starting position. As seen above the tail starts in the middle, goes up to the left in a counter-clockwise rotation outward.

Here the length is 19 plus a tail and a head.

As another example, here is length 1:

```<code><\
 @

</code>```

Winning

This is code-golf so the answer that is submitted with the smallest number of bytes wins, with time to be used as a tie breaker.

Have fun!

Title: pssssssssssssst

Body:
Perl, <s>111</s> 110 bytes

Includes +1 for -p

Give size on STDIN

snake.pl:

#!/usr/bin/perl -p
s%> %->%+s%\^ %/>%||s/
/
/g+s%.%!s/.$//mg<//&&join"",//g,$/%seg+s/ /^/+y%/\\|>-%\\/\-|%for($\="/
\@
")x$_}{


答:
C#, 116 110 bytes

```<code>s=>{string r="\n".PadLeft(s.Length+5,'#'),p="#".PadRight(s.Length+3,' ')+"#\n";return r+p+"# "+s+" #\n"+p+r;};
</code>```

Ungolfed:

```<code>s=>
{
    string r = "\n".PadLeft(s.Length + 5, '#'),         //the first line, made of '#'s
        p = "#".PadRight(s.Length + 3, ' ') + "#\n";    //the second line
    return r + p + "# " + s + " #\n" + p + r;           //output is simmetrical
};
</code>```

Initial version:

```<code>s=>{int l=s.Length;string r=new string('#',l+4)+"\n",p="#"+new string(' ',l+2)+"#\n";return r+p+"# "+s+" #\n"+p+r;};
</code>```

Full program with test cases:

```<code>using System;

namespace SurroundStringWithHashes
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string,string>f= s=>{int l=s.Length;string r=new string('#',l+4)+"\n",p="#"+new string(' ',l+2)+"#\n";return r+p+"# "+s+" #\n"+p+r;};

            Console.WriteLine(f("Hello World"));
            Console.WriteLine(f("Programming Puzzles & Code Golf"));
        }
    }
}
</code>```

Title: Surround a string with hashes

Body:
I've already made this in Python, but it seems that it could be shortened a lot:

```<code>txt = input("Type something.. ")
c = "#"
b = " "
print(c * (len(txt) + 4))
print(c, b * len(txt), c)
print(c, txt, c)
print(c, b * len(txt), c)
print(c * (len(txt) + 4))
</code>```

So if the user types:

```<code>Hello World
</code>```

The program prints:

```<code>###############
#             #
# Hello World #
#             #
###############
</code>```

Fewest bytes wins—and of course, the answer can be written in any language.

Body:
C#, 116 110 bytes

s=>{string r="\n".PadLeft(s.Length+5,'#'),p="#".PadRight(s.Length+3,' ')+"#\n";return r+p+"# "+s+" #\n"+p+r;};

Ungolfed:

s=>
{
    string r = "\n".PadLeft(s.Length + 5, '#'),         //the first line, made of '#'s
        p = "#".PadRight(s.Length + 3, ' ') + "#\n";    //the second line
    return r + p + "# " + s + " #\n" + p + r;           //output is simmetrical
};

Initial version:

s=>{int l=s.Length;string r=new string('#',l+4)+"\n",p="#"+new string(' ',l+2)+"#\n";return r+p+"# "+s+" #\n"+p+r;};

Full program with test cases:

using System;

namespace SurroundStringWithHashes
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string,string>f= s=>{int l=s.Length;string r=new string('#',l+4)+"\n",p="#"+new string(' ',l+2)+"#\n";return r+p+"# "+s+" #\n"+p+r;};

            Console.WriteLine(f("Hello World"));
            Console.WriteLine(f("Programming Puzzles & Code Golf"));
        }
    }
}


答:
C++, 205 bytes

```<code>#include <string>
std::string g(std::string s){int i,z;if(s=="1")return"11";for(i=z=0;i<s.length();i++)if(s[i]=='1')z++;i--;if(z%2){char c=s[i];s.erase(i);s=g(s);s+=c;}else{s[i]=s[i]==49?48:49;}return s;}
</code>```

Description: Even numbers have even number of ones. Variable z counts ones; if z is even (z mod 2 = z%2 = 0 - else branch), alter the last bit; if z is odd, call this function again without the last character and calculate new value, then append the last character afterwards.

Click here to try it for the test cases.

Title: Incrementing Gray Codes

Body:
Introduction

A Gray Code is an alternative to binary representation in which a number is incremented by toggling only one bit, rather than a variable amount of bits. Here are some gray codes along with their decimal and binary equivalents:

```<code> decimal | binary | gray
-------------------------
       0 |      0 |    0
-------------------------
       1 |      1 |    1
-------------------------
       2 |     10 |   11
-------------------------
       3 |     11 |   10
-------------------------
       4 |    100 |  110
-------------------------
       5 |    101 |  111
-------------------------
       6 |    110 |  101
-------------------------
       7 |    111 |  100
-------------------------
       8 |   1000 | 1100
-------------------------
       9 |   1001 | 1101
-------------------------
      10 |   1010 | 1111
-------------------------
      11 |   1011 | 1110
-------------------------
      12 |   1100 | 1010
-------------------------
      13 |   1101 | 1011
-------------------------
      14 |   1110 | 1001
-------------------------
      15 |   1111 | 1000
</code>```

Cyclic Bit Pattern of a Gray Code

Sometimes called "reflected binary", the property of changing only one bit at a time is easily achieved with cyclic bit patterns for each column starting from the least significant bit:

```<code>bit 0: 0110011001100110011001100110011001100110011001100110011001100110
bit 1: 0011110000111100001111000011110000111100001111000011110000111100
bit 2: 0000111111110000000011111111000000001111111100000000111111110000
bit 3: 0000000011111111111111110000000000000000111111111111111100000000
bit 4: 0000000000000000111111111111111111111111111111110000000000000000
bit 5: 0000000000000000000000000000000011111111111111111111111111111111
</code>```

...and so on.

Objective

Given a non-padded input string of a gray code, increment the gray code by alternating a single character in the sequence or prepending a 1 (when incrementing to the next power of 2), then output the result as a non-padded gray code.

Caveats

Do not worry about taking 0 or an empty string as input.

The lowest input will be 1, and there is no upper-bound to the string length other than memory limitations imposed by the environment.

By non-padded string, I mean there will be no leading or trailing whitespace (other than an optional trailing newline), and no leading 0s in the input or output.

I/O formats

The following formats are accepted form for input and output, but strings are encouraged over other formats:

most significant "bit" first

non-padded character array or string of ASCII '1's and '0's

non-padded integer array of 1s and 0s

non-padded boolean array

What's not allowed:

least significant "bit" first

decimal, binary or unary integer

fixed-length data-structure

character array or string of non-printable ASCII indices 1 and 0

Tests

```<code>input -> output
1 -> 11
11 -> 10
111 -> 101
1011 -> 1001
1111 -> 1110
10111 -> 10110
101100 -> 100100
100000 -> 1100000
</code>```

More tests can be added by request.

Criteria

This is code-golf, so shortest program in bytes wins! All ties will be broken by favoring earlier submissions; standard loopholes apply. The best submitted answer will be accepted October 9th, 2016, and updated whenever better answers are given.

Body:
C++, 205 bytes

#include <string>
std::string g(std::string s){int i,z;if(s=="1")return"11";for(i=z=0;i<s.length();i++)if(s[i]=='1')z++;i--;if(z%2){char c=s[i];s.erase(i);s=g(s);s+=c;}else{s[i]=s[i]==49?48:49;}return s;}

Description: Even numbers have even number of ones. Variable z counts ones; if z is even (z mod 2 = z%2 = 0 - else branch), alter the last bit; if z is odd, call this function again without the last character and calculate new value, then append the last character afterwards.

Click here to try it for the test cases.


问:
Hurricane Matthew and the Lightning Bolts
Challenge

Inspired by this challenge and the nasty Hurricane Matthew, we will be generating some lightning bolts dynamically.

n = 15:

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

Input

Positive Integer n determines the depth of the lightning round.

Rules and Constraints

/ and \ should be used

The probability guiding the lightning's direction is as follow:

25% Splits into 2 paths

25% Path reaches dead end

25% Goes Left

25% Goes Right

There are a few exceptions regarding overlapping and dead end below:

The code should not be deterministic, a new lightning bolt should be generated randomly every time

The bolts should not overlap: e.g. if there is already a bolt to the left of the current bolt, the current bolt should either end or go right, but not go left or split (probability still applies, in this case it become 50%end/50%right)

If there does not exist another available split path, the path should not end: e.g. in the beginning when there is only 1 path, the path should not end until it splits, also applies when there are multiple paths but all except one path are dead, (probability becomes 33%split/33%left/33%right) your goal is to reach the bottom

Whitespaces can be added on the left (all you would need should only be height-1)

However you want to generate the bolt is up to you, you can go from bottom up, left to right, etc. As long as all the rules above are satisfied

Another example

n = 10

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

Stay safe and have fun golfing!
Please golf responsibly only when you are in a safe area!!

答:
JavaScript (ES6), 154 bytes

f=(n,r=[],s=" ".repeat(n)+"/",t=s.replace(/ \/|\\ |\\$/g,_=>"  /  \\/\\".substr(Math.random()*8&6,2)))=>n?/^ +$|\\\//.test(t)?f(n,r,s):f(n-1,[...r,t],t):r```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input type="number" min=1 oninput=o.textContent=f(this.value).join`\n`><pre id=o></code>```

I struggled with the implementation until I saw @TonHospel's answer, at which point it just degenerated into a port. Sample output:

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

Body:
JavaScript (ES6), 154 bytes

f=(n,r=[],s=" ".repeat(n)+"/",t=s.replace(/ \/|\\ |\\$/g,_=>"  /  \\/\\".substr(Math.random()*8&6,2)))=>n?/^ +$|\\\//.test(t)?f(n,r,s):f(n-1,[...r,t],t):r

<input type="number" min=1 oninput=o.textContent=f(this.value).join`\n`><pre id=o>

I struggled with the implementation until I saw @TonHospel's answer, at which point it just degenerated into a port. Sample output:

         /\
        / /\
       /\   \
        /\   \
         /\  /
          / /\
         / / /\
            / /\
            \   \
             \


Title: Surround a string with hashes

Body:
Racket 172 bytes

(λ(s)(let((n(string-length s))(p #\space)(g(λ(l c)(make-string l c))))(display(string-append
(g(+ 4 n)#\#)"\n#"(g(+ 2 n)p)"#\n# "s" #\n#"(g(+ 2 n)p)"#\n"(g(+ 4 n)#\#)))))

Ungolfed:

(define (f s)
  (let ((n (string-length s))
        (p #\space)
        (g (λ (l c) (make-string l c))))
    (display (string-append (g (+ 4 n) #\#)
                            "\n#"
                            (g (+ 2 n) p)
                            "#\n# "
                            s
                            " #\n#"
                            (g (+ 2 n) p)
                            "#\n"
                            (g (+ 4 n) #\#)
                            ))))

Testing:

(f "This is a test" )

Output:

##################
#                #
# This is a test #
#                #
##################


问:
Find the Swirling Words!
Don't ask me how or why but while coding on a project I noticed that the characters of a couple of words had a particular pattern referred to the alphabet, I connected each character of the words with the pencil on the alphabet and I obtained two spirals, then I noticed that the first spiral was clockwise and the other was counterclockwise, and other characteristics... so I named them Swirling Words!

A Swirling Word can be:

clockwise or counterclockwise

centripetal or centrifugal

Here there are some examples of Swirling Words:

Task 1:

Write a full program or function that will take a word from standard input and will output if is a Swirling Word and it's characteristics, in a readable format, extended text, 3 characters, flags, etc.

Test cases and example outputs for different words (but you can decide how to represent the results):

```<code>EARTH, GROUP            > NO        // NOT A SWIRLING WORD
OPERA, STAY, IRIS       > SW,CF,CW  // SWIRLING WORD, CENTRIFUGAL, CLOCKWISE
MINER, TAX, PLUG, META  > SW,CF,CC  // SWIRLING WORD, CENTRIFUGAL, COUNTERCLOCKWISE
AXIOM, AXIS, COOK       > SW,CP,CW  // SWIRLING WORD, CENTRIPETAL, CLOCKWISE
WATCH, YETI, PILL       > SW,CP,CC  // SWIRLING WORD, CENTRIPETAL, COUNTERCLOCKWISE

MORE EXAMPLES OF FALSE TEST CASES (NOT SWIRLING WORDS):
EARTH, GROUP, OUTPUT, WORD, CONNECTION, ODD, MOM, DAD,
CHARACTER, EXAMPLE, QUESTION, NEWSLETTER, OTHER
</code>```

Rules:

The connection between the first two characters must be up (like in the graphics), all the even connection must be down, all the odd connections must be up.

You can ignore upper/lowercase or consider/convert all to upper case or all to lower case.

The input words are only characters in the alphabet range of A-Z, no spaces, no punctuation, etc.

If a word has double characters, like "GROOVE", you must collapse the doubles to one character: "GROOVE" > "GROVE".

The input words will contain at least 3 distinct characters. Words like "MOM", "DAD", "LOL" are not valid words.

It's possible to pass multiple times in the same character, like "IRIS".

Shortest code wins.

Task 2:

To obtain more reputation, find the longest Swirling Words, and it's characteristics, that you can find in the english dictionary, following the above rules. You can take for example as reference the complete list of the english words here.

Happy coding!

答:
Python, 152 bytes:

```<code>lambda C:[C[-1]in max(C)+min(C),C[1]>C[0]]*all([[i>g,i<g][[h%2>0,h%2<1][C[1]>C[0]]]for i,g,h in filter(lambda i:i[0]!=i[1],zip(C,C[1:],range(len(C))))])
</code>```

An anonymous lambda function. Call as print(<Function Name>('<String>')).

Takes input as all lowercase or uppercase, but not mixed case.

Outputs an array containing nothing ([]) if the word is not swirly, or an array in the following format otherwise:

1st element is True/False for Centrifugal/Centripetal.

2nd element is True/False for Clockwise/Counterclockwise.

Try It Online! (Ideone)

Title: Find the Swirling Words!

Body:
Python, 152 bytes:

lambda C:[C[-1]in max(C)+min(C),C[1]>C[0]]*all([[i>g,i<g][[h%2>0,h%2<1][C[1]>C[0]]]for i,g,h in filter(lambda i:i[0]!=i[1],zip(C,C[1:],range(len(C))))])

An anonymous lambda function. Call as print(<Function Name>('<String>')).

Takes input as all lowercase or uppercase, but not mixed case.

Outputs an array containing nothing ([]) if the word is not swirly, or an array in the following format otherwise:

1st element is True/False for Centrifugal/Centripetal.

2nd element is True/False for Clockwise/Counterclockwise.

Try It Online! (Ideone)


答:
APL, 19 bytes

```<code>{⍺,∊1↓⍵⍴⊂⍺↓⍨⊃⍺=⊃⌽⍺}
</code>```

Usage:

```<code>      '^_^' {⍺,∊1↓⍵⍴⊂⍺↓⍨⊃⍺=⊃⌽⍺} 5
^_^_^_^_^_^
</code>```

Explanation:

⊃⍺=⊃⌽⍺: see if the first character matches the last character

⍺↓⍨: if this is the case, drop the first character

⊂: enclose the result

⍵⍴: replicate it ⍵ times

1↓: drop the first one (this is shorter than (⍵-1)⍴)

∊: get all the simple elements (undo the boxing)

⍺,: add one instance of the whole string to the front

Title: Let's do the Wave!

Body:
APL, 19 bytes

{⍺,∊1↓⍵⍴⊂⍺↓⍨⊃⍺=⊃⌽⍺}

Usage:

      '^_^' {⍺,∊1↓⍵⍴⊂⍺↓⍨⊃⍺=⊃⌽⍺} 5
^_^_^_^_^_^

Explanation:

⊃⍺=⊃⌽⍺: see if the first character matches the last character

⍺↓⍨: if this is the case, drop the first character

⊂: enclose the result

⍵⍴: replicate it ⍵ times

1↓: drop the first one (this is shorter than (⍵-1)⍴)

∊: get all the simple elements (undo the boxing)

⍺,: add one instance of the whole string to the front


问:
Print Triangle Wave of Numbers
Given the amplitude and period for a wave, print the wave. See sample output for more details. The total number of wave forms equals the period, and the height of each wave equals the amplitude. Amplitude and Period are less than 10. You can ignore the trailing spaces but not the leading spaces.</p>

```<code>Sample Input
3 2

Sample Output
  3           3
 232         232
12321 12321 12321 12321
       232         232
        3           3
</code>```

ContentLicense: CC BY-SA 2.5

Title: Print Triangle Wave of Numbers

Body:
J, 87 characters

As a program:

b=:]\@(]#~' '~:])(":@:>:@i.@-)
,.~^:(<:Y)(,.|.)@(' ',.~((<:({."1|."1)b),.b),' '$~2<:])X
        Y                                              X

runs like this:

,.~^:(<:2)(,.|.)@(' ',.~((<:({."1|."1)b),.b),' '$~2#<:) 3
  3           3
 232         232
12321 12321 12321 12321
       232         232
        3           3
,.~^:(<:4)(,.|.)@(' ',.~((<:({."1|."1)b),.b),' '$~2#<:) 2
 2       2       2       2       2       2       2       2
121 121 121 121 121 121 121 121 121 121 121 121 121 121 121 121
     2       2       2       2       2       2       2       2

It's 5 more characters if we need it as a function F:

3 F 2
  3           3
 232         232
12321 12321 12321 12321
       232         232
        3           3


问:
Add two numbers
Input: Two integers. Preferably decimal integers, but other forms of numbers can be used. These can be given to the code in standard input, as arguments to the program or function, or as a list.

Output: Their sum. Use the same format for output integers as input integers. For example, the input 5 16 would lead to the output 21.

Restrictions: No standard loopholes please. This is code-golf, answer in lowest amount of bytes wins.

Notes: This should be fairly trivial, however I'm interested to see how it can be implemented. The answer can be a complete program or a function, but please identify which one it is.

Test cases:

```<code>1 2 -> 3
14 15 -> 29
7 9 -> 16
-1 8 -> 7
8 -9 -> -1
-8 -9 -> -17
</code>```

Or as CSV:

```<code>a,b,c
1,2,3
14,15,29
7,9,16
-1,8,7
8,-9,-1
-8,-9,-17
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
C, 19 bytes

```<code>f(a,b){return a+b;}
</code>```

Title: Add two numbers

Body:
C, 19 bytes

f(a,b){return a+b;}


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

Task

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

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

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

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

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

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

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

Additional rules

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

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

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

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

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

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

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

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

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

Catalogue

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
pb, 20 bytes

```<code>^w[B!0]{t[B]vb[T]^>}
</code>```

It will print an input prompt, but I can't do anything about it. This language has no way of supporting infinite input.

Title: Simple cat program

Body:
pb, 20 bytes

^w[B!0]{t[B]vb[T]^>}

It will print an input prompt, but I can't do anything about it. This language has no way of supporting infinite input.


答:
R, 14 bytes

Output stdin, nothing fancy.

```<code>cat(scan(,''))
</code>```

If stdin consists solely of numbers, you can do it in 11 bytes with cat(scan()).

As far as I know, there's no way to handle infinite input.

Title: Simple cat program

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

Task

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

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

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

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

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

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

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

Additional rules

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

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

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

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

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

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

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

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

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

Catalogue

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

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

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

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

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

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

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

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

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

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

Body:
R, 14 bytes

Output stdin, nothing fancy.

cat(scan(,''))

If stdin consists solely of numbers, you can do it in 11 bytes with cat(scan()).

As far as I know, there's no way to handle infinite input.


答:
Lolo, 2 bytes

```<code>Lo
</code>```

Not very interesting for a language only made up of Ls and Os.

It's basically printing whats in the stack. Since there is nothing, it gets the input.

Title: Simple cat program

Body:
Lolo, 2 bytes

Lo

Not very interesting for a language only made up of Ls and Os.

It's basically printing whats in the stack. Since there is nothing, it gets the input.


问:
Turn an Array into a Math Problem
Given a nonempty list of nonnegative integers, consider rewriting it as an arithmetic problem where:

A plus sign (+) is inserted between pairs of numbers that increase from left to right (a.k.a. from the start of the list to the end).

A minus sign (-) is inserted between pairs of numbers that decrease from left to right.

A multiplication sign (*) is inserted between pairs of numbers that are equal.

Said another way: any sublist a,b becomes a+b if a<b, a-b if  a>b, and a*b if a==b.

For example, the list

```<code>[12, 0, 7, 7, 29, 10, 2, 2, 1]
</code>```

would become the expression

```<code>12 - 0 + 7*7 + 29 - 10 - 2*2 - 1
</code>```

which evaluates to 75.

Write a program or function that takes in such a list and evaluates it, printing or returning the result.

Order of operations matters. Multiplications should be done before any addition or subtraction.

If the input list has one number, that should be what it evaluates to. e.g. [64] should give 64.

Use of eval or exec or similar constructs is allowed.

Here are some additional examples:

```<code>[list]
expression
value

[0]
0
0

[1]
1
1

[78557]
78557
78557

[0,0]
0*0
0

[1,1]
1*1
1

[2,2]
2*2
4

[0,1]
0+1
1

[1,0]
1-0
1

[1,2]
1+2
3

[2,1]
2-1
1

[15,4,4]
15-4*4
-1

[9,8,1]
9-8-1
0

[4,2,2,4]
4-2*2+4
4

[10,9,9,12]
10-9*9+12
-59

[1,1,2,2,3,3]
1*1+2*2+3*3
14

[5,5,4,4,3,3]
5*5-4*4-3*3
0

[3,1,4,1,5,9,2,6,5,3,5,9]
3-1+4-1+5+9-2+6-5-3+5+9
29

[7637,388,389,388,387,12,0,0,34,35,35,27,27,2]
7637-388+389-388-387-12-0*0+34+35*35-27*27-2
7379
</code>```

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

答:
R, 92 bytes

There's likely still some good golfing that can be done here.

```<code>eval(parse(t=paste(i<-scan(),c(ifelse(d<-diff(i),ifelse(d>0,"+","-"),"*"),""),collapse="")))
</code>```

Ungolfed:

```<code>i = scan()                # Read list from stdin
d = diff(i)               # Calculate difference between each element of list
s = ifelse(d,             # If d!=0
             ifelse(d>0,  # And if d>1
                    "+",  # Return plus
                    "-"), # Else return minus
             "*")         # Else (i.e. d==0) return multiply.
s = c(s,"")               # Pad the list s with an empty string, so it's the same
                          # length as i
p = paste(i,s,collapse="")# Paste the elements of i and s into one long string.
eval(parse(t=p))          # Evaluate the string as a language object.
</code>```

Title: Turn an Array into a Math Problem

Body:
R, 92 bytes

There's likely still some good golfing that can be done here.

eval(parse(t=paste(i<-scan(),c(ifelse(d<-diff(i),ifelse(d>0,"+","-"),"*"),""),collapse="")))

Ungolfed:

i = scan()                # Read list from stdin
d = diff(i)               # Calculate difference between each element of list
s = ifelse(d,             # If d!=0
             ifelse(d>0,  # And if d>1
                    "+",  # Return plus
                    "-"), # Else return minus
             "*")         # Else (i.e. d==0) return multiply.
s = c(s,"")               # Pad the list s with an empty string, so it's the same
                          # length as i
p = paste(i,s,collapse="")# Paste the elements of i and s into one long string.
eval(parse(t=p))          # Evaluate the string as a language object.


答:
TCL, 28 bytes

```<code>puts -nonewline [read stdin]
</code>```

Title: Simple cat program

Body:
TCL, 28 bytes

puts -nonewline [read stdin]


问:
ASCII PPCG Beta Logo Golf
We shall soon have a new logo & site design, let us use this last breath of the simple times and golf this ASCII version of the speech bubble beta logo:

```<code>+-------------------------------------------+
|    .---------------------------------.    |
|   .EPEpEpBPEpEGCXCgCgCGJgCgP&PWP&P&P&Y`   |
|  .RSRsRWRSRsRsHoNoNONxNONONuJuSUSUSVSUS`  |
|  :o@OTO@O@O@W@IDiDIWiDIDIDWZEZeZEWEZeZE-  |
|  :GWGFGfGFKFGFMEMwMEMEMeXEMZLZLWLZLzLZH-  |
|  :rLRLRLXLRLrLMBMGMGmGXGMGMLzTZLZLZLYLZ-  |
|  :AOAoBOAOAOAYAOAoAoBOAOAoAWZEZEZEVEZEZ-  |
|  :MGVGm!'""'!GRLr!'""'!LRKRS!'""'!uSuSU-  |
|  :XEME' .''% !Gf' .;G% 'GFG' .;P% '&PVP-  |
|  :IDID  !DI! !V! .OPoYOPOP!  -gCGCGHGCG-  |
|  :NONw  ``` .OR! .RWRRRRRR! !ONo* 'ONON-  |
|  :GBGC  !CXCGCP! !POP; !xOP  `IJ; `!IDW-  |
|  :P&P&._!&P&P&F~.____.;GFGF~.____.;eJEM-  |
|  :USUSVSUSuSuTLRlRLRWRLRlRLWMGMGmGwGmGM-  |
|  :ZeWEZEZeZWZeOAOaKAOAOaOwOOAoAOXoAoAOA-  |
|  :wLZLZLzHZLZLGMxMgMGMgBGMGLRLXLRLrLRTr-  |
|  :LZLZLYLZLZLzBMEMEMEyEmEMEfBFGFGfGWGFG-  |
|  :EZEVEZEZeZVZDIdIDYdIdIDIx@O@o@oKO@O@o-  |
|  `SkSuSuSUXUSuONOVONOnONWNOSRSRWRSRSRS-   |
|   `.&P&PVP&P&PCXcGCGCGVGcGCEPYPEpEPE?.-   |
|      ```````````````````:STACKE-`````     |
|                         :XCHA-`           |
|                         :NG-`             |
|           ?=W...HWYWVWB :E`               |
+-------------------------------------------+
</code>```

This is kolmogorov-complexity code-golf, so it's straight forward, output all the text that appears in the above code-block in as few bytes of code as possible, without any funny-business.

input

None

Output

The ASCII content of the code-block above as a return value or printed to STDOUT or equivalent;

carriage returns (13) and/or new lines (10) are acceptable;

a trailing empty line is also allowed.

Update

The original aim of this challenge was to have a puzzle aspect. It seems this has not been noticed, so I have decided to make the puzzle portion significantly easier, but still present, by performing a couple of steps to get you going:

There is a use of the string "STACKEXCHANGE" in the very bottom portion of the speech-bubble.

If one reads the rows of text in the main-portion of the speech-bubble, one might notice an almost repetitive nature of pairs of letters, for example the fourth row reads "GWGFGfGFKFGFMEMwMEMEMeXEMZLZLWLZLzLZH" which is almost "GFGFGFGFGFGFMEMEMEMEMEMEMZLZLZLZLZLZH", except some letters have been changed either to another letter (e.g. the second letter from F to W), to lower-case (e.g. the sixth letter from F to f), or both (e.g. the sixteenth letter from E to w). The rows seem to all conform to such a pattern with a 12-13-12 character split (ignoring the mess of the PPG logo's white space and border).

The process described in (2), once noticed, should be quite easy to undo for the unmasked rows of the speech-bubble (the top six and bottom seven), by first converting the whole text to upper-case and then replacing the odd-ones-out and results in:

```<code>+-------------------------------------------+
|    .---------------------------------.    |
|   .EPEPEPEPEPEGCGCGCGCGCGCGP&P&P&P&P&P`   |
|  .RSRSRSRSRSRSNONONONONONONUSUSUSUSUSUS`  |
|  :O@OTO@O@O@O@IDIDIWIDIDIDIZEZEZEZEZEZE-  |
|  :GFGFGFGFGFGFMEMEMEMEMEMEMZLZLZLZLZLZL-  |
|  :RLRLRLRLRLRLMGMGMGMGMGMGMLZLZLZLZLZLZ-  |
|  :AOAOAOAOAOAOAOAOAOBOAOAOAEZEZEZEZEZEZ-  |
|  :MGVGm!'""'!GRLr!'""'!LRKRS!'""'!uSuSU-  |
|  :XEME' .''% !Gf' .;G% 'GFG' .;P% '&PVP-  |
|  :IDID  !DI! !V! .OPoYOPOP!  -gCGCGHGCG-  |
|  :NONw  ``` .OR! .RWRRRRRR! !ONo* 'ONON-  |
|  :GBGC  !CXCGCP! !POP; !xOP  `IJ; `!IDW-  |
|  :P&P&._!&P&P&F~.____.;GFGF~.____.;eJEM-  |
|  :USUSUSUSUSURLRLRLRLRLRLRLGMGMGMGMGMGM-  |
|  :ZEZEZEZEZEZEOAOAOAOAOAOAOOAOAOAOAOAOA-  |
|  :ZLZLZLZLZLZLGMGMGMGMGMGMGLRLRLRLRLRLR-  |
|  :LZLZLZLZLZLZEMEMEMEMEMEMEFGFGFGFGFGFG-  |
|  :EZEZEZEZEZEZDIDIDIDIDIDID@O@O@O@O@O@O-  |
|  `SUSUSUSUSUSUONONONONONONOSRSRSRSRSRS-   |
|   `.&P&P&P&P&PCGCGCGCGCGCGCEPEPEPEPEP.-   |
|      ```````````````````:STACKE-`````     |
|                         :XCHA-`           |
|                         :NG-`             |
|           ?=W...HWYWVWB :E`               |
+-------------------------------------------+
</code>```

While carrying out (3) one may notice a couple of things. First the least obvious: that the only ?, in the very bottom-right became a P, whereas the extra text at the bottom says ?=W..., and that a large proportion of replaced characters were also W. Second that the odd-ones out in upper-case were B,H,J,K,T,V,W,X,Y. Third that the odd-ones out occurred every seven letters. The second and third observation helps to fill in the middle rows - which, if we remove the PCG mask of spaces and non-letters, non & (used in the top and bottom row) and replace it with the letters yields:

```<code>+-------------------------------------------+
|    .---------------------------------.    |
|   .EPEPEPEPEPEGCGCGCGCGCGCGP&P&P&P&P&P`   |
|  .RSRSRSRSRSRSNONONONONONONUSUSUSUSUSUS`  |
|  :O@O@O@O@O@O@IDIDIWIDIDIDIZEZEZEZEZEZE-  |
|  :GFGFGFGFGFGFMEMEMEMEMEMEMZLZLZLZLZLZL-  |
|  :RLRLRLRLRLRLMGMGMGMGMGMGMLZLZLZLZLZLZ-  |
|  :AOAOAOAOAOAOAOAOAOBOAOAOAEZEZEZEZEZEZ-  |
|  :MGMGMGMGMGMGRLRLRLRLRLRLRSUSUSUSUSUSU-  |
|  :MEMEMEMEMEMEGFGFGFGFGFGFG&P&P&P&P&P&P-  |
|  :IDIDIDIDIDIDOPOPOPOPOPOPOCGCGCGCGCGCG-  |
|  :NONONONONONORRRRRRRRRRRRRONONONONONON-  |
|  :GCGCGCGCGCGCPOPOPOPOPOPOPDIDIDIDIDIDI-  |
|  :P&P&P&P&P&P&FGFGFGFGFGFGFEMEMEMEMEMEM-  |
|  :USUSUSUSUSURLRLRLRLRLRLRLGMGMGMGMGMGM-  |
|  :ZEZEZEZEZEZEOAOAOAOAOAOAOOAOAOAOAOAOA-  |
|  :ZLZLZLZLZLZLGMGMGMGMGMGMGLRLRLRLRLRLR-  |
|  :LZLZLZLZLZLZEMEMEMEMEMEMEFGFGFGFGFGFG-  |
|  :EZEZEZEZEZEZDIDIDIDIDIDID@O@O@O@O@O@O-  |
|  `SUSUSUSUSUSUONONONONONONOSRSRSRSRSRS-   |
|   `.&P&P&P&P&PCGCGCGCGCGCGCEPEPEPEPEP.-   |
|      ```````````````````:STACKE-`````     |
|                         :XCHA-`           |
|                         :NG-`             |
|           ?=W...HWYWVWB :E`               |
+-------------------------------------------+
```

Now reading the columns one can see that the "input" text to make this base grid was PROGRAMMINGPUZZLES&CODEGOLFPROGRAMMINGPUZZLES&CODEGOLF@SE.

The lower-casing and replacement characters are to be determined by you, but also note that the ten remaining letters in the alphabet after removing those present in that string are B,H,J,K,Q,T,V,W,X,Y - the replacements plus Q.

答:
PHP, 780 Bytes

```<code><?=gzinflate(base64_decode("lZRvb9owEMbfT9p3cCq1kYbiDwCaShIcE0hiK2FxkjdNtQY0bSwVVQVDVT/7HpuBYZv2x6e7XKKfD/sem4H372Pw9s0LwaB/JanGXg44ZZI9ssdARx5W4QrGZ4jyRio4rG5POM2L/ClXJj5N+6zPRLaDi+x59lx8gJXw9ogP+7FYiLE2NY4nnyaxgsNUw5quYcpE74RzxSO+5NE84lHK0i2cpV3F0iZpEgXfJ83U4pskh1XwTZIGKU/5mleIabJf6BlNUieNxX3h94HwtdU6//HW+3o1sFJHi6e85GvHvbpyHY5fOGRJPs+LQ/pcYMcWxyqZS6jrXhOHL5GN+DVxsR+dSqQ3spQW110gxJnEDnFKh1Ah+1pIIR1CPCgQ8inc4ujwlpC2bUHmwKGBGZgtsv4dcbUGZ40MeIjq0JOHKOmg8Ig4OyFRI56NSOtAA4trlemdY9SOXukdBpYPEY55N2OpxY86owOLJP8CEVRunuqgwRZ+hjedYkZv1XRo+P1cS3AvtkL3XlS9jr7Ft0a5/VRHnu7SFYquAhQ+aZ0vNhY/6qznBObAsG9sjbgMInOa9Jmy+FHnrimbSfwQT+oHHeMdzmg/7uf6rPYnvC0+F0bnCrtFi0v4V5GpTBS4A/oewDx7m1qqe1iaexNWH7kWsuR4MlnrGybZLT3DiZH05zEsFn44Z555IeQC/80YVuHU99qzL3/GM34B/4LfvleU0qmqVakCNOwSNvjgf/6WvgM="));
</code>```

Maybe helpful maybe not I do not know
I give up to find an other way.
beginning the first line at 1
you could concat lines they have the sum 24 with one letter
starts with the W in the middle go up go left and go reverse the 2 line down then concat the first letter of line 13 with the end of line 11 and go to the middle
now I assume that you must go down to line 14

It seems for me that "?=W...HWYWVWB" is a hint to solve this

Title: ASCII PPCG Beta Logo Golf

Body:
PHP, 780 Bytes

<?=gzinflate(base64_decode("lZRvb9owEMbfT9p3cCq1kYbiDwCaShIcE0hiK2FxkjdNtQY0bSwVVQVDVT/7HpuBYZv2x6e7XKKfD/sem4H372Pw9s0LwaB/JanGXg44ZZI9ssdARx5W4QrGZ4jyRio4rG5POM2L/ClXJj5N+6zPRLaDi+x59lx8gJXw9ogP+7FYiLE2NY4nnyaxgsNUw5quYcpE74RzxSO+5NE84lHK0i2cpV3F0iZpEgXfJ83U4pskh1XwTZIGKU/5mleIabJf6BlNUieNxX3h94HwtdU6//HW+3o1sFJHi6e85GvHvbpyHY5fOGRJPs+LQ/pcYMcWxyqZS6jrXhOHL5GN+DVxsR+dSqQ3spQW110gxJnEDnFKh1Ah+1pIIR1CPCgQ8inc4ujwlpC2bUHmwKGBGZgtsv4dcbUGZ40MeIjq0JOHKOmg8Ig4OyFRI56NSOtAA4trlemdY9SOXukdBpYPEY55N2OpxY86owOLJP8CEVRunuqgwRZ+hjedYkZv1XRo+P1cS3AvtkL3XlS9jr7Ft0a5/VRHnu7SFYquAhQ+aZ0vNhY/6qznBObAsG9sjbgMInOa9Jmy+FHnrimbSfwQT+oHHeMdzmg/7uf6rPYnvC0+F0bnCrtFi0v4V5GpTBS4A/oewDx7m1qqe1iaexNWH7kWsuR4MlnrGybZLT3DiZH05zEsFn44Z555IeQC/80YVuHU99qzL3/GM34B/4LfvleU0qmqVakCNOwSNvjgf/6WvgM="));

Maybe helpful maybe not I do not know
I give up to find an other way.
beginning the first line at 1
you could concat lines they have the sum 24 with one letter
starts with the W in the middle go up go left and go reverse the 2 line down then concat the first letter of line 13 with the end of line 11 and go to the middle
now I assume that you must go down to line 14

It seems for me that "?=W...HWYWVWB" is a hint to solve this


答:
Actually, <s>20</s> <s>19</s> 13 bytes

Based on Martin Ender's Jelly answer with my own version of "cumulative reduce of XOR over the input". Golfing suggestions welcome. Try it online!

```<code>σ1♀&2@¿u;½≈^├
</code>```

Ungolfing

```<code>      Implicit input a as a list, such as [1,0,1,1,0,0].
σ     Get the cumulative sums of a.
1♀&   Map x&1 (equivalent to x%2) over every member of the cumulative sum.
2@¿   Convert from binary to decimal.
u     Increment x.
;½≈   Duplicate and integer divide by 2.
^     XOR x and x//2.
├     Convert to binary to obtain our incremented Gray code.
      Implicit return as a string, such as "100100".
</code>```

Title: Incrementing Gray Codes

Body:
Actually, <s>20</s> <s>19</s> 13 bytes

Based on Martin Ender's Jelly answer with my own version of "cumulative reduce of XOR over the input". Golfing suggestions welcome. Try it online!

σ1♀&2@¿u;½≈^├

Ungolfing

      Implicit input a as a list, such as [1,0,1,1,0,0].
σ     Get the cumulative sums of a.
1♀&   Map x&1 (equivalent to x%2) over every member of the cumulative sum.
2@¿   Convert from binary to decimal.
u     Increment x.
;½≈   Duplicate and integer divide by 2.
^     XOR x and x//2.
├     Convert to binary to obtain our incremented Gray code.
      Implicit return as a string, such as "100100".


问:
Correlation Coefficient of Words
This is going to be relatively quick...

Challenge

Given a lower-case word as input, calculate the Pearson's Correlation Coefficient between the letter position of the word (nth letter within the word, x), and the letter position within the alphabet (nth letter of the alphabet, y).

Background

Pearson's Correlation Coefficient is worked out for data sets x and y, as:

where x and y are the respective data sets as explained above (and further below), and n is the length of the string.

Examples

```<code>  Input: forty
  Output: 0.964406804
</code>```

Explanation:

```<code>  Letters: f o r t y
  Alphabet Number (y): 6 15 18 20 25
  Letter Position (x): 1 2 3 4 5
  Length of word (n): 5
</code>```

Correlation coefficient is worked out from the above formula.

```<code>  Input: bells
  Output: 0.971793199
</code>```

Explanation:

```<code>  Letters: b e l l s
  Alphabet Number (y): 2 5 12 12 19
  Letter Position (x): 1 2 3 4 5
  Length of word (n): 5
</code>```

Correlation coefficient is once again worked out from the above formula.

Rules

Input must provide the word as a lower-case alphabetic string with no spaces (assumed input). The delivery of this string is entirely up to you (file, STDIN, function, array, carrier pigeon, etc.)

Output is in the form of a numeric that will, by the formula, provide r, such that -1 <= r <= 1. Delivery of the output, once again, is entirely up to you.

No silly loop holes

This is not code-golf, as I'm sure there will be many languages that may have native statistical functions. Instead, this will be a popularity contest, so most votes wins here, so make your entry count... I'll be throwing in a bounty for the most creative answer that attracts my attention a little later down the line...

Any questions/comments?

答:
Python 3

Simply uses the formula in the challenge. Doesn't use any libraries like numpy and friends.

from math import sqrt

def correlation_coefficient(word):
  alphabet = 'abcdefghijklmnopqrstuvwxyz'

  x = list(range(len(word)))
  y = list(map(alphabet.index, word))
  n = len(word)

  top = n * sum(a*b for a, b in zip(x, y)) - sum(x) * sum(y)
  bottom = (sqrt(n * sum(a ** 2 for a in x) - sum(x) ** 2)
          * sqrt(n * sum(a ** 2 for a in y) - sum(y) ** 2))

  r = top / bottom
  return r
```

Ideone it!

Title: Correlation Coefficient of Words

Body:
Python 3

Simply uses the formula in the challenge. Doesn't use any libraries like numpy and friends.

from math import sqrt

def correlation_coefficient(word):
  alphabet = 'abcdefghijklmnopqrstuvwxyz'

  x = list(range(len(word)))
  y = list(map(alphabet.index, word))
  n = len(word)

  top = n * sum(a*b for a, b in zip(x, y)) - sum(x) * sum(y)
  bottom = (sqrt(n * sum(a ** 2 for a in x) - sum(x) ** 2)
          * sqrt(n * sum(a ** 2 for a in y) - sum(y) ** 2))

  r = top / bottom
  return r

Ideone it!


答:
BaCon, <s>514</s> <s>496</s> 455 bytes

The BASIC program below is shown with its indentation. But without the indentation it consists of 455 bytes.

The idea is to use the time schedules as indexes to an associative array. Then, each day represents a bit: Monday = bit 0, Tuesday = bit 1, Wednesday = bit 2 and so on. The actual values for the members of the associative array are calculated by the respective bits of the days using a binary OR.

After that, it is a matter of checking how many consecutive bits are present in the associative array members, starting with bit 0.

In case bit 0 and also bit 6 are set, there is a week wrap. In that case, start looking for the start of the next sequence of bits, memorizing this start position. Print the rest of the sequences, and as soon bit 6 is reached, the day range should be ended with the memorized position earlier.

```<code>LOCAL n$[]={"mon","tue","wed","thu","fri","sat","sun"}
GLOBAL p ASSOC int
SUB s(VAR t$ SIZE a)
    FOR i = 0 TO a-1
        p(t$[i])=p(t$[i])|BIT(i)
    NEXT
    LOOKUP p TO c$ SIZE o
    b=e=0
    REPEAT
        FOR i=0 TO o-1
            IF p(c$[i])&BIT(b) THEN
                IF b=0 AND p(c$[i])&65=65 THEN
                    WHILE p(c$[i])&BIT(b)
                        INCR b
                    WEND
                    e=b
                    BREAK
                FI
                ?n$[b];
                r=b
                REPEAT
                    INCR b
                UNTIL NOT(p(c$[i])&BIT(b))
                IF e AND b>6 THEN
                    ?"-",n$[e-1];
                ELIF b-r>1 THEN
                    ?"-",n$[b-1];
                FI
                ?" ",c$[i]
            FI
        NEXT
    UNTIL b>6
    FREE p
ENDSUB
</code>```

Using the following calls to invoke the SUB:

```<code>s("0900-1800", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500")
PRINT "======"
s("0900-1800", "0900-1800", "0900-1800", "0930-1700", "0900-1800", "1100-1500", "1100-1500")
PRINT "======"
s("1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500")
PRINT "======"
s("1100-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500")
PRINT "======"
s("1200-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500")
</code>```

Output:

```<code>mon-fri 0900-1800
sat-sun 1100-1500
======
mon-wed 0900-1800
thu 0930-1700
fri 0900-1800
sat-sun 1100-1500
======
tue-fri 0900-1800
sat-mon 1100-1500
======
wed-sat 0900-1800
sun-tue 1100-1500
======
mon 1200-1500
tue 1100-1500
wed-sat 0900-1800
sun 1100-1500
</code>```

Body:
You have probably seen these signs on the doors of various shops:

OPENING HOURS

mon-fri 0900-1800

  sat-sun 1100-1530

The task here is to generate a sign like that, grouping consecutive days with the same opening hours, from a list of opening hours for the whole week. Note that the week "wraps around" for what is considered consecutive.

Input:

7 elements, representing the opening hours for each day in a week, starting with Monday.

Each element is a string, on the form XXXX-XXXX

Example input:

```<code>0900-1800 0900-1800 0930-1730 0930-1730 0900-1500 1100-1500 1100-1500
</code>```

It's ok to send the input as an array (for instance as input to a function if you don't read from stdin)

Output:

A list of opening hours, where consecutive days with the same opening hours are shown as a range. Note that sunday (the last day) and monday (the first day) also are consecutive days.

A day where the day doesn't have similar opening hours to the days before or after is printed by itself

Days are specified as three lowercase letters: mon tue wed thu fri sat sun

Remember that first element in the input corresponds to mon, next to tue etc.

Opening hours are shown as in the input

Two examples

```<code>mon-fri 0900-1800, sat-sun 1100-1500
mon-wed 1030-1530, thu 100-1800, fri-sun 1200-1630
</code>```

The output should be sorted, so ranges appear in the order the days do in the week. Monday is preferred to be first, but it may happen it is not first in a group because the week wraps. So in this case tue is the first range.

```<code>tue-fri 0900-1800, sat-mon 1100-1500
</code>```

Don't group unless consecutive, here wednesday and friday have same opening hours but are separated by a Thursday with different opening hours so they are listed by themselves.

```<code>mon-tue 1000-1200, wed 0900-1500, thu 1000-1800, fri 0900-1500, sat-sun 1000-1500
</code>```

The output can be either comma-separated as the examples here, or separated by a newline as in the example on top.

Test cases

First line is input, second line is expected output

```<code>0900-1800 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500 1100-1500
mon-fri 0900-1800, sat-sun 1100-1500

0900-1800 0900-1800 0900-1800 0930-1700 0900-1800 1100-1500 1100-1500
mon-wed 0900-1800, thu 0930-1700, fri 0900-1800, sat-sun 1100-1500

1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500 1100-1500
tue-fri 0900-1800, sat-mon 1100-1500

1100-1500 1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500
wed-sat 0900-1800, sun-tue 1100-1500

1200-1500 1100-1500 0900-1800 0900-1800 0900-1800 0900-1800 1100-1500
mon 1200-1500, tue 1100-1500, wed-sat 0900-1800, sun 1100-1500
</code>```

Rules

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

Body:
BaCon, <s>514</s> <s>496</s> 455 bytes

The BASIC program below is shown with its indentation. But without the indentation it consists of 455 bytes.

The idea is to use the time schedules as indexes to an associative array. Then, each day represents a bit: Monday = bit 0, Tuesday = bit 1, Wednesday = bit 2 and so on. The actual values for the members of the associative array are calculated by the respective bits of the days using a binary OR.

After that, it is a matter of checking how many consecutive bits are present in the associative array members, starting with bit 0.

In case bit 0 and also bit 6 are set, there is a week wrap. In that case, start looking for the start of the next sequence of bits, memorizing this start position. Print the rest of the sequences, and as soon bit 6 is reached, the day range should be ended with the memorized position earlier.

LOCAL n$[]={"mon","tue","wed","thu","fri","sat","sun"}
GLOBAL p ASSOC int
SUB s(VAR t$ SIZE a)
    FOR i = 0 TO a-1
        p(t$[i])=p(t$[i])|BIT(i)
    NEXT
    LOOKUP p TO c$ SIZE o
    b=e=0
    REPEAT
        FOR i=0 TO o-1
            IF p(c$[i])&BIT(b) THEN
                IF b=0 AND p(c$[i])&65=65 THEN
                    WHILE p(c$[i])&BIT(b)
                        INCR b
                    WEND
                    e=b
                    BREAK
                FI
                ?n$[b];
                r=b
                REPEAT
                    INCR b
                UNTIL NOT(p(c$[i])&BIT(b))
                IF e AND b>6 THEN
                    ?"-",n$[e-1];
                ELIF b-r>1 THEN
                    ?"-",n$[b-1];
                FI
                ?" ",c$[i]
            FI
        NEXT
    UNTIL b>6
    FREE p
ENDSUB

Using the following calls to invoke the SUB:

s("0900-1800", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500")
PRINT "======"
s("0900-1800", "0900-1800", "0900-1800", "0930-1700", "0900-1800", "1100-1500", "1100-1500")
PRINT "======"
s("1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500", "1100-1500")
PRINT "======"
s("1100-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500")
PRINT "======"
s("1200-1500", "1100-1500", "0900-1800", "0900-1800", "0900-1800", "0900-1800", "1100-1500")

Output:

mon-fri 0900-1800
sat-sun 1100-1500
======
mon-wed 0900-1800
thu 0930-1700
fri 0900-1800
sat-sun 1100-1500
======
tue-fri 0900-1800
sat-mon 1100-1500
======
wed-sat 0900-1800
sun-tue 1100-1500
======
mon 1200-1500
tue 1100-1500
wed-sat 0900-1800
sun 1100-1500


答:
R, 63 bytes

```<code>s=strsplit(scan(,""),"")[[1]];cor(match(s,letters),1:length(s))
</code>```

Ungolfed :

```<code>#Takes the input and splits it, letters by letters
s=strsplit(
           scan(,""),
           "")[[1]];

#Finds the positions of each letters in the lowercase alphabet, and correlates them with
#their position in the word
cor(
    match(s,letters),
    1:length(s)
    )
</code>```

Title: Correlation Coefficient of Words

Body:
This is going to be relatively quick...

Challenge

Given a lower-case word as input, calculate the Pearson's Correlation Coefficient between the letter position of the word (nth letter within the word, x), and the letter position within the alphabet (nth letter of the alphabet, y).

Background

Pearson's Correlation Coefficient is worked out for data sets x and y, as:

where x and y are the respective data sets as explained above (and further below), and n is the length of the string.

Examples

```<code>  Input: forty
  Output: 0.964406804
</code>```

Explanation:

```<code>  Letters: f o r t y
  Alphabet Number (y): 6 15 18 20 25
  Letter Position (x): 1 2 3 4 5
  Length of word (n): 5
</code>```

Correlation coefficient is worked out from the above formula.

```<code>  Input: bells
  Output: 0.971793199
</code>```

Explanation:

```<code>  Letters: b e l l s
  Alphabet Number (y): 2 5 12 12 19
  Letter Position (x): 1 2 3 4 5
  Length of word (n): 5
</code>```

Correlation coefficient is once again worked out from the above formula.

Rules

Input must provide the word as a lower-case alphabetic string with no spaces (assumed input). The delivery of this string is entirely up to you (file, STDIN, function, array, carrier pigeon, etc.)

Output is in the form of a numeric that will, by the formula, provide r, such that -1 <= r <= 1. Delivery of the output, once again, is entirely up to you.

No silly loop holes

This is not code-golf, as I'm sure there will be many languages that may have native statistical functions. Instead, this will be a popularity contest, so most votes wins here, so make your entry count... I'll be throwing in a bounty for the most creative answer that attracts my attention a little later down the line...

Any questions/comments?

Body:
R, 63 bytes

s=strsplit(scan(,""),"")[[1]];cor(match(s,letters),1:length(s))

Ungolfed :

#Takes the input and splits it, letters by letters
s=strsplit(
           scan(,""),
           "")[[1]];

#Finds the positions of each letters in the lowercase alphabet, and correlates them with
#their position in the word
cor(
    match(s,letters),
    1:length(s)
    )