[Question]
  [
This is the cop's thread. The [robber's thread is here](https://codegolf.stackexchange.com/questions/112300/robbers-crack-the-regex-make-a-snake).
---
Write a code that takes an input `n` and creates a n-by-n "snake matrix".
A snake matrix is a matrix that follows this pattern:
3-by-3:
```
1  2  3
6  5  4
7  8  9
```
and 4-by-4:
```
1   2   3   4
8   7   6   5
9   10  11  12
16  15  14  13
```
The exact output format is optional. You may for instance output `[[1 2 3],[6 5 4],[7 8 9]]`, or something similar.
You must provide the language name, and a regex that fully matches your code. You can choose how detailed your regex should be. In the extreme, you can write a regex that matches every possible string, in which case it will be very easy to crack your code. You must also provide the output for `n=4`, so that robbers know the exact format you have opted for.
You may use one of the regex-flavors that are available on [regex101.com](https://regex101.com/), or the Ruby flavor.
* PCRE (PHP)
* Javascript
* Python
* Golang
* [Ruby](http://rubular.com/)
You must specify which one you are using.
Notes:
* You must support any reasonably large `n`. You may assume it won't overflow the datatype or memory. If the default datatype is 8-bit signed integers, then you can assume `n<=11`, if it's unsigned 8-bit integers, then you can assume `n<=15`.
* The robbers have to match the submission's output format, except leading/trailing spaces and newlines, since that might have been stripped away by the SE formatting.
**Winning criterion:**
The winner will be the uncracked submission with the shortest regex, measured in number of characters.
If your post has remained uncracked for 7 days, then you may post the intended solution and mark your submission as safe.
  
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), [Cracked by mbomb007](https://codegolf.stackexchange.com/a/112307/47066)
Hopefully fun to crack and not too obvious.
**Regex (PCRE):**
```
^\w*[+\-*\/%]*\w*.{0,2}$
```
**Output n=4:**
```
[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]
```
**Original solution**
```
UXFXLNX*+NFR}ˆ
```
[Answer]
# [Python 2](https://docs.python.org/2/), length 62, [cracked](http://codegolf.stackexchange.com/a/112626/12012)
### Regex (PCRE)
```
^while ((?=\S)[1di\W]|an|eval|nput|nt|or|pr){55}s(?1){45}n...$
```
### Sample output
```
   1    2    3    4
   8    7    6    5
   9   10   11   12
  16   15   14   13
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), length 6, [cracked](https://codegolf.stackexchange.com/a/112349/12012)
### Regex (PCRE)
```
^.{9}$
```
### Sample output
```
 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13
```
[Answer]
# R, length 14 [Cracked by plannapus](https://codegolf.stackexchange.com/a/112389/31347)
I hope I got this regex right. What I trying to say is 77 characters excluding `<space>`, `#`, `;` and `[`. I tested it [here](https://regex101.com/)  
**Regex**
```
^[^ #;\[]{77}$
```
**Sample output n= 4**
```
1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13  
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), [Cracked by Value Ink](https://codegolf.stackexchange.com/a/112607/47066)
Lets kick it up a notch :)  
Hopefully a nice puzzle.
**Regex (PCRE)**
```
^\w*..\w*$
```
**Output n=4**
```
[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]
```
[Answer]
# [><>](http://esolangs.org/wiki/Fish), length 49, [Cracked by Aaron](https://codegolf.stackexchange.com/a/112764/44807)
### Regex (Javascript)
```
^.{7}\n.{12}\n\?.{6};[^v^]{27}(\n.{13}:&.{2}){2}$
```
### Sample output (n=4)
```
1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13 
```
Formatting is a bit weird, but checking for number length would have made it a lot longer.
Might have gone a bit overboard on the regex, not sure!
Edit: Also I forgot to mention, I use the initial stack (-v flag) for input, not the usual fish input. Sorry!
### Original Code:
```
<v1*2&:
 >:{:}=?v:1+
?^{r0}v;>&:&[r]{&:&2*+}::&:::&*@+@(
+:}=?v>n" "o&:&{1
0~{oa<^v?)*&::&:}
```
Aaron's is a lot simpler! The complexity of my original code is based around the idea of using `n[r]` every n-th number to flip that segment (row), then printing all numbers at once at the end
[Answer]
# [Ohm](https://github.com/MiningPotatoes/Ohm), [cracked](https://codegolf.stackexchange.com/a/112403/65298)
Also my first Cops and Robbers challenge, so tell me if there are issues with this pattern (especially since this is a fairly unknown language).
### Regex (PCRE)
```
^\S{6}\W{0,3}\w$
```
### Output (n = 4)
```
[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]
```
[Answer]
# PHP, 221 Bytes ([Cracked](https://codegolf.stackexchange.com/a/112405/32353))
I hope it is difficult enough.
## Regex (PCRE): 16 Bytes
```
^[^\s/\#6]{221}$
```
No space, No comments, no use of base64\_decode. Have Fun.
## Output
```
  1  2  3  4
  8  7  6  5
  9 10 11 12
 16 15 14 13
```
## Original Code
```
$w=$argv[1];$s="";$r=range(1,$w**2);for($i=0;$i<$w;$i++)if($i%2)array_splice($r,$i*$w,$w,array_reverse(array_slice($r,$i*$w,$w)));foreach(($r)as$v)$s.=str_pad($v,$l=strlen(max($r))+1,"\x20",0);echo(chunk_split($s,$l*$w));
```
[Answer]
# C# net46 [(Cracked)](https://codegolf.stackexchange.com/a/112636/32353 "(Cracked)")
(<http://ideone.com/> works)
## Regex PCRE flavor length 58 tested at regex101
```
^sta((?![\d%bh\/]|==|if|(\[.*){4}|(i.*){6}).){142}urn....$
```
Only the method is regexed.
Method returns a 2d int[,] array (int[4,4]) for an input n=4. If printed looks like this:
```
1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13 
```
This is my first entry into anything like this, let me know if I did anything wrong. Not trying to win by regex length for sure, I'm just interested to see how well I did at preventing cracking :)
Original code:
```
static int[,]g(int n){int l,j,k=n-n,c,s;var _=new int[n,n];var d=n!=n;c=k;c++;s=k;for(l=k;l<n;l++){for(j=k;j<n;j++){_[l,d?n-j-c:j]=++s;}d=!d;}return _;}
```
[Answer]
# QBasic, regex length 10 ([cracked](https://codegolf.stackexchange.com/a/112653/32353))
### Regex
Should work in any regex flavor, but we'll call it Python flavor.
```
([A-Z]+.)+
```
**NOTE:** My solution uses unformatted QBasic; after formatting, the code doesn't match the regex due to added spaces. (But I *can* tell you that that's the only change that makes a difference. `([A-Z]+ ?. ?)+` still works on the formatted version.)
For testing purposes, I used [QB64](http://qb64.net) with code formatting turned off (under Options > Code layout). If you don't want to download something, you can also run QBasic online at [archive.org](https://archive.org/details/msdos_qbasic_megapack) (but there you can't turn formatting off).
### Sample output
```
 1  2  3  4 
 8  7  6  5 
 9  10  11  12 
 16  15  14  13 
```
[Answer]
# Python 3, 55 bytes [(Cracked)](https://codegolf.stackexchange.com/a/112677/32353)
PCRE / Python / Golang flavor.
```
def [triangles=(1,SNAKE)]{27}:print[]SNAKE(--:>or[]{48}
```
*(Be reminded that [Full match is required](https://codegolf.stackexchange.com/a/112472/32353). Assume `^` and `$` when testing.)*
Sample output:
```
[1, 2, 3, 4]
[8, 7, 6, 5]
[9, 10, 11, 12]
[16, 15, 14, 13]
```
---
Original solution:
```
def r(N,S=1,A=1,K=range,E=list):print(E(K(S,S+N))[::A])or(S+N>N*N)or(r(N,S+N,-A,K,E))
```
Should have trimmed 4 bytes :p
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), Regex length 12   [Cracked by seshoumara!](https://codegolf.stackexchange.com/a/112512/59825)
```
^[^# !]{59}$
```
This regular expression is simple enough that I don't think the flavor of regex matters -- it should work across the board. (Note the space after the # in the regex.)
I've tested all four flavors at regex101.com (PCRE/PHP, Javascript, Python, and Golang), as well as the Ruby version at rubular.com. The dc program matches the regex in all five regex versions.
---
The dc program takes its input on stdin and puts its output on stdout.
Sample output for input 4 (there's a trailing space at the end of each line):
```
1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13 
```
---
# Original code (added after being cracked)
This has been [cracked by @seshoumara](https://codegolf.stackexchange.com/a/112512/59825). Here's my intended code:
```
?sd[AP]s+0[dddld/2%rld%2*1+ldr-*+1+n2CP1+dld%0=+dvld>l]dslx
```
Explanation:
```
?sd      Input number and store it in register d.
[AP]s+   Macro that prints a newline. The macro is stored in register '+'.
0        Push 0 on the stack, initializing a loop.  (The top of the stack is the index variable.  It will go up to d^2-1.)
[        Start a macro definition.  (The macro will be stored in register l.)
ddd      Push 3 copies of the loop index variable on the stack, so they'll be available later. I'll call this number i.
ld/      Divide the last copy of i by d (integer division); this computes the row of the square that we're in (starting with row 0).
2%       Replace the row number with 0 if the row number is even, with 1 if the row number is odd.
r        Swap the top two items on the stack, so the top item is now the next to last copy of i, and the second item on the stack is the row number mod 2.
ld%      Compute i mod d; this goes from 0 to d-1. It is the column in the square that the next number will be placed in.  (The leftmost column is column 0.)
2*1+     Top of the stack is replaced with 2*(column number)+1.
ldr      Inserts d as the second item on the stack.
-        Computes d-2*(column number)-1.
*        The second item on the stack is the row number mod 2, so multiplying yields 0 if the row number is even, and d-2*(column number)-1 if the row number is odd.
+        Add to the remaining copy of i. The sum is i itself in even-numbered rows, and it's i+d-2*(column number)-1 in odd-numbered rows.
```
The sum at the top of the stack now is the next number we want to print:
* It's easy to see that that's correct if the row number is even, since then the sum is just i.
* For odd-numbered rows, notice that i = d\*(i/d)+(i%d) = d \* (row number) + column number. It follows that the sum i+d-2\*(column number)-1 is d \* (row number) + column number + d - 2\*(column number)- 1 = d \* (row number + 1) - column number - 1, which is the number we want to put in the indicated row and column to ensure that we're counting backwards in the odd-numbered rows.
Returning to the explanation now:
```
n        Print the desired number for the current row and column.
2CP      Print a space.  (2C, which is computed by dc as 20 + 12, is 32, the ASCII code for a space.)
1+       The original copy of i is at the top of the stack; add 1 to it.
dld%0=+  If (the incremented value of) i is a multiple of d, call the macro at register '+', which prints a newline.
dvld>l   If d > sqrt(i) (in other words, if i < d^2), then go back to the top of the loop by calling macro l again.
]dslx    End the macro definition, store the macro in register l, and execute it.
```
[Answer]
# Bash, regex length 38, cracked ([@kennytm](https://codegolf.stackexchange.com/a/112656/32353 "@kennytm"))
```
^sort -n <[1adegnopqrstx$\-*()|'; ]+$
```
Input:
```
n=4; <command>
```
Output:
```
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
```
[Answer]
# PHP
I hope this will be a fun one! :D
### Output (n=4)
```
[[1,2,3,4],[8,7,6,5],[9,10,11,12],[16,15,14,13]]
```
---
### Level 1: PCRE (length=17) ([Cracked by Jörg Hülsermann](https://codegolf.stackexchange.com/questions/112300/robbers-crack-the-regex-make-a-snake/112639#112639))
```
^<[^'"\d{vV;<$]+$
```
* No single or double quotes so... no strings!
* No digits!
* No `{` so... no anonymous functions!
* No `v` so... no `eval()`!
* No `;` so... it must be a single statement!
* No `<` so... no `Heredoc` nor multiple PHP blocks!
* The big one! No **$** so... good luck defining variables! >:D
---
[@JörgHülsermann](https://codegolf.stackexchange.com/questions/112300/robbers-crack-the-regex-make-a-snake/112639#112639) had an interesting approach, but it's not what I had in mind :). Therefore, I'm introducing a new level of difficulty (I promise I have the code that fits this and I'm not just messing with you):
### Level 2: PCRE (length=23) ([Cracked by Jörg Hülsermann](https://regex101.com/r/XtVl9G/1))
```
^<[^'"\d{v;<$_~|&A-Z]+$
```
* All the restrictions of **Level 1**
* New on this level: none of these `_~|&A-Z`! :)
---
Have fun!
---
### THE ORIGINAL SOLUTION
So, forbidding the `$` meant the variables couldn't be accessed the regular way, but that doesn't mean they can't be used at all! You can still use `extract()/compact()` to import/export variables into the current scope. :)
```
$i = 1;
// can be written as
extract(['i' => 1])
echo $i;
// can be written as
echo compact('i')['i'];
```
However, there's a gotcha: `compact('x')['x']++` wouldn't work because variables in PHP are passed by value... with one exception! Objects.
```
$x = (object) ['i' => 1];
// is
extract(['x' => (object) ['i' => 1]]);
// and
compact('x')['x']->i++;
// works just fine!
```
The rest is easy.
* Numbers `0` and `1` are easily generated by converting `false` and `true` to `int` by prepending them with the `+` sign
* Use `and` and `or` since `&` and `|` are forbidden
* To work around the forbidden quotes, just use undefined constants, which are treated as strings
* To suppress the notices generated by using undefined constants, just use `@`
* The forbidden letter `v` can be generated by using `chr(ord('u') + 1)`, which translates to `@chr(ord(u) + true)` using the above workarounds
* The underscore is similar to the above: `chr(ord('a') - 2)` which translates to `chr(ord(a) - true - true)`
* Calling functions which contain forbidden characters can be done by taking advantage of PHP's `callable` type, which can be a string containing the name of the function. So, you can concatenate undefined constants and single character strings generated by `ord()` to build the name of the function and invoke it like this: `array_reverse()` becomes `(a.rray.chr(ord(a)-true-true).re.chr(ord(u)+true).erse)()` (`array` is a language construct, that's why it's split into the undefined constants `a` and `rray`)
* Take advantage of the fact that, when it comes to conditional and loop constructs, the curly brackets are optional if the construct applies just to the immediately following statement. This means you can do stuff like:
`if ($n = $argv[1] and $i = 0) while ($n > $i++ and do_some and other_stuff or exit)`
The logic in human readable code would be:
```
if (
    $x = (object) [
        'result' => [],
        'i' => 0
    ]
    and
    define('n', $argv[1])
    and
    define('un', '_')
    and
    // create the initial set which we'll loop through
    define('segments', array_chunk(range(1, pow(n, 2)), n))
) while (
    // store each odd segment as-is and increment the "pointer"
    ($x->result[] = @segments[$x->i++])
    and
    // store each even segment reversed and increment the "pointer"
    ($x->result[] = @array_reverse(segments[$x->i++]))
    and
    // check if we need to break out of the loop
    n > $x->i
    or
    // exit and output the result if the above is false
    die(json_encode(
        // if n is odd, the above would have copied a NULL entry 
        // from the segments, so it needs to be filtered out
        array_filter($x->result)
    ))
)
```
And the unfriendly version that matches the regex:
`<?php if (@extract([x=>(object)[s=>[],i=>+false]])and@define(n,compact(arg.chr(ord(u)+true))[arg.chr(ord(u)+true)][+true]?:+true)and@define(un,chr(ord(a)-true-true))and@define(s,(a.rray.un.chunk)(range(+true,pow(n,true+true)),n)))while((@compact(x)[x]->s[]=s[@compact(x)[x]->i++])and(@compact(x)[x]->s[]=(a.rray.un.re.chr(ord(u)+true).erse)(s[@compact(x)[x]->i++]))and(n>@compact(x)[x]->i)or(@die((json.un.encode)((a.rray.un.filter)(@compact(x)[x]->s)))))?>`
[Answer]
# Ruby [[cracked]](https://codegolf.stackexchange.com/a/112640/32353)
First Cops and Robbers challenge. Hope I didn't make this too easy.
EDIT: replaced `\g<1>` with `(?1)` because they're evidently equivalent in PCRE.
### Regex(PCRE)
```
^(\W?\W\w){4}..(?1){2}[(-=Z-~]*(?1){5}\w*(?1)(.)\2$
```
### Output (n=4)
```
[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13]]
```
(Returns an array of arrays. It's a lambda, BTW, but maybe that gives away too much?)
[Answer]
# JavaScript [(Cracked)](https://codegolf.stackexchange.com/a/112313/64424)
First time doing a Cops and Robbers challenge, hopefully doing it right.
### Regex (JavaScript)
```
^.*(\.\w+\(.*\)){4}$
```
### Output
An array equal to:
```
[[1,2,3,4],[8,7,6,5],[9,10,11,12],[16,15,14,13]]
```
[Answer]
# Swift, regex 25 [(Cracked)](https://codegolf.stackexchange.com/a/112401/15394)
Right, let's see if I've got the hang of this. This is my first cops and robbers post, so lemme know if I've messed up!
## Regex
*I used javascript flavour on regex101.com*
```
^.{21}print[^/]{49}o.{7}$
```
## Sample Output
```
[1, 2, 3, 4]
[8, 7, 6, 5]
[9, 10, 11, 12]
[16, 15, 14, 13]
```
## Original Code
```
(0..<n).forEach{i in print((0..<n).map{i%2>0 ?(i+1)*n-$0 :i*n+$0+1},separator:",")}
```
[Answer]
# C – regex of 42 characters in length – [cracked](https://codegolf.stackexchange.com/a/112447/15259)
Javascript regex as used in [regex101](https://regex101.com).
```
^[-h<=*c+m?{printf("\/a: %d\\',o);}]{137}$
```
Guessing this will be trivial...
```
> main 4
1   2   3   4
8   7   6   5
9   10  11  12
16  15  14  13
>
```
Output is tab-delimited with `\n` after each line.
My solution, here integers 0 - 2 were obtained via `t-t`, `t/t`, and `t`:
```
main(int t,char**a){int o=t-t,i=t/t,m,n,h=atoi(*(a+i));for(m=o;m<h;m++)for(n=o;n<h;n++)printf("%d%c",m*h+(m%t?h-n:n+i),n<h-i?'\t':'\n');}
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), length 14 [cracked](https://codegolf.stackexchange.com/a/112500/12012)
cracked by Dennis
```
[^/P-`mvḊ-ṫ€]*
```
Python regex.
Added `m` back in again after I let it slip.
`/` (reduce quick);  
from `P` (product) to ``` (monad from dyad quick);  
`m` (modulo indexing);  
`v` (eval dyad);  
from `Ḋ` (dequeue) to `ṫ` (tail); and  
`€` (for each quick)
For an input of `4` mine outputs:
```
 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13
```
...because I formatted a list of lists as a grid with `G`.
[Answer]
# Powershell, 23 Bytes
[Cracked By Matt](https://codegolf.stackexchange.com/a/112598/59735)
```
^.+?%.{42}%.{11}:.{35}$
```
Original Solution:
```
$n="$args";$script:r=0;$a=1..$n|%{$t=++$script:r..($script:r+=$n-1);if(!($_%2)){[Array]::Reverse($t)};,$t};$a|%{$_-join" "}
```
Takes input as argument and outputs to stdout
Hopefully this regex is OK, I don't expect this being too difficult to crack, as I haven't obfuscated much of it, and the regex gives a good few starting points to fill in the gaps, there's one thing in the first segment which is very uncommon in code golf though, which may catch someone out, I think a non-greedy match is required there to make this a bit tougher.
First cops challenge anyway.
```
1..4 | % { "----$_----" ; .\snake-cops.ps1 $_  }
----1----
1
----2----
1 2
4 3
----3----
1 2 3
6 5 4
7 8 9
----4----
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
```
[Answer]
# [Röda 0.12](https://github.com/fergusq/roda/tree/roda-0.12), length 19 [(Cracked by @KritixiLithos)](https://codegolf.stackexchange.com/a/112631/66323)
PCRE:
```
^{(\|[^\/#\s]*){8}$
```
Sample output (n=4):
```
[1, 2, 3, 4][8, 7, 6, 5][9, 10, 11, 12][16, 15, 14, 13]
```
Original code:
```
{|n|seq(0,n-1+n%2)|push([{|i|seq(n*i+1,n*i+n)}(_)],[{|j|seq(n*j+n,n*j+1,step=-1)}(_)])|head(n)}
```
[Try it online!](https://tio.run/nexus/roda#y03MzKtOs435X12TV1OcWqhhoJOna6idp2qkWVNQWpyhEV1dkwmWyNPK1DbUAZF5mrUa8ZqxOkCpLKhUlnaeDog01CkuSS2w1TWEKNGsyUhNTNEAavifpmBS@x8A "Röda – TIO Nexus")
[Answer]
# PHP 7 (Safe)
## Original Code
```
for($z=0,$q="";$z<($x=$argv[1])**2;){$w=($d=intdiv($z,$x))%2?($d+1)*$x-$z%$x:($z+1);for($f=0;$f<(log10($x**2)^0)-(log10($w)^0);$f++)$q.="\x20";$q.=++$z%$x?"$w\x20":"$w\n";}print(rtrim($q));
```
Second Try
## Regex (PCRE): 29 Bytes
```
^[^A-Z#\/\s\>busy_heck]{189}$
```
No space, No comments, no use of base64\_decode. 
Many functions are not allowed! underscore
## Output n=11
```
  1   2   3   4   5   6   7   8   9  10  11
 22  21  20  19  18  17  16  15  14  13  12
 23  24  25  26  27  28  29  30  31  32  33
 44  43  42  41  40  39  38  37  36  35  34
 45  46  47  48  49  50  51  52  53  54  55
 66  65  64  63  62  61  60  59  58  57  56
 67  68  69  70  71  72  73  74  75  76  77
 88  87  86  85  84  83  82  81  80  79  78
 89  90  91  92  93  94  95  96  97  98  99
110 109 108 107 106 105 104 103 102 101 100
111 112 113 114 115 116 117 118 119 120 121
```
## Output n=4
```
 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13
```
## Output n=3
```
1 2 3
6 5 4
7 8 9
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), length 12 (safe)
## Regex
Uses Python flavour:
```
(\w{3}\W){5}
```
## Example output
For `n=4`:
```
 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13
```
---
### Solution
```
txU:GeG:oEq*S5M*TTx!
```
To see how this works, consider input `n=4`.
```
tx   % Implicit input n, duplicate, delete. So this does nothing
     % STACK: 4
U    % Square
     % STACK: 16
:    % Range
     % STACK: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16]
Ge   % Reshape as an n-row array in column major order
     % STACK: [1  5  9 13;
               2  6 10 14;
               3  7 11 15;
               4  8 12 16]
G:   % Push range [1 2 ... n]
     % STACK: [1  5  9 13;
               2  6 10 14;
               3  7 11 15;
               4  8 12 16]
               [1 2 3 4]
o    % Modulo 2
     % STACK: [1  5  9 13;
               2  6 10 14;
               3  7 11 15;
               4  8 12 16]
              [1  0  1  0]
Eq   % Times 2, minus 1 (element-wise)
     % STACK: [1  5  9 13;
               2  6 10 14;
               3  7 11 15;
               4  8 12 16]
              [1 -1  1 -1]
*    % Multiply (element-wise with broadcast)
     % STACK: [1 -5  9 -13;
               2 -6 10 -14
               3 -7 11 -15
               4 -8 12 -16]
S    % Sort each column
     % STACK: [1 -8  9 -16;
               2 -7 10 -15;
               3 -6 11 -14;
               4 -5 12 -13]
5M   % Push [1 -1 1 -1] again
     % STACK: [1 -8  9 -16;
               2 -7 10 -15;
               3 -6 11 -14;
               4 -5 12 -13]
              [1 -1  1  -1]
*    % Multiply (element-wise with broadcast)
     % STACK: [1  8  9  16;
               2  7 10  15;
               3  6 11  14;
               4  5 12  13]
TTx  % Push [true true] and delete it. So this does nothing
!    % Transpose. Implicitly display
     % STACK: [ 1  2  3  4;
                8  7  6  5;
                9 10 11 12;
               16 15 14 13]
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), length 17 (safe)
```
[^/P-`mvÇ-ıḃ-ṫ€]*
```
Python regex.
Tightening the knot, this bans some more useful things, for your aid here are the banned bytes:
```
/PQRSTUVWXYZ[\]^_`mvÇÐÑ×ØÞßæçðñ÷øþĊċĖėĠġİıḃḄḅḊḋḌḍḞḟḢḣḤḥḲḳḶḷṀṁṂṃṄṅṆṇṖṗṘṙṚṛṠṡṢṣṪṫ€
```
*just under a third of them!*
For an input of `4` mine outputs:
```
 1  2  3  4
 8  7  6  5
 9 10 11 12
16 15 14 13
```
...because I formatted a list of lists as a grid with `G`.
### A solution:
```
’:2o1
Ḃ¬aẋ@0
’r0;0ẋ$ẋ1Ŀ¬0¦;2ĿÆ¡œ?⁸²¤s⁸G
```
**[Try it online!](https://tio.run/nexus/jelly#@/@oYaaVUb4h18MdTYfWJD7c1e1gwAUUKzKwNgByVIDY8Mj@Q2sMDi2zNjqy/3DboYVHJ9s/atxxaNOhJcVA2v3///8WAA)** / **[regex101](https://regex101.com/r/ad5STi/1/)**
The main trick here is to index into a lexicographically sorted list of the permutations of the natural numbers up to **n2** (using `œ?` to avoid building the list of length **n2!**), and to split the result into chunks of length **n**. The aforementioned index is found by forming its representation in the [factorial number system](https://en.wikipedia.org/wiki/Factorial_number_system) which is formulaic since the "unsliced" snake is created by permuting elements in a prescribed manner (this may be readily converted to a number with `Æ¡`).
The solution I present uses `Ŀ` to reference previous links as monads (replacing `Ñ` and `Ç`), but multiple `$` in a row could be employed instead to "inline" these helper functions. It also uses `r` since `Ḷ` and `R` are banned.
```
’:2o1 - Link 1, periodic repetitions in the factorial base representation: n
’     - decrement n
 :2   - integer divide by 2
   o1 - or 1 (keep one period in the cases n=1 and n=2)
Ḃ¬aẋ@0 - Link 2, n zeros if n is even, else an empty list: n
Ḃ      - mod 2
 ¬     - not
   ẋ@0 - 0 repeated n times
  a    - and
’r0;0ẋ$ẋ1Ŀ¬0¦;2ĿÆ¡œ?⁸²¤s⁸G - Main link: n                    e.g. 6
’r0                        - inclusive range(n-1, 0)              [5,4,3,2,1,0]
    0ẋ$                    - 0 repeated n times                   [0,0,0,0,0,0]
   ;                       - concatenate (makes one "period")     [5,4,3,2,1,0,0,0,0,0,0,0]
        1Ŀ                 - call link 1 as a monad               2
       ẋ                   - repeat list                          [5,4,3,2,1,0,0,0,0,0,0,0,5,4,3,2,1,0,0,0,0,0,0,0]
           0¦              - apply to index 0 (rightmost index):
          ¬                -     not (make the last 0 a 1)        [5,4,3,2,1,0,0,0,0,0,0,0,5,4,3,2,1,0,0,0,0,0,0,1]
              2Ŀ           - call link 2 as a monad               [0,0,0,0,0,0]
             ;             - concatenate                          [5,4,3,2,1,0,0,0,0,0,0,0,5,4,3,2,1,0,0,0,0,0,0,1,0,0,0,0,0,0]
                Æ¡         - convert from factorial base          45461852049628918679695458739920
                      ¤    - nilad followed by link(s) as a nilad
                    ⁸      -     left argument, n                 6
                     ²     -     square                           36
                  œ?       - lexicographical permutation lookup   [1,2,3,4,5,6,12,11,10,9,8,7,13,14,15,16,17,18,24,23,22,21,20,19,25,26,27,28,29,30,36,35,34,33,32,31]
                       s⁸  - split into chunks of length n        [[1,2,3,4,5,6],[12,11,10,9,8,7],[13,14,15,16,17,18],[24,23,22,21,20,19],[25,26,27,28,29,30],[36,35,34,33,32,31]]
                         G - format as a grid
```
[Answer]
# [Pip](https://github.com/dloscutoff/pip), regex length 3 (safe)
The solution is a full program that takes *n* as a command-line argument. It does not use any command-line flags.
### Regex (any flavor)
```
\w+
```
### Sample output
```
1 2 3 4 
8 7 6 5 
9 10 11 12 
16 15 14 13 
```
---
## My solution
```
YENsXaPBsPOyY_MUyFi_MUENsXaIiBA1PsPUPODQENsXiXaPBsX_PBsMRVyEI1PsPUPODQENsXiXaPBsX_PBsMy
```
[Try it online!](https://tio.run/nexus/pip#@x/p6lcckRjgVBzgXxkZ7xta6ZYJJMGCnplOjoYBxQGhAf4ugSCRTLDCiHgg4RsUVunqiVO28v///yYA)
## Strategy
Here's the code we would *like* to write:
```
Y \,a
F i ,a
 I i%2
  P i*a+_.s M RVy
 E
  P i*a+_.s M y
```
That is:
* Store the numbers 1 through `a` in `y`
* Loop over values of `i` from 0 through `a-1`
* If `i` is odd, reverse y, add `i*a` to each element, concatenate a space to each element, and print
* Otherwise, do the same thing, but without reversing first
### Difficulties
A lot of commands and variables in Pip use letters, but some important ones don't:
* Range and inclusive range (`,` and `\,`)
* Most math operations (`+`, `-`, `*`, `%`, `++`)
* Assignment (`:`)
* We can't have a loop or function body with more than one statement (that would need `{}`)
* We can't use parentheses to enforce precedence
How we get around those limitations:
* `EN`umerate can be used in place of `,`; we just need a string with the number of characters we want, and we need to extract the first element of each sublist in a structure like `[[0 "H"] [1 "i"]]`.
* We don't need to increment anything if we can solve the problem with `F`or loops.
* We can assign to the `y` variable with the `Y`ank operator.
* We can do math with strings: `X` is string multiplication, and `PU`sh (or `PB` "push-back") will concatenate a string to another string in-place. To take the length of a string, we can `EN`umerate it and extract the right number from the resulting list.
* We can use functions as long as they can be written as single-expression lambda functions using `_`.
## Specifics
The building blocks of our program:
### Range
```
_MUENsXa
```
That's `map-unpack(_, enumerate(repeat(space, a)))` in pseudocode. Map-unpack is like Python's `itertools.starmap`: given a list of lists, it calls a function on the items of each sublist. `_` returns its first argument, so `_MU` just gets the first item of each sublist. For example, if a = 3:
```
     sXa  "   "
   EN     [[0 " "] [1 " "] [2 " "]]
_MU       [0 1 2]
```
... which is the same as `,a`.
### Inclusive range
I'm not sure there's a way to do `inclusive-range(1, a)` in a single expression, but fortunately we only need it once, so we can construct it in the `y` variable in three steps.
```
YENsXaPBs
```
In pseudocode, `yank(enumerate(repeat(space, a).push-back(space)))`:
```
   sXa     "   "
      PBs  "    "
 EN        [[0 " "] [1 " "] [2 " "] [3 " "]]
Y          Store that in y
```
Next `POy` pops the first item from `y` and discards it, leaving `[[1 " "] [2 " "] [3 " "]]`.
Finally,
```
Y_MUy
```
That is, `yank(map-unpack(_, y))`: extract the first element of each sublist and yank the resulting list back into `y`. `y` is now `[1 2 3]`.
### Length
```
PODQENaPBs
```
In pseudocode, `pop(dequeue(enumerate(a.push-back(space))))`. The difficulty here is that enumerate only gives us numbers up to `len(a)-1`, but we want `len(a)`. So we first push a space to `a`, lengthening it by one character, and then take `len-1` of the new string.
```
      a     "xyz"
       PBs  "xyz "
    EN      [[0 "x"] [1 "y"] [2 "z"] [3 " "]]
  DQ        [3 " "]
PO          3
```
### Math
Now that we have a way to take the length of strings, we can use strings to do multiplication and addition of numbers:
```
PODQENsXaXbPBs
PODQENsXaPBsXbPBs
```
The first does `sXaXb` to create a string of `a*b` spaces and then takes the length of it; the second does `sXaPBsXb` to push a string of `b` spaces to a string of `a` spaces and then takes the length of it.
The nice part is that all the operators we're using here (`PU`, `PO`, `PB`, `DQ`, `EN`, `X`) can be used with `_` to form lambda expressions. So we can map mathematical transformations to the inclusive range we constructed earlier.
We also need to check `i%2` inside the loop, but this is easily accomplished with bitwise AND: `iBA1`.
### Put them together
The full code, with some added whitespace:
```
YENsXaPBs POy Y_MUy              Get \,a into y
F i _MUENsXa                     For i in ,a
 I iBA1                           If i%2=1
  P sPUPODQENsXiXaPBsX_PBs M RVy   Print sPUi*a+_ M RVy
 EI1                              Elseif 1 (using E would cause a parsing problem)
  P sPUPODQENsXiXaPBsX_PBs M y     Print sPUi*a+_ M y
```
[Answer]
# CJam, PCRE, length 8, [cracked](https://codegolf.stackexchange.com/a/112743/8478)
```
^[a-~]*$
```
Example output for 4:
```
[[1 2 3 4] [8 7 6 5] [9 10 11 12] [16 15 14 13]]
```
[Answer]
# CJam, PCRE, length 9, [cracked](https://codegolf.stackexchange.com/a/112749/8478)
```
^[a-z~]*$
```
Example output for 4:
```
[[1 2 3 4] [8 7 6 5] [9 10 11 12] [16 15 14 13]]
```
Now `{|}` are banned, too.
[Answer]
## Mathematica, regex length 11, [non-competing](https://codegolf.meta.stackexchange.com/q/11726/8478), [cracked](https://codegolf.stackexchange.com/a/112863/8478)
PCRE flavour:
```
^[^]@]{49}$
```
The correct solution will be a function which takes an integer and returns the output as a nested list like:
```
{{1, 2, 3, 4}, {8, 7, 6, 5}, {9, 10, 11, 12}, {16, 15, 14, 13}}
```
[Answer]
# [tinylisp](https://github.com/dloscutoff/Esolangs/tree/master/tinylisp), regex length 3 ([cracked](https://codegolf.stackexchange.com/a/113018/56183))
You can test tinylisp code at [Try it online!](https://tio.run/nexus/tinylisp)
### Regex (any flavor)
```
\S+
```
Time to go hardcore.
### Output
The solution defines a **function** that takes a single integer argument and returns a list like this (for n=4):
```
((1 2 3 4) (8 7 6 5) (9 10 11 12) (16 15 14 13))
```
---
My original code uses the same basic idea Brian McCutchon came up with, building lists and eval'ing them. Here it is in one line:
```
(v(c(h(q(d)))(c(h(q(d')))(c(c(h(q(q)))(c(c()(c(q(arglist))(c(c(h(q(v)))(c(c(h(q(c)))(c(c(h(q(q)))(q(d)))(q(arglist))))()))())))()))()))))(d'(seq-args(c(h(q(start)))(c(h(q(stop)))(c(h(q(step)))())))))(d'(seq(c(c(h(q(accum)))seq-args)(q((i(e(v(h(q(start))))stop)(c(v(h(q(start))))accum)(seq(c(v(h(q(stop))))accum)start(s(v(h(q(stop))))step)step)))))))(d'(f'(c(c(h(q(index)))(c(h(q(size)))seq-args))(q((i(e(v(h(q(index))))size)()(c(seq()start(v(h(q(stop))))step)(f'(a(h(q(1)))index)size(a(v(h(q(stop))))size)(a(v(h(q(start))))size)(s(h(q(0)))step)))))))))(d'(f(q((size)(f'(h(q(0)))size(h(q(1)))size(h(q(1))))))))
```
I used the full construct-and-eval method once, to define a macro `d'` that makes definitions like `d`, but takes its arguments wrapped in a list: so instead of `(d x 42)`, you can do `(d'(x 42))`. Then it was just a matter of rewriting any lists in the definitions that might need whitespace: `(q(a b))` -> `(c a(q(b)))` -> `(c(h(q(a)))(q(b)))`.
[Answer]
# Python3, length 162 [(Cracked!)](https://codegolf.stackexchange.com/a/112462/41754)
Regex: `^([^"' #]){24}"(?1){11}i%n(?1){4}2\*n-(?1){4}i%n(?1){10}i\/n(\)\/\/1)(?1){5}(?2)(?1){3}2\*\(i%n\)(?1){4}[int()2\/]{16}for i in range\(j,(?1){4}\]\)(?1){6}\"\*n\)$`
Okay, I know, it's *quite* long. Fortunately, it won't be cracked in under a week... :'D.
I think I didn't make a mistake anywhere, that would allow loophole-y answers.
## Output format
```
4:
[1, 2, 3, 4]
[8, 7, 6, 5]
[9, 10, 11, 12]
[16, 15, 14, 13]
```
Original code:`n=int(input());j=0;exec("print([int(i%n+1+(2*n-(2*(i%n)+1))*((((i/n)//1+1)/2)//1)+(2*(i%n)+1)*int(int(i/n)/2))for i in range(j,j+n)]);j+=n;"*n)`
]