答:
Scala, 165 bytes

```<code>(s:String,r:String)=>r split "AND"map(_ split "TO"map(_.trim.toInt))flatMap{case Array(a,b)=>if(a<b)a to b else a to(b,-1)
case x=>x}map(i=>s lift(i-1)getOrElse "")
</code>```

Explanation:

```<code>(s:String,r:String)=> //define a function
r split "AND"         //split the range expression at every occurance of "AND"
map(                  //map each part...
  _ split "TO"          //split at to
  map(                  //for each of these splitted parts, map them to...
    _.trim.toInt          //trim all whitespace and parse as an int
  )
)                     //now we have an Array[Array[Int]]
flatMap{              //map each inner Array...
  case Array(a,b)=>if(a<b)a to b else a to(b,-1) //if it has two elements, create a Range
  case x=>x             //otherwise just return it
}                     //and flatten, so we get an Array[Int]
map(i=>               //for each int
  s lift(i-1)         //try to get the char with index i-1, since Scala is zero-based
  getOrElse ""        //otherwise return ""
)
</code>```

Title: Interpret loose ranges

Body:
Interpret loose ranges

ListSharp is an interpreted programming language that has many features, one of those features is a 1 index based range creator that works like this:

You define a range as (INT) TO (INT) or just (INT) where both or the single int can go from min to max int32 value

Then you can use those ranges to extract elements of an array without fearing to overstep it's boundaries

therefore:

1 TO 5 generates: {1,2,3,4,5}

3 generates: {3}

Ranges can be added up using the AND operator

1 TO 5 AND 3 TO 6 generates: {1,2,3,4,5,3,4,5,6}

remember this works with negative numbers as well

3 TO -3 generates: {3,2,1,0,-1,-2,-3}

The challenge is the following:

Input

A character array and the previously defined range clause as a string

Output

The elements at the 1 index based locations of the range (non existing/negative indexes translate to an empty character)

How to win

As a code-golf challenge you are supposed to create the program with the shortest byte count to win

It has been pointed out empty characters do not exist, therefore you should be ignoring them (I only showed them here to make it easier to understand yet it confused people)

Test cases:

```<code>input array is:
{'H','e','l','l','o',' ','W','o','r','l','d'}

range clause:
"1 TO 3" => "Hel"
"5" => "o"
"-10 TO 10" => "Hello Worl"
"0 AND 2 AND 4" => "el"
"8 TO 3" => "oW oll"
"-300 AND 300" => ""
"1 TO 3 AND 3 TO 1" => "HelleH"
"-20 TO 0 AND 1 AND 4" => "Hl"
</code>```

Body:
Scala, 165 bytes

(s:String,r:String)=>r split "AND"map(_ split "TO"map(_.trim.toInt))flatMap{case Array(a,b)=>if(a<b)a to b else a to(b,-1)
case x=>x}map(i=>s lift(i-1)getOrElse "")

Explanation:

(s:String,r:String)=> //define a function
r split "AND"         //split the range expression at every occurance of "AND"
map(                  //map each part...
  _ split "TO"          //split at to
  map(                  //for each of these splitted parts, map them to...
    _.trim.toInt          //trim all whitespace and parse as an int
  )
)                     //now we have an Array[Array[Int]]
flatMap{              //map each inner Array...
  case Array(a,b)=>if(a<b)a to b else a to(b,-1) //if it has two elements, create a Range
  case x=>x             //otherwise just return it
}                     //and flatten, so we get an Array[Int]
map(i=>               //for each int
  s lift(i-1)         //try to get the char with index i-1, since Scala is zero-based
  getOrElse ""        //otherwise return ""
)


问:
Yes, of course I'm an adult!
I think we've all done this as a kid: some websites require a minimum age of 18, so we just subtract a few years from the year of birth and voilà, we 'are' 18+.

In addition, for most rides at amusement parks the minimum height to enter is 1.40 meters (here in The Netherlands it as at least). Of course this can be cheated less easily than age, but you could wear shoes with thick heels, put your hair up, wear a hat, stand on your toes, etc.

Input:

Your program/function accepts a positive integer or decimal.

Output:

Is the input an integer >= 18? Simply print the input.

Is the input an integer 0-17? Print 18.

Is the input a decimal >= 1.4? Simply print the input.

Is the input a decimal 0.0-1.4? Print 1.4.

Challenge rules:

Assume the input will always be in the range of 0-122 (oldest woman ever was 122) or 0.0-2.72 (tallest man ever was 2.72).

You are allowed to take the input as a String, object, or anything else you prefer.

The decimal inputs will never have more than three decimal places after the decimal point.

2 or 2. both aren't valid outputs for 2.0. You are free to output 2.00 or 2.000 instead of 2.0 however.

Just like the input the output will never have more than three decimal places after the point.

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>0      ->  18
1      ->  18
2      ->  18
12     ->  18
18     ->  18
43     ->  43
115    ->  115
122    ->  122

0.0    ->  1.4
1.04   ->  1.4
1.225  ->  1.4
1.399  ->  1.4
1.4    ->  1.4
1.74   ->  1.74
2.0    ->  2.0
2.72   ->  2.72
</code>```

答:
Scala, 44 bytes

```<code>def?(x:Int)=18 max x
def?(x:Float)=1.4 max x
</code>```

Defines two methods using overloading.

ContentLicense: CC BY-SA 3.0

Title: Yes, of course I'm an adult!

Body:
Scala, 44 bytes

def?(x:Int)=18 max x
def?(x:Float)=1.4 max x

Defines two methods using overloading.


答:
Java, <s>79</s> 70  bytes

```<code>int f(int x){return x<18?18:x;}
float f(float x){return x<1.4?1.4f:x;}
</code>```

Defines two methods with overloading, which use the conditional operator.

Call it like f(5) or f(1.4f).

Title: Yes, of course I'm an adult!

Body:
I think we've all done this as a kid: some websites require a minimum age of 18, so we just subtract a few years from the year of birth and voilà, we 'are' 18+.

In addition, for most rides at amusement parks the minimum height to enter is 1.40 meters (here in The Netherlands it as at least). Of course this can be cheated less easily than age, but you could wear shoes with thick heels, put your hair up, wear a hat, stand on your toes, etc.

Input:

Your program/function accepts a positive integer or decimal.

Output:

Is the input an integer >= 18? Simply print the input.

Is the input an integer 0-17? Print 18.

Is the input a decimal >= 1.4? Simply print the input.

Is the input a decimal 0.0-1.4? Print 1.4.

Challenge rules:

Assume the input will always be in the range of 0-122 (oldest woman ever was 122) or 0.0-2.72 (tallest man ever was 2.72).

You are allowed to take the input as a String, object, or anything else you prefer.

The decimal inputs will never have more than three decimal places after the decimal point.

2 or 2. both aren't valid outputs for 2.0. You are free to output 2.00 or 2.000 instead of 2.0 however.

Just like the input the output will never have more than three decimal places after the point.

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>0      ->  18
1      ->  18
2      ->  18
12     ->  18
18     ->  18
43     ->  43
115    ->  115
122    ->  122

0.0    ->  1.4
1.04   ->  1.4
1.225  ->  1.4
1.399  ->  1.4
1.4    ->  1.4
1.74   ->  1.74
2.0    ->  2.0
2.72   ->  2.72
</code>```

Body:
Java, <s>79</s> 70  bytes

int f(int x){return x<18?18:x;}
float f(float x){return x<1.4?1.4f:x;}

Defines two methods with overloading, which use the conditional operator.

Call it like f(5) or f(1.4f).


问:
Faux Source Code
Output one random character for each character of source code (as illustrated below). The probability of each character is its frequency in the original source code. Thus the output will be fake source code resembling a quine.

Specification

Restrictions

Standard quine constrains apply. No empty programs or functions. Also no reading your own source.

Output

The number of characters output should be exactly the number of characters in the source code

Each output character should be randomly choosen

The probability of choosing any character is equal to (occurrences in source) / (length of source)

This means that even a unary solution needs to 'randomly' choose 1 with probability 1. Which is to say that the output can't be hard coded.

Winning

This is code golf, so fewest bytes wins

Example

```<code>Program           Frequency           Probability           Possible Output
-------           ---------           -----------           ---------------
 a@!@              a - 1               a - 25%               @@a@
                   ! - 1               ! - 25%
                   @ - 2               @ - 50%
</code>```

```<code>Program           Frequency           Probability           Possible Output
-------           ---------           -----------           ---------------
caBaDBcDaBDB       a - 3               a - 25%               aaaBBBBccDDD
                   B - 4               B - 33%
                   c - 2               c - 17%
                   D - 3               D - 25%
</code>```

答:
Perl 5, 54 bytes

$_=q{print$_[rand@_]for@_="\$_=q{$_};eval"=~/./g};eval
```
<p>Try it online!</p>
<p>Produces output like:</p>
<pre class="lang-perl prettyprint-override"><code>_anr_;q.=fn_}v"_eo_f=n\di{nqde}[;}}o}t==@$@$=nvr$}/r=.
"q}=g{;}=[av$a}a__l[q@@;$;_}./@__a.ne=@@i_}_aet.=$=_o"
/arr_r]po{{l_=;__e"_et=="@vr__a_}@nl"ll~$=~_q~d"=v$~$/
q/@=_$__{f{vl;.]@=__=@lpapr}da@eeg_[$@lr\_{{pq$$$vrq=/
=v{[_l=p{{={/n$nv$n[_/aev_v=@on}la;}q{_otr$oaglve$.a_}
_aa;@r='{{=@{ntf;;.if}f}a$;$g/n;g;_}rroaqra=;}l.gre[t'
</code>```

In a brief test, ~3-4% of the results of the program eval successfully. I'm not sure what that says about Perl...

Title: Faux Source Code

Body:
Perl 5, 54 bytes

$_=q{print$_[rand@_]for@_="\$_=q{$_};eval"=~/./g};eval

Try it online!

Produces output like:

_anr_;q.=fn_}v"_eo_f=n\di{nqde}[;}}o}t==@$@$=nvr$}/r=.
"q}=g{;}=[av$a}a__l[q@@;$;_}./@__a.ne=@@i_}_aet.=$=_o"
/arr_r]po{{l_=;__e"_et=="@vr__a_}@nl"ll~$=~_q~d"=v$~$/
q/@=_$__{f{vl;.]@=__=@lpapr}da@eeg_[$@lr\_{{pq$$$vrq=/
=v{[_l=p{{={/n$nv$n[_/aev_v=@on}la;}q{_otr$oaglve$.a_}
_aa;@r='{{=@{ntf;;.if}f}a$;$g/n;g;_}rroaqra=;}l.gre[t'

In a brief test, ~3-4% of the results of the program eval successfully. I'm not sure what that says about Perl...

ContentLicense: CC BY-SA 4.0


问:
Interpret loose ranges

Interpret loose ranges

ListSharp is an interpreted programming language that has many features, one of those features is a 1 index based range creator that works like this:

You define a range as (INT) TO (INT) or just (INT) where both or the single int can go from min to max int32 value

Then you can use those ranges to extract elements of an array without fearing to overstep it's boundaries

therefore:

1 TO 5 generates: {1,2,3,4,5}

3 generates: {3}

Ranges can be added up using the AND operator

1 TO 5 AND 3 TO 6 generates: {1,2,3,4,5,3,4,5,6}

remember this works with negative numbers as well

3 TO -3 generates: {3,2,1,0,-1,-2,-3}

The challenge is the following:

Input

A character array and the previously defined range clause as a string

Output

The elements at the 1 index based locations of the range (non existing/negative indexes translate to an empty character)

How to win

As a code-golf challenge you are supposed to create the program with the shortest byte count to win

It has been pointed out empty characters do not exist, therefore you should be ignoring them (I only showed them here to make it easier to understand yet it confused people)

Test cases:

```<code>input array is:
{'H','e','l','l','o',' ','W','o','r','l','d'}

range clause:
"1 TO 3" => "Hel"
"5" => "o"
"-10 TO 10" => "Hello Worl"
"0 AND 2 AND 4" => "el"
"8 TO 3" => "oW oll"
"-300 AND 300" => ""
"1 TO 3 AND 3 TO 1" => "HelleH"
"-20 TO 0 AND 1 AND 4" => "Hl"
</code>```

答:
Python 2 - 239 211 210 bytes

Thanks to @mbomb007 and @Cyoce for further golfing this solution!

def r(s):
 t=[]
 for x in s.split("AND"):
  if"T"in x:a=map(int,x.split("TO"));b=2*(a[0]<a[1])-1;t+=range(a[0],a[1]+b,b)
  else:t+=int(x),
 return t
lambda p,v:[(['']+p+['']*max(map(abs,r(v))))[x]for x in r(v)]
```

<p>Straight-forward approach. Tried generators and a recursive version, but they couldn't beat the simple for each loop. I'm a golfing noob, so this can most likely be improved quite a bit. Also, the major flaw of this snippet is that the range as a list object is computed again each time an element is retrieved from the character array (see last line, list comprehension). This means <code>r(s)</code> is executed <code>len(r(s)) + 1</code> times.</p>

<h3>Ungolfed code:</h3>

<pre class="lang-python prettyprint-override"><code>def find_range(string):
    result = []

    # Split at each AND and look at each element separately
    for element in string.split("AND"):
        # Element is just a number, so add that number to the result list
        if "TO" not in string:
            result += [int(string)]

        # Generate a list with all the values in between the boundaries
        # (and the boundaries themselves, of course) and append it to the result list
        else:
            boundaries = map(int, string.split("TO"))
            ascending = boundaries[0] < boundaries[1]

            # range(start, stop, step) returns [start, ..., stop - 1], so extend the stop value accordingly
            # range(8, 3, 1) returns just [], so choose respective step (negative for a descending sequence)
            result += range(boundaries[0], boundaries[1] + (1 if ascending else -1), 1 if ascending else -1)

# Make the char array 1-indexed by appending an empty char in 0th position
# Add enough empty chars at the end so too large and negative values won't wrap around
interpret = lambda chars, range_expr: [(['']+chars+['']*max(map(abs, find_range(range_expr))))[x] for x in find_range(range_expr)]
</code>```

Test cases:

c = list("Hello World")
print interpret(c, "1 TO 3")
print interpret(c, "5")
print interpret(c, "-10 TO 10")
print interpret(c, "0 AND 2 AND 4")
print interpret(c, "8 TO 3")
print interpret(c, "-300 AND 300")
```

<h3>Output:</h3>

<pre class="lang-python prettyprint-override"><code>['H', 'e', 'l']
['o']
['', '', '', '', '', '', '', '', '', '', '', 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l']
['', 'e', 'l']
['o', 'W', ' ', 'o', 'l', 'l']
['', '']
</code>```

Title: Interpret loose ranges

Body:
Python 2 - 239 211 210 bytes

Thanks to @mbomb007 and @Cyoce for further golfing this solution!

def r(s):
 t=[]
 for x in s.split("AND"):
  if"T"in x:a=map(int,x.split("TO"));b=2*(a[0]<a[1])-1;t+=range(a[0],a[1]+b,b)
  else:t+=int(x),
 return t
lambda p,v:[(['']+p+['']*max(map(abs,r(v))))[x]for x in r(v)]

Straight-forward approach. Tried generators and a recursive version, but they couldn't beat the simple for each loop. I'm a golfing noob, so this can most likely be improved quite a bit. Also, the major flaw of this snippet is that the range as a list object is computed again each time an element is retrieved from the character array (see last line, list comprehension). This means r(s) is executed len(r(s)) + 1 times.

Ungolfed code:

def find_range(string):
    result = []

    # Split at each AND and look at each element separately
    for element in string.split("AND"):
        # Element is just a number, so add that number to the result list
        if "TO" not in string:
            result += [int(string)]

        # Generate a list with all the values in between the boundaries
        # (and the boundaries themselves, of course) and append it to the result list
        else:
            boundaries = map(int, string.split("TO"))
            ascending = boundaries[0] < boundaries[1]

            # range(start, stop, step) returns [start, ..., stop - 1], so extend the stop value accordingly
            # range(8, 3, 1) returns just [], so choose respective step (negative for a descending sequence)
            result += range(boundaries[0], boundaries[1] + (1 if ascending else -1), 1 if ascending else -1)

# Make the char array 1-indexed by appending an empty char in 0th position
# Add enough empty chars at the end so too large and negative values won't wrap around
interpret = lambda chars, range_expr: [(['']+chars+['']*max(map(abs, find_range(range_expr))))[x] for x in find_range(range_expr)]

Test cases:

c = list("Hello World")
print interpret(c, "1 TO 3")
print interpret(c, "5")
print interpret(c, "-10 TO 10")
print interpret(c, "0 AND 2 AND 4")
print interpret(c, "8 TO 3")
print interpret(c, "-300 AND 300")

Output:

['H', 'e', 'l']
['o']
['', '', '', '', '', '', '', '', '', '', '', 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l']
['', 'e', 'l']
['o', 'W', ' ', 'o', 'l', 'l']
['', '']


问:
De-Snakify a String
A regular string looks like this:

```<code>Hello,IAmAStringSnake!
</code>```

And a string snake looks something like this:

```<code>Hel
  l      rin
  o,IAmASt g
           S
       !ekan
</code>```

Your Task

String snakes are dangerous, so you must make a program that takes a string snake as input and outputs it as a regular string.

Specifications

Input can be a multiline string or an array of strings.

Each line of the input will be padded with spaces to form a rectangular grid.

Characters in the snake can only connect to adjacent characters above, below, left or right of them (just like in the game Snake). They cannot go diagonal.

The snake characters will never be adjacent to another part of the snake, only the connected characters.

The first character of the string is the end character with the shortest Manhattan distance from the top-left corner of the input grid (i.e. the minimum number of moves it would take for a snake to go directly from the end character to the top-left corner). Both ends will never have the same distance.

The string can contain any ASCII character between code points 33 and 126 inclusive (no spaces or newlines).

The string will be between 2 and 100 characters long.

Shortest code in bytes wins.

Test Cases

(Input grid, followed by the output string)

```<code>Hel
  l      rin
  o,IAmASt g
           S
       !ekan

Hello,IAmAStringSnake!

----------

Python

Python

----------

P  ngPu  Code
r  i  z  d  G
o  m  z  n  o
gram  lesA  lf

ProgrammingPuzzlesAndCodeGolf

----------

   ~ zyx tsr XWVUTSR
   }|{ wvu q Y     Q
!          p Z `ab P
"#$ 6789:; o [ _ c O
  % 5    < n \]^ d N
('& 432  = m     e M
)     1  > lkjihgf L
*+,-./0  ?         K
         @ABCDEFGHIJ

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

----------

  tSyrep
  r    p
  in Sli
   g    Sile
   Snakes  n
Ser      ylt
a eh   ilS
fe w   t
   emo h
     Sre

SlipperyStringSnakesSilentlySlitherSomewhereSafe
</code>```

答:
PHP, <s>199</s> <s>184</s> 182 bytes

may still have a little golfing potential

```<code>for($w=strpos($i=$argv[1],"
");;)for($y=++$n;$y--;)if($i[$p=$y*$w+$n-1]>" ")break 2;for($p-=$d=$w++;$d&&print$i[$p+=$e=$d];)foreach([-$w,-1,1,$w,0]as$d)if($d+$e&&" "<$i[$d+$p])break;
</code>```

takes input as multiline string from command line, expects linux style linebreaks.

Run php -r '' '<string>'; escape linebreaks.

breakdown

```<code>for(
    // find width
    $w=strpos($i=$argv[1],"\n")
    ;
    // find first character: initialize $p(osition)
    ;
)
    for($y=++$n             // increase distance
        ;$y--;)             // loop $y from (old)$n to 0
        if(" "<$i[$p=$y*$w+$n   // if character at $y*($width+1)+$x(=$d-$y) is no space
            -1                  // (adjust for the premature increment)
        ])
            break 2;                    // break loops

for(
    $p-=            // b) reverse the increment that follows in the pre-condition
    $d=             // a) initialize $d to anything!=0 to enable the first iteration
    $w++;           // c) increase $w for easier directions
    $d              // loop while direction is not 0 (cursor has moved)
    &&
    print$i[$p+=$e=$d]              // remember direction, move cursor, print character
    ;
)
    foreach([-$w,-1,1,$w,0]as$d)// loop through directions
        if($d+$e                    // if not opposite previous direction
            &&" "<$i[$d+$p]         // and character in that direction is not space
        )break;                     // break this loop
</code>```

Title: De-Snakify a String

Body:
PHP, <s>199</s> <s>184</s> 182 bytes

may still have a little golfing potential

for($w=strpos($i=$argv[1],"
");;)for($y=++$n;$y--;)if($i[$p=$y*$w+$n-1]>" ")break 2;for($p-=$d=$w++;$d&&print$i[$p+=$e=$d];)foreach([-$w,-1,1,$w,0]as$d)if($d+$e&&" "<$i[$d+$p])break;

takes input as multiline string from command line, expects linux style linebreaks.

Run php -r '<code>' '<string>'; escape linebreaks.

breakdown

for(
    // find width
    $w=strpos($i=$argv[1],"\n")
    ;
    // find first character: initialize $p(osition)
    ;
)
    for($y=++$n             // increase distance
        ;$y--;)             // loop $y from (old)$n to 0
        if(" "<$i[$p=$y*$w+$n   // if character at $y*($width+1)+$x(=$d-$y) is no space
            -1                  // (adjust for the premature increment)
        ])
            break 2;                    // break loops

for(
    $p-=            // b) reverse the increment that follows in the pre-condition
    $d=             // a) initialize $d to anything!=0 to enable the first iteration
    $w++;           // c) increase $w for easier directions
    $d              // loop while direction is not 0 (cursor has moved)
    &&
    print$i[$p+=$e=$d]              // remember direction, move cursor, print character
    ;
)
    foreach([-$w,-1,1,$w,0]as$d)// loop through directions
        if($d+$e                    // if not opposite previous direction
            &&" "<$i[$d+$p]         // and character in that direction is not space
        )break;                     // break this loop


问:
When was this language released?
Your challenge is simple. You need to write a program that prints to either STDOUT or a file the year the language it is written in was released. Because this is such a simple task, the twist is that it must be written in as many different languages as possible.

Your score is the total number of different years that are correctly printed.

For each language you use, you must

Specify which version of the language you are using. (If there are multiple versions)

Specify what year that version was first released, and

Provide a link to a page proving the date of your version/language.

Any one of these counts as release date proof, as long as it specifies the version number (if applicable) and a release date.

A wikipedia page.

An esolangs page.

The language's official website. A github page or similar counts, as long as it has a release date. (Latest commit does not count, unless there is a version number somewhere in the code)

If there are not multiple versions or releases of a language, just use the initial release date of the language.

Minor versions of the same language do count as different languages, as long as they come from different years and still produce the correct output. You may not use any builtins that give you information (including release date) about the current version of the language you are using. For example, this is an invalid python submission:

```<code>import platform
i = platform.python_version()
if i == '3.5':
    print(2015)
if i == '3.4':
    print(2014)
if i == '3.3':
    print(2012)
...
</code>```

Whichever submission correctly prints the most distinct years wins!

Rules

Each program must print out the language year and nothing more. A trailing newline (windows style or *nix style) is allowed.

No programs may take any input.

In case of a tie, the shortest code scored in bytes wins. You may use whatever encoding you like for this, but all programs must use the same encoding.

Any of the programs may print to STDERR, or throw runtime/compile time errors and warnings as long as the correct output is still printed to STDOUT or a file.

Different languages may use different IO methods, but they most all be full programs, (functions not allowed for this challenge) and follow one of our default IO methods allowed.

Happy <s>golfing</s> polyglotting!

答:
8 years, TI-Basic

```<code>Disp 1996           <-- TI-83
Text(-1,1,1,1
ClrHome
Disp 1999           <-- TI-83+ OS 1.03 (initial OS)
sub(1
ClrHome
Disp 2002           <-- TI-83+ OS 1.15
isClockOn
ClrHome
Disp 2004           <-- TI-84+ OS 2.21
invT(e,1
ClrHome
Disp 2005           <-- TI-84+ OS 2.40
CLASSIC
ClrHome
Disp 2009           <-- TI-84+ OS 2.53
BackgroundOn
ClrHome
Disp 2013           <-- TI-84+ Color Silver Edition
Send({1
ClrHome
2015                <-- TI-84+ Color Edition OS 5.1
</code>```

"Any of the programs may print to STDERR, or throw runtime/compile time errors and warnings as long as the correct output is still printed to STDOUT or a file." Currently, the only non-error display is the year, so we are complying with this rule. However, if you'd like to write to the memory instead, replace Disp (date) with (date)->I.

References:

Calculator release dates - https://epsstore.ti.com/OA_HTML/csksxvm.jsp?nSetId=74258

TI-83+ OS 1.15 release date - http://wikiti.brandonw.net/index.php?title=83Plus:OS:VersionDifferences#TIOS_1.15

Calculator compatibility - http://tibasicdev.wikidot.com/compatibility

TI-84+CSE release date - https://www.amazon.com/Texas-Instruments-Silver-Graphing-Calculator/dp/B00AWRQKDC

TI-84+CE release date - http://www.prnewswire.com/news-releases/texas-instruments-unveils-the-new-ti-84-plus-ce-300026266.html and https://www.cemetech.net/forum/viewtopic.php?t=8870

Title: When was this language released?

Body:
8 years, TI-Basic

Disp 1996           <-- TI-83
Text(-1,1,1,1
ClrHome
Disp 1999           <-- TI-83+ OS 1.03 (initial OS)
sub(1
ClrHome
Disp 2002           <-- TI-83+ OS 1.15
isClockOn
ClrHome
Disp 2004           <-- TI-84+ OS 2.21
invT(e,1
ClrHome
Disp 2005           <-- TI-84+ OS 2.40
CLASSIC
ClrHome
Disp 2009           <-- TI-84+ OS 2.53
BackgroundOn
ClrHome
Disp 2013           <-- TI-84+ Color Silver Edition
Send({1
ClrHome
2015                <-- TI-84+ Color Edition OS 5.1

"Any of the programs may print to STDERR, or throw runtime/compile time errors and warnings as long as the correct output is still printed to STDOUT or a file." Currently, the only non-error display is the year, so we are complying with this rule. However, if you'd like to write to the memory instead, replace Disp (date) with (date)->I.

References:

Calculator release dates - https://epsstore.ti.com/OA_HTML/csksxvm.jsp?nSetId=74258

TI-83+ OS 1.15 release date - http://wikiti.brandonw.net/index.php?title=83Plus:OS:VersionDifferences#TIOS_1.15

Calculator compatibility - http://tibasicdev.wikidot.com/compatibility

TI-84+CSE release date - https://www.amazon.com/Texas-Instruments-Silver-Graphing-Calculator/dp/B00AWRQKDC

TI-84+CE release date - http://www.prnewswire.com/news-releases/texas-instruments-unveils-the-new-ti-84-plus-ce-300026266.html and https://www.cemetech.net/forum/viewtopic.php?t=8870


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

答:
MATL, <s>24</s> <s>23</s> <s>20</s> <s>18</s> 16 bytes

```<code>Tjdl<vYsG!UlXQ&=
</code>```

Returns a truthy of falsey matrix

Try it Online!

Also, congrats @Dennis!

Explanation

```<code>T       % Push a literal TRUE to the stack
        %   STACK: {1}
j       % Explicitly grab the input as a string
        %   STACK: {1, '2846145'}
d       % Compute the difference between successive ASCII codes
        %   STACK: {1, [6 -4 2 -5 3 1]}
l<      % Find where that difference is less than 1
        %   STACK: {1, [0 1 0 1 0 0]}
v       % Prepend the TRUE value we pushed previously
        %   STACK: {[1 0 1 0 1 0 0]}
Ys      % Compute the cumulative sum. This assigns a unique integer label to
        % each set of increasing numbers
        %   STACK: {[1 1 2 2 3 3 3]}
G!U     % Grab the input as numeric digits
        %   STACK: {[1 1 2 2 3 3 3], [2 8 4 6 1 4 5]}
lXQ     % Compute the sum of each group of increasing digits
        %   STACK: {[10 10 10]}
&=      % Computes element-wise equality (automatically broadcasts). A
        % truthy value in MATL is a matrix of all ones which is only the case
        % when all elements are equal:
        %   STACK: {[1 1 1
        %            1 1 1
        %            1 1 1]}
        % Implicitly display the result
</code>```

Title: Dennis numbers 2.0

Body:
MATL, <s>24</s> <s>23</s> <s>20</s> <s>18</s> 16 bytes

Tjdl<vYsG!UlXQ&=

Returns a truthy of falsey matrix

Try it Online!

Also, congrats @Dennis!

Explanation

T       % Push a literal TRUE to the stack
        %   STACK: {1}
j       % Explicitly grab the input as a string
        %   STACK: {1, '2846145'}
d       % Compute the difference between successive ASCII codes
        %   STACK: {1, [6 -4 2 -5 3 1]}
l<      % Find where that difference is less than 1
        %   STACK: {1, [0 1 0 1 0 0]}
v       % Prepend the TRUE value we pushed previously
        %   STACK: {[1 0 1 0 1 0 0]}
Ys      % Compute the cumulative sum. This assigns a unique integer label to
        % each set of increasing numbers
        %   STACK: {[1 1 2 2 3 3 3]}
G!U     % Grab the input as numeric digits
        %   STACK: {[1 1 2 2 3 3 3], [2 8 4 6 1 4 5]}
lXQ     % Compute the sum of each group of increasing digits
        %   STACK: {[10 10 10]}
&=      % Computes element-wise equality (automatically broadcasts). A
        % truthy value in MATL is a matrix of all ones which is only the case
        % when all elements are equal:
        %   STACK: {[1 1 1
        %            1 1 1
        %            1 1 1]}
        % Implicitly display the result


答:
15 years, JavaScript

Since JavaScript's release cycle is very unusual and inconsistent, I'm going to use the Firefox implementation. Please let me know if this is not allowed.

Versions: Phoenix 0.1, Firebird 0.6, Firefox 1.0.0, 1.5.0, 2.0.0, 3.0 Beta 1, 3.0.0, 3.5.0, 3.6.0, 4.0.0, 10.0.0, 18.0.0, 27.0.0, 35.0.0, 44.0.0 (all tested on Windows 7)

Important note: Installing and opening Firefox 1.0.0 or any later version may erase all of your saved Firefox data, including history and bookmarks.

Also, starting with 1.0.0, you can only have one version open at a time; trying to open another version results in a new window of the already-open version.

Instructions

Option 1: Save the code below to your computer as an HTML document and open it in each browser.

Option 2: Open https://ethproductions.github.io/js-year-test.html in each browser.

Code

```

Title: When was this language released?

Body:
Your challenge is simple. You need to write a program that prints to either STDOUT or a file the year the language it is written in was released. Because this is such a simple task, the twist is that it must be written in as many different languages as possible.

Your score is the total number of different years that are correctly printed.

For each language you use, you must

Specify which version of the language you are using. (If there are multiple versions)

Specify what year that version was first released, and

Provide a link to a page proving the date of your version/language.

Any one of these counts as release date proof, as long as it specifies the version number (if applicable) and a release date.

A wikipedia page.

An esolangs page.

The language's official website. A github page or similar counts, as long as it has a release date. (Latest commit does not count, unless there is a version number somewhere in the code)

If there are not multiple versions or releases of a language, just use the initial release date of the language.

Minor versions of the same language do count as different languages, as long as they come from different years and still produce the correct output. You may not use any builtins that give you information (including release date) about the current version of the language you are using. For example, this is an invalid python submission:

```<code>import platform
i = platform.python_version()
if i == '3.5':
    print(2015)
if i == '3.4':
    print(2014)
if i == '3.3':
    print(2012)
...
</code>```

Whichever submission correctly prints the most distinct years wins!

Rules

Each program must print out the language year and nothing more. A trailing newline (windows style or *nix style) is allowed.

No programs may take any input.

In case of a tie, the shortest code scored in bytes wins. You may use whatever encoding you like for this, but all programs must use the same encoding.

Any of the programs may print to STDERR, or throw runtime/compile time errors and warnings as long as the correct output is still printed to STDOUT or a file.

Different languages may use different IO methods, but they most all be full programs, (functions not allowed for this challenge) and follow one of our default IO methods allowed.

Happy <s>golfing</s> polyglotting!

Body:
15 years, JavaScript

Since JavaScript's release cycle is very unusual and inconsistent, I'm going to use the Firefox implementation. Please let me know if this is not allowed.

Versions: Phoenix 0.1, Firebird 0.6, Firefox 1.0.0, 1.5.0, 2.0.0, 3.0 Beta 1, 3.0.0, 3.5.0, 3.6.0, 4.0.0, 10.0.0, 18.0.0, 27.0.0, 35.0.0, 44.0.0 (all tested on Windows 7)

Important note: Installing and opening Firefox 1.0.0 or any later version may erase all of your saved Firefox data, including history and bookmarks.

Also, starting with 1.0.0, you can only have one version open at a time; trying to open another version results in a new window of the already-open version.

Instructions

Option 1: Save the code below to your computer as an HTML document and open it in each browser.

Option 2: Open https://ethproductions.github.io/js-year-test.html in each browser.

Code

<script onbeforeunload="123">
// This uses document.write because alert does nothing in Phoenix (Firefox) 0.1.
document.write((function () {
    function assert (code) {
        try {
            eval(code);
            return true;
        } catch (e) {
            return false;
        }
    }

    // Firefox 44 supports octal and binary literals in Number(); Firefox 35 does not.
    if (Number("0o1") === 1)
        return 2016;

    // Firefox 35 supports template strings; Firefox 27 does not.
    if (assert("`abc`"))
        return 2015;

    // Firefox 27 supports argument spreading; Firefox 18 does not.
    if (assert("Math.max(...[1, 2, 3])"))
        return 2014;

    // Firefox 18 supports default arguments; Firefox 10 does not.
    if (assert("function q(a = 1) { }"))
        return 2013;

    // Firefox 10 has basic WeakMap support; Firefox 4 does not.
    if (assert("WeakMap.a"))
        return 2012;

    // Firefox 4 has basic typed array support; Firefox 3.6 does not.
    if (assert("Int8Array.a"))
        return 2011;

    // Firefox 3.6 added the async attribute to script elements.
    if (assert("document.getElementsByTagName('script')[0].async.a"))
        return 2010;

    // Firefox 3.5 added the String.prototype.trim() method.
    if (assert("'abc'.trim()"))
        return 2009;

    // Firefox 3.0 added partial support for object destructuring.
    if (assert("var {c} = {c: 7}"))
        return 2008;

    // Firefox 3.0 beta 1 added the Array.prototype.reduce() and Array.prototype.reduceRight() methods.
    if (assert("[].reduce.a"))
        return 2007;

    // Firefox 2.0 added support for restricted words as properties.
    if (assert("({if:1}).if"))
        return 2006;

    // Firefox 1.5 added the Array.prototype.indexOf() methods, along with a couple other Array methods.
    if (assert("[1].indexOf(1)"))
        return 2005;

    // Practically the only JS difference between v0.6 and v1.0 is the addition of the onbeforeunload event.
    if (assert("document.getElementsByTagName('script')[0].onbeforeunload.a"))
        return 2004;

    // The Object.prototype.eval() method was removed in Firebird 0.6.
    if (!assert("'abc'.eval()"))
        return 2003;

    // We're all the way back to the good old Phoenix 0.1 browser...
    return 2002;
})());
</script>


答:
JavaScript (ES6), 141

Unnamed function with 2 parameters, the first being the character array (can be a string either), the second the string containing the range definition.

The return value is an array where each element can either be a single character or the js value undefined. When stringified, this result in a sequence of comma separated chars having undefined shown as the "empty" char - as the test cases in the first version of the question.

Using .join you can get a string result similar to the test case output in the current version of the question.

(l,r,u,z=[])=>(r+' E').replace(/\S+/g,x=>x>'T'?u=t:x>'A'?[...Array((t-(w=(u=u||t)-(d=+u<t?1:-1)-1)-1)*d)].map(_=>z.push(l[w+=d]),u=0):t=x)&&z
```
<p><em>Less golfed</em></p>
<pre class="lang-js prettyprint-override"><code>(
 l, r, // input paramaters, array/string and string
 u,    // local variable start at 'undefined'
 z=[]  // local variable, will contain the ouput
) =>
  (r+' E') // add an end marker
  .replace( /\S+/g, x=> // execute for each nonspace substring
    x > 'T' // check if 'TO'
    ? u = t // if 'TO' save first value in u (it's a string so even 0 is a truthy value)
    : x > 'A' // check if 'AND' or 'E'
      ? (
          u = u||t, // if u is falsy, it's a single value range t -> t
          d = +u < t ? 1 :-1, // direction of range up or down,comparison has to be numeric, so the leading +
          w = u - d - 1, // starting value (decrement by 1 as js array are 0 based)
          u = 0, // set u to falsy again for next round
          [...Array((t - w - 1) * d)] // build the array of required number of elements
          .map(_ => z.push(l[w+=d])) // iterate adding elements of l to z
        )
      : t = x // if not a keyword, save value in t
  ) && z // return output in z
</code>```

Test

f=
(l,r,u,z=[])=>(r+' E').replace(/\S+/g,x=>x>'T'?u=t:x>'A'?[...Array((t-(w=(u=u||t)-(d=+u<t?1:-1)-1)-1)*d)].map(_=>z.push(l[w+=d]),u=0):t=x)&&z

function run(x)
{
  R.value=x;
  O.textContent=f(L.value,x)
}

run("10 TO 5 AND 5 TO 10")```
<pre class="snippet-code-html lang-html prettyprint-override"><code><table>
<tr><td>Base string</td><td><input id=L value="Hello World"></td></tr>
<tr><td>Custom range</td><td><input id=R ><button onclick='run(R.value)'>-></button></td></tr>
<tr><td>Output</td><td><pre id=O>```

Test case ranges
<select id=T onchange='run(this.value)'>
<option/>
<option value="1 TO 3">1 TO 3 => {'H','e','l'}</option>
<option value="5">5 => {'o'}</option>
<option value="-10 TO 10">-10 TO 10 => {'','','','','','','','','','','','H','e','l','l','o',' ','W','o','r','l'}</option>
<option value="0 AND 2 AND 4">0 AND 2 AND 4 => {'','e','l'}
"8 TO 3" => {'o','W',' ','o','l','l'}</option>
<option value="-300 AND 300">-300 AND 300 => {'',''}</option>
<option value="1 TO 3 AND 3 TO 1">1 TO 3 AND 3 TO 1 => "HelleH"</option>
<option value="-20 TO 0 AND 1 AND 4">-20 TO 0 AND 1 AND 4 => "Hl"</option>
</select>

```

Title: Interpret loose ranges

Body:
JavaScript (ES6), 141

Unnamed function with 2 parameters, the first being the character array (can be a string either), the second the string containing the range definition.

The return value is an array where each element can either be a single character or the js value undefined. When stringified, this result in a sequence of comma separated chars having undefined shown as the "empty" char - as the test cases in the first version of the question.

Using .join you can get a string result similar to the test case output in the current version of the question.

(l,r,u,z=[])=>(r+' E').replace(/\S+/g,x=>x>'T'?u=t:x>'A'?[...Array((t-(w=(u=u||t)-(d=+u<t?1:-1)-1)-1)*d)].map(_=>z.push(l[w+=d]),u=0):t=x)&&z

Less golfed

(
 l, r, // input paramaters, array/string and string
 u,    // local variable start at 'undefined'
 z=[]  // local variable, will contain the ouput
) =>
  (r+' E') // add an end marker
  .replace( /\S+/g, x=> // execute for each nonspace substring
    x > 'T' // check if 'TO'
    ? u = t // if 'TO' save first value in u (it's a string so even 0 is a truthy value)
    : x > 'A' // check if 'AND' or 'E'
      ? (
          u = u||t, // if u is falsy, it's a single value range t -> t
          d = +u < t ? 1 :-1, // direction of range up or down,comparison has to be numeric, so the leading +
          w = u - d - 1, // starting value (decrement by 1 as js array are 0 based)
          u = 0, // set u to falsy again for next round
          [...Array((t - w - 1) * d)] // build the array of required number of elements
          .map(_ => z.push(l[w+=d])) // iterate adding elements of l to z
        )
      : t = x // if not a keyword, save value in t
  ) && z // return output in z

Test

f=
(l,r,u,z=[])=>(r+' E').replace(/\S+/g,x=>x>'T'?u=t:x>'A'?[...Array((t-(w=(u=u||t)-(d=+u<t?1:-1)-1)-1)*d)].map(_=>z.push(l[w+=d]),u=0):t=x)&&z

function run(x)
{
  R.value=x;
  O.textContent=f(L.value,x)
}

run("10 TO 5 AND 5 TO 10")

<table>
<tr><td>Base string</td><td><input id=L value="Hello World"></td></tr>
<tr><td>Custom range</td><td><input id=R ><button onclick='run(R.value)'>-></button></td></tr>
<tr><td>Output</td><td><pre id=O></pre></td></tr>
<tr><td>Test case ranges</td><td>
<select id=T onchange='run(this.value)'>
<option/>
<option value="1 TO 3">1 TO 3 =&gt; {'H','e','l'}</option>
<option value="5">5 =&gt; {'o'}</option>
<option value="-10 TO 10">-10 TO 10 =&gt; {'','','','','','','','','','','','H','e','l','l','o',' ','W','o','r','l'}</option>
<option value="0 AND 2 AND 4">0 AND 2 AND 4 =&gt; {'','e','l'}
"8 TO 3" => {'o','W',' ','o','l','l'}</option>
<option value="-300 AND 300">-300 AND 300 =&gt; {'',''}</option>
<option value="1 TO 3 AND 3 TO 1">1 TO 3 AND 3 TO 1 =&gt; "HelleH"</option>
<option value="-20 TO 0 AND 1 AND 4">-20 TO 0 AND 1 AND 4 =&gt; "Hl"</option>
</select>
</td></tr>
</table>


答:
R, 142 bytes

Assuming I understood the challenge correctly, here I am assuming that r is the pre-defined range clause in string format, and that the input array ("Hello world", in the examples) is read from stdin.

```<code>r=eval(parse(t=paste("c(",gsub("AND",",",gsub("TO",":",r)),")")))
o=strsplit(readline(),e<-"")[[1]][r[r>0]]
o[is.na(o)]=e
c(rep(e,sum(r<1)),o)
</code>```

Some test cases:

```<code>r="1 TO 3"
[1] "H" "e" "l"

r="5"
[1] "o"

r="-10 TO 10"
[1] ""  ""  ""  ""  ""  ""  ""  ""  ""  ""  ""  "H" "e" "l" "l" "o" " " "w" "o" "r" "l"

r="0 AND 2 AND 4"
[1] ""  "e" "l"

r="8 TO 3"
[1] "o" "w" " " "o" "l" "l"

r="-300 AND 300"
[1] "" ""
</code>```

Ungolfed/explained

Line 1

```<code>r=eval(parse(t=paste("c(",gsub("AND",",",gsub("TO",":",r)),")")))
</code>```

R has a nice infix operator : which generates sequences. 1:5 gives [1, 2, 3, 4, 5], and 0:-2 gives [0, -1, -2]. So, we replace the TO in the loose range clause with :.

```<code>                                         gsub("TO",":",r)
</code>```

Interpreting AND is just concatenation. We can use the function c for that, which handily is able to take an arbitrary number of arguments, comma-separated. So we replace AND with ,

```<code>                          gsub("AND",",",      ...       )
</code>```

and then wrap the whole thing in c(, ).

```<code>               paste("c(",              ...               ,")")
</code>```

This yields a character string that could look like c( 1 : 5 , 7 ). We call parse to convert to type "expression" and then eval to evaluate the expression. The resulting sequence of numbers is then re-assigned to the variable r.

```<code>r=eval(parse(t=                     ...                        ))
</code>```

Line 2

```<code>o=strsplit(readline(),e<-"")[[1]][r[r>0]]
</code>```

Now for the ugly part - dealing with strings in R, which gets messy quickly. First we define e to be an empty string (we will need this later).

```<code>                      e<-""
</code>```

We read from stdin and convert the character string to an array of individual characters by splitting at the empty string. (E.g. we go from "Hi" to ["H", "i"].) This returns a list of length 1, so we have to ask for the first element [[1]] to get an array that we can work with. Ugh, I warned you this was messy.

```<code>  strsplit(readline(), ... )[[1]]
</code>```

R indexes beginning at 1, and has a nice feature with negative numbers. Suppose x is ['a', 'b', 'c']. Calling x[1] unsurprisingly returns 'a'. Calling x[-1] returns all of x except index 1, i.e. ['b', 'c']. This is a cool feature, but means that we have to be careful with our negative indices for this problem. So for now, we just return the elements of the input array with index >0, and assign the result to o.

```<code>o=               ...             [r[r>0]]
</code>```

Line 3

However, there's a problem! For indices that are greater than the length of the array, R just returns NA values. We need it to return empty strings. So we redefine the elements of o for which is.na(o) is TRUE to be the empty string.

```<code>o[is.na(o)]=e
</code>```

Line 4

```<code>c(rep(e,sum(r<1)),o)
</code>```

Finally, how do we deal with the negative (and zero) indices? They all need to return the empty string, so we repeat the empty string N times, where N is the number of indices that are <1.

```<code>  rep(e,sum(r<1))
</code>```

Finally, we concatenate the previously-defined o to this (potentially empty) list.

```<code>c(      ...      ,o)
</code>```

Title: Interpret loose ranges

Body:
R, 142 bytes

Assuming I understood the challenge correctly, here I am assuming that r is the pre-defined range clause in string format, and that the input array ("Hello world", in the examples) is read from stdin.

r=eval(parse(t=paste("c(",gsub("AND",",",gsub("TO",":",r)),")")))
o=strsplit(readline(),e<-"")[[1]][r[r>0]]
o[is.na(o)]=e
c(rep(e,sum(r<1)),o)

Some test cases:

r="1 TO 3"
[1] "H" "e" "l"

r="5"
[1] "o"

r="-10 TO 10"
[1] ""  ""  ""  ""  ""  ""  ""  ""  ""  ""  ""  "H" "e" "l" "l" "o" " " "w" "o" "r" "l"

r="0 AND 2 AND 4"
[1] ""  "e" "l"

r="8 TO 3"
[1] "o" "w" " " "o" "l" "l"

r="-300 AND 300"
[1] "" ""

Ungolfed/explained

Line 1

r=eval(parse(t=paste("c(",gsub("AND",",",gsub("TO",":",r)),")")))

R has a nice infix operator : which generates sequences. 1:5 gives [1, 2, 3, 4, 5], and 0:-2 gives [0, -1, -2]. So, we replace the TO in the loose range clause with :.

                                         gsub("TO",":",r)

Interpreting AND is just concatenation. We can use the function c for that, which handily is able to take an arbitrary number of arguments, comma-separated. So we replace AND with ,

                          gsub("AND",",",      ...       )

and then wrap the whole thing in c(, ).

               paste("c(",              ...               ,")")

This yields a character string that could look like c( 1 : 5 , 7 ). We call parse to convert to type "expression" and then eval to evaluate the expression. The resulting sequence of numbers is then re-assigned to the variable r.

r=eval(parse(t=                     ...                        ))

Line 2

o=strsplit(readline(),e<-"")[[1]][r[r>0]]

Now for the ugly part - dealing with strings in R, which gets messy quickly. First we define e to be an empty string (we will need this later).

                      e<-""

We read from stdin and convert the character string to an array of individual characters by splitting at the empty string. (E.g. we go from "Hi" to ["H", "i"].) This returns a list of length 1, so we have to ask for the first element [[1]] to get an array that we can work with. Ugh, I warned you this was messy.

  strsplit(readline(), ... )[[1]]

R indexes beginning at 1, and has a nice feature with negative numbers. Suppose x is ['a', 'b', 'c']. Calling x[1] unsurprisingly returns 'a'. Calling x[-1] returns all of x except index 1, i.e. ['b', 'c']. This is a cool feature, but means that we have to be careful with our negative indices for this problem. So for now, we just return the elements of the input array with index >0, and assign the result to o.

o=               ...             [r[r>0]]

Line 3

However, there's a problem! For indices that are greater than the length of the array, R just returns NA values. We need it to return empty strings. So we redefine the elements of o for which is.na(o) is TRUE to be the empty string.

o[is.na(o)]=e

Line 4

c(rep(e,sum(r<1)),o)

Finally, how do we deal with the negative (and zero) indices? They all need to return the empty string, so we repeat the empty string N times, where N is the number of indices that are <1.

  rep(e,sum(r<1))

Finally, we concatenate the previously-defined o to this (potentially empty) list.

c(      ...      ,o)


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

Challenge:

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

Test cases (true)

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

Test cases (false)

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

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

答:
Groovy (<s>85</s> 73 Bytes)

```<code>f={n->x=n.collect{[it,it]}.flatten().collate(n.size())*.sum();x[0]==x[1]}
</code>```

.collect{[it,it]} - Dupe all elements into a 2D array.

.flatten() - Turn 2D array into 1D array.

.collate(n.size()) - Split new array in half.

*.sum() - Sum both sub-arrays.

x[0]==x[1] - Check for equality / return.

Title: Is it a balanced number?

Body:
Groovy (<s>85</s> 73 Bytes)

f={n->x=n.collect{[it,it]}.flatten().collate(n.size())*.sum();x[0]==x[1]}

.collect{[it,it]} - Dupe all elements into a 2D array.

.flatten() - Turn 2D array into 1D array.

.collate(n.size()) - Split new array in half.

*.sum() - Sum both sub-arrays.

x[0]==x[1] - Check for equality / return.


答:
Jelly, <s>13</s> 12 bytes

1 byte thanks to @Dennis.

```<code>DIṠ’0;œṗDS€E
</code>```

Try it online!

Explanation

```<code>DIṠ’0;œṗDS€E    Main link. Argument: N
D               Convert N to its digits.
 I              Find the differences between the elements.
  Ṡ             Find the sign of each difference. This yields 1 for locations where the
                list is strictly increasing and 0 or -1 elsewhere.
   ’            Decrement. This yields 0 for locations where the list is strictly
                increasing and -1 or -2 elsewhere.
    0;          Prepend a 0.
        D       Get another list of digits.
      œṗ        Split the list of digits at truthy positions, i.e. the -1s and -2s.
         S€     Sum each sublist.
           E    Check if all values are equal.
</code>```

Title: Dennis numbers 2.0

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

Body:
Jelly, <s>13</s> 12 bytes

1 byte thanks to @Dennis.

DIṠ’0;œṗDS€E

Try it online!

Explanation

DIṠ’0;œṗDS€E    Main link. Argument: N
D               Convert N to its digits.
 I              Find the differences between the elements.
  Ṡ             Find the sign of each difference. This yields 1 for locations where the
                list is strictly increasing and 0 or -1 elsewhere.
   ’            Decrement. This yields 0 for locations where the list is strictly
                increasing and -1 or -2 elsewhere.
    0;          Prepend a 0.
        D       Get another list of digits.
      œṗ        Split the list of digits at truthy positions, i.e. the -1s and -2s.
         S€     Sum each sublist.
           E    Check if all values are equal.


答:
PowerShell v2+, <s>100</s> <s>64</s> 61 bytes

```<code>-join([char[]]$args[0]|%{("+$_","-eq$_")[$_-le$i];$i=$_})|iex
</code>```

A literal one-liner, as this is all one pipeline. Takes input as a string $args[0]. Loops through it as a char-array, each iteration placing either the current element with a + or -eq in front of it onto the pipeline based on whether the current value is -less-than-or-equal to the previous value $i. Those strings are -joined together and piped to iex (short for Invoke-Expression and similar to eval. For example, for input 2846145 this will be evaluated as +2+8-eq4+6-eq1+4+5, which is True.

That Boolean is left on the pipeline, and True/False is implicitly written at program completion.

NB - for single-digit input, the resulting digit is left on the pipeline, which is a truthy value in PowerShell.

Examples

```<code>PS C:\Tools\Scripts\golfing> 2846145,681,777,12366,2|%{"$_ -> "+(.\dennis-number-20.ps1 "$_")}
2846145 -> True
681 -> False
777 -> True
12366 -> False
2 -> 2
</code>```

Title: Dennis numbers 2.0

Body:
PowerShell v2+, <s>100</s> <s>64</s> 61 bytes

-join([char[]]$args[0]|%{("+$_","-eq$_")[$_-le$i];$i=$_})|iex

A literal one-liner, as this is all one pipeline. Takes input as a string $args[0]. Loops through it as a char-array, each iteration placing either the current element with a + or -eq in front of it onto the pipeline based on whether the current value is -less-than-or-equal to the previous value $i. Those strings are -joined together and piped to iex (short for Invoke-Expression and similar to eval. For example, for input 2846145 this will be evaluated as +2+8-eq4+6-eq1+4+5, which is True.

That Boolean is left on the pipeline, and True/False is implicitly written at program completion.

NB - for single-digit input, the resulting digit is left on the pipeline, which is a truthy value in PowerShell.

Examples

PS C:\Tools\Scripts\golfing> 2846145,681,777,12366,2|%{"$_ -> "+(.\dennis-number-20.ps1 "$_")}
2846145 -> True
681 -> False
777 -> True
12366 -> False
2 -> 2


答:
JavaScript (ES6), <s>66</s> <s>65</s> 63 bytes

Saved 2 bytes thanks to @edc65

```<code>x=>[...x,p=t=z=0].every(c=>p>=(t+=+p,p=c)?(z?z==t:z=t)+(t=0):1)
</code>```

Takes input as a string. Old version (only works in Firefox 30+):

```<code>x=>[for(c of(p=t=0,x))if(p>=(t+=+p,p=c))t+(t=0)].every(q=>q==+p+t)
</code>```

Title: Dennis numbers 2.0

Body:
JavaScript (ES6), <s>66</s> <s>65</s> 63 bytes

Saved 2 bytes thanks to @edc65

x=>[...x,p=t=z=0].every(c=>p>=(t+=+p,p=c)?(z?z==t:z=t)+(t=0):1)

Takes input as a string. Old version (only works in Firefox 30+):

x=>[for(c of(p=t=0,x))if(p>=(t+=+p,p=c))t+(t=0)].every(q=>q==+p+t)


答:
Pyke, 18 bytes

```<code>mb$1m>0R+fMbms}lt!
</code>```

Try it here!

```<code>mb                 -         map(int, input)
  $                -        delta(^)
   1m>             -       map(^, 1>i)
      0R+          -      [0]+^
         f         -     input.split_at(^)
          Mb       -    deep_map(int, ^)
            ms     -   map(sum, ^)
              }    -  uniquify(^)
               lt! - len(^) == 1
</code>```

Title: Dennis numbers 2.0

Body:
Pyke, 18 bytes

mb$1m>0R+fMbms}lt!

Try it here!

mb                 -         map(int, input)
  $                -        delta(^)
   1m>             -       map(^, 1>i)
      0R+          -      [0]+^
         f         -     input.split_at(^)
          Mb       -    deep_map(int, ^)
            ms     -   map(sum, ^)
              }    -  uniquify(^)
               lt! - len(^) == 1


答:
Brachylog, 13 bytes

```<code>~c@e:{<+}a!#=
</code>```

Try it online!

Explanation

```<code>~c               Find a list of integers which when concatenated result in the Input
  @e             Split the integers into lists of digits
    :{<+}a       Each list of digit is stricly increasing, and compute its sum
          !      Discard all other choice points (prevents backtracking for smaller sublists)
           #=    All sums must be equal
</code>```

~c will unify with the biggest sublists first.

Title: Dennis numbers 2.0

Body:
Brachylog, 13 bytes

~c@e:{<+}a!#=

Try it online!

Explanation

~c               Find a list of integers which when concatenated result in the Input
  @e             Split the integers into lists of digits
    :{<+}a       Each list of digit is stricly increasing, and compute its sum
          !      Discard all other choice points (prevents backtracking for smaller sublists)
           #=    All sums must be equal

~c will unify with the biggest sublists first.


问:
Convert pointfree to pointful
Being a Haskell hacker, I prefer pointfree notation over pointful. Unfortunately some people find pointfree notation hard to read, and I find it hard to get the correct number of parentheses when I write in pointful.
Help me convert code written in pointfree to pointful notation!

About

In pointfree notation we use points (yes, really) to feed the output of one function into another. Say, if you had a function succ that takes a number and adds 1 to it, and you wanted to make a function that adds 3 to a number, instead of doing this:

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

you could do this:

```<code>succ.succ.succ
</code>```

Pointfree only works with functions that take a single parameter however (in this challenge anyway), so if our function wasn't succ but rather add which take 2 numbers and adds them together, we would have to feed it arguments until there is only one left:

```<code>pointful:  \x -> add 1(add 1(add 1 x))
pointfree: add 1 . add 1 . add 1
</code>```

Lastly, functions may take other functions as arguments:

```<code>Pointfree: map (f a . f b) . id
Pointful:  \x -> map (\x -> f a (f b x)) (id x)

Javascript equivalent: x => map (x => f(a,f(b,x)), id(x))
</code>```

Input and expected output

```<code>f . f . f
\x -> f (f (f x))

f a . f b . f c
\x -> f a (f b (f c x))

f (f a . f b) . f c
\x -> f (\x -> f a (f b x)) (f c x)

a b c . d e . f g h i . j k l . m
\x -> a b c (d e (f g h i (j k l (m x))))

a.b(c.d)e.f g(h)(i j.k).l(m(n.o).p)
\x->a(b(\y->c(d y))e(f g h(\z->i j(k z))(l(\q->m(\w->n(o w))(p q))x)))
</code>```

Rules

Your output may have more spaces or parentheses than required, as long as they are balanced

You don't have to make sure that the name of the variable you create \x isn't already used somewhere else in the code

It is your choice whether to create a function or a full program

This is codegolf, shortest code in bytes win!

You might find blunt useful, it converts between the two notations (but also factorizes the code when possible): https://blunt.herokuapp.com

Title: Convert pointfree to pointful

Body:
Haskell, <s>163 142</s> 133 bytes

p(x:r)|[a,b]<-p r=case[x]of"("->["(\\x->"++a++p b!!0,""];"."->['(':a++")",b];")"->[" x)",r];_->[x:a,b]
p r=[r,r]
f s=p('(':s++")")!!0

Try it on Ideone.

Ungolfed:

p('(':r)|(a,b)<-p r = ("(\\x->"++a++(fst(p b)),"")
p('.':r)|(a,b)<-p r = ('(':a++")",              b)
p(')':r)            = (" x)",                   r)
p(x  :r)|(a,b)<-p r = (x:a,                     b)
p _                 = ("",                     "")

f s=fst(p('(':s++")"))


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

Takes a string as input. Returns either false or a truthy value (which can be a number).

It's using a regular expression to transform an input string such as "2846145" into:

```<code>"(a=2+8)&&(a==4+6)&&(a==1+4+5)"
</code>```

Then calls eval() on this expression.

let f =

n=>eval(n.replace(/./g,(v,i)=>(v>n[i-1]?'+':i?')&&(a==':'(a=')+v)+')')

console.log(f("101"));
console.log(f("102"));
console.log(f("777"));
console.log(f("2846145"));```

Title: Dennis numbers 2.0

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

Takes a string as input. Returns either false or a truthy value (which can be a number).

It's using a regular expression to transform an input string such as "2846145" into:

"(a=2+8)&&(a==4+6)&&(a==1+4+5)"

Then calls eval() on this expression.

let f =

n=>eval(n.replace(/./g,(v,i)=>(v>n[i-1]?'+':i?')&&(a==':'(a=')+v)+')')

console.log(f("101"));
console.log(f("102"));
console.log(f("777"));
console.log(f("2846145"));


答:
Python 2, <s>156</s> 155 bytes

My answer has some similar ideas as 1Darco1's answer, but by using a different approach from the start (string slicing rather than lists), it ended up quite a bit shorter. It would be four bytes shorter if 0-indexing was allowed.

s,r=input()
o=""
for x in r.split("AND"):
    i=map(int,x.split("TO"));d=2*(i[0]<i[-1])-1
    for _ in-1,0:i[_]-=11**9*(i[_]<0)
    o+=s[i[0]-1:i[-1]+d-1:d]
print o
```
<p><strong>Try it online</strong></p>
<p>Fortunately, I can parse strings containing spaces into integers. Negative indexing in Python indexes from the end of the string, so I use <code>i[-1]</code> to either be the same as <code>i[0]</code> or the second value, if there is one. Then I have to adjust any negative range values to <em>more</em> negative, so they won't mess with the slicing. Multiplying negative values by <code>11**9</code> (<code>2357947691</code>) will account for ranges using integer min value. Then, simply slice the string, using reverse slice if the range is reversed.</p>
<h3>With zero-indexing (151 bytes):</h3>
<pre class="lang-python prettyprint-override"><code>s,r=input()
o=""
for x in r.split("AND"):
    i=map(int,x.split("TO"));d=2*(i[0]<i[-1])-1
    for _ in-1,0:i[_]-=11**9*(i[_]<0)
    o+=s[i[0]:i[-1]+d:d]
print o
</code>```

Title: Interpret loose ranges

Body:
Interpret loose ranges

ListSharp is an interpreted programming language that has many features, one of those features is a 1 index based range creator that works like this:

You define a range as (INT) TO (INT) or just (INT) where both or the single int can go from min to max int32 value

Then you can use those ranges to extract elements of an array without fearing to overstep it's boundaries

therefore:

1 TO 5 generates: {1,2,3,4,5}

3 generates: {3}

Ranges can be added up using the AND operator

1 TO 5 AND 3 TO 6 generates: {1,2,3,4,5,3,4,5,6}

remember this works with negative numbers as well

3 TO -3 generates: {3,2,1,0,-1,-2,-3}

The challenge is the following:

Input

A character array and the previously defined range clause as a string

Output

The elements at the 1 index based locations of the range (non existing/negative indexes translate to an empty character)

How to win

As a code-golf challenge you are supposed to create the program with the shortest byte count to win

It has been pointed out empty characters do not exist, therefore you should be ignoring them (I only showed them here to make it easier to understand yet it confused people)

Test cases:

```<code>input array is:
{'H','e','l','l','o',' ','W','o','r','l','d'}

range clause:
"1 TO 3" => "Hel"
"5" => "o"
"-10 TO 10" => "Hello Worl"
"0 AND 2 AND 4" => "el"
"8 TO 3" => "oW oll"
"-300 AND 300" => ""
"1 TO 3 AND 3 TO 1" => "HelleH"
"-20 TO 0 AND 1 AND 4" => "Hl"
</code>```

Body:
Python 2, <s>156</s> 155 bytes

My answer has some similar ideas as 1Darco1's answer, but by using a different approach from the start (string slicing rather than lists), it ended up quite a bit shorter. It would be four bytes shorter if 0-indexing was allowed.

s,r=input()
o=""
for x in r.split("AND"):
    i=map(int,x.split("TO"));d=2*(i[0]<i[-1])-1
    for _ in-1,0:i[_]-=11**9*(i[_]<0)
    o+=s[i[0]-1:i[-1]+d-1:d]
print o

Try it online

Fortunately, I can parse strings containing spaces into integers. Negative indexing in Python indexes from the end of the string, so I use i[-1] to either be the same as i[0] or the second value, if there is one. Then I have to adjust any negative range values to more negative, so they won't mess with the slicing. Multiplying negative values by 11**9 (2357947691) will account for ranges using integer min value. Then, simply slice the string, using reverse slice if the range is reversed.

With zero-indexing (151 bytes):

s,r=input()
o=""
for x in r.split("AND"):
    i=map(int,x.split("TO"));d=2*(i[0]<i[-1])-1
    for _ in-1,0:i[_]-=11**9*(i[_]<0)
    o+=s[i[0]:i[-1]+d:d]
print o


答:
PHP, 144 bytes

```<code><?php preg_match_all("/0?1?2?3?4?5?6?7?8?9?/",$argv[1],$n);foreach($n[0]as$i)if(strlen($i)&&($a=array_sum(str_split($i)))!=$s=$s??$a)die;echo 1;
</code>```

I'm sure there's a much cleverer (and shorter) way to do this but it will do for now.

Title: Dennis numbers 2.0

Body:
PHP, 144 bytes

<?php preg_match_all("/0?1?2?3?4?5?6?7?8?9?/",$argv[1],$n);foreach($n[0]as$i)if(strlen($i)&&($a=array_sum(str_split($i)))!=$s=$s??$a)die;echo 1;

I'm sure there's a much cleverer (and shorter) way to do this but it will do for now.


问:
Multiple-Key Sorting
Given a list of indices and zero or more lists of integers, output the lists of integers, sorted in ascending order, with the key priority from the first input.

Example

Let the keys input be [1, 0, 2], and the lists input be [[5, 3, 4], [6, 2, 1], [5, 2, 1]]. Those lists need to be sorted by their second element, then first element, then third element, in ascending order:

First, we sort by the values at index 1: [[6, 2, 1], [5, 2, 1], [5, 3, 4]]

Next, we break any ties from the first sort using the values at index 0: [[5, 2, 1], [6, 2, 1], [5, 3, 4]]

Finally, we break any remaining ties with the vlues at index 2 (this doesn't actually change anything, because there are no ties remaining).

Details

Sorting is stable: if two elements compare equal with respect to the given sort keys, they must remain in the same relative order in the output. For example, if A and B are equal under the given sort keys, and the input was [..., A, ..., B, ...], A must be placed before B in the output.

A sort key will never reference a non-existant element in one of the input lists.

No sort key will be repeated. Thus, [1, 2, 1] is not a valid list of sort keys.

Any elements not referenced by the sort keys do not factor into the sorting order. Only the initial relative order and the values of the elements referenced by the sort keys determine the output order.

You may choose whether the sort keys are zero-indexed or one-indexed.

There will be no negative values in the sort keys. If you choose to use one-indexing, there will be no zeroes in the sort keys either.

Integer values will not exceed your language's natively-representable range. If your chosen language is natively capable of arbitrary-precision integers (like Python), then any integer value can be present in the input, subject to memory constraints.

Reference Implementation (Python 2)

#!/usr/bin/env python

keys = input()
lists = input()

print sorted(lists, key=lambda l:[l[x] for x in keys])
```
<p>Try it online</p>
<h2>Test Cases</h2>
<p>Format: <code>keys lists -> output</code>. All sort keys are zero-indexed.</p>
```[1, 0, 2] [[5, 3, 4], [6, 2, 1], [5, 2, 1]] -> [[5, 2, 1], [6, 2, 1], [5, 3, 4]]
[1, 2] [[5, 3, 4], [6, 2, 1], [5, 2, 1]] -> [[6, 2, 1], [5, 2, 1], [5, 3, 4]]
[0, 1] [[1, 2], [2, 1]] -> [[1, 2], [2, 1]]
[1, 0] [[1, 2], [2, 1]] -> [[2, 1], [1, 2]]
[0] [[4], [10, 11, -88], [-2, 7]] -> [[-2, 7], [4], [10, 11, -88]]
[2] [[-1, -5, 8, -1, -4, -10, -5, 4, 4, 6, -8, 4, 2], [-7, 6, 2, -8, -7, 7, -3, 3, 0, -6, 1], [-9, 8, -5, -1, -7, -8, -5, -6, 5, -6, 6]] -> [[-9, 8, -5, -1, -7, -8, -5, -6, 5, -6, 6], [-7, 6, 2, -8, -7, 7, -3, 3, 0, -6, 1], [-1, -5, 8, -1, -4, -10, -5, 4, 4, 6, -8, 4, 2]]
[2, 1] [[9, 2, -2, -10, -6], [3, -4, -2]] -> [[3, -4, -2], [9, 2, -2, -10, -6]]
[2, 4, 8] [[5, -3, 4, -6, -1, -2, -2, -4, 5], [-2, -3, 6, -4, -1, -4, -4, -5, 8, 9, 9, -3, 3, -9, -3], [2, 0, 10, -10, -1, 2, -1, 5, -1, 10, -5], [-7, -8, -6, 7, 3, 8, 6, -7, -2, 0, -6, -4, 4, -3, 2, -3]] -> [[-7, -8, -6, 7, 3, 8, 6, -7, -2, 0, -6, -4, 4, -3, 2, -3], [5, -3, 4, -6, -1, -2, -2, -4, 5], [-2, -3, 6, -4, -1, -4, -4, -5, 8, 9, 9, -3, 3, -9, -3], [2, 0, 10, -10, -1, 2, -1, 5, -1, 10, -5]]
[1, 2, 3, 4, 5] [[-7, 3, -8, 3, 5, -1, 6, -6, 9, 8], [-9, -1, -7, -9, -10, -2, -8, -10, -10, -3], [5, 3, -6, -5, -4, -4, -8, 2], [9, -4, 1, -1, -3, -2], [-6, -10, 4, -10, 6, 6, -1, 3, 0, 0], [1, -2, -7, -6, -7, -7, -1, 0, -4, 3, 3], [7, -1, -7, 2, -2, 9, 7, 5, -6, -8], [1, -5, -3, -10, -7, 9, -8, -5, -1], [-9, 4, -1, -1, 2, 4]] -> [[-6, -10, 4, -10, 6, 6, -1, 3, 0, 0], [1, -5, -3, -10, -7, 9, -8, -5, -1], [9, -4, 1, -1, -3, -2], [1, -2, -7, -6, -7, -7, -1, 0, -4, 3, 3], [-9, -1, -7, -9, -10, -2, -8, -10, -10, -3], [7, -1, -7, 2, -2, 9, 7, 5, -6, -8], [-7, 3, -8, 3, 5, -1, 6, -6, 9, 8], [5, 3, -6, -5, -4, -4, -8, 2], [-9, 4, -1, -1, 2, 4]]
[8, 7, 3, 2, 4, 9, 1] [[8, -5, 1, -6, -1, -4, 6, 10, 10, 6, 9, 5], [4, -8, 6, -10, -2, -3, 2, -6, 9, 5, 4, 10, 2, 3], [10, -1, 3, 0, -4, 1, -5, -4, -1, -7, 9, -9, -1, -5, 7, 8, 9, 6, -3], [0, -9, -7, -2, 2, -5, 7, 4, 6, -4, 1, 8, -7, 10], [5, 6, -9, 0, -1, 5, 4, 7, 5, 10, 2, 5, 7, -9]] -> [[10, -1, 3, 0, -4, 1, -5, -4, -1, -7, 9, -9, -1, -5, 7, 8, 9, 6, -3], [5, 6, -9, 0, -1, 5, 4, 7, 5, 10, 2, 5, 7, -9], [0, -9, -7, -2, 2, -5, 7, 4, 6, -4, 1, 8, -7, 10], [4, -8, 6, -10, -2, -3, 2, -6, 9, 5, 4, 10, 2, 3], [8, -5, 1, -6, -1, -4, 6, 10, 10, 6, 9, 5]]
```

答:
R 40 bytes

```<code>for(i in rev(il)){dd=dd[order(dd[,i]),]}
</code>```

Explanation:

List of lists is best represented as a data.frame in R:

```<code>ll2 = list(c(5,3,4), c(5,3,7), c(6,2,1), c(6,1,3), c(5,2,1))
dd = data.frame(do.call(rbind, ll2))
dd
      X1 X2 X3
    1  5  3  4
    2  5  3  7
    3  6  2  1
    4  6  1  3
    5  5  2  1
</code>```

If index list is il (indexing is from 1):

```<code>il = list(1, 2, 3)
</code>```

Sorting can be done with following code:

```<code>for(i in rev(il)){dd = dd[order(dd[,i]),]}
</code>```

Output:

```<code>dd
  X1 X2 X3
5  5  2  1
1  5  3  4
2  5  3  7
4  6  1  3
3  6  2  1
</code>```

Title: Multiple-Key Sorting

Body:
R 40 bytes

for(i in rev(il)){dd=dd[order(dd[,i]),]}

Explanation:

List of lists is best represented as a data.frame in R:

ll2 = list(c(5,3,4), c(5,3,7), c(6,2,1), c(6,1,3), c(5,2,1))
dd = data.frame(do.call(rbind, ll2))
dd
      X1 X2 X3
    1  5  3  4
    2  5  3  7
    3  6  2  1
    4  6  1  3
    5  5  2  1

If index list is il (indexing is from 1):

il = list(1, 2, 3)

Sorting can be done with following code:

for(i in rev(il)){dd = dd[order(dd[,i]),]}

Output:

dd
  X1 X2 X3
5  5  2  1
1  5  3  4
2  5  3  7
4  6  1  3
3  6  2  1


问:
Output a string's cumulative slope

Challenge

Given a string such as Hello World!, break it down into its character values: 72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33.

Then calculate the difference between each consecutive pair of characters: 29, 7, 0, 3, -79, 55, 24, 3, -6, -8, -67.

Finally, sum them and print the final result: -39.

Rules

Standard loopholes apply

No using pre-made functions that perform this exact task

Creative solutions encouraged

Have fun

This is marked as code-golf, the shortest answer in bytes wins but will not be selected.

答:
Groovy (80 Bytes)

```<code>f={n->s=[];n.eachWithIndex{x,i->s<<(i+1<n.size()?(int)n[i+1]-(int)x:0)};s.sum()}
</code>```

Title: Output a string's cumulative slope

Body:
Groovy (80 Bytes)

f={n->s=[];n.eachWithIndex{x,i->s<<(i+1<n.size()?(int)n[i+1]-(int)x:0)};s.sum()}


问:
Priority to the right
Your task is to regulate traffic on a crossroads. There are 4 roads coming from north, east, south and west.

The input is a string representing the upcoming traffic on each road. For example, NNNWS indicates there is a total of 5 cars: three at the north, one at the west and one at the south. The order of characters has no importance here, NNNWS is equivalent to WNNSN.

You must output the order in which the cars should go, using the priority to the right rule: cars coming from the south must let cars coming from east go first, east gives way to north, north gives way to west and west gives way to south.

For example, with the input NNNWS, the south car should go first, then the west car, then the 3 north cars. The output should thus be SWNNN.

There are some indecidable cases, for example NS or NNWSE : you should then output the string stuck.

Test cases

```<code>N => N
NW => WN
NWS => SWN
SNW => SWN
SSSSS => SSSSS
ENNNNES => NNNNEES
NS => stuck
NNWSE => stuck
</code>```

答:
JavaScript (ES6), <s>108</s> <s>107</s> <s>106</s> 104 bytes

```<code>s=>(r=t=`NESWNE`,s.replace(/./g,c=>r|=2<<t.search(c)),t.substr(449778192>>r&3,1053417876>>r&3)||`stuck`)
</code>```

Accumulates a bitmask of which directions have approaching cars and extracts the appropriate portion of the priority string.

Title: Priority to the right

Body:
JavaScript (ES6), <s>108</s> <s>107</s> <s>106</s> 104 bytes

s=>(r=t=`NESWNE`,s.replace(/./g,c=>r|=2<<t.search(c)),t.substr(449778192>>r&3,1053417876>>r&3)||`stuck`)

Accumulates a bitmask of which directions have approaching cars and extracts the appropriate portion of the priority string.


问:
Now I know my ABCs, won't you come and golf with me?
Write a program or function that outputs this exact text, case-insensitive:

```<code>A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P,
Q, R, S,
T, U, V,
W, X, Y, Z.
</code>```

(Based on the alphabet song that many American kids learn to help memorize the alphabet, though edited for more compressibility.)

The output must look exactly the same as the above (again, case-insensitive), but may contain trailing spaces on each line and/or trailing newlines. Notice the period at the end.

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

答:
Jelly, <s>19</s> 18 bytes

```<code>ØAp”,ṁ79334DR¤GṖ”.
</code>```

Thanks to @Adnan for golfing off 1 byte!

Try it online!

How it works

```<code>ØAp”,ṁ79334DR¤GṖ”.  Main link. No arguments.

ØA                  Yield "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
  p”,               Cartesian product with ','; append a comma to each letter.
             ¤      Combine the two links to the left into a niladic chain.
      79334D          Decimal; yield [7, 9, 3, 3, 4].
            R         Range; yield [[1, 2, 3, 4, 5, 6, 7], ..., [1, 2, 3, 4]].
     ṁ              Mold; reshape the array of letters with commata like the
                    generated 2D array.
              G     Grid; separate rows by spaces, columns by linefeeds.
               Ṗ    Pop; discard the last comma.
                ”.  Print the previous result and set the return value to '.'.
                     (implicit) Print the return value.
</code>```

Body:
Jelly, <s>19</s> 18 bytes

ØAp”,ṁ79334DR¤GṖ”.

Thanks to @Adnan for golfing off 1 byte!

Try it online!

How it works

ØAp”,ṁ79334DR¤GṖ”.  Main link. No arguments.

ØA                  Yield "ABCDEFGHIJKLMNOPQRSTUVWXYZ".
  p”,               Cartesian product with ','; append a comma to each letter.
             ¤      Combine the two links to the left into a niladic chain.
      79334D          Decimal; yield [7, 9, 3, 3, 4].
            R         Range; yield [[1, 2, 3, 4, 5, 6, 7], ..., [1, 2, 3, 4]].
     ṁ              Mold; reshape the array of letters with commata like the
                    generated 2D array.
              G     Grid; separate rows by spaces, columns by linefeeds.
               Ṗ    Pop; discard the last comma.
                ”.  Print the previous result and set the return value to '.'.
                     (implicit) Print the return value.


答:
Cheddar, 70 bytes

```<code>->[65@"71,72@"80,"QRS","TUV","WXYZ"].map(@.chars.join(", ")).vfuse+'.'
</code>```

Looks like it's not getting shorter than this. I've made other versions of this which use quite interesting methods but this is shortest

Try it online!

Explanation

```<code>->                        // Function with no arguments
  [                       // Array, each item represents a line
   65@"71,                // See below on what @" does
   72@"80,
   "QRS",
   "TUV",
   "WXYZ"
  ].map(                  // On each item...
    @.chars.join(", ")    // Join the characters on ", "
  ).vfuse                 // Vertical fuse or join by newlines
  + '.'                   // The period at the end
</code>```

The @" operator is used to generate string ranged. It generates a string starting from the left char code to the right char code.

For example, 65 is the char code for A and 90 for Z. Doing 65 @" 90 would generate A through Z or the alphabet.

Title: Now I know my ABCs, won't you come and golf with me?

Body:
Write a program or function that outputs this exact text, case-insensitive:

```<code>A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P,
Q, R, S,
T, U, V,
W, X, Y, Z.
</code>```

(Based on the alphabet song that many American kids learn to help memorize the alphabet, though edited for more compressibility.)

The output must look exactly the same as the above (again, case-insensitive), but may contain trailing spaces on each line and/or trailing newlines. Notice the period at the end.

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

Body:
Cheddar, 70 bytes

->[65@"71,72@"80,"QRS","TUV","WXYZ"].map(@.chars.join(", ")).vfuse+'.'

Looks like it's not getting shorter than this. I've made other versions of this which use quite interesting methods but this is shortest

Try it online!

Explanation

->                        // Function with no arguments
  [                       // Array, each item represents a line
   65@"71,                // See below on what @" does
   72@"80,
   "QRS",
   "TUV",
   "WXYZ"
  ].map(                  // On each item...
    @.chars.join(", ")    // Join the characters on ", "
  ).vfuse                 // Vertical fuse or join by newlines
  + '.'                   // The period at the end

The @" operator is used to generate string ranged. It generates a string starting from the left char code to the right char code.

For example, 65 is the char code for A and 90 for Z. Doing 65 @" 90 would generate A through Z or the alphabet.


答:
PHP, <s>108</s> <s>105</s> 92 bytes

```<code>$p=-1;foreach(str_split("$argv[1].")as$d)$p>=$d?$r&&$s-$r?die(1):($r=$s)&$s=$p=$d:$s+=$p=$d;
</code>```

takes input from argument, exits with 0 for Dennis-2.0 number, with 1 else.

breakdown

```<code>$p=-1;                              // init $p(revious digit) to -1
foreach(str_split("$argv[1].")as$d) // loop $d(igit) through input characters
                                    // (plus a dot, to catch the final sum)
    $p>=$d                              // if not ascending:
        ?$r                             // do we have a sum remembered
        &&$s-$r                         // and does it differ from the current sum?
                ?die(1)                     // then exit with failure
                :($r=$s)&$s=$p=$d           // remember sum, set sum to digit, remember digit
        :$s+=$p=$d                      // ascending: increase sum, remember digit
    ;
//
</code>```

Title: Dennis numbers 2.0

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

Body:
PHP, <s>108</s> <s>105</s> 92 bytes

$p=-1;foreach(str_split("$argv[1].")as$d)$p>=$d?$r&&$s-$r?die(1):($r=$s)&$s=$p=$d:$s+=$p=$d;

takes input from argument, exits with 0 for Dennis-2.0 number, with 1 else.

breakdown

$p=-1;                              // init $p(revious digit) to -1
foreach(str_split("$argv[1].")as$d) // loop $d(igit) through input characters
                                    // (plus a dot, to catch the final sum)
    $p>=$d                              // if not ascending:
        ?$r                             // do we have a sum remembered
        &&$s-$r                         // and does it differ from the current sum?
                ?die(1)                     // then exit with failure
                :($r=$s)&$s=$p=$d           // remember sum, set sum to digit, remember digit
        :$s+=$p=$d                      // ascending: increase sum, remember digit
    ;
//


答:
Bash + GNU utilities, 36

5 bytes saved thanks to Neil.

echo {A..Y}, Z.|sed 's/[HQTW]/\n&/g'
```

Ideone.

Body:
Bash + GNU utilities, 36

5 bytes saved thanks to Neil.

echo {A..Y}, Z.|sed 's/[HQTW]/\n&/g'

Ideone.


答:
05AB1E, 16 bytes

Code

```<code>A',â79334S£»¨'.J
</code>```

Explanation:

```<code>A                  # Push the alphabet.
 ',â               # Cartesian product with ','.
    79334S         # Push [7, 9, 3, 3, 4].
          £        # Contigious substring, pushes the substrings [0:7], [7:7+9],
                     [7+9:7+9+3], [7+9+3:7+9+3+3], [7+9+3+3:7+9+3+3+4].
           »       # Gridify, join the inner arrays with spaces and join those arrays
                     with newlines.
            ¨      # Remove the last character.
             '.J   # Append a '.'-character.
</code>```

Uses the CP-1252 encoding. Try it online!

Body:
05AB1E, 16 bytes

Code

A',â79334S£»¨'.J

Explanation:

A                  # Push the alphabet.
 ',â               # Cartesian product with ','.
    79334S         # Push [7, 9, 3, 3, 4].
          £        # Contigious substring, pushes the substrings [0:7], [7:7+9],
                     [7+9:7+9+3], [7+9+3:7+9+3+3], [7+9+3+3:7+9+3+3+4].
           »       # Gridify, join the inner arrays with spaces and join those arrays
                     with newlines.
            ¨      # Remove the last character.
             '.J   # Append a '.'-character.

Uses the CP-1252 encoding. Try it online!


答:
Vim, <s>42</s>, 40 keystrokes/bytes

```<code>:h<_<cr>jjYZZP:s/./&, /g<cr>7f r<cr>9;.3;.3;.$ch.
</code>```

Thanks to Lynn and her awesome vim answer for the tip to grab the alphabet from help.

Thanks to RomanGräf for saving two bytes!

Explanation:

```<code>:h<_<cr>                                      " Open up vim-help
        jj                                    " Move down two lines
          Y                                   " Yank this line (containing the alphabet)
           ZZ                                 " Close this buffer
             P                                " Paste the line we just yanked
              :s/./&, /g<cr>                  " Replace every character with that character followed by a comma and a space
                            7f                " Find the seven space on this line
                               r<cr>          " And replace it with a newline
                                    9;        " Repeat the last search (space) 9 times
                                      .       " Repeat the last edit (replace with a newline)
                                       3;     " Third space
                                         .    " Replace with newline
                                          3;  " Third space
                                            . " Replace with newline
</code>```

Then, we move the end of the of the line with $, change back a character with ch and insert a dot.

Body:
Vim, <s>42</s>, 40 keystrokes/bytes

:h<_<cr>jjYZZP:s/./&, /g<cr>7f r<cr>9;.3;.3;.$ch.

Thanks to Lynn and her awesome vim answer for the tip to grab the alphabet from help.

Thanks to RomanGräf for saving two bytes!

Explanation:

:h<_<cr>                                      " Open up vim-help
        jj                                    " Move down two lines
          Y                                   " Yank this line (containing the alphabet)
           ZZ                                 " Close this buffer
             P                                " Paste the line we just yanked
              :s/./&, /g<cr>                  " Replace every character with that character followed by a comma and a space
                            7f                " Find the seven space on this line
                               r<cr>          " And replace it with a newline
                                    9;        " Repeat the last search (space) 9 times
                                      .       " Repeat the last edit (replace with a newline)
                                       3;     " Third space
                                         .    " Replace with newline
                                          3;  " Third space
                                            . " Replace with newline

Then, we move the end of the of the line with $, change back a character with ch and insert a dot.


Title: Dennis numbers 2.0

Body:
GNU sed 217 or 115

Both include +1 for -r

217:

s/./&,/g;s/^/,/g;:;s,0,,;s,2,11,;s,3,21,;s,4,31,;s,5,41,;s,6,51,
s,7,61,;s,8,71,;s,9,81,;t;s/(,1*)(1*)\1,/\1\2X\1,/;t;s/,//g
s,1X1(1*),X\1a,;t;/^1.*X/c0
/Xa*$/s,a*$,,;y,a,1,;/1X1/b;/1X|X1/c0
c1

Takes input in normal decimal

Try it online!

115:

s/^|$/,/g;:;s/(,1*)(1*)\1,/\1\2X\1,/;t;s/,//g
s,1X1(1*),X\1a,;t;/^1.*X/c0
/Xa*$/s,a*$,,;y,a,1,;/1X1/b;/1X|X1/c0
c1

Takes input as a comma separated list of the numbers digits in unary. e.g. 123 would be 1,11,111

Try it online!


Body:
q, 46 bytes

-1@'(", "sv/:0 7 16 19 22_,:'[.Q.A]),'",,,,.";


答:
PowerShell v3+, <s>60</s> <s>78</s> 67 bytes

```<code>-join(65..90|%{[char]$_+'.,'[$_-le89]+" "+"`n"*($_-in71,80,83,86)})
</code>```

OK. I've actually read, understood, and followed the spec this time. Promise. :D

Takes the array 65..90 and loops over each element |%{...}. Each iteration, we're constructing a new string using concatenation, indexing, and multiplication.

First, we take the current number and char cast it to make it an ASCII letter. That's concatenated with another char, based on indexing into the string '.,' whether we're at 90 or not (i.e., to account for Z. while having all the rest be commas). That's string concatenated with " " to space-separate the letters, and string multiplication of "`n" based on Boolean value for whether the current element is -in the specified array (i.e., whether we need to concatenate on a newline character). The resulting string is left on the pipeline.

Those strings are encapsulated in parens, and -joined together into a new string, which is then also left on the pipeline and implicit Write-Output at the end prints the result. Since we have `n in the string, it's automatically converted to newlines upon printing.

Requires v3+ for the -in operator. Has a trailing space on each line, which is OK per the challenge specs.

Example

```<code>PS C:\Tools\Scripts\golfing> .\now-i-know-my-abc.ps1
A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P,
Q, R, S,
T, U, V,
W, X, Y, Z.
</code>```

Body:
PowerShell v3+, <s>60</s> <s>78</s> 67 bytes

-join(65..90|%{[char]$_+'.,'[$_-le89]+" "+"`n"*($_-in71,80,83,86)})

OK. I've actually read, understood, and followed the spec this time. Promise. :D

Takes the array 65..90 and loops over each element |%{...}. Each iteration, we're constructing a new string using concatenation, indexing, and multiplication.

First, we take the current number and char cast it to make it an ASCII letter. That's concatenated with another char, based on indexing into the string '.,' whether we're at 90 or not (i.e., to account for Z. while having all the rest be commas). That's string concatenated with " " to space-separate the letters, and string multiplication of "`n" based on Boolean value for whether the current element is -in the specified array (i.e., whether we need to concatenate on a newline character). The resulting string is left on the pipeline.

Those strings are encapsulated in parens, and -joined together into a new string, which is then also left on the pipeline and implicit Write-Output at the end prints the result. Since we have `n in the string, it's automatically converted to newlines upon printing.

Requires v3+ for the -in operator. Has a trailing space on each line, which is OK per the challenge specs.

Example

PS C:\Tools\Scripts\golfing> .\now-i-know-my-abc.ps1
A, B, C, D, E, F, G,
H, I, J, K, L, M, N, O, P,
Q, R, S,
T, U, V,
W, X, Y, Z.


答:
MATL, <s>38</s> 29 bytes

9 bytes saved thanks to @Luis!

```<code>1Y2X{', '&Zc46h1[CEII]I*11hY{
</code>```

Try it Online!

Explanation

```<code>1Y2     % Push the upper-case alphabet to the stack
X{      % Break the character array into a cell array (similar to a list)
        % where each element is a letter
', '&Zc % Combine back into a string with ', ' between each element
46h     % Append '.' (via ASCII code) to the end of the string
1       % Push the number 1
[CEII]  % Push the array: [7, 9, 3, 3]
I*      % Multiply this array by 3: [21, 27, 9, 9]
llh     % Append an 11 to this array: [21, 27, 9, 9, 11]
Y{      % Break our comma-separated list of characters into groups of this size
        % Implicitly display the result
</code>```

Body:
MATL, <s>38</s> 29 bytes

9 bytes saved thanks to @Luis!

1Y2X{', '&Zc46h1[CEII]I*11hY{

Try it Online!

Explanation

1Y2     % Push the upper-case alphabet to the stack
X{      % Break the character array into a cell array (similar to a list)
        % where each element is a letter
', '&Zc % Combine back into a string with ', ' between each element
46h     % Append '.' (via ASCII code) to the end of the string
1       % Push the number 1
[CEII]  % Push the array: [7, 9, 3, 3]
I*      % Multiply this array by 3: [21, 27, 9, 9]
llh     % Append an 11 to this array: [21, 27, 9, 9, 11]
Y{      % Break our comma-separated list of characters into groups of this size
        % Implicitly display the result


答:
PHP, 90 chars

```<code>A<?for($i=66;$i<91;$i++){echo", ";if(in_array($i,[72,81,84,87]))echo"\n";echo chr($i);}?>.
</code>```

I know it's longer than 77 chars, but this is as short as it gets.

Body:
PHP, 90 chars

A<?for($i=66;$i<91;$i++){echo", ";if(in_array($i,[72,81,84,87]))echo"\n";echo chr($i);}?>.

I know it's longer than 77 chars, but this is as short as it gets.


答:
Retina, 43 bytes

```<code>
Z
{2`
$`
}T01`L`_L
.
$&,
[HQTW]
¶$&
, $
.</code>```

Leading newline is significant. Try it online!

This is my first time using Retina, so any golfing tips are appreciated...

Body:
Retina, 43 bytes

Z
{2`
$`
}T01`L`_L
.
$&,
[HQTW]
¶$&
, $
.

Leading newline is significant. Try it online!

This is my first time using Retina, so any golfing tips are appreciated...


答:
Batch, 216 bytes

```<code>@echo off
set/pt=
set/an=2,e=4,s=8,w=16,r=0
:l
set/ar^|=%t:~0,1%
set t=%t:~1%
if not "%t%"=="" goto l
set/a"o=449778192>>r&3,l=1053417876>>r&3"
if %l%==0 (echo stuck)else set t=NESWNE&call echo %%t:~%o%,%l%%%
</code>```

Simple port of my JavaScript answer. Takes input on STDIN in upper or lower case.

Title: Priority to the right

Body:
Your task is to regulate traffic on a crossroads. There are 4 roads coming from north, east, south and west.

The input is a string representing the upcoming traffic on each road. For example, NNNWS indicates there is a total of 5 cars: three at the north, one at the west and one at the south. The order of characters has no importance here, NNNWS is equivalent to WNNSN.

You must output the order in which the cars should go, using the priority to the right rule: cars coming from the south must let cars coming from east go first, east gives way to north, north gives way to west and west gives way to south.

For example, with the input NNNWS, the south car should go first, then the west car, then the 3 north cars. The output should thus be SWNNN.

There are some indecidable cases, for example NS or NNWSE : you should then output the string stuck.

Test cases

```<code>N => N
NW => WN
NWS => SWN
SNW => SWN
SSSSS => SSSSS
ENNNNES => NNNNEES
NS => stuck
NNWSE => stuck
</code>```

Body:
Batch, 216 bytes

@echo off
set/pt=
set/an=2,e=4,s=8,w=16,r=0
:l
set/ar^|=%t:~0,1%
set t=%t:~1%
if not "%t%"=="" goto l
set/a"o=449778192>>r&3,l=1053417876>>r&3"
if %l%==0 (echo stuck)else set t=NESWNE&call echo %%t:~%o%,%l%%%

Simple port of my JavaScript answer. Takes input on STDIN in upper or lower case.