text:
Is My Swipe Pattern Legal?
Most Android smartphones allow the user to use a swipe pattern to open their phone:

Certain patterns are legitimate, and others are impossible. Given an input swipe pattern, return a truthy or falsy indicating if the given input pattern is legal or not.
Input
The grid is labelled row-wise 1 through 9:
1 2 3
4 5 6
7 8 9

The input is a number comprised of the nodes visited from first to last. For example, the swipe pattern above is 12357.
Input can be a decimal number, string or list of numbers. It will not contain 0 because there is no node 0.
Amendment: indexing 0-8 is allowed since a lot of languages index from 0. If you use 0-8, it'll be necessary to indicate as such at the beginning of your answer and adjust the test cases accordingly.
Rules

Every node starts as unvisited initially and may only be visited once. Any pattern which visits a node more than once is falsy.
A truthy pattern must contain at least one swipe, so a minimum of 2 nodes.
It's not possible to skip over an unvisited node directly in line with another.
For example, 13 is falsy because 2 is unvisited and directly in line.
It is only possible to skip over a visited node. 42631 is an example of this.
Lines may cross otherwise. For example, 1524 is truthy.
Assume node widths are insignificant and ignore practical issues (finger thickness, etc). So 16 is truthy even though it may be slightly harder to achieve in reality.

Test Cases
1 -> false
12 -> true
13 -> false
16 -> true
31 -> false
33 -> false
137 -> false
582 -> true
519 -> true
1541 -> false
12357 -> true
15782 -> true
19735 -> false
42631 -> true
157842 -> true
167294385 -> true
297381645 -> false
294381675 -> true

This is code-golf, so the fewest number of bytes wins.

Related.

Related.

Is the input list guaranteed to be nonempty?

@Zgarb yes. It'll be nonempty.

Related maths question: https://math.stackexchange.com/questions/205049/what-are-my-chances-in-a-most-excellent-adventure

JavaScript (ES6), 64 bytes
Takes input as an array of numbers. Falsy values are 0 or NaN. Truthy values are strictly positive integers.
a=>a[p=1]*a.every(n=>a[p=a[n&p&p*n%5<0|~(p-=n)==9&&p/2]&&-n]^=p)

Try it online!
How?
Preamble
Two digits are vertically, horizontally or diagonally opposed if:

they are both odd, different from each other and different from 5 (figure 1)

OR they are both even and their sum is 10 (figure 2)

Besides, the digit standing between two opposed digits n and p is equal to (n + p) / 2.
Formatted source code
a =>
  // force a falsy result if a[1] is undefined
  a[p = 1] *
  // walk through all values n in a[]
  a.every(n =>
    // access either a[-n] or a[undefined]
    a[
      // set p to either -n or undefined
      p =
        // read either a[0] or a[in_between_digit]
        a[
          n & p & p * n % 5 < 0 | ~(p -= n) == 9
          && p / 2
        ]
        && -n
    ]
    // toggle the flag
    ^= p
  )

Keeping track of previous digits
Flags for visited digits are stored at negative indices in the input array a, so that they don't collide with its original elements.

If p is set to -n:
If the current digit n was not previously selected, a[-n] ^= -n will set the flag and let the every() loop go on with the next iteration. Otherwise, it will clear the flag and force the loop to fail immediately.

If p is set to undefined:
a[undefined] ^= undefined results in 0, which also forces the loop to fail.

Detecting opposed digits
The following expression is used to test whether the current digit n and the previous digit -p are opposed digits, as defined in the preamble:
n & p & ((p * n) % 5 < 0) | ~(p -= n) == 9

which is equivalent to:
n & p & ((p * n) % 5 < 0) | (p -= n) == -10

Note: In JS, the result of the modulo has the same sign as the dividend.
It can be interpreted as:
(n is odd AND -p is odd AND (neither -p or n is equal to 5)) OR (n + -p = 10)

Therefore, this expression returns 1 if and only if n and -p are opposed digits or they are the same odd digit. Because a digit can't be selected twice, this latter case is correctly taken care of anyway.
If this expression returns 1, we test a[p / 2] (where p is now equal to the negated sum of the digits) in order to know whether the 'in-between digit' was previously visited. Otherwise, we test a[0] which is guaranteed to be truthy.
About the first iteration
The first iteration is a special case, in that there is no previous digit and we want it to be unconditionally successful.
We achieve that by initializing p to 1, because for any n in [1 .. 9]:

(1 * n) % 5 can't be negative
~(1 - n) can't be equal to 9

Original answer, 90 bytes
Removed from this post so that it doesn't get too verbose. You can see it here.

-1 byte by replacing !!a[1]& with a[1]&&, since any truthy value can be returned

@HermanLauenstein Thanks, that seems OK indeed. (Now, a[1]* is even shorter.)

I was desperately trying to think of a formula for has a node directly in line, I didn't realise it would be so simple...

@Neil By looking at the revision history of this post, I'm sure you can tell that I didn't realize that immediately either... :)

Think you can replace ?a[-n]^=1:0 with &&a[-n]^=1 for -1, can’t test (on mobile)

@StanStrum Only &&(a[-n]^=1) would work, costing +1 byte.

@arnauld if you don't mind, would you explain how you chose the original hash function you used for the original solution? Did you apply some specific number-theoretic algorithm to choose the constants and/or the particular multiply-mod-mod construction—or did you engage in trial and error with some prime numbers?

@SarahG Nothing really sophisticated here. The constants were found by brute-forcing over arbitrary ranges.

x86 32-bit machine code, 62 60 bytes
Hexdump:
33 c0 60 8b f2 33 db 99 80 f9 02 72 2d ad 50 0f
ab c2 72 25 3b c3 77 01 93 2b c3 d1 e8 72 14 68
92 08 0e 02 0f a3 5c 04 ff 5f 73 07 03 d8 0f a3
da 73 06 5b e2 d7 61 40 c3 58 61 c3

It receives the length of the list in ecx and a pointer to the first element in edx, and returns the result in al:
__declspec(naked) bool __fastcall check(int length, const int* list)

There are 8 lines that contain a node in the middle:

1 - 3
4 - 6
7 - 9
1 - 7
2 - 8
3 - 9
1 - 9
3 - 7

I grouped them according to the difference between the bigger and the smaller number.

Difference 2: 3 lines (starting at 1, 4 or 7)
    1 - 3
    4 - 6
    7 - 9
Difference 4: 1 line (starting at 3)
    3 - 7
Difference 6: 3 lines (starting at 1, 2 or 3)
    1 - 7
    2 - 8
    3 - 9
Difference 8: 1 line (starting at 1)
    1 - 9

Then, I converted that to a 2-D lookup table indexed by half-difference and smaller number:
76543210
--------
10010010 - half-difference 1
00001000 - half-difference 2
00001110 - half-difference 3
00000010 - half-difference 4

This makes a "magic" bitmap of 32 bits. To index it, the code pushes it into the stack. Then, it extracts one byte using one index, and from that byte, it extracts one bit using the other index. All this using one instruction:
bt byte ptr [esp + eax - 1], ebx; // -1 because half-difference is 1-based

If the bitmap indicates that there is a node in the middle, it's easy to calculate - add half the difference to the smaller number.
Assembly source:
    xor eax, eax;   // prepare to return false
    pushad;         // save all registers
    mov esi, edx;   // esi = pointer to input list
    xor ebx, ebx;   // ebx = previously encountered number = 0
    cdq;            // edx = bitmap of visited numbers = 0

    cmp cl, 2;      // is input list too short?
    jb bad_no_pop;  // bad!

again:
    lodsd;          // read one number
    push eax;

    bts edx, eax;   // check and update the bitmap
    jc bad;         // same number twice? - bad!

    cmp eax, ebx;   // sort two recent numbers (ebx = minimum)
    ja skip1;
    xchg eax, ebx;
skip1:

    // Check whether the line crosses a node
    sub eax, ebx;   // calculate half the difference
    shr eax, 1;
    jc skip_cross;  // odd difference? - no node in the middle

    push 0x020e0892;// push magic bitmap onto stack
    bt byte ptr [esp + eax - 1], ebx; // is there a node in the middle?
    pop edi;
    jnc skip_cross; // no - skip the check

    add ebx, eax;   // calculate the node in the middle
    bt edx, ebx;    // was it visited?
    jnc bad;        // no - bad!

skip_cross:
    pop ebx;
    loop again;

    // The loop was finished normally - return true
    popad;          // restore registers
    inc eax;        // change 0 to 1
    ret;            // return

    // Return false
bad:
    pop eax;        // discard data on stack
bad_no_pop:
    popad;          // restore registers
    ret;            // return

Nice! I really like this bt byte ptr [esp + eax], ebx.

Nice to see assembly solution :) You can use cdq instead of xor edx, edx as eax is zero. Also, you can fold the dec eax into bt [esp + eax - 1], ebx which is same length but then allows you to remove the inc ebx later. This should save you two bytes.

Thanks for the ideas! You have secured your place in the golfer's paradise, if there is one :)

I think we can all agree that Golfers paradise is hell for everyone else.

Python 2, 140 131 114 104 99 bytes
-2 bytes thanks to Jonathan Frech
-5 bytes thanks to Chas Brown
v={0};k=input()
for l,n in zip(k,k[1:])or q:(2**n+~2**l)%21%15%9==5<v-{l+n>>1}==v>q;v|={l};n in v>q

Try it online!
Explanation:
# full program, raising a NameError for invalid input
v={0}            # set of visited nodes
k=input()        # load pattern
# iterate through adjacent pairs, if there is no pair, raise a NameError
for l,n in zip(k,k[1:])or q:
  # detect moves skipping over nodes, details below
  (2**n + ~2**l) % 21 % 15 % 9 == 5 < v - {l+n >> 1} == v > q
  v |= {l}       # add the last node to the set of visited nodes
  n in v > q     # if the current node was previously visited, raise a NameError

Try it online!
Only 8 pairs of nodes have a node in between them. A pair of nodes can be represented as a single integer by the formula 2^a-2^b-1. This number can be shortened by repeated modulo:
a  b  2^a-2^b-1  (2^a-2^b-1)%21%15%9
1  3         -7                    5
1  7       -127                    5
1  9       -511                    5
2  8       -253                    5
3  1          5                    5
3  7       -121                    5
3  9       -505                    5
4  6        -49                    5
6  4         47                    5
7  1        125                    5
7  3        119                    5
7  9       -385                    5
8  2        251                    5
9  1        509                    5
9  3        503                    5
9  7        383                    5

(2**n+~2**l)%21%15%9==5 first checks if such a pair is present, then v-{l+n>>1}==v tests whether the node in between, which is given by (a+b)/2, was not visited yet and q raises a NameError. By using chained comparison between these pairs, the next comparison is only executed when the previous returned True.

Jelly,  24 22 19 18  17 bytes

-2 since we are no longer required to handle an empty list
-1 switching from join, j@, to concatenate, ; (the missed item does not need to be encountered in the middle for the method employed, being at the start of the trio is fine)
-2 switching from P¬aSH to oSH(OK to have two results since we flatten, half of 1 is 0.5 which is filtered out anyway, and having multiple equal results has no affect on the method employed either)
-1 Thanks to Mr. Xcoder (0-indexed input is allowed)
-1 using the (newer) invariance quick, Ƒ, and filter-keep quick alias, Ƈ.

d3ZIỊoSH;µƝFḞƑƇQ⁼

A monadic link taking a list of integers in [0,8] and returning a truthy value (1) if legal and a falsey value (0) if not.
Try it online! or see a test-suite.
How?
Looks at each adjacent pair of 0-indexed nodes in the input list. If the integer division by three of the two differs by 2 they are on the top and bottom rows, if the modulo by three of the two differs by 2 they are in the left and right columns. The sum of such pairs divided by two is either the 0-indexed mid-node of a three-node-line or a non-integer value -- so these values are first inserted in-front of the 0-indexed pair and then any bogus nodes (like 0.5 or 3.5) are removed, the resulting list of lists is flattened and then de-duplicated (to yield order-preserved, unique entries) and finally compared to the input - for a legal swipe all of this will end up being a no-op while illegal ones will add missing mid-nodes and/or remove duplicate nodes (note that no special casing is required for an input list of length 1 since it has no adjacent pairs):
d3ZIỊoSH;µƝFḞƑƇQ⁼ - left input is a list of integers   e.g. [3,4,7,1,2,8,3]
         µƝ       - perform the chain to the left for adjacent pairs:
                  - e.g. for [a,b] in:   [3,4]         [4,7]         [7,1]         [1,2]         [2,8]         [8,3]
d3                -   divmod by 3        [[1,0],[1,1]] [[1,1],[2,1]] [[2,1],[0,1]] [[0,1],[0,2]] [[0,2],[2,2]] [[2,2],[1,0]]
  Z               -   transpose          [[1,1],[0,1]] [[1,2],[1,1]] [[2,0],[1,1]] [[0,0],[1,2]] [[0,2],[2,2]] [[2,1],[2,0]]
   I              -   differences        [0,1]         [1,0]         [-2,0]        [0,1]         [2,0]         [-1,-2]
    Ị             -   abs(v)<=1          [1,1]         [1,1]         [0,1]         [1,1]         [0,1]         [1,0]
      S           -   sum (of [a,b])      7            11            8              3            10            11
     o            -   OR (vectorises)    [1,1]         [1,1]         [8,1]         [1,1]         [10,1]        [1,11]
       H          -   halve (vectorises) [0.5,0.5]     [0.5,0.5]     [4,0.5]       [0.5,0.5]     [5,0.5]       [0.5,5.5]
        ;         -   concatenate        [0.5,0.5,3,4] [0.5,0.5,4,7] [4,0.5,7,1]   [0.5,0.5,1,2] [5,0.5,2,8]   [0.5,5.5,8,3]
           F      - flatten              [0.5,0.5,3,4,  0.5,0.5,4,7,  4,0.5,7,1,    0.5,0.5,1,2,  5,0.5,2,8,    0.5,5.5,8,3]
              Ƈ   - keep those for which:
             Ƒ    -   is invariant under?:
            Ḟ     -     floor            [        3,4,          4,7,  4,    7,1,            1,2,  5,    2,8,           ,8,3]
               Q  - deduplicate          [3,4,7,1,2,5,8]
                ⁼ - equal to the input?  e.g. 0 (here because 5 was introduced AND because 3 was removed from the right)

Previous method
Jelly,  36  35 bytes
9s3;Z$;“Æ7a‘DZ¤;U$;©0m€2iị®oµƝFQ⁼ȧȦ

Try it online! or see a test-suite.
How?
Similar to the above but constructs all three-node-line possibilities and performs look-up (rather than checking as it goes using divmod to test and halving the sum for the mid-node).
Firstly the construction of the list of three-node-lines:
9s3;Z$;“Æ7a‘DZ¤;U$;©0
9s3                   - nine (implicit range) split into threes = [[1,2,3],[4,5,6],[7,8,9]]
     $                - last two links as a monad:
    Z                 -   transpose = [[1,4,7],[2,5,8],[6,7,9]]
   ;                  -   concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9]]
              ¤       - nilad followed by link(s) as a nilad:
       “Æ7a‘          -   code-page index list = [13,55,97]
            D         -   decimal (vectorises) = [[1,3],[5,5],[9,7]]
             Z        -   transpose = [[1,5,9],[3,5,7]]
      ;               - concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7]]
                 $    - last two links as a monad:
                U     -   upend = [[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3]]
               ;      -   concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7],[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3]]
                    0 - literal zero (to cater for non-matches in the main link since ị, index into, is 1-based and modular the 0th index is the rightmost)
                  ;   - concatenate = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7],[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3],0]
                   ©  - copy the result to the register

Now the decision making:
...m€2iị®oµƝFQ⁼ȧȦ - left input is a list of integers               e.g. [4,5,8,2,3,9,4]
          µƝ      - perform the chain to the left for adjacent pairs:
                  - i.e. for [a,b] in [[4,5],[5,8],[8,2],[2,3],[3,9],[9,4]]
...               -   perform the code described above = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7],[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3],0]
   m€2            -   modulo-2 slice €ach = [[1,3],[4,6],[3,9],[1,7],[2,8],[6,9],[1,9],[3,7],[3,1],[6,4],[9,7],[7,1],[8,2],[9,3],[9,1],[7,3],[0]]
      i           -   index of [a,b] in that (or 0 if not there)    e.g. [0,0,13,0,6,0]
        ®         -   recall from register = [[1,2,3],[4,5,6],[7,8,9],[1,4,7],[2,5,8],[3,6,9],[1,5,9],[3,5,7],[3,2,1],[6,5,4],[9,8,7],[7,4,1],[8,5,2],[9,6,3],[9,5,1],[7,5,3],0]
       ị          -   index into (1-based & modular)     e.g. [0,0,[8,5,2],0,[3,6,9],0]
         o        -   OR [a,b]           e.g. [[4,5],[5,8],[8,5,2],[2,3],[3,6,9],[9,4]]
            F     - flatten                          e.g. [4,5,5,8,8,5,2,2,3,3,6,9,9,4]
             Q    - deduplicate                                    e.g. [4,5,8,2,3,6,9]
              ⁼   - equal to the input?                            e.g. 0 (here because 6 was introduced AND because 4 was removed from the right)
                Ȧ - any and all? (0 if input is empty [or contains a falsey value when flattened - no such input], 1 otherwise)
               ȧ  - AND (to force an empty input to evaluate as 1 AND 0 = 0)

How does it come out to 19 bytes when there's a bunch of unicode characters?

@Izkata Jelly uses its own code-page, which you can see by clicking "bytes" in the header. In its raw byte-form each of the Unicode characters you can see in the source-code is only a single byte.

Stax, 28 bytes
æ¡_t¿♂≥7▼├öä▒╨½╧£x╪╨┌i╒ë╖¢g•

Run it
It produces 0 for false, and positive integers for true.  The corresponding ascii representation of the same program is this.
cu=x%v*x2BF1379E-%_|+YA=!*yhxi(#+*

The general idea is calculate several necessary conditions for legal swipe patterns and multiply them all together.
cu=                                 First: no duplicates
   x%v*                             Second: length of input minus 1
       x2B                          Get all adjacent pairs
          F                         For each pair, execute the rest
           1379E-%                  a) Any digits that are not 1, 3, 7, 9?
                  _|+Y              Get sum of pair, and store in Y register
                      A=!           b) Sum is not equal to 10?
                         *          c) multiply; logical and: a, b
                          yh        half of y; this will be equal to the
                                        number directly between the current
                                        pair if there is one
                            xi(#    d) has the middle number been observed yet?
                                +   e) plus; logical or: c, d
                                 *  multiply by the accumulated value so far

Clever use of the Y register.

Another issue on github.

I coincidentally had already fixed that bug, but hadn't deployed it until just now. (it doesn't affect my program)

It may sound strange, but you can drop the first v and include 1 as falsy value. 2 and above are truthy.

JavaScript, 112 bytes
x=>/^(?!.*(.).*\1|[^5]*(19|28|37|46|91|82|73|64)|[^2]*(13|31)|[^8]*(79|97)|[^4]*(17|71)|[^6]*(39|93))../.test(x)

Maybe some regex based language should be more shorter. But I don't know.

f=
x=>/^(?!.*(.).*\1|[^5]*(19|28|37|46|91|82|73|64)|[^2]*(13|31)|[^8]*(79|97)|[^4]*(17|71)|[^6]*(39|93))../.test(x)
<input id=i oninput=o.value=(f(i.value)?'':'in')+'valid'> is <output id=o>

Thanks to Neil, change )(?! to | save 3 bytes.

@WeijunZhou I got true for 213, what's wrong?

Nothing is wrong, sorry for it.

Now since OP clarified, fails for 144.

@WeijunZhou should been fixed; 2 more bytes...

In case you were wondering, a Retina 0.8.2 port seems to work out at 98 bytes.

Can you not use | instead of )(?!?

@Neil I probably got 98 bytes a different way than you did, but I couldn't get it shorter.

@mbomb007 I failed to save my answer, but I think yours closely resembles it.

-6: x=>/.../.test(x) -> /.../.test

@Makonede js won’t bind the regex to this by default (as what Python do).

Husk, 25 20 bytes
S=öufΛ¦1ΣẊ§Jzo½+em‰3

Takes a list of integers with 0-based indexing.
Returns 0 or 1.
Try it online!
Explanation
I stole some ideas from Jonathan Allan's Jelly answer.
The idea is the same: insert a new "average node" between each adjacent pair, filter out those that are not actual nodes, remove duplicates and compare to the original list.
If the original list contains duplicates, the result is falsy.
If the list skips an unvisited node, then it is present in the processed list between the corresponding pair, and the result is falsy.
If the input is a singleton, the processed list is empty, and the result is falsy.
Otherwise, it is truthy.
S=öufΛ¦1ΣẊ§Jzo½+em‰3  Implicit input, say [0,4,6,7,1]
                 m‰3  Divmod each by 3: L = [[0,0],[1,1],[2,0],[2,1],[0,1]]
         Ẋ§Jzo½+e     This part inserts the middle node between adjacent nodes.
         Ẋ            Do this for each adjacent pair, e.g. [1,1],[2,0]:
          §           Apply two functions and combine results with third.
            zo½+      First function:
            z         Zip with
               +      addition,
             o½       then halve: N = [3/2,1/2]
                e     Second function: pair: P = [[1,1],[2,0]]
           J          Combining function: join P with N: [[1,1],[3/2,1/2],[2,0]]
                      Result is a list of such triples.
        Σ             Concatenate: [[0,0],[1/2,1/2],[1,1],[1,1],[3/2,1/2],...,[0,1]]
    f                 Keep only those pairs
     Λ                both of whose elements
      ¦1              are divisible by 1, i.e. are integers: [[0,0],[1,1],[1,1],,...,[0,1]]
   u                  Remove duplicates: [[0,0],[1,1],[2,0],[2,1],[0,1]]
S=ö                   Is the result equal to L? Implicitly print 1 or 0.

Retina 0.8.2, 98 bytes
Influenced by tsh's answer. I tried to "rephrase" it to be the opposite, matching invalid swipes, then Anti-grepping.
A`(.).*\1|^([^5]*(19|28|37|46|91|82|73|64)|[^2]*(13|31)|[^8]*(79|97)|[^4]*(17|71)|[^6]*(39|93)|.$)

Try it online

C++, 267 256 bytes
#define R)return 0
#define H(a,q)if(d==q&&n==a&&!m[a]R;
int v(int s[],int l){if(l<2 R;int m[10]{},i=1,p=s[0],d,n;for(;i<l;++i){m[p]=1;if(m[s[i]]R;d=(d=p-s[i])<0?-d:d;if(d%2<1){n=(p+s[i])/2;H(5,4)H(5,8)H(2,2)H(5,2)H(8,2)H(4,6)H(5,6)H(6,6)}p=s[i];}return 1;}

To check if the pattern does not skip over a unvisited node, it does several things :

Calculate d where d is the numerical difference between the current node and the last node.
If d is odd, then there's no need to check, it can't skip over a node.
If d is equal to 4 or 8, then the jump is between nodes 1-9 or 3-7, so check node 5
If d is 2, and the middle node ( (last_node + current_node)/2 ) is either 2,5 or 8, then check the middle node
If d is 6, same check as before but with 4,5 or 6

The parameters are an int[] and it's element count.
It returns an int which can be interpreted as a bool type

!(d%2) => d%2<1 should work.

256 bytes

I learned a new trick: int s[] => int*s. I think that'll work.

212 bytes

MATL, 42 41 39 bytes
9:IeXKi"Ky@=&fJ*+XK+y&fJ*+Em~zw0@(]z8<v

This produces

a non-empty column vector containing only non-zero numbers as truthy output; or
a non-empty column vector containing at least a zero as falsy.

Here you can read why these outputs are respectively truthy and falsy. Try it online!
Or verify all test cases, with footer code that includes the standard test for truthiness/falsiness.

Perl, 135 bytes (134 + -n)
@a{split//}=1;(@{[/./g]}==keys%a&&/../)||die();for$c(qw/132 465 798 174 285 396 195 375/){$c=~/(.)(.)(.)/;/^[^$3]*($1$2|$2$1)/&&die()}

Slightly ungolfed version
@a{split//} = 1;
(@{[/./g]} == keys %a && /../) || die();
for $c (qw/132 465 798 174 285 396 195 375/) {
  $c=~/(.)(.)(.)/;
  /^[^$3]*($1$2|$2$1)/&&die()
}

Outputs via exit code. 0 is truthy, any other value is falsy. As per meta consensus, STDERR output in the failure case is ignored.
There's probably a quicker way to check the "can't jump over" rule than simply listing all the possibilities.

Stax, 73 72 66 65 bytesCP437
ÉWyƒ▬ºJOTƒw-H┌↓&ⁿç↨¼<ü6π║¢S○j⌂zXΣE7≈╩╕╤ö±÷C6▒☼■iP-↑⌐¥]╩q|+zΦ4Φ·¥Ω

79 bytes when unpacked,
d4{cAs-5F132396978714EEL3/{xs:IBc0<A*++cEd:-1=sccHs|M=s{U>m|A**mEx%2<xu%x%=!L|+

Run and debug online!
or run the batch test, where meX is a header so that Stax can process multiline input.
Implementation without using hash.Outputs strictly positive number (actually the number of failed tests) for falsy cases and 0 for truthy ones.
Explanation
d clears the input stack. The input is in variable x anyway.
4{cAs-5F generates first part of the middle-node list.
132396978714EE hardcodes the second part of the middle-node list.
L3/ Collects all elements in main stack and divide into parts each containing 3 elements, the result is array a, which is just the array of all invalid 3-node groups.
{xs:IBc0<A*++cEd:-1=sccHs|M=s{U>m|A**mE For each invalid node list, perform the following checks. The result of the check results are anded using the **. Since there are 8 invalid node lists, the result of this code will be an array of 8 elements. The final E dispatches the array to its individual elements on the main stack.
xs:I get the index of the node list elements in the input array.
Bc0<A*++ If the index of "middle node" (e.g. 5 in the node set 1,5,9) is -1 (which means it doesn't exist in the input array), change the index to 9.
cEd:-1= test whether the two "terminal nodes" (e.g. 1,5 in the node set 1,5,9) are adjacent in the input array.
sccHs|M= test whether the transformed index of the "middle node" is larger than those of the two "terminal nodes", which includes two cases: the "middle node" is missing, or the "middle node" comes after the two "terminal nodes"
s{U>m|A tests whether both indexes of the "end nodes" are nonnegative. (i.e. they both appear in the input).
Two additional tests are performed,
x%2< tests whether the input array is a singleton.
xu%x%=! tests whether are nodes that have been visited twice.
There are 10 test result on the main stack (one for each of the invalid node list, plus two additional tests).
L|+ collects the 10 elements and adds them. |a could have also been used which simply checks whether there are any truthy elements on the array.
Implicit output.

Java, 375 355 bytes
-20 bytes thanks to Zacharý
int v(int s[]){int[]m=new int[10];int i=1,p=s[0],d,n,l=s.length;if(l<2)return 0;for(;i<l;++i){m[p]=1;if(m[s[i]]!=0)return 0;d=(d=p-s[i])<0?-d:d;if(d%2==0){n=(p+s[i])/2;if((d==4||d==8)&&n==5&&m[5]==0)return 0;if(d==2&&(n==2&&m[2]==0||n==5&&m[5]==0||n==8&&m[8]==0))return 0;if(d==6&&(n==4&&m[4]==0||n==5&&m[5]==0||n==6&&m[6]==0))return 0;}p=s[i];}return 1;}

This is a port of this answer and it works on the same principles

Woah. You're anwering in Java.

int v(int s[]){int[]m=new int[10];int i=1,p=s[0],d,n,l=s.length;if(l<2)return 0;for(;i<l;++i){m[p]=1;if(m[s[i]]!=0)return 0;d=(d=p-s[i])<0?-d:d;if(d%2==0){n=(p+s[i])/2;if((d==4||d==8)&&n==5&&m[5]==0)return 0;if((d==2)&&(n==2&&m[2]==0||n==5&&m[5]==0||n==8&&m[8]==0))return 0;if(d==6&&(n==4&&m[4]==0||n==5&&m[5]==0||n==6&&m[6]==0))return 0;}p=s[i];}return 1;} should work (order of operations)

You can change (d==2) to just d==2, I overlooked that before.

d%2==0 => d%2<1

231 bytes

Python 2, 97 bytes
Based on ovs' answer but 2 bytes shorter and less cryptic. Just converts indexes to 2d coordinates and tests parity. Assumes 0-8 indexes.
v={9}
s=input()
for n,l in zip(s[1:]or q,s):n/3+l/3&1|n%3+l%3&1or n+l>>1in v or q;v|={l};n in v>q

Try it online!

Japt, 35 bytes
eUä@[(Xu3 aYu3)¥1ªX+Y ÷2XY]Ãc f9o)â

Try it online!
Slightly ungolfed & How it works
eUä@[(Xu3 aYu3)¥1ªX+Y ÷2XY]Ãc f9o)â

Implicit beginning U(input) and some arbitrary sequence conversions

UeUä@[(Xu3 aYu3)==1||X+Y ÷2XY]} c f9o)â

  Uä             Convert the input array into length-2 subsections and map...
    @[ ... ]}      function of X,Y which returns an array of...
      Xu3 aYu3==1||X+Y ÷2          (abs(X%3 - Y%3)==1||X+Y)/2,
                         XY        X, Y
  c              Flatten the result of mapping
    f9o          Intersect with range(9)
        â        Take unique elements, preserving order
Ue             Is the result the same as original array?

Ported the idea from this Jelly solution, with some difference in determining potential jumps:

The Jelly answer uses divmod to see if a pair has difference of 2 when applied /3 or %3.
This answer uses only %3 and checks if the difference is 0 or 2. If the difference is 0, the two cells are vertically aligned, and non-jumps still share the property of (X+Y)%2 != 0.

Vyxal, 26 bytes
2lƛ∑n3vḋ∩vƒ-vṅv∨½p;f~¨=⌊U⁼

Try it Online!
Port of Jelly.

Pyth, 33 bytes
q{@U9.nm+mc|g1aZksd2-MC.DR3d_dC,t

Test suite.
Uses 0-based indexing.
Explanation

q{@U9.nm+mc|g1aZksd2-MC.DR3d_dC,t –> Full program. Input: a list L from STDIN.

                               ,t –> Pair L with L without the first element.
                              C   –> Transpose.
       m                          –> Map over the list of pairs (2-element lists):
        +mc|g1aZksd2-MC.DR3d      –> The function to be mapped (variable: d):
                         R d          –> For each element of d ...
                       .D 3           –> ... Take its divmod by 3.
                      C               –> Tranpose.
                    -M                –> Reduce each by subtraction.
         m                            –> For each difference (variable: k):
            g1aZl                     –> Is |k| ≤ 1?
           |     sd                   –> If that's falsy, replace it by the sum of d.
          c        2                  –> Divide by 2.
        +                   _d    –> Append the reverse of d to the result of mapping.
     .n                           –> Flatten.
  @U9                             –> Take the intersection with (ℤ ∩ [0; 9)).
 {                                –> Deduplicate.
q                                 –> And check whether the result equals L.

Alternative approach for 34 bytes:
q{sI#I#+Fm+,hdcR2+MCd]edCtBK.DR3QK

Haskell, 97 bytes
(%)=elem
f(h:t)=t>[]&&and[x%a<(gcd(x*v)10>1&&x+v/=10||div(x+v)2%a)|x:a@(v:_)<-scanl(flip(:))[h]t]

Try it online!
Make sure t>[] (so length ≥ 2), and then: for each reversed-prefix matching x:a@(v:_), check whether visiting x when coming from v (and having visited all of a so far) is valid.
Going from v to x is legal under these conditions:

x%a< — we have not yet visited x, and…
gcd(x*v)10>1&&x+v/=10 — v and x are not opposites, or

div(x+v)2%a — if they are, at least we've visited the number between them.

Flipped back around, our "opposites check" is gcd(x*v)10==1||x+v==10. The gcd trick works because x*v can only be coprime to 10 if both of x or v are among [1,3,7,9] (opposing corners). Then, x+v==10 takes care of the even digits.

05AB1E, 25 bytes
ü‚εODÈ*y3‰øÆÄ2@·÷0Ky«}˜ÙQ

Port of @JonathanAllan's Jelly answer, so make sure to upvote him!!
Input as a 0-based list of digits.
Try it online or verify all test cases.
Explanation:
ü‚             # Create overlapping pairs of the (implicit) input-list:
               #  i.e. [3,4,7,1,2,8,3] → [[3,4],[4,7],[7,1],[1,2],[2,8],[8,3]]
  ε            # Map each pair `y` to:
   O           #  Take the sum of the pair
               #   → [7,11,8,3,10,11]
    DÈ         #  Duplicate the sum, and check whether it's even (1 if truhy; 0 if falsey)
               #  → [0,0,1,0,1,0]
      *        #  And multiply it by the sum
               #  → [0,0,8,0,10,0]
   y           #  Push the current pair again
    3‰         #  Take the divmod-3 on both values
               #   → [[[1,0],[1,1]],[[1,1],[2,1]],[[2,1],[0,1]],[[0,1],[0,2]],[[0,2],[2,2]],[[2,2],[1,0]]]
      ø        #  Zip/transpose; swapping rows/columns
               #   → [[[1,1],[0,1]],[[1,2],[1,1]],[[2,0],[1,1]],[[0,0],[1,2]],[[0,2],[2,2]],[[2,1],[2,0]]]
       Æ       #  Reduce each by subtracting
               #   → [[0,-1],[-1,0],[2,0],[0,-1],[-2,0],[1,2]]
        Ä      #  Take the absolute value of each
               #   → [[0,1],[1,0],[2,0],[0,1],[2,0],[1,2]]
         2@    #  Check for each that it's >=2 (1 if truthy; 0 if falsey)
               #   → [[0,0],[0,0],[1,0],[0,0],[1,0],[0,1]]
           ·   #  Double each
               #   → [[0,0],[0,0],[2,0],[0,0],[2,0],[0,2]]
            ÷  #  (Integer-)divide the earlier sum by this,
               #  where dividing by 0 results in 0 in this 05AB1E version
               #   → [[0,0],[0,0],[4,0],[0,0],[5,0],[0,0]]
 0K            #  Remove all 0s
               #   → [[],[],[4],[],[5],[]]
   y«          #  Merge the pair to it
               #   → [[3,4],[4,7],[4,7,1],[1,2],[5,2,8],[8,3]]
}˜             # After the map: flatten the list
               #  → [3,4,4,7,4,7,1,1,2,5,2,8,8,3]
  Ù            # Uniquify it
               #  → [3,4,7,1,2,5,8]
   Q           # And check whether it's equal to the (implicit) input-list
               #  → 0 (falsey)
               # (after which this result is output implicitly)

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


text:
Flattened Spiral Permutation Index
Context
Consider square matrices with n columns and rows containing the first n^2 (i.e. n squared) positive integers, where n is odd. The elements of the matrices are arranged such that the integers 1 through n^2 are placed sequentially in a counterclockwise spiral starting at the center and initially moving to the left. Call these matrices M(n)
For n=1 this simply gives the one element matrix M(1)=[[1]].
M(3) is the matrix
9 8 7
2 1 6
3 4 5

M(5) is the matrix
25 24 23 22 21
10  9  8  7 20
11  2  1  6 19
12  3  4  5 18
13 14 15 16 17

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

Now consider flattening this matrix into a list/array by concatenating its rows starting from the top and moving down. Call these lists L(n). L(3), L(5) and L(7) are represented below, with their elements delimited by spaces.
9 8 7 2 1 6 3 4 5     (n=3)
25 24 23 22 21 10 9 8 7 20 11 2 1 6 19 12 3 4 5 18 13 14 15 16 17    (n=5)
49 48 47 46 45 44 43 26 25 24 23 22 21 42 27 10 9 8 7 20 41 28 11 2 1 6 19 40 29 12 3 4 5 18 39 30 13 14 15 16 17 38 31 32 33 34 35 36 37    (n=7)

We can find the index i(n) of L(n) in a lexicographically sorted list of permutations of L(n). In Jelly, the Œ¿ atom gives this index for the list it acts on.
Challenge
Your challenge is to take an positive odd integer n as input and output the index i(n).
The first few values are
n  i(n)
-------
1  1
3  362299
5  15511208759089364438087641
7  608281864033718930841258106553056047013696596030153750700912081

Note that i(n) ~= (n^2)!. This is not on OEIS.
This is code golf per language, so achieve this in the fewest bytes possible.
Sandbox post.

Jelly, 21 19 bytes
-;,N$ṁx"RFḣNṙ-+\ỤŒ¿

Try it online!
Based on the method from a J article on volutes.
Explanation
-;,N$ṁx"RFḣNṙ-+\ỤŒ¿  Main link. Input: integer n
-;                   Prepend -1. [-1, n]
  ,N$                Pair with its negated value. [[-1, n], [1, -n]]
     ṁ               Mold it to length n.
        R            Range. [1, 2, ..., n]
      x"             Vectorized copy each value that many times.
         F           Flatten
           N         Negate n
          ḣ          Head. Select all but the last n values.
            ṙ-       Rotate left by -1 (right by 1).
              +\     Cumulative sum.
                Ụ    Grade up.
                 Œ¿  Permutation index.

J, 48 38 Bytes
-10 bytes thanks to @miles !
[:A.@/:_1+/\@|.(2#1+i.)#&}:+:$_1,],1,-

Old:
3 :'A.,(,~|.@(>:@i.@#+{:)@{.)@|:@|.^:(+:<:y),.1'

Note that the result is 0-indexed, so i(1) = 0 and i(5) = 15511208759089364438087640
Explanation (old):
3 :'                                           ' | Explicit verb definition
                                            ,.1  | Make 1 into a 2d array
                                     (+:<:y)     | 4*n, where y = 2*n + 1
                                   ^:            | Repeat 4*n times
                              |:@|.              | Clockwise rotation
       (                    )@                   | Monadic Hook:
             (          )@{.                     | To the first row, apply...
                      {:                         | The last and largest item
                     +                           | Added to...
              >:@i.@#                            | The list 1, 2, ..., n; where n is the row length
          |.@                                    | Reverse
        ,~                                       | Append to the top of the array
      ,                                          | Ravel
    A.                                           | Permutation index

Making the spiral could be quicker, but the orientation would get messed up.
I don't know how J is optimizing this, but it only takes 0.000414 seconds to calculate for n=7 (on a fresh J console session).

Maybe J does something similar to how I made Jelly do it (code)?

I golfed your method to 39 bytes [:A.@,,.@*0&((,~(#\.+{:)@{.)@|:|.)~2*<:. I also golfed a version of the method in the volute article to 38 bytes [:A.@/:_1+/\@|.(2#1+i.)#&}:+:$_1,],1,-.

MATL, 16 15 14 bytes
lYL!PletY@wXmf

Fails for test cases larger than 3 due to both floating-point inaccuracies and memory limitations.
Try it online!
Explanation
lYL    % Implicit input n. Spiral matrix of that side length
!P     % Transpose, flip vertically. This is needed to match the orientation
       % of columns in the spiral with that of rows in the challenge text
le     % Convert to a row, reading in column-major order (down, then across)
t      % Duplicate
Y@     % All permutations, arranged as rows of a matrix, in lexicographical
       % order
w      % Swap
Xm     % Row membership: gives a column vector containing true / false,
       % where true indicates that the corresponding row in the first input
       % matches a row from the second output. In this case the second input
       % consists of a single row
f      % Find: gives indices of nonzeros. Implicit display

Does MATL have built-ins for spirals?

@EriktheOutgolfer It may have one

Explanation added

Jelly, 27 bytes
ZUðẎṀ+ṚW;⁸µJ
1WÇẎ⁸²¤ḟ$$¿ẎŒ¿

Try it online!

source: Stack Exchange

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

sort: votes


text:
Deranged Rearrangements
Your task is to write a computer program such that when it is cut up into lines (split on the newline character) every arrangement of the lines will output a different number between 1 and n! (where n is the total number of lines).  No number should be output by two different arrangements and every arrangement should output a number on this range. Since there are n! ways to arrange the lines of a program this means each number should be output by one rearrangement.
For example the python program
print 1;"""
print 2;"""

Has two arrangements
print 1;"""
print 2;"""

and
print 2;"""
print 1;"""

The first outputs 1 and the second outputs 2.
You may use whatever output formats are standard in the language you are using.  You may not assume any sort of boilerplate. I think this challenge is more interesting if you have to work around whatever formats the language insists on.
Scoring
Your score will be the number of lines in your program with a higher score being better.  You may choose to output numbers from 0 to n!-1 if you would like.

What about answers that present constructions which work for any n? Are they all tied at a score of ∞?

@MartinEnder Yes.  ∞ is a fine score.  If you find a construction like that then you win.

@AdmBorkBork Yes each arrangement should output one number.  Could that be clearer?

How far will it be cut up? Down to individual bytes or individual words?

@moonheart08 It just gets cut into lines no further.

So what about programs that contain no newlines? :P

@moonheart08 Then they have 1 line so they ought to output 1.

Time for self replicaton, then. :)

Full program or..?

@totallyhuman Standard output rules for whatever language you are using.  I'll update the question to be completely clear on this.

Is there a tie-breaker? Otherwise Martin's answer is final.

@EriktheOutgolfer No tie breaker.  Martin may have found a way to score infinity in CJam but there are plenty of other languages to try on.

Why not have length (in bytes) of the shortest line be the tie breaker?

Why must you make this impossible for brain-flak :(

@Christopher It's certainly not impossible in Brain-Flak.  You can definitely port the CJam method to Brain-Flak.

@WheatWizard I actually have a super golfy solution that works with infinity score but there appears to be a bug in the interpreter

gahh turns out my idea was wrong lol

I think I did it!

CJam, score: ∞
Each line is of the form
];Lx+:L{__(f<0+:+\,,(;1+:**\(;}h]:+

where x is a number from 0 to n-1. The result is in the range 0 to n!-1.
Try it online! (For n=3.)
Credits to jimmy23013 for the code that computes the actual permutation index. I've only replaced the bit that reads the input with ];Lx+:L which discards the result from the previous line and then adds the index of the current line to the variable L (which is initially an empty array).

Oh, I did write that. But it doesn't look golfy... (for example the 0+:+) I think you can get a much shorter version using ,m!#.

Perl: ∞
$z.="-1,";$_.=A;END{$m.=!!s/./{${z}B}/g,map(/B/||s/\d+\K/,/g*/(-\d*,).*\1/||($n{$_}||=$m++),sort glob),print$n{$z}if/A/}
$z.="-2,";$_.=A;END{$m.=!!s/./{${z}B}/g,map(/B/||s/\d+\K/,/g*/(-\d*,).*\1/||($n{$_}||=$m++),sort glob),print$n{$z}if/A/}
$z.="-3,";$_.=A;END{$m.=!!s/./{${z}B}/g,map(/B/||s/\d+\K/,/g*/(-\d*,).*\1/||($n{$_}||=$m++),sort glob),print$n{$z}if/A/}

Extend to any length you like
Will quickly run out of memory since memory usage is like O(n^n). It would however be easy to replace the permutation indexer by O(n) code, just longer. I'm just illustrating the way you can use END{} for this task in perl. All END{} blocks run at exit time, but only the first one that get called (the one last in the code) will output anything due to the /A/ test which is only true once
Notice that the $m counter must count as a string because as a number it would overflow (later than the end of the universe but it's the principle that counts). For the same reason I "count" the number of lines by constructing a string of As instead of using a real counter though this overflow would happen even later.
Another way to do this in perl:
@{$b.=A; if($a eq $b) {use bigint; $n=0;$n++for@F;$c=0;$c=$c*$n--+map{$z=$_;$a=grep$_&&$_>$z,@F;$_=0;}@F;print$c}}=()x push@F,"1".!($a.=A),
@{$b.=A; if($a eq $b) {use bigint; $n=0;$n++for@F;$c=0;$c=$c*$n--+map{$z=$_;$a=grep$_&&$_>$z,@F;$_=0;}@F;print$c}}=()x push@F,"2".!($a.=A),
@{$b.=A; if($a eq $b) {use bigint; $n=0;$n++for@F;$c=0;$c=$c*$n--+map{$z=$_;$a=grep$_&&$_>$z,@F;$_=0;}@F;print$c}}=()x push@F,"3".!($a.=A),

This uses that fact that in foo = bar bar is executed after foo. This version by the way doesn't go crazy in time and space but that makes the code longer
Yet another idea is to use DESTROY which has the advantage that only one of them will be executed. I'm not going to repeat the permutation indexing code of which I already gave two examples.
push@F,"1";bless\@F;DESTROY{print"Work out permutation index of @{$_[0]}\n" }
push@F,"2";bless\@F;DESTROY{print"Work out permutation index of @{$_[0]}\n" }
push@F,"3";bless\@F;DESTROY{print"Work out permutation index of @{$_[0]}\n" }

Or using BEGIN:
BEGIN{push@F,"1"} print"Work out permutation index of @F\n"; exit;
BEGIN{push@F,"2"} print"Work out permutation index of @F\n"; exit;
BEGIN{push@F,"3"} print"Work out permutation index of @F\n"; exit;

Jelly, ∞
;3ÇQŒ¿$⁼Q$?
;2ÇQŒ¿$⁼Q$?
;1ÇQŒ¿$⁼Q$?

(Example with n=3.)
Try it online!
23 13 11 bytes per line.
For a program with n lines, the lines will have the format
; <i> ÇQŒ¿$⁼Q$?
where <i> represents the number literal i and each line has a different value for i ranging from 1 to n. (The values for i don't actually have to be these specific numbers, they just have to have unique positive values.) This program no longer uses n in the line structure.
How?

Without an argument Jelly starts with 0.
;1 appends 1 to 0 or the active list.
⁼Q$ is the conditional monad for the if statement (?) that checks whether the list's elements are unique. If they are, the link above is called (Ç) and another number is appended to the list. If they are not unique, that means we have wrapped around to the first link. The repeated element is removed from the list (Q) and the index of the permutation is found (Œ¿). Note that there is a 0 at the beginning of the list when Œ¿ is taken but it does not affect the output since the values for i are all positive.

New Jelly feature
With the newly added Ƒ quick, we can reduce ⁼Q$ to QƑ, saving a byte.
10 bytes/line (for single digits)
;1ÇQŒ¿$QƑ?

Try it online!

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

Try it online!
I posted this in chat earlier but hopefully by posting it here people can build off of it.
Explanation
We start with the basic program
(({}){})
({}())

This scores 2 on its own.  In order to step up to the next level I want to add a new line.  My begining guess was
(()(){[()()]{}(<()>)}{})

This sets the TOS to 2 if it it is zero and does nothing otherwise.  This actually is a good start.  With the other two lines we are able to get all the numbers from 1 to 6 except 4, because there are 2 ways to output 2:
({}())
(({}){})
(()(){[()()]{}(<()>)}{})

and
({}())
(()(){[()()]{}(<()>)}{})
(({}){})

In order to remedy this we make our line also set 2 to be 4.  This can be done with
(()(){([()()]{})()(){[()()](<{}>)}}{})

For clarity this basically implements the Haskell function
f 0 = 2
f 2 = 4
f x = x

This fixes our problem because one of the programs that was previously outputting 2 now outputs 4 with no other program changing.

Java 7, score: ∞
public class DerangedRearrangements implements B{public void a(){System.out.println("0");}public static void main(String[]a)throws Exception{java.util.regex.Pattern p=java.util.regex.Pattern.compile("^(?:public )?class ([\\w]+).*");java.io.BufferedReader r=new java.io.BufferedReader(new java.io.FileReader("./DerangedRearrangements.java"));String line; while((line=r.readLine())!=null){java.util.regex.Matcher m=p.matcher(line);if(m.matches()){((B)Class.forName(m.group(1)).getDeclaredConstructor().newInstance()).a();}}}}interface B{void a();}
class b1 implements B{public void a(){System.out.println(getClass().getName().substring(1));}}

Try it online!
This is can print out 0 to n!-1. Additional lines are of the following format (where INDEX is a number from 1 to n!-1):
class b<INDEX> implements B{public void a(){System.out.println(getClass().getName().substring(1));}}

This method works by reading its own source in order to determine the order classes are listed in it. Unfortunately there was no cooler method I could find by parsing the compiled file or creating a custom ClassLoader thanks to how java does JIT compilation. I suppose I could have each additional class just print out a statically defined number but this seemed more fun. That would also make it so I could remove the B interface but the scoring isn't based on bytes so I'll leave that in for fun.
How it works (high level):
Reads its own source code line by line. Since each line declares a new class, we use reflection to create an instance of the new class and invoke it's a method which it needs to have because it implements the B interface.

Brain-Flak, 2 (with -d)
{}(@ltN)

Try it online!

For 2 you can use ({}()) and (({}){}).

@WheatWizard trying to make expandable format

Ruby, score: ∞
(a||=[])<<2;a.size<3?0:(p 1+a.sort.permutation.to_a.index(a))
(a||=[])<<1;a.size<3?0:(p 1+a.sort.permutation.to_a.index(a))
(a||=[])<<3;a.size<3?0:(p 1+a.sort.permutation.to_a.index(a))

Try it online!
This program has 61 bytes per line (for n<10). It has the same basic format as dylnan's solution; the first number in each line will be a different value between 1 and n, and the second number in each line will be n.
I was hoping to find a way to avoid including n in the program, but I couldn't find one.

05AB1E, score: 1,114,112
0ˆ¯JD{œsk
1ˆ¯JD{œsk
2ˆ¯JD{œsk

Try it online! 0-indexed. The ˆ at the start of each line pushes the distinct characters to the global array. The rest of the code is uselessly executed except on the last line, where it concatenates the values into a string, then finds its permutation index. 1,114,112 is the number of possible Unicode characters at time of writing (code points 48-57 are the easiest to demonstrate with of course).

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


text:
ABAA/ABBB: Generate this recursive 2D pattern
I was messing around with infinite resistor networks (long story) when I came across the following interesting recursive pattern:
|-||
|---

Each instance of this pattern is twice as wide as it is tall. To go from one level of the pattern to the next, you break up this rectangle into two sub-blocks (each of which is a NxN square):
AB =
|-||
|---

so A =
|-
|-

and B =
||
--

These halves are then duplicated and rearranged according to the following pattern:
ABAA
ABBB

giving

|-|||-|-
|---|-|-
|-||||||
|-------

Challenge
Write a program/function which, given a number N, outputs the Nth iteration of this recursive design. This is golf.
I/O format is relatively lenient: you may return a single string, a list of strings, a 2D array of characters, etc.  Arbitrary trailing whitespace is allowed.  You may also use either 0 or 1 indexing.
Examples
The first several iterations of the pattern are as follows:
N = 0
|-

N = 1
|-||
|---

N = 2
|-|||-|-
|---|-|-
|-||||||
|-------

N = 3
|-|||-|-|-|||-||
|---|-|-|---|---
|-|||||||-|||-||
|-------|---|---
|-|||-|-|-|-|-|-
|---|-|-|-|-|-|-
|-||||||||||||||
|---------------

N = 4
|-|||-|-|-|||-|||-|||-|-|-|||-|-
|---|-|-|---|---|---|-|-|---|-|-
|-|||||||-|||-|||-|||||||-||||||
|-------|---|---|-------|-------
|-|||-|-|-|-|-|-|-|||-|-|-|||-|-
|---|-|-|-|-|-|-|---|-|-|---|-|-
|-|||||||||||||||-|||||||-||||||
|---------------|-------|-------
|-|||-|-|-|||-|||-|||-|||-|||-||
|---|-|-|---|---|---|---|---|---
|-|||||||-|||-|||-|||-|||-|||-||
|-------|---|---|---|---|---|---
|-|||-|-|-|-|-|-|-|-|-|-|-|-|-|-
|---|-|-|-|-|-|-|-|-|-|-|-|-|-|-
|-||||||||||||||||||||||||||||||
|-------------------------------

I wonder if there is some short algebraic way to compute this structure.

What do you mean by "algebraic"?

@user202729 Like maybe there's some "simple" math formula f(n,x,y) which can directly calculate whether a given coordinate should contain - or |.  It might involve modulo operations or bitwise operations.  The techniques I've seen so far all involve cutting/joining arrays as shown in the spec.

f(x,y) also works, since if x,y is valid then the result doesn't depend on n

Found a recursive method to algebraically calculate the required symbol, but the implementation is far longer than my JS answer (I mean, 50% longer).

Can the output be 1-indexed, i.e. input 1 giving |-?

@Zgarb I'll allow it.

Is this loss?

APL (Dyalog Classic), 29 25 bytes
'|-'[{a,⊖⌽⍉~a←⍪⍨⍵}⍣⎕⍉⍪⍳2]

Try it online!
⍳2 is the vector 0 1
⍪ turns it into a 2x1 matrix
⍉ transposes it, so it becomes 1x2
⎕ evaluated input
{ }⍣⎕ apply a function that many times
⍪⍨⍵ concatenate the argument on top of itself - a 2x2 matrix
a← remember as a
~ negate
⍉ transpose
⌽ reverse horizontally
⊖ reverse vertically
a, concatenate with a on the left
'|-'[ ] use the matrix as indices in the string '|-', i.e. turn 0 into | and 1 into -

JavaScript (Node.js), 130 ... 106 94 92 bytes
Golfed from my alternative method and fixing the characters, -14 bytes Thanks @Shaggy
f=n=>n?f(n-1).replace(/.+/g,x=>(g=i=>x.replace(/./g,p=>p<i?s[i]+s[i]:s))`0`+`
`+g`1`):s="|-"

Try it online!
My original approach (106 102 bytes)

f=n=>n?[0,1].map(j=>f(n-1).split`
`.map(x=>x+x.substr((i=x.length/2)*j,i).repeat(2)).join`
`).join`
`:"|-"

-4 bytes Thanks @Shaggy

f=n=>n?[0,1].map(j=>f(n-1).split`
`.map(x=>x+(y=x.substr((i=x.length/2)*j,i))+y).join`
`).join`
`:"|-"

Try it online!
Explanation & Ungolfed:
function f(n) {                     // Main Function
 if (n != 0) {                      //  If n != 0: (i.e. not the base case)
  return [0, 1].map(                //   Separate the pattern into 2 parts
  function(j) {                     //   For each part:
   return f(n - 1).split("\n")      //    Split the next depth into lines
    .map(function(x) {              //    For each line in the result:
    return x                        //     The common part: "AB"
     + x.substr(
      (i = x.length / 2) * j        //     Take A if j == 0, B if j == 1
      , i                           //     Take half the original length
     ).repeat(2);                   //     Double this part
   }).join("\n");                   //    Join all lines together
  }).join("\n");                    //   Join the two parts together
 }
 else return "|-";                  //  If not (base case): return "|-";
}

My original alternative method, if "|"->"2", "-"->"1" is allowed, 105 104 bytes:
f=n=>n?f(n-1).replace(/[12]+/g,x=>(g=(y,i)=>y.replace(/1|2/g,p=>[,i?11:22,21][p]))(x,0)+`
`+g(x,1)):"21"

Try it online!
Just figured out some algebraic method towards this problem.
x=>y=>"|-||--"[(f=(x,y,t=0,m=2**30,i=!(y&m)*2+!(x&m)<<1)=>m?f(x^m,y^m,([18,0,90][t]&3<<i)>>i,m>>1):t)(x>>1,y)*2+x%2]

Try it online!
(finally a function which length's comparable to my original answer)
f(n, x, y) calculates the block type at (x, y) block at nth iteration of the following substitution:
0 => 0 1      1 => 0 0      2 => 1 1
     0 2           0 0           2 2

where 0 = "|-", 1 = "||", 2 = "--", starting from f(0, 0, 0) = 0.
Then, g(x)(y) calculates the symbol at (x, y) of the original pattern.

102 bytes for your first solution.

88 bytes for your second.

Got your second solution working with the correct characters for 95 bytes

^ 94 bytes

92 bytes

Stax, 24 17 15 bytes
╛ä├¼àz[{╧↑;ε╖>╠

Run and debug it
Here's the ascii representation of the same program.
'|'-{b\2*aa+c\}N\m

The basic idea is start with the 0-generation grid, and then repeat a block that expands the grid.
'|'-                    Push "|" and "-"
     {         }N       Get input and repeat block that many times.
      b                 Copy two top stack values
       \2*              Zip two parts, and double the height
          aa            Roll the top of the stack down to 3rd position.
            +           Concatenate two grids vertically
             c\         Copy result and zip horizontally
                  \     Zip the two parts horizontally
                   m    Output each row

Canvas, 17 16 bytes
|∙-╶［∔αω＋：∔；：＋｝＋

Try it here!
Explanation, showing the stack for the input of 1:
|∙-               push "|" and "-" - the initial halves  "|", "-"
   ╶[         }   repeat input times
     ∔              add the two parts vertically         "|¶-"
      αω            get the original arguments to that   "|¶-", "|", "-"
        +           and add those horizontally           "|¶-", "|-"
         :∔         and add to itself vertically         "|¶-", "|-¶|-"
           ;        get the vertically added parts       "|-¶|-", "|¶-"
            :+      and add to itself horizontally       "|-¶|-", "||¶--"
               +  finally, add the halves together       "|-||¶|---"

Updated to 16 bytes by fixing a bug where the values set for α/ω to work weren't copied properly (Canvas is supposed to be fully immutable, but, alas, it wasn't).

Python 2, 88 77 bytes
-11 bytes thansk to Lynn

f=lambda x:x<1and['|-']or[n+2*n[i:i+2**x/2]for i in(0,2**x/2)for n in f(x-1)]

Try it online!

You can roll those list comprehensions together for 77: f=lambda x:x<1and['|-']or[n+2*n[i:i+2**x/2]for i in(0,2**x/2)for n in f(x-1)]

Perl 5, 72 bytes
@1='|-';$l=@1,map{/.{$l}/;push@1,$_.$' x2;$_.=$&x2}@1for 1..<>;say for@1

Try it online!

Optimized to 66: $.=map{s/.{$.}$/$&$$/,push@1,$.$&x3}@1for(@1="|-")x<>;say for@1`

Husk, 17 bytes
!¡§z+DȯṁmDTm½;"|-

1-indexed.
Try it online!
Explanation
!¡§z+DȯṁmDTm½;"|-  Implicit input: a number n.
              "|-  The string "|-".
             ;     Wrap in a list: ["|-"]
 ¡                 Iterate this function on it:
                    Argument is a list of lines, e.g. L = ["|-||","|---"]
           m½       Break each line into two: [["|-","||"],["|-","--"]]
          T         Transpose: [["|-","|-"],["||","--"]]
      ȯṁ            Map and concatenate:
        mD           Map self-concatenation.
                    Result: ["|-|-","|-|-","||||","----"]
   z+               Zip using concatenation
  §  D              with L concatenated to itself: ["|-|||-|-","|---|-|-","|-||||||","|-------"]
                   Result is the infinite list [["|-"],["|-||","|---"],["|-|||-|-","|---|-|-","|-||||||","|-------"],...
!                  Take n'th element, implicitly display separated by newlines.

Jelly, 21 19 bytes
;"/;`,Ẏ;`€$
⁾|-Ç¡ZY

Try it online!

Explanation:
Initially, the value is ⁾|-, that is ["|","-"].
The last link (Ç), given [A, B], will return
   AB     AA
[  AB  ,  BB  ]

. The ¡ repeatedly apply the last link (input) number of times, and ZY formats it.
Explanation for last link:
-----------------
;"/;`,Ẏ;`€$  Monadic link. Value = [A, B]
;"/          Accumulate vectorized concatenate. Calculates (A ;" B).
             Represented as a matrix, it's |AB| (concatenated horizontally)
   ;`        Concatenate with self.      |AB|
                                Value =  |AB|  (concatenate vertically)
     ,    $  Pair with ...
      Ẏ        Tighten.  |A|    (concatenate vertically)
                 Value = |B|
       ;`€     Concatenate each with self.    |AA|
                                      Value = |BB|  (duplicate horizontally)

Clean, 121 106 bytes
import StdEnv
$0=[['|-']]
$n#z=map(splitAt(2^n/2))($(n-1))
=[u++v++u++u\\(u,v)<-z]++[u++v++v++v\\(u,v)<-z]

Try it online!

Haskell, 86 bytes
(%)=zipWith(++)
f 0=["|-"]
f n|(a,b)<-unzip$splitAt(2^(n-1))<$>f(n-1)=a%b%a%a++a%b%b%b

Try it online!
Pretty simple. Output is a list of strings. We take the previous version and split each line in half then collect those into two new lists using unzip. Then it's simply a matter of combining the arrays together the right way

R, 126 bytes
function(n,k=cbind){o=matrix(c("|","-"),1,2)
if(n>0)for(i in 1:n)o=rbind(k(a<-o[,x<-1:(2^(i-1))],b<-o[,-x],a,a),k(a,b,b,b))
o}

Try it online!
Returns a matrix. There's a bit of code in the TIO link to get it to print nicely for ease of verification.

110

Charcoal, 47 46 bytes
Ｍ²↖|-¶¶ＦＥＮＸ²ι«Ｆ²Ｃ±ι⁰Ｃ⁰ιＣ⊗ι±ιＣ×³ι±ι≦⊗ιＭ±ι±ιＴ⊗ιι

Try it online! Link is to verbose version of code. Explanation:
Ｍ²↖|-¶¶

In order to get a consistent cursor position for the following loop, I have to print step 0 at position (-2, -2) and leave the cursor at (-2, 0). (This might be due to a bug in Charcoal.)
ＦＥＮＸ²ι«

Loop over the first N powers of 2.
Ｆ²Ｃ±ι⁰Ｃ⁰ιＣ⊗ι±ιＣ×³ι±ι

Make copies of the previous output with various offsets resulting in a canvas that contains the desired next step in a rectangle within it.
≦⊗ιＭ±ι±ιＴ⊗ιι

Move to the position of that rectangle and trim the canvas.
Alternative solution, also 46 bytes:
Ｍ²→|-ＦＥＮＸ²ι«Ｆ432Ｃ×Ｉκι×³ιＦ245Ｃ×Ｉκι⊗ι≦⊗ιＪ⊗ιιＴ⊗ιι

Try it online! Link is to verbose version of code. Explanation:
Ｍ²→|-

This time step 0 has to be printed at position (2, 0), but at least the cursor position doesn't matter.
ＦＥＮＸ²ι«

Loop over the first N powers of 2.
Ｆ432Ｃ×Ｉκι×³ιＦ245Ｃ×Ｉκι⊗ι

Make copies of the previous output with various offsets resulting in a canvas that contains the desired next step in a rectangle within it.
≦⊗ιＪ⊗ιιＴ⊗ιι

Move to the position of that rectangle and trim the canvas.

J, 49 bytes
f=.3 :'''|-''{~((,.[:|.[:|."1[:|:-.)@,~)^:y,:0 1'

A clumsy translation of ngn's APL solution. I had problems making it tacit - I'll apreciate any advice.
Try it online!

K (ngn/k), 25 bytes
{"|-"x{x,'|+|~x:x,x}/,!2}

Try it online!

Wolfram Language (Mathematica), 67 65 bytes
SubstitutionSystem[{"|"->{i={"|","-"},i},"-"->{i,i}},{i},{#}]&

Try it online!
Straightforward implementation of the recursion. Returns an array of characters wrapped in a list.


text:
Wanna See a Card Trick? (Part I)
Amazingly, this is the easier of the three card tricks I know off the top of my head...
The aim of this is to have your compiler perform a specific card trick. There's no slight of hand, and the compiler won't be memorizing the choice and saying "Voila, this is your card!" The code will basically manipulate a stack of cards and the final card drawn from this stack will be the card chosen at random:
If you want to understand this trick further, feel free to follow this with an actual deck of cards so that you can learn the trick. I will be displaying the order of the cards in the face-down stack in my example in curly braces {} so that you can see what's happening.
The standards set in this trick:

A standard deck of cards is generated, 52 cards (no jokers required). From this deck, nine cards will be chosen at random to form our trick's card stack.
The backs of the cards will be displayed as @@.
The face-size of the cards will be displayed in the format XY where X is the value, A-9,T,J,Q,K (T = 10); and Y is the suit, Spades, Clubs, Diamonds, Hearts. So AS for the Ace of Spades, TC for 10 of Clubs, 8H for the 8 of Hearts, etc.
In displaying the stack of cards, from left to right, the left-most card will be located on the bottom of the stack, and the right-most card will be at the top of the stack. Similarly, if cards are in smaller sets, left-most = bottom card, right-most = top card.

Given these standards, my randomly chosen stack for this example looks like this: @@ @@ @@ @@ @@ @@ @@ @@ @@ (cards facing down)
...And when facing up: TD JD 8C 7D 8S 3C QH 9S 3S
Note, this means my facing up stack has the ten of diamonds on the bottom, and the three of spades at the top.
Your deck may vary from mine (see Standards 1 above re random generated stack)
I will go through this trick step-by-step, and how the code needs to work:

Accept a number between 1 and 9 as input, to be used later on:

2

Generate your nine-card stack and display the cards face down first, in sets of 3, four spaces in between each set. This is so that the user can see they've chosen a specific card out of a specific set:

@@ @@ @@    @@ @@ @@    @@ @@ @@

Flip the cards over, so that the user can see which card they chose:

TD JD 8C    7D 8S 3C    QH 9S 3S

Announce the card chosen, full wording of the card, e.g. the second card (derived from our input of 2 earlier on):

JACK OF DIAMONDS

Take the chosen card and place it on top of that specific set, facing up; remembering that the right-most card in each set is the top-most in each set facing up:

TD 8C JD    7D 8S 3C    QH 9S 3S

Put the other two sets on top of the set with the chosen card, also facing up, to form one stack. It does not matter which of the two sets goes first:

TD 8C JD 7D 8S 3C QH 9S 3S

Flip the stack over so that the cards are facing down:

@@ @@ @@ @@ @@ @@ @@ @@ @@
Note: At this point, the stack of cards will have now reversed in order:
{3S 9S QH 3C 8S 7D JD 8C TD}

Our ten of diamonds is on the top of the pile now... And our chosen card is third from the top... The chosen card will ALWAYS be third from the top at this point.
Now, we have to spell out the card in question, in our case the JACK OF DIAMONDS. Cards are dealt from the top of the deck to another pile, spelling out the card as we go. After the spelling of each word, the rest of the pile goes straight on top with each word. I've shown how the cards in the face-down stack are ordered after each word in curly braces:

J @@ A @@ C @@ K @@, @@ @@ @@ @@ @@ {TD 8C JD 7D 3S 9S QH 3C 8S}
O @@ F @@, @@ @@ @@ @@ @@ @@ @@ {8S 3C TD 8C JD 7D 3S 9S QH}
D @@ I @@ A @@ M @@ O @@ N @@ D @@ S @@, @@ {QH 9S 3S 7D JD 8C TD 3C 8S}

Here's what they call the prestige, the final part of the trick. Deal out the first five cards from the top of the stack, face down to the words HERE'S THE <NUMBER> OF <SUIT>! <FIFTH CARD FACE UP>, flipping the final card to show face up...

HERE'S @@ THE @@ JACK @@ OF @@ DIAMONDS! JD
The fifth card from the stack should now be the card originally chosen.
Example output, using a new randomly chosen stack, and 4 as the input.
@@ @@ @@    @@ @@ @@    @@ @@ @@
3D AD JS    TH KD QS    JC 6D 4S
TEN OF HEARTS
3D AD JS    KD QS TH    JC 6D 4S
KD QS TH 3D AD JS JC 6D 4S
@@ @@ @@ @@ @@ @@ @@ @@ @@
T @@ E @@ N @@, @@ @@ @@ @@ @@ @@
O @@ F @@, @@ @@ @@ @@ @@ @@ @@
H @@ E @@ A @@ R @@ T @@ S @@, @@ @@ @@
HERE'S @@ THE @@ TEN @@ OF @@ HEARTS! TH

Please note, the final card you are producing at the end is pulled from the card stack (array), and will always be the fifth card in the stack, not from some assigned variable; and the code needs to reflect this. Note, that if you're dealing with a zero-based array language that this would mean, element 4, as opposed to element 5 in a one-based array language.
The key to this code-golf (yes, this is going to be code-golf, muahahahahaha!) is through the manipulation of the nine-card stack. With each word spelled out, the affected cards at the top of the stack will be reversed, thrust to the bottom of the stack and the remaining cards will be placed on top; refer to the examples above to see how that works. Run through the logic with nine playing cards if you have to in order to understand how it works.
Rules

This is code-golf. Lowest byte-count will win; in the event of a tie in byte count, highest votes will win.
No silly loopholes.
The input can be implemented in whatever way you see fit: STDIN, an array, a parameter in a function, whatever takes your fancy...
Please provide a link to your executing code on an online IDE like TIO so that we can marvel at your work. Learning from one another is something I encourage, and I'd love to see how you all can code this up!
The chosen card is drawn correctly at the end providing you have the array/stack manipulations worked out. Please do not simply assign the chosen card into a variable and pull it out in the end... This will be regarded as an invalid answer.

This is a really, really interesting challenge to golf.

I'm glad you approve @Ourous, looking forward to seeing your entry!

Is trailing whitespace allowed?

It's up now, enjoy! (and also, I'd like to know if the output method is acceptable)

Perl 5, 551 549 547 546 + 1 (-p) = 547 bytes
%r=(T,TEN,J,JACK,Q,QUEEN,K,KING,A,ACE);map$r{++$.}=$_,TWO,THREE,FOUR,FIVE,SIX,SEVEN,EIGHT,NINE;map{/./;$u{$_.$&}=[$r{$_},OF,$&.$']for keys%r}DIAMONDS,HEARTS,SPADES,CLUBS;@0=(keys%u)[0..8];$x.="@0[$_..$_+2]   ",print'@@ 'x3,$"x2for@z=(0,3,6);@w=@{$u{$0[$_]}};say"
$x
@w";@t=@0[($l=$_-$_%3)..$l+2];splice@t,$_%3,1;push@t,$0[$_];@0[$l..$l+2]=@t;print"@0[$_..$_+2]   "for@z;@t=splice@0,$l,3;say"
@t @0
".'@@ 'x9;@0=reverse@t,@0;map{@t=();push@t,pop@0for/./g;say+(join$q=' @@ ',/./g),' @@,',' @@'x@0;@0=(@t,@0)}@w;$_=(join$q,"HERE'S",THE,@w)."! $0[4]"

Try it online!
Uses 0-based counting, so the cards are numbered 0-8.

Great submission but line 6 seems to only shows  the back of six cards instead of nine...?

You're right.  I messed that up while I was golfing the code.  It's fixed now.

BTW, thanks for detailing the 0-based array, did this help with golfing it down?

Saved 5 bytes.  Would have needed an extra $_--; in there otherwise.

Python 2, 593 589 bytes
from random import*
N=input()-1
n='\n';A='@@ ';V='A23456789TJQK';Z='SCDH'
J=' '.join
j='    '.join
s=sample(map(''.join,zip(V*4,Z*13)),9)
x,y=s[N]
S=[s[:3],s[3:6],s[6:]]
x,y=dict(zip(V,'ACE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN JACK QUEEN KING'.split()))[x],dict(zip(Z,'SPADES CLUBS DIAMONDS HEARTS'.split()))[y]
print(A*3+'   ')*3+n+j(map(J,S))+n+x,'OF',y
S[N/3]+=S[N/3].pop(N%3),
print j(map(J,S))
s=S.pop(N/3)+S[0]+S[1]
print J(s)+n+A*9;s=s[::-1]
for w in x,'OF',y:l=len(w);s=s[:~l:-1]+s[:-l];print' @@ '.join(w)+' @@, '+-l%9*A
print"HERE'S @@ THE %s @@ OF %s! %s"%(A+x,A+y,s[4])

Try it online!
-4 bytes thanks to ovs

Clean, 764 ... 686 bytes
import StdEnv,Math.Random,System._Unsafe,Text,System.Time
f=["","","   ":f]
w=" "
^ ="@@"
$s=g[hd u+t\\u<-s&t<-f]
d=reverse
r=repeatn 9
j=join
g=j w
s=split w
?n#n=n-1
#!a=removeDup[[[w<+y.[0],x,"OF",y]\\w<-:"A123456789TJQK"&x<-s"ACE ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN JACK QUEEN KING",y<-s"CLUBS HEARTS DIAMONDS SPADES"]!!(i rem 52)\\i<-genRandInt(toInt(accUnsafe time))]%(0,8)
#v=a!!n
#b=insertAt(n/3*3+2)v(removeAt n a)
#c=b%(n/3,n/3+2)
#c=c++removeMembers b c
#v=tl v
#(z,s)=foldl(\(c,s)k=let(p,q)=splitAt(9-size k)c in(d q++p,[j"@@ "[e<+w\\e<-:k]+j^["@@, ":[w\\_<-p]]:s]))(d c,[g(r^),g(map hd c),$b,g v,$a,$(r[^])])v
#[x:y]=z!!4
=d[j" @@ "["HERE'S","THE":y]+"! "+x:s]

Try it online!
Defines the function ? :: Int -> [String], taking the card number and returning a list of lines.
Explanation coming when answer is finalized so I don't need to keep retyping it

What does ?n#n do?

@EsolangingFruit It's actually two statements, the function definition ?n, and the node expression #n=n-1. The second of which effectively subtracts 1 from n.

So # is not a prefix operator but actually away to introduce non-recursive bindings?

@EsolangingFruit Yep. Essentially an imperative assignment, with the exception of functions which can still recurse when used in # expressions.

Interesting approach, though I'm wondering if you may have done yourself an injustice with using a language that doesn't appear very golfable?

@WallyWest It can do.. okay. I enjoy writing well-golfed, but long answers more than short and easily-golfed ones.

I meant no disrespect, @Ourous... It's a great submission, don't get me wrong... I guess having code-golfed a fair bit, I've been so used to seeing code that isn't so... tidy! ;) Look forward to later golfs of this piece when you have the time :)


text:
Orient the Rubik's Cube
Introduction:
I collect twisty puzzles, so I'm quite the fan of rubiks-cube-challenges (even though most are fairly difficult). So, let's try a fairly easy rubiks-cube-challenge for a change.
When an NxNxN Cube gets scrambled during a WCA (World Cubing Association) competition, the cube is always held in the same way before executing the scramble-algorithm:

Article 4: Scrambling

4d) Scrambling orientation:

4d1) NxNxN puzzles and Megaminx are scrambled starting with the white face (if not possible, then the lightest face) on top and the green face (if not possible, then the darkest adjacent face) on the front.

"NxNxN puzzles are scrambled starting with the white face on top and the green face on the front."
Challenge:
For the sake of this challenge we only have to look at the centers, so we'll use a 1x1x1 instead of a 3x3x3. Given a valid 1x1x1 Cube in any orientation, output which rotations of x/x', y/y', and/or z/z' are required to have green at the front and white at the top.
Input:
The input will be a 1x1x1 Cube layout in the following format (where F is the front, and U is the top):
 U
LFRB
 D

For example:
 Y
BRGO
 W

Output:
The output will be the least amount of rotations of x/x', y/y', and/or z/z' required to have the white center at the top and green center at the front.
         x                      y                      z

         x'                     y'                     z'

We basically always want to end up in this orientation:
 W
OGRB
 Y

The example given above would therefore result in either of these outputs: x2y/xxy/x'x'y.
NOTE: In the still image of the gifs above, White is the Upper face and Red is the Front face. So the still image of the gif is:
 W
GRBO
 Y

Challenge rules:

You are allowed to take the input in any reasonable format.

You could use other characters or numbers (i.e. 0-5/1-6) instead of WYROGB
You can take the input as single String, as new-line delimiter single String, as String-array, character-array or -matrix, integer-array or -matrix, etc. Your call. (For example, WOGRBY is a valid input in the format ULFRBD.)
Please specify what input-format you've used!

The output must use xyz, but instead of x' you are also allowed to use x3 or X, or instead of x2 you can also use xx (NOTE: You are NOT allowed to use xxx instead of x'/x3/X).

Always output the least amount of rotations. So although x'x'y'y'y' instead of x2y results in the same orientation of the Cube in the end, it's not a valid output because there is a better alternative. Same applies to
x2y2, because xy'z is one move shorter (x2/xx counts as two moves).
As thumb rule: every possible input results in 0-2 x, 0-2 y and/or 0-2 z rotations, and you'll never need more than three rotations in total (i.e. x2z2 → y2)

You can assume all inputs are valid 1x1x1 Cubes.
If the input is already in the correct position (green front, white top), output nothing (or something indicating nothing, like null, false, 0, an error, etc.)

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:   Output (multiple valid answers are possible for some):

 Y
BRGO     x2y   y'x2   z2y'   yz2   zy'x   zxz   xzx   xyz
 W

 W
OGRB     nothing
 Y

 G
RWOY     y2x'   z2x   yzy   xy2   x'z2   yx'z   zxy   zyz
 B

 W
RBOG     y2
 Y

 R
BWGY     yz   zx   xy
 O

 G
WOYR     x'z   zy   yx'
 B

@Arnauld About your first comment. Some of your answers seem to be slightly incorrect. It looks like you're mixing up moves sometimes. Just double checked, but all outputs currently given should be correct. I could have missed other valid outputs however.

There must be something that we're interpreting differently. The way I understand it, the still image in the GIF is WRBOGY in ULFRBD format. Is that correct?

@Arnauld Ah, now I understand the confusion. I'll edit it, but in the still image of the gif it's U=W; F=R; R=B; D=Y; B=O; L=G. So White is the Top, Red is the Front. So used to that orientation on puzzles myself that I forgot that others might not..

if all the puzzles cost $15, you spent ~ $6000 bro... solid life goals xD

Avatar checks out.

Gotcha! Here is what I have now: 1:[ 'zzY', 'zYx', 'zxz', 'yzz', 'Yxx', 'xzx', 'xyz', 'xxy' ], 2:[ '' ], 3:[ 'zzx', 'zyz', 'zxy', 'yzy', 'yyX', 'yXz', 'xyy', 'Xzz' ], 4:[ 'yy' ], 5:[ 'zx', 'yz', 'xy' ], 6:[ 'zy', 'yX', 'Xz' ].

@Arnauld All test cases check out, so I've added the ones I missed. Well done!

@tfbninja Although I don't want to think about it, 6k seems about accurate. Cheapest puzzles were gifts (so free), most expensive 600 USD. I think average of about 17.5 is more accurate due to some expensive ones. Ah well.

Jelly,  47  43 bytes
To answer my own question, yes a straight hash is shorter, and not just a little!
“ḥɦƁþhƓWsFUḃṡIụA]OṆrṠ€5ⱮI’ṃ“XZyxzY ”Ḳɓ%⁽'Ṙị

A monadic link taking an integer with WOGRBY as 145362 and returning a list of characters using the x, xx, X format.
Try it online!
How?
Uses the hash function found by Herman Lauenstein in their JavaScript answer -- go give credit!
“ḥɦƁþhƓWsFUḃṡIụA]OṆrṠ€5ⱮI’ṃ“XZyxzY ”Ḳɓ%⁽'Ṙị - Main link 1: integer, N
“ḥɦƁþhƓWsFUḃṡIụA]OṆrṠ€5ⱮI’                  - base 250 literal = 3078729180217463783054936423617578759678999380687706537574
                           “XZyxzY ”        - literal list of characters = "XZyxzY "
                          ṃ                 - base decompress = "X Zyx ZX z ZY zz x Y zx zy Zyy zzX xx zX y zY Z zzx  Zx zzy Zxx Zy yy"
                                            - (use the seven characters as digits 1,2,3,4,5,6,0)
                                    Ḳ       - split at spaces = ["X","Zyx","ZX","z","ZY","zz","x","Y","zx","zy","Zyy","zzX","xx","zX","y","zY","Z","zzx","","Zx","zzy","Zxx","Zy","yy"]
                                     ɓ      - new dyadic chain with swapped arguments
                                       ⁽'Ṙ  - 10955
                                      %     - modulo (N) by (10955)
                                          ị - index into (the move list)
                                            -   Note: Jelly indexing is 1-based & modular
                                            -         so a %24 is surplus to requirements

JavaScript (ES6), 95 bytes
n=>'y2+X+Zyx+ZX+z+ZY+z2+x+Y+zx+zy+Zy2+z2X+x2+zX+y+zY+Z+z2x++Zx+z2Y+Zx2+Zy'.split`+`[n%10955%24]

This works similarly to @Arnauld's answer (credits to him for the idea), but inputs as a base-10 integer (with 123456 instead of WYROGB), which skips the base decoding.
Hash function
Input  | mod 10955 | mod 24 | Output
-------+-----------+--------+-------
136452 |      4992 |      0 | "y2"
145362 |      2947 |     19 | ""
153642 |       272 |      8 | "Y"
164532 |       207 |     15 | "y"
235461 |      5406 |      6 | "z2"
246351 |      5341 |     13 | "x2"
254631 |      2666 |      2 | "Zyx"
263541 |       621 |     21 | "z2Y"
315264 |      8524 |      4 | "z"
326154 |      8459 |     11 | "Zy2"
352614 |      2054 |     14 | "zX"
361524 |         9 |      9 | "zx"
416253 |     10918 |     22 | "Zx2"
425163 |      8873 |     17 | "Z"
451623 |      2468 |     20 | "Zx"
462513 |      2403 |      3 | "ZX"
514236 |     10306 |     10 | "zy"
523146 |      8261 |      5 | "ZY"
531426 |      5586 |     18 | "z2x"
542316 |      5521 |      1 | "X"
613245 |     10720 |     16 | "zY"
624135 |     10655 |     23 | "Zy"
632415 |      7980 |     12 | "z2X"
641325 |      5935 |      7 | "x"

Test Cases

f=n=>'y2+X+Zyx+ZX+z+ZY+z2+x+Y+zx+zy+Zy2+z2X+x2+zX+y+zY+Z+z2x++Zx+z2Y+Zx2+Zy'.split`+`[n%10955%24]
console.log(f(263541))
console.log(f(145362))
console.log(f(531426))
console.log(f(136452))
console.log(f(361524))
console.log(f(514236))

I wasted so much time looking at the cube in the wrong direction that I completely forgot the rule allowing alternate inputs... +1 for finding a perfect hash!

JavaScript (ES6), 114 bytes
Saved 15 bytes thanks to @ngn
Picking the results from a lookup table turns out to be significantly shorter than my best attempt so far at golfing a solver.
Outputs X, Y and Z instead of x', y', z'.
s=>'X//Zy//Zyx/z2/zX/Zx2//z2Y/x/Zy2//x2/Zx/z2X/zY/z2x/ZY/z/y//ZX/zy/y2//zx/Z/Y/'.split`/`[parseInt(s+0,35)%405%31]

Test cases

let f =

s=>'X//Zy//Zyx/z2/zX/Zx2//z2Y/x/Zy2//x2/Zx/z2X/zY/z2x/ZY/z/y//ZX/zy/y2//zx/Z/Y/'.split`/`[parseInt(s+0,35)%405%31]

console.log(f('YBRGOW')); // z2Y
console.log(f('WOGRBY')); // nothing
console.log(f('GRWOYB')); // z2x
console.log(f('WRBOGY')); // y2
console.log(f('RBWGYO')); // zx
console.log(f('GWOYRB')); // zy

Solver
Here is the solver used to generate the moves stored in the lookup table.
s => {
  const rot = [ '215304', '023415', '152043' ];
  const S = [];

  // recursive function looking for all possible solutions of at most 6 clockwise moves
  const g = (s, m, r = 0) => {
    if(s == 'WOGRBY') {
      // this is a solution; replace 3 consecutive identical clockwise moves with a
      // single counterclockwise move; rewrite 2 consecutive identical moves as 'x2';
      // store the result in S[]
      S.push(m.replace(/(.)\1\1/g, s => s[0].toUpperCase()).replace(/(.)\1/g, '$12'));
    }
    else if(!m[5]) {
      // try the next rotation on the current cube
      if(r < 2) {
        g(s, m, r + 1);
      }
      // apply the current rotation and restart from there
      g([...rot[r]].reduce((r, i) => r + s[i], ''), m + 'xyz'[r]);
    }
  }

  // find all solutions
  g(s, '');
  // find the length of the shortest solution(s)
  const min = Math.min(...S.map(s => s.length));
  // return the 1st solution matching this length
  return S.find(s => s.length == min);
}

Hash function
Below is a summary of the results provided by the hash function for all 24 valid inputs, along with the corresponding solutions.
 input    | base 35->10 | * 35        | mod 405 | mod 31 | output
----------+-------------+-------------+---------+--------+--------
 "WOGRBY" |  1717434494 | 60110207290 |     370 |     29 | ""
 "WBOGRY" |  1698256454 | 59438975890 |     175 |     20 | "y"
 "WRBOGY" |  1721718494 | 60260147290 |      55 |     24 | "y2"
 "WGRBOY" |  1705881974 | 59705869090 |     400 |     28 | "Y"
 "OGWBYR" |  1285921692 | 45007259220 |      45 |     14 | "Zx"
 "OYGWBR" |  1312271862 | 45929515170 |     120 |     27 | "Z"
 "OBYGWR" |  1278510372 | 44747863020 |     270 |     22 | "ZX"
 "OWBYGR" |  1309058862 | 45817060170 |     255 |      7 | "Zx2"
 "GRWOYB" |   882269476 | 30879431660 |     110 |     17 | "z2x"
 "GYRWOB" |   892568926 | 31239912410 |      80 |     18 | "ZY"
 "GOYRWB" |   877856956 | 30724993460 |     155 |      0 | "X"
 "GWOYRB" |   889441606 | 31130456210 |     395 |     23 | "zy"
 "RBWGYO" |  1435990314 | 50259660990 |     150 |     26 | "zx"
 "RYBWGO" |  1469623284 | 51436814940 |     135 |     11 | "Zy2"
 "RGYBWO" |  1443572994 | 50525054790 |     285 |      6 | "zX"
 "RWGYBO" |  1466838684 | 51339353940 |     360 |     19 | "z"
 "BYOWRG" |   629831036 | 22044086260 |     250 |      2 | "Zy"
 "BRYOWG" |   619745786 | 21691102510 |     325 |     15 | "z2X"
 "BWRYOG" |   626960756 | 21943626460 |     295 |     16 | "zY"
 "BOWRYG" |   615161906 | 21530666710 |      10 |     10 | "x"
 "YOBRGW" |  1822264042 | 63779241470 |     230 |     13 | "x2"
 "YGOBRW" |  1810797202 | 63377902070 |      35 |      4 | "Zyx"
 "YRGOBW" |  1826976442 | 63944175470 |       5 |      5 | "z2"
 "YBRGOW" |  1803428722 | 63120005270 |     350 |      9 | "z2Y"

it would be easier and shorter to use 'X00Zy0...'.split(0)[...]

@ngn Not sure what I was thinking here. Thanks!

much better with backticks :) here's another one: parseInt(s,35)*35 -> parseInt(s+0,35)

Ruby, 84 83 bytes
->a{k=a.index(0);%W{#{} z x Z X zz xx}[k+=k/5*a[2]/3]+%W{#{} Y yy y}[a[c=1+k%2]-c]}

Try it online!
Llambda function taking an array of 6 numbers 0..5 representing the faces, with the following solved configuration
   0
  1234
   5

Searches for the index of the array element containing 0 and selects a string for the move required to move it to the top: either by rotating in the x or z axis (or the empty string if it is already there, represented by #{} in %W{} notation.)
Then, inspect either array element 1 or 2 (whichever would not be altered by performing the move in the above step), select a string (always rotation in the y axis) for the move required to move the contents of the element to their solved location, and return the concatenated moves.
An issue arises when the index of the array containing 0 is 5, as there are two possible moves that will return it to the top: zz and xx. If array element 2 (the front of the cube) contains 2 the cube can be completely solved by zz, and if it contains 4 it can be solved by xx. The default is value to be returned is zz but if the front face contains 3 or 4 the expression k/5*a[2]/3 adds 1 to the index of %W{#{} z x Z X zz xx} that is returned, correcting it to xx. (Note that if the front face contains 1 or 3 it doesn't matter whether xxor zz is used as in these cases an additional 90 deg rotation will be required about the y axis regardless of whether xx or zz is used.)

Jelly, 75 bytes
I've been meaning to do this challenge for a while. I wonder if a straight hashing approach will be shorter than this solver.
“¡Çµ‘ṗÐ€7Ḷ¤Ẏ
œ?ạ⁸%7¤¦7
⁹Ḣ¤ç¥⁹¿
ỤỤḣ3çÐ€ÑĠḢịÑ+9µŒgPL⁼¥¡€3Fµ€LÞḢ×28+62%⁹%9ị³Ṣ¤

A full program accepting a list of characters as input and printing the result to STDOUT using the x, xx, X format.
For the sake of saving two! bytes it uses the somewhat confusing input:
X = White     Y = Orange    Z = Green
z = Yellow    y = Red       x = Blue      note: this makes the solved state XYZyxz

Try it online!
How?
Defines a dyadic link which can perform an x, y, or z to its right argument, an Up-Left-Front triple (ULF) of faces where:
1 = White     2 = Orange    3 = Green
6 = Yellow    5 = Red       4 = Blue      note: the solved state has ULF = 1,2,3
7             7             7       <--  ...and the sums of opposite faces are all 7

for certain left arguments:
if left % 6 == 0 and left % 7 in (0, 3):     # e.g. left = 0
    performs x
    # switches U&F, ULF to FLU, (permutation 0)
    # and switches the new U (index 0 or 3) to its opposite colour (7-value)
elif left % 6 == 2 and left % 7 in (0, 3):   # e.g. left = 14
    performs y
    # switches L&F, ULF to UFL, (permutation 2)
    # and switches the new L (index 0 or 3) to its opposite colour (7-value)
elif left % 6 == 3 and left % 7 in (-1, 2):  # e.g. left = 9
    performs z
    # switches U&L, ULF to LUF, (permutation 3)
    # and switches the new U (index -1 or 2) to its opposite colour (7-value)
else:
    does some other permutation and opposite colour swap which we wont use.

Creates all sequences made from the left inputs 0,14,9 of length zero to six
i.e. [[],[0],[14],[9],[0,0],[0,14],[0,9],[14,0],...,[9,9,9,9,9,9]]

and then repeatedly applies the link to the ULF of the translated input with the numbers in the list as the left arguments.
Translation of the input is performed by a double application of grade-up, Ụ, since the ordering used is chosen to make that work (the natural ordering of the characters is XYZxyz); while UFL is extracted by simply taking the first three results, ḣ3.
The sequences that result in a transformation to [1,2,3] (the solved state) are then transformed such that any run of exactly three of the same move are multiplied together.
Some arithmetic is performed to transform the results to be the indexes of "XYZxyz". This was found by brute-force to be to add nine prior to the multiplication, then to multiply all results by 28, to add another 62, to modulo by 256 to modulo again by 9 and finally to modulo by 6 (although the final modulo may be performed by indexing into something of length 6 since Jelly indexing is modular)
move  value     add 9      product  times 28  add 62  mod 256  mod 9  mod 6
 X    [ 0, 0, 0] [ 9, 9, 9]   729     20412    20474   250       7      1
 Y    [14,14,14] [23,23,23] 12167    340676   340738     2       2      2
 Z    [ 9, 9, 9] [18,18,18]  5832    163296   163358    30       3      3
 x     0          9             9       252      314    58       4      4
 y    14         23            23       644      706   194       5      5
 z     9         18            18       504      566    54       0      0

All that remains is to take the first shortest result and to index into the sorted input, "XYZxyz"

Commented code:
“¡Çµ‘ṗÐ€7Ḷ¤Ẏ - Link 1, get all sequences of 0,14,9 up to length 6: no arguments
“¡Çµ‘        - code-page indices = [0,14,9]
          ¤  - nilad followed by link(s) as a nilad:
        7    -   literal seven
         Ḷ   -   lowered range = [0,1,2,3,4,5,6]
      Ð€     - map across right:
     ṗ       -   Cartesian power -> [[[]],[[0],[14],[9]],[[0,0],[0,14],[0,9],...,[9,9]],...,[[0,0,0,0,0,0],...,[9,9,9,9,9,9]]]
           Ẏ - tighten -> [[],[0],[14],[9],[0,0],[0,14],[0,9],...,[9,9],...,[0,0,0,0,0,0],...,[9,9,9,9,9,9]]

œ?ạ⁸%7¤¦7 - Link 2, perform a manoeuvre: integer, N; list of integers, [U,L,F]
œ?        - Nth permutation of [U,L,F]
        7 - literal seven
       ¦  - sparse application...
  ạ       - ...of: absolute difference (from 7) -- i.e. opposite colour
      ¤   - ...to indexes: nilad followed by link(s) as a nilad:
   ⁸      -   chain's left argument = N
     7    -   literal seven
    %     -   modulo

⁹Ḣ¤ç¥⁹¿   - Link 3, perform manoeuvres: list of integers, [U,L,F], list of integers, M
      ¿   - while...
     ⁹    - ...condition: chain's right argument, M (while there are manoeuvres)
    ¥     - ...do: last two links as a dyad:
  ¤       -   nilad followed by link(s) as a nilad:
⁹         -     chain's right argument, M
 Ḣ        -     pop head -- gets the first element and modifies M
   ç      -     call last link (2) as a dyad (right is chain's left argument, [U,L,F])

ỤỤḣ3çÐ€ÑĠḢịÑ+9µŒgPL⁼¥¡€3Fµ€LÞḢ×28+62%⁹%9ị³Ṣ¤ - Main link: list of characters, S
Ụ                                            - grade-up (sort indices by value)
 Ụ                                           - grade-up again (net effect X->1, Y=>2, Z->3, x->4, y->5, z->6)
  ḣ3                                         - head to index three (get the ULF triple)
       Ñ                                     - call next link (1) as a monad (the input is not consumed, but that's OK)
     Ð€                                      - map across right with:
    ç                                        -   call last link (3)
        Ġ                                    - group the indices by value (placing all solved indices in the head, since [1,2,3] is less than others)
         Ḣ                                   - head
           Ñ                                 - call next link (1) as a monad (get the instructions again)
          ị                                  - index into (get the solving instruction lists)
            +9                               - add nine to all values in all instruction lists
              µ          µ€                  - for €ach instruction list:
               Œg                            -   group runs of equal elements
                       3                     -   literal three
                     ¡€                      -   repeat for €ach group...
                 P                           -   ...action: product
                    ¥                        -   ...number of times: last two links as a dyad
                  L                          -     length
                   ⁼                         -     equal to (three)? -- i.e. take the product of any run of exactly three values
                        F                    -   flatten (back to a single list)
                            Þ                - sort by:
                           L                 -   length (getting the shorted solving instruction list to the front)
                             Ḣ               - head
                              ×28            - multiply all the values by 28
                                 +62         - add 62 to all the values
                                     ⁹       - literal 256
                                    %        - modulo by (256)
                                      %9     - modulo by 9
                                           ¤ - nilad followed by link(s) as a nilad:
                                         ³   -   program's (1st) input
                                          Ṣ  -   sort (always = "XYZxyz")
                                        ị    - index into
                                             - implicit print to STDOUT