text:
There are two new sheriffs in town – Identifying DJMcMego pairs!
We have some new sheriffs moderators in town, Mego and DJMcMayhem. We need a challenge to properly honour them for their new positions, so there we go.
Here's something that has caught my attention when hovering over their profiles –  their user IDs are \$31716\$ and \$45941\$. If you perform digit-wise subtraction, you'll notice something pretty exciting (of course, taking the absolute differences):
3|1|7|1|6
4|5|9|4|1
-+-+-+-+- (-)
1|4|2|3|5

The number generated by the above algorithm is \$14235\$. There is something special about this integer: It consists of consecutive digits only, sorted in  ascending order, but exactly one of the digits is not placed correctly — \$4\$.
We will call a pair of positive integers \$(a, b)\$ a DJMcMego pair if the digit-wise absolute differences are consecutive integers, sorted in ascending order, but exactly one of them is not where it belongs. That is, it is possible to move exactly one digit of the result of digit-wise subtraction to another position, such that the integer obtained only has consecutive digits, sorted in ascending order.
In our example above, the pair \$(31716, 45941)\$ is a DJMcMego pair, because if \$4\$ is moved between \$3\$ and \$5\$, the result is \$12345\$, which fulfils the criteria. Note that the digits of the resulting number do not need to start at \$1\$, they just ought to be consecutive. When one is unsure about what decision they should make, they can always rely on the other's help to sort things out.
Your task is to output a truthy/falsy value depending on whether a pair of positive integers given as input is a DJMcMego pair.

You are guaranteed that \$a\$ and \$b\$ will have the same number of digits, always at least 4.
You can take the integers in any reasonable format (i.e. native integers, strings, lists of digits, etc.)
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.

Test cases
a, b -> Output

31716, 45941 -> Truthy
12354, 11111 -> Truthy
56798, 22222 -> Truthy
23564, 11111 -> Truthy
1759,  2435  -> Truthy
12345, 11111 -> Falsy
3333,  2101  -> Falsy
22354, 22222 -> Falsy
31717, 45941 -> Falsy
14325, 11111 -> Falsy
89789, 78865 -> Falsy
14954, 61713 -> Falsy
25631, 11114 -> Falsy

Or, in another format.

Can we output truthy for non-DJMcMego pairs and falsy for DJMcMego pairs? Also do the truthy/falsy values need to be consistent?

Mego can have my upvote if he writes a solution in Actually.

@Blacksilver I think I've beaten him to it :P

@dylnan 1) They do not have to be from 1 to n, they just have to be consecutive. The test cases already cover that. 2) Swapping the truthy / falsy values is allowed by default 3) The truthy/ falsy values need not to be consistent by default.

@Mr.Xcoder "Swapping the truthy / falsy values is allowed by default" Is that actually a thing?

@MartinEnder I lost the count of Returns False if the input is an X number, True otherwise I've seen so far. Yes I believe it is allowed, otherwise I'm going to allow it for this challenge anyway

@Mr.Xcoder Sure, many challenges allow it, but saying "it's allowed by default" implies to me that there's a meta post about it somewhere.

@MartinEnder I do think there is a meta post about it. I'll try searching for it shortly, and if I don't find anything, I'll just ask myself.

Could we output one consistent value for true and a different but inconsistent value for false? For example, 1 for true and any other number for false.

@Shaggy Your output must satisfy the standard definition of truthy / falsy. If all other numbers except for 1 are falsy in your language (i.e. in 05AB1E, only 1 is truthy), then that is allowed. If that's not the case, I am afraid that's not allowed (that would disadvantage the existing answers). So you need to include ==1 or a variation thereof in your byte count :)

MegoMayhem pairs hehehe... Me Go Mayhem.

@Mr.Xcoder (1) may have been covered in the examples but it wasn't clear from the challenge specifications. I've had a challenge closed for that before. Not saying this challenge should have been closed I just think all specs should be written explicitly.

Maybe add 25631, 11114 as example. The differences are 14523 which confuses several of the current programs

Please add 14325, 11111 as a test case.

What you're doing is similar to Ramanujan's "taxicab numbers": he was able to find an interesting property (the smallest number expressible as two cubes in multiple ways) in coincidental data (his taxicab number, 1729). Strangely enough, the OEIS sequence number for the taxicab numbers is 1235, which looks almost like one of these sequences :P

C (gcc), 259 258 254 253 250 248 233 222 bytes

Thanks to Stan Strum for inspring a one byte golf.
Saved four bytes by juggling some variable initializations.
Saved a byte by golfing for(...;l++)b*=B[l]==-~B[l-1]; to for(...;b*=B[l]==-~B[~-l++]); (most likely relying on undefined behaviour, as it requires first evaluating B[l] followed by -~B[~-l++]).
Saved three five bytes.
Saved fifteen twenty-six bytes thanks to ceilingcat.

j,k,l,L,r,b;f(char*A,char*B){for(j=r=0;k=A[L=j];)A[j++]=-~abs(A[j]-B[j]);for(;k-L;k++)for(j=~0;L-++j;r|=!b)if(k-j)for(bcopy(B-~l,strcpy(B,A)+l,strlen(A+l)),bcopy(B+j,B-~j,L+~j),B[j]=A[k],l=b=0;B[++l];b|=B[l]+~B[~-l]);A=r;}

Try it online!
Explanation (248 byte version)
j,k,l,L,r,b;                            // global variables
f(char*A,char*B){                       // function takes two strings
 for(j=r=0;A[j];L=j)                    // loop through A, compute array length L
  A[j++]=-~abs(A[j]-B[j]);              // set every entry in A to the absolute
                                        // difference of A and B at that position
                                        /* Test out all possible movements of        *
                                         * characters and see if any one             *
                                         * results in a sorted list => DJMcMego pair */
 for(j=0;j-L;j++)                       // loop through array
  for(k=~0;L-++k;r|=!b)                 // loop through array
   if(j-k){                             // j is not equal to k
    for(l=0;A[l];B[l++]=A[l]);          // copy A to B
    for(l=j;A[l];B[~-l]=B[++l]);        // shift part of B
    for(l=L;l-k;B[-~l]=B[--l]);         // shift part of B
    B[k]=A[j];                          // insert character at correct position
    for(l=b=0;B[++l];b|=B[l]+~B[~-l]);} // test if B is sorted
 A=r;}                                  // return if there was a DJMcMego pair found

Try it online!

For loops that only run 1 time, you can skip j=0 as in the 41st char

@StanStrum I am fairly certain that you then rely on j having the value 0 which is not necessarily the case after several calls. A function, however, should be arbitrarily often callable and still solve the challenge (relevant meta post).

@StanStrum You can, however, define j to be zero before the loop and thus save a byte.

You can shave a byte with f(char*A,char*B){ -> f(A,B)char*A,*B;{.

@LambdaBeta Those two snippets are of equal length.

@ceilingcat Thank you a lot!

@ceilingcat Thank you.

05AB1E, 18 bytes
αDæIg<ùʒD{Q}gĀ*{¥P

Try it online!

You should probably add a note that 1 is the only truthy number in 05AB1E; had Mr. Xcoder not informed me on this fact, I would have questioned the validity of this solution. Could you add an explanation, as well, when you have time?

@Shaggy You can take a look at my solution's explanation in the meantime: it's not as efficient as Enigma's but we're mostly using the same functions.

@Shaggy: Didn't have time to add an explanation when I posted this, buty it's done now :)

This fails for the new test case, 14325, 11111 (falsy).

@Dennis: Thanks, should be fixed for now (at the cost of too many bytes). Will have to try and golf this later.

JavaScript (ES6), 130 bytes
Takes input as two arrays of digits in currying syntax (a)(b). Returns a boolean.
a=>b=>a.some((_,i)=>a.some((_,j)=>i-j&&!(A=a.map((v,i)=>Math.abs(v-b[i]))).some(v=>v-A[~k--]-1,A.splice(i,0,A.splice(j,1)[k=0]))))

Try it online!

J, 27 bytes
−8 bytes thanks to FrownyFrog
1"0(-:(2-/\|\:|),1#.2>/\|)-

Try it online!
Initial solution:
J, 35 bytes
[:((1=[:*/2-/\\:~)*1=1#.0<2-/\])|@-

Try it online!
Explanation
Takes lists of digits as input
|@- finds the absolute difference between the digits of the lists
1=1#.0<2-/\] Checks if only one digits is out of its place. First I find the differences between all pairs of adjacent digits and check to see if only one of them is positive.
* Multiply the result from the above test (1 or 0) with the following test:
1=[:*/2-/\\:~ Are all digits consecutive? I sort the list down, take the differences for all pairs of adjacent digits, multiply them and check if it equals 1

Fails for 25634 11111 (as do many other submissions)

@ Ton Hospel - Yes, you are right. I'll check how ti fix it.

I didn’t fix it, just golfed.

@FrownyFrog Thank you! I have forgotten this problem.

SWI-Prolog, 157 bytes
Not very short but the problem seemed particularly well-suited for declarative predicates, variable binding and recursion, i.e., Prolog :)
n(T,Y):-s(T,Q,I,J),s(Y,W,I,J),m(Q,W).
s(T,Q,I,J):-nth0(I,T,X,R),nth0(J,Q,X,R),I\=J.
m([A,B|T],[C,D|Y]):-1 is abs(B-D)-abs(A-C),m([B|T],[D|Y]).
m([_],[_]).

Call with, e.g., n([3,1,7,1,6],[4,5,9,4,1]).
Explanation: move an element in both lists to a new position (using the SWI-Prolog nth0 built-in) and check if the difference of the new lists is consecutive.
s(T,Q,I,J)    % switch (yet unbounded) index I and J in list T, store in Q
s(Y,W,I,J)    % switch (now bounded) I and J in list Y
m(Q,W)        % check new lists
s(T,Q,I,J) :- nth0(I,T,X,R) % X (unbounded) is the I-th (unbounded) element
                            % of list T with rest R (=prefix+postfix)
nth0(J,Q,X,R) % the same X is the J-th element in list Q with the same rest R
I\=J          % I and J are unequal
m([A,B|T],[C,D|Y]) :-  % consider first two elements of both lists
1 is abs(B-D)-abs(A-C) % check if differences are consecutive
m([B|T],[D|Y])         % recursion starting with the second element
m([_],[_]).            % stop recursion at last element in the list

Jelly, 14 bytes
ạµṢ_JEċ@Œ¿-Ƥ%L

Try it online!
How it works
ạµṢ_JEċ@Œ¿-Ƥ%L  Main link. Arguments: A, B (digit arrays)

ạ               Take the elementwise absolute difference. Call the result R.
 µ              New chain. Argument: R
  Ṣ             Sort R.
    J           Indices; yield [1, ..., len(R)].
   _            Take the elementwise difference.
     E          Test if all differences are equal.
                The result is 1 if R consists of consecutive digits, 0 otherwise.
          -Ƥ    For all outfixes of R, generated by dropping one of its elements:
        Œ¿        Get its permutation index (1 if sorted, higher if not).
      ċ@        Count the number of times the Boolean from the left appears in the
                array to the right. If the Boolean is 1, the count represents the
                number of ways a single digit can be deleted to yield a sorted
                array. The count has to be positive for a DJMcMego pair, but less
                than the length of R, since R may not be sorted.
            %L  Take the result modulo len(R), mapping len(R) to 0.

Japt, 18 bytes

Been debating whether I should post this or not for a couple of hours. Came up with it quickly late last night but didn't have time to test it properly (and I thought it might be too long!). Oliver has since posted a similar solution (which was, when this one was originally posted, invalid) so if he, or the community, feels this is too similar, I'll happily delete it.

Takes input as 2 digit arrays, outputs 0 for true or any other number for false.
íaV
ä> x*Un än × É

Try it or check all test cases

Explanation
                   :Implicit input of digit arrays U and V               :[3,1,7,1,6],[4,5,9,4,1]
í V                :Interleave V with U                                  :[[3,4],[1,5],[7,9],[1,4],[6,1]]
 a                 :Get the absolute difference of each pair             :[1,4,2,3,5]
\n                 :Assign that new array to variable U
ä>                 :Is each element greater than the next?               :[false,true,false,false]
     Un            :Sort U                                               :[1,2,3,4,5]
        än         :Get the deltas                                       :[1,1,1,1]
           ×       :Reduce by multiplication                             :1
    *              :Multiply each element in the boolean array by that   :[0,1,0,0]
   x               :Reduce by addition                                   :1
             É     :Subtract 1                                           :0

And, to walk through that process on a few more test cases:
---------------------------------------------------------------
| U   | [2,3,5,6,4] | [1,2,3,4,5] | [3,1,7,1,7] | [1,4,9,5,4] |
| V   | [1,1,1,1,1] | [1,1,1,1,1] | [4,5,9,4,1] | [6,1,7,1,3] |
|-----|-------------|-------------|-------------|-------------|
| íaV | [1,2,4,5,3] | [0,1,2,3,4] | [1,4,2,3,6] | [5,3,2,4,1] |
|-----|-------------|-------------|-------------|-------------|
| ä>  | [F,F,F,T]   | [F,F,F,F]   | [F,T,F,F]   | [T,T,F,T]   |
|-----|-------------|-------------|-------------|-------------|
| Un  | [1,2,3,4,5] | [0,1,2,3,4] | [1,2,3,4,6] | [1,2,3,4,5] |
| än  | [1,1,1,1]   | [1,1,1,1]   | [1,1,1,2]   | [1,1,1,1]   |
| ×   | 1           | 1           | 2           | 1           |
|-----|-------------|-------------|-------------|-------------|
| *   | [0,0,0,1]   | [0,0,0,0]   | [0,2,0,0]   | [1,1,0,1]   |
| x   | 1           | 0           | 2           | 3           |
| É   | 0           | -1          | 1           | 2           |
---------------------------------------------------------------

Fails for 25634 11111 (as do many other submissions)

Perl, 121 118 bytes
($a,$b)=map[split//],@ARGV;
$s+=$l>$_,$l=$_ for@c=map abs($$a[$i]-$$b[$i++]),@$a;
@c=sort@c;
say$s==1&&$c[-1]-$c[0]==$#$a

Test in bash:
function golf {
   perl -E'($a,$b)=map[split//],@ARGV;$s+=$l>$_,$l=$_ for@c=map abs($$a[$i]-$$b[$i++]),@$a;@c=sort@c;say$s==1&&$c[-1]-$c[0]==$#$a' $1 $2
}
golf 31716 45941       #says 1, true
golf 12354 11111       #says 1, true
golf 56798 22222       #says 1, true
golf 46798 22222       #says nothing, false
golf 22354 22222       #says nothing, false
golf 1759 2435         #says 1, true
golf 12345 11111       #says nothing, false
golf 89789 78865       #says nothing, false
golf 14954 61713       #says nothing, false

Fails for 25634 11111 (as do many other submissions)

Perl 5, -F 87 84 83 bytes
Old style counting: 86 bytes (+3 for -F)
Give he numbers as 2 lines on STDIN, the last line without a trailing newline.
Prints the difference string up to 2 times for true, nothing for false
The long A0123456789 string is really annoying.
#!/usr/bin/perl -F
$_=<>;s%.%abs$&-$F[pos]%eg;s%%"'$`$''=~s:|:A0123456789=~/\$`$&\$'/>//&&say:reg"%eeg

Try it online!
I'm usure if this 79 counts as valid:
$_=<>;s%.%abs$&-$F[pos]%eg;s,,$a=$&;"$`$'"=~s:|:A0123456789=~/$`$a$'/%//:reg,eg

It crashes for a valid pair, so you get a non zero exit code. It does nothing if not a pair and exits with exit code 0. I know returning the result via exit code is allowed, but are they properly truthy and falsy or in fact reversed (for the shell 0 is true) ?

Java 8, 245 227 223 194 188  Bytes
Thanks to Kevin for saving ~29 bytes
Thanks to Kevin again for another 6 bytes
 z->{int l=z.length/2,c[]=new int[l],i=0,j=0;for(;i<l;)c[i]=Math.abs(z[i]-z[i+++l]);java.util.Arrays.sort(z=c.clone());for(i=0;i<l-1;j+=z[i]-z[i-1]!=1?1:0)j+=c[i]-c[++i]>0?1:0;return j==1;}

Followed the same pattern Galen came up with for his J answer.
Try it online!

You can golf a few more things like this (194 bytes): z->{int l=z.length/2,c[]=new int[l],i=0,j=0,d[];for(;i<l;)c[i]=Math.abs(z[i]-z[i+++l]);java.util.Arrays.sort(d=c.clone());for(i=0;i<l-1;j+=d[i+1]-d[i++]!=1?1:0)j+=c[i]-c[i+1]>0?1:0;return j==1;} I combined the int and int[] at the start; used l=z.length/2 once and reuse l instead of 4 times; changed the if(...)j++ to j+=...?1:0 so they can be placed inside the loops and the brackets and second semi-colon can be removed; removed the i++ and do ++ directly on the last i in the loop; etc.

188 bytes: z->{int l=z.length/2,c[]=new int[l],i=0,j=0;for(;i<l;)c[i]=Math.abs(z[i]-z[i+++l]);java.util.Arrays.sort(z=c.clone());for(i=0;i<l-1;j+=z[i]-z[i-1]!=1?1:0)j+=c[i]-c[++i]>0?1:0;return j==1;}. Removed d[] and re-used the input z you no longer need; Changed j+=c[i]-c[i+1]?1:0; and j+=d[i+1]-d[i++]!=1?1:0 to j+=c[i]-c[++i]?1:0; and j+=z[i]-z[i-1]?1:0. +1 from me, though. Nice answer! :)

Thanks @Kevin, Everytime you commented I had only found one or two of the many ways you had already golfed it down :P You are much faster than me! Thanks so much for the help!

Hehe :) It all comes with experience, I guess. I'm already golfing in Java for almost two years now. The more you do it, the easier you see these kind of things. And even my answers get golfed down by OlivierGrégoire, Nevay, and some others all the time as well. Oh, you've probably already seen them, but Tips for Golfing in Java and Tips for golfing in  are pretty interesting to read through.

Fails for 25634 11111 (as do many other submissions)

Suggest c[i]>c[++i] instead of c[i]-c[++i]>0

Retina, 102 bytes
+`(.)(.*¶)(.)(.*)
$2$4;$1,$3
\d
*
(_*),\1
_
L$w`(;_+\b)(.*)(;_+\b)
$%`$2$3$1$%"$3$1$2$'
m`(^;_+|\1_)+$

Try it online! Link includes test cases. Returns the number of ways digits can be moved to achieve an ascending sequence, which is 2 for a straight swap since either digit can be moved past the other in that case. Explanation:
+`(.)(.*¶)(.)(.*)
$2$4;$1,$3

Pair up the digits.
\d
*

Convert to unary.
(_*),\1
_

Take the difference, but then add 1 because working with zero in Retina is hard™.
L$w`(;_+\b)(.*)(;_+\b)
$%`$2$3$1$%"$3$1$2$'

List all the sequences of digits obtained by moving exactly one digit.
m`(^;_+|\1_)+$

Check for consecutive digits.

Ruby, 124 113 99 95 bytes
->l,b,d=-1{m=l.map!{|i|(i-b[d+=1]).abs}.sort;l.any?{|*i|m-i==l-i}&&m!=l&&/#{m*''}/=~[*0..9]*''}

Try it online!

Fails for 25634 11111 (as do many other submissions)

@TonHospel fixed it, thanks

Awesome rebound. Have a +1 :-)

Pyt, 20 18 bytes
ą←ą-ÅĐʁ>Ʃ1=⇹ş₋Π1=∧

Try it online!
Explanation:
       Implicitly get the first number
ą      Convert to list of digits
←      Get the second number
ą      Convert to list of digits
-Å     Take the absolute value of the differences of the lists element-wise
Đ      Duplicate the list of differences
ʁ>     Reduce by greater than
Ʃ1=    Is the sum of that array equal to 1
⇹      Swap the top two items on the stack
ş      Sort the top of the stack ascending
₋      Reduce by subtraction (from the right)
Π1=    Is the product of the array equal to 1
∧      bitwise-AND (in this case, also logical AND) the top two items on the stack
       Implicit print

Fails for 25634 11111 (as do many other submissions)

Add++, 105 bytes
D,w,@~,Ñ_€|BSVcGbU1b]2b]+º=
D,k,@,BPB*
L,BcB_€|B]dBkbUBSVcGbU£>sVcGB]VBKB#BKBcB_0º>b]GBK{w}b]++b*1=BK{k}*

Try it online!
Defines a lambda function that takes two lists of digits as input. Outputs a positive integer divisible by 241 for DJMcMego pairs, 0 otherwise.
1: If this is too restrictive, it also outputs a positive integer for DJMcMego pairs, and 0 otherwise
How it works
Here we perform 4 checks to determine if the input is valid. The parts of the code that do those checks are
BcB_€|B]dBkbUBSVcGbU£>sVcGB]V

Here, we take the list of absolute digit differences, then count the number of overlapping pairs which are sorted in descending order. Every DJMcMego pair produces a result of 1, but they are not unique in this aspect. We also store the inputs' absolute digit differences, to save bytes later. This array will be referred to as A throughout.
BKB#BKBcB_0º>b]

Next, we take the elementwise differences between A and A sorted, before asserting that at least one of those differences is negative.
D,w,@~,Ñ_€|BSVcGbU1b]2b]+º=
GBK{w}b]

Third, we check if the pair [1, 2] is contained in the forward increments of A. This checks that, in at least one position of A, it is sorted, which is a criterion for DJMcMego pairs.
D,k,@,BPB*
BK{k}

As our last check, we assert that the second element of A is never 0. In order for a pair, X and Y, to be a DJMcMego pair, we can assume that their A is always unique, as an array with duplicates in it can never be made consecutive by swapping a single value with another.
Finally, we check that the first three of these tests returned 1, and that the fourth returned a value x such that x ≠ 0
A step for step walk through of the code is as follows
D,w,		; Define a function w;
		;   This takes an array of integers
		;   Returns whether the pair [1, 2] appears in the absolute forward differences
		;
	@	; Take one argument
	~,	; Splat that argument to the stack
		;   Example argument:		[1 4 2 3 5]
		;
	Ñ_	; Increments;		STACK = [3 -2 1 2]
	€|	; Magnitudes;		STACK = [3 2 1 2]
	BSVcGbU	; Overlapping pairs;	STACK = [[3 2] [2 1] [1 2]]
	1b]2b]+	; Push [1 2];		STACK = [[3 2] [2 1] [1 2] [1 2]]
	º=	; Any equal [1 2];	STACK = [1]

; ============= ;

D,k,		; Define a function k;
		;   This function takes an array of integers
		;   Returns whether the second element is 0;
		;
	@,	; Take one argument and push to the stack
		;   Example argument:		[[1 4 2 3 5]]
		;
	BP	; Behead;		STACK = [[4 2 3 5]]
	B*	; Product;		STACK = [120]
		;
		; In DJMcMego pairs, A may begin with a 0
		; For example, 12354 and 11111, so we need to remove the first element
		; Taking the product yields 0 if any element is 0
		; However, in order to be a DJMcMego pair, two digits at the same index
		;   cannot be the same, otherwise their digit-wise difference will be 0

; ============= ;

L,		; Define a lambda function
		;
		; This lambda function takes two arrays of digits as input
		; Returns an integer to determine if those digits represent a DJMcMego pair
		;
		; A lambda function is shorter to define than a normal function
		; However, when called inside functions with the ] command,
		;   they consume the entire stack as arguments, meaning that using functions
		;   allows us to preserve important values
		;
		; Example arguments:		[[3 1 7 1 6] [4 5 9 4 1]]
		;
		; First check:
		;
	BcB_	; Digit differences;	STACK = [-1 -4 -2 -3 5]
	€|	; Magnitudes;		STACK = [1 4 2 3 5]
	B]dBkbU	; Save a copy, A	STACK = [1 4 2 3 5]			A: [1 4 2 3 5]
	BSVcGbU	; Overlapping pairs;	STACK = [[1 4] [4 2] [2 3] [3 5]]
	£>	; Sorted descendingly?	STACK = [0 1 0 0]
	sVcG	; How many?		STACK = [1]
	B]V	; Save a copy;		STACK = []				Register: [1]
		;
		; Second check:
		;
	BK	; Retrieve A;		STACK = [[1 4 2 3 5]]
	B#	; Sort;			STACK = [[1 2 3 4 5]]
	BK	; Retrieve A;		STACK = [[1 2 3 4 5] [1 4 2 3 5]]
	BcB_	; Element differences;	STACK = [0 -2 1 1 0]
	0º>b]	; Any negatives;	STACk = [[1]]
		;
		; Third and fourth checks:
		;
	G	; Retrieve register;	STACK = [[1] [1]]
	BK	; Retreive A;		STACK = [[1] [1] [1 4 2 3 5]]
	{w}b]	; Run w;		STACK = [[1] [1] [1]]
	++	; Concatenate;		STACK = [[1 1 1]]
	b*1=	; Product = 1;		STACK = [1]
	BK{k}	; Run k;		STACK = [1 120]
	*	; Multiply;		STACK = [120]

		; To force output as 1 and 0 values,
		;   append a ? to the end, to output the sign (forces boolean conversion)

R, 110 106 84 bytes
function(x,y,z=abs(x-y),w=z-min(z)+1)adist(p(1:max(w)),p(w),c("s"=9))==2
p=intToUtf8

Try it online!
@JayCe with a ridiculous 22 byte save!
The workhorse here is adist, which gives a "generalized Levenshtein edit distance" between two strings. By default the distance is the count of the minimal number of insertions, deletions, and substitutions required to transform one string into another. But adist allows you to weight things how you like - so I've weighted each substitution to add 9 to the distance rather than 1. This effectively forces the algorithm to look for insertions and deletions only.
This code accepts vectors of integers, computes the absolute elementwise differences, and translates the result to begin at 1, calling it w.
Then the custom weighted Levenshtein distance is computed between w pasted together to make a string and the string "1234..." (actually utf-8 "\001\002\003\004..." but adist doesn't care.) with the same number of characters as w.
The only way the string can have exactly one digit out of place is if you make one deletion and one insertion, giving a distance of 2.

This fails for the new test case, 14325, 11111 (falsy).

I think paste0 can be just paste since there's only one input.

p=intToUtf8  ?

I thought I had a golf replacing w=z-min(z)+1)adist(p(1:max(w)) with w=z-min(z))adist(p(0:max(w)) but it doesn't work since intToUtf8(\000) is NULL.

This is an interesting solution that deserves more upvotes.... I think predicting the upvotes in Codegolf is the next frontier for AI :)

@JayCe everyone's just jealous because their languages don't have approximate string matching built-ins.

Do you think calculating Levenshtein's distance would make a good codegolf question? (with a 5-byte answer in R hehe) - nvmd I checked there are plenty of such questions !!

@JayCe it seems like https://codegolf.stackexchange.com/questions/67474/levenshtein-distance is still awaiting its R solution!

True! it's not allowing built-ins so I will have to think harder :)...it will involve utf8ToInt for sure :D

Python 2, 116 119 106 bytes
Thanks Mr. Xcoder for the 116->84 cut, but I found I have missed the "consecutive number" criteria, so 26 bytes are added for that purpose :(
After that, -1 more Thanks Mr. Xcoder, and -13 Thanks ovs
def m(a,b):l=[abs(x-y)for x,y in zip(a,b)];print sum(e>f for e,f in zip(l,l[1:]))==1==len(l)-max(l)+min(l)

Try it online!
That one below fixes 25634 - 11111 problem but with double length (211 206 145 142B)... Golfing...
def m(a,b):l=[abs(x-y)for x,y in zip(a,b)];r=[l[i]-i-min(l)for i in range(len(l))];print(sum(r)==0)&(len([x for x in r if abs(x)>1])<2)&any(r)

Try it online!
And congratulations to new moderators :)
Explanation:
l=[abs(x-y)for x,y in zip(a,b)]

Generates the list of absolute differences of the digits.
r=[l[i]-i-min(l)for i in range(len(l))]

Calculates the offset from the proper position.
sum(r)==0

If the sequence is not continuous, then offset sum will "usually" not be 0. But even if it equals 0, the next ones will block them out.
len([x for x in r if abs(x)>1])<2

Only 0 or 1 item will have absolute offset larger than 1 (the one with wrong position, and 0 is in the case like 1,2,3,5,4)
any(r)

Blocks the case when the numbers are all in correct positions

It seems to fail for m([3,3,3,3],[2,1,0,1]) (returns True) Tio

@AsoneTuhid I have fixed the problem based on his golf because when I submitted the answer and he golfed my answer I forgot that case.

Fails for 25634 11111 (as do many other submissions)

@TonHospel Oh, that's tricky. I'm thinking of methods to fix it but seems it will add quite a bunch of bytes to the answer

JavaScript, 137 136 135 134 132 123 bytes
Takes input as two arrays of digits in currying syntax, outputs 0 for true and any other number for false.
a=>b=>(c=a.map((x,y)=>(x-=b[y])<0?-x:x)).map(x=>t+=x>c[++j]&(d=[...c].sort()).slice(i=0,-1).every(x=>d[++i]-x&1),t=j=0)|t^1

Test Cases

f=
a=>b=>(c=a.map((x,y)=>(x-=b[y])<0?-x:x)).map(x=>t+=x>c[++j]&(d=[...c].sort()).slice(i=0,-1).every(x=>d[++i]-x&1),t=j=0)|t^1
o.innerText=`${l=`-`.repeat(21)}\n|   #1  |   #2  | f |${m=`\n|${`|`.padStart(8,`-`).repeat(2)}---|\n`}${[[31716,45941],[12354,11111],[56798,22222],[23564,11111],[1759,2435],[12345,11111],[3333,2101],[22354,22222],[31717,45941],[89789,78865],[14954,61713]].map(([x,y])=>`| ${JSON.stringify(x).padEnd(6)}| ${JSON.stringify(y).padEnd(6)}| ${f([...``+x])([...``+y])} |`).join(m)}\n`+l
<pre id=o></pre>

[...u].sort(y=0) is invalid javascript, the argument for the sort must be a function

@edc65, that's long since been edited out. Invalid as it may be, though, it worked! ;)

"Fails for 25634 11111 (as do many other submissions)" - Ton Hospel

Haskell, 182 163 162 132 bytes
(#)=zipWith(-)
a&b|s<-abs<$>a#b=or[all(==1)$tail a#a|(x,h:y)<-p s,(q,r)<-p$x++y,a<-[q++h:r],a/=s]
p l=[splitAt k l|k<-[0..length l]]

Takes input as a list of digits. Helper function p that gives all possible ways to split a list into two parts is used to take an element out and again to insert it elsewhere.
Try it online!

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


text:
Hermitian matrix?
Note that this challenge requires no handling or understanding of complex numbers.
Given a non-empty square matrix where every element is a two-element (Re,Im) integer list, determine (giving any truthy/falsy values or any two consistent values) whether this represents a Hermitian matrix.
Note that the input is a 3D array of integers; not a 2D array of complex numbers. If your language cannot take a 3D array directly, you may take a flat list (and the n×n or n×n×2 shape if that helps).
A matrix is Hermitian if it equals its own conjugate transpose. In other words, if you flip it across its top-left to bottom-right diagonal and negate the second element of all the two-element leaf-lists, it is identical to the input matrix. Note that the order of flipping and negating is irrelevant, so you may negate first, and flip afterwards.
Walk-though example
This example uses JSON with superfluous white-space to ease reading:
[[ [2, 0] , [2, 1] , [4, 0] ],
 [ [2,-1] , [3, 0] , [0, 1] ],
 [ [4, 0] , [0,-1] , [1, 0] ]]

Transpose (flip across NW—SE diagonal):
[[ [2, 0] , [2,-1] , [4, 0] ],
 [ [2, 1] , [3, 0] , [0,-1] ],
 [ [4, 0] , [0, 1] , [1, 0] ]]

Negate second elements of leaf-lists:
[[ [2, 0] , [2, 1] , [4, 0] ],
 [ [2,-1] , [3, 0] , [0, 1] ],
 [ [4, 0] , [0,-1] , [1, 0] ]]

As this is identical to the input, the matrix is Hermitian.
Test cases
Hermitian
[[[2,0],[2,1],[4,0]],[[2,-1],[3,0],[0,1]],[[4,0],[0,-1],[1,0]]]
[[[1,0],[2,0]],[[2,0],[1,0]]]
[[[1,0],[2,-3]],[[2,3],[1,0]]]
[[[42,0]]]
Non-Hermitian
[[[2,0],[2,1],[4,0]],[[2,-1],[3,0],[0,1]],[[4,0],[0,-1],[1,-1]]]
[[[0,1],[0,2]],[[0,2],[0,1]]]
[[[1,0],[2,3]],[[2,3],[1,0]]]
[[[3,2]]]

@LuisMendo I'm still thinking. Any ideas?

For the record, a new Meta-post. (I haven't voted to close, but I see someone has, so I'm curious what the community thinks about this).

@LuisMendo What do other challenges do when 3+D arrays are required?

@LuisMendo Then I don't need to specify anything more, do I?

@Adám I would make it as explicit as possible, but it's up to you. Flexibility in input and output formats is usually desired, but cannot be inferred by default, specially when you say the input is a 3D array of real numbers; not a 2D array of complex numbers. It's not clear how broad your concept of 3D array input format is

@WheatWizard every element is a two-element (Re,Im) integer list

@Adám Can a pair of 2D matrices (one for real part, one for imaginary part) be taken as input?

@dylnan No. Input has to be a single structure representing some sort of 3-dimensionality where the leaf dimension contains the Re-Im pairs.

@LuisMendo What's unclear about the output?

@LuisMendo OK, I've updated output. I don't know how to fix input. Any ideas? How about JSON?

@Adam My idea would be to leave it flexible as usual, and to clearly state that in the challenge. For example, I don’t see why complex input should be forbidden (but of course keep that restriction if you have a reason). At least I would allow a flat array with shape specified separately, or two separate matrices, or of course a 3D array directly

@LuisMendo You don't need shape, though, as the last dimension is always length 2, and the first two dimensions have same length. Anyway, added.

@LuisMendo No. Added.

R, 71 48 47 bytes
function(A)all(Conj(t(B<-A[,,1]+A[,,2]*1i))==B)

Takes a 3D array of real numbers, make a 2D array of imaginary numbers, transpose, conjugate and compare.
Thanks to @Giuseppe for reducing the byte count by an astounding 23 bytes, and to @Vlo for the final 1!
Try it online!
Example:
> A <- array(c(2,2,4,2,3,0,4,0,1,0,-1,0,1,0,-1,0,1,0),dim=c(3,3,2))
> A
, , 1

     [,1] [,2] [,3]
[1,]    2    2    4
[2,]    2    3    0
[3,]    4    0    1

, , 2

     [,1] [,2] [,3]
[1,]    0    1    0
[2,]   -1    0    1
[3,]    0   -1    0

> f <- function(A)all(Conj(t(B<-A[,,1]+A[,,2]*1i))==B)
> f(A)
[1] TRUE

B=A[,,1]+A[,,2]*1i should save a few bytes.

@GIuseppe arf I thought i tried that but apparently not. Thanks!

Also, isSymmetric exists and works for Hermitian complex matrices but the 1x1 case is tricky since [ drops attributes and it results in a complex rather than a matrix

function(A)all(Conj(t(B<-A[,,1]+A[,,2]*1i))==B) In-line assignment saves 1.

Octave, 39 34 31 bytes
@(x)(y=x(:,:,1)+j*x(:,:,2))==y'

Try it online!
Saved 3 bytes thanks to Luis Mendo who informed me about the clarifications in the challenge text.
Explanation:
In MATLAB and Octave, ' is the conjugate complex transpose, not the "regular" transpose.
We create a variable y inline that's the first layer of the 3D matrix plus the second layer multiplied with the complex unit j, i.e. a complex matrix where the real term is the first "layer", and the imaginary is the second "layer". We then check if it equals itself complex conjugate transposed.
This will output a matrix containing only 1 if true, and a matrix containing at least one 0 if false. These are considered true and false in Octave (Proof).

Python 2, 50 bytes
lambda m:[[[a,-b]for a,b in l]for l in zip(*m)]==m

Try it online!

APL (Dyalog Unicode), 22 15 9 7 bytes
⍉≡⊢∘-\¨

Try it online!
Tacit prefix function.
Thanks to Adám for 7 bytes on the Dfn, and to both Adám and ErikTheOutgolfer for putting up with my stupidity helping me find the tacit version.
Thanks to ngn for 2 bytes on the tacit version.
How?
⍉≡⊢∘-\¨ ⍝ Anonymous tacit function.
      ¨ ⍝ Apply to each element of the argument:
     \  ⍝ Cumulative reduction, using
  ⊢∘-   ⍝ Ignore the first element, then negate the second
 ≡      ⍝ And match
⍉       ⍝ To the argument's transposition.

Wolfram Language (Mathematica), 45 34 33 26 21 18 bytes

Saved eleven bytes thanks to JungHwan Min.
Saved a byte thanks to Martin Ender.
Saved seven bytes thanks to alephalpha.
Saved five bytes thanks to alephalpha.
Saved three bytes.

#==#&[#.{1,I}]&
Try it online!

34 bytes: Try it online!

@alephalpha Thanks a lot; I know that 0xf3c7 is the transpose operator, but what is 0xf3c8?

@alephalpha There is also 0xf3c9 (Wolfram Documentation).

Java 8, 137 136 134 126 119 116 bytes
m->{int r=1,l=m.length,i=l*l,j,k;for(;i-->0;)r=m[j=i/l][k=i%l][0]!=m[k][j][0]|m[j][k][1]!=-m[k][j][1]?0:r;return r;}

-3 bytes thanks to @ceilingcat.
Returns 1 if Hermitian, 0 otherwise.
Explanation:
Try it online.
m->{                 // Method with 3D integer-array as parameter and boolean return-type
  int r=1,           //  Flag-integer `r`, starting at 1
      l=m.length,    //  The size of the 3D input array
      i=l*l,j,k;     //  Index-integers
  for(;i-->0;)       //  Loop over the rows and columns
    r=m[j=i/l][k=i%l][0]!=m[k][j][0]
                     //   If the first numbers diagonally aren't equal,
      |m[j][k][1]!=-m[k][j][1]?
                     //   or the second numbers aren't negatives of each other:
       0             //    Set the flag `r` to 0
      :              //   Else:
       r;            //    Leave the flag `r` the same
  return r;}         //  Return the flag `r`

J, 14 bytes
[:(+-:|:)j./"1

Try it online!
Explanation
[:(+-:|:)j./"1  Input: 3d array
         j./"1  Reduce by complex combine at rank 1
[:              Cap, operate on the 2d array of complex values
   +              Conjugate
      |:          Transpose
    -:            Match?

Also 14: -:0 2|:(,-)/"1

Jelly,  6  5 bytes
Z×Ø+⁼

A monadic link returning 1 for a Hermitian input and 0 otherwise.
Try it online!
How?
Z×Ø+⁼ - Link: list of lists of lists, M
Z     - transpose
  Ø+  - literal = [1,-1]
 ×    - multiply (vectorises)
    ⁼ - equal to M?

I believe modern Jelly has Ø+.

@lirtosiast indeed you are correct, updated to use it; thanks!

Haskell, 50 bytes
-7 bytes thanks to H.PWiz.
(==)<*>map(map((0-)<$>)).foldr(zipWith(:))e
e=[]:e

Try it online!

05AB1E, 9 bytes
øεεX®‚*]Q

Try it online!
Explanation
ø           # transpose
 ε          # apply to each 2-d array
  ε         # apply to each pair
   X®‚*     # multiply by [1,-1]
       ]    # end apply(s)
        Q   # compare to input for equality

Ruby, 46 bytes
->m{m.transpose.map{|l|l.map{|a,b|[a,-b]}}==m}

Try it online!
Port of my Python answer

Husk, 7 bytes
=¹mmṀ_T

Try it online!
How?
Note that † should work instead of mm
, but there's an annoying bug that prevents me from using it :(

=¹mmṀ_T – Full program. Takes input from Command line args, as a list of lists of tuples.
  m   T – For each list in the input's tranpose...
   mṀ_  – ... Negate the last value of each tuple they contain.
=¹      – Check whether this is the same as the input.

Perl 5, -a0 48 bytes
Old counting: 50 bytes (+2 for a0). Not bad for a language that has no builtin transpose (I'm not jealous at all, no sirree)
Give the input matrix on STDIN with , between the real and imaginary part, so e.g.:
2,0 2,1 4,0
2,-1 3,0 0,1
4,0 0,-1 1,0

Will print 1 for hermitian, nothing otherwise
#!/usr/bin/perl -a0
say@F~~[map/(\S+,)(\S+)/gc?$1.-$2:(),(/.+/g)x@F]

Try it online!

C (gcc), 107 103 100 bytes

Saved four bytes thanks to Steadybox; golfed A[0] to *A twice.
Saved three bytes thanks to ceilingcat.

j,k,r;f(A,s)int***A;{for(r=0,j=s;j--;)for(k=s;k--;)r|=*A[j][k]-*A[k][j]|A[j][k][1]+A[k][j][1];A=!r;}

Try it online!

103 bytes

@Steadybox Thanks a lot. Funny ... A few hours ago I had exactly this golf in mind -- dereferencing instead of indexing -- but simply forgot ...

@ceilingcat Thank you.

JavaScript (ES6), 53 bytes
Saved 2 bytes thanks to @Neil
Returns false for Hermitian or true for non-Hermitian.
m=>m.some((r,y)=>r.some(([a,b],x)=>m[x][y]!=a+[,-b]))

Try it online!

Save 3 bytes on https://codegolf.stackexchange.com/a/156714 - f=([c,...s],p='')=>c?p+c+f(s,p+''):p.

C,  111   110  108 bytes
Thanks to @Jonathan Frech for saving a byte and thanks to @ceilingcat for saving two bytes!
i,j,r;f(A,n)int*A;{for(r=i=0;i<n*2;i+=2)for(j=n*2;j;r|=A[i*n+j]-A[j*n+i]|A[i*n-~j]+A[j*n-~i])j-=2;return!r;}

Try it online!
C (gcc),  106  104 bytes
i,j,r;f(A,n)int*A;{for(r=i=0;i<n*2;i+=2)for(j=n*2;j;r|=A[i*n+j]-A[j*n+i]|A[i*n-~j]+A[j*n-~i])j-=2;A=!r;}

Try it online!

I think r|=...|... works as well as r+=...||....

@JonathanFrech Yes, it does. Thanks!

Actually, 13 bytes
┬⌠⌠Çá╫k⌡M⌡Mß=

Try it online!
How it works?
This submission actually makes use of complex numbers. If taking input as a matrix of complex entries was allowed, then it would be 8 bytes.
┬⌠⌠Çá╫k⌡M⌡Mß=  –> Full program.
┬              –> Transpose.
 ⌠       ⌡M    –> For each list in the input's transpose do the following:
  ⌠    ⌡M         –> For each two-element list of the form [a, b]...
   Ç              –> Turn it into a complex number (a+bi).
    á             –> Find its complex conjugate: Push (a-bi).
     ╫k           –> Push [Re(N), Im(N)], so [a, -b].
           ß=  –> Check whether the result equals the input.

Pyth, 9 bytes
qCmm,hk_e

Explanation:
qCmm,hk_ekdQQ  Autofill variables
    ,hk_ek     [a,-b]...
  mm      dQ    ...for each [a,b] in the input (m...Q)'s rows (m...d).
 C             Transpose.
q           Q  Is this result equal to the original?

Test suite.

Your answer is actually 9 bytes... A 9-byte alternative: qCmm*V_B1.

I golfed off one byte as I was making the submission, from qCmm.e_Fbk... apparently I forgot to edit the byte count in the final submission. @Mr.Xcoder I fixed it regardless, thanks for the catch!

Actually, 13 bytes
;┬⌠⌠d±@q⌡M⌡M=

Try it online!
Explanation:
;┬⌠⌠d±@q⌡M⌡M=
;              make a copy
 ┬             transpose copy
  ⌠⌠d±@q⌡M⌡M   for each row:
   ⌠d±@q⌡M       for each cell in row:
    d              remove last element from list
     ±             swap sign
      @q           insert at end of list
            =  compare equality with original

Stax, 9 bytes
ü♦╧Γ♥├eï∞

Run and debug it

source: Stack Exchange

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

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

sort: votes


text:
The cell at the end of the rainbow
We all know of, or at least have heard of, brainfuck, one of the most famous and influential esoteric languages. While these days most implementations use an infinite tape, the original compiler by Urban Müller had a tape of 30000 cells. A little known fact* is that there is actually a special value at the end of the tape, something that is almost never interacted with in a typical brainfuck program.
While you could print this value with 29999 >s and a ., brainfuck is known for its short and concise solutions, so your aim is to print this value with the minimum number of characters.
*fiction
Rules:

A refresher on the brainfuck instructions:

+/-: Increment/decrement the current cell, wrapping from 255 to 0 when 255 is incremented and vice-versa
</>: Move the pointer left/right on the tape
.: Print the value of the current cell.
[: Jump to the corresponding ] if the value at the cell is 0
]: Jump to the corresponding [ if the value at the cell is not 0

In this case , (Get input) does nothing, as the original compiler leaves the cell unchanged on EOF, and this program should receive no input.
The tape is initially filled with all 0s, except for cell 30000, which contains an unknown value
The pointer starts at cell 1 and should end on cell 30000, having printed it.
Cells to the left of 1 and to the right of 30000 have undefined behaviour, so solutions should not visit these cells.
Note that the value at 30000 is may be a 0, so simply looping until you hit a non-zero cell will not work.
You should print only the value at cell 30000
The shortest solution wins!

Tie-breaker is the more efficient program (executes in the least steps), followed by the fastest submission time.

Tip: Esolanging Fruit suggests using https://copy.sh/brainfuck to test your code. The specs are as described in this challenge, and you can select the abort option so your program halts if it goes out of bounds.

Sandbox (deleted)

Can we assume the implementation allows for holding values up to and including 30000 in a cell?

@hakr14 "+/-: Increment/decrement the current cell, wrapping from 255 to 0 when 255 is incremented and vice-versa"

1 byte: .. I win.

@EsolangingFruit Let me have my delusions please...

@JoKing oh, whoops. Well in that case, I have no idea. Here's a basic (not golfed) solution for 16-bit cells, if anyone wants to use the ideas for a real solution.

@hakr14 Your link doesn't seem to show anything

@JoKing Oh. Yeah, that's cool. Not like I worked hard on that or anything.
This link should work. Sorry about that.

What happens if the memory pointer moves past the cell boundary?

@user202729 Your solution becomes invalid

I suggest changing the rule to "initially all the cells have the value of 0, except the last cell which have an unknown value".

Done, thanks @user202729

Tip for anyone doing this: copy.sh/brainfuck is probably the best site for doing this, as it implements BF as described in this challenge and has a 30k tape by default. Moving right past the end of the tape causes the interpreter to hang.

@EsolangingFruit That's my favorite BF interpreter. The input capabilities are nice, you can choose cell size and wrapping, and the memory dumping/inspection is helpful as well.

50 bytes
>+[>+[<]>->+]>-<<[>>-------[[>]+[<]>-]<<-]>>>[>]>.

Try It Here!
The first section (>+[>+[<]>->+]>-<<) sets up the tape as
0*12 121' 0 110

The next section ([>>-------[[>]+[<]>-]<<-]) iterates 121 times, appending 249 1s to the end of the tape each time. If you're quick with math, you might realise this 121*249 results in 30129 1s, but the first iteration has the leftover 110 to deal with and only appends (110-7) 103 1s to the tape, meaning there's only 29983 1s. The final tape looks like:
0*12 0' 0 0 1*29983 0 ???

And a final >>>[>]>. to print the value.
Some other algorithms of note:

252*119 = 29988 (also 50 bytes)
163*184 = 29992 (56 bytes)
204*147 = 29988 (60 bytes)
153*196 = 29988 (56 bytes)
191*157 = 29987 (57 bytes)
254*118 = 29972 (56 bytes)

This one is the one I consider the next closest to beating 50, since the extra bytes are basically just travelling the extra distance. If I could find an algorithm that generates 118 and travels further than 14 cells, this could beat it.

54 Bytes
------[>+++<--]>[->----[-[->+<]<[->+<]>>]<]>>>>>>>>>>.

119 x 252 = 29988. Straightforward nested loop.
I used this tool to verify that the pointer stops at 29999.

81
-[+>+[<]>++]<<+[-->-[-<]>]>-[>[->+[[->+<]<]>>>]<[-<<+>>]<<<-]>-------[[->+<]>-]>.

This moves over by 150 cells 200 times.
This is much longer than I'd like it to be, and there's a serious obstacle to golfing:
I no longer know why I works.
This is littered with compensations for off-by-ones to the point where some of them could probably cancel out. I've added and deleted various segments so much that I no longer remember why I put certain things where they are (for example, why does the first part initialize the tape cells to 199 and 151 instead of 200 and 150?).
Here is my commented version of this monstrosity anyways, in the hope that I (or someone else) might find them useful:
-[+>+[<]>++]<<+[-->-[-<]>]>-

0 0 0 199' 155

[
  n' k 0
  >[
    n k' j
    ->+[[->+<]<]>
    0' n k－1 j＋1 OR
    n 0 0' j＋1
    >>
  ]
  0*k n 0 0 k 0'
  <[-<<+>>]<<<-
  0*k n－1' k
]
>-------[[->+<]>-]>.

This doesn't actually print the value, and if the value is positive it overflows. But a great attempt

Then add a ., would it help?

@JoKing Fixed that.

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


text:
How to print the below format in the fewest bytes?
This challenge is inspired by this, now deleted question.

Take a positive integer N as input, and output a matrix with the numbers 1 .. N2 that follows the pattern below:
Fill in the first row with 1 .. N then fill the last row (row number N) with (N+1) .. 2N, then fill the second row with (2N+1) .. 3N and continue until you have filled all rows.
The output format is flexible, so list of lists etc. are accepted.
N = 1
1

N = 2
1  2
3  4

N = 3
1  2  3
7  8  9
4  5  6

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

N = 5
 1  2  3  4  5
11 12 13 14 15
21 22 23 24 25
16 17 18 19 20
 6  7  8  9 10

Standard rules apply. Shortest answer in bytes in each language wins. Explanations are encouraged as always.

Are entries allowed to terminate with an error, as long as that error is not printed to STDOUT?

@Sok yes, that's allowed by default.

I guess the title is taken from the deleted question, but as it's not very searchable (to find for dupe etc.), can you change to a better one?

Since "the output format is flexible", may I output a one-dimensional array with the numbers ordered from line to line? (ex: 1 2 3 7 8 9 4 5 6) Is the output format that flexible?

The APL solution is probably a single character of Old Persian cuneiform.

05AB1E, 13 8 bytes
Saved 5 bytes thanks to Rod
nLôÂ«āÉÏ

Try it online!
Explanation
n           # push input^2
 L          # push range [1 ... input^2]
  ô         # split into pieces each the size of the input
   Â«       # append the reverse of this 2D-list
     ā      # push range [1 ... len(list)]
      É     # check each element for oddness
       Ï    # keep only the elements in the 2D list which are true in this list

Ruby, 53 bytes
->n{r=*1..n*n;n.times{|x|p r.slice!(r[x*=n]?x:-n,n)}}

Explanation:
Put all the numbers into a single array first, then slice the array skipping a line for each iteration. After the first (n/2+n%2) iterations there is nothing left to skip, then get all the remaining lines backwards.
Try it online!

Python 2, 75 bytes
def f(n):a=range(n);print[[i*n-~j for j in a]for i in a[::2]+a[~(n%2)::-2]]

Try it online!

JavaScript, 68 bytes
Edit 3 bytes saved, whetted by @user71546
First try, following the obvious route: count from 1 and fill the array from both sides, from outer to inner
n=>(v=0,q=[...Array(n)]).map((_,i)=>q[i&1?--n:i/2]=q.map(_=>++v))&&q

Test

var F=
n=>(v=0,q=[...Array(n)]).map((_,i)=>q[i&1?--n:i/2]=q.map(_=>++v))&&q

function test() {
  var n=+N.value;
  O.innerHTML = '
'
  +F(n).map(r=>r.join('	')).join('

')
  +'
'
}

test()
#O { margin: 1em }
td { text-align: right }
<input id=N type=number min=1 value=5 oninput='test()'>

70 bytes ;)

@user71546 now 68

><>, 51+3=54 47 bytes
:&v
?!\1-:&:&*}}r:
 ~\
!~>1+::n&:&%:a84*@@?$~o?

Try it online!
Input is expected on top of the stack at program start using the -v flag. Output consists of non-aligned numbers separated by single spaces, and each line is separated by a single newline. Example output for N=5:
1 2 3 4 5
11 12 13 14 15
21 22 23 24 25
16 17 18 19 20
6 7 8 9 10

... followed by a single newline. Program terminates with an error (something smells fishy...), but that's on STDERR rather thatn STDOUT.
Explaination:
The first line simply stores a copy of N in the register.
The second line builds up the offset for each output row by subtracting 1 from N, multiplying this by N, rotating it to the bottom of the stack and then reversing the entire stack. When the number on top of the stack reaches 0, the stack should look like this (example uses N=5):
5 15 20 10 0 0

The third line discards the duplicate 0 from the top of the stack.
The fourth line increments the top of the stack and outputs a copy of it. This is then taken mod N, and this is used to decide if a space or newline should be printed, and if the top of the stack should be discarded - if last number printed is x, then x mod N == 0 indicates that the end of that output row has been reached. Execution ends when 1+ gets executed on an empty stack, throwing the termination error.
Previous version
This explicitly checked for an empty stack to end execution, and I was also including 3 bytes for the -v flag usage.
:&v
?!\1-:&:&*}}r:
 ~\
!;>1+::n&:&%:a84*@@?$~o?!~l?

Try it online!

According to this meta, we no longer add flags to byte count so it is enough that you specify that the flag is used.

@Emigna O_O thank goodness for that! Thanks for the heads up

Haskell, 62 bytes
(0#)
m#n|m>=n^2=[]|k<-m+n=[m+1..k]:(k+n)#n++[[k+1..k+n]|k<n^2]

Try it online! Output is a list of lists, e.g. (0#) 3 yields [[1,2,3],[7,8,9],[4,5,6]].

Perl 5, -p 52 51 bytes
#!/usr/bin/perl -p
map{$|--?$\="@0
".$\:say"@0";$_+=@0for@0}@0=1..$_}{

Try it online!

JavaScript (ES6), 69 68 bytes
n=>[...Array(n)].map((_,i,a,j=((i*=2)<n?i:n+n+~i)*n)=>a.map(_=>++j))

Well it got outgolfed before I could post it but here it is anyway. Edit: Saved 1 byte thanks to @KevinCruijssen.

n+n-i-1 can be n+n+~i for -1 byte, so then you are toe-to-toe with the other JavaScript answer again. :)

@KevinCruijssen Brilliant thanks!

Java (OpenJDK 9), 101 bytes
n->{int x[][]=new int[n][n],i=0,j;for(;i<n;i++)for(j=0;j<n;)x[i%2<1?i/2:n+~i/2][j]=++j+i*n;return x;}

Try it online!
Credits

-4 bytes thanks to Kevin Cruijssen.

You can save three bytes by changing the position of the j++: 102 bytes

And another byte changing n-i/2-1 to n+~i/2 101 bytes

@KevinCruijssen Thanks! I somehow posted the raw version, not the fully golfed one. My mistake, the first issue was tackled, but not the second. But you wrote them, so credits to you ;-)

Note: if somehow one-dimensional arrays are accepted, n->{int i=n*n,x[]=new int[i],r;for(;i-->0;x[(r%2<1?r/2:n+~r/2)*n+i%n]=i+1)r=i/n;return x;}

98 bytes

Jelly, 13 ... 6 bytes
Thanks JonathanAllan for -1 byte!
²sm0m2

Try it online!

Use an identical algorithm to the 05AB1E answer.

Save a byte by removing R since s has implicit range of left.

R, 70 59 47 bytes
function(n)matrix(1:n^2,n,,T)[c(1:n,n:1)*!0:1,]

Try it online!
Thanks to Robin Ryder for a 4 byte golf, which I then golfed further.
Returns a matrix; constructs the matrix in sequence, e.g., [[1 2 3] [4 5 6] [7 8 9]], then rearranges the rows.

66 bytes by avoiding rbind.

@RobinRyder 59 bytes -- on mobile so I'll edit this in later

Jelly, 10 bytes
²ss2Ṛj@/Fs

Try it online!
How it works
²ss2Ṛj@/Fs  Main link. Argument: n

²           Square; yield n².
 s          Split; promote n² to [1, ..., n²] and split it into chuks of length n.
  s2        Split 2; generate all non-overlapping pairs of chunks.
            If n is odd, this leaves a singleton array at the end.
    Ṛ       Reverse the order.
     j@/    Reduce by join with reversed arguments.
            In each step, this places the first and second element of the next pair
            at the top and bottom of the accumulator.
        Fs  Flatten and split to restore the matrix shape.

Stax, 10 bytes
│æ╘▐⌡r▌═∟Y

Run and debug it online
The corresponding ascii representation of the same program is 12 characters.
JRx/r{]+rFmJ

Here's how it works.
JR              range [1 .. x^2] where x=input
  x/            split into subarrays of size x
    r           reverse
     {   F      for each subarray, execute block
      ]+r       concat array, and reverse result
          m     for each row, output ...
           J        each subarray joined by spaces

Octave, 102 bytes
n=input('');A=B=vec2mat(1:n*n,n);i=j=0;do
B(++i,:)=A(++j,:);if++j<n
B(n-i+1,:)=A(j,:);end;until j>=n
B

Try it online!

Nice! I didn't know Octave had an until command.And I didnt't know about vec2mat :( Unfortunately the same length: A=B=vec2mat(1:(n=input(''))*n,n) :(

while j++<n is also exactly the same length... Have you tried the various options or are those just coincidences?

@StewieGriffin In this case the while loop is the same length, I tried it both ways. Often do ... until is one byte shorter than while ... end, though.

Python 2, 72 68 63 bytes
-4 bytes thanks to Neil

def f(n):w=zip(*[iter(range(1,n*n+1))]*n);print(w+w[::-1])[::2]

Try it online!

I assume you can save 4 bytes by eliminating the intermediate x variable?

C++ + Range V3, 159 bytes
#include<range/v3/all.hpp>
using namespace ranges::view;

[](int n){auto r=iota(1,n*n+1)|chunk(n);return concat(r|stride(2),r|reverse|drop(n%2)|stride(2));}

Live on Wandbox
Not counting the 2 newlines after using namespace range::view; they are just there to separate imports from the lambda.
Mildly interesting fact: this solution makes no heap allocations. It solves the problem in O(1) space.

Explanation:

iota(1, n*n+1) -> [1 ... n*n]
chunk(n): every n elements together, so [1 ... n] [n+1 ... 2*n] ...
Call that r
r | stride(2): take every other element: [1 ... n] [2*n+1...] ...
concatenate that with:
r | reverse | drop(n % 2): reverse, then drop the [1 ... n] term if n is odd (there'll be an odd number of rows and we only want to print the first term once). It seems like I should be able to just do r | reverse | take, but that doesn't work for some reason.
stride(2) again, take every other element. This time it's in reverse.

More readable, and testable:
#include <range/v3/all.hpp>
using namespace ranges::view;

auto f(int n)
{
    auto rows = iota(1, n * n + 1)
        | chunk(n);
    return concat(
        rows | stride(2),
        rows
            | reverse
            | drop(n % 2)
            | stride(2));
}

#include <iostream>
int main(int argc, char** argv)
{
    std::cout << "N = " << argc << '\n';
    auto res = f(argc);

    for (auto const& row : res | bounded) {
        for (auto const& elem : row | bounded) {
            std::cout << elem << ' ';
        }
        std::cout << '\n';
    }
}

O(log(n)) for storing the input, if measured in bit complexity.

@user202729 Unsure what you mean. Are you saying that for an int n, I need log(n) bits to store the input? But that's the input anyway, and we are dealing with an int where sizeof(int) == 4 (most systems), so it's a constant number of bytes used regardless of the input.

C (gcc), 110 bytes
i,c,t,b;f(a,n)int*a;{for(b=n-1;i<n*n;t++,b--){for(c=0;c<n;)a[t*n+c++]=++i;for(c=0;c<n&i<n*n;)a[b*n+c++]=++i;}}

Try it online!
Fills out an array by alternating between 2 indices for rows: one index starting at the top and one starting at the bottom. The top row index starts at 0 and is incremented every 2 rows; the bottom row index starts at n-1 and is decremented every 2 rows.
Ungolfed:
void f(int* a, int n)
{
    //i = value to be written [1,n]; c = column index; t = top row index; b = bottom row index
    for(int i=1, c=0, t=0, b=n-1;
        i <= n*n; //when i = n*n, we have written all the values and we're done
        t++, b--) //t increments every 2 rows, b decrements every 2 rows
    {
        //write out 2 rows per loop

        //first row: fill out row at t
        for(c=0; c<n; c++, i++)
            a[t*n+c]=i;

        //second row: fill out row at b
        //this step will be skipped on the final loop for odd values of n, hence the (i<=n*n) test
        for(c=0; c<n && i<=n*n; c++, i++)
            a[b*n+c]=i;
    }
}

APL (Dyalog Extended), 19 bytes (SBCS)
Anonymous tacit prefix function.
(⍋1∘+|-\⍤⍳)⊇,⍨⍴∘⍳×⍨

Try it online!
×⍨ self-multiplicate (i.e. square N)
∘⍳ ɩndices one through that, then:
 …⍴ reshape to the following shape:
  ,⍨ self-concatenate (i.e. \$N\$-by-\$N\$ matrix)
(…)⊇ permute the rows into the following order:
 ∘⍳ ɩndices one through \$N\$, then
  -\ alternating sum; \$\big\{1,(1-2),(1-2+3),(1-2+3-4),…,(1-2+3-…\pm N)\big\}=\Big\{1,-1,2,-2,…,\pm\big\lfloor\frac{N}2\big\rfloor\Big\}\$
 …| division remainder when divided by:
  1∘+ the incremented \$N\$
 ⍋ grade (permutation that would sort)

Jelly, 11 bytes
s2ZU2¦Ẏị²s$

Try it online!

CJam, 22 bytes
ri__*,:)/2/z[1W].{%:p}

Try it online!

C (gcc) 80 78
I see now this solution is wrong
i;f(n){for(i=0;i++<n*n;printf("\n%3d"+!!(~-i%n),i>n?n+(i+n>n*n?i%n?:n:i):i));}

Try it online!

C (gcc), 36+8+61 = 105 bytes
compile with -Dp=printf("%d ",i),i++%n;);puts("") -Dq=i,n)
f(q{g(1,i);}g(q{for(;p;i<n*n&&h(q;}h(q{for(n+i<n*n&&g(n+q;p;}

Try it online!

Japt, 10 bytes
Outputs a 3D array; add c1 at the end for +2 bytes to flatten by one level.
²õ òU ó oÔ

Try it


text:
Visit and exit an array
Challenge:
Input:

An integer n (> 0)
An integer-array a of size > 0 (which contains positive and negative values, but no zeroes)

Output:

First output the first n items
Then take the last item you've outputted (let's call it e), and go e steps forward if e is positive, or abs(e) steps backwards if e is negative. And from that position, output abs(e) items (again either going forward / backwards depending on positive / negative).
Continue the process until you've either:

Outputted every distinct value of the array
Output one of the items at least n times

Example 1:
n = 3
a = [2, 6, 9, 2, -4, -1, 3, 5, -7, 3, -2, 2, 2, 3]
     ^  ^  ^  ^   ^   ^  ^  ^   ^  ^   ^  ^  ^  ^
     A  B  C  D   E   F  G  H   I  J   K  L  M  N   ← Added as clarification

Step 1:
- Starting position A, n=3
- Output line 1: 2, 6, 9 (A-C)
- e = 9 (C)
- Distinct values already visited: 2, 6, 9
- Distinct values left to visit: -7, -4, -1, -2, 3, 5
- Amount of times we've visited the items: A=1, B=1, C=1
Step 2:
- Starting position L (9 steps forward from position C), e=9
- Output line 2: 2, 2, 3, 2, 6, 9, 2, -4, -1 (L-N + A-F)
- e = -1 (F)
- Distinct values already visited: -4, -1, 2, 3, 6, 9
- Distinct values left to visit: -7, -2, 5
- Amount of times we've visited the items: A=2, B=2, C=2, D=1, E=1, F=1, L=1, M=1, N=1
Step 3:
- Starting position E (1 step backwards from position F), e=-1
- Output line 3: -4 (E)
- e = -4 (E)
- Distinct values already visited: -4, -1, 2, 3, 6, 9
- Distinct values left to visit: -7, -2, 5
- Amount of times we've visited the items: A=2, B=2, C=2, D=1, E=2, F=1, L=1, M=1, N=1
Step 4:
- Starting position A (4 steps backwards from position E), e=-4
- Output line 4: 2, 3, 2, 2 (A + N-L)
- e = 2 (L)
- Distinct values already visited: -4, -1, 2, 3, 6, 9
- Distinct values left to visit: -7, -2, 5
- Amount of times we've visited the items: A=3, B=2, C=2, D=1, E=2, F=1, L=2, M=2, N=2
We've now visited A n (3) amount of times, so we stop.
Example 2:
n = 2
a = [2, 3, 2]
     ^  ^  ^
     A  B  C   ← Added as clarification

Step 1:
- Starting position A, n=2
- Output line 1: 2, 3 (A-B)
- e = 3 (B)
- Distinct values already visited: 2, 3
- Distinct values left to visit: none
- Amount of times we've visited the items: A=1, B=1
We've already outputted all distinct values, so we stop.
Challenge rules:

Input and output are flexible. Input can be an array/list of integers, string with delimiter, etc. Output can be to STDOUT, can be a 2D integer array/list, a string, etc.
As you may have noticed from the test cases, you wrap around the array if you're out of bounds.
The input n can also be larger than the size of a (i.e. n = 5, a = [2, 3, 4] will have an output of 2, 3, 4, 2, 3, and will stop there since we've outputted all distinct values already).
Input array can contain any reasonable integer (including those larger than the array-size) excluding 0.
If the input for n is 1, it means the output will always be just the first item.

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, please add an explanation if necessary.

Test cases:
Input: 3, [2, 6, 9, 2, -4, -1, 3, 5, -7, 3, -2, 2, 2, 3]
Output: [[2, 6, 9], [2, 2, 3, 2, 6, 9, 2, -4, -1], [-4], [2, 3, 2, 2]]

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

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

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

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

Input: 17, [1, 4, 9]
Output: [[1, 4, 9, 1, 4, 9, 1, 4, 9, 1, 4, 9, 1, 4, 9, 1, 4]]

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

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

Input: 3, [-1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
Output: [[-1, 1, 2], [4, 5], [10, 11, 12, 13, -1], [13], [12, 13, -1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]

Input: 5, [5, 2, -3, 7, -3, 2, -4, 4, 4, 4]
Output: [[5, 2, -3, 7, -3], [2, 5, 4], [7, -3, 2, -4]]

Input: 2, [7, 24, 11]
Output: [[7, 24], [24, 11, 7, 24, 11, 7, 24, 11, 7, 24, 11, 7, 24, 11, 7, 24, 11, 7, 24, 11, 7, 24, 11, 7]]

Python 2, 149 140 bytes
n,a=input()
l=len(a)
s=set(a)
i=0
v=[n]*l
while min(v)and s:
 for x in range(i,i+n,n>0 or-1):v[x%l]-=1;n=a[x%l];s-={n};print n,
 i=x+n;print

Try it online!

-9 bytes, thanks to Bubbler

Count down from n instead of counting up from 0 to eliminate the need for e; e>0 or-1 is better than [1,-1][e<0]. TIO (140 bytes)

R, 167 163 bytes
function(n,a,l=sum(a^0),u=rep(n,l),v=0)while(!(all(a%in%v))&min(u)){for(i in F+0:(n-sign(n))){x=i%%l+1
v=c(v,a[x]);u[x]=u[x]-1}
print(tail(v,abs(n)));n=a[x];F=i+n}

Try it online!
I started with a slightly longer solution but then got inspired by TFeld's Python 2 answer which saved me 3 bytes.
−4 bytes thanks to Giuseppe.

use F instead of f to save another 4 bytes.

Pyth, 112 109 bytes
=HQJ@H0K@H1=H.{K=bJ=Y*]0lKW&>J@.MZY0HI._bVrZ+Zb XYNh@YN=b@KN=-Hbp+bd).?Vr+ZbZ XYNh@YN=b@KN=-Hbp+bd))=Z+Nbp"\n

Try it online!
This is just a translation of TFeld's Python 2 answer. Could probably be golfed far better by someone with a better understanding of Pyth, but I figured I might as well share this anyway.

JavaScript (ES6), 188 bytes
(n,l)=>{for(N=l.length,b=l.map(_=>0),o=[],u=l,e=n,p=0,O=[];!o[n]*u[0];p+=j-s,e=j,O.push(g))for(s=e<0?-1:1,g=[],i=0;i<e*s;p+=s)g[i++]=j=l[p=(p%N+N)%N],o[++b[p]]=u=u.filter(k=>k-j);return O}

Try it online! Comes with a header/footer that run the test cases.
Works somewhat like TFeld's Python answer, but ended up slightly longer.

Perl 5, -a 123 120 116 115 114 bytes
This has the slight blemish that it prints an extra space at the start of each line
#!/usr/bin/perl -a
@;{@F}=$,=$";say$e!~/-?/,map$U{$z}=$S[++$s[$%]]=$e=$F[$%=($&.1+$%)%@F],($%+=$&.~-$')x($' or$@.=<>)until@S>$@|%U~~%

Try it online!