text:
Find the largest root of a polynomial with a neural network
The challenge
Find the smallest feedforward neural network such that, given any 3-dimensional input vector \$(a,b,c)\$ with integer entries in \$[-10,10]\$, the network outputs the largest (i.e., "most positive") root of the polynomial \$x^3+ax^2+bx+c\$ with error strictly smaller than \$0.1\$.
Admissibility
The notion of admissibility in my previous neural net golfing challenge seemed a bit restrictive, so for this challenge, we are using a more liberal definition of feedforward neural network:
A neuron is a function \$\nu\colon\mathbf{R}^n\to\mathbf{R}\$ that is specified by a vector \$w\in\mathbf{R}^{n}\$ of weights, a bias \$b\in\mathbf{R}\$, and an activation function \$f\colon\mathbf{R}\to\mathbf{R}\$ in the following way:
$$ \nu(x) := f(w^\top x+b), \qquad x\in\mathbf{R}^n. $$
A feedforward neural network with input nodes \$\{1,\ldots,n\}\$ is a function of \$(x_1,\ldots,x_n)\in\mathbf{R}^n\$ that can be built from a sequence \$(\nu_k)_{k=n+1}^N\$ of neurons, where each \$\nu_k\colon\mathbf{R}^{k-1}\to\mathbf{R}\$ takes inputs from \$(x_1,\ldots,x_{k-1})\$ and outputs a scalar \$x_k\$. Given some specified set \$S\subseteq\{1,\ldots,N\}\$ of output nodes, then the output of the neural network is the vector \$(x_k)_{k\in S}\$.
Since activation functions can be tuned for any given task, we need to restrict the class of activation functions to keep this challenge interesting. The following activation functions are permitted:

Identity. \$f(t)=t\$
ReLU. \$f(t)=\operatorname{max}(t,0)\$
SoftPlus. \$f(t)=\ln(e^t+1)\$
Sigmoid. \$f(t)=\frac{e^t}{e^t+1}\$
Sinusoid. \$f(t)=\sin t\$

Overall, an admissible neural net is specified by input nodes, a sequence of neurons, and output nodes, while each neuron is specified by a vector of weights, a bias, and an activation function from the above list. For example, the following neural net is admissible, though it does not meet the performance goal of this challenge:

Input nodes: \$\{1,2\}\$
Neurons: \$\nu_k(x_1,\ldots,x_{k-1}):=x_{k-2}+x_{k-1}\$ for \$k\in\{3,\ldots,10\}\$
Output nodes: \$\{5,9,10\}\$

This network consists of 8 neurons, each with zero bias and identity activation. In words, this network computes the generalized Fibonacci sequence generated by \$x_1\$ and \$x_2\$ and then outputs the 5th, 9th, and 10th numbers from this sequence, in that order.
Scoring
Given a real number \$x\$ with terminating decimal expansion, let \$p(x)\$ be the smallest nonnegative integer \$p\$ for which \$10^{-p}\cdot |x|<1\$, and let \$q(x)\$ be the smallest nonnegative integer \$q\$ for which \$10^q \cdot x\$ is integer. Then we say \$p(x)+q(x)\$ is the precision of \$x\$.
For example, \$x=1.001\$ has a precision of \$4\$, whereas \$x=0\$ has a precision of \$0\$.
Your score is the sum of the precisions of the weights and biases in your neural network.
(E.g., the above example has a score of 16.)
Verification
While the roots can be expressed in terms of the cubic formula, the largest root is perhaps most easily accessed by numerical means. Following @xnor's suggestion, I computed the largest root for every choice of integers \$a,b,c\in[-10,10]\$, and the results can be found here. Each line of this text file is of the form a,b,c,root. For example, the first line reports that the largest root of \$x^3-10x^2-10x-10\$ is approximately \$10.99247140445449\$.
Edit: The original file I posted had errors in cases where the polynomial exhibited a multiple root. The current version should be free of such errors.

What happens in the input polynomial has no real roots, like when a=0 and the quadratic has two complex roots?

I think the cleanest solution would be the say that the input will have a be nonzero, or even just 1. Also, I'd recommend putting in some test cases, giving the roots to high precision so we can checks ours are within 0.1. It would also be good to have outputs for all possible inputs, probably in a link since that's a lot for the post.

@xnor - Good eye, thanks! I'll work on some test cases.

I like the new admissibility rules. It looks like the new sinusoid function is extremely exploitable though. I have a sketchy proof that a function of the form x -> a * sin(b * softplus(x) + c) can overfit any finite number of data points with integer x to arbitrary precision using an extremely large and precise frequency.

@xnor - Thanks for spotting that. I expect sinusoid to be useful, but I agree that your exploit is extreme, so I updated the scoring mechanism to reflect precision. It seems more natural in hindsight.

Not sure how useful it would be (for future challenges): In number theory we use height functions to measure the complexity of a number. For example the naive height of a (reduced) fraction $p/q$ is given by $h=\log\max{|p|,|q|}$ (and there are lot of generalizations). Maybe this could be used as an alternative measure.

@DustinG.Mixon I'm not sure if you're aware but we do have a sandbox for posting drafts and discussing details of a challenge a well as a chat.

@xnor He changed the coefficient of x^3 to constant 1 as to prevent this. BTW: this would only happen if a is zero and the discriminant of the quadratic is negative.

14,674,000,667 5,436,050 5,403,448 10,385 5,994 4,447  3,806 total precision
For a baseline, I investigated the following approach: Select \$M,\delta,\epsilon>0\$ such that if we sample the polynomial \$p(x)=x^3+ax^2+bx+c\$ at
$$ S:=\{-M,-M+\delta,-M+2\delta,\ldots,M\}, $$
then the largest sample point \$s^\star\in S\$ satisfying \$p(s^\star)<\epsilon\$ necessarily exists and necessarily resides within \$0.1\$ of the largest root of \$p\$. One can show that for our collection of polynomials, one may take \$M=11\$, \$\delta=0.1\$, and \$\epsilon=10^{-4}\$.
To design a neural net that implements this logic, we start with a layer of neurons that sample the polynomial on \$S\$. For each \$s\in S\$, we take
$$ x_{1,s} = s^2\cdot a + s\cdot b + 1\cdot c + s^3. $$
Next, we identify which of these are less than \$\epsilon=10^{-4}\$. It turns out that for \$s\in S\$, it holds that \$p(s)<10^{-4}\$ only if \$p(s)\leq 0\$. As such, we can use relu activations to exactly identify our samples:
$$ \frac{\mathrm{relu}(10^{-4}-t) - \mathrm{relu}(-t)}{10^{-4}} = \left\{\begin{array}{cl}1&\text{if }t\leq 0\\0&\text{if }t\geq 10^{-4}.\end{array}\right.$$
We implement this with a few layers of neurons:
$$ \begin{aligned}
x_{2,s} &= \mathrm{relu}(-1\cdot x_{1,s}+10^{-4}), \\
x_{3,s} & = \mathrm{relu}(-1\cdot x_{1,s}), \\
x_{4,s} &= 10^{4}\cdot x_{2,s}-10^{4}\cdot x_{3,s}. \end{aligned}$$
At this point, we have \$x_{4,s}=1\$ when \$p(s)<10^{-4}\$, and otherwise \$x_{4,s}=0\$. Recall that we seek the largest \$s^\star\$ for which \$x_{4,s^\star}=1\$. To this end, we label \$x_{4,M}\$ as \$x_{5,M}\$ (for notational convenience), and for each \$k\geq 1\$, we iteratively define
$$ x_{5,M-k\delta} = 1\cdot x_{4,M-k\delta}+2\cdot x_{5,M-(k-1)\delta} = \sum_{j=0}^k 2^{k-j}x_{4,M-j\delta}. $$
Thanks to this transformation, every \$x_{5,s}\$ is a nonnegative integer, and \$s^\star\$ is the unique \$s\$ for which \$x_{5,s}=1\$. We may now identify \$s^\star\$ by another application of relu activations:
$$ \mathrm{relu}(t-2)-2\cdot\mathrm{relu}(t-1)+t = \left\{\begin{array}{cl}1&\text{if }t=1\\0&\text{if }t\in\mathbf{Z}_{\geq 0}\setminus\{1\}.\end{array}\right.$$
Explicitly, we define neurons by
$$ \begin{aligned}
x_{6,s} &= \mathrm{relu}(1\cdot x_{5,s} - 2), \\
x_{7,s} &= \mathrm{relu}(1\cdot x_{5,s} - 1), \\
x_{8,s} &= 1\cdot x_{6,s} - 2\cdot x_{7,s} + 1\cdot x_{5s}.
\end{aligned} $$
Then \$x_{8,s}=1\$ if \$s=s^\star\$ and otherwise \$x_{8,s}=0\$. We linearly combine these to produce our output node:
$$ x_9 = \sum_{s\in S} s\cdot x_{8,s} = s^\star. $$
For the score, each layer has neurons with different levels of precision:
(1) \$6+3+1+9=19\$, (2) \$1+4=5\$, (3) \$1\$, (4) \$5+5=10\$, (5) \$1+1=2\$, (6) \$1+1=2\$, (7) \$1+1=2\$, (8) \$1+1+1=3\$, (9) \$3|S|\$. Furthermore, all but two of the layers have \$|S|=221\$ neurons; layer 5 has \$|S|-1\$ neurons and layer 9 has \$1\$ neuron.
Edit: Improvements: (1) We can sample the polynomial much more efficiently using finite differences. (2) We can bypass layers 2 through 4 by instead using a sigmoid activation. (3) The overflow issues in layer 5 can be averted (and subsequent layers can be combined) by more carefully applying relu activations. (4) The final sum is cheaper with summation by parts.
What follows is the MATLAB code. To be clear, prec is a function (found here) that computes the precision of a vector of weights or biases.
function sstar = findsstar2(a,b,c)

relu = @(x) x .* (x>0);

totprec = 0;

% x1 samples the polynomial on -11:0.1:11
x1=[];
for s = -11:0.1:11
    if length(x1) < 5
        w1 = [s^2 s 1];
        b1 = s^3;
        x1(end+1,:) = w1 * [a; b; c] + b1;
        totprec = totprec + prec(w1) + prec(b1);
    else
        w1 = [-1 4 -6 4];
        x1(end+1,:) = w1 * x1(end-3:end,:);
        totprec = totprec + prec(w1);
    end
end

% x4 indicates whether the polynomial is nonpositive
w4 = -6e5;
b4 = 60;
x4=[];
for ii=1:length(x1)
    x4(end+1) = sigmf(w4 * x1(ii) + b4, [1,0]);
    totprec = totprec + prec(w4) + prec(b4);
end

% x6 indicates which entries are less than or equal to sstar
x5 = zeros(size(x1));
x6 = zeros(size(x1));
x5(end) = 0;
x6(end) = 0;
for ii = 1:length(x5)-1
    w5 = [-1 -1];
    b5 = 1;
    x5(end-ii) = relu(w5 * [x4(end-ii); x6(end-ii+1)] + b5);
    totprec = totprec + prec(w5) + prec(b5);
    w6 = -1;
    b6 = 1;
    x6(end-ii) = w6 * x5(end-ii) + b6;
    totprec = totprec + prec(w6) + prec(b6);
end

% a linear combination produces sstar
w7 = 0.1*ones(1,length(x1));
w7(1) = -11;
sstar = w7 * x6;

%disp(totprec) % uncomment to display score

end

53,268 29,596 29,306  total precision
Private communication with @A.Rex led to this solution, in which we construct a neural net that memorizes the answers. The core idea is that every function \$f\colon S\to\mathbf{R}\$ over a finite set \$S\$ enjoys the decomposition
$$ f(x) = \sum_{s\in S}f(s)\cdot \left\{\begin{array}{cl}1&\text{if }x=s\\0&\text{else}\end{array}\right\}. $$
As such, one may construct a neural net implementation of \$f\$ by first transforming the input into an indicator function of the input, and then linearly combining using the desired outputs as weights. Furthermore, relu activations make this transformation possible:
$$ \mathrm{relu}(t-1)-2\cdot\mathrm{relu}(t)+\mathrm{relu}(t+1) = \left\{\begin{array}{cl}1&\text{if } t=0\\0&\text{if }t\in\mathbf{Z}\setminus\{0\}.\end{array}\right. $$
What follows is a MATLAB implementation of this approach. To be clear, roots.txt is the roots file posted above (found here), and prec is a function (found here) that computes the total precision of a vector of weights or biases.
Edit 1: Two improvements over the original: (1) I factored some neurons out of the for loops. (2) I implemented "Lebesgue integration" in the final sum by first combining terms from the same level set. This way, I pay for the higher-precision value of an output only once every level set. Also, it is safe to round outputs to the nearest fifth by the rational root theorem.
Edit 2: Additional minor improvements: (1) I factored more neurons out of a for loop. (2) I don't bother computing the term in the final sum for which the output is already zero.
function r = approxroot(a,b,c)

relu = @(x)x .* (x>0);

totalprec=0;

% x4 indicates which entry of (-10:10) is a
w1 = ones(21,1);   b1 = -(-10:10)'-1;    x1 = relu(w1 * a + b1);
w2 = ones(21,1);   b2 = -(-10:10)';      x2 = relu(w2 * a + b2);
w3 = ones(21,1);   b3 = -(-10:10)'+1;    x3 = relu(w3 * a + b3);
w4p1 = ones(21,1); w4p2 = -2*ones(21,1); w4p3 = ones(21,1);
x4 = w4p1 .* x1 + w4p2 .* x2 + w4p3 .* x3;
totalprec = totalprec + prec(w1) + prec(w2) + prec(w3) + prec(b1) + prec(b2) + prec(b3) + prec(w4p1) + prec(w4p2) + prec(w4p3);

% x8 indicates which entry of (-10:10) is b
w5 = ones(21,1);   b5 = -(-10:10)'-1;    x5 = relu(w5 * b + b5);
w6 = ones(21,1);   b6 = -(-10:10)';      x6 = relu(w6 * b + b6);
w7 = ones(21,1);   b7 = -(-10:10)'+1;    x7 = relu(w7 * b + b7);
w8p1 = ones(21,1); w8p2 = -2*ones(21,1); w8p3 = ones(21,1);
x8 = w8p1 .* x5 + w8p2 .* x6 + w8p3 .* x7;
totalprec = totalprec + prec(w5) + prec(w6) + prec(w7) + prec(b5) + prec(b6) + prec(b7) + prec(w8p1) + prec(w8p2) + prec(w8p3);

% x12 indicates which entry of (-10:10) is c
w9 = ones(21,1);    b9 = -(-10:10)'-1;     x9 = relu(w9 * c + b9);
w10 = ones(21,1);   b10 = -(-10:10)';      x10 = relu(w10 * c + b10);
w11 = ones(21,1);   b11 = -(-10:10)'+1;    x11 = relu(w11 * c + b11);
w12p1 = ones(21,1); w12p2 = -2*ones(21,1); w12p3 = ones(21,1);
x12 = w12p1 .* x9 + w12p2 .* x10 + w12p3 .* x11;
totalprec = totalprec + prec(w9) + prec(w10) + prec(w11) + prec(b9) + prec(b10) + prec(b11) + prec(w12p1) + prec(w12p2) + prec(w12p3);

% x15 indicates which row of the roots file is relevant
x15=[];
for aa=-10:10
    w13 = 1;
    b13 = -2;
    x13 = w13 * x4(aa+11) + b13;
    totalprec = totalprec + prec(w13) + prec(b13);
    for bb=-10:10
        w14p1 = 1;
        w14p2 = 1;
        x14 = w14p1 * x13 + w14p2 * x8(bb+11);
        totalprec = totalprec + prec(w14p1) + prec(w14p2);
        for cc=-10:10
            w15p1 = 1;
            w15p2 = 1;
            x15(end+1,1) = relu(w15p1 * x14 + w15p2 * x12(cc+11));
            totalprec = totalprec + prec(w15p1) + prec(w15p2);
        end
    end
end

% r is the desired root, rounded to the nearest fifth
A = importdata('roots.txt');
outputs = 0.2 * round(5 * A(:,4)');
uniqueoutputs = unique(outputs);
x16 = [];
for rr = uniqueoutputs
    if rr == 0
        x16(end+1,:) = 0;
    else
        lvlset = find(outputs == rr);
        w16 = ones(1,length(lvlset));
        x16(end+1,:) = w16 * x15(lvlset);
        totalprec = totalprec + prec(w16);
    end
end
w17 = uniqueoutputs;
r = w17 * x16;
totalprec = totalprec + prec(w17);

%disp(totalprec) % uncomment to display score

end


text:
Postman Delivery
I just got a job as a postman and I need your help to keep it.
I have to order a lot of mails before I go out to deliver them.
Streets are numbered strictly sequentially, starting with 1 at the start of the street, and continuing in order skipping no numbers until the end, with odd numbers on the left side and evens on the right side.
Plus houses were added later so we may also have letters appended to the civic number.
The chest contains all mail of the city so I have to choose only mails of my street.
I need your help to order the mails faster.
What I ask you is to write a function or full program taking:
  - A street name.
  - A list of civic numbers ordered following my path.
  - A list of addresses (representing the mail chest).
And output a list of addresses containing only the ones of my street, ordered following the list of civic numbers.
An address has the form :
 Person Name/n
 CivicN Street Name

Where CivicN is a number that can be followed by a '/' and an UPPERCASE LETTER (10 10/B). If you prefer, lowercase is acceptable.
If Streets Names overlaps they are considered different streets:
Church Road  != Saint Lorenz Church Road

We omit the rest of the address for simplicity (assuming it is the same for every mail)
Letters must be delivered fast so shortest answer wins.
EXAMPLE:
Layout :
 1 1/B     3 5 7      9 11 13
 ==============================
       2 4       4/B 6

Input :
"Tea Avenue"
["1","1/B","2","4","3","5","7","4/B","6","9","11","13"]
["Mrs. Pie O. Pinky\n6 Tea Avenue","Ms. Kita I. Omeeha\n6 Tea Avenue","Mr. Raile A. Lee\n26 Uea Grove","Odd O. Nic\n76 Mira Road","Mrs. Fuel Tee\n78 Uea Grove","Ny O. Ondip\n55 Uea Grove","Mrs. Black\n67 Uea Grove","Ollie E.\n11 Tea Avenue","Mr. Urna Li\n75 Mira Road","Ms. Polly\n2 Tea Avenue"]

Output :
Ms. Polly
2 Tea Avenue

Mrs. Pie O. Pinky
6 Tea Avenue

Ms. Kita I. Omeeha
6 Tea Avenue

Ollie E.
11 Tea Avenue

Input :
"Church Road"
["1","3","5","5/B","2","4","7","7/B","6","9","9/B","11","11/B"]
["Billy Ray V.\n5 Church Roadside East","Ms. Mia\n5 Church Road","Mrs. Dadeos\n9/B Church Road","Dr. Ymin U.\n3 Church Road","Atty. Nerou\n3 Church Road","Ollie A. Chaim\n6 Saint Lorenz Church Road","Ms. Rose\n5 Church Road","Alf Taohy\n79 Berry Road","Ms. Ootr E.\n5 Saint Lorenz Church Road","Lol E.\n21 Berry Road","Ms. Norton\n2 Church Road"]

Output :
Dr. Ymin U.
3 Church Road

Atty. Nerou
3 Church Road

Ms. Mia
5 Church Road

Ms. Rose
5 Church Road

Ms. Norton
2 Church Road"

Mrs. Dadeos
9/B Church Road

Test generator: Try it online!
Change string_wrapper_left/right and separator to modify formatting.
Rules :
- Standard loopholes are forbidden.
- Standard input/output methods.
- Shortest answer in bytes wins.

I was afraid you were going to ask us to solve the travelling salesman problem.

Can you provide a test case in which the house number contains a letter?

May we take each address as an array of 2 strings? (e.g. ["Mrs. Pie O. Pinky","6 Tea Avenue"])

Sorry @Arnauld , I think an address should be only one string as I read it on a mail during my work.

@Jitse I added a test generator for this purpose. Anyway here's one:
Po Road
[1,2,2/B,3,5,7,7/B,4,6,6/B,9,8]
["Brother Odti U. Bbehf
20 Nco Street","Capt. Rndd A. Raulsi
97/A Aaiiso Grove","Mr. Iaw E. Ueaeoe
42 Aaiiso Grove","Sn O. Xuu
2/B Po Road","Mrs. Cw O. Saieso
6/B Po Road","Ogsa I. Auui
8 Po Road","Mr. Tah I. Tdrlii
27/A Aaiiso Grove","Atty. Dereh I. Oainuo
1 Po Road","Mr. Nn I. Ri
79 Aaiiso Grove"]
OUTPUT :
["Atty. Dereh I. Oainuo
1 Po Road"
"Sn O. Xuu
2/B Po Road"
"Mrs. Cw O. Saieso
6/B Po Road"
"Ogsa I. Auui
8 Po Road"]

@AZTECCO Thanks! It is highly recommended to have several test cases embedded in your post, not just in the demo code.

Can street names overlap (i.e. Church Lane and Sint Nicholas Church Lane)? Two of the three existing answers would match both of these if Church Lane was given as street-input.

@Kevin Cruijssen no they can't, they are different streets, sorry I had to make it clear. Can I update to specify it or it's too late?

Don't you mean "yes they can overlap, they are different streets" or "no they cannot overlap, you won't get test cases like this"? Your sentence contradicts itself right now. ;) But I don't mind if you specify it in the challenge. If you do mean that test cases like that are possible, I'll edit my 05AB1E answer to account for it. And @Jitse would have to change his Python answer as well in that case.

Oh.. I meant "yes they can overlap, they are considered different streets"

Is this legitimately for your job? Or are you pulling my leg?

I think your leg is longer now ;) anyway I worked for real as a season postman many years ago and this problem really existed!

Can confirm. I used to work as a Saturday postman as well many years ago. :) Although in almost all streets of my delivery districts it was more time efficient to just park my bike at the edge of the street, walk one way and deliver all odd numbers, and then walk the other side back doing all even numbers, ending up at my bike again. Then again, with big streets, busy periods like Christmas, or loads of commercial folders, I usually had to walk back to my bike in between a few times because I couldn't carry all post of the entire street in one go.. >.>

We also had a separated sorting center. But although the idea was they'd be done before 11 o'clock so I could start delivering, loads of time I ended up helping them because they were too slow and I otherwise could start at 12:30 instead if I'd waited for them without helping.. >.<

I can still remember a small village I was assigned, there was an extremely complex layout (really inefficient) streets were renamed and renumbered 3 times! Whit names of one street assigned to another and back like a deck of cards, same people family names for many houses, and a mountain scenario. I had to learn most of the people names and didn't used the addresses, then my season ended lol

Can street names overlap in both ways? Obviously Church Lane and Sint Nicholas Church Lane, but also Church Lane Road?

@Jitse Yes, because we may also have a "mulholland drive" and a "mulholland drivers road" for example

@AZTECCO Then a few answers still fail. Perhaps add a testcase for this issue.

@Jitse right, thanks, I'll add a test case for it.

05AB1E, 15 13 12 bytes
ε²ðýUʒ¶¡Xk]˜

-2 bytes by porting @JonathanAllan's Jelly answer, so make sure to upvote him!
-1 byte thanks to @Grimy.
Inputs are in the order: [list of civic numbers], street name, [list of addresses].
Try it online.
Explanation:
ε       # Map over the (implicit) input-list of civic numbers
 ²      #  Push the second street-input
  ðý    #  And join the two values by a space
    U   #  Pop and store this street + num string in variable `X`
 ʒ      #  Filter the (implicit) input-list of addresses by:
  ¶¡    #   Split on newlines
    Xk  #   Get the index of string `X` (street + num) in this list,
        #   which will be either -1 (not found), 0 (first address-line), or
        #   1 (second address-line), and only 1 is truthy in 05AB1E
]       # After both the inner filter and outer map:
 ˜      # Flatten the array to remove any empty inner lists
        # (after which the result is output implicitly)

Waiting for edit, thanks a lot for the help !

I've edited a test case with overlap test case adding "Billy Ray V.\n5 Church Roadside East" , he should not appear in the output, please fix your answer. Sorry for the inconvenience, I'll pay more attention on my challenges in the future.

@AZTECCO Should be fixed now by using Grimy's first golfing suggestion.

Thanks for your time!

Jelly, 13 bytes
,⁵KỴṪ⁼ɗƇ@ɗ€ẎY

A full program accepting three arguments - a list of civic numbers on your named street, a list of the addresses in the mail chest, and your street name - which prints the addresses to which you need to deliver in the order of the given civic numbers.
Try it online!
How?
,⁵KỴṪ⁼ɗƇ@ɗ€ẎY - Main link: civic numbers, addresses
          €   - for each (civic number):
         ɗ    -   last three links as a dyad - i.e. f(civic number, addresses):
,⁵            -     pair (the civic number) with 3rd program input (the street name)
  K           -     join (that) with a space -- i.e. X=civic number+' '+street name
        @     -     with swapped arguments i.e. f(addresses, X):
       Ƈ      -       filter (the addresses) keeping those for which:
      ɗ       -         last three links as a dyad - i.e. f(address, X):
   Ỵ          -           split (address) at newlines
    Ṫ         -           tail (get the second line)
     ⁼        -           equals (X)?
           Ẏ  - tighten (the list of lists to a single list)
            Y - join with newlines

JavaScript (Node.js), 58 bytes
(s,n,a)=>n.flatMap(n=>a.filter(x=>x.split`
`[1]==n+' '+s))

Try it online!
Commented
(s, n, a) =>          // s = street name, n[] = civic numbers, a[] = addresses
  n.flatMap(n =>      // for each civic number n in n[]:
    a.filter(x =>     //   for each address x in a[]:
      x.split`\n`[1]  //     keep it if the 2nd part is equal to
      == n + ' ' + s  //     n + space + expected street name
    )                 //   end of filter()
  )                   // end of flatMap() (empty entries are discarded)

First answer! You saved my job! Thanks for improvement btw

Perl 5, 51 bytes
sub{my($r,$a,@B)=@_;map{$n=$_;grep/
$n $r$/,@B}@$a}

Try it online!

I've edited a test case with overlap test case adding "Billy Ray V.\n5 Church Roadside East" , he should not appear in the output, please fix your answer. Sorry for the inconvenience, I'll pay more attention on my challenges in the future.

fixed +1byte, adding $ anchor at the end of regex

Thanks for your time

Ruby, 65 bytes
->s,o,n{n.grep(/\d\S* #{s}$/).sort_by{|i|o.index i[/\d+(\/.)?/]}}

Try it online!

Python 3, 65 bytes
lambda s,n,m:[a for i in n for a in m if a.endswith('\n%s '%i+s)]

Try it online!
Also works in Python 2.
For each number i in the list of civic numbers n, the function will iterate over all addresses a in the list of mail m and keep the ones where the combination of the civic number i and the street name s matches with a. This results in a sorted and filtered list.

C# (Visual C# Interactive Compiler), 63 bytes
(a,b,c)=>b.SelectMany(x=>c.Where(l=>l.Split('\n')[1]==x+" "+a))

Try it online!

Python 3, 79 85 bytes (thanks to squid)
d=lambda s,n,a:n and[k for k in a if k.split('\n')[1]==n[0]+' '+s]+d(s,n[1:],a)

old:
d=lambda s,n,a:[k for k in a if k.split('\n')[1]==n[0]+' '+s]+d(s,n[1:],a)if n else[]

79 bytes unless this breaks it somehow

cool, I didn't know you could use 'and' to produce outputs like that

Kotlin, 145 bytes
fun p(s:String,o:List<String>,m:List<String>):List<String>
=if(o.size<1)List(0){""}
else
m.filter{it.split("\n")[1]==o[0]+" "+s}+p(s,o.drop(1),m)

Try it online!

source: Stack Exchange

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

sort: votes


text:
BLUEREDGOLDEGGSFEATHERSFEATHERS
There's a little-known secret in Banjo-Kazooie that you can interleave the three Cheato codes on the Treasure Trove Cove Sandcastle floor and it will still recognize all of them. So you could, for instance, enter BLUREEGOLDDFFEEGEAATHTHEEGSRSRS, activating BLUEEGGS, REDFEATHERS, and GOLDFEATHERS all at once.
Challenge
Your task is to take a list of cheat codes and a code entry and determine which of the codes are activated.
A code entry is valid if and only if some substring of the entry can spell out a subset of the cheat codes by assigning letters one at a time to exactly one word in order until all codes are exactly filled in. For example, applying this to the above code entry:
BLUREEGOLDDFFEEGEAATHTHEEGSRSRS

BLU_E________E_G_________GS____
___R_E___D_F__E__A_TH__E___RS__
______GOL_D_F___E_A__TH_E____RS

Other Assumptions

Both cheats and entries will contain only uppercase letters A-Z.
Each code in the input list will appear only once.
If two cheat codes share a prefix or a suffix, their shared letters must still appear twice to be counted, thus REDGOLDFEATHERS would, for the purposes of this challenge, only return GOLDFEATHERS.
Each code entry can only contain one matching substring.
If it is ambigous how a code-matching substring could be chosen, choose the one that starts the earliest and is the longest match for that particular starting point.
The order of matched codes returned does not matter.
If it is ambiguous which code could be used, prefer cheat codes that appear earlier in the code list.
A substring does not match if some of the letters inside it cannot be assigned to a cheat code. For instance BLUEXEGGS does not match any cheat codes.
If no codes are matched, you may return an empty list or any falsy value.

Note that this may not necessarily be consistent with the nuances of the game`s implementation
Example Test Cases
Codes:
  BLUEEGGS

Entry: BLUEEGGS

Result:
  BLUEEGGS

Codes:
  BLUEEGGS
  REDFEATHERS
  GOLDFEATHERS

Entry: BANJOGOLDBLUREEDFEATHEERGGSSKAZOOIE

Result:
  BLUEEGGS
  REDFEATHERS

Codes:
  BLUEEGGS
  REDFEATHERS
  GOLDFEATHERS

Entry: KAZOOIEBLUREEGOLDDFFEEGEAATHTHEEGSRSRSBANJO

Result:
  BLUEEGGS
  REDFEATHERS
  GOLDFEATHERS

Codes:
  BLUEEGGS
  REDFEATHERS
  GOLDFEATHERS

Entry: BANJOKAZOOIE

Result: <falsy>

Codes:
  CAT
  DOG

Entry: CCADOGATT

Result:
  DOG
(The substring may not contain the same code twice)

Codes:
  COG
  ATE
  CAT
  DOG

Entry: CDCOAGTE

Result:
  DOG
  CAT
(Match the earliest and longest substring)

Codes:
  ACE
  BDF
  ABC
  DEF

Entry: ABCDEF

Result:
  ACE
  BDF
(Prefer matching codes earlier in the list)

Rules/Scoring
Standard procedure for code golf applies. I/O can use any convenient format. Fewest bytes wins.

How do we know when the user is done entering cheat codes?

@spuck "I/O can use any convenient format." Your entry could be a string on stdin, or an argument, your list of cheat codes could be a list passed to a function or a string delimited by newlines/spaces/commas/whatever.

To use the titles from the test cases: how do we determine when "Codes" are done so we know when to accept "Entry"? On stdin, do we then have to handle all input at once so "Entry" is the last line before EOF?

Use any convenient format. If that works best for you then use it, if it doesn't don't.

For the CDCOAGTE test case, shouldn't the output be COG and CAT?

@Joel no, because that contains a superfluous D

Sorry but I still don't get it. Why doesn't the match C__O_G__ & __C_A_T_ beat the DOG & CAT match?

@Joel That split/assignment doesn't account for the D. You have to use all the letters from that particular substring. (Substrings must be made up of contiguous letters) C__O_G_ & __C_A_T still leaves you with _D______ left unused.

I see. BTW, this criteria "choose the one that starts the earliest and is the longest match for that particular starting point" has two conditions and it seems unclear which one has the priority if they do not agree.

Some test cases I'm unclear on: 1) codes ABC, AB, CD, EF, DE and entry ABCDEF. 2) codes ABC, BCDEFG, DE entry ABCDEFG.

As far as I can tell "choose the one that starts the earliest and is the longest match for that particular starting point" means "find the largest prefix of the entry a suffix of which matches at least one code, then take the largest suffix of that prefix which matches at least one code". Conveniently happens to line up perfectly with the generation order of Brachylog's substring builtin, and probably some other language's as well.

Brachylog, 25 bytes
hsS&t⊇.g;Sz{∋ʰ}ᵐhᵍ{tᵐc}ᵐp

Try some of the faster test cases online!
Extremely slow brute force, that I haven't verified on the longer test cases yet. It wouldn't surprise me if a clever implementation of a smarter algorithm turns out considerably shorter. Takes input as a list [entry,codes] through the input variable and outputs through the output variable if it succeeds. Seems to comply fully with the spec to the extent to which I've tested it at all.
The exact nature of the brute force is that for every substring of the entry (until there's a match), it tries every subset of the codes until it's possible to assign one code to each letter of the substring such that the letters assigned to each code taken in order form that code. The worst case complexity, where the worst case is failure, is something vaguely along the lines of \$O(x^22^yy^x)\$ with \$x\$ the length of the entry and \$y\$ the number of codes.

Ten minutes on my toaster still haven't produced anything for ["BANJOGOLDBLUREEDFEATHEERGGSSKAZOOIE",["BLUEEGGS","REDFEATHERS","GOLDFEATHERS"]]

Eighty minutes still haven't.

yeah I'm not sure how much longer I want to run this

1+ for dedication :) Also for being the only answer so far

It shouldn't be hard for most languages to do this very efficiently, it just wouldn't be quite so short in Brachylog...

Python 2, 419 416 bytes
def f(a,s):
 V=[]
 for u,c in((u,c)for z in product(*[g(c,s)for c in a])for u,c in zip(S(z),S(a))):A=set(sum(u,[]));L=sum(map(len,u));V+=A and(len(A)==L>max(A)-min(A))*[(min(A),-L,c)]
 return V and sorted(V)[0][2]
S=lambda A:A and[u+[A[0]]for u in S(A[1:])]+S(A[1:])or[[]]
def g(c,s,i=0):
 r=[[]]*(c=='')
 while c and c[0]in s[i:]:i=s.find(c[0],i)+1;r+=[u+[i-1]for u in g(c[1:],s,i)]
 return r
from itertools import*

Try it online!
After some trivial spaces being removed, still pretty long!
The function S returns the power set of a collection. The function g(c,s) return a list whose elements are a list of indexes of a potential embedding of the code c in the entry string s.
The function f(a,s) then looks at all possible combinations of embeddings of some or all of the codewords in s, selecting those which end up being a continuous sub-string of s (the bit about A and L first ensures that the particular choice of embeddings are pairwise disjoint, and then that there are no gaps).
By nature of the use of product and the action of S, the unsorted results will "prefer cheat codes that appear earlier"; we then further sort by first the starting index of such a substring, and then by length in case of a tie; so that in case of a tie for both starting index and length, the original ordering will prevail as I think was demanded.
If no embeddings are found, the empty list is returned.
I'm guessing the g can be golfed a bit more, at the expense of a much longer running time...

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


text:
Little Endian Number to String Conversion
Introduction
During work with BMP (bitmap) generator I face problem of converting number to little endian hex string. Here is function which I create in JavaScript - but wonder how small code can works similarly

let liEnd= num => num.toString(16).padStart(8,'0').match(/../g).reverse().join``;
console.log(liEnd(304767)) // 304767 dec = 0x4a67f hex

Challenge
Write function which will take 32bit unsigned integer number on input, and produce 8-digit hexadecimal string with little endian order. The example algorithm which do the job:

convert numb to hex string e.g: 304767 -> '4a67f'
add padding zeros to get 8-char string: '0004a67f'
split string to four 2-char pieces: '00','04','a6','7f'
reverse order of pieces '7f','a6','04','00'
join pieces and return as result: '7fa60400'

Example Input and Output
Input number (or string with dec number) is on the left of ->, output hex string is on the right
2141586432 -> 0004a67f
304767     -> 7fa60400

05AB1E, 10 9 bytes
žJ+h¦2ôRJ

Try it online!
-1 byte by inspiration of the Jelly answer.
žJ+   add 2^32 to input
h     convert to hex
¦     drop leading 1
2ô    split in groups of 2
R     reverse groups
J     and join them

R, 54 53 bytes
format.hexmode(scan()%/%256^(0:3)%%256%*%256^(3:0),8)

Try it online!
Each group of 2 characters is actually the hex representation of a digit in base 256. scan()%/%256^(0:3)%%256 converts to a base 256 number with 4 digits reversed,
...%*%256^(3:0) joins them as a single integer, and format.hexmode(...,8) converts that number to its hex representation with 8 digits.

Python 3, 37 bytes
lambda n:n.to_bytes(4,"little").hex()

Try it online!
Arithmetic-based recursive solution (50 49 bytes, works also for Python 2):
f=lambda n,i=4:i*'1'and"%02x"%(n%256)+f(n>>8,i-1)

Try it online!
-1 byte thanks to @JonathanAllan

I'd say submit the recursive one as a Python 2 entry :)

f=lambda n,i=4:i*'1'and'%02x'%(n%256)+f(n>>8,i-1) saves a byte :)

@JonathanAllan Thanks. I am not familiar with all Python 2 tricks and do not see how it can be made shorter though.

it doesn't but the 37 won't work in py 2

Yeah. Some of those built-ins are Python-3-only.

@negativeseven Interesting approach. You may post it as another answer for Python 2.

JavaScript (ES7),  59  57 bytes
String manipulation.
n=>(n+2**32).toString(16).match(/\B../g).reverse().join``

Try it online!
How?
We first convert \$n + 2^{32}\$ to hexadecimal to make sure that all leading \$0\$'s are included:
(304767 + 2**32).toString(16) // --> '10004a67f'

Try it online!
We use the regular expression /\B../g to match all groups of 2 digits, ignoring the leading \$1\$ thanks to \B (non-word boundary).
'10004a67f'.match(/\B../g) // --> [ '00', '04', 'a6', '7f' ]

Try it online!
We reverse() and join() to get the final string.

JavaScript (ES6), 61 bytes
Recursive function.
f=(n,k=4)=>k?[(x=n&255)>>4&&'']+x.toString(16)+f(n>>8,k-1):''

Try it online!

⭐ - you get star for nice answer - I like it, short but still clean and "human-redable" :)

C# (Visual C# Interactive Compiler), 54 bytes
x=>$"{(x=x>>16|x<<16)>>8&16711935|(x&16711935)<<8:x8}"

Saved 4 bytes thanks to @PeterCordes
Try it online!
Explanation
x=>                                                    //Lambda taking in an uint
     (x=x>>16|x<<16)                                   //Swap the first two and the last two bytes of the uint (0x7fa60400 -> 0x04007fa6)
                    >>8&16711935|(x&16711935)<<8       //Swap each pair of bytes in every group of 2 bytes (0x04007fa6 -> 0x0004a67f)
  $"{                                           :x8}"  //Format as hex string, padded with leading zeroes to length 8

Can you shrink the 4278255360 mask constant to 16711935 (0xff00ff) if you shift before masking?   Or does that cost extra parens?  Also, if not then 0xff00ff00 is the same length but much more meaningful to humans.

@PeterCordes It also has the added advantage of being able to remove the brackets as >> has higher precedence than &, whcih saved 4 bytes total. Thanks!

Cool.  In your "explanation" section, I'd suggest writing the constants in hex.

Zsh, 46 bytes
i=$1
repeat 4 printf %02x $[j=i%256,i=i/256,j]

Try it online!

x86 32-bit machine code, 24 21 bytes
changelog: -3 bytes: replace standard add/cmp/jbe/add with a DAS hack by @peter ferrie
64-bit: still 24 bytes.  Long mode removed the DAS opcode.
16-bit mode: the default operand-size is 16-bit but the problem spec is inherently 32-bit.  Including hard-coded 8 hex digits.

Byte-reverse with bswap then manual int->hex in standard order (most-significant nibble first, writing hex digits to a char output buffer in ascending order.)  This avoids needing to unroll the loop to switch order between nibbles within a byte vs. across bytes.
Callable as void lehex(char buf[8] /*edi*/, uint32_t x /*esi*/); like x86-64 System V, except this doesn't work in 64-bit mode.  (It needs the output pointer in EDI for stosb.  The input number can be in any register other than ECX or EAX.)
     1                             lehex:
     2 00000000 0FCE                   bswap  esi
     3 00000002 6A08                   push   8            ; 8 hex digits
     4 00000004 59                     pop    ecx
     5                             .loop:                ;do{
     6 00000005 C1C604                 rol    esi, 4       ; rotate high nibble to the bottom
     7
     8 00000008 89F0                   mov    eax, esi
     9 0000000A 240F                   and    al, 0x0f     ; isolate low nibble
    10 0000000C 3C0A                   cmp al, 10          ; set CF according to digit <= 9
    11 0000000E 1C69                   sbb al, 0x69        ; read CF, set CF and conditionally set AF
    12 00000010 2F                     das                 ; magic, which happens to work
    13
    14 00000011 AA                     stosb               ; *edi++ = al
    15 00000012 E2F1                   loop  .loop       ; }while(--ecx)
    16
    17 00000014 C3                     ret

size = 0x15 = 21 bytes.
TIO FASM 32-bit x86 test case with an asm caller that uses a write system call to write the output after calling it twice to append 2 strings into a buffer.  Tests all hex digits 0..F, including 9 and A at the boundary between numeral vs. letter.
The DAS hack - x86 has a half-carry flag, for carry out of the low nibble.  Useful for packed-BCD stuff like the DAS instruction, intended for use after subtracting two 2-digit BCD integers.  With the low nibble of AL being outside the 0-9 range, we're definitely abusing it here.
Notice the if (old_AL > 99H) or (old_CF = 1) THEN  AL ← AL − 60H; part of the Operation section in the manual; sbb always sets CF here so that part always happens.  That and the ASCII range for upper-case letters is what motivates the choice of sbb al, 0x69

cmp 0xD, 0xA doesn't set CF
sbb 0xD - 0x69 wraps to AL=0xA4 as input to DAS. (And sets CF, clears AF)
no AL -= 6 in the first part of DAS (because 4 > 9 is false and AF=0)
AL -= 0x60 in the second part, leaving 0x44, the ASCII code for 'D'

vs. a numeral:

cmp 0x3, 0xA sets CF
sbb 3 - 0x69 - 1 = AL = 0x99 and sets CF and AF
AL -= 6 in the first part of DAS (9 > 9 is false but AF is set), leaving 0x93
AL -= 0x60 in the second part, leaving 0x33, the ASCII code for '3'.

Subtracting 0x6a in SBB will set AF for every digit <= 9 so all the numerals follow the same logic.  And leave it cleared for every alphabetic hex digit.  i.e. correctly exploiting the 9 / A split handling of DAS.

Normally (for performance) you'd use a lookup table for a scalar loop, or possibly a branchless 2x lea and cmp/cmov conditional add.  But 2-byte al, imm8 instructions are a big win for code-size.

x86-64 version version: just the part that's different, between and al, 0xf and stosb.
;; x86-64 int -> hex  in 8 bytes
    10 0000000C 0430                   add    al, '0'
    11 0000000E 3C39                   cmp    al, '9'
    12 00000010 7602                   jbe  .digit
    13 00000012 0427                     add    al, 'a'-10 - '0'     ; al =  al>9 ? al+'a'-10 : al+'0'
    14                             .digit:

Notice that the add al, '0' always runs, and the conditional add only adds the difference between 'a'-10 and '0', to make it just an if instead of if/else.
Tested and works, using the same main caller as my C answer, which uses char buf[8] and printf("%.8s\n", buf).

can you create online-working snippet in e.g. here ?

@KamilKiełczewski: TIO makes it impossible (AFAIK) to write the caller in C to test an asm function so I often don't bother, but sure since you asked and sys_write can output fixed-length strings easily.  Oh interesting, I hadn't realized FASM on TIO let you create 32-bit executables, unlike with NASM where it doesn't respect -felf32.  I prefer x86-64 anyway, and this answer doesn't save any bytes from 32-bit code.

⭐ - you get star for nice answer

Currently the shortest answer in a non-golfing language. :)

You could just call C from this (strtoll) and it could very well be shorter.

@JL2210: Do you mean sprintf?  I don't think libc has any handy int->string functions other than format-string based ones, only string->int like strtoul.  But yes, bswap / printf would probably be shorter, if you can figure out some way to count bytes for the GOT entry for a function in a dynamic library (besides the 6-byte call [rel printf wrt ..got] call site); a minimal statically linked executables can be significantly smaller than dynamic, at least when made by ld with normal defaults.  But I don't think it would be reasonable to statically link it but not count its code size.

@JL2210: Remember, this is an x86 machine code answer, not asm text source size.  I haven't used libc functions in previous machine-code answers, only Linux system calls (e.g. in Fibonacci), and IDK how I'd go about counting the cost or whether I even want to write machine-code-with-libc answers.  There are use-cases for x86 machine code where a libc isn't available, e.g. in a bootloader.

you can cut three bytes by replacing "add/cmp/jbe/add" with "cmp al, 0ah / sbb al, 69h / das"

@peterferrie: Interesting, thanks.  DAS isn't available in 64-bit mode, but it works for other modes.  It took me a while to understand and write up a proper explanation for how your idea worked!

Love the DAS hack. You can also do "add al, 0x90 / daa / adc al, 040 / daa" (though it's one byte longer than the peter ferrie method). TIO link

I believe you forgot to delete the "no" from the numeric case "no AL -= 6 in the first part of DAS (9 > 9 is false but AF is set), leaving 0x93" ... that looks like a yes to me :)

@Jester: Yes, thanks.  Fixed.

Red, 37 bytes
func[x][reverse/skip form to-hex x 2]

This breaks TIO because of the outdated compiler it uses.
Red, 43 bytes
func[x][load next mold reverse to-binary x]

Try it online!

C (gcc), 30 bytes
f(x){printf("%.8x",htonl(x));}

Try it online!

when run on a big-endian machine, this won't convert to little-endian?

@peterferrie See revision 3.

@peterferrie: Correct.  Code Golf answers have to work on at least one implementation of the language, not all.  rev 3 used __builtin_bswap32 for portability.

Japt -P, 10 bytes
sG ùT8 ò w

Try it
sG ùT8 ò w     :Implicit input of integer
s              :Convert to string
 G             :  In base-16
   ù           :Left pad
    T          :  With 0
     8         :  To length 8
       ò       :Split into 2s
         w     :Reverse
               :Implicitly join and output

What does -P do?

your answer is in the top (can you add explanation?)

@JL2210 From the docs: "-P: If the output is an array, outputs with no separator (i.e. joined with P).". So the flag is for an implicit instead of explicit join to save bytes. :)

@KamilKiełczewski, explanation added.

x86 SIMD machine code (AVX512-VBMI), 36 bytes
(16 bytes of which are a hex lookup table)
This is a function that takes an integer in xmm0 and returns 8 bytes of ASCII char data in xmm0, for the caller to store wherever it wants.  (e.g. to video memory after interleaving with attribute bytes, or into a string under construction, or whatever)
From C, call it as __m128i retval = lehex(_mm_cvtsi32_si128(x)) with the x86-64 System V calling convention, or MS Windows vectorcall.
# disassembly with machine-code bytes (the answer) and NASM source code.
0000000000401000 <lehex>:
  401000:       c5 f1 72 d0 04          vpsrld      xmm1, xmm0, 4         ; AVX1
  401005:       c5 f1 60 c8             vpunpcklbw  xmm1, xmm1, xmm0      ; AVX1
  401009:    62 f2 75 08 8d 05 01 00 00 00 vpermb  xmm0, xmm1, [rel .hex_lut]
  401013:       c3                      ret

0000000000401014 <lehex.hex_lut>:
  401014:     30 31 ...  61 62 ...     .hex_lut:  db "0123456789abcdef"

Total = 0x24 = 36 bytes.
See How to convert a number to hex? on SO for how this works.  (SSE2 for the shift / punpck, then vpermb saves work that we'd need for pshufb.  AVX1 instead of SSE2/SSSE3 also avoids a movaps register copy.)
Notice that punpcklbw with the source operands in that order will give us the most-significant nibble of the low input byte in the lowest byte element, then the least-significant nibble of the lowest source byte.  (In that SO answer, a bswap is used on the input to get a result in standard printing order with only SSE2.  But here we want that order: high nibble in lower element within each byte, but still little-endian byte order).
If we had more data constants, we could save addressing-mode space by doing one mov edx, imm32 then using [rdx+16] or whatever addressing modes.  Or vpbroadcastb xmm0, [rdx+1].
But I think a 16-byte hex LUT + vpermb is still better than implementing the n>9 : n+'a'-10 : n+'0' condition: that requires 3 constants and at least 3 instructions with AVX512BW byte-masking (compare into mask, vpaddb, merge-masked vpaddb), or more with AVX1 or SSE2.  (See How to convert a number to hex? on SO for an SSE2 version of that).  And each AVX512BW instruction is at least 6 bytes long (4-byte EVEX + opcode + modrm), longer with a displacement in the addressing mode.
Actually it would take at least 4 instructions because we need to clear high garbage with andps, (or EVEX vpandd with a 4-byte broadcast memory operand) before the compare.  And each of those needs a different vector constant.  AVX512 has broadcast memory operands, but only for elements of 32-bit and wider.  e.g. EVEX vpaddb's last operand is only xmm3/m128, not xmm3/m128/m8bcst.  (Intel's load ports can only do 32 and 64-bit broadcasts for free as part of a load uop so Intel designed AVX512BW to reflect that and not be able to encode byte or word broadcast memory operands at all, instead of giving them the option to do dword broadcasts so you can still compress your constants to 4 bytes :/.)
The reason I used AVX512VBMI vpermb instead of SSSE3 / AVX1 pshufb is twofold:

vpermb ignores high bits of the selectors.  (v)pshufb zeros bytes according to the high bit of the control vector and would have needed an extra pand or andps to actually isolate nibbles.  With XMM / 16-byte size, vpermb only looks at the low 4 bits of the shuffle-control elements, i.e. bits [3:0] in Intel's notation in the Operation section.
vpermb can take the data to be shuffled (the lookup table) as a memory operand.  (v)pshufb's xmm/mem operand is the shuffle-control vector.

Note that AVX512VBMI is only available on CannonLake / Ice Lake so you probably need a simulator to test this, like Intel's SDE.

⭐ - you get star for nice answer

@KamilKiełczewski: lol thanks.  Converting numbers to hex efficiently is one of my favourite things.  It's a nice use-case for several neat tricks and bit-manipulation.

Python 2, 43 bytes
lambda n:[("%08x"%n)[i^6]for i in range(8)]

Try it online!
-4 bytes thanks to benrg
Outputs a list of characters. Computed by retrieving, in order, the hex digits of the input at indices 6, 7, 4, 5, 2, 3, 0, 1.

[i^6]for i in range(8) saves a few bytes.

Is it allowed to output list instead of string?

output as list is not really fit for the spirit of the question imo

C (gcc) endian agnostic, no standard libs, 92 91 bytes
h(n) is a single-digit integer->hex helper function.
f(x,p) takes an integer and a char[8] pointer.  The result is 8 bytes of char data.  (Not 0-terminated unless the caller does that.)
Assumptions: ASCII character set.  2's complement int so right shift eventually brings down the sign bit, and converting a uint32_t to int doesn't munge the bit-pattern if the high bit is set.  int is at least 32-bit.  (Wider might let it work on 1's complement or sign-magnitude C implementations).
Non-assumptions: anything about implementation byte-order or signedness of char.
i;h(n){n&=15;return n>9?n+87:n+48;}f(x,p)char*p;{for(i=5;--i;x>>=8)*p++=h(x>>4),*p++=h(x);}

Try it online!  including test caller using printf("%.8s\n", buf) to print output buffer without 0-terminating it.
Ungolfed:
int h(n){n&=15;return n>9 ? n+'a'-10 : n+'0';}      // single digit integer -> hex

int i;
void ungolfed_f(x,p)char*p;{
    for(i=5; --i; x>>=8)   // LS byte first across bytes
        *p++=h(x>>4),      // MS nibble first within bytes
        *p++=h(x);
}

Doing n&=15; inside h(x) is break-even; 6 bytes there vs. 3 each for &15 to isolate the low nibble at both call sites.
, is a sequence point (or equivalent in modern terminology) so it's safe to do *p++= stuff twice in one statement when separated by the , operator.
>> on signed integer is implementation-defined as either arithmetic or logical.  GNU C defines it as arithmetic 2's complement.  But on any 2's complement machine it doesn't really matter because we never look at the shifted-in 0s or copies of the sign bit.  The original MSB will eventually get down into the low byte unchanged.  This is not the case on sign/magnitude, and I'm not sure about 1's complement.
So this may only be portable to 2's complement C implementations.  (Or where int is wider than 32 bits so bit 31 is just part of the magnitude.)  unsigned -> signed conversion also munges the bit-pattern for negative integers, so &15 on an int would only extract nibbles of the original unsigned value on 2's complement.  Again, unless int was wider than 32-bit so all inputs are non-negative.
The golfed version has UB from falling off the end of a non-void function.  Not to return a value, just to avoid declaring it void instead of default int.  Modern compilers will break this with optimization enabled.

Motivation: I was considering an x86 or ARM Thumb asm answer, thought it might be fun to do it manually in C, maybe for compiler-generated asm as a starting point.  See https://stackoverflow.com/questions/53823756/how-to-convert-a-number-to-hex for speed-efficient x86 asm, including an AVX512VBMI version that's only 2 instructions (but needs control vectors for vpmultishiftqb and vpshufb so wouldn't be great for golf).  Normally it takes extra work for SIMD to byte-reverse into printing order on little-endian x86 so this byte-reversed hex output is actually easier than normal.

Other ideas
I considered taking the integer by reference and looping over its bytes with char*, on a little-endian C implementation (like x86 or ARM).  But I don't think that would have saved much.
Using sprintf to do 1 byte at a time, 64 bytes after golfing:
int i;
void f(x,p)char*p;{
        for(i=4;sprintf(p,"%.2x",x&255),--i;x>>=8)
                p+=2;
}

But if we're using printf-like functions we might as well byte-swap and do a %x printf of the whole thing like @JL2210's answer.

⭐ - you get star for nice answer

Scala, 58 40 36 bytes
"%08X"format Integer.reverseBytes(_)

Try it online!
Still uses the builtin to reverse the bytes of an Int, but uses format to format the Int as a Hex. No need to call toHexString.
Removed the parens on format. This now means that the argument can be taken implicitly using _.

Forth (gforth), 52 51 40 bytes
: f hex 0 4. do <# # # 0. #> type loop ;

Try it online!
Code explanation
: f           \ start a new word definition
  hex         \ set the current base to base 16
  0           \ convert the input number to a double-cell integer
  4. do       \ start a counted loop from 0 to 3
    <# # #    \ start a formatted numeric string and move last 2 digits to format area
    0.        \ move remaining digits down the stack
    #>        \ delete top two stack value and convert format area to string
    type      \ output string
  loop        \ end loop
;             \ end word definition

APL+WIN, 36 34 bytes
2 bytes saved by converting to index zero
Prompts for integer:
'0123456789abcdef'[,⊖4 2⍴(8⍴16)⊤⎕]

Try it online! Courtesy Dyalog Classic

Jelly, 13 bytes
+Ø%b⁴Ḋs2Ṛ‘ịØh

Try it online!
A full program that takes an integer as its argument and prints a string.

your answer is in the top

J, 10 bytes
8{._1{3!:3

Try it online!
how
3!:3 is a J "foreign conjunction" for hex representation, documented here.  That is, it's a builtin for converting to hex.  However, it's output it not quite what we want. Eg, running:
3!:3 (304767)

produces:
e300000000000000
0400000000000000
0100000000000000
0000000000000000
7fa6040000000000

The meaning of the other lines is explained on the doc page I linked to above.  In any case, it's clear we want the first 8 chars of the last line.
_1{ get the last line.
8{. gets the first 8 characters of it.

your answer is in the top

Excel, 91 bytes
=RIGHT(DEC2HEX(A1,8),2)&MID(DEC2HEX(A1,8),5,2)&MID(DEC2HEX(A1,8),3,2)&LEFT(DEC2HEX(A1,8),2)

K4, 12 11 bytes
Solution:
,/$|4_0x0\:

Examples:
q)k),/$|4_0x0\:304767
"7fa60400"
q)0W
"0004a67f"

Explanation:
Pretty much exactly what the question asks:
,/$|4_0x0\: / the solution
      0x0\: / split to bytes
    4_      / drop first 4 bytes
   |        / reverse
  $         / convert to string
,/          / flatten

Notes:

-1 byte as K4 numbers are longs (64bit) by default, so dropping 4 bytes (32bits)

your answer is in the top

PHP, 31 bytes
<?=unpack(H8,pack(V,$argn))[1];

Try it online!
Taking advantage of PHP's pack and unpack, I pack the unsigned input with "32 bit little endian byte order" format (V) into a binary string and then unpack it with "hex string, high nibble first" format (H) and print the result.
This seems to be one of the rare cases where PHP's built-ins are actually shorter than implementing a simple algorithm!

PHP's pack()/unpack() functions are awesome for the 0 times you ever need them in most PHP projects. Congrats, you found their use!

Charcoal, 11 bytes
⪫⮌⪪﹪%08xＮ²ω

Try it online! Link is to verbose version of code. Explanation:
        Ｎ   Input as a number
   ﹪%08x    Format using literal string
  ⪪      ²  Split into pairs of characters
 ⮌          Reverse
⪫         ω Join
            Implicitly print

19 bytes without resorting to Python formatting:
⪫…⮌⪪⍘⁺Ｘ²¦³⁶Ｎ¹⁶¦²¦⁴ω

Try it online! Link is to verbose version of code. Explanation:
           Ｎ        Input as a number
     ⁺              Plus
       ²            Literal 2
      Ｘ             To power
         ³⁶         Literal 36
    ⍘               Convert to base
            ¹⁶      Literal 16
   ⪪           ²    Split into pairs of digits
  ⮌                 Reverse the list
 …               ⁴  Take the first 4 pairs
⪫                 ω Join together
                    Implicitly print

your answer is in the top

Perl 5 (-p), 22 bytes
$_=unpack H8,pack V,$_

Try it online!

Ruby, 31 27 bytes
Ended up being a port of Night2's PHP answer because Ruby has the same pack/unpack functionality.
->*i{i.pack(?V).unpack'H8'}

Try it online!
My original 31-byte answer that didn't take advantage of the H8 unpack mode because I didn't know about it:
->*i{'%02x'*4%i.pack(?V).bytes}

Try it online!

Windows Batch, 90 bytes
@for /l %%x in (24,-8,0)do @set/aa=%1^>^>%%x^&255&cmd/cexit !a!&<nul set/p=!=exitcode:~-2!
Run the command-line with /v to enable the delayed expansion.

Rust, 34 bytes
|n|print!("{:08x}",n.swap_bytes())

Try it online!
Rust has built-in hex formatting, but it displays in big-endian format, so I reversed the byte order first. Capitalize the x if you want uppercase hex digits instead of lowercase ones.

Python 3.11+, 34 bytes
lambda n:n.to_bytes(4)[::-1].hex()

This is a version of Joel's Python 3 solution that works only on Python 3.11 and higher. Pre-3.11, the byteorder argument to int.to_bytes/int.from_bytes was mandatory; in 3.11 it is now defaulted to 'big', so, golf-wise, you can omit it, let to_bytes produce the big-endian version, then reverse it with a slice, saving three characters.
(Side-note: The Attempt This Online link actually cheats and just uses Joel's solution when the Python version is below 3.11; ATO is still on 3.10.6 so it can't run this code as of April, 2023)
Attempt This Online!


text:
Test the endianness
Given a UTF-16 string, test its endianness.
Rules:

As long as the input is in UTF-16 without BOM, its type doesn't matter. In C++ on Windows, it can be std::wstring or std::u16string. In Haskell, it can be [Int16] or [Word16].
The endianness is tested by noncharacters. If the input contains a noncharacter, it is in wrong endianness.
If the original version and the endianness-swapped version both or neither contain a noncharacter, the test is inconclusive.
The type of the output must be well-ordered. Output 1 (or an equivalent enumerator) when the input is in right endianness, or -1 (or an equivalent enumerator) when the input must be endianness-swapped, or 0 (or an equivalent enumerator) when the test is inconclusive. For example, in Haskell, Ordering is a valid output type.
Wrong UTF-16 sequences are also treated as noncharacters. (So the noncharacters are: Encodings of code point from U+FDD0 to U+FDEF, encodings of code point U+XXFFFE and U+XXFFFF with XX from 00 to 10, and unpaired surrogates.)
As this is a code golf, the shortest code in bytes wins.

Examples:
Assume we're in Haskell, the system is a big-endian, and Ordering is the output type. When given the following byte sequence:
00 00 DB FF DF FE

Because it encodes the noncharacter U+10FFFE, the output must be:
LT

For the following byte sequence:
00 00 00 00 00 00

The output must be:
EQ

For the following byte sequence:
FE FF

Since the endianness-swapped version encodes the noncharacter U+FFFE, the output must be:
GT

@JoKing We output 0 when the test is inconclusive (see Rule #3). A non-UTF character is treated as a noncharacter also in the flipped version (see Rule #5).

Some more test cases would be good

You should include a description of noncharacters and invalid UTF-16 sequences in your challenge, or at least point to the specification.

@nwellnhof I improved the question accordingly. Now vote for reopen, please?

How does 00 00 DB FF DF FE encode U+10FFFE? I don't see 10 FF FE.

Late reply, but that is a surrogate pair.

ARM Thumb-2, 108 90 84 bytes
Machine code:
b5f2 2300 f000 f822 9900 000a 3a02 5a84
ba64 5284 d1fa 425b f000 f818 bdf2 5a44
f64f 56d0 1ba7 2f20 d313 0ae7 2f1b d10a
b179 3902 0ae7 d30c 5a42 0a97 2f36 d108
3209 eb04 2482 b227 3702 d202 3902 d5e6
3b01 4770

Commented assembly:
        .syntax unified
        .arch armv6t2
        .text
        .thumb
        .globl check_utf16
        .thumb_func
        // r0: string, r1: len in BYTES
        // The string will be clobbered as an internal buffer.
        // Returns in r3.
check_utf16:
        push    {r1, r4, r7, lr}
        // Set starting return value to 0. This will accumulate both results.
        movs    r3, #0
        // First, check little endian.
        // Yes, I did bl to the middle of a function. :P
        bl      .Ltest.entry
        // Reload the length, as test clobbered it.
        ldr     r1, [sp]
        // Byteswap the string.
        movs    r2, r1
.Lbswap_loop:
        // Looping backwards...
        subs    r2, #2
        // Load a halfword to r4,
        ldrh    r4, [r0, r2]
        // do a 16-bit byteswap,
        rev16   r4, r4
        // and store it back.
        strh    r4, [r0, r2]
        bne     .Lbswap_loop
.Lbswap_loop.end:
        // Negate r3 to make the start return value from native endianness positive.
        // Then, we subtract the big endian version from this to get the -1/0/1 result.
        negs    r3, r3
        // and call test again to check big endian
        bl      .Ltest.entry
        pop     {r1, r4, r7, pc}

.Ltest_loop:
        // Read the next character
        ldrh    r4, [r0, r1]
        // Check for FDD0-FDEF.
        // First we subtract 0xFDD0...
        movw    r2, #0xFDD0
        subs    r7, r4, r2
        // ...and if it is (unsigned) less than 0x20, it is
        // bad. Return false.
        cmp     r7, #0x20
        blo     .Lfalse

        // Is it a surrogate?
        // Equivalent to (r4 & 0xF800) != 0xD800
        lsrs    r7, r4, #11
        cmp     r7, #0xD800 >> 11
        bne     .Lnot_surrogate

        // NOTE: We are looping backwards, that is why we check
        // trail surrogates first.
.Lis_surrogate:
        // Beginning of string == unpaired surrogate == bad
        cbz     r1, .Lfalse
        // Decrement r1
        subs    r1, #2

        // Is it a trail surrogate? We already know it is
        // a surrogate, so we only check the trail bit.
        // Uses lsrs's carry flag to test the 10th bit.
        // Equivalent to (r4 & 0x400) == 0
        lsrs    r7, r4, #11
        bcc     .Lfalse

        // Load the preceeding (hopefully) lead surrogate to r2.
        ldrh    r2, [r0, r1]
        // Is it a lead surrogate?
        // Equivalent to (r2 & 0xFC00) != 0xD800
        lsrs    r7, r2, #10
        cmp     r7, #0xD800 >> 10
        bne     .Lfalse

        // We have two surrogates, let's merge them into a
        // full codepoint.
        //
        // Just kidding. We only need the low 16 bits, so we can take
        // a huge shortcut and let sxth correct any overflow.
        //
        // utfcpp showed us that converting a UTF-16 pair to UTF-32
        // is simply this:
        //     0xfca02400 + trail + (lead << 10)
        // where 0xfca02400 is the constant fold of this:
        //     0x10000 - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN
        //
        // Since we are only using 16 bits, we can just add 0x2400
        // instead. That saves 4 bytes, as we can do a wide add.
        //
        // HOWEVER, we can do even better: 0x2400 has the low 10 bits
        // clear, and since we need to shift the lead surrogate 10
        // bits to the left, we can just add 0x2400 >> 10 (or 0x09)
        // to the lead surrogate, then do trail + (lead << 10).
        //
        // This means that instead of generating a 32-bit constant
        // into a register, we can use the immediate narrow form of
        // adds, saving 6 bytes (4 for literal, 2 for ldr).
        adds    r2, #0x2400 >> 10
        add.w   r4, r4, r2, lsl #10
.Lnot_surrogate:
        // At this point, r4 contains the low 16 bits of the
        // codepoint, and the upper bits are garbage.

        // Check for xxFFFE/F by sign extending and adding 2.
        // If it was, there will be a carry.
        // The act of sign extending eliminates all of those
        // garbage bits for us, allowing laziness in the surrogate
        // code.
        sxth    r7, r4
        adds    r7, #2
        bcs     .Lfalse

        .thumb_func
        // We actually bl here, so we can subtract first
        // on the first iteration.
        // The possibilities of assembly are endless.
.Ltest.entry:
        // Loop while we still have data.
        subs    r1, #2
        bpl     .Ltest_loop
.Ltrue:
        // Subtract 1 for true. This is negated for native endianness, and it
        // cancels out on both true.
        subs    r3, #1
.Lfalse:
        // return
        bx      lr

Test suite:
        .syntax unified
        .arch armv6t2
        .thumb
        // W+X because PIE sucks.
        .section ".writeable_text","awx",%progbits

.macro $TEST expected:req, argc:req, argv:vararg
        // Load string buffer into r0
        adr     r0, 1f
        // Convert element count to size in bytes by doubling.
        movs    r1, #\argc * 2
        // Skip over our constant pool
        b       3f
1:
        // The UTF-16 string
        .short \argv
        .align 2
2:
        // blatant abuse of macro stringification to avoid a printf loop :P
        .asciz "\argv"
        .align 2
3:
        // Call check_utf16
        bl      check_utf16
        // Stringified version of the UTF-16 string
        adr     r1, 2b
        // Expected
        movs    r2, #\expected
        // r3 is already in place
        adr     r0, .Lprintf_str
        // printf("{ %s } -> expected: %d, got: %d\n", STR(arr), expected, retval)
        bl      printf
.endm

        .globl main
        .thumb_func
main:
        push    {r4, lr}
        // Original test cases
        $TEST   -1, 3, 0x0000, 0xDBFF, 0xDFFE
        $TEST    0, 3, 0x0000, 0x0000, 0x0000
        $TEST    1, 1, 0xFEFF

        // I've added more test cases, feel free to take them
        // 1: D3FD becomes FDD3 when swapped, which is bad
        $TEST    1, 3, 0xD3FD, 0xD83D, 0xDE0F
        // 0: proper string with surrogates both ways
        $TEST    0, 3, 0x0A00, 0xD83D, 0xDE0F
        // -1: DF10 is a lone trail surrogate
        $TEST   -1, 1, 0xDF10
        // 1: D9E0 is a lone head surrogate
        $TEST    1, 1, 0xE0D9
        // 0: 0xffff is invalid in both endiannesses
        $TEST    0, 2, 0x0314, 0xFFFF
        pop     {r4, pc}
.Lprintf_str:
        .asciz "{ %s } -> expected: %d, got: %d\n"

Try it online! (sorta)
Has the following pseudo-signature:
int check_utf16(uint16_t *ptr, size_t length_in_bytes);

However, it is NOT C-callable, it returns in r3 instead of r0.
Returns -1 if we need an endian swap, 0 if ambiguous, or 1 if we don't need an endian swap.
lsrs is the real MVP here. (☞^o^) ☞
Specifically, lsrs/lsls can do most usages of ands without setting up a constant or using a wide instruction. All of the "masking" operations can just be done by shifting right. This also lets us use a narrow cmp, as narrow cmp can only check 0-255.
Additionally, I do a really dirty trick here: I only calculate the low 16 bits of a surrogate pair codepoint.
The optimized UTF-16 to UTF-32 conversion algorithm is this (magic number explained in comments):
uint32_t codepoint = 0xfca02400 + trail + (lead << 10);

However, 0xfca02400 is a 6 byte constant, 2 bytes for ldr and 4 bytes for the literal pool.
One thing to note is that I immediately discard the upper 16 bits of the codepoint by sign extending. Therefore, we only need to add the low 16 bits of the magic number, 0x2400.
int16_t codepoint = 0x2400 + trail + (lead << 10);

This is much better, as we can do an immediate add.w instruction, saving 4 bytes.
However, 0x2400 has 10 trailing zero bits: it is simply 9 << 10.
Therefore, we can do another optimization with the distributive property:
int16_t codepoint = trail + ((lead + (0x2400 >> 10)) << 10);
// int16_t codepoint = trail + ((lead + 9) << 10);

That is even better: we no longer need add.w, 9 fits perfectly into an immediate narrow adds, saving a total of 6 bytes!


text:
Print the sequence
21, 21, 23, 20, 5, 25, 31, 24, ?
Inspired by this Puzzle, given an integer \$n>0\$ , print out the following sequence until you reach a non-Integer (spoilered, in case you want to solve the puzzle yourself first)

 \$a_0 = n\$
\$a_{4k+1} = a_{4k} \cdot(4k+1) \$
\$a_{4k+2} = a_{4k+1} + (4k+2)\$
\$a_{4k+3} = a_{4k+2} - (4k+3)\$
\$a_{4k+4} = a_{4k+3} / (4k+4)\$

 or more intuitively: *1, +2, -3, /4, *5, +6, -7, /8, ...

TestCases:

1: 1, 1, 3, 0, 0, 0, 6, -1
2: 2, 2, 4, 1
3: 3, 3, 5, 2
4: 4, 4, 6, 3
5: 5, 5, 7, 4, 1, 5, 11, 4
6: 6, 6, 8, 5
9: 9, 9, 11, 8, 2, 10, 16, 9
21: 21, 21, 23, 20, 5, 25, 31, 24, 3, 27, 37, 26

Input and Output may be taken in any reasonable format, standard loopholes are as forbidden as usual.
In the spirit of code-golf, the shortest answer in byte wins!
Sandbox: https://codegolf.meta.stackexchange.com/a/18142/59642

May we instead return an infinite list of the sequence? Also, is the output for 1 correct? I had something different after the 6.

@cole Since the sequence ends I don't think you can output an infinite list.

May we output 1 indexed, i.e. skip the first element?

No, the entire sequence must be printed.

May we print integers as floats? 1.0, 1.0, 2.0, 0.0, 0.0, 6.0, -1.0 etc

Yes, this has already been done

Can we output in groups of 4 (i.e. (21, 21, 23, 20)(5, 25, 31, 24)(3, 27, 37, 26))?

Yes you may @KevinCruijssen

Thanks for the accept but (assuming you're awarding it to the shortest solution by language), I'd rather it went to GB.

05AB1E (legacy), 18 17 bytes
[N"/*+-"Nè.VÐïÊ#=

Try it online or verify all test cases.
Explanation:
[                # Start an infinite loop:
 N               #  Push the 0-based loop-index
  "/*+-"         #  Push string "/*+-"
        Nè       #  Index into this string with the loop-index
          .V     #  And use a 05AB1E-eval to calculate the next number
 Ð               #  Triplicate this number
  ï              #  Cast it to an integer
   Ê             #  And if it's NOT equal to the number we triplicated:
    #            #   Stop the infinite loop
  =              #  Print the number without popping

I'm using the legacy version of 05AB1E here, and also first calculate the next number before printing it, because the loop is 0-based and it will do a /0 in the very first iteration. This saved a byte in comparison to the previous N> and "*+-/". This only works, because in the legacy version a number that's being divided by 0 remains the same; whereas in the new version it would become 0; and in actual math it would give a division by zero error.

Scratch 3.0 39 blocks/323 bytes

Try it online scratch!
Alternatively, as SB syntax:
when gf clicked
delete[all v]of[o v
ask()and wait
set[. v]to(answer
set[n v]to(1
repeat until<(n)contains[.
if<((n)mod(4))=(0
set[. v]to((. )*(n
else
if<((n)mod(4))=(1
change[. v]by(n
else
if<((n)mod(4))=(2
change[. v]by((0)-(n
else
set[. v]to((. )/(n
end
end
end
add(n)to[o v
change[n v]by(1
end
delete(length of(o))of[o v

Look at you guys, having fun with your fancy eval statements! Well, not me! No... Scratch doesn't have evals, so I had to do things the hard way... if statements.
At least it isn't gotos...

Look at you, having fun with if statements and float division! Well, not me! No... Whitespace doesn't have evals, if-statement, or float-division, so I had to do things the hard way... gotos and a subtraction loop to verify if we can divide, in a stack-based language. ;p (In all seriousness, nice answer, +1 from me! I just couldn't resist quoting you in my just finished Whitespace answer.)

Haskell, 75 74 73 bytes
-1 byte thanks to Will Ness
-1 byte thanks to nimi
(#1)
n#i|i`mod`4<1,n`mod`i>0=[n]|y<-i+1=n:(x!!i)n i#y
x=div:(*):(+):(-):x

Try it online!
Avoids the use of fractional ints to save on bytes

1 less.

1 less

Whitespace, 251 227 202 bytes
[S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][T   N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input][N
S S N
_Create_Label_LOOP][S N
S _Duplicate_top][T N
S T _Print_as_integer][S S S T  S T S N
_Push_10_newline][T N
S S _Print_as_character][S N
T   _Swap_top_two][S S S T  N
_Push_1][T  S S S _Add][S T S S T   N
_Copy_2nd_item][S T S S T   N
_Copy_2nd_item][S N
S _Duplicate_top][S S S T   S S N
_Push_4][T  S T T   _Modulo][S N
S _Duplicate_top][N
T   S S N
_If_0_Jump_to_Label_DIVIDE][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate_top][N
T   S T N
_If_0_Jump_to_Label_MULTIPLY][S S S T   N
_Push_1][T  S S T   _Subtract][N
T   S S S N
_If_0_Jump_to_Label_ADD][S N
T   _Swap_top_two][S T  S S T   N
_Copy_2nd_item][T   S S T   _Subtract][N
S N
N
_Jump_to_LOOP][N
S S S N
_Create_Label_DIVIDE][S N
N
_Discard_top][T S T S _Divide][S T  S S T   S N
_Copy_3nd_item][S T S S T   S N
_Copy_3nd_item][T   S T T   _Modulo][N
T   S N
_If_0_Jump_to_Label_LOOP][N
N
N
_Exit_Program][N
S S T   N
_Create_Label_MULTIPLY][S N
N
_Discard_top][T S S N
_Multiply][N
S N
N
_Jump_to_Label_LOOP][N
S S S S N
_Create_Label_ADD][T    S S S _Add][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
-24 bytes after a comment of @JoKing suggesting n%i > 0. Although only if(x < 0) and if(x == 0) are available in Whitespace, simply checking if(x*-1 < 0) is basically the same as if(x > 0).
An additional -25 bytes thanks to @JoKing.
Explanation:
Quote from the Scratch answer:

At least it isn't gotos...

Did someone say goto? Whitespace has nothing else than goto to create both loops and if-statements. xD In addition it's a stack-based language, so I have to swap/discard/copy pretty often. And to top things off: Whitespace doesn't even have floating points and only integer-division, so I've used n % i * -1 < 0 to exit the program if the integer cannot divide the current number.
Pseudo-code:
Integer n = STDIN as input
Integer i = 0
Label LOOP:
  Print n as number
  i = i + 1
  Integer t = i % 4
  If(t == 0):
    Jump to Label DIVIDE
  t = t - 1
  If(t == 0):
    Jump to Label MULTIPLY
  t = t - 1
  If(t == 0):
    Jump to Label ADD
  n = n - i
  Jump to Label LOOP
Label DIVIDE:
  n = n / i
  Integer m = n % i
  If(m == 0):
    Jump to Label LOOP
  Exit program
Label MULTIPLY:
  n = n * i
  Jump to Label LOOP
Label ADD:
  n = n + i
  Jump to Label LOOP

You absolute genius. Have my upvote!

@JoKing Whitespace only has if(n == 0) or if(n < 0) available. Unfortunately no if(n > 0) or if(n != 0). But I'm sure some aspects can be simplified. This current solution was a trial-and-error of debugging, but maybe I should just take a step back and rethink a shorter approach. When I have time again. And fixed the pseudo-code, you were indeed right I switched i/n at most places..

@JoKing I'm an idiot.. >.> I could just add a * -1 and then use the x < 0 check. Thanks for -24 bytes. Pretty ironic I can think more straight late in the evening than when I am at work.. ;)

@JoKing Thanks, both those suggestions saved bytes. The first suggestion is -7, and the second -18. :)

JavaScript (V8), 52 bytes
Prints groups of 4 terms. Inspired by GB's Ruby answer.
n=>{for(k=0;n%1==0;n/=k+=3)print(n,n*=++k,n-~k,--n)}

Try it online!

JavaScript (V8), 54 bytes
Prints the terms of the sequence.
n=>{for(k=0;n%1==0;n=eval(n+'*+-/'[k++&3]+k))print(n)}

Try it online!

JavaScript (ES6),  59  58 bytes
Returns an array.
f=(n,k)=>k&&(n=eval(n+'/*+-'[k&3]+k))%1?[]:[n,...f(n,-~k)]

Try it online!

Piet, 297 190 144 codels (432 bytes)

Tried a new approach using a pointer command as switch(k mod 4) to unify the output code, resulting in a denser 10x19 code picture. Then I golfed that down by 1 row and 2 collumns to 8x18.
Here is a trace, to see how it works:

The first line pushes a 0 on the stack as starting index (since we can only push natural numbers, we push 2 ones and then substract), then reads the input as number.
The leftmost collumn has the shared code of duplicating the number and popping one into output, then moving the index on top of the stack, incrementing it and then duplicating it thrice. We then enter the pastel red r-shaped block through the dark cyan codel for a pointer command which gives us different paths for the remainder of our index mod 4.
Mod 1, we exit through the top to multiply. We first shuffle a copy of our index down for later, then perform the multiplication. After passing through the white for a noop, we enter the collumn above to fix the cc parity (it needs to be flipped an even number of times to keep the loop stable), followed by a pointer (1) from entering the magenta bar: It acts as a catch for our four paths and send us back into the loop.
Mod 2, we exit backwards to sum. The shape of the pastel code block means we exit a row above from where we entered, and we use the 3 we push onto the stack by exiting through the red codel to pointer (3) ourselves upwards. This collumns has the white space before the arithmetic and a slightly different order of pushing and switching cc, because otherwise we would have colour overlap with integer-valued codels in the neighbouring collumn.
Mod 3 send us downwards for subtraction. Same deal as multiplication, except we cross over the division path on the way up (As the cc has differing parity when entering the pastel green bar, the two executions exit that bar at different ends). While doing so, we pick up an unwanted duplicate command, so we pop it back off with the dark green codel before entering the cc correction and collection bar.
Mod 4, we go straight ahead to divide. Here, we first have to re-shuffle the stack more severely to get two pairs of n and a to perform operations on, because we need to test if it's integer. We do that my doing mod on the first pair, then not on the result, then use that for a pointer - if it's not divisible, we keep going straight, which sends us with two pointer commands into the opposite corner into the inescapable block and thus ends program. Otherwise, we turn right and get a divide command from entering the magenta bar.
Old Version

Very straightforward code: Pushes a 1 and the input on the stack, then loops through the four operations by: Shuffling the index on top of the stack, incrementing it by 1, duplicating it, shuffling one copy back down, performing the arithmetic operation, duplicating the number and popping one into output.
For division, which is the only one where the sequence can end, it creates a more complicated stack to first check if n mod index == 0, otherwise it enters the inescapable codel and terminates. Otherwise, it uses its second copy of i and n to perform the division.

Would it be possible to mush the second and third row together? I.e., pivot the pink cell at (0,1) -> (1,2), shift the 3 cells in the middle down, and shrink the right column to a 1x2?

Not easily. I need 2 cells to execute the right turn, either for a push (1) pointer or for a black cell on top of a coloured one.

Perl 6, 44 bytes
{$_,{($_,<* + - />[$++%4]~++$).EVAL}...^*%1}

Try it online!
Anonymous code block that takes a number and returns a sequence. If we could skip the first element (which is always the same as the second element anyway), we could save 3 bytes by removing the $_,

Python 3, 60 bytes
f=lambda n,i=1:[]if n%1else[n]+f([n/i,n*i,n+i,n-i][i%4],i+1)

Try it online!

Ruby, 56 54 52 bytes
f=->n,z=1{n%1>0?[]:[n,n*=z,n-~z,n-=1]+f[n/=z+3,z+4]}

Try it online!
After some (failed) attempt with eval, I found out that the happiest solution is building the array with 4 elements at once, at least in ruby.
Thanks to Arnauld for -2 bytes.

53 bytes by porting back my last answer, which was inspired by yours.

52 bytes by using an improvement suggested by Shaggy that turned out to be just as long in JS but saves a byte in Ruby.

C# (Visual C# Interactive Compiler), 72, 70, 69 bytes
n=>{for(int i=1;n%1==0;n=new[]{n/i,n*i,n+i,n-i}[i++%4])Write(n+" ");}

Try it online!

59 bytes by porting Arnauld's first JavaScript function, which is a port of the Ruby answer. And yes, this output is allowed, just got confirmation from OP in the comments of the challenge.

@KevinCruijssen nice, I wouldn't have come up with that!

R, 90 bytes, 87 bytes 85 bytes 80 bytes 74 73 bytes
A plain implementation of the rules:
a=scan();while(T<13)a=c(a,d<-a[T]*T,d+T+1,e<-d-1,e/((T<-T+4)-1));a[!a%%1]

Try it online!
with the T<13 following from a deeper analysis of the puzzle. Indeed there are only three kinds of sequences: those of length 4, when a⁰ is not congruent to 1 modulo 8; those of length
12 when a⁰ is congruent to 21 modulo 32; and those of length 8 for the remaining cases.
An alternative code avoiding loops ends up being longer with 87 bytes:
`~`=rep;b=(scan()-1)*c(32~4,8,40~3,1,9~3)/32+c(1,1,3,0~3,6,-c(8,1,9,-71,17)/8);b[!b%%1]

Try it online!

You can remove the {} for -2 bytes.

74 bytes by avoiding length.

Haskell, 104 86 85 bytes
n#i=n:(cycle[(/),(*),(+),(-)]!!floor i)n i#(i+1)
takeWhile((==).ceiling<*>floor).(#1)

Try it online!
The h= can be omitted since it's only used for testing.
Ah, code golf, where a quadratic increase in time complexity is worth it for the reduction of one character.
104 bytes
f=flip
g x=scanl(f($))x.zipWith(f($))[1..].cycle$f<$>[(*),(+),(-),(/)]
takeWhile((==).ceiling<*>floor).g

Try it online!
I like this answer better, but alas it is longer.

Japt, 25 24 bytes
Another adaptation of GB's Ruby solution.
%1ª[UU*=°VU´ÒVU]cßU/=V±3

Try it
The main trick here is in the overloading of the c method for arrays. Pass it another array as an argument and it concatenates it to the original array. Pass it a number as an argument, as happens on the last recursive call, and it flattens the original array by that many levels - 1 in this case, after rounding. But, as the array is only ever one level deep, flattening it has no effect.
%1ª[UU*=°VU´ÒVU]cßU/=V±3     :Implicit input of integer U
%1                           :U modulo 1
  ª                          :Logical OR with
   [                         :Construct and array containing
    U                        :  U
     U*=                     :  U multiplied by
        °V                   :    V (initially 0) prefix incremented
          U´                 :  The new value of U, postfix decremented
            ÒV               :    Subtract the bitwise negation of V
              U              :  The now-decrmented U
               ]             :End array
                c            :Concatenate, or flatten by
                 ß           :  Recursive call to the programme with argument
                  U/=        :    U divided by
                     V±3     :      V incremented by 3

Husk, 16 bytes
↑¦1G`I⁰zI¢ë*+-/N

Try it online!
Explanation
↑¦1G`I⁰zI¢ë*+-/N   Input is a number n, accessible via ⁰.
          ë*+-/    Four-element list containing the functions *, +, - and /.
         ¢         Cycle infinitely.
       z       N   Zip with the list [1,2,3,4,5,..
        I          using the identity function (which works as function application since e.g. I+2 == (I+)2 == +2).
   G               Cumulative reduce from the left
    `I             using flipped identity function
      ⁰            with initial value n.
                   This results in [n, n*1, (n*1)+2, ((n*1)+2)-3, ..
↑                  Take the maximal prefix of elements
 ¦1                that are divisible by 1, or in other words are integers.

Java 8, 84 bytes
n->{for(int i=1;n%1==0;n=new float[]{n/i,n*i,n+i,n-i}[i++%4])System.out.println(n);}

Try it online.
Creating an array with all four values is inspired by @GB's Ruby answer, although I now notice that using a ternary if-statement is the same amount of bytes:
n->{for(int i=0;n%1==0;n=++i%4<1?n/i:i%4<2?n*i:i%4<3?n+i:n-i)System.out.println(n);}

Try it online.

Perl 5, 53 bytes
@a=qw(/ * + -);say,eval"\$_$a[++$i%4]=$i"while$_==int

Try it online!

Red, 102 bytes
func[n][k: m: 0 until[foreach o[* + - /][print n t: n
n: do reduce[n o m: m + 1]]k: k + 1 t % m <> 0]]

Try it online!

AWK, 57 bytes
{n=$1;for(k=1;n%1==0;n/=k++)print n,n*=k++,n+=k++,n-=k++}

Try it online!

Rutger, 310 bytes
n=e=$Input;
a=0;
w=While[{m=Modulo[$e];Not[m[1]];}];
w=w[{f=For[4];f=f[@x];f=f[{Print[$e];q=Equal[$x];i=If[{q[1];}];i=i[{k=Times[$e];}];Do[$i];i=If[{q[2];}];i=i[{k=Add[$e];}];Do[$i];i=If[{q[3];}];i=i[{k=Subtract[$e];}];Do[$i];i=If[{q[4];}];i=i[{k=Divide[$e];}];Do[$i];e=k[a=Increment[$a]];}];Do[$f];}];
Do[$w];

Try it online!
It's about time I used Rutger again. Unfortunately, it may not be the best language for the task, as it has no form of eval, forcing me to use four if statements
How it works
How Rutger works
A brief foreword on how the language works: Everything is either an assignment or a function, and every function takes exactly one argument. For operations that require more than one argument (e.g. multiplication), the first call returns a partial function, that, when called again with the second argument, returns the expected result. For example:
left = Times[5];
Print[left[6]];

will print out 30: Try it online!. While usually this is longer than the usual alternative, it can at times save bytes, if a function is called repeatedly with one constant argument, and one changing argument, for instance when printing out times tables.
This one argument rule applies to everything that isn't a constant or a variable, including loops and conditionals. However, loops and conditionals (For, Each, While, DoWhile, If and IfElse) are doable, meaning that in order to actually run them, the Do function must be called (see the last line in the answer). Again, this can save bytes when repeatedly running the same loop, or allow you to run arbitrary code between the definition and running of loops.
Finally, there are three ways of referring to variables, all of which are used in this program. The first is direct referencing, where the variable name is prefixed with a $ symbol. This accesses the value of the variable directly and returns it. The second is functional referencing, which doesn't have a prefixing character. This allows the code to distinguish between (potentially partial) functions assigned to variables, and actual variables containing a specific value. Finally, indirect referencing, prefixed with an @ symbol, creates a variable (if it doesn't already exist) and returns the variable object within a given scope. This allows you to create a loop variable (e.g. i in for i in range(...)).
How the actual solution works
Here is the ungolfed code:
n = elem = $Input;
var = 0;
while = While[{
	mod = Modulo[$elem];
	Not[mod[1]];
}];
while = while[{
for = For[4];
for = for[@index];
for = for[{
	Print[$elem];
	equal = Equal[$index];

	if = If[{ equal[1]; }];
	if = if[{ func = Times[$elem]; }];
	Do[$if];

	if = If[{ equal[2];}];
	if = if[{ func = Add[$elem];}];
	Do[$if];

	if = If[{ equal[3];}];
	if = if[{ func = Subtract[$elem];}];
	Do[$if];

	if=If[{ equal[4];}];
	if=if[{ func = Divide[$elem];}];
	Do[$if];

	elem = func[var = Increment[$var]];
	}];
	Do[$for];
}];
Do[$while];

Try it online!
As you can see, it starts by assigning the three variables n, e and a, which represent the input, the changing element in the sequence, and the modification number for each new element respectively. We then create a while loop:
w=While[{m=Modulo[$e];Not[m[1]];}];

The braces ({ and }) define a block of code, where the final statement in the block is the condition for the while loop. In this case, we start by defining a partial modulo function, which will take in a second argument m, and return e % m. We then call this partial function with \$1\$ as its second argument, returning \$0\$ for integers and a non-zero integer for floats. We then calculate the logical not of this, mapping \$0 \to 1\$ and \$n \to 0, n \ne 0\$.
Next we come to the absolute monstrosity consisting of the while loop's body:
w=w[{f=For[4];f=f[@x];f=f[{Print[$e];q=Equal[$x];i=If[{q[1];}];i=i[{k=Times[$e];}];Do[$i];i=If[{q[2];}];i=i[{k=Add[$e];}];Do[$i];i=If[{q[3];}];i=i[{k=Subtract[$e];}];Do[$i];i=If[{q[4];}];i=i[{k=Divide[$e];}];Do[$i];e=k[a=Increment[$a]];}];Do[$f];}];

The primary part of this loop is a for loop, that iterates \$4\$ times each iteration of the while loop, has an iteration variable of x and consists of:
Print[$e];
q=Equal[$x];
i=If[{q[1];}];i=i[{k=Times[$e]    ;}];Do[$i];
i=If[{q[2];}];i=i[{k=Add[$e]      ;}];Do[$i];
i=If[{q[3];}];i=i[{k=Subtract[$e] ;}];Do[$i];
i=If[{q[4];}];i=i[{k=Divide[$e]   ;}];Do[$i];
e=k[a=Increment[$a]];

The first statement prints out each iteration of the sequence before modifying it. We then create a partial function to check equality with the loop variable x, and encounter four if statements. Each statement checks if x is equal to 1, 2, 3 or 4 respectively, and then assigns k to each function in *, +, - and /, then makes it into a partial function with e as its argument. Finally, we assign e to k run with a as its second argument, and increment a.

Ruby, 52 bytes
->n{i=0.0;n=[p(n)/i+=1,n*i,n+i,n-i][i%4]until 0<n%1}

Try it online!

Save 2 bytes: i=0 and use a float as argument to the function.

@GB Nice, thank you. Are we allowed to require the input be a float?

dzaima/APL, 34 33 bytes
⌽1↓{⍵,⍨⊃⍵(⍎⊃'÷×+-'⌽⍨≢⍵)≢⍵}⍣{⍵≢⌊⍵}

Try it online!
-1 thanks to ngn

hint

TI BASIC, 68 Bytes
1→A
DelVar L1Prompt N
Repeat fPart(N
N→L1(A
NA-1→O
augment(L1,{NA,Ans+A+2,Ans→L1
O/(A+3→N
A+4→A
End
L1

We set up a counter in A and clear L1 so we can use it to track the sequence.  We then repeat until the division step causes a fraction.  Inside the loop we first store N to the list.  Storing to one element past the end of a list or an empty list creates that element, so this one store both adds the result of the division when it doesn't cause a fraction, and initializes the list during the first pass.  We then use augment to append the next 3 terms of the sequence.  The math works out a few bytes smaller by calculating term A4k+3 in variable O and then basing A4k+2 and A4k+4 off O.  Then we do the division separately to reset N for the repeat check and add 4 to A.

Charcoal, 29 bytes
ＮθＷ¬﹪θ¹«Ｉθ⸿≔§⟦∕θⅉ×θⅉ⁺θⅉ⁻θⅉ⟧ⅉθ

Try it online! Link is to verbose version of code. Explanation:
Ｎθ

Input the initial value.
Ｗ¬﹪θ¹«

Repeat until the value is no longer an integer.
Ｉθ⸿

Print the value on its own line.
≔§⟦∕θⅉ×θⅉ⁺θⅉ⁻θⅉ⟧ⅉθ

Calculate the four available arithmetic operations and select the correct one depending on the current output line number.

C (clang), 80 bytes
i;f(n){for(i=0;~i;n=++i%4?i%4-1?i%4-2?n-i:n+i:n*i:n%i?i=-1:n/i)printf("%d ",n);}

Try it online!
A golfed switch statement.

Thanks to many @ceilingcat improvements.

79 bytes

Python 3, 78 76 bytes
f=lambda n:n[-1]%1and n[:-1]or f(n+[eval(f"n[-1]{'/*+-'[len(n)%4]}len(n)")])

Try it online!
Takes input as a list of 1 item and recursively appends the next item of the sequence until it's a non-integer.
In the case that taking input as a list is not allowed, here is a very quickly patched version which takes input as an int.
Input as an integer, 102 bytes
f=lambda n:type(n)==int and f([n])or n[-1]%1and n[:-1]or f(n+[eval(f"n[-1]{'/*+-'[len(n)%4]}len(n)")])

Try it online!
+2 bytes thanks to me forgetting to name the recursive function...
-4 bytes thanks to Jitse

Nice approach! Since your function is recursive, it cannot remain anonymous. You should include f= in your main code. However, you can also save 4 bytes since n[-1] and len(n) need not be in braces. Try it online!

Not sure about taking a list rather than an integer (I'd recommend asking the OP), but n[:-(n[-1]%1>0)]or f... would save a byte

Twig, 164 bytes
Okay, this was actually horribly horrible to write.
Limitations:

No returns! You either output or don't output
No while loops. You must use recursion or nothing
No easy way to output! You have to repeat the output everytime
You can't give variables a value without using the set tag
No easy way to get out of a loop. There's no break, continue, goto or similar. This makes a loop impossible to use.
There is only 1 loop: for ... in ...., and it loops over all the elements in an array, with no way to stop.

All those made the code massive!
Hey, I even made it longer than the Java answer!
It's as long as @Arnauld's JavaScript answer! ... With all 3 alternatives combined.
Here's the code:
{%macro a(b,n=1)%}{{n<2?b}}{%set b=b*n%},{{b}}{%set b=b+n+1%},{{b}}{%set b=b-(n+2)%},{{b}}{%set b=b/(n+3)%}{%if(b//1)==b%},{{b~_self.a(b,n+4)}}{%endif%}{%endmacro%}

You can try it on https://twigfiddle.com/zw5zls

How to use:
Simply import the file and call the first macro.
{% import 'file.twig' as a %}

{{ a.a(21) }} {# 21,21,23,20,5,25,31,24,3,27,37,26 #}

To have an usable array, you can do a.a(21)|split(',').

Ungolfed:
{% macro calc(number, index = 1) %}
    {% if index < 2 %}
        {{ number }}
    {% endif %}

    {% set number = number * index %},{{ number }}
    {% set number = number + index + 1 %},{{ number }}
    {% set number = number - (index + 2) %},{{ number }}
    {% set number = number / (index + 3) %}

    {#
        verifies if it is an integer.
        this is done with an integer division with 1 and compare with itself
        if both values are the same, the number is an integer
        otherwise, it is a floating-point number
    #}
    {% if (number // 1) == number %}
        ,{{ number ~ _self.calc(number, index + 4) }}
    {% endif %}
{% endmacro %}

Should be easy to read.
This ungolfed answer will NOT give the correct output, as it will throw random whitespaces.
It exists merely to be humanly readable.

Jelly, 14 bytes
×+_÷4ƭ‘ɼ$ḞƑÐ¿Ṗ

A full program* that accepts an integer and prints the resulting sequence.
Try it online!
How?
×+_÷4ƭ‘ɼ$ḞƑÐ¿Ṗ - Main Link: integer, n
           Ð¿  - collect while X, initially n, is:
          Ƒ    - ...invariant under
         Ḟ     -     floor to the nearest integer
        $      - ...last two links as a monad - f(X):
       ɼ       -   apply to the register (initially zero) and yield:
      ‘        -     increment (i.e. get the next right operand)
    4ƭ         -   calling these four links in turn:
×              -     multiply
 +             -     add
  _            -     subtract
   ÷           -     divide
             Ṗ - pop off the trailing, non-integer
               - implicit print

* Note: this is not a reusable Link since the tie quick, ƭ, does not reset between calls to a Link.