答:
Vim 57 keystrokes

```<code>:s/[^a-zA-Z_ ]//g<cr>A <cr>ylwv$:s/\%V\c<c-v><c-r>"\h* //eg<c-v><cr>@q<esc>0"qDk@q
</code>```

Explanation:

```<code>:s/[^a-zA-Z_ ]//g                                 #Remove all invalid chars.
A <cr>                                            #Enter insert mode, and enter
                                                  #a space and a newline at the end
ylwv$:s/\\c%V<c-v><c-r>"\h* //eg<c-v><cr>@q<esc>  #Enter all of this text on the
                                                  #next line

0                                                 #Go to the beginning of the line
"qD                                               #Delete this line into register
                                                  #"q"
k@q                                               #Run "q" as a macro

#Macro
ylw                                               #Yank a single letter
   v$                                             #Visual selection to end of line
     :s/                                          #Substitute regex
       \%V\c                                      #Only apply to the selection and
                                                  #ignore case
            <c-v><c-r>"                           #Enter the yanked letter
                       \h*                        #All "Head of word" chars
                                                  #And a space
                           //                     #Replace with an empty string
                             eg                   #Continue the macro if not found
                                                  #Apply to all matches
                               <c-v><cr>          #Enter a <CR> literal
                                        @q<esc>   #Recursively call the macro
</code>```

I'm really dissapointed by how long this one is. The "Invalid" chars (everything but a-z, A-Z, _ and space) really threw me off. I'm sure there's a better way to do this:

```<code>:s/[^a-zA-Z_ ]//g
</code>```

Since \h matches all of that expect for the space, but I can't figure out how to put the metachar in a range. If anyone has tips, I'd love to hear em.

Title: Find the first word starting with each letter

Body:
Given a string, find the first word starting with each letter (case insensitive).

Sample

Using Ferulas flourish in gorgeous gardens. as input:

```<code>"Ferulas flourish in gorgeous gardens."
 ^^^^^^^          ^^ ^^^^^^^^
 |                |  |
 |                |  --> is the first word starting with `g`
 |                --> is the first word starting with `i`
 --> is the first word starting with `f`
</code>```

Then, the output for this sample should be the matched words joined by one single space:

```<code>"Ferulas in gorgeous"
</code>```

Challenge

Both input and output must be a string representation, or the closest alternative in your language.

Program or function allowed.

You can consider a word being at least one of: lowercase or uppercase letters, digits, underscore.

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

Another samples:

```<code>input: "Take all first words for each letter... this is a test"
output: "Take all first words each letter is"
</code>```

```<code>input: "Look ^_^ .... There are 3 little dogs :)"
output: "Look _ There are 3 dogs"
</code>```

```<code>input: "...maybe some day 1 plus 2 plus 20 could result in 3"
output: "maybe some day 1 plus 2 could result in 3"
</code>```

Body:
Vim 57 keystrokes

:s/[^a-zA-Z_ ]//g<cr>A <cr>ylwv$:s/\%V\c<c-v><c-r>"\h* //eg<c-v><cr>@q<esc>0"qDk@q

Explanation:

:s/[^a-zA-Z_ ]//g                                 #Remove all invalid chars.
A <cr>                                            #Enter insert mode, and enter
                                                  #a space and a newline at the end
ylwv$:s/\\c%V<c-v><c-r>"\h* //eg<c-v><cr>@q<esc>  #Enter all of this text on the
                                                  #next line

0                                                 #Go to the beginning of the line
"qD                                               #Delete this line into register
                                                  #"q"
k@q                                               #Run "q" as a macro

#Macro
ylw                                               #Yank a single letter
   v$                                             #Visual selection to end of line
     :s/                                          #Substitute regex
       \%V\c                                      #Only apply to the selection and
                                                  #ignore case
            <c-v><c-r>"                           #Enter the yanked letter
                       \h*                        #All "Head of word" chars
                                                  #And a space
                           //                     #Replace with an empty string
                             eg                   #Continue the macro if not found
                                                  #Apply to all matches
                               <c-v><cr>          #Enter a <CR> literal
                                        @q<esc>   #Recursively call the macro

I'm really dissapointed by how long this one is. The "Invalid" chars (everything but a-z, A-Z, _ and space) really threw me off. I'm sure there's a better way to do this:

:s/[^a-zA-Z_ ]//g

Since \h matches all of that expect for the space, but I can't figure out how to put the metachar in a range. If anyone has tips, I'd love to hear em.


问:
Diamondize a Matrix
Given a matrix, output a representation of the matrix where the top left element is on top, the anti-diagonal is the central row and the bottom right element is at the bottom.

For example, consider the following matrix:

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

The diamond version of this matrix is:

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

Inputs and outputs

An input matrix will be given as a list of lists (or anything similar in your language of choice). The output shall be a list of lists as well.

The matrices will only contain positive integers.

The input matrix will not necessarily be square.

The input matrix will be at least 1×1.

Test Cases

```<code>Input:  [[1]]
Output: [[1]]

Input:  [[1,2],[3,4]]
Output: [[1],[3,2],[4]]

Input:  [[1,2,3],[4,5,6]]
Output: [[1],[4,2],[5,3],[6]]

Input:  [[11,2,5],[3,99,3],[4,8,15],[16,23,42]]
Output: [[11],[3,2],[4,99,5],[16,8,3],[23,15],[42]]
</code>```

Scoring

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

答:
Python, 91 bytes

```<code>e=enumerate
lambda M:[[r[n-i]for i,r in e(M)if-1<n-i<len(r)][::-1]for n,_ in e(M[1:]+M[0])]
</code>```

Test it on Ideone.

Python + NumPy, 69 bytes

```<code>import numpy
lambda M:map(M[::-1].diagonal,range(1-len(M),len(M[0])))
</code>```

Expects a 2D NumPy array as input and returns a list of NumPy arrays. Test it on Ideone.

ContentLicense: CC BY-SA 3.0

Title: Diamondize a Matrix

Body:
Python, 91 bytes

e=enumerate
lambda M:[[r[n-i]for i,r in e(M)if-1<n-i<len(r)][::-1]for n,_ in e(M[1:]+M[0])]

Test it on Ideone.

Python + NumPy, 69 bytes

import numpy
lambda M:map(M[::-1].diagonal,range(1-len(M),len(M[0])))

Expects a 2D NumPy array as input and returns a list of NumPy arrays. Test it on Ideone.


答:
Python 2, <s>88</s> 87 bytes

lambda L:[filter(None,x)[::-1]for x in map(None,[],*[i*[0]+r for i,r in enumerate(L)])]
```

Prepend 0s, zip, then remove falsy elements. Returns a list of tuples. This uses map(None,...) to perform zip_longest  (padding missing spots with None) and filter(None,...) to remove falsy elements.

Annoyingly, we need to add an extra [] row to the map to guarantee that a list of tuples is returned, since map(None,*[[1]]) returns [1] rather than [(1,)] for a 1x1 matrix. The extra row gets stripped out by the filter though.

(Thanks to @Dennis for -1 byte)

Title: Diamondize a Matrix

Body:
Given a matrix, output a representation of the matrix where the top left element is on top, the anti-diagonal is the central row and the bottom right element is at the bottom.

For example, consider the following matrix:

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

The diamond version of this matrix is:

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

Inputs and outputs

An input matrix will be given as a list of lists (or anything similar in your language of choice). The output shall be a list of lists as well.

The matrices will only contain positive integers.

The input matrix will not necessarily be square.

The input matrix will be at least 1×1.

Test Cases

```<code>Input:  [[1]]
Output: [[1]]

Input:  [[1,2],[3,4]]
Output: [[1],[3,2],[4]]

Input:  [[1,2,3],[4,5,6]]
Output: [[1],[4,2],[5,3],[6]]

Input:  [[11,2,5],[3,99,3],[4,8,15],[16,23,42]]
Output: [[11],[3,2],[4,99,5],[16,8,3],[23,15],[42]]
</code>```

Scoring

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

Body:
Python 2, <s>88</s> 87 bytes

lambda L:[filter(None,x)[::-1]for x in map(None,[],*[i*[0]+r for i,r in enumerate(L)])]

Prepend 0s, zip, then remove falsy elements. Returns a list of tuples. This uses map(None,...) to perform zip_longest  (padding missing spots with None) and filter(None,...) to remove falsy elements.

Annoyingly, we need to add an extra [] row to the map to guarantee that a list of tuples is returned, since map(None,*[[1]]) returns [1] rather than [(1,)] for a 1x1 matrix. The extra row gets stripped out by the filter though.

(Thanks to @Dennis for -1 byte)


问:
Find the first word starting with each letter
Given a string, find the first word starting with each letter (case insensitive).

Sample

Using Ferulas flourish in gorgeous gardens. as input:

```<code>"Ferulas flourish in gorgeous gardens."
 ^^^^^^^          ^^ ^^^^^^^^
 |                |  |
 |                |  --> is the first word starting with `g`
 |                --> is the first word starting with `i`
 --> is the first word starting with `f`
</code>```

Then, the output for this sample should be the matched words joined by one single space:

```<code>"Ferulas in gorgeous"
</code>```

Challenge

Both input and output must be a string representation, or the closest alternative in your language.

Program or function allowed.

You can consider a word being at least one of: lowercase or uppercase letters, digits, underscore.

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

Another samples:

```<code>input: "Take all first words for each letter... this is a test"
output: "Take all first words each letter is"
</code>```

```<code>input: "Look ^_^ .... There are 3 little dogs :)"
output: "Look _ There are 3 dogs"
</code>```

```<code>input: "...maybe some day 1 plus 2 plus 20 could result in 3"
output: "maybe some day 1 plus 2 could result in 3"
</code>```

答:
JavaScript (ES6), <s>73</s> 71 bytes

s=>s.match(u=/\w+/g).filter(w=>u[n=parseInt(w[0],36)]?0:u[n]=1).join` `
```

<p><em>Saved 2 bytes thanks to @edc65!</em></p>

<h2>Test</h2>

<p><div class="snippet" data-lang="js" data-hide="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>var solution = s=>s.match(u=/\w+/g).filter(w=>u[n=parseInt(w[0],36)]?0:u[n]=1).join` `;
var testCases = [
  "Ferulas flourish in gorgeous gardens.",
  "Take all first words for each letter... this is a test",
  "Look ^_^ .... There are 3 little dogs :)",
  "...maybe some day 1 plus 2 plus 20 could result in 3"
];
document.write("```"+testCases.map(t=>t+"\n"+solution(t)).join("\n\n")+"```");</code>```

Body:
JavaScript (ES6), <s>73</s> 71 bytes

s=>s.match(u=/\w+/g).filter(w=>u[n=parseInt(w[0],36)]?0:u[n]=1).join` `

Saved 2 bytes thanks to @edc65!

Test

var solution = s=>s.match(u=/\w+/g).filter(w=>u[n=parseInt(w[0],36)]?0:u[n]=1).join` `;
var testCases = [
  "Ferulas flourish in gorgeous gardens.",
  "Take all first words for each letter... this is a test",
  "Look ^_^ .... There are 3 little dogs :)",
  "...maybe some day 1 plus 2 plus 20 could result in 3"
];
document.write("<pre>"+testCases.map(t=>t+"\n"+solution(t)).join("\n\n")+"</pre>");


答:
Julia, <s>165</s> <s>155</s> <s>151</s> <s>129</s> 102 bytes

g(s,d=[])=join(filter(i->i!=0,[(c=lcfirst(w)[1])∈d?0:(d=[d;c];w)for w=split(s,r"\W",keep=1<0)])," ")
```

<p>This is a function that accepts a string and returns a string.</p>

<p>Ungolfed:</p>

<pre class="lang-default prettyprint-override"><code>function g(s, d=[])
    # Split the string into an array on unwanted characters, then for
    # each word, if the first letter has been encountered, populate
    # this element of the array with 0, otherwise note the first letter
    # and use the word. This results in an array of words and zeros.
    x = [(c = lcfirst(w)[1]) ∈ d ? 0 : (d = [d; c]; w) for w = split(s, r"\W", keep=1<0)]

    # Remove the zeros, keeping only the words. Note that this works
    # even if the word is the string "0" since 0 != "0".
    z = filter(i -> i != 0, x)

    # Join into a string and return
    return join(z, " ")
end
</code>```

Saved 53 bytes with help from Sp3000!

Body:
Julia, <s>165</s> <s>155</s> <s>151</s> <s>129</s> 102 bytes

g(s,d=[])=join(filter(i->i!=0,[(c=lcfirst(w)[1])∈d?0:(d=[d;c];w)for w=split(s,r"\W",keep=1<0)])," ")

This is a function that accepts a string and returns a string.

Ungolfed:

function g(s, d=[])
    # Split the string into an array on unwanted characters, then for
    # each word, if the first letter has been encountered, populate
    # this element of the array with 0, otherwise note the first letter
    # and use the word. This results in an array of words and zeros.
    x = [(c = lcfirst(w)[1]) ∈ d ? 0 : (d = [d; c]; w) for w = split(s, r"\W", keep=1<0)]

    # Remove the zeros, keeping only the words. Note that this works
    # even if the word is the string "0" since 0 != "0".
    z = filter(i -> i != 0, x)

    # Join into a string and return
    return join(z, " ")
end

Saved 53 bytes with help from Sp3000!


答:
05AB1E, 40 bytes

Code:

```<code>94L32+çJžj-DU-ð¡""Kvy¬Xsl©åï>iX®«Uy}\}ðý
</code>```

Try it online!

Explanation:

We first generate all characters which should be deleted from the input string using 94L32+ç (Try here). We join this string using J and remove [a-zA-Z0-9_] which is stored in žj (Try here). We remove all the characters that are in the second string from the first string, which will leave us:

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

That can also be tested here. We Duplicate this and store in to X with the U-command. We then remove all the characters that are in this string from the input. We then split on whitespaces using ð¡ and remove all empty strings (using ""K). We now have this.

This is the clean version of the input, which we will work with. We map over each element using v. This uses y as the string variable. We take the first character of the string using ¬ and push X, which contains a string with all forbidden characters (!"#$%&'()*+,-./:;<=>?@[\]^`{|}~). We check if the lowercase version of the first character, (which will also be ©opied to the register), is in this string using å. Covered by this part: ï>i, if the first letter doesn't exist in the string of forbidden characters (X), we append this letter to the list of forbidden characters (done with X®«U) and we push y on top of the stack.

Finally, when the strings are filtered, we join the stack by spaces with ðý.

Body:
05AB1E, 40 bytes

Code:

94L32+çJžj-DU-ð¡""Kvy¬Xsl©åï>iX®«Uy}\}ðý

Try it online!

Explanation:

We first generate all characters which should be deleted from the input string using 94L32+ç (Try here). We join this string using J and remove [a-zA-Z0-9_] which is stored in žj (Try here). We remove all the characters that are in the second string from the first string, which will leave us:

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

That can also be tested here. We Duplicate this and store in to X with the U-command. We then remove all the characters that are in this string from the input. We then split on whitespaces using ð¡ and remove all empty strings (using ""K). We now have this.

This is the clean version of the input, which we will work with. We map over each element using v. This uses y as the string variable. We take the first character of the string using ¬ and push X, which contains a string with all forbidden characters (!"#$%&'()*+,-./:;<=>?@[\]^`{|}~). We check if the lowercase version of the first character, (which will also be ©opied to the register), is in this string using å. Covered by this part: ï>i, if the first letter doesn't exist in the string of forbidden characters (X), we append this letter to the list of forbidden characters (done with X®«U) and we push y on top of the stack.

Finally, when the strings are filtered, we join the stack by spaces with ðý.


答:
Jelly, <s>32</s> 31 bytes

```<code>ØB;”_
e€¢¬œṗf€¢¹ÐfµZḢŒlQi@€$ịj⁶
</code>```

Try it online!

Body:
Jelly, <s>32</s> 31 bytes

ØB;”_
e€¢¬œṗf€¢¹ÐfµZḢŒlQi@€$ịj⁶

Try it online!


答:
Retina, 28 bytes:

```
M!i`\b(\w)(?<!\b\1.+)\w*
¶
&#32
```

M! - Match each work and print all words separated by newlines.

i - Ignore case.

\b(\w) - Capture first letter of each word

(?<!\b\1.+) - After matching the letter, check if there wasn't a previous word starting with the same letter. \1.+ ensures at least two characters, so we are skipping the current word.

\w* - match the rest of the word.

The above matches only words - all other characters are removed.

¶\n  - Replace newlines with spaces.

Try it online!

Body:
Retina, 28 bytes:

M!i`\b(\w)(?<!\b\1.+)\w*
¶
&#32

M! - Match each work and print all words separated by newlines.

i - Ignore case.

\b(\w) - Capture first letter of each word

(?<!\b\1.+) - After matching the letter, check if there wasn't a previous word starting with the same letter. \1.+ ensures at least two characters, so we are skipping the current word.

\w* - match the rest of the word.

The above matches only words - all other characters are removed.

¶\n  - Replace newlines with spaces.

Try it online!


答:
Pyth, 23 bytes

```<code>J:z"\w+"1jdxDJhM.grhk0J
</code>```

Try it online: Demonstration or Test Suite

J:z"\w+"1 finds all the words in the input using the regex \w+ and stores them in J.

.grhk0J groups the words by their lowercase first letter, hM takes the first from each group, xDJ sorts these words by their index in the input string, and jd puts spaces between them.

Body:
Pyth, 23 bytes

J:z"\w+"1jdxDJhM.grhk0J

Try it online: Demonstration or Test Suite

J:z"\w+"1 finds all the words in the input using the regex \w+ and stores them in J.

.grhk0J groups the words by their lowercase first letter, hM takes the first from each group, xDJ sorts these words by their index in the input string, and jd puts spaces between them.


答:
Lua, 172 Bytes

It ended up way longer that I wanted...

t={}(...):gsub("[%w_]+",function(w)b=nil for i=1,#t
do b=t[i]:sub(1,1):lower()==w:sub(1,1):lower()and 1 or b
end t[#t+1]=not b and w or nil end)print(table.concat(t," "))
```

<h3>Ungolfed</h3>

<pre class="lang-lua prettyprint-override"><code>t={}                           -- initialise the accepted words list
(...):gsub("[%w_]+",function(w)-- iterate over each group of alphanumericals and underscores
  b=nil                        -- initialise b (boolean->do we have this letter or not)
  for i=1,#t                   -- iterate over t
  do
    b=t[i]:sub(1,1):lower()    -- compare the first char of t's i word
       ==w:sub(1,1):lower()    -- and the first char of the current word
           and 1               -- if they are equals, set b to 1
           or b                -- else, don't change it
  end
  t[#t+1]=not b and w or nil   -- insert w into t if b isn't set
end)

print(table.concat(t," "))     -- print the content of t separated by spaces
</code>```

Body:
Lua, 172 Bytes

It ended up way longer that I wanted...

t={}(...):gsub("[%w_]+",function(w)b=nil for i=1,#t
do b=t[i]:sub(1,1):lower()==w:sub(1,1):lower()and 1 or b
end t[#t+1]=not b and w or nil end)print(table.concat(t," "))

Ungolfed

t={}                           -- initialise the accepted words list
(...):gsub("[%w_]+",function(w)-- iterate over each group of alphanumericals and underscores
  b=nil                        -- initialise b (boolean->do we have this letter or not)
  for i=1,#t                   -- iterate over t
  do
    b=t[i]:sub(1,1):lower()    -- compare the first char of t's i word
       ==w:sub(1,1):lower()    -- and the first char of the current word
           and 1               -- if they are equals, set b to 1
           or b                -- else, don't change it
  end
  t[#t+1]=not b and w or nil   -- insert w into t if b isn't set
end)

print(table.concat(t," "))     -- print the content of t separated by spaces


答:
C# (LINQPAD) - 136 128 bytes

```<code>var w=Util.ReadLine().Split(' ');string.Join(" ",w.Select(s=>w.First(f=>Regex.IsMatch(""+f[0],"(?i)"+s[0]))).Distinct()).Dump();
</code>```

Body:
C# (LINQPAD) - 136 128 bytes

var w=Util.ReadLine().Split(' ');string.Join(" ",w.Select(s=>w.First(f=>Regex.IsMatch(""+f[0],"(?i)"+s[0]))).Distinct()).Dump();


问:
Create your own Gym Exercise and follow along irl
Let's do an exercise together, shall we? Simply follow the movements of the stickman. What stickman you ask? The one we are about to create!

Make a program that allows for a string-input only containing integers, and outputs the following nine stick-figures with an interval in between:

```<code> @  \@/ |@_ _@| @/   \@ |@| \@\ /@/
/|\  |   |   |   |   |   |   |   |
/ \ / \ / \ / \ /|\ /|\ / \ / \ / \
 1   2   3   4   5   6   7   8   9
</code>```

This will result in an animation, which we can then follow along irl.

Here is an example of the output created when the input is "123245762":

Some rules:

This is tagged code-golf, so shortest code in bytes wins

The input is a string only containing [1-9] with a length potentially varying from 2 to 100 characters **

The animation must be an endless loop

The interval time must be 750 ms

No duplicated adjacent integers are allowed in the input - this also includes the first and last integers of the input (see the seventh and eight test cases) **

** How it fails in case of invalid input is completely up to you, but it should be clear that it fails. It could throw an exception; simply return at the start; reboot your PC; delete it's own source-/compile-code; hack into the military and shoots a rocket to the compiling GPS-location. Your call. EDIT: It's not allowed to simply display a (correct / half) animation as failing input. It must be clear that something is wrong with the input for the failing testcases below. Thanks to @user81655 for bringing this to my attention, hence the edit.

Subrules:

Please post the gif for one of the (non-failing) test cases below in your answer, which you can make very easy with the following program: screentogif.codeplex.com (Any other gif-creating program is also allowed of course.)

Bonus points if you actually do the exercise alongside the animation irl when it's finished. ;)

Correct testcases:

123245762

65

121234346565879879132418791576

Failing testcases:

2 // Too few characters

7282918274959292747383785189478174826894958127476192947512897571298593912374857471978269591928974518735891891723878 // Too much characters

1232405762 // Containing invalid input (the 0)

112212 // Fails because of the 11 and 22 present

1232457621 // Fails because of the starting and leading 1

Body:
Python3, 338 bytes

import os,time
p=" @ \n/|\\\n/ \\","\\@/\n | \n/ \\","|@_\n | \n/ \\","_@|\n | \n/ \\","@/ \n | \n/|\\"," \\@\n | \n/|\\","|@|\n | \n/ \\","\\@\\\n | \n/ \\","/@/\n | \n/ \\"
i=input()
for j in range(len(i)):(i[j]in"123456789"and i[j]!=i[(j+1)%len(i)])or exit()
while 1:[[time.sleep(0.75),os.system("clear"),print(p[int(j)-1])]for j in i]


问:
Character Cross
I was expecting to post something more complex as my first puzzle in PCG, but a particular, uh... homework question on Stack Overflow inspired me to post this. They want to:

print the following pattern for any given word that contains odd number of letters:

```<code>P           M
  R       A
    O   R
      G
    O   R
  R       A
P           M
</code>```

c++

Notice that letters are a knight's move apart in the pattern you need to print. So, every other column is empty. -- (Thanks xnor for pointing this out.)

Rules

Using C++ is prohibited. As I may link this question there.

You may use stdout, or any means of quickly outputting a string (e.g. alert() in JavaScript).

As always, shortest code wins.

答:
C++:

```<code>#include <iostream>
#include <string>

int main()
{
    char a[] = {'P','R','O','G','R','A','M'};
    int length = sizeof(a)/sizeof(a[0]);
    int l = length - 1, i, j;
    for (i=0; i <= l; i++) {
        for (j=0; j <= l;j++) {
            if (j == i)
                std::cout<<a[i];
            else if (i == l-j)
                std::cout<<a[j];
            else
                std::cout<<"s";
        }
        std::cout<<"\n";
    }
}
</code>```

ContentLicense: CC BY-SA 4.0

Title: Character Cross

Body:
C++:

#include <iostream>
#include <string>

int main()
{
    char a[] = {'P','R','O','G','R','A','M'};
    int length = sizeof(a)/sizeof(a[0]);
    int l = length - 1, i, j;
    for (i=0; i <= l; i++) {
        for (j=0; j <= l;j++) {
            if (j == i)
                std::cout<<a[i];
            else if (i == l-j)
                std::cout<<a[j];
            else
                std::cout<<"s";
        }
        std::cout<<"\n";
    }
}


答:
MATL, 23 bytes

```<code>'\w+'XXtck1Z)t!=XRa~)Zc
</code>```

This borrows Jakube's idea of using a regexp for removing unwanted characters and splitting at the same time.

Input is a string enclosed by single quotes.

Try it online!

Explanation

```<code>'\w+'XX  % find words that match this regexp. Gives a cell array
t        % duplicate
c        % convert into 2D char array, right-padded with spaces
k        % make lowercase
1Z)      % get first column (starting letter of each word)
t!=      % duplicate, transpose, test for equality: all combinations
XR       % set diagonal and below to 0
a~       % true for columns that contain all zeros
)        % use as a logical index (filter) of words to keep from the original cell array
Zc       % join those words by spaces
</code>```

Body:
MATL, 23 bytes

'\w+'XXtck1Z)t!=XRa~)Zc

This borrows Jakube's idea of using a regexp for removing unwanted characters and splitting at the same time.

Input is a string enclosed by single quotes.

Try it online!

Explanation

'\w+'XX  % find words that match this regexp. Gives a cell array
t        % duplicate
c        % convert into 2D char array, right-padded with spaces
k        % make lowercase
1Z)      % get first column (starting letter of each word)
t!=      % duplicate, transpose, test for equality: all combinations
XR       % set diagonal and below to 0
a~       % true for columns that contain all zeros
)        % use as a logical index (filter) of words to keep from the original cell array
Zc       % join those words by spaces


Body:
Perl 6, 39 bytes

{.words.grep({!%.{.substr(0,1).lc}++})}


答:
C, <s>142</s> <s>132</s> 122 bytes

10 bytes lighter thanks to @tucuxi!

```<code>b[200],k;main(c){for(;~c;isalnum(c)|c==95?k&2?:(k|=!b[c|32]++?k&1?putchar(32):0,7:2),k&4?putchar(c):0:(k&=1))c=getchar();}
</code>```

<s>Prints a trailing space after the last output word.</s>

Body:
Given a string, find the first word starting with each letter (case insensitive).

Sample

Using Ferulas flourish in gorgeous gardens. as input:

```<code>"Ferulas flourish in gorgeous gardens."
 ^^^^^^^          ^^ ^^^^^^^^
 |                |  |
 |                |  --> is the first word starting with `g`
 |                --> is the first word starting with `i`
 --> is the first word starting with `f`
</code>```

Then, the output for this sample should be the matched words joined by one single space:

```<code>"Ferulas in gorgeous"
</code>```

Challenge

Both input and output must be a string representation, or the closest alternative in your language.

Program or function allowed.

You can consider a word being at least one of: lowercase or uppercase letters, digits, underscore.

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

Another samples:

```<code>input: "Take all first words for each letter... this is a test"
output: "Take all first words each letter is"
</code>```

```<code>input: "Look ^_^ .... There are 3 little dogs :)"
output: "Look _ There are 3 dogs"
</code>```

```<code>input: "...maybe some day 1 plus 2 plus 20 could result in 3"
output: "maybe some day 1 plus 2 could result in 3"
</code>```

Body:
C, <s>142</s> <s>132</s> 122 bytes

10 bytes lighter thanks to @tucuxi!

b[200],k;main(c){for(;~c;isalnum(c)|c==95?k&2?:(k|=!b[c|32]++?k&1?putchar(32):0,7:2),k&4?putchar(c):0:(k&=1))c=getchar();}

<s>Prints a trailing space after the last output word.</s>


答:
Python 3.5, 138 bytes:

```<code>import re;lambda o,t=[]:''.join([y[0]for y in[(u+' ',t.append(u[0].lower()))for u in re.sub('\W+',' ',o).split()if u[0].lower()not in t]])
</code>```

Basically, what's happening is..

Using a simple regular expression, the program replaces all the characters, except lowercase or uppercase letters, digits, or underscores in the given string with spaces, and then splits the string at those spaces.

Then, using list comprehension, create a list that iterates through all the words in the split string, and add the first letters of each word to list "t".

In the process, if the current word's first letter is NOT already in the list "t", then that word and a trailing space are added to the current list being created. Otherwise, the list continues on appending the first letters of each word to list "t".

Finally, when all words in the split have been iterated through, the words in the new list are joined into a string and returned.

Body:
Python 3.5, 138 bytes:

import re;lambda o,t=[]:''.join([y[0]for y in[(u+' ',t.append(u[0].lower()))for u in re.sub('\W+',' ',o).split()if u[0].lower()not in t]])

Basically, what's happening is..

Using a simple regular expression, the program replaces all the characters, except lowercase or uppercase letters, digits, or underscores in the given string with spaces, and then splits the string at those spaces.

Then, using list comprehension, create a list that iterates through all the words in the split string, and add the first letters of each word to list "t".

In the process, if the current word's first letter is NOT already in the list "t", then that word and a trailing space are added to the current list being created. Otherwise, the list continues on appending the first letters of each word to list "t".

Finally, when all words in the split have been iterated through, the words in the new list are joined into a string and returned.


答:
PHP 120bytes

```<code>function a($s){foreach(preg_split('/\W/',$s)as$w)if(!$o[ucfirst($w[0])]){$o[ucfirst($w[0])]=$w;}return implode(" ",$o);}
</code>```

This generates a bunch of warnings but that's fine.

Body:
PHP 120bytes

function a($s){foreach(preg_split('/\W/',$s)as$w)if(!$o[ucfirst($w[0])]){$o[ucfirst($w[0])]=$w;}return implode(" ",$o);}

This generates a bunch of warnings but that's fine.


问:
Snakify a String
A snakified string looks like this:

```<code>T AnE eOf ifi ing
h s x l A k e r
isI amp Sna dSt
</code>```

Your Task

Take a string s and a size n, then output the snakified string. The inputs ThisIsAnExampleOfaSnakifiedString and 3 would produce the example above.

Specifications

s will only contain ASCII characters between code points 33 and 126 inclusive (no spaces or newlines).

s will be between 1 and 100 characters long.

n is an integer representing the size of each output string segment. Each line of characters (up/down or left/right) that make up the curves in the "snake" is n characters long. See the test cases for examples.

n will be between 3 and 10 inclusive.

The output string always starts pointing downwards.

Trailing spaces on each line are allowed.

Trailing newlines at the end of the output are also allowed.

Leading spaces are not allowed.

code-golf means shortest code in bytes wins.

Test Cases

```<code>a 3

a

----------

Hello,World! 3

H Wor
e , l
llo d!

----------

ProgrammingPuzzlesAndCodeGolf 4

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

----------

IHopeYourProgramWorksForInputStringsWhichAre100CharactersLongBecauseThisTestCaseWillFailIfItDoesNot. 5

I   gramW   tStri   100Ch   gBeca   CaseW   DoesN
H   o   o   u   n   e   a   n   u   t   i   t   o
o   r   r   p   g   r   r   o   s   s   l   I   t
p   P   k   n   s   A   a   L   e   e   l   f   .
eYour   sForI   Which   cters   ThisT   FailI

----------

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

!        <=>?@ABCDE        `abcdefghi
"        ;        F        _        j
#        :        G        ^        k
$        9        H        ]        l
%        8        I        \        m
&        7        J        [        n
'        6        K        Z        o        ~
(        5        L        Y        p        }
)        4        M        X        q        |
*+,-./0123        NOPQRSTUVW        rstuvwxyz{
</code>```

答:
PHP, <s>127</s> <s>126</s> <s>124</s> <s>120</s> <s>119</s> <s>118</s> <s>117</s> <s>110</s> 106 bytes

Uses ISO-8859-1 encoding.

```<code>for(;($q=&$o[$y+=$d]||$q=~ÿ)&&~Ï^$q[$x+=!$d]=$argv[1][$a];$a++%($argv[2]-1)?:$d-=-!$y?:1)?><?=join(~õ,$o);
</code>```

Run like this (-d added for aesthetics only):

```<code>php -r 'for(;($q=&$o[$y+=$d]||$q=~ÿ)&&~Ï^$q[$x+=!$d]=$argv[1][$a];$a++%($argv[2]-1)?:$d-=-!$y?:1)?><?=join(~õ,$o);' "Hello W0rld!" 3 2>/dev/null;echo
</code>```

Ungolfed:

```<code>// Iterate over ...
for (
    ;
    // ... the characters of the input string. Prepend `0` so a 0 in the input
    // becomes truthy.
    0 . $char = $argv[1][$a];

    // Use modulo to determine the end of a stretch (where direction is
    // changed).
    // Change direction (`0` is right, `-1` is up and `1` is down). When
    // y coordinate is `0`, increment the direction, else decrement.
    $a++ % ($argv[2] - 1) ?: $direction += $y ? -1 : 1
)

    (
        // Increase or decrease y coordinate for direction -1 or 1 respectively.
        // Check whether the array index at new y coordinate is already set.
        $reference =& $output[$y += $direction] ||
        // If not, create it as a string (otherwise would be array of chars).
        // Null byte, won't be printed to prevent leading char.
        $reference = ~ÿ;

        // Increment x coordinate for direction 0. Set the output char at the
        // current coordinates to the char of the current iteration.
    ) & $reference[$x += !$direction] = $char;

// Output all lines, separated by a newline.
echo join(~õ, $output);
</code>```

Tweaks

Saved a byte by using < instead of !=

Saved 2 bytes by setting the string to 0 at first, so I don't have to prepend another 0 (in case the first output in a line was a 0), yielding truthy 00.

Saved 4 bytes by using a reference instead of repeating $o[$y]

Saved a byte by using modulo instead of == for comparing direction with 1 to change x coordinate

Saved a byte by removing type cast null to int for string offset, as string offset is cast to int anyway

Saved a byte by using short print tag

Saved 7 bytes by improving the direction logic

Saved 4 bytes by directly assigning the char to prevent intermediate $c

Title: Snakify a String

Body:
PHP, <s>127</s> <s>126</s> <s>124</s> <s>120</s> <s>119</s> <s>118</s> <s>117</s> <s>110</s> 106 bytes

Uses ISO-8859-1 encoding.

for(;($q=&$o[$y+=$d]||$q=~ÿ)&&~Ï^$q[$x+=!$d]=$argv[1][$a];$a++%($argv[2]-1)?:$d-=-!$y?:1)?><?=join(~õ,$o);

Run like this (-d added for aesthetics only):

php -r 'for(;($q=&$o[$y+=$d]||$q=~ÿ)&&~Ï^$q[$x+=!$d]=$argv[1][$a];$a++%($argv[2]-1)?:$d-=-!$y?:1)?><?=join(~õ,$o);' "Hello W0rld!" 3 2>/dev/null;echo

Ungolfed:

// Iterate over ...
for (
    ;
    // ... the characters of the input string. Prepend `0` so a 0 in the input
    // becomes truthy.
    0 . $char = $argv[1][$a];

    // Use modulo to determine the end of a stretch (where direction is
    // changed).
    // Change direction (`0` is right, `-1` is up and `1` is down). When
    // y coordinate is `0`, increment the direction, else decrement.
    $a++ % ($argv[2] - 1) ?: $direction += $y ? -1 : 1
)

    (
        // Increase or decrease y coordinate for direction -1 or 1 respectively.
        // Check whether the array index at new y coordinate is already set.
        $reference =& $output[$y += $direction] ||
        // If not, create it as a string (otherwise would be array of chars).
        // Null byte, won't be printed to prevent leading char.
        $reference = ~ÿ;

        // Increment x coordinate for direction 0. Set the output char at the
        // current coordinates to the char of the current iteration.
    ) & $reference[$x += !$direction] = $char;

// Output all lines, separated by a newline.
echo join(~õ, $output);

Tweaks

Saved a byte by using < instead of !=

Saved 2 bytes by setting the string to 0 at first, so I don't have to prepend another 0 (in case the first output in a line was a 0), yielding truthy 00.

Saved 4 bytes by using a reference instead of repeating $o[$y]

Saved a byte by using modulo instead of == for comparing direction with 1 to change x coordinate

Saved a byte by removing type cast null to int for string offset, as string offset is cast to int anyway

Saved a byte by using short print tag

Saved 7 bytes by improving the direction logic

Saved 4 bytes by directly assigning the char to prevent intermediate $c


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

The factorial, represented with ! is defined as such

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

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

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

Requirements:

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

Can calculate factorials for numbers up to 125

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

Completes in under a minute for numbers up to 125

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

答:
Pyth, 8 bytes

It's a shame that, 5 years after the challenge has been posted, there is no pyth answer. So I'm doing it now, even if it's ridiculous :).
BTW, this is non-competiting, since the language is newer than the challenge...

Lu*GHSb1

You call it with yx, where x is a number.
Test it here !

Explanation

```<code>Lu*GHSb1
L          Defines a lambda 'y' with argument 'b'
     Sb    Create a range from one to 'b' (function argument)
  *GH      Lambda function that takes two arguments and multiply them
 u     1   Reduce the range with the above lambda.
</code>```

Title: Find the Factorial!

Body:
Pyth, 8 bytes

It's a shame that, 5 years after the challenge has been posted, there is no pyth answer. So I'm doing it now, even if it's ridiculous :).
BTW, this is non-competiting, since the language is newer than the challenge...

Lu*GHSb1

You call it with yx, where x is a number.
Test it here !

Explanation

Lu*GHSb1
L          Defines a lambda 'y' with argument 'b'
     Sb    Create a range from one to 'b' (function argument)
  *GH      Lambda function that takes two arguments and multiply them
 u     1   Reduce the range with the above lambda.


答:
SpecBAS - 387 bytes

```<code>1 DIM m$=" @"#13"/|\"#13"/ \","\@/"#13" |"#13"/ \","|@_"#13" |"#13"/ \","_@|"#13" |"#13"/ \","@/"#13" |"#13"/|\"," \@"#13" |"#13"/|\","|@|"#13" |"#13"/ \","\@\"#13" |"#13"/ \","/@/"#13" |"#13"/ \"
2 INPUT a$: o=0
3 IF LEN a$<2 OR LEN a$>100 THEN 10
4 FOR i=1 TO LEN a$
5 n=VAL(a$(i))
6 IF n=0 OR n=o THEN 10
7 CLS : ?m$(n): o=n: WAIT 750
8 NEXT i
9 GO TO 4
10 CLS : ?" @"#13"-O-"#13"/ \"#13"FAT"
</code>```

Keeps looping until you press ESC. Failure to exercise properly (incorrect input - in this example a 0 as one of the steps) leads to fatness. The GIF loops, in the program it just stops at that point.

#13 is the SpecBAS equivalent to \n and lets you include line feed in strings.

Title: Create your own Gym Exercise and follow along irl

Body:
Let's do an exercise together, shall we? Simply follow the movements of the stickman. What stickman you ask? The one we are about to create!

Make a program that allows for a string-input only containing integers, and outputs the following nine stick-figures with an interval in between:

```<code> @  \@/ |@_ _@| @/   \@ |@| \@\ /@/
/|\  |   |   |   |   |   |   |   |
/ \ / \ / \ / \ /|\ /|\ / \ / \ / \
 1   2   3   4   5   6   7   8   9
</code>```

This will result in an animation, which we can then follow along irl.

Here is an example of the output created when the input is "123245762":

Some rules:

This is tagged code-golf, so shortest code in bytes wins

The input is a string only containing [1-9] with a length potentially varying from 2 to 100 characters **

The animation must be an endless loop

The interval time must be 750 ms

No duplicated adjacent integers are allowed in the input - this also includes the first and last integers of the input (see the seventh and eight test cases) **

** How it fails in case of invalid input is completely up to you, but it should be clear that it fails. It could throw an exception; simply return at the start; reboot your PC; delete it's own source-/compile-code; hack into the military and shoots a rocket to the compiling GPS-location. Your call. EDIT: It's not allowed to simply display a (correct / half) animation as failing input. It must be clear that something is wrong with the input for the failing testcases below. Thanks to @user81655 for bringing this to my attention, hence the edit.

Subrules:

Please post the gif for one of the (non-failing) test cases below in your answer, which you can make very easy with the following program: screentogif.codeplex.com (Any other gif-creating program is also allowed of course.)

Bonus points if you actually do the exercise alongside the animation irl when it's finished. ;)

Correct testcases:

123245762

65

121234346565879879132418791576

Failing testcases:

2 // Too few characters

7282918274959292747383785189478174826894958127476192947512897571298593912374857471978269591928974518735891891723878 // Too much characters

1232405762 // Containing invalid input (the 0)

112212 // Fails because of the 11 and 22 present

1232457621 // Fails because of the starting and leading 1

Body:
SpecBAS - 387 bytes

1 DIM m$=" @"#13"/|\"#13"/ \","\@/"#13" |"#13"/ \","|@_"#13" |"#13"/ \","_@|"#13" |"#13"/ \","@/"#13" |"#13"/|\"," \@"#13" |"#13"/|\","|@|"#13" |"#13"/ \","\@\"#13" |"#13"/ \","/@/"#13" |"#13"/ \"
2 INPUT a$: o=0
3 IF LEN a$<2 OR LEN a$>100 THEN 10
4 FOR i=1 TO LEN a$
5 n=VAL(a$(i))
6 IF n=0 OR n=o THEN 10
7 CLS : ?m$(n): o=n: WAIT 750
8 NEXT i
9 GO TO 4
10 CLS : ?" @"#13"-O-"#13"/ \"#13"FAT"

Keeps looping until you press ESC. Failure to exercise properly (incorrect input - in this example a 0 as one of the steps) leads to fatness. The GIF loops, in the program it just stops at that point.

#13 is the SpecBAS equivalent to \n and lets you include line feed in strings.


问:
KOTH: Everybody loves tokens
In this game two players compete to eat the most points worth of tokens, but there's a twist! Eating multiple tokens in a row of the same color gives an ever-growing bonus, but watch out, or your opponent will thwart your plans by eating the tokens you want before you can!

Rules:

1 versus 1

n by n board (random size between 5x5 and 15x15)

You and your opponent will spawn in the same random cell

Throughout the board will be randomly generated numbers in some cells ranging in value from 1-3

2 * (the width of the board) tokens will be generated, but there can be overrides, so there may be fewer by chance.

Each number will be one of 3 colors: Red, Green, or Blue, in hex RGB format

Each round, player 1 moves and the board is updated, then player 2 moves, and the board is updated. So each player can effectively tell what move the previous player made based on the change in the board state. This continues until the game ends, as described later.

You have 6 possible actions for a turn: UP, RIGHT, DOWN, LEFT, EAT, and PASS

The 4 move commands are self-explanatory, and you CAN pass your turn. If you return a nonsensical move, we will assume you meant pass. If you try to move off the edge of the board, you will not move. The edges don't wrap.

EAT consumes the number you are currently in the same space as

You gain as many points as the number you consume

If you eat 2 numbers in a row of the same color, you get +1

If you eat 3 numbers in a row of the same color, you get +2

If you eat m numbers in a row of the same color, you get +(m-1)

These bonuses are added cumulatively, so getting m numbers in a row leads to m*(m-1)/2 in total bonus by the time you eat a different color.

Game end conditions:

All numbers are consumed

4 * (the width of the board) turns have gone by with no effective eating (just saying “EAT” with no token where you are doesn't count) occurring by either player (any token is reachable in 2 * (the width) moves, so this bound will only be surpassed if both players have no single target token in mind)

Your AI should take less than a second to make a move, else PASS will be assumed as your choice.

The tournament will be round robin with a large number of rounds, say 100 or 1000. A random board is generated, and each ordered pair of different players is run on that board. After the tournament completes we will rank people by their total score. So even if you are player 2 for a game, your goal is still to get as many points as possible.

AI Submission: The language my controller supports is Javascript. Multiple submissions are allowed. Everyone submits a constructor for an object like this:

```<code>function (player1) {
    this.yourMove = function (b) {
        return "MOVE";
    }
}
</code>```

The input player1 is a boolean saying whether you are player 1 or not.
Your constructor must have the yourMove function, but it can have
any number of additional functions or values as well. Don't define any
global variables, just put them as variables on your object. A new version
of your object will be created at the beginning of each match, and
yourMove will be called on it, with the current board as input, on each of your turns, and should return a valid move.

b, the input to yourMove, is a copy of the current board, here are the
constructors, with input examples, though you can't call them yourself:

```<code>function token(color, points) {
    this.color = color; //"#FF0000"
    this.points = points; //5
}

function player(pos, score, colorBonus, lastColor) {
    this.pos = pos; //[5, 5]
    this.score = score; //9
    this.colorBonus = colorBonus; //i.e. 2 if you just ate 3 blue tokens in a row
                                  //0 if you just ate two different colors.
    this.lastColor = lastColor; //"#00FF00", is "#000000" at start
}

function board(player1, player2, tokens) {
    this.player1 = player1; //new player([5, 5], 9, 2, "#00FF00")
    this.player2 = player2; //new player([5, 5], 9, 2, "#00FF00")
    this.tokens = tokens; //[[new token("#0000FF", 5), false],
                      // [new token("#0000FF", 5), false]]
}
</code>```

The token array has "false" for any empty squares, and tokens[a][b] is
the token at x = a, y = b, numbered starting from the upper-left corner.

Controller:
Here's a link to the controller in GitHub. It's an html file that you can run to see how the game and the round-robin works, and it comes with two AIs, a random one that moves in a random direction each turn but eats tokens at its position, and a naive algorithm that goes for the nearest token that gives the most points. I will add in each AI as it is submitted.

Below is a snippet that allows you to run the controller on the default AI.
Current AIs:

KindaRandomAI

NaiveAI

MirrorBot

HungryBot

<!DOCTYPE html>

  <canvas id="myCanvas" width="700" height="600" style="border:1px solid #c3c3c3;">
    Your browser does not support the HTML5 canvas tag.
  </canvas>

```

答:
MirrorBot

Should be called "cannon fodder"

Description: Moves the exact opposite of what the other player did

Rationale: I wanted to get comfortable programming in JS again. This should not win

Will beat: No one

Will lose to: Everyone

```<code>function mirror(player1) {
    this.hasStarted=false;
    this.player1 = player1;
    this.opl=[0,0];
    this.yourMove = function(b){
        this.op = this.player1 ? b.player2.pos : b.player1.pos;
        out = "EAT";
        console.log(this.op);
        console.log(this.opl);
        if(this.hasStarted){
            if(this.opl[0] < this.op[0]) out = "RIGHT";
            if(this.opl[0] > this.op[0]) out = "LEFT";
            if(this.opl[1] < this.op[1]) out = "UP";
            if(this.opl[1] > this.op[1]) out = "DOWN";
        }
        this.opl = [this.op[0],this.op[1]];
        this.hasStarted = true;
        return out;
    }
}
</code>```

Title: KOTH: Everybody loves tokens

Body:
MirrorBot

Should be called "cannon fodder"

Description: Moves the exact opposite of what the other player did

Rationale: I wanted to get comfortable programming in JS again. This should not win

Will beat: No one

Will lose to: Everyone

function mirror(player1) {
    this.hasStarted=false;
    this.player1 = player1;
    this.opl=[0,0];
    this.yourMove = function(b){
        this.op = this.player1 ? b.player2.pos : b.player1.pos;
        out = "EAT";
        console.log(this.op);
        console.log(this.opl);
        if(this.hasStarted){
            if(this.opl[0] < this.op[0]) out = "RIGHT";
            if(this.opl[0] > this.op[0]) out = "LEFT";
            if(this.opl[1] < this.op[1]) out = "UP";
            if(this.opl[1] > this.op[1]) out = "DOWN";
        }
        this.opl = [this.op[0],this.op[1]];
        this.hasStarted = true;
        return out;
    }
}


答:
Perl 5, 31 bytes

```<code>$s=1;map{$s*=$_}(2..<>);print$s
</code>```

Prints the result in scientific notation, and takes care of the 0 value as well.

Another way to do it, but without the 0 case, for 26 bytes :

```<code>print eval join'*',(1..<>)
</code>```

Title: Find the Factorial!

Body:
Create the shortest program or function that finds the factorial of a non-negative integer.

The factorial, represented with ! is defined as such

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

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

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

Requirements:

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

Can calculate factorials for numbers up to 125

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

Completes in under a minute for numbers up to 125

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

Body:
Perl 5, 31 bytes

$s=1;map{$s*=$_}(2..<>);print$s

Prints the result in scientific notation, and takes care of the 0 value as well.

Another way to do it, but without the 0 case, for 26 bytes :

print eval join'*',(1..<>)


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

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

And a string snake looks something like this:

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

Your Task

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

Specifications

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

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

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

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

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

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

The string will be between 2 and 100 characters long.

Shortest code in bytes wins.

Test Cases

(Input grid, followed by the output string)

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

Hello,IAmAStringSnake!

----------

Python

Python

----------

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

ProgrammingPuzzlesAndCodeGolf

----------

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

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

----------

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

SlipperyStringSnakesSilentlySlitherSomewhereSafe
</code>```

答:
JavaScript (ES6) + SnakeEx, 176 bytes

```<code>a=b=>snakeEx.run("s{A}:<+>([^ ]<P>)+",b).reduce((c,d)=>(e=c.marks.length-d.marks.length)>0?c:e?d:c.x+c.y>d.x+d.y?d:c).marks.reduce((c,d,e,f)=>e%2?c+b.split`\n`[d][f[e-1]]:c,"")
</code>```

Remember SnakeEx? Good, because neither do I! Golfing suggestions welcome.

Title: De-Snakify a String

Body:
JavaScript (ES6) + SnakeEx, 176 bytes

a=b=>snakeEx.run("s{A}:<+>([^ ]<P>)+",b).reduce((c,d)=>(e=c.marks.length-d.marks.length)>0?c:e?d:c.x+c.y>d.x+d.y?d:c).marks.reduce((c,d,e,f)=>e%2?c+b.split`\n`[d][f[e-1]]:c,"")

Remember SnakeEx? Good, because neither do I! Golfing suggestions welcome.


答:
JavaScript (ES6), 131

Algorithm: mapping the position x,y in output to the index in the input string, somehow like this (unrelated) answer.

I borrowed from @LevelRiverSt the trick of keeping the horizontal width equal to the input length.

a=>m=>eval('for(--m,t=y=``;y<=m;++y,t+=`\n`)for(x=0;a[x];)t+=a[2*(x-x%m)+((h=x++%(2*m))?h-m?!y&h>m?h:y<m|h>m?NaN:m+h:m-y:y)]||`.`')
```
<p><strong>Less golfed</strong></p>
<p>This was the first working draft before golfing</p>
<pre class="lang-js prettyprint-override"><code>f=(a,n)=>{
  l=a.length
  m=n-1
  s=m*2 // horizontal period

  b=-~(~-l/s)*m // total horizontal len, useless in golfed version
  t=''
  for(y=0;y<n;y++)
  {
    for(x=0;x<b;x++)
    {
      k = x / m | 0
      h = x % s
      if (h ==0 )
        c=k*s+y
      else if (h == m)
        c=k*s+m-y
      else if (y == 0 && h>m)
        c=k*s+h
      else if (y == m && h<m)
        c=k*s+m+h
      else
        c=-1
      t+=a[c]||' '
    }
    t+='\n'
  }
  return t
}
</code>```

Test

F=a=>m=>eval('for(--m,t=y=``;y<=m;++y,t+=`\n`)for(x=0;a[x];)t+=a[2*(x-x%m)+((h=x++%(2*m))?h-m?!y&h>m?h:y<m|h>m?NaN:m+h:m-y:y)]||` `')

function test()
{
  var n=+N.value
  var s=S.value
  O.textContent=F(s)(n)
}

test()```
<pre class="snippet-code-css lang-css prettyprint-override"><code>#S {width:80%}
#N {width:5%}</code>```

<input id=N value=5 type=number oninput='test()'>
<input id=S 5 oninput='test()'
value='IHopeYourProgramWorksForInputStringsWhichAre100CharactersLongBecauseThisTestCaseWillFailIfItDoesNot.'>

```</code>```

Title: Snakify a String

Body:
A snakified string looks like this:

```<code>T AnE eOf ifi ing
h s x l A k e r
isI amp Sna dSt
</code>```

Your Task

Take a string s and a size n, then output the snakified string. The inputs ThisIsAnExampleOfaSnakifiedString and 3 would produce the example above.

Specifications

s will only contain ASCII characters between code points 33 and 126 inclusive (no spaces or newlines).

s will be between 1 and 100 characters long.

n is an integer representing the size of each output string segment. Each line of characters (up/down or left/right) that make up the curves in the "snake" is n characters long. See the test cases for examples.

n will be between 3 and 10 inclusive.

The output string always starts pointing downwards.

Trailing spaces on each line are allowed.

Trailing newlines at the end of the output are also allowed.

Leading spaces are not allowed.

code-golf means shortest code in bytes wins.

Test Cases

```<code>a 3

a

----------

Hello,World! 3

H Wor
e , l
llo d!

----------

ProgrammingPuzzlesAndCodeGolf 4

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

----------

IHopeYourProgramWorksForInputStringsWhichAre100CharactersLongBecauseThisTestCaseWillFailIfItDoesNot. 5

I   gramW   tStri   100Ch   gBeca   CaseW   DoesN
H   o   o   u   n   e   a   n   u   t   i   t   o
o   r   r   p   g   r   r   o   s   s   l   I   t
p   P   k   n   s   A   a   L   e   e   l   f   .
eYour   sForI   Which   cters   ThisT   FailI

----------

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

!        <=>?@ABCDE        `abcdefghi
"        ;        F        _        j
#        :        G        ^        k
$        9        H        ]        l
%        8        I        \        m
&        7        J        [        n
'        6        K        Z        o        ~
(        5        L        Y        p        }
)        4        M        X        q        |
*+,-./0123        NOPQRSTUVW        rstuvwxyz{
</code>```

Body:
JavaScript (ES6), 131

Algorithm: mapping the position x,y in output to the index in the input string, somehow like this (unrelated) answer.

I borrowed from @LevelRiverSt the trick of keeping the horizontal width equal to the input length.

a=>m=>eval('for(--m,t=y=``;y<=m;++y,t+=`\n`)for(x=0;a[x];)t+=a[2*(x-x%m)+((h=x++%(2*m))?h-m?!y&h>m?h:y<m|h>m?NaN:m+h:m-y:y)]||`.`')

Less golfed

This was the first working draft before golfing

f=(a,n)=>{
  l=a.length
  m=n-1
  s=m*2 // horizontal period

  b=-~(~-l/s)*m // total horizontal len, useless in golfed version
  t=''
  for(y=0;y<n;y++)
  {
    for(x=0;x<b;x++)
    {
      k = x / m | 0
      h = x % s
      if (h ==0 )
        c=k*s+y
      else if (h == m)
        c=k*s+m-y
      else if (y == 0 && h>m)
        c=k*s+h
      else if (y == m && h<m)
        c=k*s+m+h
      else
        c=-1
      t+=a[c]||' '
    }
    t+='\n'
  }
  return t
}

Test

F=a=>m=>eval('for(--m,t=y=``;y<=m;++y,t+=`\n`)for(x=0;a[x];)t+=a[2*(x-x%m)+((h=x++%(2*m))?h-m?!y&h>m?h:y<m|h>m?NaN:m+h:m-y:y)]||` `')

function test()
{
  var n=+N.value
  var s=S.value
  O.textContent=F(s)(n)
}

test()

#S {width:80%}
#N {width:5%}

<input id=N value=5 type=number oninput='test()'>
<input id=S 5 oninput='test()'
value='IHopeYourProgramWorksForInputStringsWhichAre100CharactersLongBecauseThisTestCaseWillFailIfItDoesNot.'>
<pre id=O></pre>


答:
Python, 28 bytes

```<code>f=lambda x:x/~x+1or x*f(x-1)
</code>```

(based off Alexandru's solution)

Title: Find the Factorial!

Body:
Python, 28 bytes

f=lambda x:x/~x+1or x*f(x-1)

(based off Alexandru's solution)


问:
Are the brackets fully matched?
You must write a program or function that takes a string of brackets and outputs whether or not that string is fully matched. Your program should print a truthy or falsy value, and IO can be in any reasonable format.

Rules and definitions:

For the purpose of this challenge, a "bracket" is any of these characters: ()[]{}<>.

A pair of brackets is considered "matched" if the opening and closing brackets are in the right order and have no characters inside of them, such as

```<code>()
[]{}
</code>```

Or if every subelement inside of it is also matched.

```<code>[()()()()]
{<[]>}
(()())
</code>```

Subelements can also be nested several layers deep.

```<code>[(){<><>[()]}<>()]
<[{((()))}]>
</code>```

A string is considered "Fully matched" if and only if:

Every single character is a bracket,

Each pair of brackets has the correct opening and closing bracket and in the right order, and

Each bracket is matched.

You may assume the input will only contain printable ASCII.

Test IO

Here are some inputs that should return a truthy value:

```<code>()
[](){}<>
(((())))
({[<>]})
[{()<>()}[]]
[([]{})<{[()<()>]}()>{}]
</code>```

And here are some outputs that should return a falsy value:

```<code>(               Has no closing ')'
}{              Wrong order
(<)>            Each pair contains only half of a matched element
(()()foobar)    Contains invalid characters
[({}<>)>        The last bracket should be ']' instead of '>'
(((()))         Has 4 opening brackets, but only 3 closing brackets.
</code>```

As usual, this is code-golf, so standard loopholes apply, and shortest answer in bytes wins.

答:
Java 7, <s>156</s> 151 bytes

```<code>class A{public static void main(String[]a){for(int i=0;i<-1>>>1;++i,a[0]=a[0].replaceAll("<>|\\[]|\\(\\)|\\{}",""));System.out.print(a[0].isEmpty());}}
</code>```

I'm not expecting this to win any awards but I didn't see a Java answer yet. Additionally, I like to lurk around PPCG and I would enjoy being able to vote/comment on other answers.

Input is given as program parameters. This follows the same format as many other answers here in that it preforms a regex replacement in a loop. Originally I had it loop N times where N is the length of the original string but looping to Integer.MAX_VALUE is shorter :]. This should be ok because Integer.MAX_VALUE is the maximum length of a String in Java so there's an implicit assumption that the length of input is something that is handle-able by Java. The runtime is pretty bad (took about 20 minutes on my lappytop) on account of the loop but I didn't see any restriction on that.

Title: Are the brackets fully matched?

Body:
Java 7, <s>156</s> 151 bytes

class A{public static void main(String[]a){for(int i=0;i<-1>>>1;++i,a[0]=a[0].replaceAll("<>|\\[]|\\(\\)|\\{}",""));System.out.print(a[0].isEmpty());}}

I'm not expecting this to win any awards but I didn't see a Java answer yet. Additionally, I like to lurk around PPCG and I would enjoy being able to vote/comment on other answers.

Input is given as program parameters. This follows the same format as many other answers here in that it preforms a regex replacement in a loop. Originally I had it loop N times where N is the length of the original string but looping to Integer.MAX_VALUE is shorter :]. This should be ok because Integer.MAX_VALUE is the maximum length of a String in Java so there's an implicit assumption that the length of input is something that is handle-able by Java. The runtime is pretty bad (took about 20 minutes on my lappytop) on account of the loop but I didn't see any restriction on that.


问:
Insert semi-sorted into unsorted array
Welcome to your first day at PPCG Inc. As our newest junior assistant document sorter, you are responsible for making sure all documents we sent down to you are archived in alphabetical order. It's so easy a monkey can do it. Well, metaphorically speaking, as we did hire a monkey to do it. Guess what? Turns out monkeys lack an understanding of our alphabet. Anyway, there's no time to fix the mess there is right now, so just try to not make the situation any worse, ok? Then get to it! If you get hungry, there's bananas over by the water cooler. Good luck!

Job Description

Input

You will receive a list of strings (the archive) and a string that needs to be added to that list (the document)

All strings will contain only uppercase letters, lowercase letters and spaces

Strings will always start and end with a letter

Task

Determine the target position of the document: the position it should receive in the archive. The target position can be determined as follows:

For each position:

Count the amount of strings in the archive before that position that are alphabetically before the document

Count the amount of strings in the archive after that position that are alphabetically after the document

Define the score of the position as the sum of the above two counts

The target position of the document is the position with the highest score

In case of a tie, all positions with the highest score are equally valid as target position. Only one needs to be selected.

When sorting:

Uppercase and lowercase letters are equivalent

Spaces come before letters

Output

The archive with the document added to it in any form

OR

The target position of the document, in either a 0-based or 1-based index

Job evaluation

Fewest bytes wins!

Example I/O

```<code>Archive:
    Applebuck Season
    Friendship is Magic
    The Ticket Master
    Griffon the BrushOff
    Boast Busters
    Bridle Gossip

Document: Dragonshy

Position scores (0-based index):
0: 0 + 3 = 3
1: 1 + 3 = 4
2: 1 + 2 = 3
3: 1 + 1 = 2
4: 1 + 0 = 1
5: 2 + 0 = 2
6: 3 + 0 = 3

Target position: 1
</code>```

答:
JavaScript (ES6), 81 bytes

```<code>(a,d)=>a.map((e,i)=>d[l="toLowerCase"]()<e[l]()?s--:++s>m&&(++m,p=++i),m=s=p=0)|p
</code>```

Ungolfed:

```<code>function position(archive, document) {
    var score = 0;
    var max = 0;
    var pos = 0;
    var i = 0;
    while (i < archive.length) {
        if (archive[i++].toLowerCase() > document.toLowerCase()) {
            score--;
        } else {
            score++;
            if (score > max) {
                max++;
                pos = i;
            }
        }
    }
    return pos;
}
</code>```

Edit: Saved a lot of bytes thanks to @user81655.

Title: Insert semi-sorted into unsorted array

Body:
JavaScript (ES6), 81 bytes

(a,d)=>a.map((e,i)=>d[l="toLowerCase"]()<e[l]()?s--:++s>m&&(++m,p=++i),m=s=p=0)|p

Ungolfed:

function position(archive, document) {
    var score = 0;
    var max = 0;
    var pos = 0;
    var i = 0;
    while (i < archive.length) {
        if (archive[i++].toLowerCase() > document.toLowerCase()) {
            score--;
        } else {
            score++;
            if (score > max) {
                max++;
                pos = i;
            }
        }
    }
    return pos;
}

Edit: Saved a lot of bytes thanks to @user81655.


问:
I'm not the language you're looking for!
Isn't it annoying when you find a piece of code and you don't know what language it was written in? This challenge attempts to somewhat solve this.

Challenge

You will have to write a program that when run in two different languages, will output the string:

This program wasn't written in <language program compiled/interpreted in>, it was built for <other language the program can be run in>!

In the output, language names should have official capitalization. eg: CJam, C++

Neither program should take any input from the user.

When run in both languages, output should be to stdout or equivalent.

There should be no output to stderr in either program.

You may use comments in either language.

Two different versions of the same language count as different languages.

If this is done, the program should output the major version number, and if running on two different minor versions, should report the minor version also.

You should not use prebuilt version functions (this includes variables that have already been evaluated at runtime).

Example output:

Perl and Ruby:

Perl: This program wasn't written in Perl, it was built for Ruby!

Ruby: This program wasn't written in Ruby, it was built for Perl!

Python and C:

Python: This program wasn't written in Python, it was built for C!

C: This program wasn't written in C, it was built for Python!

Python 2 and Python 3:

Python 2: This program wasn't written in Python 2, it was built for Python 3!

Python 3: This program wasn't written in Python 3, it was built for Python 2!

Python 2.4 and Python 2.7:

Python 2.4: This program wasn't written in Python 2.4, it was built for Python 2.7!

Python 2.7: This program wasn't written in Python 2.7, it was built for Python 2.4!

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

答:
Pyke/Foo, 71

```<code>"This program wasn't written in ""Foo"", it was built for ""Pyke"R3"!"s
</code>```

Try it in Pyke!

Foo just prints everything in double quotes.

R3 rotates the top 3 items of the stack and s  joins them together. It auto-prints the stack at the end

Body:
Pyke/Foo, 71

"This program wasn't written in ""Foo"", it was built for ""Pyke"R3"!"s

Try it in Pyke!

Foo just prints everything in double quotes.

R3 rotates the top 3 items of the stack and s  joins them together. It auto-prints the stack at the end


答:
Lua, <s>562</s> <s>535</s> <s>529</s> <s>513</s> <s>507</s> <s>504</s> <s>466</s> 458 Bytes

By far my most massive golf at the moment, <s>I think I can still cut off 100 bytes, which I'll work toward, but posting it as an answer as it already took some time :).</s> I was right, I've cutted down more than 100 bytes! I don't think there's lot of room for improvement.

this function have to be called with a 2D array containing one character per cell.

Saved 40 bytes while working with @KennyLau, thanks to him!

Woohoo! Under 500!

function f(m)t=2u=1i=1j=1s=" "::a::if s~=m[i][j]and(i<#m and m[i+1][j]~=s)~=(j<#m[i]and m[i][j+1]~=s)~=(i>1 and m[i-1][j]~=s)~=(j>1 and m[i][j-1]~=s)then goto b end
i,t=i%t+1,#m>t and t==i and t+1or t j=j>1 and j-1or u u=u<#m[1]and j==1 and u+1or u goto a::b::io.write(m[i][j])m[i][j]=s
i,j=i<#m and s~=m[i+1][j]and i+1or i>1 and s~=m[i-1][j]and i-1or i,j<#m[i]and s~=m[i][j+1]and j+1or j>1 and s~=m[i][j-1]and j-1or j
if s==m[i][j]then return end goto b end
```

<h2>Ungolfed</h2>

<p><s>Explanations will come once I'm done golfing this, for the moment, i'll lend you a readable version of this source code :D</s> Here comes the explanations!</p>

<p><strong>Edit: not updated with the latest modification, still golfing before updating. Same goes for the explanations</strong></p>

<pre class="lang-lua prettyprint-override"><code>function f(m)                    -- declare the function f which takes a matrix of characters
  t=2                            -- initialise the treshold for i
                                 -- when looking for the first end of the snake
  u=1                            -- same thing for j
  i,j=1,1                        -- initialise i and j,our position in the matrix
  s=" "                          -- shorthand for a space
  ::a::                          -- label a, start of an infinite loop
    if m[i][j]~=s                -- check if the current character isn't a space
      and(i<#m                   -- and weither it is surrounded by exactly
          and m[i+1][j]~=s)      -- 3 spaces or not
      ~=(j<#m[i]
          and m[i][j+1]~=s)      -- (more explanations below)
      ~=(i>1
          and m[i-1][j]~=s)
      ~=(j>1
          and m[i][j-1]~=s)
      then goto b end            -- if it is, go to the label b, we found the head
    i,t=                         -- at the same time
      i%t+1,                     -- increment i
      #m>t and t==i and t+1or t  -- if we checked all chars in the current range, t++
    j=j>1 and j-1or u            -- decrement j
    u=u>#m[1]and j==1 and u+1or u-- if we checked all chars in the current range, u++
  goto a                         -- loop back to label a

  ::b::                          -- label b, start of infinite loop
  io.write(m[i][j])                    -- output the current char
    m[i][j]=s                    -- and set it to a space
    i,j=i<#m                     -- change i and j to find the next character in the snake
          and m[i+1][j]~=s       -- this nested ternary is also explained below
            and i+1              -- as it takes a lot of lines in comment ^^'
          or i>1
            and m[i-1][j]~=s
            and i-1
          or i,
       j<#m[i]
         and m[i][j+1]~=s
           and j+1
         or j>1
           and m[i][j-1]~=s
           and j-1
         or j
    if m[i][j]==s                -- if the new char is a space
    then                         -- it means we finished
      return                  -- exit properly to avoid infinite
    end                          -- printing of spaces
  goto b                         -- else, loop back to label b
end
</code>```

So here comes some detailed explanations about how this program works.

First of all, let's consider the loop labeled a, it allows us to find the closest end to the top-left corner. It will loop forever if there's no end, but that's not a problem :D.

On a 4x4 grid, it here are the snake distances(left), and the order they are looked at (right)

1  2  3  4    |     1  2  4  7
2  3  4  5    |     3  5  8 11
3  4  5  6    |     6  9 12 14
4  5  6  7    |    10 13 15 16
```

<p>For each of this character, to be the end, it have to check two conditions:
  -  Not being a space
  -  Being surrounded by exactly 3 spaces (or exactly 1 non-space)</p>

<p>These conditions are checked the following piece of code</p>

<pre class="lang-lua prettyprint-override"><code>r=m[i][j]~=s
    and(i<#m and m[i+1][j]~=s)
    ==not(j<#m[i] and m[i][j+1]~=s)
    ==not(i-1>0 and m[i-1][j]~=s)
    ==not(j-1>0 and m[i][j-1]~=s)
    and m[i][j]
    or r
  -- special note: "==not" is used as an equivalent to xor
  -- as Lua doesn't know what is a xor...
</code>```

Checking if the char isn't a space is achieved by the expression m[i][j]~=s.

Checking if w're surrounded by only 1 non-space is achived by xor-ing the above conditions for our surrounding, this could be written as

m[i+1][j]~=" " ⊕ m[i][j+1]~=" " ⊕ m[i-1][j]~=" " ⊕ m[i][j-1]~=" "
```

<p>And finally, if all the above is evaluated to true, the ternary will return what's in the last <code>and</code> -> <code>m[i][j]</code>. Else , we let <code>r</code> unset :)</p>

<p>Now that we have the head of the snake, let's get all the way to the other end! Iterating the snake is mainly achieved by the following nested ternaries:</p>

<pre class="lang-lua prettyprint-override"><code>i,j=i<#m and m[i+1][j]~=s and i+1or i-1>0 and m[i-1][j]~=s and i-1or i,
    j<#m[i]and m[i][j+1]~=s and j+1or j-1>0 and m[i][j-1]~=s and j-1or j
</code>```

We re-set i and j at the same time to avoid needing dummies to store the old values They both have the exact same structure, and use simple conditions, so I'll present them in the form of nested if, it should allow you to read them more easily. :)

i=i<#m and m[i+1][j]~=s and i+1or i-1>0 and m[i-1][j]~=s and i-1or i
```

<p>Can be translated to:</p>

<pre class="lang-lua prettyprint-override"><code>if(i<#m)
then
  if(m[i+1][j]~=" ")
  then
    i=i+1
  end
elseif(i-1>0)
then
  if(m[i-1][j]~=" ")
  then
    i=i-1
  end
end
</code>```

Test it!

Here's the code I use to run this, you can test it online by copy-pasting it.

function f(m)t=2u=1i=1j=1s=" "::a::if s~=m[i][j]and(i<#m and m[i+1][j]~=s)~=(j<#m[i]and m[i][j+1]~=s)~=(i>1 and m[i-1][j]~=s)~=(j>1 and m[i][j-1]~=s)then goto b end
i,t=i%t+1,#m>t and t==i and t+1or t j=j>1 and j-1or u u=u<#m[1]and j==1 and u+1or u goto a::b::io.write(m[i][j])m[i][j]=s
i,j=i<#m and s~=m[i+1][j]and i+1or i>1 and s~=m[i-1][j]and i-1or i,j<#m[i]and s~=m[i][j+1]and j+1or j>1 and s~=m[i][j-1]and j-1or j
if s==m[i][j]then return end goto b end

test1={}
s1={
"  tSyrep    ",
"  r    p    ",
"  in Sli    ",
"   g    Sile",
"   Snakes  n",
"Ser      ylt",
"a eh   ilS  ",
"fe w   t    ",
"   emo h    ",
"     Sre    ",
     }
for i=1,#s1
do
  test1[i]={}
  s1[i]:gsub(".",function(c)test1[i][#test1[i]+1]=c end)
end
f(test1)
```

Title: De-Snakify a String

Body:
A regular string looks like this:

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

And a string snake looks something like this:

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

Your Task

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

Specifications

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

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

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

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

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

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

The string will be between 2 and 100 characters long.

Shortest code in bytes wins.

Test Cases

(Input grid, followed by the output string)

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

Hello,IAmAStringSnake!

----------

Python

Python

----------

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

ProgrammingPuzzlesAndCodeGolf

----------

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

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

----------

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

SlipperyStringSnakesSilentlySlitherSomewhereSafe
</code>```

Body:
Lua, <s>562</s> <s>535</s> <s>529</s> <s>513</s> <s>507</s> <s>504</s> <s>466</s> 458 Bytes

By far my most massive golf at the moment, <s>I think I can still cut off 100 bytes, which I'll work toward, but posting it as an answer as it already took some time :).</s> I was right, I've cutted down more than 100 bytes! I don't think there's lot of room for improvement.

this function have to be called with a 2D array containing one character per cell.

Saved 40 bytes while working with @KennyLau, thanks to him!

Woohoo! Under 500!

function f(m)t=2u=1i=1j=1s=" "::a::if s~=m[i][j]and(i<#m and m[i+1][j]~=s)~=(j<#m[i]and m[i][j+1]~=s)~=(i>1 and m[i-1][j]~=s)~=(j>1 and m[i][j-1]~=s)then goto b end
i,t=i%t+1,#m>t and t==i and t+1or t j=j>1 and j-1or u u=u<#m[1]and j==1 and u+1or u goto a::b::io.write(m[i][j])m[i][j]=s
i,j=i<#m and s~=m[i+1][j]and i+1or i>1 and s~=m[i-1][j]and i-1or i,j<#m[i]and s~=m[i][j+1]and j+1or j>1 and s~=m[i][j-1]and j-1or j
if s==m[i][j]then return end goto b end

Ungolfed

<s>Explanations will come once I'm done golfing this, for the moment, i'll lend you a readable version of this source code :D</s> Here comes the explanations!

Edit: not updated with the latest modification, still golfing before updating. Same goes for the explanations

function f(m)                    -- declare the function f which takes a matrix of characters
  t=2                            -- initialise the treshold for i
                                 -- when looking for the first end of the snake
  u=1                            -- same thing for j
  i,j=1,1                        -- initialise i and j,our position in the matrix
  s=" "                          -- shorthand for a space
  ::a::                          -- label a, start of an infinite loop
    if m[i][j]~=s                -- check if the current character isn't a space
      and(i<#m                   -- and weither it is surrounded by exactly
          and m[i+1][j]~=s)      -- 3 spaces or not
      ~=(j<#m[i]
          and m[i][j+1]~=s)      -- (more explanations below)
      ~=(i>1
          and m[i-1][j]~=s)
      ~=(j>1
          and m[i][j-1]~=s)
      then goto b end            -- if it is, go to the label b, we found the head
    i,t=                         -- at the same time
      i%t+1,                     -- increment i
      #m>t and t==i and t+1or t  -- if we checked all chars in the current range, t++
    j=j>1 and j-1or u            -- decrement j
    u=u>#m[1]and j==1 and u+1or u-- if we checked all chars in the current range, u++
  goto a                         -- loop back to label a

  ::b::                          -- label b, start of infinite loop
  io.write(m[i][j])                    -- output the current char
    m[i][j]=s                    -- and set it to a space
    i,j=i<#m                     -- change i and j to find the next character in the snake
          and m[i+1][j]~=s       -- this nested ternary is also explained below
            and i+1              -- as it takes a lot of lines in comment ^^'
          or i>1
            and m[i-1][j]~=s
            and i-1
          or i,
       j<#m[i]
         and m[i][j+1]~=s
           and j+1
         or j>1
           and m[i][j-1]~=s
           and j-1
         or j
    if m[i][j]==s                -- if the new char is a space
    then                         -- it means we finished
      return                  -- exit properly to avoid infinite
    end                          -- printing of spaces
  goto b                         -- else, loop back to label b
end

So here comes some detailed explanations about how this program works.

First of all, let's consider the loop labeled a, it allows us to find the closest end to the top-left corner. It will loop forever if there's no end, but that's not a problem :D.

On a 4x4 grid, it here are the snake distances(left), and the order they are looked at (right)

1  2  3  4    |     1  2  4  7
2  3  4  5    |     3  5  8 11
3  4  5  6    |     6  9 12 14
4  5  6  7    |    10 13 15 16

For each of this character, to be the end, it have to check two conditions:
  -  Not being a space
  -  Being surrounded by exactly 3 spaces (or exactly 1 non-space)

These conditions are checked the following piece of code

r=m[i][j]~=s
    and(i<#m and m[i+1][j]~=s)
    ==not(j<#m[i] and m[i][j+1]~=s)
    ==not(i-1>0 and m[i-1][j]~=s)
    ==not(j-1>0 and m[i][j-1]~=s)
    and m[i][j]
    or r
  -- special note: "==not" is used as an equivalent to xor
  -- as Lua doesn't know what is a xor...

Checking if the char isn't a space is achieved by the expression m[i][j]~=s.

Checking if w're surrounded by only 1 non-space is achived by xor-ing the above conditions for our surrounding, this could be written as

m[i+1][j]~=" " ⊕ m[i][j+1]~=" " ⊕ m[i-1][j]~=" " ⊕ m[i][j-1]~=" "

And finally, if all the above is evaluated to true, the ternary will return what's in the last and -> m[i][j]. Else , we let r unset :)

Now that we have the head of the snake, let's get all the way to the other end! Iterating the snake is mainly achieved by the following nested ternaries:

i,j=i<#m and m[i+1][j]~=s and i+1or i-1>0 and m[i-1][j]~=s and i-1or i,
    j<#m[i]and m[i][j+1]~=s and j+1or j-1>0 and m[i][j-1]~=s and j-1or j

We re-set i and j at the same time to avoid needing dummies to store the old values They both have the exact same structure, and use simple conditions, so I'll present them in the form of nested if, it should allow you to read them more easily. :)

i=i<#m and m[i+1][j]~=s and i+1or i-1>0 and m[i-1][j]~=s and i-1or i

Can be translated to:

if(i<#m)
then
  if(m[i+1][j]~=" ")
  then
    i=i+1
  end
elseif(i-1>0)
then
  if(m[i-1][j]~=" ")
  then
    i=i-1
  end
end

Test it!

Here's the code I use to run this, you can test it online by copy-pasting it.

function f(m)t=2u=1i=1j=1s=" "::a::if s~=m[i][j]and(i<#m and m[i+1][j]~=s)~=(j<#m[i]and m[i][j+1]~=s)~=(i>1 and m[i-1][j]~=s)~=(j>1 and m[i][j-1]~=s)then goto b end
i,t=i%t+1,#m>t and t==i and t+1or t j=j>1 and j-1or u u=u<#m[1]and j==1 and u+1or u goto a::b::io.write(m[i][j])m[i][j]=s
i,j=i<#m and s~=m[i+1][j]and i+1or i>1 and s~=m[i-1][j]and i-1or i,j<#m[i]and s~=m[i][j+1]and j+1or j>1 and s~=m[i][j-1]and j-1or j
if s==m[i][j]then return end goto b end

test1={}
s1={
"  tSyrep    ",
"  r    p    ",
"  in Sli    ",
"   g    Sile",
"   Snakes  n",
"Ser      ylt",
"a eh   ilS  ",
"fe w   t    ",
"   emo h    ",
"     Sre    ",
     }
for i=1,#s1
do
  test1[i]={}
  s1[i]:gsub(".",function(c)test1[i][#test1[i]+1]=c end)
end
f(test1)


问:
Is the path correct?

Is the path correct ?

Given a string, your program must determine whether or not Alice can reach Bob, following the signs on the map. You must return a truthy or falsy value.

The input string will contain the following characters :

 (space) and \n. Only used for padding.

>, <, ^, v, are the "signs". They show the direction.

&. Ignore next char, whatever it is (including spaces and Bob)

A and B respectively Alice and Bob.

The map is a torus. If Alice reaches the end of a row, then she is teleported back to the beginning of that row. Same applies for columns.

Examples

Given those examples as input, your program must return a truthy value (each input is separated with a - line):

```<code>A>B
-----------------
<BA
-----------------
A       B
-----------------
BA
-----------------
Av  >B
 >  ^
-----------------
Av
 B
-----------------
A>v
  >B
-----------------
A>v>   v>B
 v< > &<^
 > ^
-----------------
A>v>   v
 v< >B&<
 > ^
-----------------
A&<B
-----------------
A&B<
-----------------
<A       &B
</code>```

For the following, your program must output a falsy value or nothing :

```<code>AvB
-----------------
A&B
-----------------
A><B
-----------------
A>v
 ^<B
</code>```

Path viewer

You can have a visual representation of the input here. Thanks to arnemart for this.

Some rules

The input may be padded with spaces to form a rectangle

Initially, Alice goes straight forward (from above, she goes to the right)

Your program should handle infinite loop cases (see Hint)

A is not always the first character, as you may have seen, however, you may write a program that handles only input with A being the first char, but 20 bytes will be added to your score.

A map (the input) is considered invalid in case there are other characters than those specified above. Your program won't have to handle them.

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

Hint

Your program will most likely be a loop, unless you find a more mathematical solution to this challenge. To handle infinite path, I recommend using a finite loop (e.g for) instead of a potentially infinite one (e.g while).

Therefore, the maximum iteration of the loop I can think of (I did not do any maths, any correction is welcome) is (length of input)*4

Title: Is the path correct?

Body:
JavaScript (ES6), 176 bytes

m=>[...m,q=~m.length,l=~m.search`
`||q,a=m.search`A`,p=d=r=1].map(_=>(a+=d,a-=d*((a-l+1)%l?m[a]?0:q/l:~l),c=m[a],p=="&"?0:d={">":1,"<":-1,"^":l,v:-l}[c=="B"?r=0:c]||d,p=c))&&!r

Explanation

Requires the input to be space-padded to form a rectangle (I hope this is OK).

var solution =

m=>[
    ...m,                           // iterate m.length times
    q=~m.length,                    // q = total length of m
    l=~m.search`\n`||q,             // l = line length
    a=m.search`A`,                  // a = index of Alice
    p=                              // p = previous character
    d=                              // d = direction offset
    r=1                             // r = result
  ].map(_=>(                        // loop
    a+=d,                           // move Alice
    a-=d*((a-l+1)%l?m[a]?0:q/l:~l), // wrap
    c=m[a],
    p=="&"?0:                       // do nothing after &
    d={">":1,"<":-1,"^":l,v:-l}     // set the new direction
      [c=="B"?r=0:c]                // if on Bob, r = 0
    ||d,
    p=c
  ))&&!r                            // return result

var testCasesTrue =
`A>B
-----------------
<BA
-----------------
A       B
-----------------
BA
-----------------
Av  >B
 >  ^
-----------------
Av
 B
-----------------
A>v
  >B
-----------------
A>v>   v>B
 v< > &<^
 > ^
-----------------
A>v>   v
 v< >B&<
 > ^
-----------------
A&<B
-----------------
A&B<
-----------------
<A       &B`
.split("\n-----------------\n");

var testCasesFalse =
`AvB
-----------------
A&B
-----------------
A><B
-----------------
A>v
 ^<B`
.split("\n-----------------\n");

var test = (cases, expected) => cases.map((t,i)=>++i+": "+(solution(t)==expected?"Pass":"Fail")).join`\n`;
document.write(`<pre>${test(testCasesTrue,true)}\n\n${test(testCasesFalse,false)}</pre>`);


答:
C, 250 bytes

```<code>#define h x=(j+x-1+d%3)%j,i=(j+i+(d=='v')-(d==94))%j
char a[999],b[999];x,i,d=2,k,f;main(j){for(;gets(a+j*i);)j=strlen(a+j*i++);for(x=strchr(a,65)-a,i=x/j,x=x%j;!k*d;h)k|=b[f=j*i+x]&1<<d%5,b[f]|=1<<d%5,(f=a[f])&16?d=f:f&4?h:f&2?d=0:0;putchar(48+!k);}
</code>```

This also requires that the input is padded with spaces.

Ungolfed:

```<code>#define h x=(j+x-1+d%3)%j,i=(j+i+(d=='v')-(d==94))%j
char a[999],b[999];x,i,d=2,k,f;
main(j){
 for(;gets(a+j*i);)j=strlen(a+j*i++); //read lines and determine line length
 for(x=strchr(a,65)-a,i=x/j,x=x%j;    //the current position is 'A'
 !k*d; //as long as we have not arrived at 'B'
       //and not travelled through the same cell and in the same direction twice
 h)    //advance one in the current direction
   k|=b[f=j*i+x]&1<<d%5,b[f]|=1<<d%5,  //if we have already travelled
                                       //through this cell in this direction
   (f=a[f])&16?d=f //change direction if this cell is one of <>^v
   :f&4?h          //if this cell is '&', advance one in the current direction
   :f&2?d=0:0;     //if we have reached 'B'
 putchar(48+!k);
}
</code>```

Title: Is the path correct?

Body:
Is the path correct ?

Given a string, your program must determine whether or not Alice can reach Bob, following the signs on the map. You must return a truthy or falsy value.

The input string will contain the following characters :

 (space) and \n. Only used for padding.

>, <, ^, v, are the "signs". They show the direction.

&. Ignore next char, whatever it is (including spaces and Bob)

A and B respectively Alice and Bob.

The map is a torus. If Alice reaches the end of a row, then she is teleported back to the beginning of that row. Same applies for columns.

Examples

Given those examples as input, your program must return a truthy value (each input is separated with a - line):

```<code>A>B
-----------------
<BA
-----------------
A       B
-----------------
BA
-----------------
Av  >B
 >  ^
-----------------
Av
 B
-----------------
A>v
  >B
-----------------
A>v>   v>B
 v< > &<^
 > ^
-----------------
A>v>   v
 v< >B&<
 > ^
-----------------
A&<B
-----------------
A&B<
-----------------
<A       &B
</code>```

For the following, your program must output a falsy value or nothing :

```<code>AvB
-----------------
A&B
-----------------
A><B
-----------------
A>v
 ^<B
</code>```

Path viewer

You can have a visual representation of the input here. Thanks to arnemart for this.

Some rules

The input may be padded with spaces to form a rectangle

Initially, Alice goes straight forward (from above, she goes to the right)

Your program should handle infinite loop cases (see Hint)

A is not always the first character, as you may have seen, however, you may write a program that handles only input with A being the first char, but 20 bytes will be added to your score.

A map (the input) is considered invalid in case there are other characters than those specified above. Your program won't have to handle them.

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

Hint

Your program will most likely be a loop, unless you find a more mathematical solution to this challenge. To handle infinite path, I recommend using a finite loop (e.g for) instead of a potentially infinite one (e.g while).

Therefore, the maximum iteration of the loop I can think of (I did not do any maths, any correction is welcome) is (length of input)*4

Body:
C, 250 bytes

#define h x=(j+x-1+d%3)%j,i=(j+i+(d=='v')-(d==94))%j
char a[999],b[999];x,i,d=2,k,f;main(j){for(;gets(a+j*i);)j=strlen(a+j*i++);for(x=strchr(a,65)-a,i=x/j,x=x%j;!k*d;h)k|=b[f=j*i+x]&1<<d%5,b[f]|=1<<d%5,(f=a[f])&16?d=f:f&4?h:f&2?d=0:0;putchar(48+!k);}

This also requires that the input is padded with spaces.

Ungolfed:

#define h x=(j+x-1+d%3)%j,i=(j+i+(d=='v')-(d==94))%j
char a[999],b[999];x,i,d=2,k,f;
main(j){
 for(;gets(a+j*i);)j=strlen(a+j*i++); //read lines and determine line length
 for(x=strchr(a,65)-a,i=x/j,x=x%j;    //the current position is 'A'
 !k*d; //as long as we have not arrived at 'B'
       //and not travelled through the same cell and in the same direction twice
 h)    //advance one in the current direction
   k|=b[f=j*i+x]&1<<d%5,b[f]|=1<<d%5,  //if we have already travelled
                                       //through this cell in this direction
   (f=a[f])&16?d=f //change direction if this cell is one of <>^v
   :f&4?h          //if this cell is '&', advance one in the current direction
   :f&2?d=0:0;     //if we have reached 'B'
 putchar(48+!k);
}


答:
Fuzzy Octo Guacamole and Jolf, 112 bytes

(non-competing, FOG is newer than the challenge)

```<code>a++++"This program wasn\'t written in ""Jolf"", it was built for ""Fuzzy Octo Guacamole""!"//__ssss.Z_sssts''.jX
</code>```

Prints This program wasn't written in Fuzzy Octo Guacamole, it was built for Jolf! in FOG, and This program wasn't written in Jolf, it was built for Fuzzy Octo Guacamole! in Jolf.

This was fun.

FOG side is complicated, because there is no command to swap the top 2 items.

FOG Explanation:

```<code>a++++"This program wasn\'t written in ""Jolf"", it was built for ""Fuzzy Octo Guacamole""!"//__ssss.Z_sssts''.j_;
</code>```

The a adds the 2 top items, adding 0 and 0 and pushing the result, 0.  Does nothing.

The + increment, so at the end the stack has [5].

The strings just push those to the stack.

The // does nothing but push '/' to the stack twice, but in Jolf it is a comment.

The __ pops the 2 '/'s we pushed, just removing them.

The ssss moves the top 4 strings, the parts that need rearranging, to the other stack. They are now in reverse order also.

The . switches stacks.

Z reverses the stack.

_ pops the '!', so we get it out of the way.  It is set to the temp var.

Then we move the 'Fuzzy Octo Guacamole', the 'was built for', and the 'Jolf' to the other stack in that order. That is the 3 s.

t pushes the temp var, which is still the '!' and then the next s puts it on the other stack.

We have all the strings, but how to print?

We first push '', the empty string.

Then we switch stacks with ..

Then we use j.  This is join.  It pushes the current stack as a string with the top of the inactive stack as a separator.

This is equivalent to the python ''.join(stack).

Then the X pops and prints, and we are done!

Side note: The poor 5 is left on the stack, all by himself. ;_;

Jolf Explanation:

Much simpler.

Jolf is prefix, so the a gets the alert function ready.

The + all concatenate the strings, so they just get stuck together.

So this just prints as-is, no need to rearrange. And the // is a comment, and hides the FOG side code.

Thanks to @CᴏɴᴏʀO'Bʀɪᴇɴ for making Jolf, a wonderful language to use.

Aʟsᴏ, ғʀᴇᴇ ᴘʟᴜɢ ғᴏʀ sᴍᴀʟʟ ᴄᴀᴘs!!!

Title: I'm not the language you're looking for!

Body:
Isn't it annoying when you find a piece of code and you don't know what language it was written in? This challenge attempts to somewhat solve this.

Challenge

You will have to write a program that when run in two different languages, will output the string:

This program wasn't written in <language program compiled/interpreted in>, it was built for <other language the program can be run in>!

In the output, language names should have official capitalization. eg: CJam, C++

Neither program should take any input from the user.

When run in both languages, output should be to stdout or equivalent.

There should be no output to stderr in either program.

You may use comments in either language.

Two different versions of the same language count as different languages.

If this is done, the program should output the major version number, and if running on two different minor versions, should report the minor version also.

You should not use prebuilt version functions (this includes variables that have already been evaluated at runtime).

Example output:

Perl and Ruby:

Perl: This program wasn't written in Perl, it was built for Ruby!

Ruby: This program wasn't written in Ruby, it was built for Perl!

Python and C:

Python: This program wasn't written in Python, it was built for C!

C: This program wasn't written in C, it was built for Python!

Python 2 and Python 3:

Python 2: This program wasn't written in Python 2, it was built for Python 3!

Python 3: This program wasn't written in Python 3, it was built for Python 2!

Python 2.4 and Python 2.7:

Python 2.4: This program wasn't written in Python 2.4, it was built for Python 2.7!

Python 2.7: This program wasn't written in Python 2.7, it was built for Python 2.4!

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

Body:
Fuzzy Octo Guacamole and Jolf, 112 bytes

(non-competing, FOG is newer than the challenge)

a++++"This program wasn\'t written in ""Jolf"", it was built for ""Fuzzy Octo Guacamole""!"//__ssss.Z_sssts''.jX

Prints This program wasn't written in Fuzzy Octo Guacamole, it was built for Jolf! in FOG, and This program wasn't written in Jolf, it was built for Fuzzy Octo Guacamole! in Jolf.

This was fun.

FOG side is complicated, because there is no command to swap the top 2 items.

FOG Explanation:

a++++"This program wasn\'t written in ""Jolf"", it was built for ""Fuzzy Octo Guacamole""!"//__ssss.Z_sssts''.j_;

The a adds the 2 top items, adding 0 and 0 and pushing the result, 0.  Does nothing.

The + increment, so at the end the stack has [5].

The strings just push those to the stack.

The // does nothing but push '/' to the stack twice, but in Jolf it is a comment.

The __ pops the 2 '/'s we pushed, just removing them.

The ssss moves the top 4 strings, the parts that need rearranging, to the other stack. They are now in reverse order also.

The . switches stacks.

Z reverses the stack.

_ pops the '!', so we get it out of the way.  It is set to the temp var.

Then we move the 'Fuzzy Octo Guacamole', the 'was built for', and the 'Jolf' to the other stack in that order. That is the 3 s.

t pushes the temp var, which is still the '!' and then the next s puts it on the other stack.

We have all the strings, but how to print?

We first push '', the empty string.

Then we switch stacks with ..

Then we use j.  This is join.  It pushes the current stack as a string with the top of the inactive stack as a separator.

This is equivalent to the python ''.join(stack).

Then the X pops and prints, and we are done!

Side note: The poor 5 is left on the stack, all by himself. ;_;

Jolf Explanation:

Much simpler.

Jolf is prefix, so the a gets the alert function ready.

The + all concatenate the strings, so they just get stuck together.

So this just prints as-is, no need to rearrange. And the // is a comment, and hides the FOG side code.

Thanks to @CᴏɴᴏʀO'Bʀɪᴇɴ for making Jolf, a wonderful language to use.

Aʟsᴏ, ғʀᴇᴇ ᴘʟᴜɢ ғᴏʀ sᴍᴀʟʟ ᴄᴀᴘs!!!