答:
JavaScript (ES6), 144

Using parseInt base 36 to separate first half, second half and other. For any character c, I evaluate y=parseInt(c,36) so that

c '0'..'9' -> y 0..9

c 'a'..'m' or 'A'..'M' -> y 10..22

c 'n'..'z' or 'N'..'Z' -> y 23..35

c any other -> y NaN

So y=parseInt(c,36), x=(y>22)+(y>9) gives x==1 for first half, x==2 for second half and x==0 for any other (as NaN > any number is false)

First step: the input string is mapped to an array of 0,1 or 2. Meanwhile all the string characters ar added to 3 arrays. At the end of this first step the array 1 and 2 are rotated in opposite directions.

Second step: the mapped array is scanned, rebuilding an output string taking each character from the 3 temporary arrays.

s=>[...s].map(c=>a[y=parseInt(c,36),x=(y>22)+(y>9)].push(c)&&x,a=[[],p=[],q=[]]).map(x=>a[x].shift(),p.unshift(p.pop(q.push(q.shift())))).join``
```
<p><em>Less golfed</em></p>
<pre class="lang-js prettyprint-override"><code>s=>[...s].map(
  c => a[ y = parseInt(c, 36), x=(y > 22) + (y > 9)].push(c)
       && x,
  a = [ [], p=[], q=[] ]
).map(
  x => a[x].shift(),  // get the output char from the right temp array
  p.unshift(p.pop()), // rotate p
  q.push(q.shift())   // rotate q opposite direction
).join``
</code>```

Test

f=
s=>[...s].map(c=>a[y=parseInt(c,36),x=(y>22)+(y>9)].push(c)&&x,a=[[],p=[],q=[]]).map(x=>a[x].shift(),p.unshift(p.pop()),q.push(q.shift())).join``

function update() {
  O.textContent=f(I.value);
}

update()```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id=I oninput='update()' value='Hello, world'>
<pre id=O>``````

Title: Double rotation

Body:
JavaScript (ES6), 144

Using parseInt base 36 to separate first half, second half and other. For any character c, I evaluate y=parseInt(c,36) so that

c '0'..'9' -> y 0..9

c 'a'..'m' or 'A'..'M' -> y 10..22

c 'n'..'z' or 'N'..'Z' -> y 23..35

c any other -> y NaN

So y=parseInt(c,36), x=(y>22)+(y>9) gives x==1 for first half, x==2 for second half and x==0 for any other (as NaN > any number is false)

First step: the input string is mapped to an array of 0,1 or 2. Meanwhile all the string characters ar added to 3 arrays. At the end of this first step the array 1 and 2 are rotated in opposite directions.

Second step: the mapped array is scanned, rebuilding an output string taking each character from the 3 temporary arrays.

s=>[...s].map(c=>a[y=parseInt(c,36),x=(y>22)+(y>9)].push(c)&&x,a=[[],p=[],q=[]]).map(x=>a[x].shift(),p.unshift(p.pop(q.push(q.shift())))).join``

Less golfed

s=>[...s].map(
  c => a[ y = parseInt(c, 36), x=(y > 22) + (y > 9)].push(c)
       && x,
  a = [ [], p=[], q=[] ]
).map(
  x => a[x].shift(),  // get the output char from the right temp array
  p.unshift(p.pop()), // rotate p
  q.push(q.shift())   // rotate q opposite direction
).join``

Test

f=
s=>[...s].map(c=>a[y=parseInt(c,36),x=(y>22)+(y>9)].push(c)&&x,a=[[],p=[],q=[]]).map(x=>a[x].shift(),p.unshift(p.pop()),q.push(q.shift())).join``

function update() {
  O.textContent=f(I.value);
}

update()

<input id=I oninput='update()' value='Hello, world'>
<pre id=O></pre>


问:
Count from 1 to 100... in Roman Numerals
Write a program that count from 1 to 100 in Roman Numerals and print these numbers by standard output. Each one of the numbers must be separated by spaces.

You cannot use any built in function to transform to roman numerals nor external application or library to do so.

The desired result is

```<code>I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX XXI XXII XXIII XXIV XXV XXVI XXVII XXVIII XXIX XXX XXXI XXXII XXXIII XXXIV XXXV XXXVI XXXVII XXXVIII XXXIX XL XLI XLII XLIII XLIV XLV XLVI XLVII XLVIII XLIX L LI LII LIII LIV LV LVI LVII LVIII LIX LX LXI LXII LXIII LXIV LXV LXVI LXVII LXVIII LXIX LXX LXXI LXXII LXXIII LXXIV LXXV LXXVI LXXVII LXXVIII LXXIX LXXX LXXXI LXXXII LXXXIII LXXXIV LXXXV LXXXVI LXXXVII LXXXVIII LXXXIX XC XCI XCII XCIII XCIV XCV XCVI XCVII XCVIII XCIX C
</code>```

As it is a code golf challenge, shortest code wins.

答:
C, 177 160 147 chars

There are shorter solutions, but none in C, so here's my try.

New solution, completely different from my previous one:

```<code>char*c;
f(n){
    printf("%.*s",n%5>3?2:n%5+n/5,c+=n%5>3?n%4*4:2-n/5);
}
main(i){
        for(;i<100;putchar(32))
                c="XLXXXC",f(i/10),
                c="IVIIIX",f(i++%10);
        puts("C");
}
</code>```

Previous solution (160 chars):

Logic:

1. f prints a number from 1 to 10. c is the digits used, which can be IVX or XLC. Called once for the tens once for the ones.

2. If n%5==0 - print nothing or c[n/5] which is I or V (or L or C).

3. If n%4==4 - 4 or 9 - print I (or X), by n+1.

4. If n>4 - print 5 (i.e. V or L) then n-5.

5. If n<4 - print I then n-1 (i.e. n times I).

```<code>char*c;
p(c){putchar(c);}
f(n){
        n%5?
                n%5>3?
                        f(1),f(n+1):
                        n>4?
                                f(5),f(n-5):
                                f(n-1,p(*c)):
                n&&p(c[n/5]);
}
main(i){
        for(;++i<101;p(32))
                c="XLC",f(i/10),
                c="IVX",f(i%10);
        p(10);
}
</code>```

ContentLicense: CC BY-SA 3.0

Body:
C, 177 160 147 chars

There are shorter solutions, but none in C, so here's my try.

New solution, completely different from my previous one:

char*c;
f(n){
    printf("%.*s",n%5>3?2:n%5+n/5,c+=n%5>3?n%4*4:2-n/5);
}
main(i){
        for(;i<100;putchar(32))
                c="XLXXXC",f(i/10),
                c="IVIIIX",f(i++%10);
        puts("C");
}

Previous solution (160 chars):

Logic:

1. f prints a number from 1 to 10. c is the digits used, which can be IVX or XLC. Called once for the tens once for the ones.

2. If n%5==0 - print nothing or c[n/5] which is I or V (or L or C).

3. If n%4==4 - 4 or 9 - print I (or X), by n+1.

4. If n>4 - print 5 (i.e. V or L) then n-5.

5. If n<4 - print I then n-1 (i.e. n times I).

char*c;
p(c){putchar(c);}
f(n){
        n%5?
                n%5>3?
                        f(1),f(n+1):
                        n>4?
                                f(5),f(n-5):
                                f(n-1,p(*c)):
                n&&p(c[n/5]);
}
main(i){
        for(;++i<101;p(32))
                c="XLC",f(i/10),
                c="IVX",f(i%10);
        p(10);
}


问:
The Letter E with E
Your task is to display the below letter "E" shaped ASCII art, given five inputs.

Examples:

Input: 7,2,+,|,- (Note: You don't have to follow this exact input format, and if you don't use it, then you must explain how your own input format works)

Explanation:

7 total width, including the left and right edge characters.

2 Number of vertical characters.

+ The character that should display at the edges.

| The character that should display vertically between the edges.

- The character that should display horizontally.

Output of the above example:

```<code>+-----+
|
|
+-----+
|
|
+-----+
</code>```

Other examples:

Input: 7,2,@,|,-

Output:

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

Input: 7,2,+,|,#

Output:

```<code>+#####+
|
|
+#####+
|
|
+#####+
</code>```

Input: 8,3,+,|,#

Output:

```<code>+######+
|
|
|
+######+
|
|
|
+######+
</code>```

Input: 8,3,+,@,#

Output:

```<code>+######+
@
@
@
+######+
@
@
@
+######+
</code>```

Input: 9,4,^,$,!

Output:

```<code>^!!!!!!!^
$
$
$
$
^!!!!!!!^
$
$
$
$
^!!!!!!!^
</code>```

Cheating and standard loopholes are not allowed.

Your code must not print anything to STDERR.

Your code may accept any character encoding you choose as the input, but any character encoding you choose must, as a minimum, support all the 95 printable ASCII characters.

The shortest code, in bytes, that completes this challenge successfully, is the winning code.

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
PowerShell v2+, <s>60</s> 59 bytes

```<code>param($a,$b,$c,$d,$e)(,($x="$c$($e*($a-2))$c")+,$d*$b)*2;$x
</code>```

Takes input as individual command-line arguments. Constructs the horizontal string, stores that into $x for use later, then forms that into an array with the comma-operator ,. Performs array concatenation (i.e., adding elements to the end) of $d formulated into an array of $b elements. That, in turn, is formulated into an array of two elements with another comma operator, and is left on the pipeline. Then, the horizontal $x is left on the pipeline. Abuses the default formatting of Write-Output to put a newline between elements.

Example

```<code>PS C:\Tools\Scripts\golfing> .\the-letter-e-without-e.ps1 5 3 "z" "v" "d"
zdddz
v
v
v
zdddz
v
v
v
zdddz
</code>```

Title: The Letter E with E

Body:
PowerShell v2+, <s>60</s> 59 bytes

param($a,$b,$c,$d,$e)(,($x="$c$($e*($a-2))$c")+,$d*$b)*2;$x

Takes input as individual command-line arguments. Constructs the horizontal string, stores that into $x for use later, then forms that into an array with the comma-operator ,. Performs array concatenation (i.e., adding elements to the end) of $d formulated into an array of $b elements. That, in turn, is formulated into an array of two elements with another comma operator, and is left on the pipeline. Then, the horizontal $x is left on the pipeline. Abuses the default formatting of Write-Output to put a newline between elements.

Example

PS C:\Tools\Scripts\golfing> .\the-letter-e-without-e.ps1 5 3 "z" "v" "d"
zdddz
v
v
v
zdddz
v
v
v
zdddz


问:
Invalid Invali Inval
This idea is loosely based upon @TùxCräftîñg's chat message.

Take a look at the below example sequence:

INVALID0, INVALID1, INVALID2 INVALID3, INVALID4... INVALID9

After INVALID9, it goes on like this:

INVALI0, INVALI1, INVALI2, INVALI3... INVALI9

And after INVALI9, it's like this:

INVAL0,INVAL1, INVAL2, INVAL3... INVAL9

After, INVAL9, it's like this:

INVA0, INVA1, INVA2, INVA3, ... INVA9

Notice how we we kept removing a letter from the word INVALID each time.

You'll keep repeating this until you reach a single letter, that is, the letter I:

I0, I1, I2, I3, I4 ... I9

Now, your task is, to take an input of a word, and produce a sequence from it like the above example. Your code must also work with single letters, and in that case the resulting sequence will be shorter.

You may choose any input and output format that you prefer (with or without a separator, as you wish), but you must specify which one you have chosen.

The sequence needs to be in the exact specified order.

The shortest code, in bytes, that successfully completes this challenge, wins the challenge.

Full sequence in the above example:

```<code>INVALID0, INVALID1, INVALID2, INVALID3, INVALID4, INVALID5, INVALID6, INVALID7, INVALID8, INVALID9, INVALI0, INVALI1, INVALI2, INVALI3, INVALI4, INVALI5, INVALI6, INVALI7, INVALI8, INVALI9, INVAL0, INVAL1, INVAL2, INVAL3, INVAL4, INVAL5, INVAL6, INVAL7, INVAL8, INVAL9, INVA0, INVA1, INVA2, INVA3, INVA4, INVA5, INVA6, INVA7, INVA8, INVA9, INV0, INV1, INV2, INV3, INV4, INV5, INV6, INV7, INV8, INV9, IN0, IN1, IN2, IN3, IN4, IN5, IN6, IN7, IN8, IN9, I0, I1, I2, I3, I4, I5, I6, I7, I8, I9
</code>```

Other examples:

Input: MAYBE (Uppercase and lowercase don't matter)

Output:

```<code>MAYBE0, MAYBE1, MAYBE2, MAYBE3, MAYBE4, MAYBE5, MAYBE6, MAYBE7, MAYBE8, MAYBE9, MAYB0, MAYB1, MAYB2, MAYB3, MAYB4, MAYB5, MAYB6, MAYB7, MAYB8, MAYB9, MAY0, MAY1, MAY2, MAY3, MAY4, MAY5, MAY6, MAY7, MAY8, MAY9, MA0, MA1, MA2, MA3, MA4, MA5, MA6, MA7, MA8, MA9, M0, M1, M2, M3, M4, M5, M6, M7, M8, M9
</code>```

Input: AFTER

Output:

```<code>AFTER0, AFTER1, AFTER2, AFTER3, AFTER4, AFTER5, AFTER6, AFTER7, AFTER8, AFTER9, AFTE0, AFTE1, AFTE2, AFTE3, AFTE4, AFTE5, AFTE6, AFTE7, AFTE8, AFTE9, AFT0, AFT1, AFT2, AFT3, AFT4, AFT5, AFT6, AFT7, AFT8, AFT9, AF0, AF1, AF2, AF3, AF4, AF5, AF6, AF7, AF8, AF9, A0, A1, A2, A3, A4, A5, A6, A7, A8, A9
</code>```

Input: WHAT ARE YOU DOING

```<code>WHAT ARE YOU DOING0, WHAT ARE YOU DOING1, WHAT ARE YOU DOING2, WHAT ARE YOU DOING3, WHAT ARE YOU DOING4, WHAT ARE YOU DOING5, WHAT ARE YOU DOING6, WHAT ARE YOU DOING7, WHAT ARE YOU DOING8, WHAT ARE YOU DOING9, WHAT ARE YOU DOIN0, WHAT ARE YOU DOIN1, WHAT ARE YOU DOIN2, WHAT ARE YOU DOIN3, WHAT ARE YOU DOIN4, WHAT ARE YOU DOIN5, WHAT ARE YOU DOIN6, WHAT ARE YOU DOIN7, WHAT ARE YOU DOIN8, WHAT ARE YOU DOIN9, WHAT ARE YOU DOI0, WHAT ARE YOU DOI1, WHAT ARE YOU DOI2, WHAT ARE YOU DOI3, WHAT ARE YOU DOI4, WHAT ARE YOU DOI5, WHAT ARE YOU DOI6, WHAT ARE YOU DOI7, WHAT ARE YOU DOI8, WHAT ARE YOU DOI9, WHAT ARE YOU DO0, WHAT ARE YOU DO1, WHAT ARE YOU DO2, WHAT ARE YOU DO3, WHAT ARE YOU DO4, WHAT ARE YOU DO5, WHAT ARE YOU DO6, WHAT ARE YOU DO7, WHAT ARE YOU DO8, WHAT ARE YOU DO9, WHAT ARE YOU D0, WHAT ARE YOU D1, WHAT ARE YOU D2, WHAT ARE YOU D3, WHAT ARE YOU D4, WHAT ARE YOU D5, WHAT ARE YOU D6, WHAT ARE YOU D7, WHAT ARE YOU D8, WHAT ARE YOU D9, WHAT ARE YOU 0, WHAT ARE YOU 1, WHAT ARE YOU 2, WHAT ARE YOU 3, WHAT ARE YOU 4, WHAT ARE YOU 5, WHAT ARE YOU 6, WHAT ARE YOU 7, WHAT ARE YOU 8, WHAT ARE YOU 9, WHAT ARE YOU0, WHAT ARE YOU1, WHAT ARE YOU2, WHAT ARE YOU3, WHAT ARE YOU4, WHAT ARE YOU5, WHAT ARE YOU6, WHAT ARE YOU7, WHAT ARE YOU8, WHAT ARE YOU9, WHAT ARE YO0, WHAT ARE YO1, WHAT ARE YO2, WHAT ARE YO3, WHAT ARE YO4, WHAT ARE YO5, WHAT ARE YO6, WHAT ARE YO7, WHAT ARE YO8, WHAT ARE YO9, WHAT ARE Y0, WHAT ARE Y1, WHAT ARE Y2, WHAT ARE Y3, WHAT ARE Y4, WHAT ARE Y5, WHAT ARE Y6, WHAT ARE Y7, WHAT ARE Y8, WHAT ARE Y9, WHAT ARE 0, WHAT ARE 1, WHAT ARE 2, WHAT ARE 3, WHAT ARE 4, WHAT ARE 5, WHAT ARE 6, WHAT ARE 7, WHAT ARE 8, WHAT ARE 9, WHAT ARE0, WHAT ARE1, WHAT ARE2, WHAT ARE3, WHAT ARE4, WHAT ARE5, WHAT ARE6, WHAT ARE7, WHAT ARE8, WHAT ARE9, WHAT AR0, WHAT AR1, WHAT AR2, WHAT AR3, WHAT AR4, WHAT AR5, WHAT AR6, WHAT AR7, WHAT AR8, WHAT AR9, WHAT A0, WHAT A1, WHAT A2, WHAT A3, WHAT A4, WHAT A5, WHAT A6, WHAT A7, WHAT A8, WHAT A9, WHAT 0, WHAT 1, WHAT 2, WHAT 3, WHAT 4, WHAT 5, WHAT 6, WHAT 7, WHAT 8, WHAT 9, WHAT0, WHAT1, WHAT2, WHAT3, WHAT4, WHAT5, WHAT6, WHAT7, WHAT8, WHAT9, WHA0, WHA1, WHA2, WHA3, WHA4, WHA5, WHA6, WHA7, WHA8, WHA9, WH0, WH1, WH2, WH3, WH4, WH5, WH6, WH7, WH8, WH9, W0, W1, W2, W3, W4, W5, W6, W7, W8, W9
</code>```

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
PowerShell v2+, 60 bytes

```<code>param($n)$n.length..1|%{$i=$_-1;0..9|%{-join$n[0..$i]+"$_"}}
</code>```

Loops from the length of the input string down to 1. Each iteration, set helper $i equal to the current number minus 1. This is necessary because .length is the total number of characters, but indexing a string is 0-based. Then, we loop from 0 to 9. Each inner loop, slice the input string $n based on the value of our outer loop, -join it back into a string, and string-concatenate on the inner loop count. Each individual loop result is placed on the pipeline, and output is implicit at program completion.

```<code>PS C:\Tools\Scripts\golfing> .\invalid-invali-inval.ps1 'foo'
foo0
foo1
foo2
foo3
foo4
foo5
foo6
foo7
foo8
foo9
fo0
fo1
fo2
fo3
fo4
fo5
fo6
fo7
fo8
fo9
f0
f1
f2
f3
f4
f5
f6
f7
f8
f9
</code>```

Title: Invalid Invali Inval

Body:
PowerShell v2+, 60 bytes

param($n)$n.length..1|%{$i=$_-1;0..9|%{-join$n[0..$i]+"$_"}}

Loops from the length of the input string down to 1. Each iteration, set helper $i equal to the current number minus 1. This is necessary because .length is the total number of characters, but indexing a string is 0-based. Then, we loop from 0 to 9. Each inner loop, slice the input string $n based on the value of our outer loop, -join it back into a string, and string-concatenate on the inner loop count. Each individual loop result is placed on the pipeline, and output is implicit at program completion.

PS C:\Tools\Scripts\golfing> .\invalid-invali-inval.ps1 'foo'
foo0
foo1
foo2
foo3
foo4
foo5
foo6
foo7
foo8
foo9
fo0
fo1
fo2
fo3
fo4
fo5
fo6
fo7
fo8
fo9
f0
f1
f2
f3
f4
f5
f6
f7
f8
f9


问:
Slowly turn a string into another

The Challenge

Given two strings/an array of strings, output the first string slowly shrinking and expanding back into the second string.

You can assume the strings will always start with the same character.

Example

```<code>Input:
"Test", "Testing"

Output:
Test
Tes
Te
T
Te
Tes
Test
Testi
Testin
Testing
</code>```

First you output the first word:

```<code>Test
</code>```

Then you keep removing one letter until the string is one character long:

```<code>Tes
Te
T
</code>```

Then keep adding one letter of the second word until it's done:

```<code>Te
Tes
Test
Testi
Testin
Testing
</code>```

(if both strings are one character long, then just output one of them once.)

Test Cases

```<code>"Hello!", "Hi."
Hello!
Hello
Hell
Hel
He
H
Hi
Hi.

"O", "O"

O

"z", "zz"

z
zz

".vimrc", ".minecraft"

.vimrc
.vimr
.vim
.vi
.v
.
.m
.mi
.min
.mine
.minec
.minecr
.minecra
.minecraf
.minecraft

"     ", "   "

SSSSS
SSSS
SSS
SS
S
SS
SSS

"0123456789", "02468"

0123456789
012345678
01234567
0123456
012345
01234
0123
012
01
0
02
024
0246
02468
</code>```

(note: on the space/fourth test case, replace the S with spaces)

Rules

This is code-golf, so shortest answer in bytes wins! Tiebreaker is most upvoted post. Winner will be chosen on 09/10/2016.

Standard loopholes are forbidden.

答:
PowerShell v2+, 99 bytes

```<code>param($a,$b)if($a-eq$b){$a;exit}$a.length..1|%{-join$a[0..--$_]};1..($b.length-1)|%{-join$b[0..$_]}
</code>```

Straightforward. Loops downward through the first string $a, then loops upward through the second string $b. Has some additional logic at the start where if the strings are equal, so that it only outputs once then exits. The loop indices are off from each other to account for fenceposting.

Title: Slowly turn a string into another

Body:
PowerShell v2+, 99 bytes

param($a,$b)if($a-eq$b){$a;exit}$a.length..1|%{-join$a[0..--$_]};1..($b.length-1)|%{-join$b[0..$_]}

Straightforward. Loops downward through the first string $a, then loops upward through the second string $b. Has some additional logic at the start where if the strings are equal, so that it only outputs once then exits. The loop indices are off from each other to account for fenceposting.


问:
Traveling on a flat Earth
Coordinates in the flat-Earth world consist of latitude (x) and longitude (y), which are integers in the range 0...9999. Much like Gaussian integers, but they are always written using this notation:

```<code>411S 370E
</code>```

That is, with S or N appended to the latitude, and E or W appended to the longitude, with space(s) between the two components.

Goal

Write a program (not a function) that reads two coordinates, separated by whitespace, and outputs their sum. The first coordinate is a starting point, the second one is a displacement, and the output is the resulting position.

Input/Output

Since this challenge is partially about formatting, I'll try to define the input and output formats unambiguously.

The preferred input format has 1 space between the coordinate components, no leading zeros, and a newline character between the two coordinates. The program must be able to read the preferred format.

The output can contain any amount of whitespace and leading zeros. If it's different from the preferred input format, the program must be able to read this format too.

Just to make it clear, the input cannot (will not) contain any additional formatting characters. Just spaces and newlines where needed.

Scoring

This is an experiment on a new winning condition. I'll choose the winner by accepting an answer in a few weeks. If a better answer appears afterwards, I'll change the accepted answer.

The score for the program is its byte count. The winning program is one that is shorter than 400 bytes, has the fewest byte count, but is written in the most verbose programming language. To determine the winner:

Remove programs with byte count 400 or more (they can participate but cannot win)

Consider only the shortest program for each programming language

The longest program wins

Polyglots compete against programs in all languages in which they are valid (e.g. if a program is valid in both bash and sh, it competes against programs in both languages).

Test cases

In the test cases, the first two lines are the input, and the third line is the output.

```<code>0S 0E
0S 0W
0N 0E
</code>```

(the direction of zero doesn't matter, both in input and output)

```<code>0S 9999E
9999N 9999W
9999N 0E
</code>```

(maximal values)

```<code>42S 314W
42N 2718W
0N 3032W
</code>```

(the direction of zero doesn't matter in the output)

```<code>5555N 8888W
7777S 0E
2222S 8888W
</code>```

(no negative values; change the direction if you need to change the sign)

```<code>0001N        4545W
0999N        5454W
1000N        9999W
</code>```

(if the program outputs leading zeros and several spaces, it must be able to read them; it must also be able to read input that doesn't contain them)

```<code>8888N 8888W
9999N 9999W
</code>```

(invalid input - any behavior is acceptable, including crash and infinite loop)

答:
Python 2.7 - <s>232</s> 175 bytes

Works for all of the test cases. Always inserts N or W for 0. I'm sure a better Python golfer than me could shave a good few more bytes off.

f=(raw_input().split(" ")+raw_input().split(" "))
for x in range(4):
 i=f[x]
 if "S" in i or "E" in i:i="-"+i
 f[x]=int(i[:-1])
n=f[0]+f[2]
q=f[1]+f[3]
print str(abs(n))+("S" if n<0 else "N"),str(abs(q))+("E" if q<0 else "W")
```
<p><strong>EDIT</strong></p>
<p>Golfed off a mighty 57 bytes due to some great tips from @mbomb007 and @Titus plus by spotting the fact that I could combine the two raw_inputs with a space then just use one .split() which splits on the space without specifying it. The algorithm is the same but just much better golfed.</p>
```f=(raw_input()+" "+raw_input()).split()
for x in 0,1,2,3:
 i=f[x]
 if i[-1]in"SE":i="-"+i
 f[x]=int(i[:-1])
n=f[0]+f[2]
q=f[1]+f[3]
print`abs(n)`+"NS"[n<0],`abs(q)`+"WE"[q<0]
```

Title: Traveling on a flat Earth

Body:
Python 2.7 - <s>232</s> 175 bytes

Works for all of the test cases. Always inserts N or W for 0. I'm sure a better Python golfer than me could shave a good few more bytes off.

f=(raw_input().split(" ")+raw_input().split(" "))
for x in range(4):
 i=f[x]
 if "S" in i or "E" in i:i="-"+i
 f[x]=int(i[:-1])
n=f[0]+f[2]
q=f[1]+f[3]
print str(abs(n))+("S" if n<0 else "N"),str(abs(q))+("E" if q<0 else "W")

EDIT

Golfed off a mighty 57 bytes due to some great tips from @mbomb007 and @Titus plus by spotting the fact that I could combine the two raw_inputs with a space then just use one .split() which splits on the space without specifying it. The algorithm is the same but just much better golfed.

f=(raw_input()+" "+raw_input()).split()
for x in 0,1,2,3:
 i=f[x]
 if i[-1]in"SE":i="-"+i
 f[x]=int(i[:-1])
n=f[0]+f[2]
q=f[1]+f[3]
print`abs(n)`+"NS"[n<0],`abs(q)`+"WE"[q<0]


问:
4-way intersection generator
Here is an ASCII-art of a 4-way intersection:

```<code>     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
</code>```

(Note how the horizontal roads are 3 rows tall, while the vertical roads are 5 columns wide. This is for aesthetic reasons, because of the rectangular font.)

Your challenge is to produce this ASCII art. However, as I'm sure you all know, not every intersection has a road travelling off in every single direction. This particular intersection goes NESW, but some intersections might go, for example, NW:

```<code>     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
-----+-----+
     |     |
- - -|     |
     |     |
-----+-----+
</code>```

Or it might go SWE:

```<code>-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
</code>```

Or it may even go E, just a single direction (although you can hardly call this an intersection, but try to avoid being overly pedantic):

```<code>     +-----+-----
     |     |
     |     |- - -
     |     |
     +-----+-----
</code>```

You need to write a program or function that can easily generate any of these combinations. More specifically, your challenge is to write a program or function that takes a string of directions, consisting of NESW, as input, and outputs or returns this ASCII art of an intersection with roads pointing in those directions. These directions may appear in any order, but the input will not contain any characters except for N, E, S, or W. If you like, you may request inputs to be lowercase instead, but you must specify this in your answer. You may also assume that all inputs will contain at least one direction.

The last example had leading spaces on each line, because there is no road going west. If you do not have a road going west, these leading spaces are optional. This:

```<code>+-----+-----
|     |
|     |- - -
|     |
+-----+-----
</code>```

Would also be an acceptable output. Similarly, if N or S is gone, empty lines in there place are optional. One trailing newline is allowed, and trailing spaces are allowed as long as the output is visually the same.

You may take input and output in any reasonable format, such as STDIN/STDOUT, command line args, files, function arguments/return values, etc.

As usual, this is code-golf, so try to get the shortest possible answer in whatever language you happen to use!

Sample IO:

```<code>NESW:

     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |

NS:

|  |  |
|     |
|  |  |
|     |
|  |  |
+-----+
|     |
|     |
|     |
+-----+
|  |  |
|     |
|  |  |
|     |
|  |  |

S:

+-----+
|     |
|     |
|     |
+-----+
|  |  |
|     |
|  |  |
|     |
|  |  |

EW:

-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----

SE:
+-----+-----
|     |
|     |- - -
|     |
+-----+-----
|  |  |
|     |
|  |  |
|     |
|  |  |
</code>```

答:
PowerShell v3+, <s>226</s> <s>204</s> <s>192</s> 191 bytes

```<code>param([char[]]$a)($n=0..4|%{($x=' '*5*($b=87-in$a))+('|  |  |',($w='|     |'))[$_%2]})*(78-in$a)
($z=($y='-'*5)*$b+"+$y+"+$y*($c=69-in$a))
$x+$w
'- - -'*$b+$w+'- - -'*$c
$x+$w
$z
$n*(83-in$a)
</code>```

Takes input as a string of capital letters, explicitly casts it as a char array. Constructs the "North" segment via looping from 0 to 4. Each loop, constructs a string of 5 spaces (if W/87 is present in the input), stores that in $x, then either |     | (stored in $w) or |  |  |, depending upon whether we're currently even or odd. That array of strings is stored into $n, and multiplied by whether N/78 is -in the input. That will determine if $n is placed on the pipeline or not.

Then, we construct the middle portion. The first line, $z is the "top" of the east-west route, using the same logic for W and E/69, and surrounded in parens to also place a copy on the pipeline. We use helper variable $y to save a byte on the ----- sections.

The next line is just the appropriate number of spaces (i.e., $x) string-concatenated with the correct-width pipes (i.e., $w). Then, the middle striped line, again with W and E logic and $w filling in the middle. Then $x+$w and $z again.

Finally, since the South road is the same as the north, put $n on the pipeline if S/83 is -in $a.

All of those resultant strings are gathered from the pipeline and output is implicit at the end of program execution. Abuses the default Write-Output delimiter to insert a newline between elements.

Examples

```<code>PS C:\Tools\Scripts\golfing> .\4-way-intersection.ps1 'EN'
|  |  |
|     |
|  |  |
|     |
|  |  |
+-----+-----
|     |
|     |- - -
|     |
+-----+-----

PS C:\Tools\Scripts\golfing> .\4-way-intersection.ps1 'SNW'
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
-----+-----+
     |     |
- - -|     |
     |     |
-----+-----+
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |

PS C:\Tools\Scripts\golfing> .\4-way-intersection.ps1 'WE'
-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----
</code>```

Title: 4-way intersection generator

Body:
PowerShell v3+, <s>226</s> <s>204</s> <s>192</s> 191 bytes

param([char[]]$a)($n=0..4|%{($x=' '*5*($b=87-in$a))+('|  |  |',($w='|     |'))[$_%2]})*(78-in$a)
($z=($y='-'*5)*$b+"+$y+"+$y*($c=69-in$a))
$x+$w
'- - -'*$b+$w+'- - -'*$c
$x+$w
$z
$n*(83-in$a)

Takes input as a string of capital letters, explicitly casts it as a char array. Constructs the "North" segment via looping from 0 to 4. Each loop, constructs a string of 5 spaces (if W/87 is present in the input), stores that in $x, then either |     | (stored in $w) or |  |  |, depending upon whether we're currently even or odd. That array of strings is stored into $n, and multiplied by whether N/78 is -in the input. That will determine if $n is placed on the pipeline or not.

Then, we construct the middle portion. The first line, $z is the "top" of the east-west route, using the same logic for W and E/69, and surrounded in parens to also place a copy on the pipeline. We use helper variable $y to save a byte on the ----- sections.

The next line is just the appropriate number of spaces (i.e., $x) string-concatenated with the correct-width pipes (i.e., $w). Then, the middle striped line, again with W and E logic and $w filling in the middle. Then $x+$w and $z again.

Finally, since the South road is the same as the north, put $n on the pipeline if S/83 is -in $a.

All of those resultant strings are gathered from the pipeline and output is implicit at the end of program execution. Abuses the default Write-Output delimiter to insert a newline between elements.

Examples

PS C:\Tools\Scripts\golfing> .\4-way-intersection.ps1 'EN'
|  |  |
|     |
|  |  |
|     |
|  |  |
+-----+-----
|     |
|     |- - -
|     |
+-----+-----

PS C:\Tools\Scripts\golfing> .\4-way-intersection.ps1 'SNW'
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
-----+-----+
     |     |
- - -|     |
     |     |
-----+-----+
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |

PS C:\Tools\Scripts\golfing> .\4-way-intersection.ps1 'WE'
-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----


答:
ABAP, <s>377</s> 365 bytes

```<code>REPORT r.PARAMETERS: x TYPE string,y TYPE string.DEFINE m.SHIFT &1 RIGHT CIRCULAR.TRANSLATE &1 USING 'W-E+S-N+'. END-OF-DEFINITION. DEFINE o.&1 = |{ &1 * 1 SIGN = RIGHTPLUS DECIMALS = 0 }|.TRANSLATE &1 using &2. END-OF-DEFINITION.
SPLIT: x AT space INTO DATA(a) DATA(b),y AT ' ' INTO DATA(c) DATA(d). m: a,b,c,d.a = a + c.b = b + d.o: a '-S+N',b '-W+E'.WRITE: a, b.
</code>```

Ungolfed:

```<code>REPORT r.
PARAMETERS: x TYPE string,
            y TYPE string.
DEFINE m.
  SHIFT &1 RIGHT CIRCULAR.
  TRANSLATE &1 USING 'W-E+S-N+'.
END-OF-DEFINITION.

DEFINE o.
  &1 = |{ &1 * 1 SIGN = RIGHTPLUS DECIMALS = 0 }|.
  TRANSLATE &1 using &2.
END-OF-DEFINITION.

SPLIT: x AT space INTO DATA(a) DATA(b),y AT ' ' INTO DATA(c) DATA(d).
m: a,b,c,d.
a = a + c.
b = b + d.
o: a '-S+N',b '-W+E'.
WRITE: a, b.
</code>```

It was actually challenging to be within 400 characters.

Some notes:

Original version had ADD c TO a. which is one of my favourite verbose statements.

The built-in editor would not accept this as a 1 liner

Using subroutines with FORM and PERFORM exploded the char count, so I kept to macros

Chaining statements with colons is discouraged outside of data declarations, but was needed for saving bytes

+ without a preceding space is an offset operator, requiring many spaces in the code

ABAP writes a space after numbers, hence the trick to just replace the sign

In order to use RIGHTPLUS the expression needed to be a number, so the need to mulitply with 1, but then the format has decimals.. so hence DECIMALS

Title: Traveling on a flat Earth

Body:
Coordinates in the flat-Earth world consist of latitude (x) and longitude (y), which are integers in the range 0...9999. Much like Gaussian integers, but they are always written using this notation:

```<code>411S 370E
</code>```

That is, with S or N appended to the latitude, and E or W appended to the longitude, with space(s) between the two components.

Goal

Write a program (not a function) that reads two coordinates, separated by whitespace, and outputs their sum. The first coordinate is a starting point, the second one is a displacement, and the output is the resulting position.

Input/Output

Since this challenge is partially about formatting, I'll try to define the input and output formats unambiguously.

The preferred input format has 1 space between the coordinate components, no leading zeros, and a newline character between the two coordinates. The program must be able to read the preferred format.

The output can contain any amount of whitespace and leading zeros. If it's different from the preferred input format, the program must be able to read this format too.

Just to make it clear, the input cannot (will not) contain any additional formatting characters. Just spaces and newlines where needed.

Scoring

This is an experiment on a new winning condition. I'll choose the winner by accepting an answer in a few weeks. If a better answer appears afterwards, I'll change the accepted answer.

The score for the program is its byte count. The winning program is one that is shorter than 400 bytes, has the fewest byte count, but is written in the most verbose programming language. To determine the winner:

Remove programs with byte count 400 or more (they can participate but cannot win)

Consider only the shortest program for each programming language

The longest program wins

Polyglots compete against programs in all languages in which they are valid (e.g. if a program is valid in both bash and sh, it competes against programs in both languages).

Test cases

In the test cases, the first two lines are the input, and the third line is the output.

```<code>0S 0E
0S 0W
0N 0E
</code>```

(the direction of zero doesn't matter, both in input and output)

```<code>0S 9999E
9999N 9999W
9999N 0E
</code>```

(maximal values)

```<code>42S 314W
42N 2718W
0N 3032W
</code>```

(the direction of zero doesn't matter in the output)

```<code>5555N 8888W
7777S 0E
2222S 8888W
</code>```

(no negative values; change the direction if you need to change the sign)

```<code>0001N        4545W
0999N        5454W
1000N        9999W
</code>```

(if the program outputs leading zeros and several spaces, it must be able to read them; it must also be able to read input that doesn't contain them)

```<code>8888N 8888W
9999N 9999W
</code>```

(invalid input - any behavior is acceptable, including crash and infinite loop)

Body:
ABAP, <s>377</s> 365 bytes

REPORT r.PARAMETERS: x TYPE string,y TYPE string.DEFINE m.SHIFT &1 RIGHT CIRCULAR.TRANSLATE &1 USING 'W-E+S-N+'. END-OF-DEFINITION. DEFINE o.&1 = |{ &1 * 1 SIGN = RIGHTPLUS DECIMALS = 0 }|.TRANSLATE &1 using &2. END-OF-DEFINITION.
SPLIT: x AT space INTO DATA(a) DATA(b),y AT ' ' INTO DATA(c) DATA(d). m: a,b,c,d.a = a + c.b = b + d.o: a '-S+N',b '-W+E'.WRITE: a, b.

Ungolfed:

REPORT r.
PARAMETERS: x TYPE string,
            y TYPE string.
DEFINE m.
  SHIFT &1 RIGHT CIRCULAR.
  TRANSLATE &1 USING 'W-E+S-N+'.
END-OF-DEFINITION.

DEFINE o.
  &1 = |{ &1 * 1 SIGN = RIGHTPLUS DECIMALS = 0 }|.
  TRANSLATE &1 using &2.
END-OF-DEFINITION.

SPLIT: x AT space INTO DATA(a) DATA(b),y AT ' ' INTO DATA(c) DATA(d).
m: a,b,c,d.
a = a + c.
b = b + d.
o: a '-S+N',b '-W+E'.
WRITE: a, b.

It was actually challenging to be within 400 characters.

Some notes:

Original version had ADD c TO a. which is one of my favourite verbose statements.

The built-in editor would not accept this as a 1 liner

Using subroutines with FORM and PERFORM exploded the char count, so I kept to macros

Chaining statements with colons is discouraged outside of data declarations, but was needed for saving bytes

+ without a preceding space is an offset operator, requiring many spaces in the code

ABAP writes a space after numbers, hence the trick to just replace the sign

In order to use RIGHTPLUS the expression needed to be a number, so the need to mulitply with 1, but then the format has decimals.. so hence DECIMALS


答:
PHP 291 Bytes.

```<code><?php $E=0;$N=0;$l=explode(PHP_EOL,STDIN);foreach($l as $i){ $x=explode(' ',$i); $s=(substr($x[0],-1,1)=='N')?1:-1; $N=$N+((substr($x[0],0,-1)*$s));$s=(substr($x[1],-1,1)=='E')?1:-1;$E=$E+((substr($x[1],0,-1))*$s);}$l=($E<=0)?'W':'E';$u=($N<=0)?'S':'N';echo'<br/>'.abs($N).$u.' '.abs($E).$l;
</code>```

Does not do anything clever, just plods through the problem.

```<code><?php
$lines = explode(PHP_EOL, STDIN);
foreach ($lines as $line) {
    $bits = explode(' ', $line);
    $sign = (substr($bits[0],-1, 1) == 'N')? 1 : -1;
    $N = $N + ( (substr($bits[0],0,-1) * $sign) );
    $sign = (substr($bits[1],-1, 1) == 'E')? 1 : -1;
    $E = $E + ( (substr($bits[1],0,-1)) * $sign );
}
$side = ($E<=0)?'W':'E';
$up = ($N<=0)?'S':'N';
echo '<br />'.abs($N).$up.' '.abs($E).$side;
</code>```

The rules should have an additional clause saying only the language with at least 2 entries can win.

Title: Traveling on a flat Earth

Body:
PHP 291 Bytes.

<?php $E=0;$N=0;$l=explode(PHP_EOL,STDIN);foreach($l as $i){ $x=explode(' ',$i); $s=(substr($x[0],-1,1)=='N')?1:-1; $N=$N+((substr($x[0],0,-1)*$s));$s=(substr($x[1],-1,1)=='E')?1:-1;$E=$E+((substr($x[1],0,-1))*$s);}$l=($E<=0)?'W':'E';$u=($N<=0)?'S':'N';echo'<br/>'.abs($N).$u.' '.abs($E).$l;

Does not do anything clever, just plods through the problem.

<?php
$lines = explode(PHP_EOL, STDIN);
foreach ($lines as $line) {
    $bits = explode(' ', $line);
    $sign = (substr($bits[0],-1, 1) == 'N')? 1 : -1;
    $N = $N + ( (substr($bits[0],0,-1) * $sign) );
    $sign = (substr($bits[1],-1, 1) == 'E')? 1 : -1;
    $E = $E + ( (substr($bits[1],0,-1)) * $sign );
}
$side = ($E<=0)?'W':'E';
$up = ($N<=0)?'S':'N';
echo '<br />'.abs($N).$up.' '.abs($E).$side;

The rules should have an additional clause saying only the language with at least 2 entries can win.


问:
Is this a Smith number?

Challenge description

A Smith number is a composite number whose sum of digits is equal to the sum of sums of digits of its prime factors. Given an integer N, determine if it's a Smith number or not.

The first few Smith numbers are 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346, 355, 378, 382, 391, 438 (sequence A006753 in OEIS).

Sample input / output

```<code>18: False (sum of digits: 1 + 8 = 9; factors: 2, 3, 3; sum of digits of factors: 2 + 3 + 3 = 8)
22: True
13: False (meets the digit requirement, but is prime)
666: True (sum of digits: 6 + 6 + 6 = 18; factors: 2, 3, 3, 37; sum of digits of factors: 2 + 3 + 3 + 3 + 7 = 18)
-265: False (negative numbers can't be composite)
0: False (not composite)
1: False (not composite)
4937775: True
</code>```

Notes

Your code can be a function (method) or a full working program,

Instead of words like True and False, you can use any truthy and falsy values, as long as it's clear what they are,

This is a code-golf challenge, so make your code as short as possible!

答:
Racket 176 bytes

```<code>(define(sd x)(if(= x 0)0(+(modulo x 10)(sd(/(- x(modulo x 10))10)))))
(require math)(define(f N)
(if(=(for/sum((i(factorize N)))(*(sd(list-ref i 0))(list-ref i 1)))(sd N))1 0))
</code>```

Returns 1 if true and 0 if false:

```<code>(f 27)
1
(f 28)
0
(f 85)
1
(f 86)
0
</code>```

Detailed version:

```<code>(define (sd x)   ; fn to find sum of digits
  (if (= x 0)
      0
      (+ (modulo x 10)
         (sd (/ (- x (modulo x 10)) 10)))))

(require math)
(define (f N)
  (if (= (for/sum ((i (factorize N)))
           (* (sd (list-ref i 0))
              (list-ref i 1)))
         (sd N)) 1 0))
</code>```

Title: Is this a Smith number?

Body:
Racket 176 bytes

(define(sd x)(if(= x 0)0(+(modulo x 10)(sd(/(- x(modulo x 10))10)))))
(require math)(define(f N)
(if(=(for/sum((i(factorize N)))(*(sd(list-ref i 0))(list-ref i 1)))(sd N))1 0))

Returns 1 if true and 0 if false:

(f 27)
1
(f 28)
0
(f 85)
1
(f 86)
0

Detailed version:

(define (sd x)   ; fn to find sum of digits
  (if (= x 0)
      0
      (+ (modulo x 10)
         (sd (/ (- x (modulo x 10)) 10)))))

(require math)
(define (f N)
  (if (= (for/sum ((i (factorize N)))
           (* (sd (list-ref i 0))
              (list-ref i 1)))
         (sd N)) 1 0))


问:
Divide a number by 3 without using *, /, +, -, % operators
Quoting this question on SO (Spoiler alert!):

This question has been asked in an Oracle interview.

How would you divide a number by 3 without using *, /, +, -, %,
  operators?

The number may be signed or unsigned.

The task is solvable, but see if you can write the shortest code.

Rules:

Perform the required integer division (/3)

Do not use the non-text-based operators *, /, +, -, or % (or their equivalents, such as __div__ or add()). This also applies to incrementing and decrementing operators, like i++ or i--. Use of operators for string concatenation and formatting are OK. Using these characters for different operators, such as unary - operator for negative numbers, or * to represent a pointer in C is OK as well.

Input value can be arbitrarily large (whatever your system can handle), both positive and negative

Input can be on STDIN or ARGV or entered any other way

Create the shortest code you can to do the above

答:
APL (NARS2000), 7 characters

Inspiration

```<code>⍎⍞,'r3'
</code>```

⍎ evaluate

⍞ text input

,'r3' followed by "r3"

So "15" becomes "15r3" which is NARS2000's rational point notation and evaluates to 5.

Note that the OP states

Input can be on STDIN or ARGV or entered any other way

Create the shortest code you can to do the above

which allows me to take input as string, and count code length in characters (not bytes – as this is a fairly old challenge that predates the adoption of bytes as default code length unit).

ContentLicense: CC BY-SA 4.0

Body:
APL (NARS2000), 7 characters

Inspiration

⍎⍞,'r3'

⍎ evaluate

⍞ text input

,'r3' followed by "r3"

So "15" becomes "15r3" which is NARS2000's rational point notation and evaluates to 5.

Note that the OP states

Input can be on STDIN or ARGV or entered any other way

Create the shortest code you can to do the above

which allows me to take input as string, and count code length in characters (not bytes – as this is a fairly old challenge that predates the adoption of bytes as default code length unit).


问:
Tips for golfing in PowerShell
What general tips do you have for golfing in Windows PowerShell? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to PowerShell (e.g. "remove comments" is not an answer). Please post one tip per answer.

—taken nearly verbatim from marcog's question.

答: Semicolons and line breaks are interchangeable. Golfed code is often more readable if not jammed into a single line. And the length is still the same (provided you use U+000A as line break which PowerShell handles without problems).</p>

Title: Tips for golfing in PowerShell

ContentLicense: CC BY-SA 2.5


答:
JavaScript, 123

Inspired by a longer version I came across in a Polish newsgroup (at least, Chrome thought it was Polish).

```<code>for(i=100,a=[];n=i--;a[i]=r)
  for(r=y='',x=5;n;y++,x^=7)
    for(m=n%x,n=n/x^0;m--;)
      r='IVXLC'[m>2?y+n-(n&=-2)+(m=1):+y]+r;
alert(a)
</code>```

Title: Count from 1 to 100... in Roman Numerals

Body:
Write a program that count from 1 to 100 in Roman Numerals and print these numbers by standard output. Each one of the numbers must be separated by spaces.

You cannot use any built in function to transform to roman numerals nor external application or library to do so.

The desired result is

```<code>I II III IV V VI VII VIII IX X XI XII XIII XIV XV XVI XVII XVIII XIX XX XXI XXII XXIII XXIV XXV XXVI XXVII XXVIII XXIX XXX XXXI XXXII XXXIII XXXIV XXXV XXXVI XXXVII XXXVIII XXXIX XL XLI XLII XLIII XLIV XLV XLVI XLVII XLVIII XLIX L LI LII LIII LIV LV LVI LVII LVIII LIX LX LXI LXII LXIII LXIV LXV LXVI LXVII LXVIII LXIX LXX LXXI LXXII LXXIII LXXIV LXXV LXXVI LXXVII LXXVIII LXXIX LXXX LXXXI LXXXII LXXXIII LXXXIV LXXXV LXXXVI LXXXVII LXXXVIII LXXXIX XC XCI XCII XCIII XCIV XCV XCVI XCVII XCVIII XCIX C
</code>```

As it is a code golf challenge, shortest code wins.

Body:
JavaScript, 123

Inspired by a longer version I came across in a Polish newsgroup (at least, Chrome thought it was Polish).

for(i=100,a=[];n=i--;a[i]=r)
  for(r=y='',x=5;n;y++,x^=7)
    for(m=n%x,n=n/x^0;m--;)
      r='IVXLC'[m>2?y+n-(n&=-2)+(m=1):+y]+r;
alert(a)


问:
Two Symbol Math

Introduction

The four basic math operators (+, -, *, /) can be reduced to just two, due to the fact that:

```<code>x + y = x - (-y)
x * y = x / (1/y), y != 0
x * 0 = 0/x
</code>```

Challenge

The challenge is to take input as a "string" containing:

Numbers

Single character variables ("x", "y")

The four basic math operators (+, -, *, /)

Parenthesis

and output a string manipulated so that it would produce the same mathematical result as the input, but containing only the mathematical symbols '-' and '/'

Specifics

Input can be in any acceptable form (file, STDIN, etc.) and may be represented as a string or character array (but not an array of arrays)

Output can be in any acceptable form (file, STDIN, etc.) and may be represented as a string or character array (but not an array of arrays)

You must recognize and maintain balanced parenthesis

Standard loopholes are disallowed

It is your choice if you want to represent x + y as x - -y or x - (-y)

You must maintain the order of operations

You never have to handle invalid input

Input can be empty or a single number/variable, in that case the program should output the input

Note: You do not have to use the substitutions in the introduction, so long as input = output, your program could change 2 * 2 to 8/2, if you wanted

You can assume that "0" is the only way a zero will appear in the equation (I.e. you don't have to handle 1 * (4 - 4))

Suggestion: to test your program, go to this website type in input = output, where input is the input, and output is the output, and if the result is "true" your program handled that case successfully (example, example)

Test Cases

Below are some test cases, input as a single string and output as a single string.

```<code>x + y
x - (-y)

x * y
x / (1/y)

x / y
x / y

x - y
x - y

1
1

5
5

-6
-6

+x
x

1 + (x * 4) - (512 * 3)
1 - (-(x / (1/4))) - (512 / (1/3))

1 - 3 / 4 + l / g
1 - 3/4 - (-(l / g))

5 * 0 / 2
0/5 / 2

(a + g) * 0
0/(a - (-g))
</code>```

Scoring

It's code-golf, so shortest answer in bytes wins. Ties are resolved by first-post.

答:
SED 272 246 239 213

```<code>s,^\+,,;s,[^+*/()-]\+,(&),g;t;:;s,)[^)]*)\*(0,&,;tr;s,\((.*)\)\*(0),(0/\1),;ty;s,\*([^)]*(,&,;tr;s,\*\(([^)]*)\),/(1/\1),;ty;s,\+([^)]*(,&,;tr;s,\+\(([^)]*)\),-(-\1),;ty;p;q;:r;s,(\([^()]*\)),!\1@,;t;:y;y,!@,(),;b
</code>```

Take input without spaces (e.g. x+y*2).

This is one of the few cases where it is actually shorter to just escape ( and ) for capture groups instead of using -r. I'm sure this can be golfed more, but I'm happy for now.

Ungolfed, with comments:

```<code>s,^\+,, #remove leading +
s,[^+*/()-]\+,(&),g #suround numbers/variables in ()
t start #reset the test because the line above will always match

:start
#------------- deal with *0 ------------------
s,)[^)]*)\*(0,&, #remove inner matching ()
t replace
s,\((.*)\)\*(0),(0/\1),
t y
#------------- deal with generic * -----------
s,\*([^)]*(,&, #remove inner matching ()
t replace
s,\*\(([^)]*)\),/(1/\1),
t y
#------------- deal with + -------------------
s,\+([^)]*(,&, #remove inner matching ()
t replace
s,\+\(([^)]*)\),-(-\1),
t y

b end #all done, branch to the end

#------------- replace a set of () with !@ ---
#repeated application of this helps find the matching ( or )
:replace
s,(\([^()]*\)),!\1@,
t start

:y
y,!@,(),
b start

:end
</code>```

Title: Two Symbol Math

Body:
SED 272 246 239 213

s,^\+,,;s,[^+*/()-]\+,(&),g;t;:;s,)[^)]*)\*(0,&,;tr;s,\((.*)\)\*(0),(0/\1),;ty;s,\*([^)]*(,&,;tr;s,\*\(([^)]*)\),/(1/\1),;ty;s,\+([^)]*(,&,;tr;s,\+\(([^)]*)\),-(-\1),;ty;p;q;:r;s,(\([^()]*\)),!\1@,;t;:y;y,!@,(),;b

Take input without spaces (e.g. x+y*2).

This is one of the few cases where it is actually shorter to just escape ( and ) for capture groups instead of using -r. I'm sure this can be golfed more, but I'm happy for now.

Ungolfed, with comments:

s,^\+,, #remove leading +
s,[^+*/()-]\+,(&),g #suround numbers/variables in ()
t start #reset the test because the line above will always match

:start
#------------- deal with *0 ------------------
s,)[^)]*)\*(0,&, #remove inner matching ()
t replace
s,\((.*)\)\*(0),(0/\1),
t y
#------------- deal with generic * -----------
s,\*([^)]*(,&, #remove inner matching ()
t replace
s,\*\(([^)]*)\),/(1/\1),
t y
#------------- deal with + -------------------
s,\+([^)]*(,&, #remove inner matching ()
t replace
s,\+\(([^)]*)\),-(-\1),
t y

b end #all done, branch to the end

#------------- replace a set of () with !@ ---
#repeated application of this helps find the matching ( or )
:replace
s,(\([^()]*\)),!\1@,
t start

:y
y,!@,(),
b start

:end


答:
Javascript (ES6), <s>190</s> <s>187</s> 185 bytes

This is an attempt to build this ASCII art character per character by iterating on a 17x15 matrix. Therefore, the output is always made of 15 rows of 17 columns with the intersection of the roads centered in the middle.

```<code>p=>eval("for(y=15,s='';y--;s+=`\n`)for(x=17;x--;)s+=' |-+'[+[a=y>4,b=y<10,c=x>4,d=x<12].every((c,i)=>c|p.search('SNEW'[i])+1)&&!((z=x-8||y&1|a&b)&&z*z-9)+2*!((z=y-7||x&1|c&d)&&z*z-4)]")
</code>```

Ungolfed and commented

```<code>for(y = 15, s = ''; y--; s += `\n`)   // iterate on y, from 14 to 0 / append line feeds
  for(x = 17; x--;)                   // iterate on x, from 16 to 0
    s += ' |-+' [                     // append next character to string
      +[ a = y > 4,                   // a = outside South area?
         b = y < 10,                  // b = outside North area?
         c = x > 4,                   // c = outside East area?
         d = x < 12 ]                 // d = outside West area?
      .every((c, i) =>                // for each area, see if either:
        c |                           //   - we're currently outside it
        p.search('SNEW' [i]) + 1      //   - or it's an allowed area (p = function param.)
      )                               // if all tests pass, add a:
      &&                              //   - vertical bar (encoded as 1) if:
      !((z = x - 8 || y & 1 | a & b)  //     - x=8, y is even and we're not in the middle
      && z * z - 9)                   //     - OR x=5 OR x=11 (<=> (x-8)*(x-8) = 9)
      + 2 *                           //   - horizontal bar (encoded as 2) if:
      !((z = y - 7 || x & 1 | c & d)  //     - y=7, x is even and we're not in the middle
      && z * z - 4)                   //     - OR y=5 OR y=9 (<=> (y-7)*(y-7) = 4)
    ]                                 // (vertical + horizontal = 3, which leads to '+')
</code>```

Matrix

Below is the matrix with the coordinates used in the code.

Demo

The following snippet allows to try any road configuration.

let f =
p=>eval("for(y=15,s='';y--;s+=`\n`)for(x=17;x--;)s+=' |-+'[+[a=y>4,b=y<10,c=x>4,d=x<12].every((c,i)=>c|p.search('SNEW'[i])+1)&&!((z=x-8||y&1|a&b)&&z*z-9)+2*!((z=y-7||x&1|c&d)&&z*z-4)]")

function update() {
  document.getElementById("o").innerHTML = f(document.getElementById("s").value);
}
update();```
<pre class="snippet-code-html lang-html prettyprint-override"><code><input id="s" size=4 value="NSEW" oninput="update()">
<pre id="o" style="font-size:9px">``````

Title: 4-way intersection generator

Body:
Here is an ASCII-art of a 4-way intersection:

```<code>     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
</code>```

(Note how the horizontal roads are 3 rows tall, while the vertical roads are 5 columns wide. This is for aesthetic reasons, because of the rectangular font.)

Your challenge is to produce this ASCII art. However, as I'm sure you all know, not every intersection has a road travelling off in every single direction. This particular intersection goes NESW, but some intersections might go, for example, NW:

```<code>     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
-----+-----+
     |     |
- - -|     |
     |     |
-----+-----+
</code>```

Or it might go SWE:

```<code>-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
</code>```

Or it may even go E, just a single direction (although you can hardly call this an intersection, but try to avoid being overly pedantic):

```<code>     +-----+-----
     |     |
     |     |- - -
     |     |
     +-----+-----
</code>```

You need to write a program or function that can easily generate any of these combinations. More specifically, your challenge is to write a program or function that takes a string of directions, consisting of NESW, as input, and outputs or returns this ASCII art of an intersection with roads pointing in those directions. These directions may appear in any order, but the input will not contain any characters except for N, E, S, or W. If you like, you may request inputs to be lowercase instead, but you must specify this in your answer. You may also assume that all inputs will contain at least one direction.

The last example had leading spaces on each line, because there is no road going west. If you do not have a road going west, these leading spaces are optional. This:

```<code>+-----+-----
|     |
|     |- - -
|     |
+-----+-----
</code>```

Would also be an acceptable output. Similarly, if N or S is gone, empty lines in there place are optional. One trailing newline is allowed, and trailing spaces are allowed as long as the output is visually the same.

You may take input and output in any reasonable format, such as STDIN/STDOUT, command line args, files, function arguments/return values, etc.

As usual, this is code-golf, so try to get the shortest possible answer in whatever language you happen to use!

Sample IO:

```<code>NESW:

     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |
-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----
     |  |  |
     |     |
     |  |  |
     |     |
     |  |  |

NS:

|  |  |
|     |
|  |  |
|     |
|  |  |
+-----+
|     |
|     |
|     |
+-----+
|  |  |
|     |
|  |  |
|     |
|  |  |

S:

+-----+
|     |
|     |
|     |
+-----+
|  |  |
|     |
|  |  |
|     |
|  |  |

EW:

-----+-----+-----
     |     |
- - -|     |- - -
     |     |
-----+-----+-----

SE:
+-----+-----
|     |
|     |- - -
|     |
+-----+-----
|  |  |
|     |
|  |  |
|     |
|  |  |
</code>```

Body:
Javascript (ES6), <s>190</s> <s>187</s> 185 bytes

This is an attempt to build this ASCII art character per character by iterating on a 17x15 matrix. Therefore, the output is always made of 15 rows of 17 columns with the intersection of the roads centered in the middle.

p=>eval("for(y=15,s='';y--;s+=`\n`)for(x=17;x--;)s+=' |-+'[+[a=y>4,b=y<10,c=x>4,d=x<12].every((c,i)=>c|p.search('SNEW'[i])+1)&&!((z=x-8||y&1|a&b)&&z*z-9)+2*!((z=y-7||x&1|c&d)&&z*z-4)]")

Ungolfed and commented

for(y = 15, s = ''; y--; s += `\n`)   // iterate on y, from 14 to 0 / append line feeds
  for(x = 17; x--;)                   // iterate on x, from 16 to 0
    s += ' |-+' [                     // append next character to string
      +[ a = y > 4,                   // a = outside South area?
         b = y < 10,                  // b = outside North area?
         c = x > 4,                   // c = outside East area?
         d = x < 12 ]                 // d = outside West area?
      .every((c, i) =>                // for each area, see if either:
        c |                           //   - we're currently outside it
        p.search('SNEW' [i]) + 1      //   - or it's an allowed area (p = function param.)
      )                               // if all tests pass, add a:
      &&                              //   - vertical bar (encoded as 1) if:
      !((z = x - 8 || y & 1 | a & b)  //     - x=8, y is even and we're not in the middle
      && z * z - 9)                   //     - OR x=5 OR x=11 (<=> (x-8)*(x-8) = 9)
      + 2 *                           //   - horizontal bar (encoded as 2) if:
      !((z = y - 7 || x & 1 | c & d)  //     - y=7, x is even and we're not in the middle
      && z * z - 4)                   //     - OR y=5 OR y=9 (<=> (y-7)*(y-7) = 4)
    ]                                 // (vertical + horizontal = 3, which leads to '+')

Matrix

Below is the matrix with the coordinates used in the code.

Demo

The following snippet allows to try any road configuration.

let f =
p=>eval("for(y=15,s='';y--;s+=`\n`)for(x=17;x--;)s+=' |-+'[+[a=y>4,b=y<10,c=x>4,d=x<12].every((c,i)=>c|p.search('SNEW'[i])+1)&&!((z=x-8||y&1|a&b)&&z*z-9)+2*!((z=y-7||x&1|c&d)&&z*z-4)]")

function update() {
  document.getElementById("o").innerHTML = f(document.getElementById("s").value);
}
update();

<input id="s" size=4 value="NSEW" oninput="update()">
<pre id="o" style="font-size:9px"></pre>


问:
Help: Aliens Programmers only speak ASCII

Setting the Scene:

It is an average afternoon, as you unwind after a long day by engaging in your favorite pastime: answering the plethora of captivating questions on PPCG. It hasn't been a good day for you; those damned Pyth programmers keep getting best answer and it's killing your vibe. Suddenly, you notice a new question has been posted! You make up your mind; not this time CJammers. Furiously, you begin to type, birthing a stream of characters; a fetus of the glorious BrainFuck loop that your end product will be. You type and type. Faster! Faster still! You're so focused you don't even notice the lights on your screen start to flicker on and off. Suddenly, the monitor glows green, an alien like symbol branded upon the desktop. Using your impeccable skills you cat ~/Desktop/aliensymbol and get presented with a bunch of numbers, a message! Being the shrewd PPCG programmer that you are, you notice that it looks like ASCII. No matter for you, you print(chr(i) for i in file) and decipher the message. Your first thought: "I need to share this with the community!".

...

Who would've thought it? That the first people to make contact with aliens would be the humble programmers of PPCG. Why us? Maybe it is because we are the epitome of human intelligence. Or maybe because BrainFuck is about as close as we have to an alien language. Nevertheless, the aliens - being the ultra-intelligent life forms that they are - want to test whether they should classify the human race as  intelligent or not. As a test of our mental prowess, the aliens have asked us to send them a few computer programs to demonstrate that we are technologically cultured. The issue is, the only human language they understand is numerical ASCII!

Help humankind show those creatures who the real intellectual alpha is. We need to send them a script that will convert our text based source codes into their numerical ASCII versions. Unfortunately, due to our underdeveloped technology (thanks Obama), we must send as small a translating program as possible. Good thing they chose to contact PPCG!

The Challenge:

The premise of this challenge is simple: you are to write a program that will take any program's source code (or any general text file for that matter), and output a space separated version of it with an ASCII translation below each line. That is, given an input of a text file, you need to output each line of that file followed by a line containing the ASCII representation of each character in the line above it (with each number lining up with the character it represents).

An example will greatly clarify this. Taking the source code of the infamous hello world as the input:

```<code>#include <stdio.h>

int main() {
    printf("hello, world\n");
    return 0;
}
</code>```

your program should output:

```<code>#   i   n   c   l   u   d   e       <   s   t   d   i   o   .   h   >
35  105 110 99  108 117 100 101 32  60  115 116 100 105 111 46  104 62  10

10
i   n   t       m   a   i   n   (   )       {
105 110 116 32  109 97  105 110 40  41  32  123 10
                p   r   i   n   t   f   (   "   h   e   l   l   o   ,       w   o   r   l   d   \   n   "   )   ;
32  32  32  32  112 114 105 110 116 102 40  34  104 101 108 108 111 44  32  119 111 114 108 100 92  110 34  41  59  10
                r   e   t   u   r   n       0   ;
32  32  32  32  114 101 116 117 114 110 32  48  59  10
}
125 10
</code>```

Implementation Details:

You may choose to take the input in whatever form you wish (opening file, command line pipe, function parameter etc.) and you should output to stdout or return the output from a function.

Things to note

Each character in the output is separated by a '\t' to allow for the space of 3 digits in the line below to line up (we are going to assume your tab is set to 4 spaces or more).

The newlines are displayed on the line that the return key was pressed (notice the 10's in the example)

The '\t' and '\n' printing requirements are lax. Your output must, in the general sense, look pleasing to the eye (need to show those aliens we have aesthetic sense as well), and if you can bend the previous two points while maintaining visual integrity, you will be forgiven.

You can choose to assume whether or not there is a newline at the end of the last line.

Scoring

This is code-golf so shortest program wins. Note, even if your program isn't the shortest, but uses really neat tricks relative to the language you are using, many +1's to you!

Good luck. The intergalactic intelligence ranking of humanity rests on your shoulders.

Note: Please forgive the plot holes. I'm not a writer :D

答:
Powershell, 56 Bytes

```<code>gc $args|%{($a=[char[]]$_)-join"    ";[int[]]$a+10-join"    "}
</code>```

Script accepts a filepath as input. Get-Content automatically splits input into an array of strings split on newlines in the source.

From there I enter a foreach, cast to an array of characters and set that to $a, join that with tabs and print it. Next but still within the foreach I cast the character array to an integer array, append a linefeed and join again with a tab.

Call looks like this:

```<code>PS C:\PretendFolder> .\aoua.ps1 ".\aoua.txt"
</code>```

and here is an output sample

```<code>#   i   n   c   l   u   d   e       <   s   t   d   i   o   .   h   >
35  105 110 99  108 117 100 101 32  60  115 116 100 105 111 46  104 62  10

10
i   n   t       m   a   i   n   (   )       {
105 110 116 32  109 97  105 110 40  41  32  123 10
                p   r   i   n   t   f   (   "   h   e   l   l   o   ,       w   o   r   l   d   \   n   "   )   ;
32  32  32  32  112 114 105 110 116 102 40  34  104 101 108 108 111 44  32  119 111 114 108 100 92  110 34  41  59  10
                r   e   t   u   r   n       0   ;
32  32  32  32  114 101 116 117 114 110 32  48  59  10
}
125 10
</code>```

Body:
Powershell, 56 Bytes

gc $args|%{($a=[char[]]$_)-join"    ";[int[]]$a+10-join"    "}

Script accepts a filepath as input. Get-Content automatically splits input into an array of strings split on newlines in the source.

From there I enter a foreach, cast to an array of characters and set that to $a, join that with tabs and print it. Next but still within the foreach I cast the character array to an integer array, append a linefeed and join again with a tab.

Call looks like this:

PS C:\PretendFolder> .\aoua.ps1 ".\aoua.txt"

and here is an output sample

#   i   n   c   l   u   d   e       <   s   t   d   i   o   .   h   >
35  105 110 99  108 117 100 101 32  60  115 116 100 105 111 46  104 62  10

10
i   n   t       m   a   i   n   (   )       {
105 110 116 32  109 97  105 110 40  41  32  123 10
                p   r   i   n   t   f   (   "   h   e   l   l   o   ,       w   o   r   l   d   \   n   "   )   ;
32  32  32  32  112 114 105 110 116 102 40  34  104 101 108 108 111 44  32  119 111 114 108 100 92  110 34  41  59  10
                r   e   t   u   r   n       0   ;
32  32  32  32  114 101 116 117 114 110 32  48  59  10
}
125 10


问:
Dimensional countdown
Write a function f(n,k) that displays the k-dimensional countdown from n.

A 1-dimensional countdown from 5 looks like

```<code> 54321
</code>```

A 2-dimensional countdown from 5 looks like

```<code> 54321
 4321
 321
 21
 1
</code>```

Finally, a 3-dimensional countdown from 5 looks like

```<code> 54321
 4321
 321
 21
 1
 4321
 321
 21
 1
 321
 21
 1
 21
 1
 1
</code>```

Formal definition

The 1-dimensional countdown from any n is a single line with the digits n, n-1,...,1 concatenated (followed by a newline).

For any k, the k-dimensional countdown from 1 is the single line

```<code> 1
</code>```

For n > 1 and k > 1, a k-dimensional countdown from n is a (k-1)-dimensional countdown from n followed by a k-dimensional countdown from n-1.

Input

Two positive integers k and n <= 9, in any format you choose.

Output

The k-dimensional countdown from n, with a newline after each 1-dimensional countdown. Extra newlines are permitted in the output.

Scoring

Standard golf scoring.

Bonus example

Here's an example with k > n, a 4-dimensional countdown from 3 (with extra comments that are not to be included in actual solutions):

```<code> -- 3-dimensional countdown from 3
 321
 21
 1
 21
 1
 1
 -- 4-dimensional countdown from 2:
 ---- 3-dimensional countdown from 2:
 21
 1
 1
 ---- 4-dimensional countdown from 1:
 1
</code>```

Clarifications:

Digits on a line do not need to be adjacent, but they must be evenly-spaced.

You may write a full program instead of just a function, if you prefer.

Title: Dimensional countdown

Body:
C 93 Bytes

Iterative implementation.

m,i,j;f(n,k){for(;m<k+2;m++)for(j=0;j<n;j++){for(i=m;i<n-j;i++)printf("%d",n-j-i);puts("");}}

C <s>67</s> <s>65</s> <s>61</s> <s>56</s> 52 Bytes

Recursive implementation

f(n,k){n*k?f(n,k-1)+f(n-1,k):puts("987654321"+9-n);}


问:
Build a sandpile
An abelian sandpile, for our purposes, is an infinite grid with integer coordinates, initially empty of sand. After each second, a grain of sand is placed at (0,0). Whenever a grid cell has 4 or more grains of sand, it spills one grain of sand to each of its four neighbors simultaneously. The neighbors of (x,y) are (x-1,y), (x+1,y), (x,y-1), and (x,y+1).

When a cell spills, it may cause its neighbors to spill. Some facts:

This cascade will eventually stop.

The order in which the cells spill is irrelevant; the result will be the same.

Example

After 3 seconds, the grid looks like

```<code>.....
.....
..3..
.....
.....
</code>```

After 4 seconds:

```<code>.....
..1..
.1.1.
..1..
.....
</code>```

After 15 seconds:

```<code>.....
..3..
.333.
..3..
.....
</code>```

And after 16 seconds:

```<code>..1..
.212.
11.11
.212.
..1..
</code>```

The challenge

In as few bytes as possible, write a function that takes a single positive
integer t and outputs a picture of the sandpile after t seconds.

Input

A single positive integer t, in any format you choose.

Output

A picture of the sandpile after t seconds, using the characters

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

Edit: Use any four distinct characters you like, or draw a picture. If you're not using ".123" or "0123", specify in your answer what the characters signify.

Unlike in the examples, your output should contain the minimal number of rows and columns necessary to show the nonzero part of the sandpile.

That is, for input 3, the output should be

```<code> 3
</code>```

For 4, the output should be

```<code> .1.
 1.1
 .1.
</code>```

Scoring

Standard golf scoring applies.

Rules

No language functions or libraries that already know what a sandpile is are allowed.

Edit: The output section has been edited, the character set restriction has been completely lifted. Use any four distinct characters or colors you like.

答:
J, 76 bytes

```<code>p=:0,.~0,.0,~0,]
p`(4&|+3 3([:+/@,*&(_3]\2|i.9));._3[:<.4%~p)@.([:*/4>{.)^:_
</code>```

I define a verb p which pads a border of zeros around the input. The main verb takes an array as input. It then checks the first row for any sandpile that contains 4 or more grains. If one does, it outputs the same array except padded using p, and otherwise it performs 2d convolution to simulate falling grains. The main verb is repeated until convergence using the power operator ^:_.

Usage

```<code>   p =: 0,.~0,.0,~0,]
   f =: p`(4&|+3 3([:+/@,*&(_3]\2|i.9));._3[:<.4%~p)@.([:*/4>{.)^:_
   f 15
0 3 0
3 3 3
0 3 0
   f 50
0 0 0 1 0 0 0
0 0 3 1 3 0 0
0 3 2 2 2 3 0
1 1 2 2 2 1 1
0 3 2 2 2 3 0
0 0 3 1 3 0 0
0 0 0 1 0 0 0
   timex 'r =: f 50000'
46.3472
   load 'viewmat'
   ((256#.3&#)"0<.255*4%~i._4) viewmat r
</code>```

It takes about 46 seconds to compute the result for n = 50000, and the result can be displayed using the viewmat addon with a monochrome color scheme.

Title: Build a sandpile

Body:
J, 76 bytes

p=:0,.~0,.0,~0,]
p`(4&|+3 3([:+/@,*&(_3]\2|i.9));._3[:<.4%~p)@.([:*/4>{.)^:_

I define a verb p which pads a border of zeros around the input. The main verb takes an array as input. It then checks the first row for any sandpile that contains 4 or more grains. If one does, it outputs the same array except padded using p, and otherwise it performs 2d convolution to simulate falling grains. The main verb is repeated until convergence using the power operator ^:_.

Usage

   p =: 0,.~0,.0,~0,]
   f =: p`(4&|+3 3([:+/@,*&(_3]\2|i.9));._3[:<.4%~p)@.([:*/4>{.)^:_
   f 15
0 3 0
3 3 3
0 3 0
   f 50
0 0 0 1 0 0 0
0 0 3 1 3 0 0
0 3 2 2 2 3 0
1 1 2 2 2 1 1
0 3 2 2 2 3 0
0 0 3 1 3 0 0
0 0 0 1 0 0 0
   timex 'r =: f 50000'
46.3472
   load 'viewmat'
   ((256#.3&#)"0<.255*4%~i._4) viewmat r

It takes about 46 seconds to compute the result for n = 50000, and the result can be displayed using the viewmat addon with a monochrome color scheme.


问:
The Path to the Result
Input:

A grid of varying size only containing numbers in the range 00-99, the following four characters: ^; >; v; <, and spaces to fill (and new-lines of course).

Output:

The result of the sum (integer) when you follow the path.

How does this work?

You start at the arrow with the highest number, and follow the path the arrows point to.

For each of the four arrows we'll do a different arithmetic calculation:

> = Addition (+);

< = Subtraction (−);

^ = Multiplication (* or × or ·);

v = Real / Calculator Division (/ or ÷);

(NOTE: The symbols between parenthesis are just added as clarification. If your programming language uses a completely different symbol for the arithmetic operation than the examples, then that is of course completely acceptable.)

Challenge rules:

You can choose the input (to some extent). A string-array would be most logical I think, but a symbol/newline-separated single string is also fine. (Full functions as input that are simply executed in the actual code snippet aren't allowed!)

Trailing spaces for the input are optional.

Numbers 0-9 will have a leading 0 so all numbers plus arrow are of an equal three-character length.

The number & arrow will always have the following format: DDA (D being a digit; A being one of the four arrows).

You use the current value with the previous arithmetic operation (the example below explains this better).

The final arithmetic operation can be ignored because of the rule above.

It is possible to have DDA's in the input-grid that aren't being used in the path to the resulting sum.

There won't be any test-cases for arrows that form a loop.

There won't be any test-cases for dividing by 0.

There won't be any test-cases where dividing creates a decimal sum-result. You only have to worry about integers.

EDIT: Since there weren't any answer yet, I decided to change the grids slightly to perhaps make it easier. I know this is usually not recommended to do with challenges, but since no answers were given yet, I think this will make it slightly easier, giving more (/any) answers:
<s>The spaces between de DDA's are random. There could even be no spaces in between at all.</s> All DDA's and spaces are grouped per three. Also, it is possible to have no spaces between DDA's at all.

Example:

Input:

```<code>94>      66v
   05v   08<
         43>
   03>   00^
</code>```

Path it follows:

```<code>Path it follows   |   Current sum value
________________________________________
94>               |   94  (highest value)
66v               |   160 (+)
08<               |   20  (/)
05v               |   15  (-)
03>               |   5   (/)
00^               |   5   (+)
43>               |   215 (*)
                          '>' after 43 is ignored because it's the last number
</code>```

Output: 215

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>94>      66v           ->     215
   05v   08<
         43>
   03>   00^

77>   80v55^02<        ->     -19
      20>   14^

22>11>15>80>14v        ->     -16
18^17>      10v
00^   90v43^02v
07^11<15<22v01<

99>98>97>96>95>94v     ->     102
93>92>   91v   03<
</code>```

答:
Python 2, 449 bytes

```<code>i=input();p,d,a,o,l=[-1,0],">",0,"+",0
for y in range(len(i)):
 for x in range(len(i[0])):
  if i[y][x]in"><^v":
   v=int(i[y][x-2]+i[y][x-1])
   if v>l:l=v;p=[x-2,y]
while 1:
 if d==">":p[0]+=1
 if d=="<":p[0]-=1
 if d=="^":p[1]-=1
 if d=="v":p[1]+=1
 try:
  c=i[p[1]][p[0]]
  if c in"><^v":
   d=c
   if p[0]<0 or p[1]<0:1/0
   a=eval(str(a)+o+str(int(i[p[1]][p[0]-2]+i[p[1]][p[0]-1])));o={">":"+","<":"-","^":"*","v":"/"}[c]
 except:print a;break
</code>```

This takes an array of strings as input

Ungolfed:

```<code>pointer = [-1,0]
dir = ">"
output=0
operation="+"

largest = 0
for y in range(len(input)):
    for x in range(len(input[0])):
        if input[y][x] in "><^v":
            value = int(input[y][x-2]+input[y][x-1])
            if value > largest: largest = value; pointer = [x-2, y]

while 1:
    if dir==">":pointer[0]+=1
    if dir=="<":pointer[0]-=1
    if dir=="^":pointer[1]-=1
    if dir=="v":pointer[1]+=1
    try:
        current = input[pointer[1]][pointer[0]]
        if current in "><^v":
            dir = current
            value = int(input[pointer[1]][pointer[0]-2]+input[pointer[1]][pointer[0]-1])

            if pointer[0]<0 or pointer[1]<0:1/0
            output=eval(str(output)+operation+str(value))

            if current==">":operation="+"
            if current=="<":operation="-"
            if current=="^":operation="*"
            if current=="v":operation="/"

    except:
        print output;break
</code>```

Title: The Path to the Result

Body:
Python 2, 449 bytes

i=input();p,d,a,o,l=[-1,0],">",0,"+",0
for y in range(len(i)):
 for x in range(len(i[0])):
  if i[y][x]in"><^v":
   v=int(i[y][x-2]+i[y][x-1])
   if v>l:l=v;p=[x-2,y]
while 1:
 if d==">":p[0]+=1
 if d=="<":p[0]-=1
 if d=="^":p[1]-=1
 if d=="v":p[1]+=1
 try:
  c=i[p[1]][p[0]]
  if c in"><^v":
   d=c
   if p[0]<0 or p[1]<0:1/0
   a=eval(str(a)+o+str(int(i[p[1]][p[0]-2]+i[p[1]][p[0]-1])));o={">":"+","<":"-","^":"*","v":"/"}[c]
 except:print a;break

This takes an array of strings as input

Ungolfed:

pointer = [-1,0]
dir = ">"
output=0
operation="+"

largest = 0
for y in range(len(input)):
    for x in range(len(input[0])):
        if input[y][x] in "><^v":
            value = int(input[y][x-2]+input[y][x-1])
            if value > largest: largest = value; pointer = [x-2, y]

while 1:
    if dir==">":pointer[0]+=1
    if dir=="<":pointer[0]-=1
    if dir=="^":pointer[1]-=1
    if dir=="v":pointer[1]+=1
    try:
        current = input[pointer[1]][pointer[0]]
        if current in "><^v":
            dir = current
            value = int(input[pointer[1]][pointer[0]-2]+input[pointer[1]][pointer[0]-1])

            if pointer[0]<0 or pointer[1]<0:1/0
            output=eval(str(output)+operation+str(value))

            if current==">":operation="+"
            if current=="<":operation="-"
            if current=="^":operation="*"
            if current=="v":operation="/"

    except:
        print output;break


答:
Batch, <s>351</s> <s>344</s> 341 bytes

```<code>@echo off
set/pi=
set t=
if not "%i:n=%"=="%i%" call:l
set l=-----
set r=%l%
if "%i:w=%"=="%i%" set l=%t%
if "%i:e=%"=="%i%" set r=
for %%s in (%l%+-----+%r% "%t%|%t%|" "%l:--=- %|%t%|%r:--=- %" "%t%|%t%|" %l%+-----+%r%) do echo %%~s
if "%i:s=%"=="%i%" exit/b
:l
call :m
call :n
:n
echo %t%^|%t%^|
:m
echo %t%^|  ^|  ^|
</code>```

Note: The line set t= ends in five spaces, and the line if "%i:e=%"=="%i%" set r= ends in a space. Takes case-insensitive input from STDIN. Edit: Saved 7 bytes by eliminating the d variable. Saved 3 bytes by using a for loop to print the middle section. If I'm allowed separate command-line parameters instead, then for <s>326</s> <s>319</s> 316 bytes:

```<code>@echo off
set t=%*
set/an=s=e=w=5,%t: ==%=0
set t=
call:%n%
set r=-----%t%
call set l=%%r:~%w%,5%%
call set r=%%r:~%e%%%
for %%s in (%l%+-----+%r% "%t%|%t%|" "%l:--=- %|%t%|%r:--=- %" "%t%|%t%|" %l%+-----+%r%) do echo %%~s
goto %s%
:0
call :1
call :2
:2
echo %t%^|%t%^|
:1
echo %t%^|  ^|  ^|
:5
</code>```

Title: 4-way intersection generator

Body:
Batch, <s>351</s> <s>344</s> 341 bytes

@echo off
set/pi=
set t=
if not "%i:n=%"=="%i%" call:l
set l=-----
set r=%l%
if "%i:w=%"=="%i%" set l=%t%
if "%i:e=%"=="%i%" set r=
for %%s in (%l%+-----+%r% "%t%|%t%|" "%l:--=- %|%t%|%r:--=- %" "%t%|%t%|" %l%+-----+%r%) do echo %%~s
if "%i:s=%"=="%i%" exit/b
:l
call :m
call :n
:n
echo %t%^|%t%^|
:m
echo %t%^|  ^|  ^|

Note: The line set t= ends in five spaces, and the line if "%i:e=%"=="%i%" set r= ends in a space. Takes case-insensitive input from STDIN. Edit: Saved 7 bytes by eliminating the d variable. Saved 3 bytes by using a for loop to print the middle section. If I'm allowed separate command-line parameters instead, then for <s>326</s> <s>319</s> 316 bytes:

@echo off
set t=%*
set/an=s=e=w=5,%t: ==%=0
set t=
call:%n%
set r=-----%t%
call set l=%%r:~%w%,5%%
call set r=%%r:~%e%%%
for %%s in (%l%+-----+%r% "%t%|%t%|" "%l:--=- %|%t%|%r:--=- %" "%t%|%t%|" %l%+-----+%r%) do echo %%~s
goto %s%
:0
call :1
call :2
:2
echo %t%^|%t%^|
:1
echo %t%^|  ^|  ^|
:5


问:
UNIX Uniq Uknow?

Challenge

You must write a program which takes a string and a flag as input and performs one of the following functions.

Input

If your language does not support command line arguments, you may take the arguments as input via STDIN.

The flag will be two characters: a dash and an ASCII character such as -d or -c.

Functions

The following is the list of functions which you must implement in your program. The title of each is the flag which corresponds to the function.

Counting: -c

This counts the number of duplicate lines in the input file. For example, if the input is:

```<code>aa
aa
bb
bb
bb
xx
</code>```

The output will be:

```<code>2 aa
3 bb
1 xx
</code>```

Because there are two lines of aa, three lines of bb, and one line of xx. The output should be separated by newlines.

Duplication: -d

This shows which lines are duplicates. For example, using the above example string (aa\naa\nbb\nbb\nbb\nxx), the output would be:

```<code>aa
bb
</code>```

Because these are lines which have been duplicated. You should only output each line once.

Duplication: -D

This is almost the same as -d except it outputs each line the number of times that it occurs in the input file. For example, using the example string the output will be:

```<code>aa
aa
bb
bb
bb
</code>```

Because aa occurs twice and bb occurs three times.

Unique: -u

Similar to above except it only prints unique lines. For example, using the example file, the output will be:

```<code>xx
</code>```

Because xx is the only unique line. Also, due to xx being unique, you will only ever have to output this once.

Example

Note that although the input string will not always be sorted, the output must be sorted alphabetically. For example, for the following input:

```<code>hello world
apple pie
zebra
dog
hello world
apple pie
apple pie
apple pie
</code>```

The output for each of the flags would be:

-c

```<code>4 apple pie
1 dog
2 hello world
1 zebra
</code>```

-d

```<code>apple pie
hello world
</code>```

-D

```<code>apple pie
apple pie
apple pie
apple pie
hello world
hello world
</code>```

-u

```<code>dog
zebra
</code>```

Rules

Your programs must not use the UNIX program uniq as, frankly, that is plain cheating.

All output should be to STDOUT.

The file will only ever contain lowercase, alphabetical characters, newlines and spaces:

```<code>2 aa
3 bb
1 xx
</code>```0

The output should be sorted alphabetically.

In case there is any confusion, programs written on any operating system can enter. The challenge is not limited to UNIX.

As per PPCG standard, functions and anonymous functions are allowed, taking input via their arguments and outputting via a returned string.

Winning

As this is code-golf, the shortest code in bytes wins.

答:
Java, 19(import java.util.*;) + 315 = 334 bytes

```<code>String f(String[]r,String q){TreeMap<String,Integer>m=new TreeMap();for(String s:r)m.put(s,m.get(s)==null?1:m.get(s)+1);int a=q.charAt(1),v;String o="",k;for(Map.Entry<String,Integer>e:m.entrySet()){v=e.getValue();k=e.getKey()+"\n";while(68==a&&v-->1)o+=k;o+='u'==a&&v<2||'d'==a&&v>1?k:99==a?v+" "+k:"";}return o;}}
</code>```

Usage

```<code>String[] input = {"hello world","apple pie","zebra","dog","hello world","apple pie","apple pie","apple pie"};
System.out.println("-c");
System.out.println(f(input,"-c"));
System.out.println("-d");
System.out.println(f(input,"-d"));
System.out.println("-D");
System.out.println(f(input,"-D"));
System.out.println("-u");
System.out.println(f(input,"-u"));
</code>```

Output

```<code>-c
4 apple pie
1 dog
2 hello world
1 zebra

-d
apple pie
hello world

-D
apple pie
apple pie
apple pie
hello world

-u
dog
zebra
</code>```

Explanation
A TreeMap<String, Integer> is used to store pairs of words and how many times they were repeated. The TreeMap is sorted so no extra call to sort it is required. Ternary operator is used to construct the output string regarding the input argument.

Title: UNIX Uniq Uknow?

Body:
Java, 19(import java.util.*;) + 315 = 334 bytes

String f(String[]r,String q){TreeMap<String,Integer>m=new TreeMap();for(String s:r)m.put(s,m.get(s)==null?1:m.get(s)+1);int a=q.charAt(1),v;String o="",k;for(Map.Entry<String,Integer>e:m.entrySet()){v=e.getValue();k=e.getKey()+"\n";while(68==a&&v-->1)o+=k;o+='u'==a&&v<2||'d'==a&&v>1?k:99==a?v+" "+k:"";}return o;}}

Usage

String[] input = {"hello world","apple pie","zebra","dog","hello world","apple pie","apple pie","apple pie"};
System.out.println("-c");
System.out.println(f(input,"-c"));
System.out.println("-d");
System.out.println(f(input,"-d"));
System.out.println("-D");
System.out.println(f(input,"-D"));
System.out.println("-u");
System.out.println(f(input,"-u"));

Output

-c
4 apple pie
1 dog
2 hello world
1 zebra

-d
apple pie
hello world

-D
apple pie
apple pie
apple pie
hello world

-u
dog
zebra

Explanation
A TreeMap<String, Integer> is used to store pairs of words and how many times they were repeated. The TreeMap is sorted so no extra call to sort it is required. Ternary operator is used to construct the output string regarding the input argument.


问:
A Fragile Quine

A Fragile Quine

A fragile quine is a quine that satisfies the property of having each substring made by removing a single character, when evaluated, produces an error.

For example. If your program asdf is a quine, then for it to be fragile, the following programs must error:

```<code>sdf
adf
asf
asd
</code>```

Your program (and all of its substrings) must be fully deterministic, and must be in the same language. A program falling into an infinite loop (that is, failing to terminate), even if not eventually producing an error is considered to "produce an error" for the purposes of this challenge.

Standard loopholes apply, including the usual quine restrictions (e.g. not able to read own source code).

For example, print("foo") is not fragile. All these substrings must error:

```<code>rint("foo")
pint("foo")
prnt("foo")
prit("foo")
prin("foo")
print"foo")
print(foo")
print("oo")
print("fo")
print("fo")
print("foo)
print("foo"
</code>```

The ones that don't error are:

```<code>print("oo")
print("fo")
print("fo")
</code>```

So it is not fragile.

An important note on quines

By consensus, any possible quine must satisfy this:

It must be possible to identify a section of the program which encodes a different part of the program. ("Different" meaning that the two parts appear in different positions.)

Furthermore, a quine must not access its own source, directly or indirectly.

Example

Since I consider JavaScript's function#toString to be "reading it's own source code", I am disallowing it. However, if I weren't to bar it, here is a fragile quine in JavaScript:

```<code>f=(n=b=`f=${f}`)=>(a=(n)==`f=${f}`,n=0,a)&(n!=b)?b:q
</code>```

Tester

Here is a program that, given the source code of your program, generates all programs that must error.

let f = (s) =>
  [...Array(s.length).keys()].map(i =>
    s.slice(0, i) + s.slice(i + 1)).join("\n");

let update = () => {
  output.innerHTML = "";
  output.appendChild(document.createTextNode(f(input.value)));
};

input.addEventListener("change", update);

update();```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#output {
  white-space: pre;
}

#input, #output {
  font-family: Consolas, monospace;
}</code>```

<input id="input" value="print('foo')">

```

答:
Python 2, 59 bytes

```<code>x='x=%r;1/(len(x)==30);print x%%x';1/(len(x)==30);print x%x
</code>```

This throws a ZeroDivisionError if a 0, a 3, or a character is removed from the string. Removing a different character results in a NameError or a SyntaxError.

Title: A Fragile Quine

Body:
Python 2, 59 bytes

x='x=%r;1/(len(x)==30);print x%%x';1/(len(x)==30);print x%x

This throws a ZeroDivisionError if a 0, a 3, or a character is removed from the string. Removing a different character results in a NameError or a SyntaxError.


问:
Greater than less than greater than something fishy
Given a length N string of less-than and greater-than signs (<, >), insert the integers 0 through N at the start and end and in between each pair of signs such that all the inequalities are satisfied. Output the resulting string. If there are multiple valid outputs, output any one (and just one) of them.

For example

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

has 7 characters so all the numbers from 0 to 7 inclusive must be inserted. A valid output is

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

because all the inequalities taken one at a time

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

are true.

If desired, the output may have spaces surrounding the signs, e.g. 2 < 3 < 4 > 1 < 5 > 0 < 6 < 7.

The shortest code in bytes wins.

Test Cases

The first line after an empty line is the input and the next line(s) are each valid output examples.

```<code>[empty string]
0

<
0<1

>
1>0

<<
0<1<2

<>
1<2>0

><
1>0<2
2>0<1

>>
2>1>0

<<<
0<1<2<3

><>
1>0<3>2

>><
3>2>0<1
3>1>0<2
2>1>0<3

>>>
3>2>1>0

>>><<<
3>2>1>0<4<5<6
6>3>1>0<2<4<5
4>2>1>0<3<5<6
4>3>1>0<2<5<6

<<><><<
2<3<4>1<5>0<6<7

>><><>>
7>6>0<5>1<4>3>2

<<<<<<<<<<<<<<
0<1<2<3<4<5<6<7<8<9<10<11<12<13<14

>><<<<><>><><<
6>5>4<7<8<9<10>3<11>2>1<12>0<13<14
14>5>4<7<8<9<10>3<11>2>1<12>0<13<6
</code>```

答:
Retina, 20 bytes

Byte count assumes ISO 8859-1 encoding.

```<code>
$.'
S`>
%O#`\d+
¶
></code>```

Try it online! (The first line enables a linefeed-separated test-suite.)

Explanation

A simple way to find a valid permutation is to start by inserting the numbers from 0 to N in order, and then to reverse the numbers surrounding each substring of >s. Take <><<>>><< as an example:

```<code>0<1>2<3<4>5>6>7<8<9
  ---   -------      these sections are wrong, so we reverse them
0<2>1<3<7>6>5>4<8<9
</code>```

Both of those tasks are fairly simple in Retina, even though all we can really work with are strings. We can save an additional byte by inserting the numbers from N down to 0 and reversing the sections surrounding < instead, but the principle is the same.

Stage 1: Substitution

```<code>
$.'</code>```

We start by inserting the length of $' (the suffix, i.e. everything after the match) into every possible position in the input. This inserts the numbers from N down to 0.

Stage 2: Split

```<code>S`>
</code>```

We split the input around > into separate lines, so each line is either an individual number or a list of numbers joined with <.

Stage 3: Sort

```<code>%O#`\d+
</code>```

Within each line (%) we sort (O) the numbers (\d#) by their numerical value (#). Since we inserted the number in reverse numerical order, this reverses them.

Stage 4: Substitution

```<code>¶
>
</code>```

We turn the linefeeds into > again to join everything back into a single line. That's it.

As a side note, I've been meaning to add a way to apply % to other delimiters than linefeeds. Had I already done that, this submission would have been 14 bytes, because then the last three stages would have been reduced to a single one:

```<code>%'>O#`\d+
</code>```

Body:
Retina, 20 bytes

Byte count assumes ISO 8859-1 encoding.

$.'
S`>
%O#`\d+
¶
>

Try it online! (The first line enables a linefeed-separated test-suite.)

Explanation

A simple way to find a valid permutation is to start by inserting the numbers from 0 to N in order, and then to reverse the numbers surrounding each substring of >s. Take <><<>>><< as an example:

0<1>2<3<4>5>6>7<8<9
  ---   -------      these sections are wrong, so we reverse them
0<2>1<3<7>6>5>4<8<9

Both of those tasks are fairly simple in Retina, even though all we can really work with are strings. We can save an additional byte by inserting the numbers from N down to 0 and reversing the sections surrounding < instead, but the principle is the same.

Stage 1: Substitution

$.'

We start by inserting the length of $' (the suffix, i.e. everything after the match) into every possible position in the input. This inserts the numbers from N down to 0.

Stage 2: Split

S`>

We split the input around > into separate lines, so each line is either an individual number or a list of numbers joined with <.

Stage 3: Sort

%O#`\d+

Within each line (%) we sort (O) the numbers (\d#) by their numerical value (#). Since we inserted the number in reverse numerical order, this reverses them.

Stage 4: Substitution

¶
>

We turn the linefeeds into > again to join everything back into a single line. That's it.

As a side note, I've been meaning to add a way to apply % to other delimiters than linefeeds. Had I already done that, this submission would have been 14 bytes, because then the last three stages would have been reduced to a single one:

%'>O#`\d+


答:
Haskell, 162 bytes

```<code>import Data.List
(a:b)%(c:d)=show c++a:b%d
_%[x]=show x
f l=map(l%).filter(l#)$permutations[0..length l]
(e:f)#(x:y:z)=(e!x)y&&f#(y:z)
_#_=0<1
'>'!x=(>)x
_!x=(<)x
</code>```

This is friggin' long.

Title: Greater than less than greater than something fishy

Body:
Given a length N string of less-than and greater-than signs (<, >), insert the integers 0 through N at the start and end and in between each pair of signs such that all the inequalities are satisfied. Output the resulting string. If there are multiple valid outputs, output any one (and just one) of them.

For example

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

has 7 characters so all the numbers from 0 to 7 inclusive must be inserted. A valid output is

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

because all the inequalities taken one at a time

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

are true.

If desired, the output may have spaces surrounding the signs, e.g. 2 < 3 < 4 > 1 < 5 > 0 < 6 < 7.

The shortest code in bytes wins.

Test Cases

The first line after an empty line is the input and the next line(s) are each valid output examples.

```<code>[empty string]
0

<
0<1

>
1>0

<<
0<1<2

<>
1<2>0

><
1>0<2
2>0<1

>>
2>1>0

<<<
0<1<2<3

><>
1>0<3>2

>><
3>2>0<1
3>1>0<2
2>1>0<3

>>>
3>2>1>0

>>><<<
3>2>1>0<4<5<6
6>3>1>0<2<4<5
4>2>1>0<3<5<6
4>3>1>0<2<5<6

<<><><<
2<3<4>1<5>0<6<7

>><><>>
7>6>0<5>1<4>3>2

<<<<<<<<<<<<<<
0<1<2<3<4<5<6<7<8<9<10<11<12<13<14

>><<<<><>><><<
6>5>4<7<8<9<10>3<11>2>1<12>0<13<14
14>5>4<7<8<9<10>3<11>2>1<12>0<13<6
</code>```

Body:
Haskell, 162 bytes

import Data.List
(a:b)%(c:d)=show c++a:b%d
_%[x]=show x
f l=map(l%).filter(l#)$permutations[0..length l]
(e:f)#(x:y:z)=(e!x)y&&f#(y:z)
_#_=0<1
'>'!x=(>)x
_!x=(<)x

This is friggin' long.