答:
Pyth, 122 bytes

```<code>=k@Q0J-@Q1 1K*4J=T*@Q1[*lkd;Vlk=Z+*%NJ/%N*J2J*/N*J2J=Y.a-+**/%N*J2J!/%NK*J2J*%NJ!/%N*J2J**!/%N*J2J/%NK*J2J XTYX@TYZ@kN;jbT
</code>```

I've made a formula to calculate the x, y positions of each character based on the segment size / modulo, but they got larger than I expected :c

Explanation:

```<code>=k@Q0                                                                                # Initialize var with the text
     J-@Q1 1                                                                                # Initialize var with the segment size (minus 1)
            K*4J                                                                                # Initialize var with the "block" size (where the pattern start to repeat)
                =T*@Q1[*lkd;                                                                                # Initialize output var with an empty array of strings
                            Vlk                                                                                # Interate over the text
                               =Z+*%NJ/%N*J2J*/N*J2J                                                                      # Matemagics to calculate X position
                                                    =Y.a-+**/%N*J2J!/%NK*J2J*%NJ!/%N*J2J**!/%N*J2J/%NK*J2J                # Matemagics to calculate Y position
                                                                                XTYX@TYZ@kN;    # Assign the letter being iterated at x,y in the output
                                                                                jbT # Join with newlines and print the output
</code>```

Test here

For the Math formulas, I used mod to generate 0/1 flags and then multiplied by a factor based on the input n, added the spreadsheet with each step on the snippet bellow

td{padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11.0pt;font-weight:400;font-style:normal;text-decoration:none;font-family:Calibri,sans-serif}.x1{text-align:general;vertical-align:bottom;white-space:nowrap}.x2{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid gray;white-space:nowrap}.x3{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid windowtext;white-space:nowrap}.x4{text-align:general;vertical-align:bottom;border:.5pt solid gray;white-space:nowrap}.x5{text-align:general;vertical-align:bottom;border:.5pt solid gray;background:#c5d9f1;white-space:nowrap}.x6{text-align:general;vertical-align:bottom;border:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x7{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid windowtext;border-bottom:.5pt solid gray;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x8{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid windowtext;background:#d9d9d9;white-space:nowrap}.x9{text-align:general;vertical-align:bottom;border:.5pt solid gray;background:#d9d9d9;white-space:nowrap}.x10{text-align:right;vertical-align:bottom;border:.5pt solid gray;white-space:nowrap}.x11{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid windowtext;background:#d9d9d9;white-space:nowrap}.x12{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;background:#d9d9d9;white-space:nowrap}.x13{text-align:right;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;white-space:nowrap}.x14{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;white-space:nowrap}.x15{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;background:#c5d9f1;white-space:nowrap}.x16{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x17{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid windowtext;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x18{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:0;border-left:.5pt solid gray;white-space:nowrap}.x19{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid windowtext;white-space:nowrap}.x20{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid gray;background:#c5d9f1;white-space:nowrap}.x21{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x22{text-align:general;vertical-align:bottom;border-right:.5pt solid windowtext;border-bottom:.5pt solid gray;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x23{text-align:center;vertical-align:bottom;border:.5pt solid windowtext;white-space:nowrap}.x24{text-align:center;vertical-align:bottom;border-right:.5pt solid windowtext;border-bottom:0;border-left:.5pt solid windowtext;white-space:nowrap}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><table style="border-collapse:collapse;table-layout:fixed;width:761pt" border="0" cellpadding="0" cellspacing="0" width="1015">
<colgroup><col style="width:16pt" width="21">
<col style="mso-width-alt:2742;width:56pt" span="2" width="75">
<col style="width:23pt" width="31">
<col style="width:50pt" width="67">
<col style="width:60pt" width="80">
<col style="width:85pt" width="113">
<col style="width:26pt" width="35">
<col style="width:41pt" width="54">
<col style="width:29pt" width="39">
<col style="width:41pt" width="55">
<col style="width:104pt" width="138">
<col style="width:29pt" width="39">
<col style="width:41pt" width="54">
<col style="width:65pt" width="87">
<col style="width:39pt" width="52">
</colgroup><tbody><tr style="height:15.0pt" height="20">
<td class="x23" style="height:15.0pt;width:16pt" width="21" height="20">d</td>
<td class="x23" style="width:56pt" width="75">e</td>
<td class="x23" style="width:56pt" width="75">f</td>
<td class="x24" style="width:23pt" width="31"> </td>
<td class="x23" style="width:50pt" width="67">h</td>
<td class="x23" style="width:60pt" width="80">i</td>
<td class="x23" style="width:85pt" width="113">j</td>
<td class="x23" style="width:26pt" width="35">k</td>
<td class="x23" style="width:41pt" width="54">l</td>
<td class="x23" style="width:29pt" width="39">m</td>
<td class="x23" style="width:41pt" width="55">n</td>
<td class="x23" style="width:104pt" width="138">o</td>
<td class="x23" style="width:29pt" width="39">p</td>
<td class="x23" style="width:41pt" width="54">q</td>
<td class="x23" style="width:65pt" width="87">r</td>
<td class="x23" style="width:39pt" width="52">s</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x23" style="height:15.0pt" height="20">i</td>
<td class="x23">expected x</td>
<td class="x23">expected y</td>
<td class="x24" style=""> </td>
<td class="x23">pos % seg</td>
<td class="x23">pos/(seg*2)</td>
<td class="x23">pos%(seg*2)/seg</td>
<td class="x23">not j</td>
<td class="x23">seg*i+h</td>
<td class="x23">i*seg</td>
<td class="x23">j*l+k*m</td>
<td class="x23">pos%(seg*4)/(seg*2)</td>
<td class="x23">not o</td>
<td class="x23">j*p*seg</td>
<td class="x23">abs(o*seg-h)</td>
<td class="x23">q*j+r*k</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x19" style="height:15.0pt" align="right" height="20">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x18" style=""> </td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">1</td>
<td class="x2" style="" align="right">0</td>
<td class="x20" style="" align="right">0</td>
<td class="x21" style="" align="right">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">1</td>
<td class="x2" style="" align="right">0</td>
<td class="x20" style="" align="right">0</td>
<td class="x22" style="" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x18" style=""> </td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">0</td>
<td class="x6" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x7" align="right">1</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">2</td>
<td class="x18" style=""> </td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">2</td>
<td class="x5" align="right">0</td>
<td class="x6" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x7" align="right">2</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">3</td>
<td class="x9" align="right">0</td>
<td class="x9" align="right">3</td>
<td class="x18" style=""> </td>
<td class="x10">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x6" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">4</td>
<td class="x9" align="right">1</td>
<td class="x9" align="right">3</td>
<td class="x18" style=""> </td>
<td class="x10">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x6" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">5</td>
<td class="x9" align="right">2</td>
<td class="x9" align="right">3</td>
<td class="x18" style=""> </td>
<td class="x10">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x6" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">2</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">6</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">3</td>
<td class="x18" style=""> </td>
<td class="x10">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">3</td>
<td class="x5" align="right">3</td>
<td class="x6" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">3</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">7</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">2</td>
<td class="x18" style=""> </td>
<td class="x10">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">4</td>
<td class="x5" align="right">3</td>
<td class="x6" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x7" align="right">2</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">8</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x18" style=""> </td>
<td class="x10">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">5</td>
<td class="x5" align="right">3</td>
<td class="x6" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x7" align="right">1</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">9</td>
<td class="x9" align="right">3</td>
<td class="x9" align="right">0</td>
<td class="x18" style=""> </td>
<td class="x10">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">3</td>
<td class="x6" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">3</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">10</td>
<td class="x9" align="right">4</td>
<td class="x9" align="right">0</td>
<td class="x18" style=""> </td>
<td class="x10">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">4</td>
<td class="x4" align="right">3</td>
<td class="x6" align="right">4</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">2</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">11</td>
<td class="x9" align="right">5</td>
<td class="x9" align="right">0</td>
<td class="x18" style=""> </td>
<td class="x10">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">5</td>
<td class="x4" align="right">3</td>
<td class="x6" align="right">5</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">12</td>
<td class="x4" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x18" style=""> </td>
<td class="x10">0</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">6</td>
<td class="x5" align="right">6</td>
<td class="x6" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">13</td>
<td class="x4" align="right">6</td>
<td class="x4" align="right">1</td>
<td class="x18" style=""> </td>
<td class="x10">1</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">7</td>
<td class="x5" align="right">6</td>
<td class="x6" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x7" align="right">1</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">14</td>
<td class="x4" align="right">6</td>
<td class="x4" align="right">2</td>
<td class="x18" style=""> </td>
<td class="x10">2</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">8</td>
<td class="x5" align="right">6</td>
<td class="x6" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x7" align="right">2</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">15</td>
<td class="x9" align="right">6</td>
<td class="x9" align="right">3</td>
<td class="x18" style=""> </td>
<td class="x10">0</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">6</td>
<td class="x4" align="right">6</td>
<td class="x6" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">16</td>
<td class="x9" align="right">7</td>
<td class="x9" align="right">3</td>
<td class="x18" style=""> </td>
<td class="x10">1</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">7</td>
<td class="x4" align="right">6</td>
<td class="x6" align="right">7</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">17</td>
<td class="x9" align="right">8</td>
<td class="x9" align="right">3</td>
<td class="x18" style=""> </td>
<td class="x10">2</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">8</td>
<td class="x4" align="right">6</td>
<td class="x6" align="right">8</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">2</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">18</td>
<td class="x4" align="right">9</td>
<td class="x4" align="right">3</td>
<td class="x18" style=""> </td>
<td class="x10">0</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">9</td>
<td class="x5" align="right">9</td>
<td class="x6" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">3</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">19</td>
<td class="x4" align="right">9</td>
<td class="x4" align="right">2</td>
<td class="x18" style=""> </td>
<td class="x10">1</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">10</td>
<td class="x5" align="right">9</td>
<td class="x6" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x7" align="right">2</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">20</td>
<td class="x4" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x18" style=""> </td>
<td class="x10">2</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">11</td>
<td class="x5" align="right">9</td>
<td class="x6" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x7" align="right">1</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">21</td>
<td class="x9" align="right">9</td>
<td class="x9" align="right">0</td>
<td class="x18" style=""> </td>
<td class="x10">0</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">9</td>
<td class="x4" align="right">9</td>
<td class="x6" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">3</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">22</td>
<td class="x9" align="right">10</td>
<td class="x9" align="right">0</td>
<td class="x18" style=""> </td>
<td class="x10">1</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">10</td>
<td class="x4" align="right">9</td>
<td class="x6" align="right">10</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">2</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x11" style="height:15.0pt;border-top:none" align="right" height="20">23</td>
<td class="x12" align="right">11</td>
<td class="x12" align="right">0</td>
<td class="x18" style=""> </td>
<td class="x13">2</td>
<td class="x14" align="right">3</td>
<td class="x14" align="right">1</td>
<td class="x14" align="right">0</td>
<td class="x15" align="right">11</td>
<td class="x14" align="right">9</td>
<td class="x16" align="right">11</td>
<td class="x14" align="right">1</td>
<td class="x14" align="right">0</td>
<td class="x15" align="right">0</td>
<td class="x14" align="right">1</td>
<td class="x17" align="right">0</td>
</tr>
</tr>
</tbody></table></code>```

Title: Snakify a String

Body:
Pyth, 122 bytes

=k@Q0J-@Q1 1K*4J=T*@Q1[*lkd;Vlk=Z+*%NJ/%N*J2J*/N*J2J=Y.a-+**/%N*J2J!/%NK*J2J*%NJ!/%N*J2J**!/%N*J2J/%NK*J2J XTYX@TYZ@kN;jbT

I've made a formula to calculate the x, y positions of each character based on the segment size / modulo, but they got larger than I expected :c

Explanation:

=k@Q0                                                                                # Initialize var with the text
     J-@Q1 1                                                                                # Initialize var with the segment size (minus 1)
            K*4J                                                                                # Initialize var with the "block" size (where the pattern start to repeat)
                =T*@Q1[*lkd;                                                                                # Initialize output var with an empty array of strings
                            Vlk                                                                                # Interate over the text
                               =Z+*%NJ/%N*J2J*/N*J2J                                                                      # Matemagics to calculate X position
                                                    =Y.a-+**/%N*J2J!/%NK*J2J*%NJ!/%N*J2J**!/%N*J2J/%NK*J2J                # Matemagics to calculate Y position
                                                                                XTYX@TYZ@kN;    # Assign the letter being iterated at x,y in the output
                                                                                jbT # Join with newlines and print the output

<a href="https://pyth.herokuapp.com/?code=%3Dk%40Q0J-%40Q1%201K*4J%3DT*%40Q1[*lkd%3BVlk%3DZ%2B*%25NJ%2F%25N*J2J*%2FN*J2J%3DY.a-%2B**%2F%25N*J2J!%2F%25NK*J2J*%25NJ!%2F%25N*J2J**!%2F%25N*J2J%2F%25NK*J2J%20XTYX%40TYZ%40kN%3BjbT&input=[%22IHopeYourProgramWorksForInputStringsWhichAre100CharactersLongBecauseThisTestCaseWillFailIfItDoesNot.%22%2C5]&test_suite=1&test_suite_input=[%22a%22%2C%203]%0A[%22Hello%2CWorld!%22%2C%203]%0A[%22ProgrammingPuzzlesAndCodeGolf%22%2C%204]%0A[%22IHopeYourProgramWorksForInputStringsWhichAre100CharactersLongBecauseThisTestCaseWillFailIfItDoesNot.%22%2C%205]%0A[%22!%5C%22%23%24%25%26%27%28%29*%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMNOPQRSTUVWXYZ[%5C]%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D~%22%2C%2010]&debug=0" rel="nofollow">Test here

For the Math formulas, I used mod to generate 0/1 flags and then multiplied by a factor based on the input n, added the spreadsheet with each step on the snippet bellow

td{padding-top:1px;padding-right:1px;padding-left:1px;color:black;font-size:11.0pt;font-weight:400;font-style:normal;text-decoration:none;font-family:Calibri,sans-serif}.x1{text-align:general;vertical-align:bottom;white-space:nowrap}.x2{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid gray;white-space:nowrap}.x3{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid windowtext;white-space:nowrap}.x4{text-align:general;vertical-align:bottom;border:.5pt solid gray;white-space:nowrap}.x5{text-align:general;vertical-align:bottom;border:.5pt solid gray;background:#c5d9f1;white-space:nowrap}.x6{text-align:general;vertical-align:bottom;border:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x7{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid windowtext;border-bottom:.5pt solid gray;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x8{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid windowtext;background:#d9d9d9;white-space:nowrap}.x9{text-align:general;vertical-align:bottom;border:.5pt solid gray;background:#d9d9d9;white-space:nowrap}.x10{text-align:right;vertical-align:bottom;border:.5pt solid gray;white-space:nowrap}.x11{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid windowtext;background:#d9d9d9;white-space:nowrap}.x12{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;background:#d9d9d9;white-space:nowrap}.x13{text-align:right;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;white-space:nowrap}.x14{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;white-space:nowrap}.x15{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;background:#c5d9f1;white-space:nowrap}.x16{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid gray;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x17{text-align:general;vertical-align:bottom;border-top:.5pt solid gray;border-right:.5pt solid windowtext;border-bottom:.5pt solid windowtext;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x18{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:0;border-left:.5pt solid gray;white-space:nowrap}.x19{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid windowtext;white-space:nowrap}.x20{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid gray;background:#c5d9f1;white-space:nowrap}.x21{text-align:general;vertical-align:bottom;border-right:.5pt solid gray;border-bottom:.5pt solid gray;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x22{text-align:general;vertical-align:bottom;border-right:.5pt solid windowtext;border-bottom:.5pt solid gray;border-left:.5pt solid gray;background:#ebf1de;white-space:nowrap}.x23{text-align:center;vertical-align:bottom;border:.5pt solid windowtext;white-space:nowrap}.x24{text-align:center;vertical-align:bottom;border-right:.5pt solid windowtext;border-bottom:0;border-left:.5pt solid windowtext;white-space:nowrap}

<table style="border-collapse:collapse;table-layout:fixed;width:761pt" border="0" cellpadding="0" cellspacing="0" width="1015">
<colgroup><col style="width:16pt" width="21">
<col style="mso-width-alt:2742;width:56pt" span="2" width="75">
<col style="width:23pt" width="31">
<col style="width:50pt" width="67">
<col style="width:60pt" width="80">
<col style="width:85pt" width="113">
<col style="width:26pt" width="35">
<col style="width:41pt" width="54">
<col style="width:29pt" width="39">
<col style="width:41pt" width="55">
<col style="width:104pt" width="138">
<col style="width:29pt" width="39">
<col style="width:41pt" width="54">
<col style="width:65pt" width="87">
<col style="width:39pt" width="52">
</colgroup><tbody><tr style="height:15.0pt" height="20">
<td class="x23" style="height:15.0pt;width:16pt" width="21" height="20">d</td>
<td class="x23" style="width:56pt" width="75">e</td>
<td class="x23" style="width:56pt" width="75">f</td>
<td class="x24" style="width:23pt" width="31">&nbsp;</td>
<td class="x23" style="width:50pt" width="67">h</td>
<td class="x23" style="width:60pt" width="80">i</td>
<td class="x23" style="width:85pt" width="113">j</td>
<td class="x23" style="width:26pt" width="35">k</td>
<td class="x23" style="width:41pt" width="54">l</td>
<td class="x23" style="width:29pt" width="39">m</td>
<td class="x23" style="width:41pt" width="55">n</td>
<td class="x23" style="width:104pt" width="138">o</td>
<td class="x23" style="width:29pt" width="39">p</td>
<td class="x23" style="width:41pt" width="54">q</td>
<td class="x23" style="width:65pt" width="87">r</td>
<td class="x23" style="width:39pt" width="52">s</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x23" style="height:15.0pt" height="20">i</td>
<td class="x23">expected x</td>
<td class="x23">expected y</td>
<td class="x24" style="">&nbsp;</td>
<td class="x23">pos % seg</td>
<td class="x23">pos/(seg*2)</td>
<td class="x23">pos%(seg*2)/seg</td>
<td class="x23">not j</td>
<td class="x23">seg*i+h</td>
<td class="x23">i*seg</td>
<td class="x23">j*l+k*m</td>
<td class="x23">pos%(seg*4)/(seg*2)</td>
<td class="x23">not o</td>
<td class="x23">j*p*seg</td>
<td class="x23">abs(o*seg-h)</td>
<td class="x23">q*j+r*k</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x19" style="height:15.0pt" align="right" height="20">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x18" style="">&nbsp;</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">1</td>
<td class="x2" style="" align="right">0</td>
<td class="x20" style="" align="right">0</td>
<td class="x21" style="" align="right">0</td>
<td class="x2" style="" align="right">0</td>
<td class="x2" style="" align="right">1</td>
<td class="x2" style="" align="right">0</td>
<td class="x20" style="" align="right">0</td>
<td class="x22" style="" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x18" style="">&nbsp;</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">0</td>
<td class="x6" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x7" align="right">1</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">2</td>
<td class="x18" style="">&nbsp;</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">2</td>
<td class="x5" align="right">0</td>
<td class="x6" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x7" align="right">2</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">3</td>
<td class="x9" align="right">0</td>
<td class="x9" align="right">3</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x6" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">4</td>
<td class="x9" align="right">1</td>
<td class="x9" align="right">3</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x6" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">5</td>
<td class="x9" align="right">2</td>
<td class="x9" align="right">3</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x6" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">2</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">6</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">3</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">3</td>
<td class="x5" align="right">3</td>
<td class="x6" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">3</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">7</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">2</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">4</td>
<td class="x5" align="right">3</td>
<td class="x6" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x7" align="right">2</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">8</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">5</td>
<td class="x5" align="right">3</td>
<td class="x6" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x7" align="right">1</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">9</td>
<td class="x9" align="right">3</td>
<td class="x9" align="right">0</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">3</td>
<td class="x6" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">3</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">10</td>
<td class="x9" align="right">4</td>
<td class="x9" align="right">0</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">4</td>
<td class="x4" align="right">3</td>
<td class="x6" align="right">4</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">2</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">11</td>
<td class="x9" align="right">5</td>
<td class="x9" align="right">0</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">5</td>
<td class="x4" align="right">3</td>
<td class="x6" align="right">5</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">12</td>
<td class="x4" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">0</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">6</td>
<td class="x5" align="right">6</td>
<td class="x6" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">13</td>
<td class="x4" align="right">6</td>
<td class="x4" align="right">1</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">1</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">7</td>
<td class="x5" align="right">6</td>
<td class="x6" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x7" align="right">1</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">14</td>
<td class="x4" align="right">6</td>
<td class="x4" align="right">2</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">2</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">8</td>
<td class="x5" align="right">6</td>
<td class="x6" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x7" align="right">2</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">15</td>
<td class="x9" align="right">6</td>
<td class="x9" align="right">3</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">0</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">6</td>
<td class="x4" align="right">6</td>
<td class="x6" align="right">6</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">16</td>
<td class="x9" align="right">7</td>
<td class="x9" align="right">3</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">1</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">7</td>
<td class="x4" align="right">6</td>
<td class="x6" align="right">7</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">17</td>
<td class="x9" align="right">8</td>
<td class="x9" align="right">3</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">2</td>
<td class="x4" align="right">2</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">8</td>
<td class="x4" align="right">6</td>
<td class="x6" align="right">8</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x5" align="right">3</td>
<td class="x4" align="right">2</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">18</td>
<td class="x4" align="right">9</td>
<td class="x4" align="right">3</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">0</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">9</td>
<td class="x5" align="right">9</td>
<td class="x6" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">3</td>
<td class="x7" align="right">3</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">19</td>
<td class="x4" align="right">9</td>
<td class="x4" align="right">2</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">1</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">10</td>
<td class="x5" align="right">9</td>
<td class="x6" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">2</td>
<td class="x7" align="right">2</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x3" style="height:15.0pt;border-top:none" align="right" height="20">20</td>
<td class="x4" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">2</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">11</td>
<td class="x5" align="right">9</td>
<td class="x6" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">1</td>
<td class="x7" align="right">1</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">21</td>
<td class="x9" align="right">9</td>
<td class="x9" align="right">0</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">0</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">9</td>
<td class="x4" align="right">9</td>
<td class="x6" align="right">9</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">3</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x8" style="height:15.0pt;border-top:none" align="right" height="20">22</td>
<td class="x9" align="right">10</td>
<td class="x9" align="right">0</td>
<td class="x18" style="">&nbsp;</td>
<td class="x10">1</td>
<td class="x4" align="right">3</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">10</td>
<td class="x4" align="right">9</td>
<td class="x6" align="right">10</td>
<td class="x4" align="right">1</td>
<td class="x4" align="right">0</td>
<td class="x5" align="right">0</td>
<td class="x4" align="right">2</td>
<td class="x7" align="right">0</td>
</tr>
<tr style="height:15.0pt" height="20">
<td class="x11" style="height:15.0pt;border-top:none" align="right" height="20">23</td>
<td class="x12" align="right">11</td>
<td class="x12" align="right">0</td>
<td class="x18" style="">&nbsp;</td>
<td class="x13">2</td>
<td class="x14" align="right">3</td>
<td class="x14" align="right">1</td>
<td class="x14" align="right">0</td>
<td class="x15" align="right">11</td>
<td class="x14" align="right">9</td>
<td class="x16" align="right">11</td>
<td class="x14" align="right">1</td>
<td class="x14" align="right">0</td>
<td class="x15" align="right">0</td>
<td class="x14" align="right">1</td>
<td class="x17" align="right">0</td>
</tr>
</tr>
</tbody></table>


问:
Magic number of a given length
Your program must take an input (n for the purpose of description) and output all permutations of a number that is n digits long with no repeating digits, where each of the digits preceding and including its index are divisible by the place in the number that it falls.

You can read about magic numbers here.

Rules:

1 <= n <= 10

No digits may be repeated

The leading 0 must be present (if applicable)

The 1st through xth digit of the number (starting with the first character as 1) must be divisible by x, i.e. in 30685, 3 is divisible by 1, 30 is divisible by 2, 306 is divisible by 3, 3068 is divisible by 4, and 30685 is divislbe by 5.

The program must take an integer as input (through the command line, as a function argument, etc.) and print all permutations that satisfy the rules.

Output must be separated by 1 or more white space character

Permutations may start and with zero (so they're not technically magic numbers).

The order of output does not matter

You do not need to handle unexpected input

Least characters in bytes wins

Examples

Given 1:

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

Given 2:

```<code>02
04
06
08
10
12
14
16
18
20
24
26
28
30
32
34
36
38
40
42
46
48
50
52
54
56
58
60
62
64
68
70
72
74
76
78
80
82
84
86
90
92
94
96
98
</code>```

Given 10:

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

Credit to Pizza Hut & John H. Conway for the original puzzle (Option A).
Thanks to @Mego and @sp3000 for their links.

答:
MATL, 30 bytes

```<code>4Y2Z^!"@Sd@!U10G:q^/kPG:\~h?@!
</code>```

Try it online!

It's very slow. For input 3 it takes a few seconds in the online compiler. To see the numbers appearing one by one, include a D at the end of the code.

Explanation

```<code>4Y2       % predefined literal: string '0123456789'
Z^        % implicit input. Cartesian power: 2D char array. Each number is a row
!         % transpose
"         % for each column
  @       %   push current column
  Sd      %   sort and compute consecutive differences (*)
  @!U     %   push current column. Convert to number
  10G:q^  %   array [1 10 100 ... 10^(n-1)], where n is the input
  /k      %   divide element-wise. Round down
  P       %   reverse array
  G:      %   array [1 2 ... n]
  \~      %   modulo operation, element-wise. Negate: gives 1 if divisible (**)
  h       %   concatenate (*) and (**). Truthy if all elements are nonzero
  ?       %   if so
    @!    %     current number as a row array of char (string)
          %   implicitly end if
          % implicitly end if
          % implicitly display stack contents
</code>```

ContentLicense: CC BY-SA 3.0

Title: Magic number of a given length

Body:
MATL, 30 bytes

4Y2Z^!"@Sd@!U10G:q^/kPG:\~h?@!

Try it online!

It's very slow. For input 3 it takes a few seconds in the online compiler. To see the numbers appearing one by one, include a D at the end of the code.

Explanation

4Y2       % predefined literal: string '0123456789'
Z^        % implicit input. Cartesian power: 2D char array. Each number is a row
!         % transpose
"         % for each column
  @       %   push current column
  Sd      %   sort and compute consecutive differences (*)
  @!U     %   push current column. Convert to number
  10G:q^  %   array [1 10 100 ... 10^(n-1)], where n is the input
  /k      %   divide element-wise. Round down
  P       %   reverse array
  G:      %   array [1 2 ... n]
  \~      %   modulo operation, element-wise. Negate: gives 1 if divisible (**)
  h       %   concatenate (*) and (**). Truthy if all elements are nonzero
  ?       %   if so
    @!    %     current number as a row array of char (string)
          %   implicitly end if
          % implicitly end if
          % implicitly display stack contents


答:
Pyth, 19 bytes

```<code>jf!s%VsM._TS;.PjkUT
</code>```

Demonstration

A brute force solution. Explanation to follow. Inspiration thanks to FryAmTheEggman

22 bytes

```<code>juf!%sThH{I#sm+LdTGQ]k
</code>```

Demonstration

Numbers are built and stored as strings, and only converted to ints to check divisibility.

Explanation:

```<code>juf!%sThH{I#sm+LdTGQ]k
 u                 Q]k    Apply the following input many times, starting with ['']
             m    G       For each string at the previous step,
              +LdT        Append each digit to it
            s             Concatenate
         {I#              Filter out strings with repeats
  f                       Filter on
     sT                   The integer
    %  hH                 Mod the 1 indexed iteration number
   !                      Is zero.
j                         Join on newlines.
</code>```

Title: Magic number of a given length

Body:
Your program must take an input (n for the purpose of description) and output all permutations of a number that is n digits long with no repeating digits, where each of the digits preceding and including its index are divisible by the place in the number that it falls.

You can read about magic numbers here.

Rules:

1 <= n <= 10

No digits may be repeated

The leading 0 must be present (if applicable)

The 1st through xth digit of the number (starting with the first character as 1) must be divisible by x, i.e. in 30685, 3 is divisible by 1, 30 is divisible by 2, 306 is divisible by 3, 3068 is divisible by 4, and 30685 is divislbe by 5.

The program must take an integer as input (through the command line, as a function argument, etc.) and print all permutations that satisfy the rules.

Output must be separated by 1 or more white space character

Permutations may start and with zero (so they're not technically magic numbers).

The order of output does not matter

You do not need to handle unexpected input

Least characters in bytes wins

Examples

Given 1:

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

Given 2:

```<code>02
04
06
08
10
12
14
16
18
20
24
26
28
30
32
34
36
38
40
42
46
48
50
52
54
56
58
60
62
64
68
70
72
74
76
78
80
82
84
86
90
92
94
96
98
</code>```

Given 10:

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

Credit to Pizza Hut & John H. Conway for the original puzzle (Option A).
Thanks to @Mego and @sp3000 for their links.

Body:
Pyth, 19 bytes

jf!s%VsM._TS;.PjkUT

Demonstration

A brute force solution. Explanation to follow. Inspiration thanks to FryAmTheEggman

22 bytes

juf!%sThH{I#sm+LdTGQ]k

Demonstration

Numbers are built and stored as strings, and only converted to ints to check divisibility.

Explanation:

juf!%sThH{I#sm+LdTGQ]k
 u                 Q]k    Apply the following input many times, starting with ['']
             m    G       For each string at the previous step,
              +LdT        Append each digit to it
            s             Concatenate
         {I#              Filter out strings with repeats
  f                       Filter on
     sT                   The integer
    %  hH                 Mod the 1 indexed iteration number
   !                      Is zero.
j                         Join on newlines.


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

答:
Pyth, <s>48</s> <s>45</s> <s>44</s> <s>43</s> 42 bytes

```<code>=Y0juXGZX@G~+Z-!J%/HtQ4q2J~+Y%J2@zHlzm*;lz
</code>```

Try it online.

This approach does the same trailing whitespace abuse as the Ruby answer.

Title: Snakify a String

Body:
Pyth, <s>48</s> <s>45</s> <s>44</s> <s>43</s> 42 bytes

=Y0juXGZX@G~+Z-!J%/HtQ4q2J~+Y%J2@zHlzm*;lz

Try it online.

This approach does the same trailing whitespace abuse as the Ruby answer.


问:
Finish a symmetrical map
You are given one-quarter of a map that is symmetrical over the x- and y-axes as input. The program should print the complete map.

The map can contain the following characters: -+/\|., and they should be turned as expected. The in data is always rectangular and small.

Example

```<code>$ cat in
+---
|./.
|/..

$ ./solution < in
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+
</code>```

Shortest code wins.

ContentLicense: CC BY-SA 2.5

Title: Finish a symmetrical map

Body:
Ruby - 88 87 chars

t=->s{s.tr'/\\\\','\\\\/'}
puts a=$<.map{|l|l.chop!+t[l.reverse]}
puts a.reverse.map &t

Test Run

D:\tmp>ruby cg_sym_map.rb < sym_map.in.
+------+
|./..\.|
|/....\|
|\..../|
|.\../.|
+------+


问:
Cat goes "Meow"

cat goes  "Meow"

We are all familiar with the concept of a cat program. The user types something in, it is echoed back to the user. Easy. But all cat programs I've seen so far have missed one fact: a cat goes "Meow". So your task is to write a program that copies all STDIN to STDOUT UNLESS the input is cat, in which case your program should output cat goes "Meow".

Scoring

This is code-golf, so your score is your byte count, with a few modifiers:

If your program works for any additional animals other than cat (e.g. cow: cow goes "Moo"), for each additional animal: -10

If your program doesn't use the word "cat": -15

If your program responds to fox with "What does the fox say": -25

Animals and sounds that go together:

cow goes moo
duck goes quack
sheep goes baa
bees go buzz
frogs go croak

Anything else on this list is allowed.

Rules

Standard loopholes apply

You must not write anything to STDERR

You can use single quotes/no quotes instead of double quotes.

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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

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

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

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

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

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

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

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

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Pylongolf2, 33-15=18 bytes

```<code>"tac"╨1cd_@0=b?" goes Meow"¿~
</code>```

Explanations:

```<code>"tac"╨1cd_@0=b?" goes Meow"¿~
"tac"                         push "tac" to stack
     ╨1                       reverse it
       cd                     read input and then select latest item in stack
         _                    duplicate input
          @0                  select first item in stack
            =b                compare then swap places
              ?               if true,
               " goes Meow"¿  push " goes Meow" to stack and end if statement
                            ~ print it.
</code>```

Title: Cat goes "Meow"

Body:
Pylongolf2, 33-15=18 bytes

"tac"╨1cd_@0=b?" goes Meow"¿~

Explanations:

"tac"╨1cd_@0=b?" goes Meow"¿~
"tac"                         push "tac" to stack
     ╨1                       reverse it
       cd                     read input and then select latest item in stack
         _                    duplicate input
          @0                  select first item in stack
            =b                compare then swap places
              ?               if true,
               " goes Meow"¿  push " goes Meow" to stack and end if statement
                            ~ print it.


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

答:
sed, 39 36 bytes (34 for code, 2 for -r)

```<code>:a
s/\(\)|\[]|<>|\{}//;ta
/./c0
c1
</code>```

Try it online!

sed version of what appears to be the standard approach.  Requires extended regular expressions (sed -r)

Saved 3 bytes thanks to Cows quack

Title: Are the brackets fully matched?

Body:
sed, 39 36 bytes (34 for code, 2 for -r)

:a
s/\(\)|\[]|<>|\{}//;ta
/./c0
c1

Try it online!

sed version of what appears to be the standard approach.  Requires extended regular expressions (sed -r)

Saved 3 bytes thanks to Cows quack

ContentLicense: CC BY-SA 4.0


问:
Showcase of Languages

Notes

This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not create additional showcase questions.

This is no longer a popularity-contest, nor are snippet lengths limited by the vote tally. If you know this thread from before, please make sure you familiarize yourself with the changes.

This thread is dedicated to showing off interesting, useful, obscure, and/or unique features your favorite programming languages have to offer. This is neither a challenge nor a competition, but a collaboration effort to showcase as many programming languages as possible as well as possible.

How this works

All answers should include the name of the programming language at the top of the post, prefixed by a #.

Answers may contain one (and only one) factoid, i.e., a couple of sentences without code that describe the language.

Aside from the factoid, answers should consist of snippets of code, which can (but don't have to be) programs or functions.

The snippets do not need to be related. In fact, snippets that are too related may be redundant.

Since this is not a contest, all programming languages are welcome, whenever they were created.

Answers that contain more than a handful of code snippets should use a Stack Snippet to collapse everything except the factoid and one of the snippets.

Whenever possible, there should be only one answer per programming language. This is a community wiki, so feel free to add snippets to any answer, even if you haven't created it yourself. There is a Stack Snippet for compressing posts, which should mitigate the effect of the 30,000 character limit.

Answers that predate these guidelines should be edited. Please help updating them as needed.

Current answers, sorted alphabetically by language name

$.ajax({type:"GET",url:"https://api.stackexchange.com/2.2/questions/44680/answers?site=codegolf&filter=withbody",success:function(data){for(var i=0;i<data.items.length;i++){var temp=document.createElement('p');temp.innerHTML = data.items[i].body.split("\n")[0];$('#list').append('
' + temp.innerText || temp.textContent + '');}}})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><base href="http://codegolf.stackexchange.com"><ul id="list"></ul></code>```

答:
WireMod Expression 2

Length 1

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

This a comment in E2.

Length 2

```<code>?:
</code>```

E2 supports a the ternary operator. Really useful.

Length 5

```<code>#[ ]#
</code>```

E2's multiline comments are formatted as such

Factoid

Expression 2 is a programming language inside Lua, inside a game.

(Page takes a while to load)

Title: Showcase of Languages

Body:
WireMod Expression 2

Length 1

#

This a comment in E2.

Length 2

?:

E2 supports a the ternary operator. Really useful.

Length 5

#[ ]#

E2's multiline comments are formatted as such

Factoid

Expression 2 is a programming language inside Lua, inside a game.

(Page takes a while to load)


答:
Ruby, 87 bytes

Basic recursive solution.

```<code>f=->n,x="",j=1{j>n ?puts(x):([*?0..?9]-x.chars).map{|i|f[n,x+i,j+1]if((x+i).to_i)%j<1}}
</code>```

If you're allowed to return a list of the permutations instead of printing, 85 bytes:

```<code>f=->n,x="",j=1{j>n ?x:([*?0..?9]-x.chars).map{|i|f[n,x+i,j+1]if((x+i).to_i)%j<1}-[p]}
</code>```

Title: Magic number of a given length

Body:
Ruby, 87 bytes

Basic recursive solution.

f=->n,x="",j=1{j>n ?puts(x):([*?0..?9]-x.chars).map{|i|f[n,x+i,j+1]if((x+i).to_i)%j<1}}

If you're allowed to return a list of the permutations instead of printing, 85 bytes:

f=->n,x="",j=1{j>n ?x:([*?0..?9]-x.chars).map{|i|f[n,x+i,j+1]if((x+i).to_i)%j<1}-[p]}


问:
Golf the xᵗʰ root of x
While bored in high-school (when I was half my current age...), I found that \$f(x) = x^{x^{-1}}\$ had some interesting properties, including e.g. that the maximum \$f\$ for \$0 ≤ x\$ is \$f(e)\$, and that the binding energy per nucleon of an isotope can be approximated as \$6 × f(x ÷ 21)\$...

Anyway, write the shortest function or program that calculates the xth root of x for any number in your language's domain.

Examples cases

For all languages

```<code>     -1   >       -1
   ¯0.2   >    -3125
   ¯0.5   >        4
    0.5   >     0.25
      1   >        1
      2   >    1.414
      e   >    1.444
      3   >    1.442
    100   >    1.047
  10000   >    1.001
</code>```

For languages that handle complex numbers

```<code>   -2   >        -0.7071i
    i   >            4.81
   2i   >    2.063-0.745i
 1+2i   >   1.820-0.1834i
 2+2i   >   1.575-0.1003i
</code>```

For languages that handle infinities

```<code>-1/∞   >   0    (or ∞ or ̃∞)
   0   >   0    (or 1 or ∞)
 1/∞   >   0
   ∞   >   1
  -∞   >   1
</code>```

For languages that handle both infinities and complex numbers

```<code> -∞-2i   >   1      (or ̃∞)
</code>```

 ̃∞ denotes directed infinity.

答:
dc, <s>8</s> 6 chars

Outputs to the top of the stack:

```<code>?d1r/^
</code>```

Or if I can expect the input at the top of the stack, this 5 char solution works too:

```<code>d1r/^
</code>```

Explanation:

```<code>?        take input from STDIN and execute it (numbers are executed by pushing to the stack)
 d1r     duplicate top of stack, push 1 and swap them
    /^   divide and exponentiate
</code>```

Alas, dc does not allow for fractional exponents so this answer does not actually work for any given inputs above 1, and gives the wrong answer for 0 < input < 1. It does the same thing as many of the other programs though.

Title: Golf the xᵗʰ root of x

Body:
dc, <s>8</s> 6 chars

Outputs to the top of the stack:

?d1r/^

Or if I can expect the input at the top of the stack, this 5 char solution works too:

d1r/^

Explanation:

?        take input from STDIN and execute it (numbers are executed by pushing to the stack)
 d1r     duplicate top of stack, push 1 and swap them
    /^   divide and exponentiate

Alas, dc does not allow for fractional exponents so this answer does not actually work for any given inputs above 1, and gives the wrong answer for 0 < input < 1. It does the same thing as many of the other programs though.


答:
Lua 5.3.2, 229 - 25 - 15 - 80 (extra animals) = 109 bytes

```<code>r={...}a={['\99\97\116']='Meow',duck='Quack',sheep='Baa',bee='Buzz',frog='Croak',bat='Screech',elk='Bugle',swan='Cry',pig='Oink'}print(r[1]=='fox' and 'What does the fox say' or(a[r[1]] and r[1]..' goes "'..a[r[1]]..'"' or r[1]))
</code>```

Ungolfed

```<code>local Args = {...}
local Sounds = {
    ['\99\97\116'] = 'Meow',
    duck = 'Quack',
    sheep = 'Baa',
    bee = 'Buzz',
    frog = 'Croak',
    bat = 'Screech',
    elk = 'Bugle',
    swan = 'Cry',
    pig = 'Oink'
}
print(
    Args[1] == 'fox' and 'What does the fox say' or (
        Sounds[Args[1]] and Args[1] .. ' goes "' .. Sounds[Args[1]] .. '"' or Args[1]
    )
)
</code>```

I tried to make the logic a little clearer by putting it on multiple lines.

It's essentially a ternary operator ?:

Title: Cat goes "Meow"

Body:
cat goes  "Meow"

We are all familiar with the concept of a cat program. The user types something in, it is echoed back to the user. Easy. But all cat programs I've seen so far have missed one fact: a cat goes "Meow". So your task is to write a program that copies all STDIN to STDOUT UNLESS the input is cat, in which case your program should output cat goes "Meow".

Scoring

This is code-golf, so your score is your byte count, with a few modifiers:

If your program works for any additional animals other than cat (e.g. cow: cow goes "Moo"), for each additional animal: -10

If your program doesn't use the word "cat": -15

If your program responds to fox with "What does the fox say": -25

Animals and sounds that go together:

cow goes moo
duck goes quack
sheep goes baa
bees go buzz
frogs go croak

Anything else on this list is allowed.

Rules

Standard loopholes apply

You must not write anything to STDERR

You can use single quotes/no quotes instead of double quotes.

Leaderboard

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

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

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

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

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

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

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

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

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

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

Body:
Lua 5.3.2, 229 - 25 - 15 - 80 (extra animals) = 109 bytes

r={...}a={['\99\97\116']='Meow',duck='Quack',sheep='Baa',bee='Buzz',frog='Croak',bat='Screech',elk='Bugle',swan='Cry',pig='Oink'}print(r[1]=='fox' and 'What does the fox say' or(a[r[1]] and r[1]..' goes "'..a[r[1]]..'"' or r[1]))

Ungolfed

local Args = {...}
local Sounds = {
    ['\99\97\116'] = 'Meow',
    duck = 'Quack',
    sheep = 'Baa',
    bee = 'Buzz',
    frog = 'Croak',
    bat = 'Screech',
    elk = 'Bugle',
    swan = 'Cry',
    pig = 'Oink'
}
print(
    Args[1] == 'fox' and 'What does the fox say' or (
        Sounds[Args[1]] and Args[1] .. ' goes "' .. Sounds[Args[1]] .. '"' or Args[1]
    )
)

I tried to make the logic a little clearer by putting it on multiple lines.

It's essentially a ternary operator ?:


答:
Jelly, <s>20</s> <s>17</s> 16 bytes

```<code>QḣQV%S
ØDṗçÐḟRj⁷
</code>```

This is very slow and memory intensive... Try it online!

How it works

```<code>ØDṗçÐḟRj⁷  Main link. Input: n (integer)

ØD         Yield d := '0123456789'.
  ṗ        Compute the nth Cartesian power of d.
      R    Range; yield [1, ..., n].
    Ðḟ     Filter false; keep strings of digits for which the following yields 0.
   ç         Apply the helper link to each digit string and the range to the right.
       j⁷  Join the kept strings, separating by linefeeds.

QḣQḌ%S     Helper link. Arguments: s (digit string), r (range from 1 to n)

Q          Unique; deduplicate s.
 ḣ         Head; get the prefixes of length 1, ..., n or less.
           If s had duplicates, the final prefixes fill be equal to each other.
  Q        Unique; deduplicate the array of prefixes.
   V       Eval all prefixes.
    %      Compute the residues of the kth prefixes modulo k.
           If s and the array of prefixes have different lengths (i.e., if the
           digits are not unique), some right arguments of % won't have corr. left
           arguments. In this case, % is not applied, and the unaltered right
           argument is the (positive) result.
     S     Add all residues/indices. This sum is zero iff all digits are unique
           and the kth prefixes are divisible by k.
</code>```

Title: Magic number of a given length

Body:
Jelly, <s>20</s> <s>17</s> 16 bytes

QḣQV%S
ØDṗçÐḟRj⁷

This is very slow and memory intensive... Try it online!

How it works

ØDṗçÐḟRj⁷  Main link. Input: n (integer)

ØD         Yield d := '0123456789'.
  ṗ        Compute the nth Cartesian power of d.
      R    Range; yield [1, ..., n].
    Ðḟ     Filter false; keep strings of digits for which the following yields 0.
   ç         Apply the helper link to each digit string and the range to the right.
       j⁷  Join the kept strings, separating by linefeeds.

QḣQḌ%S     Helper link. Arguments: s (digit string), r (range from 1 to n)

Q          Unique; deduplicate s.
 ḣ         Head; get the prefixes of length 1, ..., n or less.
           If s had duplicates, the final prefixes fill be equal to each other.
  Q        Unique; deduplicate the array of prefixes.
   V       Eval all prefixes.
    %      Compute the residues of the kth prefixes modulo k.
           If s and the array of prefixes have different lengths (i.e., if the
           digits are not unique), some right arguments of % won't have corr. left
           arguments. In this case, % is not applied, and the unaltered right
           argument is the (positive) result.
     S     Add all residues/indices. This sum is zero iff all digits are unique
           and the kth prefixes are divisible by k.


问:
Arithmetic Sequences
An arithmetic sequence is a sequence of numbers of the form a,a+n,a+2n,a+3n, etc. In this case, a and n will both be either integers or decimals.

Given two inputs, a, n, and a top number value, return a list of numbers where the last term is less than or equal to the top number value.

The input can be formatted in any way, as well as the output.

The catch to this problem is dealing with floating point arithmetic errors.

For example, 0.1 + 0.3 * 3 is 1, however this will display 0.99999999999... if you simply go 0.1 + 0.3 * 3. We want 1, not 0.99999999999...

Test Cases

a=2, n=3, top=10: [2, 5, 8]

a=3, n=1.5, top=12: [3, 4.5, 6, 7.5, 9, 10.5, 12]

a=3.14159, n=2.71828, top=10: [3.14159, 5.85987, 8.57815]

a=0.1, n=0.3, top=2: [0.1, 0.4, 0.7, 1, 1.3, 1.6, 1.9]

Shortest code wins. Good luck!

答:
TI-Basic, 20

```<code>Prompt A,N,T:For(I,A,T,N:Disp I:End
</code>```

Title: Arithmetic Sequences

Body:
TI-Basic, 20

Prompt A,N,T:For(I,A,T,N:Disp I:End


问:
Double-duty quine: quine!dlroW ,olleH
Write a program that will output its own source code when run, and nothing else. Seems easy, right?

The catch is that when the source code is reversed, your program must output "Hello, World!" exactly, without the quotes.

This is code-golf, so lowest byte count wins.

Edit: Your quine must be a proper quine.

答:
Fission 2, 42 bytes

Shameless adaptation of a excellent quine by @MartinBüttner in this answer

```<code>'!+O!'!d'!l'!r'!o'!W'! '!,'!o'!!l'!e'!H'R"
</code>```

Try it online

And reversed

```<code>"R'H!'e!'l!!'o!',!' !'W!'o!'r!'l!'d!'!O+!'
</code>```

Try it online

In the quine version the atom starts at the R heading right.  The "starts print mode which wraps to the next " (itself).  This prints everything out except the ".  '!+ set the atom to char ".  O prints it out and destroys the atom ending the program.

The reversed version starts at the R again and for each character in Hello, World set the atom and prints ! it out without destroying the atom.  For the final character ! the print O destroys the atom.

Title: Double-duty quine: quine!dlroW ,olleH

Body:
Fission 2, 42 bytes

Shameless adaptation of a excellent quine by @MartinBüttner in this answer

'!+O!'!d'!l'!r'!o'!W'! '!,'!o'!!l'!e'!H'R"

Try it online

And reversed

"R'H!'e!'l!!'o!',!' !'W!'o!'r!'l!'d!'!O+!'

Try it online

In the quine version the atom starts at the R heading right.  The "starts print mode which wraps to the next " (itself).  This prints everything out except the ".  '!+ set the atom to char ".  O prints it out and destroys the atom ending the program.

The reversed version starts at the R again and for each character in Hello, World set the atom and prints ! it out without destroying the atom.  For the final character ! the print O destroys the atom.


答:
Reng

5-vote

```<code>1¶:+!
</code>```

This uses an intersting feature: default stack pop override! ¶ pops n and sets n to the default value when popping from an empty stack. (This is 0 by default.) What this code does is initially lay down a 1, sets that as a default pop, : duplicates value (getting default pop) and adds it with the default pop, leaving twice the default pop on the stack. ! skips the 1 instruction, and ¶ sets the default pop to twice what it was.

4-vote

```<code>is~o
</code>```

This is a cat program. It takes input (i), s jumps if the byte != -1, and o outputs. When reading EOF for input, -1 is put on the stack, and the program terminates.

3-vote

```<code>9#q
</code>```

This stores the number 9 in the variable q.

2-vote

```<code>{}
</code>```

Reng has codeblocks! This pushes an empty codeblock to the stack. Forever.

1-vote

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

This ends the program.

0-vote

Reng is like ><>, but with some more functionality. Not made for golfing, as you may come to see... ;)

Title: Showcase of Languages

Body:
Notes

This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not create additional showcase questions.

This is no longer a popularity-contest, nor are snippet lengths limited by the vote tally. If you know this thread from before, please make sure you familiarize yourself with the changes.

This thread is dedicated to showing off interesting, useful, obscure, and/or unique features your favorite programming languages have to offer. This is neither a challenge nor a competition, but a collaboration effort to showcase as many programming languages as possible as well as possible.

How this works

All answers should include the name of the programming language at the top of the post, prefixed by a #.

Answers may contain one (and only one) factoid, i.e., a couple of sentences without code that describe the language.

Aside from the factoid, answers should consist of snippets of code, which can (but don't have to be) programs or functions.

The snippets do not need to be related. In fact, snippets that are too related may be redundant.

Since this is not a contest, all programming languages are welcome, whenever they were created.

Answers that contain more than a handful of code snippets should use a Stack Snippet to collapse everything except the factoid and one of the snippets.

Whenever possible, there should be only one answer per programming language. This is a community wiki, so feel free to add snippets to any answer, even if you haven't created it yourself. There is a Stack Snippet for compressing posts, which should mitigate the effect of the 30,000 character limit.

Answers that predate these guidelines should be edited. Please help updating them as needed.

Current answers, sorted alphabetically by language name

$.ajax({type:"GET",url:"https://api.stackexchange.com/2.2/questions/44680/answers?site=codegolf&filter=withbody",success:function(data){for(var i=0;i<data.items.length;i++){var temp=document.createElement('p');temp.innerHTML = data.items[i].body.split("\n")[0];$('#list').append('
' + temp.innerText || temp.textContent + '');}}})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><base href="http://codegolf.stackexchange.com"><ul id="list"></ul></code>```

Body:
Reng

5-vote

1¶:+!

This uses an intersting feature: default stack pop override! ¶ pops n and sets n to the default value when popping from an empty stack. (This is 0 by default.) What this code does is initially lay down a 1, sets that as a default pop, : duplicates value (getting default pop) and adds it with the default pop, leaving twice the default pop on the stack. ! skips the 1 instruction, and ¶ sets the default pop to twice what it was.

4-vote

is~o

This is a cat program. It takes input (i), s jumps if the byte != -1, and o outputs. When reading EOF for input, -1 is put on the stack, and the program terminates.

3-vote

9#q

This stores the number 9 in the variable q.

2-vote

{}

Reng has codeblocks! This pushes an empty codeblock to the stack. Forever.

1-vote

~

This ends the program.

0-vote

Reng is like ><>, but with some more functionality. Not made for golfing, as you may come to see... ;)


问:
A simple TCP server
Write a program or function that listens for incoming TCP traffic on port N. It offers a simple service: it calculates sum of IP address fields of incoming connection and returns.

Program or function reads integer N from arguments or stdin. It listens to incoming TCP connections on port N. When someone connects to that port, the program calculates sum of its IP address fields and sends it back to the client with trailing newline and closes connection.

Port number N is a valid port, and 210 < N < 215

Trailing newline can be either \nor \r\n

You can use either IPv4 or IPv6. Since IPv6 addresses are written in hexadecimal form, you must also provide result in same format, for example 2001:0db8:0000:0042:0000:8a2e:0370:7334 => 12ecd.

This is code-golf. Standard rules and loopholes apply.

Example

You run your server with ./server 1234. The server is now running and waiting for connections on port 1234. Then a client from 127.0.0.1 connects to your server. Your server performs a simple calculation: 127+0+0+1 => 128 and sends the result to the client (with trailing newline): 128\n. Then server closes connection and waits for next client.

Leaderboard

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

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
Haskell, 185 (+ 19 = 204)? bytes

```<code>import Network.Simple.TCP(serve)
import Network.Socket
import Data.List.Split
main=getLine>>=flip(serve"*4")(\(a,b)->()<$(send a$(++"\n")$show$sum.map read.take 4.sepByOneOf":."$show b)
</code>```

Takes port number as one line on stdin; requires network-simple from Cabal.

As usual with Haskell answers that don't constrain themselves to pure functions, the imports take up far too many bytes. The trailing newline is also worth 9 bytes...

Somewhat similar to @Jules's answer, but I use string manipulation instead of byte operations. I <s>stole</s> used the -XOverloadedStrings extension as well, which is probably worth 19 bytes extra.

Title: A simple TCP server

Body:
Haskell, 185 (+ 19 = 204)? bytes

import Network.Simple.TCP(serve)
import Network.Socket
import Data.List.Split
main=getLine>>=flip(serve"*4")(\(a,b)->()<$(send a$(++"\n")$show$sum.map read.take 4.sepByOneOf":."$show b)

Takes port number as one line on stdin; requires network-simple from Cabal.

As usual with Haskell answers that don't constrain themselves to pure functions, the imports take up far too many bytes. The trailing newline is also worth 9 bytes...

Somewhat similar to @Jules's answer, but I use string manipulation instead of byte operations. I <s>stole</s> used the -XOverloadedStrings extension as well, which is probably worth 19 bytes extra.