text:
Robbers: Crack the regex - Make a snake
This is the robber's thread. The cop's thread is here.

A snake matrix is a square 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

Your task is to write a code that takes an input n and creates such a matrix, in the same language as a cop post, and with a code that matches the cop's regex. The output format of your code must match the output format of the cop's code.
Please leave a comment under the Cop's post to indicate that you have cracked it.
Winning criterion:
The winner will be the user that has cracked the most submissions. In case of a tie, then there will be multiple winners.

Jelly, 9 bytes, cracks @Dennis' answer
²sµUFḤ$¦G

Try it online!
Should be correct now; I had to rather rethink what I was doing.
Explanation
The hardest part of this problem is getting a list of the even indices inside the ¦ (which applies an operation at specific indices). Unlike most operations, which use the input to the whole program as a default for the second operand, ¦ uses the most recently seen value as a default (because it conceptually has two left operands, rather than a left and a right operand like most things that take in two values).
However, we can observe that we have a list of numbers, including all integers from 1 to half the input, already in the current value at the time. As such, flattening and doubling it gives us a list of even numbers, including all the even indices (also some other even numbers but we don't care about those). It's even possible to spend one µ solely to avoid a parsing ambiguity and still come in within 9 characters.
²sµUFḤ$¦G
 s         Split
²          {the list of numbers from 1 to} the square of {the input}
  µ        into a number of pieces equal to {the input};
   U       then reverse
       ¦   the elements at indexes
    F      obtained by flattening the split list
      $    and
     Ḥ     doubling each element in the flattened list;
        G  finally, format it into a grid.

Uh, the way ¦ works kills me every time, I tried this yesterday but with Ṛ rather than U and decided the Ḥ was not working out.

Nice, I nearly had it but got stuck at selecting every other element as well. F was a great idea,

My original code is pretty much identical to this. I just used J instead of F.

@Dennis Oh, J... I had tried with LR but couldn't get it under 11 bytes

05AB1E, Emigna
This was my first time using 05AB1E. Got it with a little bit of help. That was fun. :)
UXFXLNX*+N2BSR1k_iR}ˆ

Try it online
Explanation:
U                       Assign input to X
 XF                     For N in range(0,X):
   XL                   Push list [1 .. X]
     NX*+               Add N*X to each element of the list
         N2BSR1k_       Super clever way to get N%2:
                            not bool(reversed(str(bin(N))).index('1')) (N%2 is odd)
                 iR}    if N%2 is odd, then reverse the list
                    ˆ   Add row to global array
                        Implicit print

I actually found this similar program on my own, but the output format is different:
UXFXLNX*+N2BSR1k_iR}=

Try it online
[1, 2, 3, 4]
[8, 7, 6, 5]
[9, 10, 11, 12]
[16, 15, 14, 13]

See the edit history for my previous two attempts.

Nice job! Quite similar to the original solution.

not bool(reversed(str(bin(N))).index('1'))... I think that's the most absurd way I've seen anyone do a N%2 operation.

@StewieGriffin When life gives you lemons but no water or sugar, you just have to eat them raw. :D

Python 2, Dennis
This is a fun token golfing problem.
while ord>eval:1;int,eval=int<1and(int,eval+1)or(-input(),1);i=int;ord=i*i;print'%*s'%(-i,(eval+~i+~-eval%-i*~1,eval)[eval/i&1])+'\nt'[:-1<eval%int],

Regex verification

Ohm, Nick Clifford
My first time attempting Ohm.
Really nice language that I look forward to use again :)
²@┼σ▓_^è?R

Explanation
²             # square input
 @            # range [1 ... input^2]
  ┼σ          # split in input sized chunks
    ▓         # perform the following block on each element of the array
     _        # current element
      ^è?     # if index is odd
         R    # reverse

My first attempt that didn't work as adding an array and an int is not possible:
@┼MDR┼+;W

My second attempt that didn't match the regex:
²@┼σ▓_^MR

You did it exactly how I did! Great job!

05AB1E, Emigna (2nd submission)
First time working with 05AB1E.
VYLUYFYXDˆ+RU

Try it online! | Regex verification
Explanation
VYLUYFYXDˆ+RU  # Implicit input
V              # Save input to Y
 YL            # Push [1 .. Y]
   U           # Save list to X
    YF         # Repeat Y times:
      YX       # Push Y, then X
        Dˆ     # Add X into the global array (could've used X here instead)
          +    # Push X + Y
           R   # Reverse top of stack
            U  # Save updated list to X
               # Implicit loop end
               # Implicit global array print if stack is empty

Nice job! You got the intended solution :)

@Emigna thanks! I wouldn't have gotten it if it weren't for the other solutions on here (yours included) that let me realize that the global array will print if the stack is empty! If it weren't for that I'd never have figured it out; I kept trying to do tricks that ended with ) thinking it'd be the only way to get the correct result on the stack.

Yeah it's pretty impossible to do with ) when you can only use 2 non-alphanumeric characters. The tricky part here was meant to be structuring the program to only use 2 wildcards and have them sequential. Would likely have been a bit harder without the other solutions but there should have been some puzzling involved :)

@Emigna What I want to know is if ^\w*..$ is possible.

@mbomb007: I don't think so. With this tactic you'd need to save the result of the addition for the next iteration and you can't use the stack for this meaning that one of UV need to come after +ˆ. I can't think of another way to do it with only 2 wildcards at the end either. It can be done with 3 wildcards though.

I didn't mean with this tactic, specifically. I meant at all, with any tactic.

CJam, Lynn
esmpmpmeimtmemqmememqicelic
esmpmpmeimememqmlmtmemoc
esmpmpmeimememqmtmtmtmtmeic
esmpmpmeimememqmtmtmtmtmeic
esmpmpmeimeiscic
esmpmpmeimemeimfsic
esmpmpmeisciscimqmtmemeic
esmpmpmeiscimlmqmqmemeic
esmpmpmeimemomqmqmemeic
esmpmpmeisciscimfsimqic
esmpmpmeimeiscic
esmpmpmeisciscimfsimqic
esmpmpmeimemomqmemqmemtmemoc
esmpmpmeiscic
esmpmpmeimemomeimqmeic
esmpmpmeimemeimqmlmtmeic
esmpmpmeimtmtmqmemtmtmeic
esmpmpmeimemomqmqmtmeic
esmpmpmeimemqmqmemeic
esmpmpmeiscimlmqmqmemeic
esmpmpmeiscimqmtmtmtmqmemeic
esmpmpmeimeimemtmqmemeic
esmpmpmeimeiscimlmlmtmlmtic
esmpmpmeimemeimqmlmtmeic
~~

All linefeeds are for cosmetic purposes and can be removed without affecting the program.
Try it online!
Explanation
After Lynn removed {|} from the list of allowed characters, I had to try something new. It turns out we can still construct arbitrary strings and evaluate them as code.
First, we need to get some value onto the stack. The only available built-ins that push something without popping something else first (and without reading the input) are es, ea and et. I'm sure you could start from all of these one way or another, but I went with es which pushes the current timestamp. Since I didn't want to make any assumptions about its actual value, I test its primality with mp (which gives 0 and 1) and test that value's primality again to ensure I've got a 0 on the stack. A 1 will be more useful, so we compute exp(0) with me and turn it into an integer with i. So all the numbers start with:
esmpmpmei

Now we've got a whole bunch of unary maths operators to work with:
i    int(x) (floor for positive numbers, ceiling for negative)
me   exp(x)
ml   ln(x)
mq   sqrt(x)
mo   round(x)
mt   tan(x)

We can also combine a few built-ins for more elaborate functions of x:
sci     Extract first digit of x and add 48 (convert to string, convert
        to character, convert to integer).
ceui    Convert to character, convert to upper case, convert to integer.
celi    Convert to character, convert to lower case, convert to integer.
mfsi    Get a sorted list of prime factors of x and concatenate them into
        a new number.
mfseei  Get a sorted list of prime factors, interleave it with 1,2,3,..., and
        concatenate the result into a new number.

Using these, we can obtain any number in 0 <= x < 128 (and many others) in less than 10 steps from 1. I'm sure a much smaller subset of these commands would also suffice. I've written a small Mathematica program, to determine all of these snippets (it's not very readable, sorry):
codes = SortBy[
  Select[Nest[Select[DeleteDuplicatesBy[SortBy[Join @@ (Through[{
               List,
               If[1 <= # < 50, {Exp@#, #2 <> "me"}, Nothing] &,
               If[# >= 1, {Log@#, #2 <> "ml"}, Nothing] &,
               If[# > 1, {Sqrt@#, #2 <> "mq"}, Nothing] &,
               {If[# > 0, Floor@#, Ceiling@#], #2 <> "i"} &,
               {Floor[# + 1/2], #2 <> "mo"} &,
               {Tan@#, #2 <> "mt"} &,
               If[NumberQ@# && # >= 0, {First@
                   ToCharacterCode@ToString@#, #2 <> "sci"},
                 Nothing] &,
               If[IntegerQ@# &&
                  32 < # < 65536, {First@
                   ToCharacterCode@
                    ToUpperCase@FromCharacterCode@#, #2 <> "ceui"},
                 Nothing] &,
               If[IntegerQ@# &&
                  32 < # < 65536, {First@
                   ToCharacterCode@
                    ToLowerCase@FromCharacterCode@#, #2 <> "celi"},
                 Nothing] &,
               If[IntegerQ@# && # > 0, ## & @@ {
                   {FromDigits[
                    "" <> (ToString /@ (f =
                    Join @@ Table @@@ FactorInteger@#))], #2 <>
                    "mfsi"},
                   {FromDigits[
                    "" <> (ToString /@
                    MapIndexed[## & @@ {#2[[1]] - 1, #} &, f])], #2 <>
                     "mfeesi"}
                   }, Nothing] &
               }@##] &) @@@ #, StringLength@*Last],
       First], #[[1]] < 1000000 &] &, {{1, "esmpmpmei"}}, 9],
   IntegerQ@# && 0 <= # < 128 &@*First], First]

With that, we can simply push an arbitrary list of character codes, converting each of them to a character with c afterwards. Once we've pushed the entire code we want to execute, we push 95 (]). We eval that one with ~ to wrap all the others in a string, and then we eval that string with ~.
The actual code run at the end of the program is again:
ri__2#,:)/2/[1W]f.%:~<p

See my previous solution for an explanation.

Python 3, TuukkaX
Sorry, the regex you used was too easy to trivialize. No 0, # or  ? No problem!
I might've misinterpreted the example output but it's still pretty easy to tweak since I have 45 spare characters left over
n=int(input())
print(str(n)+":")
x=1-1
exec("print([*range(1+x*n,1+n*-~x)][::(1,-1)[x%2]]);x+=1;"*n)
"no-op:a_string_that_doesnt_actually_matter"

Nice! :D FYI: I'll create another one in Python, if you're interested to solve it ;) It'll be a bit longer, but the beauty lies in the uncrackfulness.

R, MickyT
lets_make_a_snake<-function(n)`for`(i,1:n,cat(i*n+1-`if`(i%%2,n:1,1:n),"\n"))

Tests cases:
> lets_make_a_snake(4)
1 2 3 4
8 7 6 5
9 10 11 12
16 15 14 13
> lets_make_a_snake(7)
1 2 3 4 5 6 7
14 13 12 11 10 9 8
15 16 17 18 19 20 21
28 27 26 25 24 23 22
29 30 31 32 33 34 35
42 41 40 39 38 37 36
43 44 45 46 47 48 49

And regex confirmation: https://regex101.com/r/OB8ZIM/1
I also had:
invisible(sapply(1:(n=scan()),function(i)cat(i*n+1-`if`(i%%2,n:1,1:n),"\n")))

which gives the same output and match the same regex.

lets_make_a_snake... I'd be surprised if that was the intended solution :P

@plannapus Great job .  The first one is basically what I was intending using  for  and  if , but a lot better golfed than mine.

Röda, fergusq
{|i|;a=1;while[a<=i]do;b=a*i-i+1;c=[];while[b<=a*i]do;c+=b;b++;done;{d=[];x=0;while[x<i]do;d+=c[i-x-1];x++;done[d]}if[a%2<1]else{[c]};a++;done;r="||||||"}

This is an anonymous function that matches this PCRE regex: ^{(\|[^\/#\s]*){8}$.
Try it online!

Bash, @Marcos M
sort -n <(seq 1 $((n * n)) | xargs -n$n | sed -n 'p;n'; seq $((n * n)) 1 | xargs -n$n | sort -n | sed -n 'n;p')

Prettified:
sort -n <(               # feed the stdout of this subshell into stdin for `sort -n`
    seq 1 $((n * n)) |   #   generate 1 2 3 ... n²
        xargs -n$n |     #     add line break every n numbers
        sed -n 'p;n';    #     print only odd lines
    seq $((n * n)) 1 |   #   generate n² ... 3 2 1
        xargs -n$n |     #     add line break every n numbers
        sort -n |        #     reverse all lines (keeping each row decreasing)
        sed -n 'n;p'     #     print only even lines
)

The first part of the subcommand will generate 1 2 3 4, 9 10 11 12, and the second part will generate 8 7 6 5, 16 15 14 13. The outer sort -n will properly mix them together to form the snake pattern.
I used the trick in https://superuser.com/a/101760 to print the odd and even lines. Thank you Marcos, really a fun one.

Very nice solution

Javascript, Tom

f=(a,i=1,j=0)=>Array(a).fill(0).map(b=>Array(a).fill(0).map(a=>i++)).map(a=>j++%2?a.reverse():a).map(a=>a)

console.log(f(4))

Python 3, @TuukkaX
n=int(input());j=0;exec("print([(j-+i%n-n++2*n-0,j+i%n+1)[1&int(i/n)//1^(0x1)//1]*(2*(i%n)*0+2222222//2222222)for i in range(j,j+n)]);j+=n;"*n)

Verify: https://regex101.com/r/GI1Zvh/1

Slightly analyzing the cop's regex shows a fixed template:
________________________"___________i%n____2*n-____i%n__________i/n)//1_____)//1___2*(i%n)____^^^^^^^^^^^^^^^^for i in range(j,____])______"*n)

where _ is any character except [ '"#] and ^ is any of [int()2/].
The "*n) at the end clearly shows an eval("..."*n) or exec("..."*n) is going on, so we just need to make sure the "..." prints the j-th row.
The for i in range(j, is too close to the end of the string, hinting list comprehension without any if. So we need to construct the i-th column using those i%n, 2*n stuff.
n = int(input())
j=0
exec("""print([
    (
        j - +i%n - n ++ 2*n - 0,    # equivalent to (n + j - i%n) for the decreasing rows
        j + i%n + 1                 # equivalent to (j + i%n + 1 == i + 1) for the increasing rows
    )[1 & int(i/n)//1 ^ (0x1)//1]   # int(i/n)   ->    get row number 0, 1, 2, 3, ...;
                                    # 1 & int(i/n)//1    ->    0 for increasing rows, 1 for decreasing rows,
                                    # 1 & int(i/n)//1 ^ (0x1)//1    ->   flip 0 and 1
    * (2*(i%n)*0+2222222//2222222)  # multiply by the constant 1.
    for i in range(j,j+n)
]); j+=n; "*n)

Nice! Well, almost survived a week :D I'll post my original code.

dc, Mitchell Spector
This was my first entry to a cops and robbers challenge, and I had a lot of fun. The regex needed to be matched was simple, ^[^# !]{59}$, which basically turned my job into a golfing one, without using those 3 characters. Initially I had difficulties getting below 60 bytes, but I cracked it in the end.
?sN0[AP]sP[ddlN~_2*lN+1-r2%*+1+n32P1+dlN%0=PdlNd*>L]dsLxqqq

Try it online!
Explanation:
My code uses one loop with N 2 iterations, keeping a zero based counter (1D), and calculates what number needs to be printed based on the corresponding matrix row and column (r, c) coordinates.
Example of what I mean, if N = 4:
 0  1  2  3            (0,0) (0,1) (0,2) (0,3)             1  2  3  4
 4  5  6  7     ->     (1,0) (1,1) (1,2) (1,3)     ->      8  7  6  5
 8  9 10 11            (2,0) (2,1) (2,2) (2,3)             9 10 11 12
12 13 14 15            (3,0) (3,1) (3,2) (3,3)            16 15 14 13

It looks complicated, but the intermediary step is helpful. Plus, I've tried using 2 loops from the start, but I ended up above the regex character limit. Number generation at each iteration (zero based):

if r % 2 = 0 (normal row), n = (r * N) + c = counter
if r % 2 = 1 (reversed row), n = ((r + 1) * N) - c - 1 = counter + N - (2 * c) - 1

Or all at once, as one based numbering: n = counter + ((N - (2 * c) - 1) * (r % 2)); n++
?sN0             # read input, save as N, initialize iteration counter
[AP]sP           # macro 'P' that prints a newline (ASCII code 10 = A)
[                # start loop
    ddlN~        # push N, calculate row and column coordinates:
                 #r = int(counter / N), c = counter % N, '~' calculates both
    _2*lN+1-     # c is on top, so this does: N - (2 * c) - 1
    r2%*+        # now r is on top, do: (r % 2) * (previous result) + counter
    1+n32P       # do: n++, print space (ASCII code 32)
    1+           # increment counter
    dlN%0=P      # call macro 'P' every Nth printed number
    dlNd*>L      # if: N * N > counter, repeat loop
]dsLx            # this saves the loop to macro 'L', then executes it
qqq              # my script was shorter, so I added a bunch of quit commands to
                 #fit the regex limit. Use of comments ('#') was prohibited.

@MitchellSpector Here is my explanation. As you see, we both have literally the same algorithm, only I use the command ~ to calculate the row and column indexes in one go. But one of my previous attempts did calculate them separately as you did. Great minds think alike? :)

Yes, it really is the same algorithm. I like your use of ~ to shorten the code.

I think you can shorten it by one byte if you use the square-root trick in the loop test at the end of the macro: ?sN0[AP]sP[ddlN~_2*lN+1-r2%*+1+n32P1+dlN%0=PdvlN>L]dsLx  https://tio.run/nexus/dc#@29f7GcQ7RgQWxwQnZKS41cXb6SV46dtqFtkpKqlbaidZ2wUYKgNlFA1sA1IKcvxs/OJTSn2qfj/3wQA

@MitchellSpector You're right, and I did notice it when reading your explanation, but commented in the chat room instead.

Yes, I see that now -- I hadn't looked at the chatroom this morning yet.

PowerShell, ConnorLSW
Crack
$mySnakeIndex=1;$seq=1..$args[0];$seq|%{$rowNum=$seq|%{($mySnakeIndex++)};if(!($_%2)){[array]::Reverse($rowNum)};$rowNum-join" "}

I started with a smaller solution to the issue and padded my variable names to get the regex to match. Trying to find a use for the colon I suppose was the hardest part to wrap my head around.
$a=1..$args[0];$i=1;$a|%{$r=$a|%{($i++)};if(!($_%2)){[array]::Reverse($r)};$r-join" "}

Explanation
# Initialize a counter that starts at one.
$mySnakeIndex=1
# Save the integer array from 1 to the input value.
$seq=1..$args[0]
# For each row of the output...
$seq|%{
    # Build the integer array for this row sequentially
    $rowNum=$seq|%{
        # Increase the integer index while sending it down the pipeline
        ($mySnakeIndex++)}
        # Check if this is and odd row. If so reverse the integer array.
        if(!($_%2)){[array]::Reverse($rowNum)}
        # Take this row and join all the numbers with spaces.
        $rowNum-join" "

Nice, I used a $script variable and some really messy looping to pad it out, the [array]::Reverse() was correct though, congrats - I think you might want to even out the length of $i and $MySnakeIndex though.

@ConnorLSW I know you would not be able to sleep at night knowing I had errors in my robber. I have fixed it.

CJam, Lynn
Something like this:
ri
{s}seu~~ci{zs}seu~~c{a}seu~~|~{w}seu~~z{w}seu~~sc~c{z}seu~~{w}seu~~sc~c{w}seu~~z{w}seu~~sc~c~

{s}seu~~ci{z}seu~~{s}seu~~c{a}seu~~|~{w}seu~~z{w}seu~~sc~c
{s}seu~~ci{z}seu~~{s}seu~~c{a}seu~~|~{w}seu~~z{w}seu~~sc~c
{s}seu~~ci{z}seu~~{s}seu~~c{a}seu~~|~{w}seu~~z{w}seu~~sc~c
{s}seu~~c{a}seu~~|
{s}seu~~c{c}seu~~|
{t}seu~~sc{a}seu~~|
{s}seu~~c{a}seu~~|{w}seu~~z{w}seu~~sc~c
{s}seu~~sc{fb}seu~~||
{s}seu~~sc{i}seu~~|
{s}seu~~sc{fb}seu~~||
{s}seu~~ci{z}seu~~{s}seu~~c{a}seu~~|~{w}seu~~z{w}seu~~sc~c{z}seu~~{w}seu~~sc~c{w}seu~~z{w}seu~~sc~c
{a}seu~~scs
{w}seu~~
{s}seu~~ci{z}seu~~{s}seu~~c{a}seu~~|~{z}seu~~{w}seu~~sc~c
{fb}s{b}s{w}seu~~sc~
{s}seu~~sc{ee}seu~~||
{s}seu~~sc{z}seu~~|{w}seu~~{w}seu~~sc~{w}seu~~{w}seu~~sc~
{t}seu~~sc{a}seu~~|
{~}s{}s{w}seu~~sc~
{t}seu~~sc{c}seu~~|

{s}seu~~ci{z}seu~~{s}seu~~c{a}seu~~|~{z}seu~~{w}seu~~sc~c~
s~
p

All whitespace is for... "readability"... and can be omitted to comply with Lynn's regex.
Try it online!
Explanation
The regex requires that we solve problem using only:

Lower-case letters.
{}, which can be used to create blocks.
|, mostly used for bitwise OR.
~, "eval" and bitwise NOT (also "dump array", but I'm not going to use it).

Since we have, ~, if we can construct arbitrary strings, we can run arbitrary code. However, at first it's not obvious how to do that.
The first piece of the puzzle is that blocks are unevaluated bits of code, which can turn into strings with s. So {abc}s gives us "{abc}". Next, we can use eu to convert these strings to upper case.
{abc}seu  e# gives "{ABC}"

The benefit of this is that upper-case letters are pre-initialised variables, so we can get a lot of constant values by creating such a string, and eval'ing it twice (once to turn the string back into a block and once to execute that block). We can't get all the letters, because some, like x aren't valid commands (so CJam will refuse to parse a block containing them). We can't use f as is, because it needs to be followed by another command, but we can use fb and then OR the two values together. Likewise, we can use ee instead of e. With that, we can get the numbers 0, -1, 3, and 10 to 19. The -1 is convenient, because if we turn it into a string ("-1") then into a character ('-) and then eval it, we can get either subtraction or set difference. Like I said, we can't get X (for 1), but we can take the absolute value of -1 with z.
We can also use s to get a string containing a space, and use c to turn that into a space character:
{s}seu~~c

This is convenient, because from there we can get lots of useful commands in the lower ASCII range by ORing the space with various numbers. To get some of the characters above code point 48, we use the character '0 as the basis instead:
{t}seu~~si

This is already enough to construct arbitrary strings, because we can get '+ (addition and string concatenation) from the following snippet:
{s}seu~~c{b}seu~~|

And we have a literal 1 so we can just push space characters, increment them to the value we need and then concatenate them all together, but that's a bit boring and the code would become massive.
Instead, I've generated [ and ] and evalled them, so that all the characters I push in between are wrapped in a string automatically. That's these two lines:
{s}seu~~ci{zs}seu~~c{a}seu~~|~{w}seu~~z{w}seu~~sc~c{z}seu~~{w}seu~~sc~c{w}seu~~z{w}seu~~sc~c~

...

{s}seu~~ci{z}seu~~{s}seu~~c{a}seu~~|~{z}seu~~{w}seu~~sc~c~

And finally, we'll need f and ~ in the string we're generating. While those are valid characters already, we don't have string literals or character literals, so we'd have to generate these as well and building up larger code points from the space is a bit annoying. Instead, I've made use of the set subtraction here, but subtracting two blocks (to get rid of the {}):
{fb}s{b}s{w}seu~~sc~
...
{~}s{}s{w}seu~~sc~

That's pretty much all there is to it. We eval [. We push all the characters, obtained by various computations from the few built-in constants we have, |, - (via eval) and + (via eval). We eval ]. We flatten the entire thing into a string, because at some point I added some strings or numbers into the list. We eval our arbitrary string with ~.
The ri...p are part of the actual final program, but I've extracted them because they don't need encoding.
Finally, this is the program we're actually running:
ri___*,:)/2/[1-1]f.%:~<p

ri      e# Read input and convert to integer.
__      e# Make two copies.
_*      e# Square the last copy.
,       e# Turn into range [0 1 ... n^2-1].
:)      e# Increment each to get [1 2 ... n^2].
/       e# Split into chunks of length n, creating a square.
2/      e# Split into pairs of lines.
[1-1]   e# Push [1 -1].
f.%     e# Use this to reverse the second line in each pair. If n was odd,
        e# this will pair a -1 with the last line.
:~      e# Flatten the pairs back into the square.
<       e# Truncate to n lines to get rid of that extraneous -1 for odd inputs.
p       e# Pretty-print.

tinylisp, @DLosc
(v(c(h(q(d)))(c(h(q(f)))(q((c(q(n))(q((g(v(h(q(n))))(s(v(h(q(n))))(v(h(q(1)))))())))))))))(v(c(h(q(d)))(c(h(q(mod)))(q((c(c(h(q(x)))(q(y)))(q((i(l(v(h(q(x))))(v(h(q(y)))))x(mod(s(v(h(q(x))))(v(h(q(y)))))y))))))))))(v(c(h(q(d)))(c(h(q(range)))(q((c(c(h(q(x)))(c(h(q(y)))(c(h(q(z)))(q(w)))))(q((i(l(times(v(h(q(z))))(v(h(q(x))))(v(h(q(0)))))(times(v(h(q(z))))(v(h(q(y))))(v(h(q(0))))))(range(v(h(q(x))))(s(v(h(q(y))))(v(h(q(z)))))z(c(s(v(h(q(y))))(v(h(q(z)))))w))w)))))))))(v(c(h(q(d)))(c(h(q(times)))(q((c(c(h(q(x)))(c(h(q(y)))(q(acc))))(q((i(l(v(h(q(x))))(v(h(q(0)))))(times(s(v(h(q(0))))(v(h(q(x)))))(s(v(h(q(0))))(v(h(q(y)))))acc)(i(e(v(h(q(x))))(v(h(q(0)))))acc(times(s(v(h(q(x))))(v(h(q(1)))))y(a(v(h(q(y))))(v(h(q(acc))))))))))))))))(v(c(h(q(d)))(c(h(q(g)))(q((c(c(h(q(n)))(c(h(q(w)))(q(r))))(q((i(l(v(h(q(w))))(v(h(q(0)))))r(g(v(h(q(n))))(s(v(h(q(w))))(v(h(q(1)))))(c(i(e(v(h(q(0))))(mod(v(h(q(w))))(v(h(q(2))))))(range(a(v(h(q(1))))(times(v(h(q(w))))(v(h(q(n))))(v(h(q(0))))))(a(a(v(h(q(1))))(times(v(h(q(w))))(v(h(q(n))))(v(h(q(0))))))n)1())(range(a(times(v(h(q(w))))(v(h(q(n))))(v(h(q(0)))))n)(times(v(h(q(w))))(v(h(q(n))))(v(h(q(0)))))(s(v(h(q(0))))(v(h(q(1)))))()))r)))))))))))

Try it online!
This defines a function f that returns the answer. It also prints the names of the functions I defined to stdout, but I assume that doesn't matter, since [we're allowed to choose our output stream] for code golf, at least. If it's a big deal, I think I can tweak it to not print those. How did I do it? I started with something fairly standard:
(d f (q ((n)
  (g n (s n 1) ()))))

(d mod (q((x y)
  (i (l x y) x
    (mod (s x y) y)))))

(d range (q((x y z w)
  (i (l (times z x 0) (times z y 0))
    (range x (s y z) z (c (s y z) w))
    w))))

(d times (q ((x y acc)
  (i (l x 0) (times (s 0 x) (s 0 y) acc)
  (i (e x 0) acc
    (times (s x 1) y (a y acc)))))))

(d g (q ((n w r)
  (i (l w 0) r
    (g n (s w 1)
       (c (i (e 0 (mod w 2))
             (range (a 1 (times w n 0)) (a (a 1 (times w n 0)) n) 1 ())
             (range (a (times w n 0) n) (times w n 0) (s 0 1) ()))
          r))))))

Then, I observed that one can transform functions definitions like this:
(d mod (q ((x y) (body))))

becomes
(v(c(h(q(d)))(c(h(q(mod)))(q((c(c(h(q(x)))(q(y)))(q((body)))))))))

And function calls like this:
(a x y)

becomes
(a(v(h(q(x))))y)

I used this recursive Vim macro, stored in register q, to do the second one (I have jk mapped to <Esc>): f s(v(h(q(jkea))))jk@q.
These two transformations were sufficient to eliminate all spaces.

Nicely done! My original code is quite similar, though I wrote a helper macro to make it a bit less painful to write. I'm curious as to your thoughts on how to avoid printing the defined symbols--if you'd care to share them, I'll be in the tinylisp chat room.

@DLosc Done, I posted there.

Swift, @James Webster
{n in for j in 0..<n{print((1...n).map{j%2==0 ?$0+j*n:j*n+n+1-$0})}} as(CShort)->()

Verification: https://regex101.com/r/7ukrM0/1

I get "Expression resolves to an unused function" with this on its own, but I'm unfamiliar with everything that makes an acceptable answer. Is the e.g. `let a = ; a(CShort(4)); required to make it run not necessary?

@JamesWebster I'm not sure about the exact rules since "a code" is pretty ambiguous. For [tag:code-golf] the submission can be a program or function, so I just provide an anonymous function here. How else do we receive the input arguments?

My original was the body of a function, so not sure mine is valid either! So I'm just gonna go with "Sure, this is fine" and upvote it. :)

@JamesWebster You can call the whole thing as (…)(4), no need to cast the integer literal to CShort.

Ah yeah! I would never have thought of that.

Technically, the cop post was invalid per meta consensus ([tag:code-golf] rules apply when it comes to I/O), but since you have already cracked it I'll allow both to stay :)

PHP, @JörgHülsermann
<?=(function($n,$snake){foreach(array_chunk(range(1,$n*$n),$n)as$i=>$a){if($i%2)$a=array_reverse($a);echo"\n",join('',array_map(function($e){return(sprintf("%3d",$e));},$a));}})($argv[1],'-=-=-=-=-=-=-=-=-=-=-=-=-=-o~')?>

Verify: https://regex101.com/r/81pUrB/1
TIO: https://tio.run/#aNvF0

221 bytes is too long (thus the snake), and the lack of whitespace can be easily worked-around.
Prettified:
<?=
(
    function($n, $snake) {
        foreach (array_chunk(range(1, $n*$n), $n) as $i => $a) {
            if($i % 2)
                $a = array_reverse($a);
            echo "\n", join('', array_map(function($e) {
                return (sprintf("%3d", $e));
            }, $a));
        }
    }
)($argv[1], '-=-=-=-=-=-=-=-=-=-=-=-=-=-o~')
?>

Nice variant. My fault was not to think about a function and make only one output

Jelly, length 12, @JonathanAllan
Ḷ-*m@"s@²$G

Try it online!
How it works
Ḷ-*m@"s@²$G  Main link. Argument: n

Ḷ            Unlength; yield [0, ..., n-1].
 -*          Yield [(-1)**0, ..., (-1)**(n-1)].
         $   Combine the two links to the left into a chain.
        ²    Yield n².
      s@     Split [1, ..., n²] into chunks of length n.
   m@"       Take the lists to the right modulo the units to the left, 1 being
             normal order and -1 being reversed.

Jelly, 12 bytes, cracks @JonathanAllan's second answer
²sµ;@/€FḤ$¦G

Try it online!
Explanation
This is almost the same as my other answer. I just made two changes:
First, I changed U ("reverse each element") to Ṛ€ ("reverse" "each element"). That doesn't help by itself, because Ṛ is also banned.
Then, I changed the Ṛ ("reverse") to ;@/ (/ "fold by" ; "concatenating" @ "in the opposite order to the original list"). That avoids all the banned characters, giving a valid solution.
I assume the next step would be to start banning array-manipulation quicks, in addition to the atoms.

Uh, I knew I should have banned €...

You can write € in terms of / too. It's just rather more verbose than this solution.

Yep and one could ;@\ṫ0, the regex is getting long.

Jelly, length 13, @JonathanAllan
1r-*Nm@"s@²$G

Try it online!
How it works
1r-*Nm@"s@²$G  Main link. Argument: n

1r             Range 1; yield [1, ..., n].
 -*            Yield [(-1)**1, ..., (-1)**n].
   N           Negate each unit.
           $   Combine the two links to the left into a chain.
          ²    Yield n².
        s@     Split [1, ..., n²] into chunks of length n.
     m@"       Take the lists to the right modulo the units to the left, 1 being
               normal order and -1 being reversed.

Oh wait, what, I missed m?!

Jelly, length 14, @JonathanAllan
²sµðạ"J×2$$¦GµL.xị"ḅ1µ$

Try it online!

That is impressive :D

Thanks! :) For some reason, I was convinced that my code couldn't contain any newlines, which forced me to discover some chain trickery.

Scala, @Soapy
def g(n:Int) = {
    var vec = Vector.fill(0)(Vector.fill(0)(1))
    for (p <- 1 to n) {
        var vec2 = Vector.fill(0)(1)
        for (q <- (p-1)*n+1 to p*n) {
            vec2 = vec2 ++ Vector(q)
        }
        if (p%2==1) vec = vec ++ Vector(vec2)
        else vec = vec ++ Vector(vec2.reverse)

    }
    println(vec)
}

Haven't touched Scala in awhile, it was fun to revisit. Unfortunately, this solution misses out on a lot of Scala's cool features.
Try it out here
Regex Confirmation

QBasic (QB64), @DLosc
Note that since the . does not match \n (U+000A, LF), the newline here is a \r (U+000D, CR).
INPUT N:ZERO=N-N:ONE=N/N:FOR I=ZERO TO N-ONE:FOR J=ONE TO N:IF ZERO=I MOD(ONE+ONE)THEN PRINT I*N+J;ELSE PRINT I*N+N-J+ONE;REM
NEXT:PRINT:NEXT

Verify:
>>> re.match('^([A-Z]+.)+$', 'INPUT N:ZERO=N-N:ONE=N/N:FOR I=ZERO TO N-ONE:FOR J=ONE TO N:IF ZERO=I MOD(ONE+ONE)THEN PRINT I*N+J;ELSE PRINT I*N+N-J+ONE;REM\rNEXT:PRINT:NEXT')
<_sre.SRE_Match object; span=(0, 141), match='INPUT N:ZERO=N-N:ONE=N/N:FOR I=ZERO TO N-ONE:FOR >

The main difficulty is how to insert a word after the ;. Thankfully, QB64 treats CR as a newline while Python's regex doesn't, so we could slip a REM\r here. Out of the five allowed regex flavors,

Perl accepts "\r" =~ /./
JavaScript rejects !/./.test('\r') (\n, \r, \u2028, \u2029 are all line separators)
Python accepts re.match('.', '\r') (only \n is considered a line break)
Golang accepts regexp.Match(".", "\r")
Ruby accepts /./ =~ "\r"

So this crack is fine as long as we don't mention JavaScript...

I'll accept this, since it works in QB64. However, I will also say that archive.org's QBasic (which I think is the actual QBasic rather than an emulation) complains about REM immediately following a statement with no statement separator. My original solution did not use comments. I've got another variation that I will be posting shortly. :D

Python 3, kennytm
def S(N,A=1,K=1,E=list,r=range):print(E(r(A,A+N)[::K]))or(A>N*N-N)or(((S(N,A+N,-K))))

Regex verification

><>, torcado
!v &0_!
_<>~ao1+>_v_
?______;__>:&:&=?;::2%:}+&:&*{3+0$.
?!v1+:n' 'o:&:&%_
?!v:n' 'o1-:&:&%_

C, @Yimin Rong
main(int c,char**p){int n=atoi(*++p),i=n-n,t,o=c;for(--o;i<n;++i)for(t=o;t<=n;++t)printf("%-*d%c",n-o,i%c?i*n+n+o-t:i*n+t,t%n?' ':'\n');}

The program cannot contain numbers, but we can get numbers via:

c, commonly known as "argc", which is always 2.
+ and - are available, so we can create 0 with n-n, and create 1 with o=c;--o.

Minor issue, cop version was tab-delimited as opposed to space-justified, but no biggy.

PHP, @Ionut Botizan
In the moment I have no better idea to crack the original solution.
Supports n<=15
It is the first time that I use getopt. Maybe not the best idea to use options as input.
start from the command line like this
php hack.php -a=4

Original Regex
Level 1:
^<[^'"\d{vV;<$]+$

Very nice combination of letters. Feel free to vote up the cops thread.
It blocks me functions like
 - strrev
 - array_reverse
 - get_defined_vars
https://regex101.com/r/5rGTnw/2
Level 2:
^<[^'"\d{v;<$_~|&A-Z]+$

https://regex101.com/r/XtVl9G/1
Solution
 <?php
    error_reporting(~E_NOTICE)&
    define(A,a.chr(E_COMPILE_ERROR-E_NOTICE+E_WARNING))
    &define(B,getopt(A,[])[a])&print_r(array_chunk(
    array_slice(
    array_merge(
    range(E_ERROR,B)
    ,range(E_WARNING*B,E_ERROR+B)
    ,range(E_WARNING*B+E_ERROR,(E_WARNING+E_ERROR)*B)
    ,range(E_PARSE*B,+E_ERROR+(E_WARNING+E_ERROR)*B)
    ,range(E_PARSE*B+E_ERROR,(E_PARSE+E_ERROR)*B)
    ,range((E_PARSE+E_WARNING)*B,+E_ERROR+(E_PARSE+E_ERROR)*B)
    ,range((E_PARSE+E_WARNING)*B+E_ERROR,(E_NOTICE-E_ERROR)*B)
    ,range(E_NOTICE*B,+E_ERROR+(E_NOTICE-E_ERROR)*B)
    ,range(E_NOTICE*B+E_ERROR,(E_NOTICE+E_ERROR)*B)
    ,range((E_NOTICE+E_WARNING)*B,E_ERROR+(E_NOTICE+E_ERROR)*B)
    ,range((E_NOTICE+E_WARNING)*B+E_ERROR,(E_NOTICE+E_WARNING+E_ERROR)*B)
    ,range((E_NOTICE+E_PARSE)*B,E_ERROR+(E_NOTICE+E_WARNING+E_ERROR)*B)
    ,range((E_NOTICE+E_PARSE)*B+E_ERROR,(E_NOTICE+E_PARSE+E_ERROR)*B)
    ,range((E_CORE_ERROR-E_WARNING)*B,E_ERROR+(E_NOTICE+E_PARSE+E_ERROR)*B)
    ,range((E_CORE_ERROR-E_WARNING)*B+E_ERROR,(E_CORE_ERROR-E_ERROR)*B)
    )
    ,B-B,B*B
    ),B)
    )
    ?>

Level 2:
<?php
define(aa,a.chr(ord(strtoupper(a))-ord(h)+ord(a)))and
define(bb,getopt(aa,[])[a])and
define(us,chr(ord(a)-true-true))and
(prin.t.(us).r)(
(arra.y.(us).chunk)(
(arra.y.(us).slice)(
(arra.y.(us).merge)(
range((ord(b)-ord(a)),bb)
,range((ord(c)-ord(a))*bb,(ord(b)-ord(a))+bb)
,range((ord(c)-ord(a))*bb+(ord(b)-ord(a)),((ord(c)-ord(a))+(ord(b)-ord(a)))*bb)
,range((ord(e)-ord(a))*bb,+(ord(b)-ord(a))+((ord(c)-ord(a))+(ord(b)-ord(a)))*bb)
,range((ord(e)-ord(a))*bb+(ord(b)-ord(a)),((ord(e)-ord(a))+(ord(b)-ord(a)))*bb)
,range(((ord(e)-ord(a))+(ord(c)-ord(a)))*bb,+(ord(b)-ord(a))+((ord(e)-ord(a))+(ord(b)-ord(a)))*bb)
,range(((ord(e)-ord(a))+(ord(c)-ord(a)))*bb+(ord(b)-ord(a)),((ord(e)-ord(a))-(ord(b)-ord(a)))*bb)
,range((ord(e)-ord(a))*bb,+(ord(b)-ord(a))+((ord(e)-ord(a))-(ord(b)-ord(a)))*bb)
,range((ord(e)-ord(a))*bb+(ord(b)-ord(a)),((ord(e)-ord(a))+(ord(b)-ord(a)))*bb)
,range(((ord(e)-ord(a))+(ord(c)-ord(a)))*bb,(ord(b)-ord(a))+((ord(e)-ord(a))+(ord(b)-ord(a)))*bb)
,range(((ord(e)-ord(a))+(ord(c)-ord(a)))*bb+(ord(b)-ord(a)),((ord(e)-ord(a))+(ord(c)-ord(a))+(ord(b)-ord(a)))*bb)
,range(((ord(e)-ord(a))+(ord(e)-ord(a)))*bb,(ord(b)-ord(a))+((ord(e)-ord(a))+(ord(c)-ord(a))+(ord(b)-ord(a)))*bb)
,range(((ord(e)-ord(a))+(ord(e)-ord(a)))*bb+(ord(b)-ord(a)),((ord(e)-ord(a))+(ord(e)-ord(a))+(ord(b)-ord(a)))*bb)
,range(((ord(q)-ord(a))-(ord(c)-ord(a)))*bb,(ord(b)-ord(a))+((ord(e)-ord(a))+(ord(e)-ord(a))+(ord(b)-ord(a)))*bb)
,range(((ord(q)-ord(a))-(ord(c)-ord(a)))*bb+(ord(b)-ord(a)),((ord(q)-ord(a))-(ord(b)-ord(a)))*bb)
)
,bb-bb,bb*bb
),bb)
)
?>

Ruby, @Value Ink
->n{(1..n).map{|r|x=(r*n-n+1..r*n).to_a;if(r.modulo(2)==1)then(x)else(x.reverse)end}}#1-2-3-4-5-6--

[(-=Z-~]* means "I can write anything I like :)"

Ah, I messed that up didn't I

Mathematica, @Martin Ender (non-competing)
((#//Range)+i#-#)~SortBy~(-(-#)^i&)~Table~{i,#} &

QBasic, @DLosc
DEFSTR S:CLS:INPUT N:ONE=N\N:TWO=ONE+ONE:FOUR=TWO+TWO:SELECT CASE N:CASE IS<FOUR:FW=ONE:CASE IS<FOUR*TWO+TWO:FW=TWO:CASE ELSE:FW=ONE+TWO:END SELECT:READ S:FOR I=ONE TO N:FOR J=ONE TO N:COL=J*FW+J-FW:LOCATE I+ONE,COL:G=I MOD TWO:F=J*TWO-ONE-N:V=I*N-J+ONE+G*F:PRINT V:LOCATE I+ONE,COL:PRINT S:NEXT:LOCATE I+ONE,N*FW+N+ONE:PRINT S:NEXT:DATA|

Prettified (s/:/\n/g):
DEFSTR S
CLS
INPUT N
ONE = N\N
TWO = ONE+ONE
FOUR = TWO+TWO
SELECT CASE N
    CASE IS < FOUR: FW = ONE
    CASE IS < FOUR*TWO+TWO: FW = TWO
    CASE ELSE: FW = ONE+TWO
END SELECT
READ S
FOR I=ONE TO N
    FOR J=ONE TO N
        COL = J*FW+J-FW
        LOCATE I+ONE, COL
        G = I MOD TWO
        F = J*TWO-ONE-N
        V = I*N-J+ONE+G*F
        PRINT V
        LOCATE I+ONE, COL
        PRINT S
    NEXT
    LOCATE I+ONE, N*FW+N+ONE
    PRINT S
NEXT
DATA|

Use LOCATE to force the output position. Use DATA/READ to obtain "|" without using functions.

Yup--pretty similar to my original code.

PHP, @Ionut Botizan
Once upon a time I remember that PHP has a goto
https://regex101.com/r/m5kNRd/1/
double assigments are alternatives
for example Newline under Mac and Linux
solution with tab
<?="";
$p="M"&";";
$cr="M"&"-";
$cr="Z"&"*";
$zero=$one=$line=$text="";
$zero++;$zero--;
$a=$zero;
$s="$zero"&"$";
$one=++$one;
$g=$argv{$one};
$dir=$one;
a:++$a;
$line=$dir?"$line$a":"$a$line";
$line=$a%$g?$dir?"$line$p":"$p$line":"$line$cr";
$dir=$a%$g?$dir:$one-$dir;
$text=$a%$g?$text:"$text$line";
$line=$a%$g?$line:"";
echo$a-$g*$g?"":$text;
$a-$g*$g?:exit;
goto a;

First I have tought that I must use dynamic spaces
<?="";
$cr="M"&"-";
$cr="Z"&"*";
$zero=$one=$line=$text="";
$zero++;$zero--;
$a=$zero;
$s="$zero"&"$";
$one=++$one;
$five=$one+$one+$one+$one+$one;
$ten=$five+$five;
${"v$zero"}="$s$s$s$s$s$s$s";
${"v$one"}="$s$s$s$s$s$s";
${"v$ten"}="$s$s$s$s$s";
$g=$argc-$one;
$g=$argv{$one};
$space=$zero;
$p=${"v$space"};
$dir=$one;
a:++$a;
$a%$ten?:$space++;
$p=${"v$space"}??$p;
$line=$dir?"$line$a":"$a$line";
$line=$a%$g?$dir?"$line$p":"$p$line":"$line$cr";
$dir=$a%$g?$dir:$one-$dir;
$text=$a%$g?$text:"$text$line";
$line=$a%$g?$line:"";
echo$a-$g*$g?"":$text;
$a-$g*$g?:exit;
goto a;

My output was aligned with tabs, but StackExchange converted them to spaces. Anyway, a tab character is just as easy to obtain as a newline so it doesn't really matter! :)

@IonutBotizan It works better with tabs. $tab="M"&"+"; or $tab="M"&";"; are two ways to create the tab

I know, that's what I used and that's why M was whitelisted! :)

tinylisp, @DLosc
A very straightforward solution, and totally unoptimized :)
(d p(q((m n)(s m(s(s 1 1)n)))))(d j(q((f g)(i(l f g)(c f(j(p f 1) g))()))))(d r(q((f g)(i(l f g)(c(s g 1)(r f(s g 1)))()))))(d k(q((m o f g n)(i(l n g)()(c(m f(p f n))(k o m(p f n)(p g 1) n))))))(d f(q((n)(k j r 1 1 n))))

Call as (disp (f 4)).

(p m n) computes m + n using subtraction s (m + n == m - ((1 - 1) - n))
(j f g) generates (f f+1 f+2 ... g-1)
(r f g) generates (g-1 g-2 g-3 ... f)
(k m o f g n) generate one row of the snake matrix, and then recurve itself for the next row, until n rows are created. The arguments m, o are substituted by j/r to generate increasing or decreasing rows. The arguments f, g are running indices to know which row we are on.
(f n) calls (k j r 1 1 n) to start the generation.

Good work. (BTW, it's more idiomatic just to do (f 4)--the disp is implied.)

PHP, @Jörg Hülsermann
$n=next($argv);$a=array();for($i=0;$i<$n;++$i){$f=$i*$n;$g=$f+++$n;$a{$i}=$i&1?range($g,$f):range($f,$g);}echo(serialize($a));;

In PHP, range(1, 4) gives [1, 2, 3, 4] while range(4, 1) gives [4, 3, 2, 1]. o_O.

Racket Intermediate Student with Lambda, @Brian McCutchon
(λ(n)(foldr(λ(p q)(cons((λ(x)(if(even? p)(range(+ x 1)(+ x n 1)1)(range(+ x n)x -1)))(* p n))q))'()(range 0 n 1)))

(λ can be replaced by lambda, both are allowed in the regex.)
Since I can't get TIO to restrict to htdp-intermediate-lambda and I don't want to download a new language, I will just assume it is fine as long as I only use functions given on that page:
λ foldr cons if even? range + *.
Since TIO does not include the words "list" in the output (it just produces '((1 2 3 4) (8 7 6 5)…), if the above crack is rejected, consider this quick fix:
(λ(n)(cons 'list(foldr(λ(p q)(cons(cons 'list((λ(x)(if(even? p)(range(+ x 1)(+ x n 1)1)(range(+ x n)x -1)))(* p n)))q))'()(range 0 n 1))))

Nice, this is exactly what I had in mind, and your code works fine. The reason there is no list in your output is because standard Racket doesn't include it; it gives the right output in ISL. Now check out my new one, which should be much harder.

Oh, and I just found out that you can run ISL with lambda in TIO by putting #lang hdtp/isl+ at the top or in the header. (Of course, you can run it from Dr. Racket without the header, so that shouldn't count as part of the program.)

Racket Intermediate Student with Lambda, @Brian McCutchon
(λ (n)(((λ (f) (f f))(λ(s)(λ (i a b) (cond [(= i(* n n))'()] [#t(cons(a 1 i)((s s) (+ n i)b a))]))))0((λ (g) (g g))(λ(u)(λ (j i) (cond [(> j n)'()][#t(cons(+ j i)((u u) (+ 1 j)i))]))))((λ(g) (g g))(λ(d) (λ(j i) (cond [(> j n)'()][#t(cons(+(- n j)1 i)((d d) (+ 1 j)i))]))))))

Uses this trick to perform recursion without define/letrec/let*, otherwise a pretty standard algorithm. Some spaces cannot be eliminated due to the regex restriction.

Hah, interesting! I used the Y combinator, which comes out to basically the same thing.

Jelly, 15 bytes, @ais523
s@²UJḤ$¦Ȯṛ“”
Ç²s

Try it online!

This doesn't match the regex. You're missing the œ?.

The ? quantifier makes œ optional.

Oh, duh. I need to go fix the regex, then. It's a pity that cops-and-robbers tends to end up littered with broken questions like this.

Come to think of it, is the original question even valid? I didn't have a submission that matched the regex (and wasn't aware of it because I missed that ? was a metacharacter).

As long as it's actually solvable, there is a solution, so it's valid. You couldn't win with your submission unless you crack it yourself though.

Jelly, 16 bytes, @ais523
s@²UJḤ$¦Ȯṛ“”
Çœ?²s

Try it online!

05AB1E, mbomb007
Unlikely to be the intended solution :)
Crack
UXF**XLNNVX*F>}YFR}ˆ

Explanation
U                      # store input in X
 XF                    # X times do:
   **                  # multiply nothing twice
     XL                # range [1 ... input]
       N               # push current iteration number
        NV             # store current iteration number in Y
          X*           # multiply current iteration by input
            F>}        # increment the range that many times
               YFR}    # iteration number times, reverse the range
                   ˆ   # add it to global array
                       # implicitly print global array after program end

Go, @Kristoffer Sall-Storgaard
package main

import . "fmt"

const (
    zero = iota
    one
    two
)

func inc(p int) int {
    var bit = one
    for {
        if (p & bit) == zero {
            return p | bit
        }
        p ^= bit
        bit *= two
    }
}

func dec(p int) int {
    var bit = one
    for {
        if (p & bit) == bit {
            return p ^ bit
        }
        p |= bit
        bit *= two
    }
}

func main() {
    var n int
    var i int
    var row = one
    var col = zero
    Scan(&n)
    print("[")
    for n*n > i {
        i = inc(i)
        if col == zero {
            print("[")
        }
        if row%two == one {
            print(i)
        } else {
            var m = row * n
            var c = col
            for c > zero {
                m = dec(m)
                c = dec(c)
            }
            print(m)
        }
        col = inc(col)
        if col == n {
            print("]")
            col = zero
            row = inc(row)
        }
        if i != n*n {
            print(" ")
        }
    }
    print("]")
}

The regex means we only use one character from + to <, i.e.

+,-./:;<0123456789

The "." is needed for fmt.Scanf anyway. Although the character set is restricted, with unlimited length we could still write very complex programs.

The lack of numbers is trivial to workaround, just use iota to define constants.
The lack of < is also simple, just use > instead.
The lack of + and - are trickier. Here I reimplemented inc(x) == x+1 and dec(x) == x-1 using bit operations. Perhaps there is an easier way but this isn't a code-golf
The lack of , means we cannot use functions with two or more arguments, so make() and append() are out. There might be other ways to construct an array, but I find printing the output as if it is an array is simpler.

You're right about the arrays, I didn't use them :) I also avoided decrement entirely by using defer instead, my inc function was actually just func inc(i *int) { *i = ^*i * -1 } having gotten the -1 by using ^0

@KristofferSall-Storgaard Ah thanks. Forgot the old x+1 == -~x and x-1 == ~-x trick :D.

C#, @Eklipz
static int[,]F(int n){var a=new int[n,n];for(int r=n-n,z=r;r<n;++r)for(var c=z;c<n;++c)a[r,c]=n*r+((r&-~z)!=z?n-c:c-~z);;;;;;;;;;;;;;;;;;;;;;;return a;}

Uses standard tricks like z := n - n == 0 and -~z == 1 to produce the missing numbers.

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Output the decimal time
For some part of history people in France used a decimal clock. with the clock having 10 hour day, 100 minutes an hour and 100 seconds per minute. Though this clock simplified calculations a bit the idea wasn't appreciated by most of the world which used our current 24 hour, 60 minute hour, and 60 second minute. And hence decimal time was scrapped
However this time system does have its merits too. It is very useful for calculating time based efficiency easily aligns with our decimal measurement system and etc.
So given an Input as a string which is in standard HH:MM:SS format (regular time) we have to convert it to decimal time and output the exact decimal time on screen
Rules:

You will be provided with a string of the 24 hour format with colon separator between different time units Eg: 06:00:00,18:00:00
Your output must be a string of decimal time of the format as in 02:50:00, 07:50:00.
Note that separators in the output do not matter. Eg: 02:50:00 is a valid output and so is 02#50#00 (replacing separator colons with hashtags does not change output validity)
No use of any time related module is allowed. You will be provided input as specified in Rule 1 (#include, import datetime etc. is not allowed)

Who is the winner:
The one whose code is smallest wins
Sample input ----> Output
00:00:00 changes to 00:00:00
06:00:00 changes to 02:50:00
06:30:00 changes to 02:70:83
12:00:00 changes to 05:00:00
18:00:00 changes to 07:50:00
18:30:00 changes to 07:70:83

Hi there! I like this challenge, but I have a question about the input/output format. Does it need to be a strict HH:MM:SS string, or can the code take input as, e.g., an array [hh, mm, ss]? The reason I ask is that as-is, it makes input parsing a large portion of the code.

"No use of any time related module is allowed" -- How do you define "time-related?"

@JungHwanMin Somewhat related, definitely not a duplicate.

@AdmBorkBork The challenge I linked requires the code to output the decimal time too, but the output has to be a decimal number. This challenge just formats the decimal number. I'd say they are duplicates, as you can pretty much copy the code from the other challenge, only adding the formatting part.

06:30:00 changes to 03:00:00 ... 06:30:00 changes to 08:00:00 Which one is correct? Shouldn't the output be 02:70:83?

@JungHwanMin I think they mean 18:30:00 changes to 08:00:00. But I also get 02:70:83 and 07:70:83

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Rotating a 2D Matrix
Let's say I have the following (2D) matrix:
[[1,  2,  3,  4 ],
 [5,  6,  7,  8 ],
 [9,  10, 11, 12],
 [13, 14, 15, 16]]

Rotate the matrix counterclockwise R times (not in 90 degree increments, just by 1 number each time),
1  2  3  4             2 3   4  8         3   4   8  12
5  6  7  8    -->      1 7  11 12   -->   2  11  10  16
9  10 11 12            5 6  10 16         1   7   6  15
13 14 15 16            9 13 14 15         5   9  13  14

Completed example:
Input:
2
[[1,  2,  3,  4 ],
 [5,  6,  7,  8 ],
 [9,  10, 11, 12],
 [13, 14, 15, 16]]

Output:
[[3,  4,  8, 12],
 [2, 11, 10, 16],
 [1,  7,  6, 15],
 [5,  9, 13, 14]]

(weird spaces are to align the numbers in nice columns)
The outer "ring" of the matrix rotates 2 counterclockwise, and the inner right rotates 2 also.  In this matrix, there are only two rings.
An example with 1 "ring":
2
[[1, 2],
 [3, 4],
 [5, 6]]

Should output:
[[4, 6],
 [2, 5],
 [1, 3]]

Your challenge is to take in a matrix and an integer R, and output the translated version after R rotations.
Rotation of a 4x5 matrix is represented by the following figure:

Constraints:

2 ≤ M, N ≤ 100, where M and N are the dimensions of the matrix. It is guaranteed that the minimum of M and N will be even.
1 ≤ R ≤ 80, where r is number of rotations.
The matrix will only ever contain positive integers.
Values are not always distinct.
The input should always be as a 2D array (if you can't take runtime input as a 2D array, then you just have to find another way to get input).

Another test case, with non-distinct values:
1
[[1, 1],
 [2, 2],
 [3, 3]]

Outputs:
[[1, 2],
 [1, 3],
 [2, 3]]

This is code-golf, so the shortest answer wins!

Related

Related.

Why is there "1 ≤ R ≤ 80, where r is number of rotations", when the rest of the challenge appears to always have R = 2? Is it always 2, or is there an additional integer in the input?

Related.

@ceasedtoturncounterclockwis Your name is very ironic for this challenge...

What if I get 1xn or nx1 brick in the middle of the matrix? How do I rotate it? (you get one if both M and N are odd numbers).

@MrScapegrace 2 ≤ M, N ≤ 100, where M and N are the dimensions of the matrix. It is guaranteed that the minimum of M and N will be even.

[[3,  4,  8, 12],  [2, 11, 10, 16],  [1,  7,  6, 16], [5,  9, 13, 14]] the 16 is suddenly duplicated I guess it should be: [[3,  4,  8, 12], [2, 11, 10, 16], [1,  7,  6, 15], [5,  9, 13, 14]]?

Jelly, 39 38 36 35 bytes
ḢṚ;Ḣ€;Ṫ;Ṫ€Ṛ$,-ṙ\;"ß¹¡
FJ©ṁ¹Çy®ịFṁµ¡

Try it online!

Octave, 210 bytes
function M=F(M,R);f=@(z)[-z/2:-1 !eye(!!mod(z,2)) 1:z/2];t=angle(f([x y]=size(M))'+f(y)*i);B=!!M;B(2:x-1,2:y-1)=0;d=bwdist(B,'ch');[~,I]=sortrows([d(:) t(:)]);for k=0:max(d(:));M(h)=shift(M(h=I(d(I)==k)),R);end

Try it on Octave Online!
Ungolfed version:
function M=F(M,R)
    [x y]=size(M);
    f=@(z)[-z/2:-1 !eye(!!mod(z,2)) 1:z/2];
    t=angle(f(x)'+f(y)*i);
    B=!!M;
    B(2:x-1,2:y-1)=0;
    d=bwdist(B,'chessboard');
    [~,I]=sortrows([d(:) t(:)]);
    for k=0:max(d(:))
        M(h)=shift(M(h=I(d(I)==k)),R);
    end
end
R=2;
M=randi(10,4,7)
F(M,R)

Explanation:
f=@(z)[-z/2:-1 !eye(!!mod(z,2)) 1:z/2];

A function that gets a number and generates a range that is ordered and centered
for input 4 (even) generates  -2  -1   1   2
for input 5(odd) generates -2.5 -1.5 0  1  2
only it should be ordered and centered
f(x)'+f(y)*i

a complex matrix generated from ranges
(-2,-2.5) (-2,-1.5) (-2,0) (-2,1) (-2,2)
(-1,-2.5) (-1,-1.5) (-1,0) (-1,1) (-1,2)
(1,-2.5)  (1,-1.5)  (1,0)  (1,1)  (1,2)
(2,-2.5)  (2,-1.5)  (2,0)  (2,1)  (2,2)

t=angle(f(x)'+f(y)*i);

Convert rectangular to polar coordinates and return angles so for each ring angles are sorted counteclockwise
-2.25  -2.50  3.14  2.68  2.36
-1.95  -2.16  3.14  2.36  2.03
-1.19  -0.98  0.00  0.79  1.11
-0.90  -0.64  0.00  0.46  0.79

B=!!M;
B(2:x-1,2:y-1)=0;

The following matrix generated
1   1   1   1   1
1   0   0   0   1
1   0   0   0   1
1   1   1   1   1

d=bwdist(B,'chessboard');

Computes the distance transform of B using chessboard distance to generate ring indices
0   0   0   0   0
0   1   1   1   0
0   1   1   1   0
0   0   0   0   0

for a 6 * 7 matrix we will have the following matrix
0   0   0   0   0   0   0
0   1   1   1   1   1   0
0   1   2   2   2   1   0
0   1   2   2   2   1   0
0   1   1   1   1   1   0
0   0   0   0   0   0   0

[~,I]=sortrows([d(:) t(:)]);

lexicographic sort first based on ring index and then by order of angle(indices of sorted elements returned)
    for k=0:max(d(:))
        M(h)=shift(M(h=I(d(I)==k)),R);
    end

and finally circular shift each ring.

Python 3, 292 288 bytes
_=eval
a=input().split()
b,a=int(a[0]),_("".join(a[1:]))[::-1]
c=len(a)
d=len(a[0])
e=range
f="int((i>=j and i+j<c-1)|2*(i>=c/2and i+d>j+c)|3*(i<c/2and i+j<d))"
l=[-1,1,0,0],[0,0,1,-1]
g=lambda x:[[x[i+l[0][_(f)]][j+l[1][_(f)]]for j in e(d)]for i in e(c)]
print(_("g("*b+"a"+")"*b)[::-1])

Takes input with newlines removed, but leaving a space after the number of increments to rotate it by.
Explanation:
Instead of modeling the matrix as a series of concentric rings per the OP's suggestion, one can instead divide it into four regions where the elements travel either up, down, right, or left during a single rotation. This is the purpose of the long eval-ed string f: to determine which region each i,j combination falls into. Then, the result of that is looked up twice in l, giving the element that must rotate into position i,j in the next step. The function g that does all of this and forms the new matrix after a single step is then called repeatedly by evaling a generated string containing the representation of a nested function call.
When I made this originally, I accidentally caused the matrix to rotate clockwise instead of counterclockwise. Rather than doing a proper fix, I added two strategically placed copies of [::-1] to reverse the matrix before and after the rotation. These could probably be golfed off to ~280 276 bytes, but I'm too lazy to do that.
Also, this is a quick untested port from a slightly longer Python 2 program, so forgive me if it doesn't work quite right. Here's the Python 2 code, anyways:
_=eval
a=raw_input().split()
b,a=int(a[0]),_("".join(a[1:]))[::-1]
c=len(a)
d=len(a[0])
e=xrange
f="int((i>=j and i+j<c-1)|2*(i>=c/2and i+d>j+c)|3*(i<c/2and i+j<d))"
l=[-1,1,0,0],[0,0,1,-1]
g=lambda x:[[x[i+l[0][_(f)]][j+l[1][_(f)]]for j in e(d)]for i in e(c)]
print _("g("*b+"a"+")"*b)[::-1]

EDIT: Golfed off 4 bytes by replacing or with | twice. and can't be helped, unfortunately.

Welcome to PPCG! Nice first post!

Funny story actually — in my high school marching band today we learned a formation where everyone moves in concentric rectangular "rings" similar to this question, and I immediately thought of this answer.

K (ngn/k), 78 76 60 64 bytes
-16 bytes from using @ngn's version
+4 because of changes in the language (prototypes)
{(,()){(,y),+|x}/|,/{1_{1_y,*x}':x,,*x}'0N 4#-1_*'(*:)(|+1_)\x}/

Try it online!

{...}/ use the "do" variant of / to run the function x times, seeded with y and returning the last result. (each iteration rotates each ring of the input matrix one position)
(*:)(|+1_)\x peel off the first row, rotating the remainder until there's nothing left, accumulating the results into a list
-1_*' take the first item of each (i.e. the "top-most" slice of the outer ring). drop the last item, as it's empty
0N 4# reshape the flat list into groups of four items; each group represents one "ring" of the input matrix
{...}' for each ring...

x,,*x append a copy of the first ring slice
1_{1_y,*x}': for each slice of the ring, append the first item of the current slice to the previous slice, dropping the first value of the result. (this has the effect of rotating the values in each ring one position)

(,()){...}/|,/ set up a /, seeded with an empty list and run over the flattened and reversed ring slices...

(,y),+|x where we prepend each ring slice to the rotated and transposed result so far

Perl, 330 328 bytes
sub f{($r,$m)=@_;$h=@m=@$m;for$s(0..(($w=$#{$m[0]})<--$h?$w:$h)/2-.5){@_=(@{$m[$s]}[@x=$s..($x=$w-$s)],(map$m[$_][$x],@y=1+$s..($y=$h-$s)-1),reverse(@{$m[$y]}[@x]),(map$m[$h-$_][$s],@y));push@_,shift
for 1..$r;@{$m[$s]}[@x]=map shift,@x;$m[$_][$x]=shift for@y;@{$m[$y]}[@x]=reverse map shift,@x;$m[$h-$_][$s]=shift for@y}@$m=@m}

Try it on Ideone.
Ungolfed:
sub f {
    my ($r, $m) = @_;

    my @m = @$m;
    my $h = $#m;
    my $w = @{$m[0]} - 1;
    my $c = (($w < $h ? $w : $h) + 1) / 2 - 1;

    for my $s (0 .. $c) {
        my $x = $w - $s;
        my $y = $h - $s;
        my @x = $s .. $x;
        my @y = $s + 1 .. $y - 1;

        # One circle.
        @_ = (@{$m[$s]}[@x],
              (map { $m[$_][$x] } @y),
              reverse(@{$m[$y]}[@x]),
              (map { $m[$h - $_][$s] } @y));

        # Circular shift.
        push(@_, shift(@_)) for 1 .. $r;

        @{$m[$s]}[@x] = map { shift(@_) } @x;
        $m[$_][$x] = shift(@_) for @y;
        @{$m[$y]}[@x] = reverse(map { shift(@_) } @x);
        $m[$h - $_][$s] = shift(@_) for @y;
    }

    @$m = @m;
}

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Numbers that are palindromes in N bases
Given an non-negative integer \$n \ge 0\$, output forever the sequence of integers \$x_i \ge 3\$ that are palindromes in exactly \$n\$ different bases \$b\$, where the base can be \$2 \le b le x_i-2\$.
This is basically the inverse of OEIS A126071, where you output which indices in that sequence have the value \$n\$. It's a bit different, because I changed it so you ignore bases \$b = x_i-1, \: x_i, \: x_i+1\$, since the results for those bases are always the same (the values are always palindromes or always not). Also, the offset is different.
\$x_i\$ is restricted to numbers \$\ge 3\$ so that the first term of the result for each \$n\$ is A037183.
Note that the output format is flexible, but the numbers should be delimited in a nice way.
Examples:
n   seq
0   3 4 6 11 19 47 53 79 103 137 139 149 163 167 ...
1   5 7 8 9 12 13 14 22 23 25 29 35 37 39 41 43 49 ...
2   10 15 16 17 18 20 27 30 31 32 33 34 38 44 ...
3   21 24 26 28 42 45 46 50 51 54 55 56 57 64 66 68 70 ...
4   36 40 48 52 63 65 85 88 90 92 98 121 128 132 136 138 ...
5   60 72 78 84 96 104 105 108 112 114 135 140 156 162 164 ...
10  252 400 420 432 510 546 600 648 784 800 810 816 819 828 858 882 910 912 1040 1056 ...

So for \$n=0\$, you get the output of this challenge (starting at \$3\$), because you get numbers that are palindromes in n=0 bases.
For \$n=1\$, \$5\$ is a palindrome in base \$2\$, and that's the only base \$2 \le b \le (5-2)\$ that it's a palindrome in. \$7\$ is a palindrome in base \$2\$, and that's the only base \$2 \le b \le (7-2)\$ that it's a palindrome in. Etc.

Iff your language does not support infinite output, you may take another integer z as input and output the first z elements of the sequence, or all elements less than z. Whichever you prefer. Please state which you used in your answer if this is the case.
Related

To be 100% clear, the numbers that are output must be palindromes in exactly n bases, not n or more bases?

Yes. That is correct. So the union of all sequences for all values of n is the set of integers >=3.

Jelly,  18  15 bytes
-1 thanks to caird coinheringaahing.
ṄµbḊŒḂ€S’⁼³µ¡‘ß

Try it online! - the online interpreter will timeout at 60 seconds then flush it's output (unless it has a cached copy), offline it will print each in turn.
How?
Evaluates numbers from n up, printing them if they are in the sequence. Note that the first number in any output will be greater than n since otherwise the range of b is not great enough, so there is no need to seed the process with 3. Also note that the number of palindromes from base 2 to xi-2 inclusive is just one less than the number of palindromes from base 2 to xi.
ṄµbḊŒḂ€S’⁼³µ¡‘ß - Main link: n
            ¡   - repeat...
Ṅ               - ...action: print (the CURRENT n)
 µ         µ    - ...number of times: this monadic chain:
   Ḋ            -      deueue -> [2,3,4,...,n]
  b             -      n converted to those bases
    ŒḂ€         -      is palindromic? for €ach
       S        -      sum: counts the 1s
        ’       -      decrement: throw away the truthy base n-1 one
         ⁼³     -      equals input: Does this equal the ORIGINAL n?
             ‘  - increment n
              ß - calls this link as a monad, with the incremented n.

-1 byte

Thanks @cairdcoinheringaahing, saved a couple more.

Mathematica, 80 71 bytes
Thanks to JungHwan Min for saving 9 bytes!
Do[#!=Length[i~IntegerReverse~Range[2,i-2]~Cases~i]||Echo@i,{i,3,∞}]&

(∞ is the three-byte character U+221E.)
Pure function taking a nonnegative integer as input. i~IntegerReverse~Range[2,i-2] creates a list of the reversals of the number i in all the bases from 2 to i-2; then Length[...~Cases~i] counts how many of these reversals are equal to i again. #!=...||Echo@i halts silently if that count is not equal to the input, and echoes i if it is equal to the input. That procedure is embedded in a straightforward infinite loop.

Clever use of short-circuit evaluation! The Echo@i term is not evaluated when the first argument is True. Can I add this to Tips for golfing in Mathematica?

By the way, Do[...,{i,3,∞}] is shorter than (i=2;While[1>0,... ++i ...]), and Cases would work instead of Position. -9 bytes: Do[#!=Length[i~IntegerReverse~Range[2,i-2]~Cases~i]||Echo@i,{i,3,∞}]&

Yes, please do add the tip!—I'm surprised it's not already in there, since I definitely learned it from this site somewhere....

Cases works great in place of Position. But I tested the Do construction, and it doesn't work for me but I have no idea why not. For some reason, it doesn't plug in the i values—I get errors like "Range specification in Range[2,-2+i] does not have appropriate bounds.". (And inserting a Print[i]; verifies that i isn't being assigned values.) Any ideas?

Apparently, there were U+200B and U+200C in the code, between , and { (probably something to do with SE's system). That breaks the code because the characters are considered a variable. I hope this doesn't have it: Do[#!=Length[i~IntegerReverse~Range[2,i-2]~Cases~i]||Echo@i,{i,3,∞}]& EDIT: Still has it. Here's a pastebin link

Pyth, 21 19 18 bytes
.V3IqQlf_IjbTr2tbb

This should work in theory. It works properly if I substitute the infinite loop for any finite one (e.g. JQFbr3 50*`bqJlf_IjbTr2tb for 3 up to 50, try here), but the Pyth interpreter doesn't know when or how to print literally infinite output.
Explanation:
.V3IqQlf_IjbTr2tbb
.V3                     increase b infinitely, starting from 3
             r2Tb       range of integers including 2 to b - 2
      lf                length of elements retained if:
          jbT             b in that base
        _I                is invariant under reversal
    qQ                  check if the length is equivalent to the input
   I             b      output b if so

Perl 6, 90 bytes
->\n{->{$_=++($ //=2);$_ if n==grep {($/=[.polymod($^b xx*)])eq[$/.reverse]},2..$_-2}...*}

Try it
-> \n {

  # sequence generator
  ->{         # using a code block with no parameter

    $_ =      # set the default scalar to the value being tested
      ++(     # preincrement
        $     # anonymous state variable
        //= 2 # initialized to 2
      );

    # the anonymous state var maintains its state
    # only for this current sequence
    # every time the outer block gets called it is created anew

    $_    # return the current value
      if  # if the following is true

        n == grep # find all that match the following code

          {
            # convert the current value to the base being tested
            # store as an Array in $/
            ($/ = [ .polymod($^b xx*) ] )

            eq    # is string equal to: (shorter than eqv)

            [ $/.reverse ]
          },

          2 .. $_ - 2 # from the list of bases to test
  }

  ...  # keep using that code block to produce values

  *    # indefinitely
}

Bash + Unix utilities, 134 132 bytes
for((x=3;;x++)){
c=$1
for((b=x-1;--b>1;)){
s=`bc<<<"for(y=$x;y;y/=$b)y%$b"`
t=`tac<<<"$s"`
[ "${s#$t}" ]||((c--))
}
((c))||echo $x
}

Try it online!
Input is passed as an argument. The output is on stdout.
If you run this normally, it will display one number at a time in the infinite sequence.
If you try this in TIO, it will display as much of the output as it has generated when it times out at 60 seconds.

Python 2, 132 bytes
B=lambda n,b:[]if(n<1)else B(n/b,b)+[n%b]
n=input()
x=3
while 1:
    if sum(B(x,b)==B(x,b)[::-1]for b in range(2,x-1))==n:print x
    x+=1

Try it online
The TIO program has a footer added so you don't have to wait 1 minute for the program to time out before seeing the output.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Find the temperature closest to 0
In this exercise, you have to analyze records of temperature to find the closest to zero.
Write a program that prints the temperature closest to 0 among input data.
Input

N, the number of temperatures to analyse (optional). This will be nonzero.
The N temperatures expressed as integers ranging from -273 to 5526.

Output
Output the temperature closest to 0. If two temperatures are equally close, take the positive one. For instance, if the temperatures are -5 and 5, output 5.
Example
Input

    5
    1 -2 -8 4 5

Output

    1

This challenge is similar to this one on CodinGame, you can view the problem statement source here.
Some modifications have been made to the text.

Mirror of CodinGame problem statement. The site might not appreciate having solutions be made publicly available. I'm not sure what our current consensus is on problems taken from elsewhere. The problem isn't copy-pasted but some of your text is taken verbatim.

Our current consensus is that it's on-topic, however attribution is required and probably should be edited into the post.

I've edited in most of the original problem statement, it's probably best to include as much of the original text as possible. Also, if you could link directly to the problem (the interactive part), that would be great.

@Riker that edit has changed the problem being asked. The input formats are stricter and there is a special case for no input

@muddyfish better?

@Riker I think so

I made the count input optional.

Python, 35 bytes
lambda l:max((-x*x,x)for x in l)[1]

Try it online!
Narrowly beats:
lambda l:min(l,key=lambda x:2*x*x-x)
lambda l:min(sorted(l)[::-1],key=abs)

why would you need to sort l in the second narrowly beaten one?

sorting it into descending order ensures the positive values come first and that min favours a positive smallest absolute value over a negative one (e.g. to prevent cases like min([-1, 1],key=abs))

JavaScript (ES6), 33 bytes
a=>a.reduce((m,n)=>n*n-n<m*m?n:m)

Demo

let f =

a=>a.reduce((m,n)=>n*n-n<m*m?n:m)

console.log(f([1, -2, -8, 4, 5]))

Jelly, 4 bytes
AÐṂṀ

Try it online!
How it works
AÐṂṀ  Main link. Argument: A (array)

AÐṂ   Take all elements with minimal absolute value.
   Ṁ  Take the maximum. Yields 0 for an empty list.

You called ????

And ADMM once again solves an minimization problem.

Brachylog (2), 5 or 2 bytes
~{≜∈}

Try it online!
It wouldn't surprise me if there were a shorter solution along the lines of the Jelly or Pyke, but I like this one because it's so weird.
This is simply Brachylog's "find a list containing the input" operator ∈, with an evaluation strategy ≜ that simply tries explicit values for integers until it finds one that works (and it happens to try in the order 0, 1, -1, 2, -2, 3, etc., which is surprisingly handy for this problem!), and inverted ~ (so that instead of trying to find an output list containing the input, it's trying to find an output contained in the input list). Unfortunately, inverting an evaluation strategy along with the value itself costs 2 bytes, so this doesn't beat the Jelly or Pyke solutions.
There's also a dubious 2-byte solution ≜∈. All Brachylog predicates take exactly two arguments, which can each be inputs or outputs; by convention, the first is used as an input and the second is used as an output, but nothing actually enforces this, as the caller has complete control over the argument pattern used (and in Prolog, which Brachylog compiles to, there's no real convention about argument order). If a solution which takes input through its second argument and produces output through its first argument is acceptable, there's no requirement to do the inversion.

I had written a meta posted about using Input as Output and vice-versa. My view is that it's kinda cheaty because ? and . are not exactly symetrical in the code (notably, one is available on the left and one on the right). Though in a Prolog sense there is really nothing wrong with it.

R, 31 bytes
(l=scan())[order(abs(l),-l)][1]

Try it online!

C++14, 64 bytes
As unnamed lambda, expecting first argument to be like vector<int> and returing via reference parameter.
[](auto L,int&r){r=L[0];for(int x:L)r=x*x<=r*r?r+x?x:x>r?x:r:r;}

Ungolfed and usage:
#include<iostream>
#include<vector>

auto f=
[](auto L,int&r){
  r=L[0];
  for(int x:L)
    r = x*x<=r*r ?   //x is absolute less or equal
      r+x ?          //r==-x?
        x :          //no, just take x
        x>r ?        //take the positive one
          x :
          r      :
      r              //x was absolute greater, so keep r
    ;
}
;

int main(){
 std::vector<int> v = {5, 2, -2, -8, 4, -1, 1};
 int r;
 f(v,r);
 std::cout << r << std::endl;
}

That might be the most beautiful C++ one-liner I've ever seen

Using the abs built-in function for ints, you can replace the for loop content with r=x*x<r*r|x==abs(r)?x:r; which is 5 characters shorter

Pyke, 4 bytes
S_0^

Try it online!
S_   - reversed(sorted(input))
  0^ - closest_to(^, 0)

MATL, 9 6 bytes
0iSPYk

Try it online!
Thanks to Luis Mendo for pointing out there's actually a built-in for this in MATL, which is not present in MATLAB.
 i     % Take input
  S    % Sort
   P   % Reverse to have largest value first.
0   Yk % Closest value to zero, prioritizing the first match found

If you wish to follow the spec and also provide the number of temperatures to be read, this should be given as the second input, and will be silently discarded.

I think OiSPYk works for 6 bytes

@LuisMendo Yes of course - no idea there was a built-in for that. I should really check the function table more often, perhaps highlight the things that ordinary MATLAB doesn't have.

Most MATL functions actually are taken from Matlab. There are only a few that don't correspond to Matlab functions

@LuisMendo I know - I usually write my MATL programs in MATLAB first because I find it more readable. But this is the second time I could have saved a lot with a built-in MATL-only function, so I should be careful not to write my programs too MATLAB-centric. Thanks for the tip, nonetheless.

Mathematica, 21 19 bytes
Max@*MinimalBy[Abs]

Composition of functions. Takes a list of integers as input and returns an integer as output.

Japt -g, 3 bytes
ña¼

Try it online!
Japt, 5 bytes
ña¼ v

Try it online!

Shouldn't the flag be added to the byte count? Especially since the answer doesn't work correctly without it?

@Nit The recent consensus on Meta is that each invocation of a flag is considered a separate language. Thus, it is not counted towards the byte count. My submission is technically considered a Japt -g answer, not Japt.

You don't need the 1.

@Shaggy Actually I don't think it's correct with or without the 1: with, it fails on [1, 0] (giving 1), without, it fails on [-1, 1] (giving -1). I believe ña¼ may be the most correct way to do it.

@ETHproductions, I'd missed the part about outputting a postive integer in the case of a tie.

@ETHproductions Thanks, fixed.

Perl 5 -p, 21 bytes
Added +1 for -p since this challenge precedes "options don't count"
$G[abs]=$_}{$_+="@G"

Try it online!

This solution violates the condition "If two temperatures are equally close, take the positive one", it takes simply the last one instead.

Haskell, 29 bytes
snd.maximum.map(\x->(-x^2,x))

Usage example: snd.maximum.map(\x->(-x^2,x)) $ [1,-2,-8,4,5]-> 1.
Map each element x to a pair (-x^2,x). Find the maximum and pick the 2nd element from the pair.

05AB1E, 16 bytes
Îåà_Di¹{RDÄßs\kè

Explanation:
Î                 Push 0 and [implicit] input array
 å                For each element in the array, is it a 0?
  à               Find the greatest value (1 if there was a 0 in it, 0 otherwise)
   _              Negate boolean (0 -> 1, 1 -> 0)
    D             Duplicate
     i            If true, continue
      ¹           Push input
       R          Reversed
        D         Duplicated
         Ä        Absolute value
          ß       Greatest element
           s      Swap top two values in stack
            \     Delete topmost value in stack
             k    Index of greatest element in the array
              è   Value of the index in the input array

Try it online!
Not at short as I'd like, but at least it works.

Java 8, 63 39 bytes
s->s.reduce(1<<15,(r,i)->r*r-r<i*i?r:i)

Port from @Arnauld's JavaScript answer. I couldn't find anything shorter..
-10 bytes converting Java 7 to 8,
and another -24 bytes thanks to @OlivierGrégoire.
Explanation:
Try it online.
s->                   // Method with IntStream parameter and int return-type
  s.reduce(1<<15,     //  Start `r` at 32768 (`32768^2` still fits inside a 32-bit integer)
     (r,i)->r*r-r<i*i?//  If `r^2 - r` is smaller than `i^2`:
       r              //   Leave `r` the same
      :               //  Else:
       i)             //   Replace the current `r` with `i`
                      //  Implicitly return the resulting `r`

Given that there was a dupe of this question recently, time to undust this one with 39 bytes: s->s.reduce(1<<15,(a,b)->a*a-a<b*b?a:b)

@OlivierGrégoire Thanks. Was looking at this answer myself after it was closed as a dupe and noticed the reduce in Arnauld's JS answer, but you beat me to it (and I forgot about it again after come colleagues came asking questions ;) ).

PHP, 81 bytes
two solutions: the first one requires an upper bound; both require all temperatures nonzero.
for($r=9e9;$t=$argv[++$i];)abs($t)>abs($r)|abs($t)==abs($r)&&$t<$r?:$r=$t;echo$r;
for(;$t=$argv[++$i];)$r&&(abs($t)>abs($r)|abs($t)==abs($r)&&$t<$r)?:$r=$t;echo$r;

Run with -r, provide temperatures as command line arguments.
A lazy solution for 92 bytes:
$a=array_slice($argv,1);usort($a,function($a,$b){return abs($a)-abs($b)?:$b-$a;});echo$a[0];

defines a callback function for usort and uses it on a slice of $argv.

Perl 6, 15 bytes
*.min:{.²,-$_}

Try it online!

JavaScript (Node.js), 30 bytes
a=>a.sort((a,b)=>a*a-a>b*b)[0]

Try it online!

Why -a is there?

Why fail [-273, 43]

Octave, 28 bytes
@(x)max(x(min(a=abs(x))==a))

Try it online!
Finds the smallest absolute value (min(a=abs(x))), then maps it back to which elements have that smallest absolute value in case of a tie (x(...==a)). Finally takes the maximum value of the results (max(...)) to ensure that in the event of a tie we get one result which is the positive one.

PHP, 209 Bytes
Not really golfed, but wanted to try to use mostly array functions, avoiding loops
Try it Online!!
Code
function f($a){$a[]=0;sort($a);$k=array_search(0,$a);$o=array_slice($a,$k+1);$u=array_reverse(array_diff($a,$o));if($u[1]&&$o[0]){$r=(abs($u[1])<abs($o[0]))?$u[1]:$o[0];}else{$r=($u[1])?$u[1]:$o[0];}return$r;}
Explanation
function f($a){
$a[]=0;                                #As all nonzero values, 0 is pushed
sort($a);                              #Sorting the array
$k=array_search(0,$a);                 #Search where zero is
$o=array_slice($a,$k+1);               #Array with all values >0
$u=array_reverse(array_diff($a,$o));   #Array with all smaller than zero values
                                       #Array has ascending order so it gets reversed
if($u[1]&&$o[0]){                      #if both are set we just compare the abs value
    $r=(abs($u[1])<abs($o[0]))?$u[1]:$o[0];
}else{
    $r=($u[1])?$u[1]:$o[0];            #al least one of them will allways be set
                                       #the first value is always returned
                                       #the 0 value on $u is not usetted that why $u[1]
}
return $r;
}

Julia 0.6, 29 bytes
x->sort(x,by=x->abs(x-.1))[1]

Sort by the absolute value of the temperature, but subtract .1 first to ensure positive temperatures always win.
Try it online!

25 bytes

05AB1E, 5 bytes
{R0.x

Try it online.
Or alternatively:
ÄWQÏà

Try it online.
Explanation:
{      # Sort the (implicit) input-list lowest-to-highest
 R     # Reverse it to highest-to-lowest
  0.x  # Pop and push the item closest to 0
       # (after which the result is output implicitly)

Ä      # Get the absolute value of each in the (implicit) input-list
 W     # Push the minimum (without popping the list)
  Q    # Check which are equal to this minimum
   Ï   # Only keep the values in the (implicit) input-list at the truthy indices
    à  # Pop and push the maximum of the remaining values
       # (after which the result is output implicitly)

Thunno 2 h, 4 bytes
ṠrþA

Try it online!
Explanation
ṠrþA  # Implicit input
Ṡr    # Reverse-sort
  þA  # Sort by |x|
      # Take the first item
      # Implicit output

Vyxal G, 20 bitsv2, 2.5 bytes
⁽ȧP

Try it Online!
Finds the minimum in the list by absolute value

Python, 62 bytes
def f(n):
    r=min(map(abs,n))
    return r if r in n else -r

It feels like there is a much simpler/shorter solution.

Can be shortened to: def f(n):r=min(map(abs,n));return r if r in n else -r

C (clang), 74 bytes
k,m;f(*i,n){for(k=*i;--n>0;k=(k*k>m*m||(k==-m&&k<m))?m:k)m=i[n];return k;}

Try it online!

66 bytes

Stax, 6 bytes
¢M║⌠§☺

Run and debug it at staxlang.xyz!
Unpacked (6 bytes) and explanation
{|a}eoH
{  }e      Get all elements of array producing the minimum value from a block.
 |a          Absolute value.
     o     Sort ascending.
      H    Take last. Implicit print.

Pyth, 4 bytes
.m.a

Try it online!
Explanation:
.m.a   #Code
.m.abQ #With implicit variables
.m   Q #Filter input list for values b with minimal value of the following:
  .ab  #Absolute value of b

Python 3, 31 bytes
a=lambda q:sorted(q,key=abs)[0]

Try it online!
Sorts items by absolute value and prints the first element.

This appears to fail if the list has two values with the same abs, and the negative first (like [5,-2,2] which should return 2, but appears to return -2)

@brhfl I tested that and I got the positive number. I’ll try it again later today

Depends on the order in the original array. If -2 is befor 2 it will print -2 in the example of @mrhfl

SmileBASIC, 56 bytes
DEF Z N,T
RSORT T
DIM V[N]ARYOP 2,V,T,T
SORT V,T?T[0]END

First, the input list is sorted, so the positive temperature will be chosen if there's a tie. Then each temperature is squared and stored in another array. The original array is sorted by this array, and the first item is printed.

Avail, 88 bytes
Method"f_«_»"is[c:[1..∞),t:integer*|quicksort a,b in t[1..c] by[|a-0.1|<|b-0.1|][1]]

Approximate deobfuscation:
Method "nearest to zero among first _ of «_»" is
[
    count : natural number,
    temps : integer*
|
    (quicksort a, b in temps[1..count] by [|a-0.1| < |b-0.1|])[1]
]

The pattern syntax in the method's name, f_«_», will read the initial count as a natural number (whose type is abbreviated above as the range type [1..∞)) separate from the collected tuple of subsequent integers.
All that remains for the body is to sort by a custom comparator. Here we escape the need for a second-level comparison between x and -x by shifting the values slightly towards -∞.

Welcome to the site! Could you perhaps edit in a link to a site where others can test your submission, such as an online IDE?

I'm not sure an online sandbox is feasible quite yet (as I understand it, the expressiveness of the language requires different approaches to parsing and compilation), but point taken! Are there any site requirements for online reproducibility?
I'm partaking as part of my learning, and to share what I've learned, not to "win" by any means.

dc, 53 bytes
Fd^sr[d*v]sA[ddlr+0=Asr]sR[dlAxlrlAx!<Rs_z0<M]dsMxlrp

Try it online!
We're going to use the register r to hold our final result, so the first thing we need to do is put a too-big number in there so that our first comparison always succeeds. I think the largest number we can push in two bytes is 165 (which is less than the required 5526), but Fd^ gives us 15^15 which is plenty large. Macro A, [d*v]sA just does the square root of the square to give us absolute value.
Macro R handles putting a value into register r; we'll come back to it in a second. Macro M, [dlAxlrlAx!<Rs_z0<M]dsMx is our main macro. Duplicates the value on the stack, runs A to get ABS, then pushes the value in r and does the same. !<R checks to see if ABS(r) is greater than or equal to not less than ABS(top of stack), and if so it runs R. Since we had to leave behind a copy of the original top of stack for R to potentially use, we store to a useless register (s_) to pop it. z0<M just loops M until the stack is empty.
Macro R, [ddlr+0=Asr]sR duplicates the top of stack twice (we need to leave something behind for M to gobble up when we return). At this point we know that of the two absolute values, our new value is less than or equal to our old value. If they're equal, and one is positive and the other is negative, we always need the positive. Fortunately, knowing this we can easily check for the case of one being the inverse of the other by simply adding them and comparing to 0. If so, we run A, and no matter what else happened we know we're storing whatever is left in r.
After M has gone through the whole stack, we load r and print it.

Octave, 19 bytes
@(x)min(complex(x))

Try it online!
This exploits the fact that min with complex input compares by absolute value, then by angle:

For complex arguments, the magnitude of the elements are used for comparison. If the magnitudes are identical, then the results are ordered by phase angle in the range (-pi, pi].

C#, 171 bytes
using static System.Console;using System.Linq;class s{static void Main()=>Write(ReadLine()=="0"?0:ReadLine().Split(' ').Select(int.Parse).OrderBy(v=>v*(.1-v)).Last());}

Try it online!

Headass, 56 bytes
O{ON-)+E:U}.U+OUO[{UO(])P:N(+)+E:}.UO[U-O{UO(])P:N(+)E:}

Try It Online!
Increments / decrements a pair of counters until the value of the counter matches one of the inputs, with the positive counter having the first go (after 0 of course) to prioritize it over negative answers.
Positive counter hereby referred to as +counter and negative counter as -counter
Code breakdown:
O{ON-)+E:U}.  code block 0
O O           initialize both counters to 0
 {ON-)  :U}   put all inputs on the queue
      +E      then move to code block 1
           .  end code block

U+OUO[{UO(])P:N(+)+E:}.  code block 1 (-counter, starting at 0)
U+O                      increment +counter and put back on queue
   UO[                   store 0/-counter to r2 and put back on queue
      {       N(+)  :}   for each input
       UO                  enqueue input
         (])               if input is equal to 0/-counter
            P:               print value and halt
                  +E     then go to code block 2
                      .  end code block

UO[U-O{UO(])P:N(+)E:}    code block 2 (+counter, starting at 1)
UO[                      store +counter to r2 and put back on queue
   U-O                   decrement -counter and put back on queue
      {       N(+) :}    for each input
       UO                  enqueue input
         (])               if input is equal to +counter
            P:               print value and halt
                  E      then go to code block 1

I tried doing this with only 2 code blocks, 1 to init and one to handle both counters, but that meant that whichever value came first between positive and negative would win, which is wrong. There might be additional logic that could be added to such a loop which, combined with some more logic-golfing, could be shorter than this version, but i still think its pretty good.

J-uby, 12 bytes
:min_by+:abs

Attempt This Online!

APL (Dyalog Unicode), 16 bytes
{⌈/⍵/⍨a=⌊/a←|¨⍵}

Try it on TryAPL.org!


text:
Order of Mia Sets
The dice game Mia introduces a very non-trivial order of sets of size two:
{3,1} < {3,2} < {4,1} < {4,2} < {4,3} < {5,1} < {5,4} < {6,1} < {6,5} < {1,1} < {2,2} < {6,6} < {1,2}

In general, the order within a tuple does not matter {x,y}={y,x},
{1,2} is greater than anything else,
Pairs are greater than non-pairs and the numeric value decides in case of a tie.
Now suppose you want to use n dice. Also, the dices have m faces.
Example:

{1,5,3,4} < {1,2,6,3} since 5431 < 6321
{1,2,3,5} < {1,1,5,6} < {1,1,5,5}, {1,1,6,6} < {1,1,1,3} < {2,2,2,3} < {1,1,1,1} < {1,2,3,4}
{2,2,5} < {1,1,6} since both sets have each one pair and 611 > 522

In a nutshell, {1, ..., n} is greater than anything else.
Let p > q, then p-of-a-kind is greater than q-of-a-kind.
In case of a tie, the second(, third, ...)-longest of-a-kind wins.
Finally, if no decision could be made yet, the greatest numerical value wins.
The numerical value of a set is the largest integer you can build from the available numbers in the set, using concatenation. Example:

{2,5,4,3} becomes 5432
{4,11,3,4} becomes B443 (>6-faced dice are allowed, B=11)

Your task is to write the smallest possible program (i.e. function) in the language of your choice, that, given two containers (list, array, set, ...) returns whether the first or the second one wins.
Note: you can assume that the two containers have the same length and contain only positive integers, but nothing else. Especially they may be not sorted. The return value could be anything, e.g. {-1, 0, 1} for {first wins, tie, second wins}.

Which one wins of {1,1,6}, {2,2,5}? Do you compare the numerical value of the largest p-of-a-kind or of any dice?

Let me check if my understanding of the ordering is right: First, {1, ..., n} is highest. For each list, take the most common value, and of equally common values take the biggest one. If one list has more of that, it wins. If equally common, whichever is greater wins. If equal both in commonness and value, remove all those from each list and compare again.

@Martin: Excellent Question. I guess there is no "canonical" decision on that, and since my julia program says {1,1,6} wins over {2,2,5}, then it's just that.

@xnor: Yes, however consider martin's comment and my answer.

@oVooVo Oh yeah, that actually makes sense considering your example where you simply sort them by numerical value after sorting the digits from largest to smallest.

@oVooVo Now I'm confused. What order are things tiebroken in?

I find it somewhat hard to give a (formal) description of how the tie breaking works. I think it is unambiguous now, given the comments. Would you mind posting an ambiguous example?

Jelly, 16 bytes
ṢŒrUṢṚZ
Ṣ⁼J;ÇµÐṀ

Takes a list of lists each of which represents a roll (so can be more than two if wanted) and returns a list of the winner(s).
Try it online! ...alternatively here is a version which sorts the rolls from weakest to strongest instead.
How?
Ṣ⁼J;ÇµÐṀ - Main link: list of list of dice rolls, L
     µÐṀ - filter keep maximal (i.e. sort L by the previous link as a key and keep maximums)
         -                                            e.g. [5,3,1,3]
Ṣ        -     sort roll                                   [1,3,3,5]
  J      -     range(length(roll))                         [1,2,3,4]
 ⁼       -     equal? [1,2,3,...n] beats everything        0
    Ç    -     call last link as a monad with input roll   [[2,1,1],[3,5,1]]
   ;     -     concatenate                                 [0,[2,1,1],[3,5,1]]

ṢŒrUṢṚZ - Link 1, rest of sort key: dice rolls        e.g. [5,3,1,3]
Ṣ       - sort the roll                                    [1,3,3,5]
 Œr     - run length encode                                [[1,1],[3,2],[5,1]]
   U    - upend (reverse each)                             [[1,1],[2,3],[1,5]]
    Ṣ   - sort                                             [[1,1],[1,5],[2,3]]
     Ṛ  - reverse                                          [[2,3],[1,5],[1,1]]
      Z - transpose                                        [[2,1,1],[3,5,1]]
        -     ...this is a list of: 1) the group sizes descending; and
                 2) the face values of each group, descending across equal group sizes

@oVooVo While trying to golf this more I noticed that 1,1,2 and 1,2,2 are deemed equal, but the spec does not currently distinguish them either.

@oVooVo upon further inspection the example has {1,1,5,6} < {1,1,5,5} where 6 > 5. Could you clarify?

@oVooVo Maybe it should be like this - I have replaced the "maximal selection", ÐṀ, with a sort, Þ, for testing purposes - using the items from the example it sorts them into the same order. The ordering used is: first by if it's "top-dog", then by counts of equal faces descending and finally by unique faces descending.

{1,1,5,5} has two "2-of-a-kind": (1,1) and (5,5). {1,1,5,6} has only one "2-of-a-kind". Hence {1,1,5,5} wins. The value does not matter here. Similarly, {1,1,2,2} > {4,5,6,6}.

{1,2,2} > {1,1,2}. Because both have one 2-of-a-kind, numeric tie-breaking applies. {1,2,2}=>221 and {1,1,2}=>211. Obviously 221 is greater than 211. I will clarify this in the specs.

@oVooVo OK this is fixed up for that ordering.

JavaScript (ES6), 162 bytes
(a,b,g=a=>a.map(n=>e[n]=e[n]+1||1,e=[1])&&[[...e].every(n=>n==1),...e.filter(i=x=>x).sort(h=(a,b)=>b-a),...a.sort(h)],c=g(a),d=g(b))=>d.map((n,i)=>n-c[i]).find(i)

Explanation: Takes two arrays as parameters. g converts each array into a list of counts. The list is then checked to see whether it corresponds to a set 1..n. The counts are sorted and the sorted values are concatenated. The two results are then compared. The return value is a positive integer if the second array wins and a negative integer if the first array wins, otherwise the falsy JavaScript value undefined is returned.

Your program says {1,1,6} < {2,2,5}, which is wrong.

@oVooVo Sorry, I must have misunderstood the rules (I thought you broke ties based on the numeric value of the longest-of-a-kind).

Julia (489 Bytes)
function a(x,y)l=length;g=collect;s=sort;m=maximum;r=repmat;function b(z)w=sum(r(z,1,m(z)).==r(g(1:m(z))',l(z),1),1);u=zeros(m(w));map(i->if i>0 u[i]+=1;end,w);return u end;function c(x,y)if l(x)>l(y)return-1 elseif l(x)<l(y)return 1 else for i=l(x):-1:1 if x[i]>y[i] return-1 elseif x[i]<y[i] return 1 end end;return 0;end end;x=s(x);y=s(y);if x==y return 0;elseif x==g(1:l(x));return-1 elseif y==g(1:l(y))return 1 else d=c(b(x),b(y));if d==0 return c(x,y);else return d;end end end

Readable:
  1 function a(ds1, ds2)
  2     function countNOfAKind(ds)
  3         # return array. n-th value is number of occurences of n-of-a-kind.
  4         # e.g. findNOfAKind([1, 1, 1, 2, 2, 3, 3]) == [0, 2, 1]
  5         ps = sum(repmat(ds, 1, maximum(ds)) .== repmat(collect(1:maximum(ds))', length(ds), 1), 1);
  6         ls = zeros(maximum(ps));
  7         map(i -> if i>0 ls[i] += 1 end, ps);
  8         return ls
  9     end
 10
 11     function cmpLex(ds1, ds2)
 12         # compare ds1, ds2 reverse-lexicographically, i.e. compare last distinct value.
 13         if length(ds1) > length(ds2)
 14             return -1
 15         elseif length(ds1) < length(ds2)
 16             return 1
 17         else
 18             for i = length(ds1):-1:1
 19                 if ds1[i] > ds2[i]
 20                     return -1
 21                 elseif ds1[i] < ds2[i]
 22                     return 1
 23                 end
 24             end
 25             return 0;
 26         end
 27     end
 28
 29     ds1=sort(ds1);
 30     ds2=sort(ds2);
 31     if ds1 == ds2
 32         return 0;
 33     elseif ds1 == collect(1:length(ds1))
 34         return -1
 35     elseif ds2 == collect(1:length(ds2))
 36         return 1
 37     else
 38         d = cmpLex(countNOfAKind(ds1), countNOfAKind(ds2))
 39         if d == 0
 40             return cmpLex(ds1, ds2);
 41         else
 42             return d;
 43         end
 44     end
 45 end

Why are you comparing lengths?  The instructions say "the two containers have the same length".  Am I missing something?

I removed the length comparison in line 31. It was not necessary but did not hurt either.
The comparison in line 15 is necessary, since cmpLex is not only used in line 40 to compare the raw inputs, but also in line 38 to compare the result of countNOfAKind.
That function however may produce different-sized outputs for equally-sized inputs: countNOfAKind([3,2]) = [2] (because there are two lonely numbers (3 and 2)), countNOfAKind([2,2]) = [0, 1] (because there is no lonely number and one pair.

PHP 333 Bytes
I assume that there are fewer dices then faces for the highest value as street beginning with 1
I make a little more. Input is an array with more then two values.
Output is the sorted array.
<? $m=$_GET[m];foreach($m as$k=>$v){rsort($v);$m[$k]=$v;}function t($a,$b){if($a==$r=range($x=count($a),1))return 1;elseif($b==$r)return-1;$c=array_pad(array_values(array_count_values($a)),$x,0);$d=array_pad(array_values(array_count_values($b)),$x,0);rsort($c);rsort($d);if($e=$c<=>$d)return$e;return$a<=>$b;}usort($m,t);print_r($m);

Breakdown
$m=$_GET["m"]; # Array as Input
foreach($m as$k=>$v){
    rsort($v); # reverse sort of an item
    $m[$k]=$v; # replace the sort item
}
function t($a,$b){ #sorting algorithm
    if($a==$r=range($x=count($a),1))return 1; # $a is highest value
    elseif($b==$r)return-1; # $b is highest value
    $c=array_pad(array_values(array_count_values($a)),$x,0);
# prepare check multiple values for fist value
    $d=array_pad(array_values(array_count_values($b)),$x,0);
# prepare check multiple values for second value
    rsort($c);
    rsort($d);
    if($e=$c<=>$d)return$e; # compare first and second multiples
    return$a<=>$b; # compare dices
}
usort($m,"t"); # start sort
print_r($m); #print sorted array from low to high