text:
Custom Number Base Converter
The powers that be want to be able to quickly convert any number they have into their own number base using any format they would like.
Input
Your program must accept 3 parameters.

Number: The string number to be converted
InputFormat: the base string the number is currently in
OutputFormat: the base string that the number is to be converted to.

Output
Your program must convert the Number from the old number base InputFormat to the new number base OutputFormat
Examples
("1","0123456789","9876543210") = "8"
("985724","9876543210","0123456789ABCDEF") = "37C3"
("FF","0123456789ABCDEF","0123456789") = "255"
("FF","0123456789ABCDEF","01234567") = "377"
("18457184548971248772157", "0123456789","Aa0Bb1Cc2Dd3Ee4Ff5Gg6Hh7Ii8Jj9Kk,Ll.Mm[Nn]Oo@Pp#Qq}Rr{Ss-Tt+Uu=Vv_Ww!Xx%Yy*Zz") = ",sekYFg_fdXb"

Additional
The new base 77 test is not required props if it works though

if your in a language where you have to convert to a number first and are locked within 32Bit you can skip it.
as it's an additional test.

All examples were generated by PHP 7.2 with the bcmath extension using the following code (vars mins but code formatted). there will probably be a shorter way this is just the way I came up with for the system I needed to do this with would be nice to see if anyone could come up with a shorter version though.
PHP 7.2 (bcmath - extension) 614 bytes
<?php
function f($a, $b, $c)
{
    $d= str_split($b,1);
    $e= str_split($c,1);
    $f= str_split($a,1);
    $g=strlen($b);
    $h=strlen($c);
    $k=strlen($a);
    $r='';
    if ($c== '0123456789')
    {
        $r=0;
        for ($i = 1;$i <= $k; $i++)
            $retval = bcadd($retval, bcmul(array_search($f[$i-1], $d),bcpow($g,$k-$i)));
        return $r;
    }
    if ($b!= '0123456789')
        $l=f($a, $b, '0123456789');
    else
        $l= $a;
    if ($l<strlen($c))
        return $e[$l];
    while($l!= '0')
    {
        $r= $e[bcmod($l,$h)].$r;
        $l= bcdiv($l,$h,0);
    }
    return $r;
}

Try it Online
Scoring
This is code golf; shortest code wins. Standard loopholes apply.

How are bigger digits i.e 50,73 denoted?

@WindmillCookies By whatever characters are in the format strings.

Oh wait. I had understood the question completely wrong, now understood correctly, thanks!

Nice first question! :-)

@Giuseppe Thanks believe it or not the reason for this is that have just had to do something that involved converting to a custom number base (40) for work, and thought this would be an awesome code gold question :D

Closely related.

It may be worth adding a test case for a "unique" base -- e.g. ["zX", "tXdsyqzSDRP02", "brFNC02bc"] => "cb". (or whatever that should actually be, if that's incorrect)

I'd suggest a test case with more than 36 characters in the formats, to catch anyone using built-ins that only go up to base 36

Are these positive numbers? Nonnegative?

@Jakob none Signed numbers so positive because the work on string's if you will know if you see a - in front of it it's the negative and the programe does not need to do that.

So zero doesn't need to be supported?

no Zero exists in none signed numbers, look at the test cases the first one shows how a 0 get's used in decimal to reverse decimal

@JoKing i have added a decimal to base 77 test case :D

@MartinBarker I meant can the input number be zero (e.g. 0 in the base with digits 0123456789)?

@Jakob oh no it does not have to work with 0.

MATL, 2 bytes
Za

Try it online!
All test cases.
For the Za lord!

.......................you know, I saw that Za did base conversion but the docs on matl.suever weren't clear that it accepted the base's characters, so I didn't try it. RIP me!

@Giuseppe Haha, I remembered it only because it seemed like a command that's ripe for (ab)use in some clever hack or two. Ironic that my first use of it is as a straight-up builtin answer. :)

My first thought when I saw "Za" was "lord, Harry Dresden". +1.

R, 124 bytes
function(n,s,t,T=L(t),N=(match(!n,!s)-1)%*%L(s)^(L(n):1-1))intToUtf8((!t)[N%/%T^rev(0:log(N,T))%%T+1])
"!"=utf8ToInt
L=nchar

Try it online!
Ugh, this was a doozy. I use the typical base conversion tricks for R, but string manipulations in R are still messy!

Unfortunately this won't work with n="0"... you should add 2 bytes doing log(N+1,T) but causing a leading zero sometimes e.g. when you convert 31 from base 10 to base 2 :(

To avoid the "zero issue" on logarithm without leading zeros, I don't see a lot of other solutions... you could do log(N+!N,T) of course using ! with the original meaning

@digEmAll the OP's comments are still a bit unclear, but it seems that zero need not be supported.

Oh well.. that's fine then :)

APL (Dyalog Unicode), 22 bytes
Anonymous infix lambda. Takes InputFormat as left argument and OutputFormat as right argument, and prompts for Number from stdin. Assumes ⎕IO (Index Origin) to be 0, which is default on many systems.
{⍵[(≢⍵)⊥⍣¯1⊢(≢⍺)⊥⍺⍳⎕]}

Try it online!
{…} "dfn"; ⍺ is left argument, ⍵ is right argument
 (mnemonic: left and right ends of the Greek alphabet)
 ⍵[…] index the output format with the following:
  ⎕ prompt for input
  ⍺⍳ ɩndices of those characters in the input format
  (…)⊥ evaluate as being in the following base:
   ≢⍺ the length of the input format
  ⊢ yield that (separates ¯1 from (≢⍺))
  (…)⊥⍣¯1 convert to the following base:
  ≢⍺ the length of the output format

Japt, 5 3 bytes
nVW

Try it

Explanation
         :Implicit input of U=Number, V=InputFormat & W=OutputFormat
 nVW     :Convert U from base V to base W

C (gcc), 79 + 46 = 125 bytes
char*O;l,n;g(n){n/l&&g(n/l);write(1,O+n%l,1);}

This must be compiled with the
-Df(s,i,o)=for(n=l=0;n=n*strlen(i)+index(i,s[l])-i,s[++l];);l=strlen(O=o);g(n)

flag. (Yes, this is incredibly sketchy, which is why I'm keeping my old answer below.) This defines a macro f that outputs the answer to STDOUT.
Try it online!
C (gcc), 133 131 bytes
char*O;l;g(n){n/l&&g(n/l);write(1,O+n%l,1);}f(s,i,o,n)char*s,*i,*o;{for(n=0,l=strlen(O=o);n=n*strlen(i)+index(i,*s)-i,*++s;);g(n);}

Try it online!
This defines a function f that outputs the answer to STDOUT.
char*O;           // declare variable to store output charset
l;                // will be set to length of O
g(n){             // helper function to print the result
  n/l&&g(n/l);    // recursively calls itself if there are more digits
  write(1,        // output to stdout...
   O+n%l,1);      // the byte at (n mod output base) in O
}
f(s,i,o,n)        // main function
char*s,*i,*o;{    // declare string inputs
for(n=0,          // initialize n to 0
l=strlen(O=o);    // assign output charset so we don't have to pass it to g
n=n*strlen(i)     // repeatedly multiply n by input base...
+index(i,*s)-i,   // ... add the index of the digit in input charset...
*++s;);           // and move to the next digit until there's none left
g(n);             // call the helper function on the resulting integer
}

You can save 2 bytes by using putchar instead of write and changing the decoding loop slightly: Try it online!

This index function saved me one byte as well with my approach, didn't know about it ;)

05AB1E, 5 bytes
ÅβIÅв

Try it online!
This does not work in the legacy version of 05AB1E. It only works on the new version, the Elixir rewrite.
How it works

ÅβIÅв – Full program.
Åβ    – Convert from custom base to decimal.
  I   – Push the third input.
   Åв – Convert from decimal to custom base.

You state it only works in 05AB1E v2 (not sure if that's the correct version number..), but you still provided a TIO-link. Is the Elixir version already on TIO?! :S Or it works for most test cases, but there are some edge cases where it only works in the new version?

05AB1E v2 is now available on TIO. 05AB1E (legacy) (search it in the tio bar) is the name of the old 05AB1E and 05AB1E is the name of the new one. I know you've already seen that in the chatroom, though, but I'll leave it here as a reference for other users.

MATL, 5 bytes
sundar found the real builtin to do this! Go upvote that answer instead of my dumb one :-(
ZAwYA

Try it online!
          % implicit input N, the number, and S, the digits of the Source base
ZA        % base2dec, convert string N using S as digits into a base 10 integer
w         % swap stack elements, with implicit input T, the digits of the Target base
YA        % dec2base, reverse the ZA operation with digits coming from T instead.

Charcoal, 5 bytes
⍘⍘ＳＳＳ

Try it online! Link is to verbose version of code. Explanation:
  Ｓ     Input the "number"
   Ｓ    Input the input format
 ⍘      Convert to number using that format
    Ｓ   Input the output format
⍘       Convert to string using that format
        Implicitly print

The BaseString function automatically converts between number and string depending on the type of the first parameter.

Python 2, 132 129 122 121 bytes
lambda n,a,b:g(sum(len(a)**i*a.find(j)for i,j in enumerate(n[::-1])),b)
g=lambda n,c:c[n:n+1]or g(n/len(c),c)+c[n%len(c)]

Try it online!
An anonymous function (thanks, Erik the Outgolfer!) which converts the original number to a base 10 integer, then passes the integer and the new base string to function g(), which recursively converts to the new base. Now passes length of the OutputFormat as a parameter to g().
Updated g() for a lower bytecount. (thanks, Dennis!)
Replaced index() with find(). (thanks, Mr. Xcoder!)
Ungolfed Explanation:
def f(n, a, b):
    # reverse the string to that the least significant place is leftmost
    # Ex: 985724 -> 427589
    n = n[::-1]
    # get the value of each place, which is its index in the InputFormat, times the base to the power of the place
    # Ex: 427589, 9876543210 -> 5*10^0, 7*10^1, 2*10^2, 4*10^3, 1*10^4, 0*10^5 -> [5,70,200,4000,10000,0]
    n = [a.find(j)*len(a)**i for i,j in enumerate(n)]
    # add all of the values together to bet the value in base 10
    # Ex: (5 + 70 + 200 + 4000 + 10000 + 0) = 14275
    n = sum(n)

    # call the convert to base function
    return g(n, b)

def g(n, c):
    # string slice, which will return an empty string if n:n+1 is not in range
    # an empty string is falsey
    if c[n:n+1]:
        return c[n:n+1]
    else:
        # get current least significant digit
        rem = c[n%len(c)]
        # get the rest of the integer
        div = n/len(c)

        # get the converted string for the rest of the integer, append the calculated least significant digit
        return g(div,c)+rem

You don't need f=, anonymous functions are allowed by default.

@Erik the Outgolfer Is that allowed when the anonymous function calls another function, tho?

As long as you include the other stuff in your bytecount, yes, you're allowed to define variables and import modules.

The helper function can become g=lambda n,c:c[n:n+1]or g(n/len(c),c)+c[n%len(c)].

And the main one can become lambda n,a,b:g(sum(len(a)**i*a.find(j)for i,j in enumerate(n[::-1])),b,len(b)).

VBA, 182 bytes
A declared subroutine which takes input, n, in the language y and projects that into language z.
Sub f(n,y,z)
l=Len(n)
For i=-l To-1
v=v+(InStr(1,y,Mid(n,-i,1))-1)*Len(y)^(l+i)
Next
l=Len(z)
While v
v=v-1
d=v Mod l+1
v=v\l
If d<0Then v=v+1:d=d-l
o=Mid(z,d+1,1)&o
Wend
n=o
End Sub

Jelly, 11 bytes
iⱮ’ḅL{ṃ⁵ṙ1¤

Try it online!
Argument order: InputFormat, Number, OutputFormat. Be sure to quote the arguments with proper escaping!

Hrm not sure I did explicitly state the order of the params...

@MartinBarker The params are taken in order 2, 1, 3 here. I can't see a requirement for a specific order in the challenge, and that would be discouraged.

@MartinBarker Pro Tip: Be flexible with such things. I find the order  of the inputs to be completely irrelevant when solving a task, so I suggest that you allow any arbitrarily  chosen ordering of the parameters

i was gonna let it stick anyways just trying to test it now.

Pyth, 21 bytes
s@LeQjimx@Q1dhQl@Q1le

Test suite
Explanation:
s@LeQjimx@Q1dhQl@Q1le  | Code
s@LeQjimx@Q1dhQl@Q1leQ |  with implicit variables
       m               | Map the function
        x   d          |   index of d in
         @Q1           |    the second string in the input
             hQ        |  over the first string in the input
      i                | Convert the resulting list to int from base
               l@Q1    |  length of the second string in the input
     j                 | Convert the int into a list in base
                   leQ |  length of the last string in the input
 @LeQ                  | Turn each number in the list into the character from the numbers index in the last string in the input
s                      | Concatenate the strings in to one string
                       | Implicit print

Haskell, 119 bytes
n!f=init.((foldl((+).(l f*))0[i|c<-n,(i,d)<-zip[0..]f,d==c],0)#)
(0,d)#b=[b!!d]
(r,d)#b=r`divMod`l b#b++[b!!d]
l=length

Try it online!

JavaScript (ES6), 90 86 bytes
Takes input as (input_format)(output_format)(number).
s=>d=>g=([c,...n],k=0)=>c?g(n,k*s.length+s.search(c)):k?g(n,k/(l=d.length)|0)+d[k%l]:n

Try it online!

Sorry, this is not valid as your changing the input format of the string to an array that is not something that can be done via a CLI input. and has to be programmed you need split the string into the array for the first param for this to be valid.

@MartinBarker Which rule are you referring to? Updated to take 3 strings anyway.

All 3 of the input parameters says "string" as C++ a string can be directly read in and used as an array with javascript it can't be.

Perl 6, 100 97 bytes
{$^c.comb[(":"~$^b.chars~[$^a.comb>>.&{index $b,$_}].perl).EVAL.polymod($c.chars xx*)].join.flip}

Try it online!
Anonymous code block that takes 3 strings in order, input, input format and output format, then returns a string
Explanation:
{  # Anonymous code block
  $^c.comb[  # Split the output format into characters
           (":"~$^b.chars~[$^a.comb>>.&{index $b,$_}].perl) # The radix syntax in a string e.g ":3[1,2,3]"
           .EVAL  # Eval'ed to produce the base 10 version
           .polymod($c.chars xx*)  # Converted to a list in the output base (reversed)
          ] # Convert the list into indexes of the output format
           .join  # Join the characters to a string
           .flip  # And unreversed
}

Python 2, 97 95 bytes
Thanks to Chas Brown for -2 bytes.
n,s,t=input()
k=0;w='';x=len(t)
for d in n:k=len(s)*k+s.find(d)
while k:w=t[k%x]+w;k/=x
print w

Try it online!

C (gcc), 130 129 bytes
v;c(r,i,s,t)char*r,*i,*t;{for(r[1]=v=0;*i;v=v*strlen(s)+index(s,*i++)-s);for(s=strlen(t),i=1;*r=t[v%s],v/=s;memmove(r+1,r,++i));}

Try it online!
-1 byte using index instead of strchr.
This is a simple iterative approach, reusing some variables (and thereby abusing sizeof(int) == sizeof(char *) on TIO) to save bytes.
Input:

i input number
s source base characters
t target base characters

Output:

r result number (pointer to a buffer)

Explanation:
v;                                        // value of number
c(r,i,s,t)char*r,*i,*t;{
    for(r[1]=v=0;                         // initialize value and second
                                          // character of output to 0
        *i;                               // loop while not at the end of
                                          // input string
         v=v*strlen(s)+index(s,*i++)-s);  // multiply value with source base
                                          // and add the value of the current
                                          // digit (position in the base string)
    for(s=strlen(t),i=1;                  // initialize s to the length of the
                                          // target base string, length of
                                          // result to 1
        *r=t[v%s],v/=s;                   // add character for current digit
                                          // (value modulo target base) and
                                          // divide value by target base until
                                          // 0 is reached
        memmove(r+1,r,++i));              // move result string one place to
                                          // the right
}

Suggest bcopy(r,r+1,++i) instead of memmove(r+1,r,++i)

Java 10, 131 bytes
A lambda taking the parameters in order as strings and returning a string.
(i,f,o)->{int n=0,b=o.length();var r="";for(var c:i.split(r))n=n*f.length()+f.indexOf(c);for(;n>0;n/=b)r=o.charAt(n%b)+r;return r;}

Try It Online
Ungolfed
(i, f, o) -> {
    int n = 0, b = o.length();
    var r = "";
    for (var c : i.split(r))
        n = n * f.length() + f.indexOf(c);
    for (; n > 0; n /= b)
        r = o.charAt(n % b) + r;
    return r;
}


text:
Codegolf Rainbow : Sorting Colors with Reflection
Introduction:
After I posted two rainbow-related challenges: Codegolf Rainbow : Fun with Integer-Arrays 1 and Codegolf Rainbow : Draw in Black-and-White 2, the following comment was made by @ChrisM in the ASCII (Draw in Black-and-White) challenge:

Maybe you know this and it's by design (I know that rainbows are not rhombuses or ascii, too, and higher orders' positions get more complicated), but aren't the colours reversed in the 2nd rainbow?

And he's indeed right. When you see a double rainbow, the second one is actually a reflection of the first, so the colors are reversed. With three rainbows, it's an actual double rainbow, with the third one being a reflection of one of the other two. And with four, there are two rainbows, and two reflections of those.

So, let's make a third related challenge using that fact.
Challenge:
Inputs: A positive integer n which is >=2, and a list of integers of size >= n+1.
Output: The same list ordered as follows:

First split the input lists in sub-lists of size n (where the trailing sub-list could be of any size in the range [1,n]).
Then we do the following based on the amount of sub-lists m:

Sort the first m - m//2 amount of sub-lists from lowest to highest (where // is integer-divide). (I.e. with 6 sub-lists the first three will be sorted from lowest to highest; with 5 sub-lists the fist three will be sorted from lowest to highest.)
Sort the last m//2 amount of sub-lists from highest to lowest (where // is integer-divide). (I.e. with 6 sub-lists the last three will be sorted from highest to lowest; with 5 sub-lists the last two will be sorted from highest to lowest.)

Merge all sub-lists together to form a single list again

Examples:
Inputs: n=7 and [3,2,1,-4,5,6,17,2,0,3,5,4,66,-7,7,6,-5,2,10]
Step 1: [[3,2,1,-4,5,6,17],[2,0,3,5,4,66,-7],[7,6,-5,2,10]]
Step 2: [[-4,1,2,3,5,6,17],[-7,0,2,3,4,5,66],[10,7,6,2,-5]]
Step 3 / Output: [-4,1,2,3,5,6,17,-7,0,2,3,4,5,66,10,7,6,2,-5]
Inputs: n=4 and [7,4,-8,9,3,19,0,-23,-13,13]
Step 1: [[7,4,-8,9],[3,19,0,-23],[-13,13]]
Step 2: [[-8,4,7,9],[-23,0,3,19],[13,-13]]
Step 3 / Output: [-8,4,7,9,-23,0,3,19,13,-13]
Challenge rules:

The integer input n is guaranteed to be larger than 1.
The size of the integer-list is guaranteed to be larger than n.
The trailing sub-list can be smaller than n (as can be seen in the examples and test cases).
I/O format is flexible in any reasonable format. Can be a list/array of integers or decimals, a comma/space/newline delimited string, stream of integers, etc. (Output may not be a 2D list of lists like step 2. Step 3 to flatten it back into a single list is required for this challenge.)

General rules:

This is code-golf, so shortest answer in bytes wins.
Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
Default Loopholes are forbidden.
If possible, please add a link with a test for your code.
Also, adding an explanation for your answer is highly recommended.

Test cases:
Inputs: n=7 and [3,2,1,-4,5,6,17,2,0,3,5,4,66,-7,7,6,-5,2,10]
Output: [-4,1,2,3,5,6,17,-7,0,2,3,4,5,66,10,7,6,2,-5]

Inputs: n=4 and [7,4,-8,9,3,19,0,-23,-13,13]
Output: [-8,4,7,9,-23,0,3,19,13,-13]

Inputs: n=2 and [7,-3,1]
Output: [-3,7,1]

Inputs: n=3 and [1,6,99,4,2]
Output: [1,6,99,4,2]

Inputs: n=2 and [5,2,9,3,-5,-5,11,-5,4,12,9,-2,0,4,1,10,11]
Output: [2,5,3,9,-5,-5,-5,11,4,12,9,-2,4,0,10,1,11]

Inputs: n=3 and [5,2,9,3,-5,-5,11,-5,4,12,9,-2,0,4,1,10,11]
Output: [2,5,9,-5,-5,3,-5,4,11,12,9,-2,4,1,0,11,10]

Brachylog, 18 17 16 bytes
ġ₎↔ḍ↔{izo₎ᵐ↔}ᶠcc

Try it online!
-1 byte thanks to @sundar
Expects input as [<integer list>, n]. Note that negative integers are
represented with _, Brachylog's "low minus". Output variable is R.
First time attempting Brachylog, so I imagine it's sub-optimal and ripe for
reducing in bytes.
Explanation
Partition, bifurcate, sort based on index (0: asc, 1: desc), flatten.
ġ₎               | split head of input into groups of length n (last of list)
  ↔              | reverse so that...
   ḍ             | dichotomize splits in two, attaching any additional element to the second list
    ↔            | reverse so first half of partitions corresponds to the 0 index
     {      }    | apply
      i          | : append index
       z         | : zip each sublist with the index of its parent
        o₎ᵐ      | : map over sublists, ordering by the zipped index
           ↔     | : undo earlier reverse
             ᶠ   | find all outputs
              cc | flatten two levels

A small tweak to your second solution, to get 17 bytes: Try it online!

@sundar I had a sneaking suspicion I was mapping one too many, thanks!

What is this language for?

@SamOrozco Terse declarative logic programming. Try clicking on the language name!

Jelly, 9 bytes
sṢ€ŒHUÐeF

Try it online!

I don't understand why this programming language exists.

@SamOrozco It's sole purpose is to solve problems with as short code as possible.

Oh, really. That's cool.

Python 2, 82 bytes
lambda n,l:sum([sorted(l[i:i+n],reverse=i>len(l)/2)for i in range(0,len(l),n)],[])

Try it online!

05AB1E (legacy), 9 bytes
ô€{2ä`í«˜

Try it online!
Try it online! in 05AB1E (Elixir rewrite) – expects input to be on the stack, a default I/O method.
Kevin came up with his own 11-byter which I used to get to 10. Then I came up with something else for 9 bytes.

Nice one. Here was my initial solution as 11-byte alternative: ô€{2äRć€R)˜.

@KevinCruijssen Got to 10 using your approach haha. EDIT: 9 now!

Ah, nice. Completely forgot about í. And nice additional golf.

Japt, 10 bytes
òV ®nÃÇwÃc

Also 10 bytes
òV mn ow c

Try it online!

JavaScript (ES6), 82 81 bytes
Saved 1 byte thanks to @redundancy
Takes input as (list)(n).
a=>n=>(g=z=>a+a?[...a.splice(0,n).sort((x,y)=>1/z?x-y:y-x),...g(a[i+=n])]:a)(i=0)

Try it online!

Since a is one-dimensional, I believe you can replace a>[] with a+a to check the non-empty case and save 1 byte. Really clever recurive strategy for partitioning and determining when to reverse the sort, as well!

@redundancy That should be safe indeed. Thanks!

Clojure, 90 bytes
#(for[i[0 1]j((split-at(/(count %)2%2)(partition-all %2%))i)k(([seq reverse]i)(sort j))]k)

Try it online!

Vyxal, 23 bytes
ẇD:L½:£⌈Ẏvs⅛_¥⌈ȯvsvṘ⅛¾f

Try it Online!
A big mess.

source: Stack Exchange

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

sort: votes


text:
Sort by what the digit pairs describe
Given a positive integer, we can form a new number that's described by its digits taken pairwise (with a leading 0 added for numbers with odd number of digits).
For eg.:

1234 can be read as one 2, three 4s - so, the output for 1234 is 2444.
643 has an odd number of digits, so a leading zero is added to make it even. Then, 0643 can be read as: zero 6s, four 3s, hence the output would be 3333.

(This is OEIS A056967).
Task: Given an array of positive integers, sort them by their digit-pair-described value, in ascending order. Order does not matter between input numbers that lead to the same value.
Input: an array/list/set of positive integers. Leading zeros in the input are not allowed, and input as strings/lists of digits/etc. are not allowed - the inputs should be as close to an integer/numeric type as your language is capable of using.
Output: the array sorted in the above-mentioned way, returned in any of the usual ways (function return value/STDOUT/shouting into the void/etc.) You can print them individually, return them as numbers, strings, or lists of digits.
Test cases
Input
Output

[19, 91, 2345, 2023]
[19, 2023, 2345, 91]

[25257, 725, 91, 5219, 146125, 14620512]
[725, 5219, 14620512, 91, 146125, 25257]

[123130415 3335 91 111111111 528 88]
[528, 111111111, 123130415, 3335, 88, 91]

[1 21 33 4 5]
[1 4 5 21 33]

[3725, 10, 2537, 1, 1225, 2512]
[10, 1, 1225, 2512, 2537, 3725]

[125, 26, 1115, 1024]
[1115, 1024, 125, 26]

(In the 4th test case, 1, 4, and 5 all evaluate to 0, and so can be sorted among themselves in any order. Similarly in the fifth test case, 10 and 1 both evaluate to 0s, and so can be sorted in either order.)
(Related: Say what you see, One 1, Two 1's, One 2 One 1
Thanks to Kevin Cruijssen for help clarifying the question in the Sandbox.

Can we take a list of lists of digits as input? Can we output a list of lists of digits?

@Mr.Xcoder Input should be as a list of integers, not lists of digits. Output can be a list of lists of digits though, if that's somehow more convenient.

as pointed out by @mnel, my answer won't work for numbers above 10 digits. is it legit to keep it as is, or should I modify it at the cost of 32 bytes.

@JayCe If I understand correctly, the limitation is because that's the limit of the integer type in R -  because strtoi returns an integer - correct? If so, that's fine, it's legal as it is.

you are correct! will keep it as is.

APL (Dyalog), 26 bytes
Thanks ngn for saving 1 byte :)
{⍵[⍋⌽↑,⍨⌿⍴⌿0 10⊤⍵⊤⍨⍴⍨100]}

Try it online!
Inspiration take from dzaima & ngn

100⊥⍣¯1⊢⍵ -> ⍵⊤⍨⍵/100 works for 26.

I don't really want WSFULLs on the given test cases

26 is possible with MAXWS=1M

100⊥⍣¯1⊢⍵ -> ⍵⊤⍨⍴⍨100

@ngn Nice. I see no reason why 100⍴100 isn't enough

@H.PWiz right, even with ⎕FR←1287 the precision is only ~34 decimal digits

@H.PWiz and here's a different solution for 26 bytes: {⍵[⍋⌽↑,⍨⌿⍴⌿⊃⊥⍣¯1/10 100⍵]}

Jelly, 10 bytes
ṚẋƝm2ṚFḌµÞ

Try it online!
Check out a test suite!
How it works

ṚẋƝm2ṚFḌµÞ    Monadic link / Full program.                            | Example: [25257, 725, 91, 5219, 146125, 14620512]
        µÞ    Sort the input list by the result of the monadic link:  | Example: 725
Ṛ             Promote N to its digit array and reverse it.            | [5, 2, 7]
 ẋƝ           For each two consecutive digits x, y, repeat x y times. | [[5, 5], [2, 2, 2, 2, 2, 2, 2]]
   m2         Modular 2. Take every other element of this array.      | [[5, 5]]
     Ṛ        Reverse.                                                | [[5, 5]]
      F       Flatten.                                                | [5, 5]
       Ḍ      Convert from decimal to integer.                        | 55

It definitely is a coincidence: 2537 and 3725 don't represent the same number.

Could you give me a test case that would catch that, and I'll add that to the question?

@sundar As Erik said, [2537, 3725]. I never doubted that this is a coincidence, hence I included that note to the answer

@Mr.Xcoder Testcase added, thanks.

R, 141 bytes
(s<-scan(,""))[order(strtoi(sapply(s,function(x)paste(strrep((m=matrix(c(if(nchar(x)%%2)0,el(strsplit(x,""))),2))[2,],m[1,]),collapse=""))))]

Try it online!
Rather laborious answer - but it works on all test cases.
Builds the digit-pair output and sorts the input according to this.

I posted my approach on another answer since I was working on it on this afternoon but I was interrupted. Just to assure you I didn't get inspiration from yours without credits ;)

@digEmAll no worries :) - Actually I think I took the name v for the variable from your other answers - I never used v before. And nice use of  intToUtf8!

ahah I'm really jealous of my single letter variables names ! No, seriously... coming from StackOverflow everytime I post a "similar" alternative it feels like stealing ;)

strtoi will return NA for integers above 10 digits, (as.numeric won't )

@mnel thanks for pointing out ! I checked with sundar and since it's a limitation of the integer type I can leave it as is :)

R, 120 bytes
(v=scan())[order(sapply(v,function(n,e=nchar(n))sum((a=rep((x=n%/%10^(0:(e-1-e%%2))%%10)[!0:1],x[!1:0]))*10^seq(a=a))))]

Try it online!

-11 bytes thanks to @sundar "arithmetical" suggestion !

Ungolfed code with explanation :
# define a function G which takes a number 'n' and uncompress it multiplied by 10
# e.g. 2735 -> 775550, 61345 -> 355550 etc.
G=function(n){
  e = nchar(n)                   # get the n.of digits in the compressed number

  x = n%/%10^(0:(e-1-e%%2))%%10  # split 'n' into vector of digits reversed adding
                                 # trailing zero if 'e' is odd (e.g. 123 -> c(0,3,2,1))

  even = x[!0:1]                 # take only the odd elements of 'x' (= even digits)
  odd  = x[!1:0]                 # take only the even elements of 'x' (= odd digits)
                                 # N.B. :
                                 # these tricks work because !0:1 is c(TRUE,FALSE)
                                 # and V[c(TRUE,FALSE)] exploits the fact that R
                                 # automatically recycles the logical indexes up to the
                                 # length of the vector V

  a = rep(even,odd)              # repeat each value in 'even' 'odd' times obtaining the
                                 # uncompressed number as digits vector. Note that in
                                 #  case of single digit 'n', 'a' will be an empty vector

  sum(a*10^seq(a=a))             # multiplies 'a' * 10^(1:length(a)) and sum
                                 # obtaining the uncompressed number multiplied by 10
                                 # N.B. in case of empty 'a', we get 0
}

v = scan()                       # take vector v from stdin

w = sapply(v,G(n))               # apply G to all numbers of 'v'

v[order(w)]                      # use the uncompressed values as weights to sort 'v'

The [!1:0] trick is real nice - never seen it before.

@sundar: explanation added ;)

Nice. I knew those [!1:0] fellas were hiding something neat. I was playing around with this and the tips on R golfing, trying to get the number from the digits arithmetically (without as.double), but only came up with a 132 byte version: TIO

@sundar: I didn't think to the arithmetical approach... I saved 11 bytes, thanks !

Pyth, 14 bytes
oir9c.[Z2jNT2T

Try it here! | Test suite! | 12 bytes with list of digits I/O
How it works?
oir9c.[Z2jNT2T – Full program.
o              – Sort the input list by the results of the following code (variable: N).
         jNT   – Cast the current element to a list of digits.
     .[Z2      – Pad it on the left with 0s to the nearest multiple of 2.
    c       2  – Split in pieces of length 2.
  r9           – Run length decode.
 i           T – Cast the list of digits to a base 10 integer.

Dyalog APL, 41 39 36 35 31 30 29 bytes
f←⊂⌷¨⍨∘⍋{10⊥∊⍴⌿0 10⊤100⊥⍣¯1⊢⍵}¨

Try it online!
-2 thanks to Cows quack
-4 (plus -4 for the base conversion idea) thanks to ngn
-2 thanks so H.PWiz

⊃,/ can become ∊

@Cowsquack I knew I was forgetting a built-in :p

{⍺⍴⍨⍎⍵} -> ⍴⍨∘⍎

@ngn of course, I can never remember all the jot/train things

here's another trick for -1 byte - trainify {⍵[⍋F ⍵]} as ⊂⌷¨⍨∘⍋F

Can ⍴/⍉ be ⍴⌿?

You should also be able to use 0 10⊤

27 bytes: {⍵[⍋⌽↑,⍨⌿⍴⌿0 10⊤100⊥⍣¯1⊢⍵]}

@H.PWiz submit that as another answer, it contains pretty much nothing that I thought of :p

C (gcc) (32bit systems), 188 177 176 bytes
char*p,*q,c[99],b[99]="0";i;d(x){for(p=b+!(sprintf(b+1,"%d",x)&1),q=c;i=*p++;++p)for(i-=48;i--;*q++=*p);*q=0;atoi(c);}m(int*a,int*b){return d(*a)-d(*b);}s(l,c){qsort(l,c,4,m);}

Try it online!
on amd64 add flag -m32 for compiling.
Usage: s(x,n); where x points to an array of integers to sort and n is the length of that array.
Second test case gives wrong result because converting 25257 gives 2222277777 which overflows a 32bit integer -- added a 5th test case without that number.
Explanation:
char*p,                                     // d(): input pointer
    *q,                                     // d(): output pointer
    c[99],                                  // d(): output buffer
    b[99]="0";                              // d(): input buffer
                                            //      (fixed first char 0)
i;                                          // d(): repeat counter

d(x){                                       // conversion function
    for(
            p=b+!(sprintf(b+1,"%d",x)&1),   // print number in decimal to
                                            // input buffer, starting at second
                                            // character, initialize input
                                            // pointer to first or second char
                                            // depending on the length of the
                                            // number
            q=c;                            // initialize output pointer
            i=*p++;                         // set repeat counter to digit and
                                            // point to next digit, stop when
                                            // NUL character is found
            ++p)                            // point to next digit after loop
        for(i-=48;i--;*q++=*p);             // inner loop, append current digit
                                            // i-48 ('0') times to output buffer
    *q=0;                                   // terminate output with NUL
    atoi(c);                                // convert to number, 'return' not
                                            // needed as atoi() leaves result
                                            // on the stack
}

m(int*a,int*b){                             // comparison function for qsort
    return d(*a)-d(*b);                     // return difference of converted
}                                           // values

s(l,c){                                     // sorting function
    qsort(l,c,4,m);                         // only "wrap" qsort, assuming
}                                           // sizeof(int) is 4

Your function d() is long because of strings and functions related to them, you can save many bytes just by reading the last 2 digits and building the output like this : o;u;i;d(x){for(u=1,o=0;x;x/=100)for(i=0;i++<x%100/10;o+=x%10*u,u*=10);x=o;}m(int*a,int*b){u=d(*a)-d(*b);}s(l,c){qsort(l,c,4,m);} you will also save bytes by avoiding declaring and initializing chars.

Nice idea -- I think working on the integer values makes this a completely different approach, so you should consider posting an answer? :)

Suggest b-~sprintf(b+1,"%d",x)%2 instead of b+!(sprintf(b+1,"%d",x)&1)

@Annyo suggest x/10%10 instead of x%100/10

Perl 6, 53 bytes
*.sort(+*.flip.comb.rotor(2).map({[x] $_}).join.flip)

Try it online!
Anonymous Whatever lambda that takes a list of values and sorts it by what the pairs of numbers describe.
In this case, I'm reversing the number, then rotoring the list by two to get each pair of numbers. This will exclude the first digit for numbers of odd length, but since that translates to 0 times that number, it's okay. Plus, it lines up the values to use [x] correctly.

Haskell, 89 88 bytes
Saved a byte thanks to ovs
import Data.List
(%)=mod
m?n|n<1=0|n%100<10=m?div n 100|w<-n-10=m*10?w+m*n%10
sortOn(1?)

The last line defines an anonymous function that can be used like so:
> sortOn(1?)[19, 91, 2345, 2023]
[19,2023,2345,91]

The core functionality is provided by the infix operator (?) which keeps track of a multiplier, m, and the remaining RLE input n. (?) continually subtracts 10 from n whilst there is a tens digit to subtract from, and as it does so it pushes another copy of the final digit to the front of the output (via the multiplier m, which is increased by 10 each time). When the tens place is exhausted, the final two digits are discarded and the process repeats until the number is reduced to 0. Finally, we use the operator (with an initial multiplier of 1) as a sort key.

m?n|n<1=0|n%100<10=m?div n 100|w<-n-10=m*10?w+m*n%10 is a byte shorter.

Python 2, 80 74 bytes
def g(l):l.sort(key=f)
f=lambda n:+(n>9)and int(`f(n/100)`+n/10%10*`n%10`)

Try it online!

Husk, 10 bytes
ÖödṁΓ*C_2d

Try it online!
Explanation
ÖödṁΓ*C_2d    Full function
Ö             Sort the input list by the result of...
 ö            The composition of these four functions:
         d      Convert to a list of digits
      C_2       Split into length-2 sublists starting at the end
   ṁ            Map the following function and concatenate the results:
    Γ*            Repeat the list tail X times, where X is the list head
  d             Convert back to an integer

Python 2, 102 101 97 101 bytes
lambda l:sorted(l,key=lambda x:int(''.join(v*int(c)for c,v in zip(*[iter(`x`[len(`x`)%2:])]*2))or 0))

Try it online!

@sundar No worries, fixed

Japt, 13 bytes
ñ_ì_ò2n)®rçÃ¬

Try it or run all test cases

Explanation
ñ_                :Sort by passing each integer through a function
  ì_              :  Split to an array of digits, pass it through the following function and implicitly convert back to an integer
    ò2n)          :    Starting from the end of the array, split at every second element
        ®         :    Map
         rç       :      Reduce X & Y by repeating X Y times
           Ã      :    End mapping
            ¬     :    Join

Brachylog, 18 bytes
{↔ġ₂ẹ{Ċj₎|Ȯt}ˢ↔c}ᵒ

Try it online!
Explanation
Loads of small stuff needed to account for the three different cases: odd number of digits, pair of 0 times a number, and normal pairs.
{               }ᵒ     Order the Input according to the output of this predicate
 ↔                       Reverse the number
  ġ₂                     Group into pairs; the last digit is alone if there are
                           an odd number of them
    ẹ{      }ˢ           For each group:
      Ċ                    If there are two elements
       j₎                  Juxtapose the first one as many times as the second
                             element (won't work if the second element is 0)
         |                 Else
          Ȯ                If there is one element (odd number of digits)
           t               just take that element
                           (Else don't select anything, i.e. 0 repetitions)
              ↔c         Reverse and concatenate back into an integer

I think the |Ȯt is unnecessary, and in fact makes it sort wrong: it's equivalent to padding with a 1 instead of a 0, so given [125, 26, 1], sorts it as [1, 26, 125] instead of [1, 125, 26].

Perl 5, 76 bytes
A function instead of a one-liner for once.
Quite straight forward: g sorts the inputs numerically, using h to convert the numbers. h does this by using the regex s/(.)(.)/$2x$1/gre (which is probably readable enough). And the 0 left-padding is done with 0 x("@_"=~y///c%2)."@_" (where y///c is a shorted way of writing length, x is the repetition operator and . the concatenation).
sub h{(0 x("@_"=~y///c%2)."@_")=~s/(.)(.)/$2x$1/gre}sub g{sort{h($a)-h$b}@_}

Try it online!
I'm expecting to see some shorter Perl answers though!

05AB1E, 20 19 bytes
ΣDgÉi¦}2ôε`sиJ}J0ìï

Bug-fixed for +1 byte, and then golfed by -2 bytes thanks to @sundar.
Try it online or verify all test cases.
Can definitely be golfed.. Not too happy about it tbh..
Explanation:
Σ                    # Sort by:
 Dg                  #  Duplicate the current number, and take it's length
                     #   i.e. 25257 → 5
                     #   i.e. 4 → 1
   Éi }              #  If this length is odd:
     ¦               #   Remove the first digit
                     #    i.e. 25257 → '5257'
                     #    i.e. 4 → ''
       2ô            #  Then split the number in pieces of 2
                     #   i.e. '5257' → ['52','57']
                     #   i.e. '' → []
         ε    }      #  And map each to:
          `          #   Push both digits to the stack
                     #    i.e. '52' → '5' and '2'
           s         #   Swap them
            и        #   Repeat the first digit the second digit amount of times
                     #    i.e. '2' and '5' → ['2','2','2','2','2']
             J       #   Join the list of digits together
                     #    i.e. ['2','2','2','2','2'] → '22222'
               J     #  Join all numbers back together again
                     #   i.e. ['','22222','77777'] → '2222277777'
                     #   i.e. [] → ''
                0ì   #  Prepend a 0 (because `Σ` will put all '' at the back)
                     #   i.e. 2222277777 → '02222277777'
                     #   i.e. '' → '0'
                  ï  #  Cast it to an integer, because sorting is done string-wise by
                     #  default despite 05AB1E's interchangeability of strings and numbers;
                     #  and it's also to remove all leading zeros
                     #   i.e. '02222277777' → 2222277777
                     #   i.e. '0' → 0

Retina, 44 bytes
^.?((..)*)$
$1 $&
%)`\G(\d)(.)
$1*$2
N`
.+

Try it online! Generating the sort key at the start of the line is harder but the short sort stage results in an overall 3 byte saving. Explanation:
%)`

Apply the first two stages on each line individually.
^.?((..)*)$
$1 $&

Match and copy an even number of trailing digits.
\G(\d)(.)
$1*$2

Replace each digit pair with their described value. The \G\d causes the match to stop at the space.
N`

Sort numerically.
.+

Delete the sort keys.

That's a clever trick to sort by a key. Good one.

JavaScript (ES8), 72 70 bytes
a=>a.sort((a,b)=>(g=n=>n&&g(n/100|0)+''.padEnd(n/10%10,n%10))(a)-g(b))

Try it online!

Attache, 50 bytes
SortBy!N@Flip##~`&&>PadRight&0&2=>Chop&2@Flip@List

Try it online!
Explanation
SortBy!N@Flip##~`&&>PadRight&0&2=>Chop&2@Flip@List      anonymous function, argument: [a1..aN]
SortBy!                                                 sort the given array by grading f[ai]
                                                        e.g. 42513
                                              List      digits of ai
                                                        e.g. [4, 2, 5, 1, 3]
                                         Flip@          flip the digits around
                                                        e.g. [3, 1, 5, 2, 4]
                                  Chop&2@               chop into groups of 2
                                                        e.g. [[3, 1], [5, 2], [4]]
                    PadRight&0&2=>                      pad each group to size 2 with 0's
                                                        e.g. [[3, 1], [5, 2], [0, 4]]
                  &>                                    using each sub array as arguments...
               ~`&                                      ...repeat the 2nd the 1st amount of times
                                                        e.g. [[1, 1, 1], [2, 2, 2, 2, 2], []]
             ##                                         then:
         Flip                                           reverse the groups
                                                        e.g. [[2, 2, 2, 2, 2], [1, 1, 1]]
       N@                                               then convert it to an number
                                                        e.g. 22222111

Jelly, 14 bytes
DŻLḂ$¡ẋ@2/ẎḌµÞ

Try it online!

Java 11, 204 189 bytes
L->{L.sort((a,b)->Long.compare(s(a+""),s(b+"")));}long s(String s){var r="";for(int l=s.length(),i=l%2;i<l;)r+=s.split("")[++i].repeat(s.charAt(i++-1)-48);return r.isEmpty()?0:new Long(r);}

Takes a List of Longs as parameter and sorts this input-List (without returning a new List).
Try it online (NOTE: String.repeat(int) is emulated as repeat(String,int) because Java 11 isn't on TIO yet. The byte-count remains the same.)
Explanation:
L->{                     // Method with ArrayList<Long> parameter and no return-type
  L.sort(                //  Sort the list by:
   (a,b)->Long.compare(  //   Using a builtin Long-comparator with:
     s(a+""),s(b+"")));} //   The correctly formatted values as described in the challenge

long s(String s){        // Separated method with String parameter and long return-type
  var r="";              //  Temp-String, starting empty
  for(int l=s.length(),  //  The length of the input-String
      i=l%2;i<l;)        //   If the length is even:
                         //    Loop `i` in the range [0,`l`) (in steps of 2)
                         //   Else (the length is odd):
                         //    Loop `i` in the range [1,`l`) (in steps of 2) instead
    r+=                  //   Append the result-String with:
      s.split("")[++i].  //    The digit at index `i+1`
      .repeat(s.charAt(i++-1)-48);
                         //    Repeated the digit at index `i` amount of times
  return r.isEmpty()?    //  If the temp-String is empty:
          0              //   Return 0
         :               //  Else:
          new Long(r);}  //   Convert the temp-String to a long and return it

Hi, the challenge explicitly disallows string input, sorry! (I'm tempted to allow it for Java, but it wouldn't be fair on the other answers.)

@sundar Ah, missed that requirement; my bad.. Luckily it's an easy fix of just adding to 2x +"" to convert the number to String. Should be fixed now. :)

Nice. I did not expect that from Java. :)

Ruby, 71 bytes
->a{a.sort_by{|a|s='';s,a=[a%10]*(a/10%10)*''+s,a/100while a>0;s.to_i}}

Try it online!

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


text:
Compute the minimum \$a(n)>a(n-1)\$ such that \$a(1)+a(2)+\dots+a(n)\$ is prime (OEIS A051935)
Background
Consider the following sequence (A051935 in OEIS):

Start with the term \$2\$.
Find the lowest integer \$n\$ greater than \$2\$ such that \$2+n\$ is prime.
Find the lowest integer \$n'\$ greater than \$n\$ such that \$2 + n + n'\$ is prime etc.

A more formal definition:
$$a_n=\begin{cases}2 & \text{if }n=0 \\ \min\{x\in\Bbb{N}\mid x>a_{n-1} \text{ and }\left(x+\sum_{i=0}^{n-1}a_i\right) \text{ is prime}\} & \text{otherwise}\end{cases}$$
The first few terms of the sequence are (please refer to these as test cases):
2, 3, 6, 8, 10, 12, 18, 20, 22, 26, 30, 34, 36, 42, 44, 46, 50, 52, 60, 66, 72, 74, ...

Task
Your task is to generate this sequence in any of the following ways:

Output its terms indefinitely.
Given \$n\$, output \$a_{n}\$ (\$n^{\text{th}}\$ term, \$0\$ or \$1\$ indexed).
Given \$n\$, output \$\{a_1, a_2, \dots, a_n\}\$ (first \$n\$ terms).

You can compete in any programming language and can take input and provide output through any standard method, while taking note that these loopholes are forbidden by default. This is code-golf, so the shortest submission (in bytes) for every language wins.

Tips to avoid while writing challenges: The prime numbers. You could've used something else other than primality.

@Okx I had a couple of reasons in mind when I choose primality this time: 1) There are some clever algorithms that are specific to this very sequence, like the one Dennis implemented 2) There is already an OEIS entry  for this

This challenge has now been mentioned on the OEIS!

Brachylog, 13 bytes
~l.<₁a₀ᵇ+ᵐṗᵐ∧

Try it online!
Output is the list of first n terms of the sequence.
?~l.<₁a₀ᵇ+ᵐṗᵐ∧    Full code (? at beginning is implicit)

?~l.              Output is a list whose length is the input
    <₁            Output is an increasing list
      a₀ᵇ+ᵐ       And the cumulative sum of the output
           ṗᵐ     Consists only of prime numbers
             ∧    No further constraints on output

Explanation for a₀ᵇ+ᵐ:
a₀ᵇ               Get the list of all prefixes of the list
                  Is returned in increasing order of length
                  For eg. [2, 3, 6, 8] -> [[2], [2, 3], [2, 3, 6], [2, 3, 6, 8]]
   +ᵐ             Sum each inner list  -> [2, 5, 11, 19]

Jelly, 11 9 bytes
0Ḥ_ÆnɗÐ¡I

This is a full program that takes n as an argument and prints the first n terms of the sequence.
Try it online!
How it works
0Ḥ_ÆnɗÐ¡I  Main link. Argument: n

0          Set the return value to 0.
      Ð¡   Accumulating iterate. When acting on a dyadic link d and called with
           arguments x and y, the resulting quicklink executes
           "x, y = d(x, y), x" n times, returning all intermediate values of x.
           Initially, x = 0 and  y = n.
     ɗ       Drei; combine the three links to the left into a dyadic chain.
 Ḥ             Unhalve; double the left argument.
  _            Subtract the right argument.
   Æn          Compute the next prime.
           This computes the partial sums of the sequence a, starting with 0.
        I  Increments; compute the forward differences.

Python 2, 63 62 bytes
n=f=a=b=1
while 1:
 f*=n;n+=1;a+=1
 if~f%n<a-b:print a;b=a;a=0

Try it online!

05AB1E v2, 10 bytes
2λλOD₁+ÅNα

Try it online!
This only works in the non-legacy version, the Elixir rewrite. Outputs an infinite stream of integers. There are some bugs with the prime test that have been fixed in the latest commits, but are not yet live on TIO. It does work locally, though. Here is a GIF of its execution on my machine, modified to output the first few terms rather than the whole stream.
How it works
2λ

Defines a recursive infinite sequence with base case \$2\$. The λ structure is among 05AB1E's very cool new features. Briefly speaking, it takes a function \$a(n)\$, setting \$a(0)\$ to the integer argument given, in this case \$2\$.
λO

In this portion of code, λ's role is different. Already being inside a recursive environment, it instead generates \$[a(0),a(1),\dots,a(n-1)]\$, the list of all previous results. Then, O sums them
up.
D₁+

Duplicate the sum for later use and add \$a(n-1)\$ to the second copy.
ÅN

Generates the lowest prime stricly greater than the above sum.
α

Finally, retrieve the absolute difference between the prime computed above and the first copy of the sum computed earlier (the sum of all previous iterations).
The stream is then implicitly printed to STDOUT indefinitely.

Ruby -rprime, 34 bytes
2.step{|i|$.+=p(i)if($.+i).prime?}

Try it online!
Outputs indefinitely.

Pyth, 12 11 bytes
.f&P-;Z=-;Z

Try it online!
Saved 1 byte thanks to isaacg.
Generates the first n such numbers, using a 1 based index.
.f finds the first k integers that satisfy a particular criterion starting from zero. Here, the criterion is that the previous prime we calculated, ;, plus the current number, Z, is prime (P). If it is, we also update the last calculated prime using the short-circuiting behaviour of the logical and function (&). Unfortunately .f's default variable is Z which costs a byte in the update.
The trick that isaacg figured out was to store the negation of the last prime and test on that minus the current value. This is shorter in Pyth since the primality check is overloaded: on positive numbers it finds the prime factorisation while on negative numbers it determines if the positive value of the number is prime.
This more or less translates into:
to_find = input()
last_prime = 0
current = 0
results = []
while to_find > 0:
    if is_prime( current + last_prime ):
        results.append( current )
        to_find -= 1
        last_prime += current
    current += 1
print results

Replace _+ with - and + with - for -1 byte.

@isaacg That's quite clever! I'll edit that in.

Perl 6, 45 bytes
2,{first (*+@_.sum).is-prime,@_[*-1]^..*}...*

Try it online!
Returns a lazy list that generates the sequence with no end.
Explanation:
This uses the Sequence operator ... which defines the sequence as:
2,  # The first element is 2
  {  # The next element is:
    first  # The first value that:
          (*+@_.sum).is-prime,  # When added to the sum is a prime
          @_[*-1]^..*  # And is larger than the previous element
  }
...*  # And continue the sequence indefinitely

Haskell, 67 bytes
(1#1)2 2
(p#n)s k|p`mod`n>0,n-s>k=k:(p#n)n(n-s)|w<-p*n=(w#(n+1))s k

Try it online!
(1#1)2 2 is a functions that takes no input and outputs an infinite list.

old answer:
Haskell, 88 83 78 76 bytes
The primality test is from this answer and improved by Christian Sievers (-2 bytes).
-5 bytes thanks to W W.

2#2
(p#s)n|n<1=p|w<-until(\m->mod(product[1..m-1])m>0)(+1)$s+p+1=(w-s)#w$n-1

Try it online!

You can do without ^2. That will change the predicate from testing is prime to testing is prime or 4, which doesn't matter in this application.

MATL, 21 bytes
O2hGq:"t0)yd0)+_Yqh]d

Try it online!
Output is the first n terms of the sequence.
Explanation:
Constructs a list of primes (with an initial 0), and at the end finds the returns the differences between successive primes in the list.
              % Implicit input, say n
O2h           % Push P = [0, 2] on the stack
Gq:"          % for loop: 1 to n-1
  t0)           % Take the last element of P
                %  Stack: [[0, 2], [2]] (in first iteration)
  yd0)          % Take the difference between the last
                %   two elements of P
                %  Stack: [[0, 2], [2], [2]]
  +             % Add those up
                %  Stack: [[0, 2], [4]]
  _Yq           % Get the next prime higher than that sum
                %  Stack: [[0, 2], [5]]
  h             % Concatenate that to the list P
                %  Stack: [[0, 2, 5]]
]             % End for loop
d             % Get the differences between successive elements of
              %   the final list P

JavaScript (ES6), 63 bytes
Returns the \$n^{th}\$ term, 1-indexed.
n=>(k=0,s=1,g=d=>s%d?g(d-1):d<2?--n?g(s-=k-(k=s)):s-k:g(s++))()

Try it online!

05AB1E (legacy), 12 bytes
0U[XN+DpiN,U

Try it online!
Explanation
0U              # initialize X as 0
  [             # start an infinite loop
   XN+          # add X to N (the current iteration number)
      Dpi       # if the sum is prime:
         N,     #   print N
           U    #   and store the sum in X

There are a couple of different 12-byte solutions possible.
This particular one could have been 10 bytes if we had a usable variable initialized as 0 (instead of 1 and 2).

Python 2, 119 bytes
f=lambda n,k=1,m=1:m%k*k>n or-~f(n,k+1,m*k*k)
def g(i):
 r=[2]
 for j in range(i):r+=[f(sum(r)+r[-1])-sum(r)]
 return r

Try it online!
Next Prime function f() taken from this answer.
Function g() takes a non-negative integer i and returns a list of all items in the sequence up to that index.

-7 bytes.

C (gcc), 100 99 bytes

Saved a byte thanks to ceilingcat.

p(r,i,m,a,l){for(l=m=a=0;a-r;)m+=i=p(a++);while(r*!l)for(++i,l=a=2;a-m-i;)l=(m+i)%a++?l:0;r=r?i:2;}

Try it online!

Haskell, 101 99 97 bytes
The function l takes no arguments and returns an infinite list. Not as short as the more direct approach by @ovs (and I obviously stole some parts form their answer), but maybe still golfable?
Thanks @H.PWiz for -2 bytes!
import Data.List
p m=mod(product[1..m-1])m>0
l=2:[until(p.(+sum a))(+1)$last a+1|a<-tail$inits l]

Try it online!

Python 2, 99 98 bytes
def f(n,s=2,v=2):
 k=s-~v
 while any(k%i<1for i in range(2,k)):k+=1
 return n and f(n-1,k,k-s)or v

Try it online!
1 byte thx to Mr. Xcoder.

I know... I know... Me and my bitwise-tricks pedantry :) But you can save a byte with k=s-~v.

@Mr. Xcoder: Your unholy bitwise sorcery will be the end of you yet! :)

Python 2, 82 80 bytes
s=p=2
i=input()
P=n=1
while i:
 P*=n;n+=1
 if P%n>0<n-s-p:p=n-s;s=n;i-=1
print p

Try it online!
This outputs the nth number of the sequence (0-based). By moving the print in the loop, this can be modified to output the first n items at the same bytecount: Try it online!

PARI/GP 73 bytes
a(n)=v=[2];s=vecsum;while(n--,v=concat(v,nextprime(s(v)+v[#v]+1)-s(v)));v

1-indexed, output: first n terms

Pyth, 13 bytes
I%sjs.BQ2 2\1.?0

Simply converts a given input to binary and prints the respective output whether the sum of 1's in the output list is even or not.
Made in about 5 seconds, and can probably be done in way fewer characters than I have, but hey, I tried.

Japt, 17 bytes
Outputs the nth term, 0-indexed.
@_+T j}aXÄT±X}g2ì

Try it


text:
Number Spiral Problem
A number spiral is an infinite grid whose upper-left square has number 1. Here are the first five layers of the spiral:

Your task is to find out the number in row y and column x.

Example:
Input: 2 3
Out  : 8
Input: 1 1
Out  : 1
Input: 4 2
Out  : 15

Note:

Any programming language is allowed.
This is a code-golf challenge so shortest code wins.
Best of Luck!

Source: https://cses.fi/problemset/task/1071

@WW What does that mean ?

It looks like your inputs are 1 indexed (coordinates start at 1,1) (although this has to be intuited from the test cases) can we use 0 indexing (coordinates start at 0,0)?

@WW No. The coordinates should start at 1,1. Sorry.

What is the reasoning for this?

@WW No reason. Just arbitrary

I think it's absolutely fine for the coordinates to start at (1, 1), especially if the program is posted that way on CSES, and the OP doesn't need to justify this. I think golfers here are getting a little too used to somewhat arbitrary freedoms.

@Lynn I second that

For circular spiral see this challenge.

Japt, 16 14 10 bytes
(Originally) Adapted from Doorknob's solution over a few beers.
wV
nU²ÒNra

Try it
wV\nnU²ÒNra     :Implicit input of integers N=[U=y, V=X]
wV              :Maximum of U & V
  \n            :Reassign to U, leaving the value in N unchanged
    n           :Subtract U from
     U²         :  U squared
       Ò        :  Subtract the bitwise NOT of
        Nr      :  N reduced by
          a     :    Absolute difference

C (gcc),  44  43 bytes
f(x,y,z){z=x>y?x:y;z=z*z-~(z%2?y-x:x-y)-z;}

Try it online!
The spiral has several "arms":
12345
22345
33345
44445
55555

The position \$(x, y)\$ is located on arm \$\max(x, y)\$ (assigned to variable z). Then, the largest number on arm \$n\$ is \$n^2\$, which alternates between being in the bottom left and top right position on the arm. Subtracting \$x\$ from \$y\$ gives the sequence \$-n+1, -n+2, \ldots, -1, 0, 1, \ldots, n-1, n-2\$ moving along arm \$n\$, so we choose the appropriate sign based on the parity of \$n\$, adjust by \$n-1\$ to get a sequence starting at 0, and subtract this value from \$n^2\$.
Thanks to Mr. Xcoder for saving a byte.

f(x,y,z){z=x>y?x:y;z=z*z-~(z%2?x-y:y-x)-z;} saves 1 byte.

@Mr.Xcoder Neat trick, thanks!

Crossed out 44 is still regular 44 ;(

@Agile_Eagle Why?

Correct me if I'm missing something. The input should be an x and y coordinate and the output is the number in row y and column x. This looks like the output is the spiral itself.

@RobertS. You are right!

@Doorknob You must output the number in row y and column x, not the spiral itself.

@JonathanFrech What do you mean ?

@RobertS. Yes, that is what the function I defined does (in the Code section on TIO). For instance, f(1, 1) returns the value 1. The Footer section loops through x=1 through 5 and y=1 through 5, calls the function for all such values, and prints its output in a grid, to demonstrate that the function is correct for all inputs shown in the question.

@Agile_Eagle The function does return the number (it couldn't output the spiral - it doesn't even have any loops!).

@Doorknob I got it! Thanks :)

Python,  54   50  49 bytes
def f(a,b):M=max(a,b);return(a-b)*(-1)**M+M*M-M+1

-4 bytes thanks to @ChasBrown
-1 bytes thanks to @Shaggy
Try it Online!
First time golfing! I'm more than aware this is not optimal, but whatever.
Essentially runs on the same principle as @Doorknob C code.

Welcome to PPCG! In this case you can save 4 bytes using the def f(a,b): approach, see here.

@ChasBrown Very interesting, thank you!

@Shaggy Thank you! I've posted a few challenges, but never been good enough to golf

In that case, then, welcome to Golf! :) I'm not a Python guy but I'm pretty sure M**2 can be replaced with M*M.

@Shaggy Thank you! Will fix right now

MATL, 15 bytes
X>ttq*QwoEqGd*+

Try it online!
Collect and print as a matrix
How?
Edit: Same technique as @Doorknob's answer, just arrived at differently.
The difference between the diagonal elements of the spiral is the arithmetic sequence \$ 0, 2, 4, 6, 8, \ldots \$. Sum of \$ n \$ terms of this is \$ n(n - 1) \$ (by the usual AP formula). This sum, incremented by 1, gives the  diagonal element  at position \$ (n, n) \$.
Given \$ (x, y) \$, we find the maximum of these two, which is the "layer" of the spiral that this point belongs to. Then, we find the diagonal value of that layer as \$ v = n(n-1) + 1 \$. For even layers, the value at \$ (x, y) \$ is then \$ v + x - y \$, for odd layers \$ v - x + y \$.
X>        % Get the maximum of the input coordinates, say n
ttq*      % Duplicate that and multiply by n-1
Q         % Add 1 to that. This is the diagonal value v at layer n
wo        % Bring the original n on top and check if it's odd (1 or 0)
Eq        % Change 1 or 0 to 1 or -1
Gd        % Push input (x, y) again, get y - x
*         % Multiply by 1 or -1
          % For odd layers, no change. For even layers, y-x becomes x-y
+         % Add that to the diagonal value v
          % Implicit output

Alternate 21 byte solution:
Pdt|Gs+ttqq*4/QJb^b*+

Try it online!
Collect and print as a matrix
From the above, we know that the function we want is
$$ f = m * (m - 1) + 1 + (-1)^m * (x - y) $$
where \$ m = max(x, y) \$.
Some basic calculation will show that one expression for max of two numbers is
$$ m = max(x, y) = \frac{x + y + abs(x - y)}{2} $$
Plugging one into another, we find that one alternate form for \$ f \$ is:
$$ f = (x-y)\cdot i^{k} + \frac{1}{4}((k-2)\cdot k) + 1 $$
where \$ k = abs(x-y) + x + y  \$.
This is the function the solution implements.

Pyth, 20 bytes
A~Qh.MZQh-+*-GH^_1Q*

Test suite
An almost literal translation of Rushabh Mehta's answer.
Explanation:
A~Qh.MZQh-+*-GH^_1Q*    | Full code
A~Qh.MZQh-+*-GH^_1Q*QQQ | Code with implicit variables filled
                        | Assign Q as the evaluated input (implicit)
A                       | Assign [G,H] as
 ~Q                     |  Q, then assign Q as
   h.MZQ                |   Q's maximal value.
                        | Print (implicit)
        h-+*-GH^_1Q*QQQ |  (G-H)*(-1)^Q+Q*Q-Q+1

Jelly, 13 bytes
»Ḃ-*×_‘+»×’$¥

Try it online!
Uses Doorknob's method. Way too long.

Alternative: »Ḃ-*×_‘+»²_»ʋ

Jelly, 13 12 bytes
ṀḂḤ’×I+²_’ṀƲ

Try it online!
Computes the diagonal term with ²_’Ṁ and adds/subtracts to the correct index value with ṀḂḤ’×I.

Brain-Flak, 76 bytes
((({}<>))<>[(({}))]<{({}[()])<>}>)<>{}((){({}[()])({})<><([{}])><>}{}<>{}<>)

Try it online!

05AB1E, 12 11 bytes
ZÐ<*>ŠGR}¥+

-1 byte thanks to @Emigna changing Èi to G.
Port of @sundar's MATL answer, so make sure to upvote him!
Try it online or verify all test cases.
Explanation:
Z              # Get the maximum of the (implicit) input-coordinate
               #  i.e. [4,5] → 5
 Ð             # Triplicate this maximum
  <            # Decrease it by 1
               #  i.e. 5 - 1 → 4
   *           # Multiply it
               #  i.e. 5 * 4 → 20
    >          # Increase it by 1
               #  i.e. 20 + 1 → 21
     Š         # Triple swap the top threes values on the stack (a,b,c to c,a,b)
               #  i.e. [4,5], 5, 21 → 21, [4,5], 5
      G }      # Loop n amount of times
       R       #  Reverse the input-coordinate each iteration
               #   i.e. 5 and [4,5] → [5,4]→[4,5]→[5,4]→[4,5] → [5,4]
         ¥     # Calculate the delta of the coordinate
               #  [5,4] → [1]
          +    # And add it to the earlier calculate value (output the result implicitly)
               #  21 + [1] → [22]

Èi could be G.

@Emigna Oh smart, thanks! :D

Pascal (FPC), 90 bytes
uses math;var x,y,z:word;begin read(x,y);z:=max(x,y);write(z*z-z+1+(1and z*2-1)*(y-x))end.

Try it online!
Port of Doorknob's answer, but sundar's answer gave me idea for z mod 2*2-1 which I transformed into 1and z*2-1 to remove space.

Mathematica 34 bytes
x = {5, 8};

so:
m = Max[x];
Subtract @@ x (-1)^m + m^2 - m + 1

(*
54
*)

Julia 1.0, 35 bytes
x\y=(m=max(x,y))*~-m+1+(-1)^m*(x-y)

Try it online!

JavaScript (ES6), 46 bytes
f=(r,c,x)=>r<c?f(c,r,1):r%2-!x?r*r-c+1:--r*r+c

Java (JDK 10), 39 bytes
x->y->(y-x)*((y=x>y?x:y)%2*2-1)+y*y-y+1

Try it online!
Credits

Port of Doorknob's answer.

Rockstar, 127 118 115 bytes
Also adapted from Doorknob's solution.
listen to Y
listen to X
let M be Y is less than X and X-0 or Y-0
let R be M*M-M
let R be-M-Y and Y-X or X-Y
say R+1

Try it here (Code will need to be pasted in, with each input integer on an individual line)


text:
Checking a file contains only null bytes
Your goal is to write a program or function that takes in as input a string representing the path to a file, and outputs a truthy value if that file is not empty and contains no non-null bytes -- i.e., all bits are 0 -- and a falsey value otherwise.
I realize it is a very simple problem and I guess I could hack
something, but I suspect there must be some short and elegant way of
doing it, and that gave me the idea to make a challenge out of it.
This is code-golf, so shortest code in bytes wins. (My own preference would go to the fastest solution, but that is too implementation dependent...)
Related questions: Pad a file with zeros
Motivation : This is only to tell where the problem comes from, in case you are interested. You do not need to read it.
ISO images of CDs and DVDs, copied with "dd" or other
means, often terminate with a sequence of useless blocks containing
only null bytes. Standard techniques to remove these blocks are known
and simple (see
https://unix.stackexchange.com/questions/74827/ )
but they may sometimes remove non null useful data because the medium
can lie about its own size. So I want to check that the removed
blocks contain only null bytes. Removing these blocks is important for defining a normalised version of ISO-images.

Pyth, 6 5 bytes
!sCM'

Try it online!
Takes a filename from STDIN, opens and reads the file, converts it to a list of ints (think Python ord) sums the list (will return 0 iff file is all null bytes), and nots the result, printing it.

Hey,
This looks a lot like a general programming question. These belong on Stack Overflow. However, from the comments under the main post, I can see that this was not your intent. That said, I feel that the discussion has been unnecessarily hostile on both sides, so I've decided to pick up the slack and give you the proper PPCG welcome!
Generally, we ask that any challenges are first posted to our sandbox for proper feedback. You can take a look at the current submissions in there to see what format we prefer for challenges. Please give it a try next time!
Just in case we've all misunderstood you and you are looking for a general solution, here's a solution in Python 3:
def main(string):
    with open(string) as file:
        return not any(map(ord,file.read()))

This will not work with a grayscale image consisting of only black pixels (zeroes), due to how powerful ' is.

Besides: OP requires taking file name as input using command-line argument, and return as status code.

GNU sed -zn, 5 bytes
The input file is passed to sed as a command-line parameter.  Output as a standard shell return code - i.e. 0 is TRUE, 1 is FALSE.
/./q1

Normally sed works on newline-delimited input records (AKA "lines").  -z changes this to nul-delimited input records.  If any input records match the . regex, then quit with exit code 1.
Try it online!

DOS, 37 bytes

100:BE 80 00 MOV SI, 0080
103:AD       LODSW ;get command-line length
104:98       CBW ;only a byte
105:93       XCHG BX,AX
106:88 40 FF MOV [BX+SI-01], AL ;zero end of name
109:B4 3D    MOV AH, 3D
10B:89 F2    MOV DX, SI
10D:CD 21    INT 21 ;open file
10F:93       XCHG BX, AX ;handle into BX
110:AF       SCASW ;DI=0
111:B4 3F    MOV AH, 3F
113:B1 01    MOV CH, 01
115:CD 21    INT 21 ;read 1 byte
117:91       XCHG CX, AX
118:E3 06    JCXZ 0120 ;quit on EOF
11A:97       XCHG DI, AX ;set true for later
11B:38 2C    CMP [SI], CH
11D:74 F2    JZ 0111 ;loop while zero
11F:4F       DEC DI ;set false
120:97       XCHG DI, AX
121:B4 4C    MOV AH, 4C ;return
123:CD 21    INT 21
It opens the file named on the command-line, returns 0 if empty or contains non-zero, otherwise returns 1.

Attache, 24 bytes
Zero@Max&0@Ords@FileRead

Try it online!
Explanation
This is a composition of 4 functions, executed one after the other:

FileRead - takes a file name as input, returns the contents of that file
Ords - returns the ASCII code points of each character in a list
Max&0 - this is equivalent to, for argument x, Max[x, 0]; this in turn computes the maximum of all entries in x and 0 (yielding 0 for the empty list)
Zero - this is a predicate that checks if this number is in fact 0, and returns that boolean.

OP requires full program, call from command line, take file name as input using argument, and return as status code. (@_@)

Doesn't this give a false positive for an empty file?

@ngenisis the original problem stated the following: "That means the empty file is considered OK" -- check the revision history, it seems that a certain user edited that point out of the question.

C (32bit platform), 65 bytes
main(x,v)int*v;{for(v=fopen(v[1],"r");!(x=fgetc(v)););return++x;}

Assumes sizes of pointers are all the same, which is almost always true. Returns with a 0 exit code on success (file contains only NUL characters), some other value otherwise.
Behavior is undefined if command line argument isn't a path to a readable file.

I think you need to write int**v? I can't find a compiler where this doesn't segfault without doing that. Also, you can save a bit by intentionally erroring, but I don't know if this is the best approach.

Huh? I tried this with gcc on mingw32, works flawlessly. I probably should add the constraint sizeof(void*) == sizeof(int) (or more generally "32-bit platform") then ... on an amd64 platform, try compiling with -m32 ;)

@FryAmTheEggman also works on TIO when compiled as 32bit code (-m32): Try it online!

Ah, of course. NIce work, then! Feel free to use my suggestion to save the couple bytes :)

Bash + GNU utilities, 26 bytes
od -An $1|grep -qv [^0\ *]

Input filename is given as a command-line parameter.  Output as a standard shell return code - i.e. 0 is TRUE, 1 is FALSE.
Try it online!

JavaScript (ES8), 52 bytes
Takes a url as an argument and returns a promise that resolves to true if the file isn't empty and contains no null bytes.
async p=>!/\0|^$/.test(await(await fetch(p)).text())

Haskell, 49 bytes
import Data.ByteString
f=(all(<1)<$>).getContents

Obviously if the import is not included, then it is 26 bytes.

I guess you meant readFile instead of getContets. I think you can read the file as a normal String, compare to =='\0' (or better <'\1') and get rid of the import.  As you can use an anonymous function, you can drop the f x= and go pointfree: (all(<'\1')<$>).readFile.

If it's a binary file, you cannot use readFile, which will throw an exception upon encountering an invalid Unicode sequence. Good point regarding the pointfree.

Python 3, 59 bytes
f=lambda s:any(open(s,'rb').read())+not len(open(s).read())

Returns 0 for success (all bytes zero).
Returns 1 for failure (at least one nonzero byte, or zero length file).

If the file is empty, you must return Failure.

APL (Dyalog Unicode), 14 bytes
Full program. Prompts for filename from stdin.
0=⌈/11 ¯1⎕MAP⍞

Try it online!
⍞ prompt for filename
11 ¯1⎕MAP map that file to a packed bit array
⌈/ maximum (reduction); smallest float if empty, otherwise 0 or 1
0= is zero equal to that?

Wolfram Language (Mathematica), 30 bytes
BinaryReadList@#~MatchQ~{0..}&

Try it online!
Explanation
                             & (* Function which returns whether *)
BinaryReadList                 (* the list of bytes *)
              @                (* of *)
               #               (* the input *)
                ~MatchQ~       (* matches *)
                        {0..}  (* a list of a one or more zeros *)

Alternate solution, 22 bytes
If empty files are supposed to pass, then this can be shortened to:
Tr@BinaryReadList@#<1&

Try it online!

Java, 149 bytes
boolean b(String f)throws Exception{java.io.InputStream s=new java.io.FileInputStream(f);int i=Math.abs(s.read());while(i==0)i+=s.read();return i<0;}

Perl 5, 20 bytes
$\=0;exit<>=~/^\0+$/
Takes a file name in command line args and returns the response in the exit code of the program

Zsh, 35 bytes
! for c (${(s::)"$(<$1)"})((i|=#c))

Try it online! Outputs via exit code.
Read in, split on characters, and bitwise-or each codepoint together.
If the file is empty, the body of the loop is never run and so the loop returns truthy. If the truthy-falsy values can be swapped, the leading ! can be removed for a 2-byte save.


text:
Polite Near-Sighted Drunk Bot on a Minefield
As the title may suggest, this problem is semi-inspired by the Polite Near-Sighted Drunk Bot by @N.P.
Our poor bot is placed on a cartesian grid at the origin, and after each minute, it moves 1 unit in one of four directions (Up, Down, Left, Right).
After n minutes, all of the latent mines on the grid activate, killing any poor bot that might find themselves over them. The mines are located at all integer coordinates satisfying the equation |y|=|x|.
Challenge
You will be provided n, the number of minutes before the mines blast, as an input, and as an output, you must find the probability that the bot is dead.
Input: An natural number representing n.
Output: Let the probability the bot is dead be p/q, where p and q are relatively prime whole numbers (q can't be 0, but p can). Output p.
Rules

Your algorithm must not run in exponential or higher time. It ideally should run in polynomial time or less.
Your algorithm must be able to handle inputs of n<20 (can be adjusted if too hard) in a reasonable time.
This is a code-golf challenge.
Iterating over all possibilities for a given n will most definitely not be accepted as an answer.

Test Cases
1->0
2->3
4->39
6->135
8->7735
10->28287
Example Calculation for n=6
We have 4 possible moves: U, D, R, and L. The total number of paths that could be taken is 4^6, or 4096. There are 4 possible cases that land along the line y = x: x,y = ±1; x,y = ±2; x,y = ±3; or x = y = 0. We will count the number of ways to end up at (1,1), (2,2), and (3,3), multiply them by 4 to account for the other quadrants, and add this to the number of ways to end up at (0,0).
Case 1: The bot ends at (3, 3). In order for the bot to end up here, it must have had 3 right moves, and 3 up moves. In other words, the total number of ways to get here is the ways to rearrange the letters in the sequence RRRUUU, which is 6 choose 3 = 20.
Case 2: The bot ends at (2,2). In order for the bot to end up here, it could have had 2 up moves, 3 right moves, and 1 left move; or 2 right moves, 3 up moves, and 1 down move. Thus, the total number of ways to get here is sum of the ways to rearrange the letters in the sequences RRRLUU and UUUDRR, both of which are (6 choose 1) * (5 choose 2) = 60, for a total of 120 possibilities.
Case 3: The bot ends at (1,1). In order for the bot to end up here, it could have had:
1 right move, 3 up moves, and 2 down moves. In this case, the number of ways to rearrange the letters in the sequence RUUUDD is (6 choose 1)*(5 choose 2) = 60.
1 up move, 3 right moves, and 2 left moves. In this case, the number of ways to rearrange the letters in the sequence URRRLL is (6 choose 1)*(5 choose 2) = 60.
2 right moves, 1 left move, 2 up moves, and 1 down move. In this case, the number of ways to rearrange the letters in the sequence UUDRRL is (6 choose 1)* (5 choose 1)*(4 choose 2) = 180.
Thus, the total number of ways to end up at (1,1) is 300.
Case 4: The bot ends at (0,0). In order for the bot to end up here, it could have had:
3 right moves and 3 left moves. In this case, the number of ways to rearrange the letters in the sequence RRRLLL is (6 choose 3) = 20.
3 up moves and 3 down moves. In this case, the number of ways to rearrange the letters in the sequence UUUDDD is (6 choose 3) = 20.
1 right move, 1 left move, 2 up moves, and 2 down moves. In this case, the number of ways to rearrange the letters in the sequence RLUUDD is (6 choose 1)* (5 choose 1)*(4 choose 2) = 180.
1 up move, 1 down move, 2 right moves, and 2 left moves. In this case, the number of ways to rearrange the letters in the sequence RRLLUD is (6 choose 1)* (5 choose 1)*(4 choose 2) = 180.
Thus, the total number of ways to end up at (0,0) is 400.
Adding these cases together, we get that the total number of ways to end up on |y| = |x| is 4(20 + 120 + 300) + 400 = 2160. Thus, our probability is 2160/4096. When this fraction is fully reduced, it is 135/256, so our answer is 135.

I like the challenge but I think it would benefit from including a worked example for one of the very small test cases (2 or 3) for instance.

@Mr.Xcoder I will add one when I have time.

I presume the bot chooses one of four directions uniformly at random? I also think it would be helpful to post the denominators for the test cases too so if our answers are off we can see which direction.

@xnor correct,  it's uniformly random.  I'll add the denominators when i'm home from work.

Interesting challenge. Note that using the word "ideally" in a rule makes it not a rule. It would be useful to say definitely one way or the other.

@trichoplax I didn't want to be too strong on the polynomial req. Rather, I want to focus on the complexity being less than exponential

But nobody talks about First Gen Learning Algorithm?

@RedwolfPrograms ahaha yea but this bot has the cooler name

Python 2, 65 bytes
def p(n):b=2**n;r=b*b-((~b)**n/b**(n/2)%-b)**2;print~n%2*r/(r&-r)

Try it online!
The probability the bot is dead can be expressed as:

$$ f(n) = 2s-s^2\text{, where }  s=\frac{1}{2^n}\binom{n}{n/2}$$

and the binomial is understood to equal \$0\$ when \$n/2\$ isn't whole.
We can reason like this. What's the probability that the bot lands on the \$y=x\$ line? This happens if the total number of up and left moves equals the total number of down and right moves. This is the same probability that, say, you flip a coin \$n\$ times and get as many tails as heads. You must choose \$n/2\$ flips to be heads of \$n\$ flips, which can be done in \$\binom{n}{n/2}\$ ways, of \$2^n\$ possible sequences overall, giving probability
$$s=\frac{1}{2^n}\binom{n}{n/2}$$
The probability of landing the \$y=-x\$ line is also \$s\$. So, the probability of landing on either line is the sum of these or \$2s\$, except we're double-counting the probability of landing of \$x=y=0\$ in both lines, and must subtract it to compensate.
It turns out the probability of landing on \$x=y=0\$ is just \$s^2\$, the product of the probability of landing on each line. We can argue the events are independent as follows: if we pick a random sequence of equal numbers of "Up or Left" and "Down or Right" to land on \$x=y\$ and likewise with "Up or Right" and "Down or Left" for \$x=-y\$, we can uniquely combine them into a sequence of Up, Down, Left, Right by taking the intersection of the pairs of directions at each position.
So, the probability of landing on \$x=y\$ or \$x=-y\$ is \$2s-s^2\$.
The code computes the binomial \$\binom{n}{n/2}\$ using this expression as (b+1)**n/b**(n/2)%b with base b=2**n. To extract the numerator from the probability fraction, we note that the denominator is a power of 2, so we use the expression r/(r&-r) to divide out the maximal power of 2 is r, expressed as the classic bit trick r&-r.
The solution is golfed by writing \$2s-s^2\$ as \$1-(1-s)^2\$ so that \$s\$ is only referenced once, and working without the \$1/2^n\$ fractions to stay within the integers. The computation is polynomial-time in \$n\$ even with the funky way of computing binomials.

After writing the proof of the probability the bot dies, I found a possibly cleaner way to prove it and present it.
Let's keep track of the values of \$a=x+y\$ and \$b=x-y\$ after each move of the bot. Each of the four directions up, down, left, and right either increments or decrements each of \$a\$ and \$b\$, with the four directions corresponding to the four combinations.
So, a random move is equivalent to randomly adding \$\pm 1\$ to \$a\$ and independently \$\pm 1\$ to \$b\$. This is equivalent to doing separate random walks on \$a\$ and \$b\$.
Now, the robot ends on the line \$x=y\$ or \$x=-y\$ exactly when \$a=0\$ or \$b=0\$. So, the probability of ending with \$a=0\$ is \$s=\frac{1}{2^n}\binom{n}{n/2}\$ and likewise for \$b=0\$. Since the walks are independent, the probability that \$a\neq 0\$ and \$b\neq 0\$ is \$(1-s)^2\$, so the probability that at least one is zero is the complement \$1-(1-s)^2\$.

Fantastic! I was waiting for someone to derive this.  I didn't imagine it being so fast.  The downside now is that most of the other answers won't have to think too much :(. Excellent +1

enjoy the small bounty (don't have much to give so sorry)

@RushabhMehta Thank you, that's very kind of you! Your bounty motivated me to write up a cleaner proof I thought of afterward.

The real inspiration for this problem was AIME I 2014 problem 11, if you want to check it out.