text:
Optimize my Nullifiers
I am a big fan of the game Creeper World, and especially the sequel. You don't need to know how this game works to answer the question, I just wanted to mention where my question originated from.
In the game, your objective is to destroy the Emitters that are spawning Creeper, using a weapon known as a nullifier.
Nullifiers can destroy any emitter in this radius:
 eee
eeeee
eenee
eeeee
 eee

Each nullifier CAN target multiple Emitters.
Your objective
Given an array simulating a 2D map consisting of nothing and emitters with whatever characters you like, could be spaces and e or numbers - just be sure they are distinguishable, output the same map with the optimal amount of nullifiers n (or what you would like) placed, so that the emitters are destroyed with the least amount of nullifiers.
If there are multiple optimal ways of doing it, just outputting one would be fine. If, however, the task is not solvable, say there are so many emitters that no layout will ever hit all of them, you must output a distinguishably different something, null will suffice
Quick Rules:

Input: multidimensional array
Input will contain two characters, meaning nothing and emitter, include what is what in your answer
Output: multidimensional array
Output will contain three characters, meaning nothing, emitter and nullifier OR a distinguishable output if the input is unsolvable
You may only replace the nothing character with a nullifier
A nullifier can hit multiple emitters, and will always hit all that
are in range
A nullifier can hit in the area specified above, and will always hit all emitters that it can target
Shortest answers in bytes win
standard loopholes forbidden

Examples
Input:
[[ , ,e, , ],
 [ , , , , ],
 [e, , , ,e],
 [ , , , , ],
 [ , ,e, , ]]

Output:
 [[ , ,e, , ],
  [ , , , , ],
  [e, ,n, ,e],
  [ , , , , ],
  [ , ,e, , ]]

Input:
[[e,e,e,e,e],
 [e, , , ,e],
 [e, , , ,e],
 [e, , , ,e],
 [e,e,e,e,e]]

Output:
[[e,e,e,e,e],
 [e, ,n, ,e],
 [e, , , ,e],
 [e, ,n, ,e],
 [e,e,e,e,e]]

Input:
[[e, , , , , , ,e, ,e, , , ,e, ,e, ,e, ,e],
 [ , ,e, , ,e, , , ,e,e, , , , ,e, , , , ],
 [ , ,e, , , ,e, ,e, ,e, ,e, ,e, ,e, , , ],
 [e, , , ,e, ,e, , , , , , , , , , , ,e, ],
 [e, , ,e, , , , , ,e, ,e, ,e, ,e, , , ,e],
 [ , , ,e, ,e, ,e, , , , , , , , , ,e, , ],
 [ ,e,e, ,e, , , ,e, ,e,e, ,e, ,e, ,e, , ],
 [ , ,e, , , ,e, , , , , , , , ,e,e, ,e, ],
 [ , , ,e, , , , ,e,e, , , , , , , , ,e, ],
 [e, , , , , , ,e, , , ,e,e, ,e, , , , , ],
 [ ,e,e, , ,e, , , , ,e, , , , , , ,e, , ],
 [ , , ,e,e, ,e, ,e, , , ,e,e, ,e, ,e, ,e],
 [e,e, , , , ,e, , , ,e, , , , , , , , , ],
 [ , , ,e, , , , , ,e, , ,e, ,e, ,e, ,e, ],
 [ , , , ,e, ,e, , , , , , , , , , , , , ],
 [e,e, , ,e,e, , ,e, , ,e, ,e, ,e, ,e, ,e],
 [e, ,e, ,e, , ,e,e,e, , ,e, , , ,e, , ,e],
 [ , , , ,e, , , , , ,e, , , ,e, , , , , ],
 [ , ,e, , , ,e, ,e, , , ,e, , , , ,e, , ],
 [ , , ,e, ,e, ,e, , ,e,e, , ,e,e, , ,e, ]]

Output (This output is hand-made, and might not be the optimal output):
[[e, , , , , , ,e, ,e, , , ,e, ,e, ,e, ,e],
 [ , ,e, , ,e, , ,n,e,e, , , ,n,e, , , , ],
 [ ,n,e, , ,n,e, ,e, ,e, ,e, ,e, ,e, ,n, ],
 [e, , , ,e, ,e, , , , , , , , , , , ,e, ],
 [e, , ,e, , , , , ,e, ,e, ,e, ,e, , , ,e],
 [ , ,n,e, ,e, ,e, , , ,n, , , , , ,e, , ],
 [ ,e,e, ,e, ,n, ,e, ,e,e, ,e, ,e,n,e, , ],
 [ , ,e, , , ,e, , , , , , , , ,e,e, ,e, ],
 [ , , ,e, , , , ,e,e, , , , , , , , ,e, ],
 [e, ,n, , , , ,e, , , ,e,e, ,e, , , , , ],
 [ ,e,e, , ,e,n, , ,n,e, , , ,n, , ,e,e, ],
 [ , , ,e,e, ,e, ,e, , , ,e,e, ,e, ,e, ,e],
 [e,e, , , , ,e, , , ,e, , , , , , , , , ],
 [ , , ,e, ,n, , , ,e, , ,e, ,e, ,e, ,e, ],
 [ ,n, , ,e, ,e, , , , , , , ,n, , , ,n, ],
 [e,e, , ,e,e, , ,e,n, ,e, ,e, ,e, ,e, ,e],
 [e, ,e, ,e, , ,e,e,e, , ,e, , , ,e, , ,e],
 [ , , , ,e, , , , , ,e, ,n, ,e, , ,n, , ],
 [ , ,e, ,n, ,e, ,e, , , ,e, ,n, , ,e, , ],
 [ , , ,e, ,e, ,e, ,n,e,e, , ,e,e, , ,e, ]]

Input:
[[e,e],
 [e,e]]

Output:
null

Can I use 0, 1 and 2 or similar?

@user202729 Yes, as long as you specify what is what, and keep it consistent, I.E. if an emitter is 1 in input, then likewise it must be 1 in the output

I loved Creeper World, it was always satisfying to finally eradicate the final traces of creeper

Link to game if anyone's interested

Pseudo code: try 1 nullifier in any position. The try 2,3,4 ... . Some constraint on execution time is needed

@edc65 The whole point of [tag:code-golf] is to minimize code size without caring about runtime.

@user202729 yet code that could run for years and cannot be tested is problematic

I love creeper world too!

Don't really know how the second example works... the nullifier can't destroy emitters on the corners right?

@Chromium Yes, the nullifiers can't hit two spaces diagonally, therefore you must place 2 so that they cover all of them irregardless

@TroelsM.B.Jensen Oh yeah, I actually thought that the nullifier(s) is in the middle like the first one... I get it now. Thanks!

Python 3, 558 511 509 bytes
from itertools import*
E=enumerate
L=len
def s(s):
 q=[(x,y)for y,r in E(s)for x,k in E(r)if k==w]
 for i in range(1,L(q)):
  for c in combinations(q,i):
   m=[l*1for l in s]
   for p in c:
    m[p[1]][p[0]]=n
    for y,r in E([list(r) for r in' xxx ,xxxxx,xxnxx,xxxxx, xxx '.split(',')]):
     for x,k in E(r):
      o=(p[0]-x+2,p[1]-y+2)
      if k==d and-1<o[0]<L(m[0])and-1<o[1]<L(m)and m[o[1]][o[0]]==e:
       m[p[1]-y+2][p[0]-x+2]=d
   if e not in ','.join([''.join(r)for r in m]):return(m)
print(s(m))

Try it online!
It's very loopy, but I don't know enough about Python to optimize it further. I did learn some things from ovs's answer, so that was fun.
The input (modified to make it easier to write test cases) expects ' ' or 'e', while the output uses ' ', 'n' for nullifier, and 'x' for a nullified emitter. The function takes the expected input that was described in the question.
I set the e, w, n, and d variables outside because they could be easily replaced with numbers and, if the input and output were modified to use numbers as well, it would print out the same thing. I used letters because they made it more readable while working on it.
Fun question, OP! Creeper World is great and it was a cool inspiration for the question :)
Edit: -47 bytes thanks to Erik the Outgolfer

Sorry, but it looks like this isn't a seriously competing entry. I recommend deleting it until you have time to optimize it.

Oops, my bad! Edited to the best of my ability

You don't actually need 2 spaces for each level of indentation, 1 is enough.

Python 2, 267 263 bytes
from itertools import*
m=input()
E=enumerate
e=[(x,y)for y,a in E(m)for x,e in E(a)if e]
for n in count():
 for p in combinations(e,n):
	k=[l*1for l in m]
	for x,y in p:k[y][x]=2
	all(e+any(8>(y-Y)**2+(x-X)**2for X,Y in p)for y,a in E(m)for x,e in E(a))>0>exit(k)

Try it online!
0 for emitter, 2 for nullifier and 1 for empty space.

Wolfram Language (Mathematica), 173 168 bytes
t=ToExpression@$ScriptInputString
P=Position
p=t~P~0
q=t~P~2
Print@ReplacePart[t,Thread[p->LinearProgramming[1&/@p,(xBoole[Norm[x-#]^2<6]&/@p)/@q,1&/@q,0,Integers]]]

Try it online!
Solves the largest test case in 1 second.
Full program. As a function, it's shorter, only 130 bytes.
Use 0 for  , 1 for n and 2 for e.
This program can be used to convert from the input format in the challenge.
If there are no solution it will print error message lpdim like this, or lpsnf like this.
Version using Outer (although more readable) is 2 bytes longer, despite the short name of Outer: Try it online!

Explanation.
Note that this can be reduced to an integer linear programming problem.
Each e cell is fixed at 2, each empty cell is an integer variable, which can be either 0 (empty) or 1 (nullifier). The list of coordinates of variables are stored in variable p. (the Positions in t that is 0)
The objective is to minimize the number of nullifier used, so the sum of those integer variables must be minimized. (1&/@p, a vector consists of all 1 and with length equal to p's length, indicates the objective function)
The constraints are, for each emitter (2) (their positions are stored in q), there must be at least a nullifier in the range around it, or to be precise, have an Euclidean distance to it of at most \$\sqrt 6\$.
This is formulated with the matrix m = (xBoole[Norm[x-#]^2<6]&/@p)/@q (for each element in q, create a row with elements being 1 if the squared distance (Norm) to the corresponding coordinate in p is less than 6) and the vector b = 1&/@q.
After that ReplacePart and Thread "applies" the variable values to t and print it.

Echo can be used instead of Print but the output contains a preceding >>.

Unfortunately 1^p doesn't work (instead of 1&/@p).

source: Stack Exchange

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

sort: votes


text:
Two Dimensional Waterflow problem
The one dimensional twitter waterflow problem is this:
You are given an array that represents a hill in the sense that the ith entry is the height of the ith location of the hill. When it rains, water logs in the hills, and you need to figure out how much water would log.
For example, after raining, the array 2 5 3 4 3 2 5 5 3 4 2 2 2 looks like this,

and 9 units of water have accumulated.

The challenge is to solve the 2D version of this. To clarify, you will be given a 2D matrix of land heights, and you will have to output the total amount of rainwater it can collect. Water cannot flow out through diagonals, but only the four cardinal directions.

duplicate?

@ngn it is pretty close, but not an exact duplicate

@AgnishomChattopadhyay Fair enough. I think you should mention big-O of what we should optimise for - the size of the matrix, or the volume of the water held, or the max height?

@AgnishomChattopadhyay also, it would be nice to have some tests

I think you should make it more obvious that the actual challenge is the second part of the post and give at least one 2D example.

Also: (1) if there is a winning criteria tag, don't need [code-challenge]. (2) best case, worst case or average case?

I voted to close because ngn 's question is not clarified.

The picture is really misleading...

Possible duplicate of Fill in the lakes

@JonathanFrech Different winning criteria.

Python 3, O(h × w × d) 296 bytes, O(h × w × d')
def f(a):
 w=0;b=[len(a[0])*[0]];a=b+a+b;a=[[0]+x+[0]for x in a];b=sorted(set(sum(a,[])))
 for[i,j]in zip(b,b[1:]+[1+max(b)]):
  c=[[0,0]]
  while c:
   [x,y]=c.pop()
   if x<len(a)and x>=0and y<len(a[0])and y>=0and a[x][y]<=i:w+=i-a[x][y];a[x][y]=j;c+=[[x+1,y],[x,y+1],[x-1,y],[x,y-1]]
 return w

Try it online! Where d' represents the number of distinct values in the input. Edit: Saved 3 bytes thanks to @Mr.Xcoder.

(what is h, w and d?)

@user202729 d is the highest land height in the w × h grid, but I like to think of it as the depth.

b=[len(a[0])*[0]] should work for 276.

Thanks for the answer. I'd like to think that there is some algorithm that is independent of d. Otherwise, scaling all the numbers by some arbitrary amount would randomly require more time.

@AgnishomChattopadhyay Better now?

This is much cooler. Where is the d factor coming from?

@AgnishomChattopadhyay ... if you mean the d' factor, it's documented in the answer.

@Neil  Yes, I see that. What I meant was, I had been wondering if there is a reason why the d' factor cannot be avoided.

@AgnishomChattopadhyay Well, I can think of an O(w² × h²) algorithm, but I hardly think that's an improvement.

Scan every row from left and right, every column from top and bottom, thereby determining the maximum limiting height for every square in each direction. Then sum up the difference of each squares height and the minimum of its borders. Should be O (n^2), which is asymptotically optimal.

@politza As far as I can tell, given the first test case I use in my demo, your algorithm would think that the 0 is covered by 6 units of water but in fact it's only 5.

Yes, you're correct.

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


text:
Implement Malbolge's "crazy" operator
One of many unique features of the Malbolge programming language is its highly unintuitive OP operator, referred to only as "op" in the documentation and source code but popularly known as the "crazy" operator. As described by Ben Olmstead, the creator of the language, in its documentation: "don't look for pattern, it's not there."
op is a "tritwise" operator -- it operates on corresponding ternary digits of its two arguments. For each trit (ternary bit), the result of op is given by the following lookup table:
           a
op(a,b)  0 1 2
       +-------
     0 | 1 0 0
   b 1 | 1 0 2
     2 | 2 2 1

For example, to calculate op(12345, 54321), first write out both numbers in ternary and then look up each pair of trits in the table:
   0121221020   (12345_3)
op 2202111220   (54321_3)
--------------
   2202220211   (54616_3)

The last important point is that all values in Malbolge are 10 trits wide, so input values should be padded with zeroes to a width of 10. (For instance, op(0, 0) is 1111111111 in ternary.)
Your task is to take two integers 0 ≤ a, b < 59049 as input, and output the integer value of op(a,b).
Test cases (in the format a b op(a,b)):
0 0 29524
1 2 29525
59048 5 7
36905 2214 0
11355 1131 20650
12345 54321 54616

Here is a reference implementation (copied directly from the Malbolge source code).

can this be answered in Malboge? ;)

I guess Malbolge is a good golfing language now!

For what it's worth, 54616_3 doesn't mean "this other thing is the decimal number 54616, but represented as base three". It means "Read 54616 as base 3". Which, of course, you can't do (there are digits that Valve can't count to in there). It'd still probably be just as clear if you got rid of the _3 entirely, and more accurate.

@Orangesandlemons I guess just using the operator in Malbolge would fall under the standard loophole. Reimplementing it using different code would be okay.

@PaŭloEbermann No, that's not a loophole.

C (gcc), 99 98 96 bytes

Saved a byte thanks to ceilingcat; golfing 19683 to L'䳣'.
Saved two bytes; golfing 108609 to L''.

M,a,l,b,o;L(g,e){for(o=b=L'䳣',l=0;o/=2.4;b/=3)M=g/b,g%=b,a=e/b,e%=b,l+=b*(L''>>M+6*a+M&3);g=l;}

Try it online!

I like the naming scheme!

JavaScript (ES7), 56 bytes
f=(a,b,k=9)=>~k&&(a%3|b%3<<9|8)**2%82%3+3*f(a/3,b/3,k-1)

Try it online!
How?
Given \$a\$ and \$b\$ in \$[0..2]\$, we compute:
$$f(a,b)=((a+512b+8)^2 \bmod 82) \bmod 3$$
Leading to:
 a | b | 512b | a + 512b |  + 8 | squared | MOD 82 | MOD 3
---+---+------+----------+------+---------+--------+-------
 0 | 0 |    0 |      0   |    8 |      64 |   64   |   1                  a
 1 | 0 |    0 |      1   |    9 |      81 |   81   |   0                0 1 2
 2 | 0 |    0 |      2   |   10 |     100 |   18   |   0              +-------
 0 | 1 |  512 |    512   |  520 |  270400 |   46   |   1            0 | 1 0 0
 1 | 1 |  512 |    513   |  521 |  271441 |   21   |   0    -->   b 1 | 1 0 2
 2 | 1 |  512 |    514   |  522 |  272484 |   80   |   2            2 | 2 2 1
 0 | 2 | 1024 |   1024   | 1032 | 1065024 |    8   |   2
 1 | 2 | 1024 |   1025   | 1033 | 1067089 |   23   |   2
 2 | 2 | 1024 |   1026   | 1034 | 1069156 |   40   |   1

Function choice
There are several other possible candidate functions of the form:
$$f_{k,c,p,m}(a,b)=((a+kb+c)^p \bmod m) \bmod 3$$
One of the shortest ones being:
$$f(a,b)=((a+5b+2)^4 \bmod 25) \bmod 3$$
But the good thing about \$(a+512b+8)\$ is that it can be performed with bitwise operators, thus implicitly discarding the decimal parts of \$a\$ and \$b\$. This is why we can simply divide them by \$3\$ without rounding between each iteration.
Commented
f = (a, b,            // given the input integers a and b
           k = 9) =>  // and starting with k = 9
  ~k &&               // if k is not equal to -1:
    ( a % 3           //   compute (a mod 3)
      | b % 3 << 9    //   add 512 * (b mod 3)
      | 8             //   add 8
    ) ** 2            //   square the result
    % 82              //   apply modulo 82
    % 3               //   apply modulo 3, leading to crazy(a % 3, b % 3)
    + 3 * f(          //   add 3 times the result of a recursive call with:
      a / 3,          //     a / 3  \__ no rounding required
      b / 3,          //     b / 3  /   (see 'Function choice')
      k - 1           //     k - 1
    )                 //   end of recursive call

I think (1581093>>b%3*2+a%3*8&3) saves a whole byte!

@Neil Unfortunately,  I'm passing a/3 and b/3 without rounding. That would fail because of that.

Interesting how you found a pattern which does not exist.

Is there any reason to prefer k = 9 ... => ~k && ... to k = 10 ... => k && ... ?

@Falco No, it's neither shorter nor more efficient in any way. I'd just tend to prefer 0-indexed stuff, so I'd rather mimic for(k=9;k>=0;k--) than for(k=10;k>=1;k--).

05AB1E, 18 bytes
Code:
3Tm+3Bø5+3m5(^3%3β

Uses the 05AB1E encoding. Try it online!

Algorithm Explanation
In order to get the number padded with zeroes, we need to add 59049 to both numbers (because 59049 in ternary is 10000000000). We do not have to leave out the leading 1 as \$(1, 1) \rightarrow 0\$. We convert the numbers from decimal to ternary and join each pair as each own number.
For example, for input 12345 and 54321, these get mapped to:
$$
\begin{array}
& 12345 \rightarrow & 1 & 0 & 1 & 2 & 1 & 2 & 2 & 1 & 0 & 2 & 0 \\
54321 \rightarrow & 1 & 2 & 2 & 0 & 2 & 1 & 1 & 1 & 2 & 2 & 0
\end{array}
$$
Which gives the following list of joined integers:
$$
11, 2, 12, 20, 12, 21, 21, 11, 2, 22, 0
$$
These integers need to be mapped by the given lookup table in the OP. The formula we currently use that maps these numbers to their corresponding trits (\$0 \rightarrow 1, 10 \rightarrow 0, \dots\$) is:
$$
f(x) = \left((x + 5)^3 \oplus -5\right) \text{ mod }3
$$
Whereas \$\oplus\$ denotes the bitwise xor function.
Eventually after mapping this function on the list of joined integers, we treat this resulting list as a number represented in base 3 and convert it from base 3 to decimal.

Code Explanation
3Tm+                  # Add 59049 to pad the ternary number with zeroes.
    3B                # Convert to base 3.
      ø               # Zip the list to get each joined integer.
       5+             # Add 5 to each element.
         3m           # Raise each element to the power of 3.
           5(^        # XOR each element with -5.
              3%      # Modulo each element with 3.
                3β    # Convert from base 3 to decimal.

Can 3Tm+3Bø19sm74%3%3β be golfed?

@JonathanAllan Nice find! It does however seem impossible to golf it any further without using some other kind of black magic formula.

R, 64 62 bytes
function(a,b,x=3^(9:0))30801%/%x[a%/%x%%3*3+b%/%x%%3+1]%%3%*%x

Try it online!
Thanks to JAD for some black magic golfing tricks and -2 bytes!
30801, when converted to a 10-trit ternary integer, is 1120020210 which just adds a trailing zero to the operation table, when read down the columns. Then we convert the ternary digits of a and b elementwise into an integer and use that as an index into the ternary digits of 30801.

62 bytes Yay for operator precedence!

Yeah, this way, you first index x using [.*]. Then all the %any% operations happen. The fun part is that if you see 30801%/%x%%3 as f=function(x)30801%/%x%%3, that f(x[index]) == (f(x))[index]. Saving the braces :)

@JAD fascinating! And as I comment above, basically black magic.

I'll happily admit that this took a lot of fiddling :P

C (gcc), 74 72 71 bytes
f(a,b,i,r){for(r=0,i=59049;i/=3;)r+=(108609>>a/i%3*2+b/i%3*6&3)*i;i=r;}

Try it online!
Breakdown
The truth table
           a
op(a,b)  0 1 2
       +-------
     0 | 1 0 0
   b 1 | 1 0 2
     2 | 2 2 1

Can be thought of as a 3x3 array, where a is the column, and b is the row. Transforming that into a one-dimensional list gives us 100102221. To save space we avoid lists and strings and make it into a number instead. To do that, we flip the order and transform every trit into a 2-bit number. Glue them together and we have a binary number we can "index" into by shifting to the right by 2 * (b * 3 + a) and masking:
 1 0 0 1 0 2 2 2 1
 1 2 2 2 0 1 0 0 1
011010100001000001

Next, we massage the expression using the power of operation precedence to become the abomination above.
3^9 = 19683 so that is a good loop limit. Since we multiply the counter by 3 each time, we can write the limit as 2e4 instead. Also we save ourselves the bother of pow() or similar.
On second thought, let's start at 3^10 and work downwards with a pre-loop divide-and-test.

Haskell, 108 bytes
2%2=1
_%2=2
0%_=1
2%1=2
_%_=0
g=take 10.map(`mod`3).iterate(`div`3)
(foldr((.(3*)).(+))0.).(.g).zipWith(%).g

Try it online!

APL (Dyalog), 41 25 bytes
9 bytes saved thanks to @Adám
3⊥(b⊤6883)[3⊥⍉⎕⊤⍨3,b←9⍴3]

Try it online!

Takes inputs in reversed order, 25 bytes: 3⊥(b⊤6883)[3⊥⍉⎕⊤⍨3,b←9⍴3]

@Adám thanks! that's some neat stuff. I guess I've gone a bit rusty :P

Jelly,  23  18 bytes
-1 thanks to Erik the Outgolfer (rearrange 3*⁵¤ to ⁵3*)
⁵3*+b3Zḅ3ị⁽½Ṡb3¤ḅ3

A monadic link accepting a list of two integers.
Try it online! Or see a test-suite.
⁹*%733%3 is a byte longer than ị⁽½Ṡb3¤ :(
How?
⁵3*+b3Zḅ3ị⁽½Ṡb3¤ḅ3 - Link: [a, b]      e.g. [11355,1131]
⁵                  - literal ten            10
 3                 - literal three          3
  *                - exponentiation         59049
   +               - addition (vectorises)  [70404,60180]
     3             - literal three          3
    b              - to base (vectorises)   [[1,0,1,2,0,1,2,0,1,2,0],[1,0,0,0,1,1,1,2,2,2,0]]
      Z            - transpose              [[1,1],[0,0],[1,0],[2,0],[0,1],[1,1],[2,1],[0,2],[1,2],[2,2],[0,0]]
        3          - literal three          3
       ḅ           - from base (vectorises) [4,0,3,6,1,4,7,2,5,8,0]
               ¤   - nilad followed by link(s) as a nilad:
          ⁽½Ṡ      -   literal 3706         3706
              3    -   literal three        3
             b     -   to base              [1,2,0,0,2,0,2,1]
         ị         - index into             [0,1,0,0,1,0,2,2,2,1,1]
                 3 - literal three          3
                ḅ  - from base              20650

Also 18: ⁵3*+b3ZḌ19*%74%3ḅ3 (uses a magic-formula after getting the pair-wise trits of converting from base ten then taking 19 to that power, modulo 74, modulo 3 to get the required trits of the output - found using a search in Python)

18 bytes (note: there should really be a "prepend y 0s"built-in)

Ugh I thought that looked awkward. Thanks!

Many things look awkward, sometimes you have to get used to them. :P

Python 2, 79 65 63 61 bytes
thanks to Arnauld for his formula (-2 bytes).
f=lambda a,b,i=9:i+1and(a%3+b%3*5+2)**4%25%3+f(a/3,b/3,i-1)*3

Try it online!

J, 37 bytes
((3 3$d 30801){~{@,.)&.(d=.(10$3)&#:)

Explanation:
((3 3$d 30801){~{@,.)&.(d=.(10$3)&#:)
                       (d=.(10$3)&#:)   convert to 10 trits, and name this function as d
                     &.                 ... which is done on both args and inverted on the result
                {@,.                    make boxed indices: 1 2 3 4 {@,. 5 6 7 8  ->  1 5 ; 2 6 ; 3 7 ; 4 8
              {~                        index out of a lookup table
 (3 3$d 30801)                          reusing the trits conversion function to make the table

Ended up being relatively readable, tbh.

Welcome to PPCG! Here is a test-suite - I stole the wrapping code from Galen Ivanov's answer.

Welcom to PPCG!
Nice solution! Here is a TIO link to it.

30

28

@FrownyFrog nice!

Charcoal, 31 bytes
Ｉ↨³⮌⭆χ§200211⁺∨﹪÷θＸ³ι³¦⁴﹪÷ηＸ³ι³

Try it online! Link is to verbose version of code. Explanation:
     χ                          Predefined variable 10
    ⭆                           Map over implicit range and join
                    ι        ι  Current index
                  Ｘ³       Ｘ³   Power of 3
                 θ              Input `a`
                          η     Input `b`
                ÷        ÷      Integer divide
               ﹪     ³  ﹪     ³ Modulo by 3
              ∨       ¦⁴        Replace zero ternary digit of `a` with 4
             ⁺                  Add
      §200211                   Index into literal string `200211`
   ⮌                            Reverse
 ↨³                             Convert from base 3
Ｉ                               Cast to string
                                Implicitly print

Alternative solution, also 31 bytes:
Ｉ↨³Ｅ↨⁺Ｘ³χθ³§200211⁺∨ι⁴§↨⁺Ｘ³χη³κ

Try it online! Link is to verbose version of code.
        χ                  χ    Predefined variable 10
      Ｘ³                 Ｘ³     Power of 3 i.e. 59049
         θ                      Input `a`
                            η   Input `b`
     ⁺                  ⁺       Sum
    ↨     ³            ↨     ³  Convert to base 3
   Ｅ                            Map over elements
                    ι           Current ternary digit of `a`
                   ∨ ⁴          Replace zero with 4
                      §       κ Index into ternary digits of `b`
                  ⁺             Add
           §200211              Index into literal string `200211`
 ↨³                             Convert from base 3
Ｉ                               Cast to string
                                Implicitly print

Python 2, 90 87 bytes
f=lambda a,b,A='':f(a/3,b/3,'100102221'[a%3+b%3*3]+A)if a+b else int(A.rjust(10,'1'),3)

Try it online!

Stax, 22 bytes
é╨¼aûé∟ç⌂zπb![5┬◘«╜‼╞♠

Run and debug it

K (ngn/k), 25 22 bytes
3/(3\10267)@3/+(10#3)\

Try it online!

Ruby, 70 bytes
->a,b,l=10{l>0?6883.digits(3)[8-b%3*3-a%3]*3**(10-l)+f[a/3,b/3,l-1]:0}

Try it online!
Decomposes a and b recursively until we get 10 digits of each. 6883 gives the flattened ternary table (reversed). Reconstructs from ternary to decimal by multiplying by 3**(10-l).

Cjam, 31 bytes
{{3bA0e[\}2*.{3*+"100102221"=}}

Try it online!

J, 43 bytes
3#.((3 3$t 6883){~<@,~"0)&(_10{.t=.3&#.inv)

It can certainly be golfed further.
Explanation:
                         &(               ) - for both arguments
                                t=.3&#.inv  - convert to base 3 (and name the verb t)
                           _10{.            - pad left with zeroes
   (              <@,~"0)                   - box the zipped pairs (for indexing)
    (3 3$t 6883)                            - the lookup table
                {~                          - use the pairs as indeces in the table
3#.                                         - back to decimal

Try it online!

Pyth 26 25 24 bytes
Saved 1 byte, thanks to @ErikTheOutgolfer
Save another byte, inspired by @JonathanAllan's answer
im@j3422 3id3Cm.[0Tjd3Q3

Input is a 2 element list [a,b]. Try it online here, or verify all test cases here.
im@j3422 3id3Cm.[0Tjd3Q3   Implicit: Q=eval(input())
              m       Q    Map each element d of the input using:
                   jd3       Convert to base 3
               .[0T          Pad to length 10 with 0's
             C             Transpose
 m                         Map each element d of the above using:
   j3422 3                   The lookup table [1,1,2,0,0,2,0,2]
  @                          Modular index into the above using
          id3                Convert d to base 10 from base 3
i                      3   Convert to base 10 from base 3, implicit print

.T can be C.

Japt, 24 23 bytes
Getting the ball rolling on Japt's run as language of the month - I fully expect to be outgolfed on this!
Takes input in reverse order as an integer array (i.e., [b,a]).
ms3 ùTA y_n3 g6883ì3Ãì3

Try it
ms3 ùTA y_n3 g6883ì3Ãì3      :Implicit input of array U=[b,a]
m                            :Map
 s3                          :  Convert to base-3 string
    ù                        :Left pad each
     T                       :  With zero
      A                      :  To length 10
        y                    :Transpose
         _                   :Map
          n3                 :  Convert from base-3 string to decimal
             g               :  Index into
              6883ì3         :    6883 converted to a base-3 digit array
                    Ã        :End map
                     ì3      :Convert from base-3 digit array to decimal

spoiler alert: Shaggy did not get outgolfed.

MMIX, 77 bytes (17 instrs + 9 data bytes)
00000000: e303000a f4040010 e3020000 e3050001  ẉ¤¡½ṡ¥¡Ñẉ£¡¡ẉ¦¡¢
00000010: 25030301 1d000003 fe060006 1d010103  %¤¤¢ø¡¡¤“©¡©ø¢¢¤
00000020: feff0006 28060606 200606ff 80060406  “”¡©(©©© ©©”⁰©¥©
00000030: 18060506 20020206 28050505 5b03fff5  ð©¦© ££©(¦¦¦[¤”ṫ
00000040: f8030000 01010200 00020002 01        ẏ¤¡¡¢¢£¡¡£¡£¢

malop   SET   $3,10         // i = 10
        GETA  $4,1F         // oparr = {1,1,2,0,0,2,0,2,1}
        SET   $2,0          // r = 0
        SET   $5,1          // p = 1
0H      SUB   $3,$3,1       // loop: i--
        DIV   $0,$0,3
        GET   $6,rR         // x:xr = x /% 3
        DIV   $1,$1,3
        GET   $255,rR       // y:yr = y /% 3
        2ADDU $6,$6,$6
        ADD   $6,$6,$255
        LDB   $6,$4,$6      // j = oparr[xr * 3 + yr]
        MUL   $6,$5,$6      // j *= p
        ADD   $2,$2,$6      // r += j
        2ADDU $5,$5,$5      // p *= 3
        PBNZ  $3,0B         // if(i) goto loop
        POP   3,0           // return r
1H      BYTE  1,1,2,0,0,2,0,2,1

Perl 5 -p, 102 bytes
sub t{map{("@_"%3,$_[0]/=3)[0]}0..9}@a=t$_;@b=t<>}{$\=(1,1,2,0,0,2,0,2,1)[(3*pop@a)+pop@b]+$\*3while@a

Try it online!

Wolfram Language (Mathematica), 75 72 60 bytes
(d=IntegerDigits)[6883,3][[{1,3}.d[#,3,10]+1]]~FromDigits~3&

Try it online!
un-golfed version:
M[{a_, b_}] :=
  FromDigits[{1, 0, 0, 1, 0, 2, 2, 2, 1}[[
    IntegerDigits[a, 3, 10] + 3*IntegerDigits[b, 3, 10] + 1
  ]], 3];

Both a and b are converted to ten-trit lists, then used pairwise as a 2D index into a lookup table of numbers {1, 0, 0, 1, 0, 2, 2, 2, 1}. The result is again interpreted as a ten-trit list and converted back to integer form.
The lookup table is coded as IntegerDigits[6883,3], which is short because we are recycling the IntegerDigits symbol.


text:
Find the sum of closest distances
For this task your code should take two sorted arrays of integers X and Y as input.  It should compute the sum of the absolute distances between each integer in X and its closest number in Y.
Examples:
X = (1 5,9)
Y = (3,4,7)

The distance is 2 + 1 + 2.
X = (1,2,3)
Y = (0,8)

The distance is 1 + 2 + 3.
Your code can take input in any way that is convenient.
The main restriction is that your code must run in linear time in the sum of the length of the two arrays.. (You can assume that adding two integers takes constant time.)

Can we use lists or streams instead of arrays?

@CatWizard Yes you can!

How is 1 + 2 + 3 derived from X = (1,2,3) and Y = (0,8)?

@guest271314 the closest number two each of 1, 2, and 3 in Y is 0. Thus the differences are 1-0, 2-0, 3-0.

@user202729 I clarified this in the question. In general, it is standard to assume you can add two O(\log n) bit integers in constant time unless you specify otherwise.

I'm not quite sure this is possible. Taking 2 arrays of numbers and finding the least differences will always take O(n) time, where n is the product of the length of the arrays.

@FreezePhoenix since both lists are sorted you can do it in O(n+m), because you iterate over list $X$, visiting each element once, and as long as you keep track of the element $Y_j$ closest to $X_i$, you can check against $Y_j$ and $Y_{j+1}$ since one of those is closest to $X_{i+1}$

Are the arrays always non-negative integers?

@Giuseppe No, sorry.

Haskell, 70 64 bytes
a%b=abs$a-b
x@(a:b)#y@(c:d)|e:_<-d,a%c>a%e=x#d|1>0=a%c+b#y
_#_=0

Try it online!
Explanation
First we define (%) to be the absolute difference between two numbers.  Then we define (#) to be the interesting function. In the first line we match when both lists are non-empty:
x@(a:b)#(c:d:e)

On our first case from here we bind d to e:_ with e:_<-d.  This ensures that d is non-empty and sets it's first element to e.
Then if the second element of \$Y\$ (e) is closer than the first (c) to the first element of \$X\$ (a), we return x#d removing the first element of \$Y\$ and calling again with the same \$X\$.
If we match the pattern but don't pass the condition we do:
a%c+b#y

Which, removes the first item of \$X\$ and adds the absolute difference of it from the first element of \$X\$ to the remaining result.
Lastly if we don't match the pattern we return \$0\$.  Not matching the pattern means that \$X\$ must be empty because \$Y\$ cannot be empty.
This algorithm has order notation \$O(|X|+|Y|)\$.
Haskell, 34 bytes
Here's how I would do it in \$O(\left|X\right|\times\left|Y\right|)\$ time:
x#y=sum[minimum$abs.(z-)<$>y|z<-x]

Try it online!

I clarified in the question that we can assume that adding two integers takes constant time.

Python 2, 124 120 bytes
X,Y=input()
i=j=s=0
while i<len(X):
 v=abs(Y[j]-X[i])
 if j+1<len(Y)and v>=abs(Y[j+1]-X[i]):j+=1
 else:s+=v;i+=1
print s

Try it online!
Saved 4 bytes by moving to program versus function.
Meeting the time-complexity constraint is possible because both lists are sorted. Note that each time around the loop, either i is incremented or j is incremented. Thus the loop is executed at most len(X)+len(Y) times.

I clarified in the question that we can assume adding two integers takes constant time.

C (gcc), 82 bytes
n;f(x,y,a,b)int*x,*y;{for(n=0;a;)--b&&*x*2-*y>y[1]?++y:(++b,--a,n+=abs(*x++-*y));}

This takes input as two integer arrays and their lengths (since C has no way to get their length otherwise). This can be shown to run in O(a+b) because either a or b is decremented on each iteration of the loop, which terminates when a reaches 0 (and b cannot be decremented below 0).
Try it online!
n;                     // define sum as an integer
f(x,y,a,b)             // function taking two arrays and two lengths
int*x,*y;              // use k&r style definitions to shorten function declaration
{
 for(n=0;              // initialize sum to 0
 a;)                   // keep looping until x (the first array) runs out
                       // we'll decrement a/b every time we increment x/y respectively
 --b&&                 // if y has ≥1 elements left (b>1, but decrements in-place)...
 *x*2-*y>y[1]?         // ... and x - y > [next y] - x, but rearranged for brevity...
 ++y:                  // increment y (we already decremented b earlier);
 (++b,                 // otherwise, undo the in-place decrement of b from before...
 --a,n+=abs(*x++-*y))  // decrement a instead, add |x-y| to n, and then increment x
;}

Some notes:

Instead of indexing into the arrays, incrementing the pointers and dereferencing directly saves enough bytes for it to be worth it (*x vs x[a] and y[1] vs y[b+1]).
The --b&& condition checks for b>1 in a roundabout way - if b is 1, it will evaluate to zero. Since this modifies b, we don't need to change it in the first branch of the ternary (which advances y), but we do need to change it back in the second (which advances x).
No return statement is needed, because black magic. (I think it's because the last statement to be evaluated will always be the n+=... expression, which uses the same register as the one used for return values.)

Mathematica, 40 bytes
x = {1, 5, 9};
y = {3, 4, 7};

Norm[Flatten[Nearest[y] /@ x] - x]

If you must create a full program, with inputs:
f[x_,y_]:= Norm[Flatten[Nearest[y] /@ x] - x]

Here's the timing for up to 1,000,000 points (sampled every 10,000) for y:

Close to linear.

This answer is a code-snippet since your input is taken as pre-existing variables.  You should reformat it to either be a sub-routine or a full program.

I'm also a bit suspicious that this works in linear time, do you have any justification as to why it should?  Mathematica tends to be rather opaque in the complexity of it's builtins.

Ruby, 88 bytes
->(p,q){a=q.each_cons(2).map{|a|a.sum/a.size}
x=a[0]
p.sum{|n|x=a.pop if n>x
(n-x).abs}}

Try it online!
Also, for fun, a shorter anonymous function that doesn't quite meet the complexity restrictions:
->(a,b){a.map{|x|x-b.min_by{|y|(x-y).abs}}.sum}

Could you explain in simple terms how this code works? I can't tell if it runs in linear time.

This fails the first test case in the question, as well as inputs such as [5, 6], [0, 1, 5].

JavaScript (Node.js), 80 bytes
x=>g=(y,i=0,j=0,v=x[i],d=v-y[j],t=d>y[j+1]-v)=>1/v?g(y,i+!t,j+t)+!t*(d>0?d:-d):0

It run in O(|X|+|Y|): Every recursion run in O(1), and it recursive |X|+|Y| times.

x, y are passed by reference, which do not copy the content

1/v is falsy if x[i] is out of range, truthy otherwise
t -> d>y[j+1]-v -> v+v>y[j]+y[j+1] is false as long as following conditions meet. And which means y[j] is the number closest to v in y

v is less than (y[j]+y[j+1])/2, or
y[j+1] is out of range, which would convert to NaN, and compare to NaN yield false

that's why we cannot flip the > sign to save 1 more byte

t is always a boolean value, and * convert it to 0/1 before calculating

Try it online!


text:
Eating fish, growing in size
You are fish in a pond that needs to survive by eating other fish. You can only eat fish that are the same size or smaller than yourself. You must create a program that takes a shoal of fish as sorted input. From this you must work out how many fish you can eat and ultimately the size you will grow to.
Size chart
+--------------+--------------+--------------+--------------+
|              | Amount extra | Total size 1 | Increase to  |
| Current size |  needed for  |     fish     |    size      |
|              |  next size   |              |              |
+--------------+--------------+--------------+--------------+
|      1       |      4       |      4       |      2       |
+--------------+--------------+--------------+--------------+
|      2       |      8       |      12      |      3       |
+--------------+--------------+--------------+--------------+
|      3       |      12      |      24      |      4       |
+--------------+--------------+--------------+--------------+
|      4       |      16      |      40      |      5       |
+--------------+--------------+--------------+--------------+
|      5       |      20      |      60      |      6       |
+--------------+--------------+--------------+--------------+
|      6       |      24      |      84      |      7       |
+--------------+--------------+--------------+--------------+

Rules

Your size starts at 1
The shoal input will contain fish integers between 0-9
0 = algae and wont help you feed.
The fish integer represents the size of the fish (1-9).
You can only eat fish the same size or less than yourself.
You can eat the fish in any order you choose to maximize your size.
You can only eat each fish once.
The bigger fish you eat, the faster you grow. A size 2 fish equals two size 1 fish, size 3 fish equals three size 1 fish, and so on.
Your size increments by one each time you reach the amounts below.

Returns an integer of the maximum size you could be
Examples
"11112222" => 3
4 fish size 1 increases to 2, 4 size 2 makes you 3

"111111111111" => 3
4 fish size 1 increases to 2, 8 size 1 makes you 3

The shortest code (counting in bytes) to do so in any language in which numbers wins.

Nice first challenge! One question though, by You must create a function called fish, do you mean we have to create a named function? Or would a program or an unnamed function suffice?

Welcome to PPCG, I took the liberty to do minor formatting changes in the question, feel free to rollback them if you think that they aren't appropriated.

Related :-)

More questions: (1) can we take a list of integers instead of an integer string? (2) can we assume the input is sorted?

I added it will be sorted and can take any input

It seems like nothing prevents that from happening, but just to clarify: may the fish reach a size greater than 9?

More test cases wouldn't go amiss.

{1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9} -> 3 for example?

All of these seem to agree that 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9 is 13.  I didn't check that one myself.

...also some with algae like 0,0,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,3 -> 3

One can remove 5,6 or 6,6  from Mark's last example and get to size 13; yet remove 5,5 instead and one can only reach size five.

That's far too soon to be accepting a solution!

Oh didn't know that I figured if someone get less bytes can move it to theirs should I un-accept?

@Scath Often you don't accept any answer as comparing answers in different languages isn't particularly fair.

This reminds me of the game Feeding Frenzy

JavaScript (ES6), 44 bytes
Takes input as an array of integers.
a=>a.map(x=>s+=(t+=s>=x&&x)>s*-~s*2,t=s=1)|s

Try it online!
How?
The threshold \$T_s\$ to reach the size \$s+1\$ is given by:
$$T_s=2s(s+1)$$
We keep track of our current size in \$s\$ and of what we've eaten so far in \$t\$ (we start with \$t=1\$, so this is actually off by \$1\$).
For each fish \$x\$ in the shoal, assuming it's sorted from smallest to biggest:

we add \$x\$ to \$t\$ (i.e. we eat the fish) whenever we have \$s\ge x\$
we increment \$s\$ (i.e. we grow in size) if \$t > T_s\$

Wolfram Language (Mathematica), 40 39 bytes
(f:=Floor@s;s=1;s<#||(s+=#/4/f)&/@#;f)&

Try it online!
Explanation
f:=Floor@s;s=1;

Store floor(s) in f, symbolically. Start with s=1 (size).
... /@#

Iterate through each element in input...
s<#||(s+=#/4/f)

If the element is not greater than s, then increment s by <element> / (4 * floor(s)). The Or (||) short-circuits otherwise.
f

Return floor(s).

Python 2, 60 bytes
f=lambda l,n=1,c=1:c>n*~-n*2and f(l,n+1,c+l.count(n)*n)or~-n

Try it online!

Jelly, 17 bytes
J×4ÄfSR$ịx`>JTḢȯ1

Try it online!
An interesting method which could well get beaten by some kind of loop or recursion.
How?
J×4ÄfSR$ịx`>JTḢȯ1 - Link: list A (ascending digits) e.g. [1,1,1,1,1,1,1,2,2,3]
J                 - range of length                      [1,2,3,4,5,6,7,8,9,10]
 ×4               - multiply all by 4                    [4,8,12,16,20,24,28,32,36,40]
   Ä              - cumulative sums                      [4,12,24,40,60,84,112,144,180,220]
       $          - last two links as a monad (of A):
     S            -   sum                                14
      R           -   range                              [1,2,3,4,5,6,7,8,9,10,11,12,13,14]
   f              - filter keep                          [4,12]
          `       - use left argument as right with:
         x        -   repeat elements                    [1,1,1,1,1,1,1,2,2,2,2,3,3,3]
        ị         - index into                           [      1,              3    ]
                  -                                    = [1,3]
            J     - range of length (of A)               [1,2,3,4,5,6,7,8,9,10]
           >      - greater than?                        [0,1,3,4,5,6,7,8,9,10]
                  -                1 not greater than 1---^ ^---3 is greater than 2
                  -   (note keeps values of longer - i.e. the 3,4,... here)
             T    - truthy indices                       [  2,3,4,5,6,7,8,9,10]
              Ḣ   - head                                 2
                1 - literal one                          1
               ȯ  - logical OR                           2
                  -   (edge-case handling when the head of an empty list yields 0)
                  -   (note that when the shoal is fully consumed the final size will
                  -    still be less than the length of that shoal, so TḢ will still give
                  -    this size due to >J keeping values of the longer argument.)

Someone said it was to soon for me to accept this do you agree?

Yes I agree; some people don't award green check marks for code-golf, others leave it about a week - accepting an answer may mean a drop in activity. As an aside I feel like this should be beatable (either in Jelly itself or as a cross-language competition) anyway! ...code-golf is a strange fit to Stack Exchange since the real competition is intra-language but the accept mark is inter-language.

Haskell, 46 bytes
(!0)
a!b|sum[y|y<-a,y<=b]/2<b*b+b=b|q<-b+1=a!q

Try it online!

Lua, 214 bytes
l,f=1,{}for j=1,9 do s,f[j]=(...):gsub(j,0)end::z::a,n=0,l*4 for i=1,l do a=a+i*f[i]end if a>=n then e=l while n>0 do if 0<f[e]and e<=n then n=n-e f[e]=-1+f[e]else e=e-1 end end l=l+1 else print(l)return end goto z

Try it online!
Not even near shortest one here but it was fun to figure it out :D


text:
Find the minimum cost matching between arrays of integers
Consider two sorted arrays of integers \$X\$ and \$Y\$ of size \$m\$ and \$n\$ respectively with \$m < n\$.  For example \$ X = (1,4)\$, \$Y = (2,10,11)\$.
We say that a matching is some way of pairing each element of \$X\$ with an element of \$Y\$ in such a way that no two elements of \$X\$ are paired with the same element of  \$Y\$.  The cost of a matching is just the sum of the absolute values of the differences in the pairs.
For example, with \$X = (7,11)\$, \$Y = (2,10,11)\$ we can make the pairs \$(7,2), (11,10)\$ which then has cost \$5+1 = 6\$.  If we had made the pairs \$(7,10), (11,11)\$ the cost would have been \$3+0 = 3\$.  If we had made the pairs \$(7,11), (11,10)\$ the cost would have been \$4+1 = 5\$.
As another example take \$X = (7,11,14)\$, \$Y = (2,10,11,18)\$. We can make the pairs \$(7,2), (11,10), (14,11)\$ for a cost of \$9\$.  The pairs \$(7,10), (11,11), (14,18)\$ cost \$7\$.
The task is to write code that, given two sorted arrays of integers \$X\$ and \$Y\$, computes a minimum cost matching.
Test cases
[1, 4],      [2, 10, 11]     => [[1, 2], [4, 10]]
[7, 11],     [2, 10, 11]     => [[7, 10], [11, 11]]
[7, 11, 14], [2, 10, 11, 18] => [[7, 10], [11, 11], [14, 18]]

Will X or Y ever have repeated values?

@Mnemonic No they won't

To be clear, we return the matching with the minimum cost, not the minimum cost.

Can we have more examples?

Can we assume there is only one matching that has minimal cost?

@dylnan No but you only have to output one of them

Can we output all of them?

@dylnan Just one please.

@Arnauld  They can be positive or negative.

What output formats are acceptable? For instance, since X is fixed, can we output only the choices of elements of Y? So in the last example the output would be 10,  11, 18

Why did you design this challenge with Y having more elements than X rather than with Y having the same number as X or more?

@LuisMendo X and Y have already been confirmed as each having no repeats (look up). Also, the no two elements bit just means your pairings are all 1:1 and the example is matching X's 11 to Y's 11.

@msh210 If they have to same number of elements there is a very simple linear time algorithm,.

I said same number or more.

Can we output [[10, 7], [11, 11]] instead of [[7, 10], [11, 11]]?

More regarding Erik's comment above - since the inputs are guaranteed to be sorted isn't it enough just to return the elements being chosen from Y?

@JonathanAllan That's a very good point and I agree.

Jelly, 15 14 12 11 bytes
Œ!ż€IASƊÞḢṁ

Try it online!

-1 byte thanks to Jonathan Allan
-1 byte thanks to Mr. Xcoder
-2 bytes thanks to an anonymous editor

Brute force. Takes input as \$Y\$ then \$X\$.
Œ!ż€IASƊÞḢṁ
Œ!                 All permutations of Y.
  ż€               Zip each of the permutations with X.

       ƊÞ          Sort by:
    I              Difference of each pair.
     A             Absolute value.
      S            Sum.
         Ḣ         Take the first matching.
          ṁ        Mold the result like X. Keeps only values up to the length
                   of X which removes unpaired values from Y.

Would L} work in place of ⁹L¤?

@Mr.Xcoder Yes, thanks!

ÐṂḢ -> ÞḢ to save a byte.

Brachylog, 16 bytes
∧≜I&pᵐz₀.-ᵐȧᵐ+I∧

Try it online!
Explanation
∧
 ≜I                   Take an integer I = 0, 1, -1, 2, -2, 3, -3, …
   &pᵐ                Permute each sublist
      z₀.             Zip the sublists together. The result of the zip is the output
         -ᵐȧᵐ         Absolute differences of each pair
             +I       The sum of these differences must be I
               ∧

Since we unify I to an integer at the very beginning, we try things from small values of I to large values of I, which means the first time it will succeed will necessarily be for the pairing with smallest absolute differences.

Haskell, 78 77 76 bytes
import Data.Lists
(argmin(sum.map(abs.uncurry(-))).).(.permutations).map.zip

TIO doesn't have Data.Lists, so no link.
Basically the same algorithm as seen in @dylnan's answer.
Edit: -1 byte thanks to @BMO.

JavaScript (ES7), 121 bytes
Takes the 2 arrays in currying syntax (x)(y).
x=>y=>(m=P=(b,[x,...a],s=0,o=[])=>1/x?b.map((v,i)=>P(b.filter(_=>i--),a,s+(x-v)**2,[[x,v],...o])):m<s||(r=o,m=s))(y,x)&&r

Try it online!

J, 24 bytes
[,.[-[:,@:(0{]#~1>])"1-/

Try it online!
Explanation/Demonstration:
A dyadic verb, x f y
-/ finds the differences
 7 11 14 -/ 2 10 11 18
 5 _3 _4 _11
 9  1  0  _7
12  4  3  _4

(0{]#~1>])"1 for each row keep only the non-positive values and take the first one:
   7 11 14 ([:(0{]#~1>])"1-/) 2 10 11 18
_3 0 _4

[:,@: flattens the list (to match the shape of the left argument)
[- subtract the min. differences from the left argument
    7 11 14 ([-[:,@:(0{]#~1>])"1-/) 2 10 11 18
10
11
18

[,. stitch them to the left argument:
   7 11 14 ([,.[-[:,@:(0{]#~1>])"1-/) 2 10 11 18
 7 10
11 11
14 18

MATL, 16 bytes
yn&Y@yy&1ZP&X<Y)

Inputs are X, then Y.
The matching is output with the first values of each pair (that is, X) in the first line, and the second values of each pair in the second line.
Try it online! Or verify all test cases.
Explanation
y       % Implicit inputs: X, Y. Duplicate from below
        % STACK: [7 11], [2 10 11], [7 11]
n       % Number of elements
        % STACK: [7 11], [2 10 11], 2
&Y@     % Variations without repetition
        % STACK: [7 11], [2 10; 2 11; 10 2; 10 11; 11 2; 11 10]
yy      % Duplicate top two elements
        % STACK: [7 11], [2 10; ...; 11 10], [7 11], [2 10; ...; 11 10]
&1ZP    % Compute cityblock distance between rows of the two input matrices
        % STACK: [7 11], [2 10;...; 11 10], [6 5 12 3 13 5]
&X<     % Argmin (first index of occurrences of the minimum)
        % STACK: [7 11], [2 10; 2 11; 10 2; 10 11; 11 2; 11 10], 4
Y)      % Row indexing. Implicit display
        % STACK: [7 11], 10 11]

Octave, 66 bytes
@(X,Y)[X;C([~,r]=min(sum(abs(X-(C=perms(Y)(:,1:numel(X)))),2)),:)]

Anonymous function that takes row vectors X, Y as inputs and outputs a 2-row matrix where each column is a pair of the matching.
Try it online!

Pyth, 18 bytes
t#h.msaMbm.T,dvz.p

Try it here!

Pyth, 16 bytes
hosaMNCM*.pQ.cEl

Try it online here, or verify all test cases at once here.
hosaMNCM*.pQ.cEl   Implicit: Q=evaluated 1st input, E=evaluated 2nd input
               l   Length of 1st input (trailing Q inferred)
            .cE    All combinations of 2nd input of the above length
         .pQ       All permutations of 1st input
        *          Cartesian product
      CM           Transpose each of the above
 o                 Order the above using:
   aMN               Take the absolute difference of each pair
  s                  ... and take their sum
h                  Take the first element of the sorted list, implicit print

Jelly, (10?) 12 bytes
10 bytes if just the elements of Y are required (see comments) - not sure if it's allowed by spec yet though (and maybe it shouldn't be since other answers already implement this detail).
This may be achieved by removing the trailing ⁸ż.
Lœc@ạS¥Þ⁸Ḣ⁸ż

A dyadic link accepting X on the left and Y on the right.
(œc⁹L¤ạS¥ÞḢż@ and the 10 byte œc⁹L¤ạS¥ÞḢ do the same with Y on the left and X on the right).
Try it online!
How?
Lœc@ạS¥Þ⁸Ḣ⁸ż - Link: sorted list of integers X, sorted list of integers Y
L            - length
   @         - with swapped arguments:
 œc          -   combinations (chosen as if picked left-to-right
             -      e.g. [2,5,7,9] œc 2 -> [[2,5],[2,7],[2,9],[5,7],[5,9],[7,9]] )
        ⁸    - chain's left argument (to be on right of the following...)
       Þ     -   sort by:
      ¥      -     last two links as a dyad:
    ạ        -       absolute difference (vectorises)
     S       -       sum
         Ḣ   - head (since sorted this is just the first minimal choices from Y)
          ⁸  - chain's left argument
           ż - zip with (the chosen Y elements)

JavaScript (ES7), 100 bytes
New here; any tips/corrections would be appreciated! A previous attempt overlooked complications with sorting an array containing a NaN value, so hopefully I haven't missed anything this time.
(x,y,q=Infinity)=>y.map((u,j)=>(p=0,s=x.map((t,i)=>(u=y[i+j],p+=(t-u)**2,[t,u])),p)<q&&(q=p,r=s))&&r

Expects two arguments as X, Y, respectively.
Try it online!
Appears to be similar to @Arnauld's solution
Explanation
Relies on the fact that given X, Y are sorted, there exists a solution of
minimum cost matches where if all pairs are arranged to preserve the order of
elements of X, all Y elements in the arrangement also preserve their order.
(x, y, q = Infinity) =>
    y.map((u, j) =>                   // iterate over indices of y
        (
            p=0,
            s=x.map((t, i) => (       // map each element of x to...
                    u = y[i+j],       // an element of y offset by j
                    p += (t-u)**2,    // accumulate the square of the difference
                    [t, u]            // new element of s
                )),
            p
        ) < q                         // if accumulated cost less than previous cost...
                                      // (if p is NaN, any comparison will return false and short circuit)
        && (q=p, r=s)                 // save cost, pair values respectively
    ) && r                            // return lowest-cost pairs


text:
Pleasanortmanteaus
A portmanteau word is a combination of two words that takes part of each word and makes them into a single new word. For example, lion + tiger => liger.
Let's write a program to generate portmanteaus from a pair of input words. Computers aren't the best at English, so we'll need to establish some rules to ensure that the output portmanteaus are pleasant to the eye and ear.
(Examples here are shown with a separator between the prefix and suffix for clarity: li|ger. However, the program's actual outputs should not have a separator: liger.)

Each portmanteau will consist of a nonempty prefix of the first word concatenated to a nonempty suffix of the second word: yes to li|ger, no to |iger.
If the prefix ends with a vowel, the suffix must start with a consonant, and vice versa: yes to lio|ger or l|er, no to lio|iger or l|ger. You may decide whether to count y as a vowel or a consonant. Your solution must pick one option and stick with it, however.
The resulting word must not contain either of the original words in full: yes to lio|ger, no to lion|iger or li|tiger.

This rule holds even if the portion in question is formed from parts of both words: with input of two + words, output tw|ords is still illegal because it contains the substring words. (The only valid output for this pair would be t|ords.)

Your program or function must take two words and output/return a list of all pleasant portmanteaus that can be formed from those words in that order.
Details

Standard input and output methods apply. Standard loopholes are forbidden.
Words will consist only of lowercase letters (or, if you prefer, only of uppercase letters).
You may take the two input words as a list, tuple, two separate inputs, a single string with a non-letter delimiter, etc.
Output format is similarly flexible; if you return or output a string, it should be delimited such that it's clear where one portmanteau word ends and the next one begins.
There should be no delimiters inside a portmanteau word.
It's okay if your output list includes duplicate results; it's also okay to remove duplicates.

Test cases
> lion, tiger
< liger, ler, liger, lir, lioger, lior

> tiger, lion
< tion, ton, tin, tigion, tigon, tigen

> spoon, fork
< sork, spork, spork, spok, spoork, spook

> smoke, fog
< sog, smog, smog, smokog

> gallop, triumph
< giumph, gumph, gariumph, gamph, gaph, gah, galiumph, galumph, galliumph, gallumph, galloriumph, gallomph, galloh

> breakfast, lunch
< bunch, brunch, brench, brech, breh, breanch, breach, breah, breakunch, breakfunch, breakfanch, breakfach, breakfah, breakfasunch

> two, words
< tords

> harry, ginny (if y is treated as a consonant)
< hinny, hanny, hany, hay, harinny, harrinny

> harry, ginny (if y is treated as a vowel)
> hinny, hy, hanny, hany, harinny, hary, harrinny

Reference solution
Here's a reference solution in Pip (treats y as a consonant).

This is code-golf: the shortest answer in each language wins!

Related. More distantly related.

must the delimiter be constant or can i put a bunch of spaces between the words?

@AsoneTuhid Sure, variable amounts of whitespace would be an acceptable delimiter. The only requirement is that "it's clear where one portmanteau word ends and the next one begins."

05AB1E, 28 bytes
y is a vowel (same byte count as consonant though).
нη¨sθ.s¨âʒ`нsθ‚žOsåË_}Jʒs¢Z_

Try it online!
or as a slightly modified Test Suite

Nice answer! Funny how there are quite a few options for the last filter, but unfortunately all the same byte-count.. ʒs¢Z_; ʒsåO_; ʒsм__; etc.

Retina, 72 bytes
L$w`(?<=[aeiou]()|.())((.+),(.+))\B(?!\4)(?<!\5\3)(?([aeiou])\2|\1)
$`$'

Try it online!

Bah, I had got as far as Lw$`(?<=[aeiou])(.+),(.+)(?<!^\2\1,\2)(?!\1)(?=[^aeiou])|(?<=[^aeiou])(.+),(.+)(?<!^\4\3,\4)(?!\3)(?=[aeiou]) but I couldn't concentrate on golfing it because of a headache.

My first attempt was quite similar, although I avoided repeating the centre part by checking the vowel/consonant thing at the end with something like (?=.(?<=[aeiou]\1[^aeiou]|[^aeiou]\1[aeiou])) and then needed probably at least six iterations to get it down to where it is now.

(The ^s in my previous comment are erroneous) Indeed, I would never have thought of that ()|.() trick, I would have probably stopped at Lw$`(?<=([aeiou])|.)((.+),(.+))(?<!\4\2)(?!\3)(?=(?(1)[^aeiou]|[aeiou])).

Japt, 32 bytes
å+ ïVw å+)f_xè"%v$" uÃmrÈ+YwÃkøN

Japt Interpreter
Saved 10 bytes thanks to Shaggy's clearer understanding of Japt's syntax.
Saved 8 bytes due to a new language feature
Saved 2 byte thanks to some suggestions from ETHproductions
The newest version of Japt introduced the Cartesian Product function, which saved quite a few bytes and allowed me to restore the ordering of inputs (so "lion" "tiger" outputs "liger" and such). "y" is still treated as a consonant.
Explanation:
   ï     )       Cartesian product of...
å+                prefixes of first input
    Vw å+         and suffixes of second input.

f_         Ã     Remove the ones where...
  xè"%v$"         the number of vowels at the joining point
          u       is not 1.

m     Ã          Replace each pair with...
 rÈ+Yw            the prefix and suffix joined together
       køN       then remove the ones that contain either input

Welcome to Japt (again!). I can definitely see some potential for more golfing here; I'll have a proper look at it when I get back to a computer.

A few quick savings for you from my phone.

Pyth, 38 bytes
f!s}RTQm+hd_edfxFm}ed"aeiou"T*._hQ.__e

Input is a list of the two words, and y isn't treated as a consonant.
Try it online here, or verify all test cases at once here.
f!s}RTQm+hd_edfxFm}ed"aeiou"T*._hQ.__e   Implicit: Q=eval(input())
                                hQ       First input word
                              ._         All prefixes of the above
                                     e   Second input word (Q inferred)
                                  .__    Reverse, take all prefixes
                             *           Cartesian product of the above
              f                          Filter the above using:
                 m          T              Map d in the current element using:
                   ed                        The last letter of the word part
                  }  "aeiou"                 Is it contained in the vowel list?
               xF                          Take the XOR of the list
                                         (This ensures that the word parts meet at one consonant)
       m                                 Map d in the filtered set using:
        +hd_ed                             Add the first part to the reversed second part
f                                        Filter the above using:
  s}RTQ                                    Does the portmanteau contain either of the input words?
 !                                         Logical NOT (remove from list if the above is true)

Java 8, 228 225 215 bytes
v->w->{String r="",t,p=" aeiou";for(int i=w.length(),j;--i>0;)for(j=1;j<v.length();)r+=(t=v.substring(0,j)+w.substring(i)).matches(v+".*|.*"+w)|p.indexOf(t.charAt(j-1))*p.indexOf(t.charAt(j++))>0?"":t+" ";return r;}

Takes two Strings in currying syntax and returns a String. Treats y as a consonant. Try it online here.
Thanks to DLosc for golfing 2 bytes.
Ungolfed:
v -> w -> { // lambda taking two String parameters in currying syntax
    String r = "", // result
    t, // temporary variable used for storing
       // the portmanteau candidate currently being evaluated
    p = " aeiou"; // vowels for the purposes of this function;
                  // the leading space is so that they all have a positive index
    for(int i = w.length(), j; --i > 0; ) // loop over all proper suffixes
                                          // of the second word
        for(j = 1; j < v.length(); )      // loop over all proper prefixes
                                          // of the first word
            r += // construct the portmanteau candidate
                 (t = v.substring(0, j) + w.substring(i))
                 // if it contains one of the input words ...
                 .matches(v + ".*|.*" + w)
                 // ... or the boundary is consonant-consonant
                 // or vowel-vowel (here we make use of the facts
                 // that all the vowels have a positive index, and
                 // indexOf() returns -1 in case of no match) ...
                 | p.indexOf(t.charAt(j-1)) * p.indexOf(t.charAt(j++)) > 0
                 ? "" // ... reject it ...
                 : t + " "; // ... else add it to the result
    return r; // return the result
}

Python 3, 156 150 bytes
I've considered y as a consonant.
lambda a,b:{a[:i]+b[j:]for i in range(1,len(a))for j in range(1,len(b))if((a[i-1]in'aeiou')^(b[j]in'aeiou'))*0**(a in a[:i]+b[j:]or b in a[:i]+b[j:])}

-6 bytes thanks to Jonathan Frech
Try it online!

Possible 150 bytes.

@JonathanFrech thanks for spotting it

You can use default arguments in lambda x=0 to get it down to save... 0 characters, annoyingly. lambda a,b,v='aeiou',r=range:{a[:i]+b[j:]for i in r(1,len(a))for j in r(1,len(b))if((a[i-1]in v)^(b[j]in v))*0**(a in a[:i]+b[j:]or b in a[:i]+b[j:])} (Still 150)

JavaScript (ES6), 124 bytes
Takes the 2 words in currying syntax (a)(b) and prints the results with alert(). Assumes y is a consonant.
a=>b=>[...a].map(c=>[...b].map((C,j)=>!(w=s+b.slice(j)).match(a+'|'+b)&v.test(c)-v.test(C)&&alert(w),s+=c),s='',v=/[aeiou]/)

Try it online!

Python 2, 179 176 166 162 bytes
lambda s,t:[w for w in g(s,t)if(s in w)<1>(t in w)]
g=lambda s,t:s[:-1]and[s[:-1]+t[j:]for j in range(1,len(t))if(s[-2]in'aeiou')^(t[j]in'aeiou')]+g(s[:-1],t)or[]

Try it online!
3 bytes from Jonathan Frech. And 10 bytes thx to The Matt.
In my world, y is not a vowel. (It's a yowl!)

There are stray spaces in t) if and t) or [].

@Jonathon Frech: Thanks! Got a bit lazy there...

I see ... I presume you also got a bit lazy whilst typing my name :P

*JonathAn: D'oh! Well, at least I was consistent! :)

You can replace all(w.find(u)<0for u in(s,t)) with (s in w)==0==(t in w) for 166 bytes. Try it online!

@The Matt: Thanks! Actually, I squeezed an additional 2 bytes out via (s in w)<1>(t in w).

Jelly, 27 bytes
¹Ƥp¹ÐƤ}Ø.ị"e€Øc⁻/ƲƇẎ€wÐḟƒ@,

Try it online!
Yy is a consonant. Both cases supported. Returns duplicates.
Output has been prettified over TIO. Remove +/€ from the footer to see the actual output.

C++ 11, 217 202 bytes
[](auto v,auto w){auto r=v,t=v,p=v;r="",p="aeiou";for(int i=w.size(),j;--i;)for(j=v.size();j;)(t=v.substr(0,j)+w.substr(i)).find(v)+1|t.find(w)+1|p.find(t[j-1])<5==p.find(t[j--])<5?v:r+=t+" ";return r;}

Makes heavy use of std::string#find. Treats y as a consonant. Try it online here.
Ungolfed:
// lambda; relies on auto to keep declarations short
[] (auto v, auto w) {
    // let's declare some strings. To keep it terse, we're using auto and the type of the arguments.
    auto r = v, // result string
    t = v,      // temporary string for storing the portmanteau candidate
    p = v;      // vowels string
    // now assign them their values
    r = "",    // result starts empty
    p = "aeiou"; // vowels don't include 'y'
    for(int i = w.size(), j; --i; ) // suffixes of the second word
        for(j = v.size(); j; ) // prefixes of the first word
            // create the portmanteau candidate
            (t = v.substr(0, j) + w.substr(i))
            // if it includes one of the input words ...
            .find(v) + 1 | t.find(w) + 1
            // ... or the boundary is consonant-consonant or vowel-vowel ...
            | p.find(t[j - 1]) < 5 == p.find(t[j--]) < 5
            ? v // ... discard it ...
            : r += t + " "; // ... else add it to the result.
    return r; // return the result
}

Emacs Lisp, 306 + 13 = 319 bytes
+13 for (require'seq)
(require'seq)(lambda(a b)(dotimes(i(1-(length b)))(dotimes(j(1-(length a)))(progn(setq w(substring a 0(1+ j))x(substring b(1+ i))c(concat w x))(defun V(c)(seq-contains"aeiou"(elt c 0)'char-equal))(if(not(or(string-prefix-p a c)(string-suffix-p b c)))(if(V(substring w -1))(if(not(V x))(print c))(if(V x)(print c))))))))

Try It Online!
Defines an anonymous lambda function. Outputs a sequence of newline-separated portmanteaus with each one surrounded by quotes. Golfing tips are welcome. The letter y is considered a consonant.
Ungolfed
(require 'seq)
(defun Portmanteus(word1 word2)
  "Find all valid portmanteus of the two given words"
  (dotimes (i (1- (length word2)))
    (dotimes (j (1- (length word1)))
      (progn
        (setq w (substring word1 0 (1+ j)) w2 (substring word2 (1+ i)) comb (concat w w2))
        (defun isVowel (c) (seq-contains "aeiou" (elt c 0) 'char-equal))
        (if (not (or (string-prefix-p word1 comb) (string-suffix-p word2 comb)))
          (if (isVowel (substring w -1))
            (if (not (isVowel w2))
              (princ (format "%s\n" comb))
            )
            (if (isVowel w2)
              (princ (format "%s\n" comb))
            )
          )
        )
      )
    )
  )
)

Ruby, 113 112 109 104 bytes
y is a consonant
This outputs the same duplicates as the examples in the question, I must be using the same loop
->a,b,i=j=1{r=a[0,i]+b[j..-1];g=:aeiou;!g[a[i-1]]^g[b[j]]|r[a]|r[b]||z=[*z,r];b[j+=1]||a[i+=j=1]?redo:z}

Try it online!


text:
Saddle points in a matrix
A matrix can be thought of as the altitudes of a surface in 3D space.
Consider the 8 neighbours (orthogonal and diagonal) of a cell as a cyclic sequence in clockwise (or anticlockwise) order. Some neighbours may be higher than the original cell, some lower, and some levelled at the same height as the original cell. We split the cycle of neighbours into segments according to that property and discard the levelled segments. If we end up with exactly 4 segments alternating between higher and lower, we call the original cell an order-2 saddle point. Boundary cells (edges and corners) are never considered to be saddle points. Your task is to output the number of order-2 saddle points in a given matrix.
For instance, in the matrix
3 3 1
4 2 3
2 1 2

the central cell's neighbours in clockwise order are
3 3 1 3 2 1 2 4
+ + - +   -   +  // + for higher, - for lower
a a b c   d   a  // segments

Note that the list is cyclic, so we consider the final 4 part of the initial segment a. The signs of segments abcd are alternating - this is indeed a saddle point.
Another example:
1 7 6
5 5 5
2 5 6

Neighbours:
1 7 6 5 6 5 2 5
- + +   +   -
a b b   c   d

We have 4 +/- segments but their signs are not alternating, so this is not a saddle point. Note how segment b is separated from segment c by a levelled segment. We discard the levelled segment, but b and c remain separated. Same goes for d and a.
Third example:
3 9 1
8 7 0
3 7 8

Neighbours:
3 9 1 0 8 7 3 8
- + - - +   - +
a b c c d   e f

The signs are alternating but the number of +/- segments is 6. This is known as a monkey saddle or an order-3 saddle point. For the purposes of this challenge we should not count it.
Write a function or a complete program. Input is an integer matrix as typically represented in your language. It will consist of integers between 0 and 9 inclusive. Output is a single integer. Standard loopholes are forbidden. The shortest solution per language wins, as code-golf (obviously?) indicates.
in                                   out

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

[[1,7,6],[5,5,5],[2,5,6]]             0

[[3,9,1],[8,7,0],[3,7,8]]             0

[[3,2,3,9,0,4,2,1,9,9,1,4,8,7,9,3],
 [1,1,5,7,9,9,0,9,8,9,9,8,8,9,0,5],
 [5,8,1,5,1,6,3,5,9,2,5,6,9,0,7,5],
 [3,0,2,4,7,2,9,1,0,0,7,2,4,6,7,2],
 [6,7,1,0,2,7,3,2,4,4,7,4,5,7,3,2],
 [6,5,1,1,6,2,1,2,8,9,4,6,9,7,1,0],
 [1,6,1,8,2,2,7,9,2,0,2,4,8,8,7,5],
 [0,6,5,4,1,3,9,3,2,3,7,2,2,8,5,4]]  19

[[2,3,2,0,8,5,5,1,2,3,7,5,6,0,0,5],
 [4,1,4,9,4,7,3,8,6,8,4,2,8,7,1,7],
 [4,1,4,6,9,3,0,1,0,7,8,5,3,0,5,3],
 [5,6,0,8,0,4,9,3,2,9,9,8,4,0,0,3],
 [7,4,1,6,7,8,7,3,6,1,4,9,4,6,2,0],
 [3,1,6,7,9,7,7,6,8,6,8,1,4,9,7,0],
 [8,9,1,1,2,4,8,2,3,9,8,7,5,3,1,9],
 [0,9,5,3,8,7,7,7,8,9,0,0,2,7,3,4]]  31

[[6,6,2,3,4,6,5,4,9,5,5,1,4,7,7,6],
 [1,5,0,5,6,7,9,8,5,0,5,6,1,5,2,9],
 [0,0,0,6,1,8,1,1,9,0,7,4,5,4,5,5],
 [4,5,3,6,3,8,0,0,7,3,9,1,3,9,2,2],
 [8,8,5,3,7,1,0,7,1,1,8,1,3,0,7,7],
 [4,5,8,0,7,2,0,4,6,7,3,3,2,8,1,2],
 [1,1,6,2,5,8,4,2,6,1,6,9,8,4,8,1],
 [3,9,1,7,0,8,1,1,7,8,5,4,8,2,0,3]]   7

Title: "Saddle points in a matrix". Challenge: "Order-2 saddle points in a matrix".

@EriktheOutgolfer when codegolf draws inspiration from journalism :)

@LuisMendo I have 3 non-golfed solutions in different languages - k, apl, and python, and they all agree. Here's a gist with the locations of the (order-2) saddle points I got for the last test. Can you identify a saddle point that's not there?

@LuisMendo for that point the clockwise neighbours are: 52952294, or relative to the centre: =-+=--+- (+ for higher, etc), so they form five (not four)  non-= segments: -,+,--,+,-. Note that the last - is not in the same segment as the first - as there's a = separating them, like in my second worked example.

@ngn Ah. I hadn't understood that = acted as separator. I was simply disregarding = symbols. Thanks

@LuisMendo I added a couple of sentences to make it more clear.

JavaScript (ES6), 179 bytes
a=>a.map((r,y)=>r.map((v,x)=>t+=x*y/r[x+1]&&a[y+1]?[...(S='12221000')+S].map((n,i)=>p-(p=d=Math.sign(v-a[y+~-n][x+~-S[i+2&7]]))&&d?s&s!=-(s=d)?T=a:T++:0,T=s=p=0)|T>>1==4:0),t=0)|t

Try it online!
How?
We iterate on each cell \$v_{y,x}\$ of each row \$r_y\$ of the input matrix.
We first make sure that we're not located over an edge of the matrix with:
x * y / r[x + 1] && a[y + 1]

(neither \$x\$ or \$y\$ is \$0\$ and both \$v_{y,x+1}\$ and \$r_{y+1}\$ are defined)
We iterate twice on each neighbor cell and keep track of the number of valid segments in \$T\$. By doing this, each segment is guaranteed to be counted twice, except the first one which may be counted either twice or three times, depending on its starting point in relation to the starting point of the cycle. Either way, we have \$\lfloor{T/2}\rfloor=4\$ for order-2 saddle points, in which case we increment the counter \$t\$.
Example:
If the first segment is aligned with the starting point:
neighbor cells: AAAABCCD --> AAAABCCDAAAABCCD
                             ^   ^^ ^^   ^^ ^  --> T = 8

If it is not aligned:
neighbor cells: AABCCDAA --> AABCCDAAAABCCDAA
                             ^ ^^ ^^   ^^ ^^   --> T = 9

We iterate on neighbor cells by starting with the rightmost one and moving clockwise with:
[...(S = '12221000') + S].map((n, i) => a[x + ~-n][y + ~-S[i + 2 & 7]])

Try it online!
We store the sign of the difference between the current cell and its current neighbor in \$d\$. We keep track of the previous value of \$d\$ in \$p\$ and the previous sign (for non-zero values) in \$s\$.
The logic to update \$p\$, \$s\$ and \$T\$ reads as follows:
p - (p = d) && d ? s & s != -(s = d) ? T = a : T++ : 0

In plain English:

Ignore identical consecutive values.
Ignore segments with \$d=0\$.
Increment \$T\$ on valid sign transitions.
Whenever an invalid sign transition is detected, do T = a to force all upcoming operations on \$T\$ to either NaN or \$0\$, thus invalidating the final test.

APL (Dyalog Unicode), 70 66 bytes
D←⊢-1∘⌽
+/,{16=×/|D⍵/⍨×⍵×D⍵}¨(⍉1↓⌽)⍣4×(⊢-{⊂(,⍵)[8(-,⊢)3,⍳3]}⌺3 3)⎕

Try it online!
-4 bytes thanks to @Bubbler and @ngn
Full program that requires ⎕IO←0
⍝ Helper function D: cyclic differences of a list
D←⊢-1∘⌽
  ⊢     ⍝ Each element
   -    ⍝ Subtract
    1∘⌽ ⍝ The one after
⍝ Main code
+/,{16=×/|D⍵/⍨×⍵×D⍵}¨¯2 ¯2↓1⊖1⌽×(⊢-{⊂(,⍵)[6 9 8 7 4,⍳3]}⌺3 3)⎕
⎕           ⍝ The input grid
{...}⌺3 3   ⍝ For the 3×3 window centered on each cell:
 (,⍵)[8(-,⊢)3,⍳3] ⍝ Obtain the cycle elements clockwise from the right
 ⊂                ⍝ Ensure that the output is the same shape as G
×⊢-         ⍝ The sign of the difference between each cycle and its center in G
(⍉1↓⌽)⍣4    ⍝ Trim off the entries with centers on an edge/corner
{...}¨      ⍝ For each sign-difference cycle:
 ×⍵×D⍵      ⍝ The indices where a +/- segment ends
              ⍝ (nonzero and different from the following element)
 ⍵/⍨        ⍝ The signs of each segment in order
              ⍝ (must be ¯1 1 ¯1 1 or reverse to be truthy --- can only have entries +/- 1)
 D          ⍝ Cyclic differences (must be 2 ¯2 2 ¯2 or reverse to be truthy --- can only have entries ¯2, 0, or 2)
 16=×/      ⍝ Test if product is 16: ensures right length and right values.
            ⍝ Note that the sum of the cyclic differences are always 0, so 2 2 2 2 is impossible)
+/,         ⍝ Count the total number that meet the condition

A creative idea I had was taking 2×2 stencils of 2×2 stencils with ({⊂⍵}⌺2 2)⍣2⊢G then extracting cycles with {1⌷⊃,/0 1 2 3{⍉∘⌽⍣⍺⊢⍵}¨,⍵}¨. This might have been shorter (if golfed a bit more) because it didn't initially require ¯2 ¯2↓1⊖1, but unfortunately we still had to subtract corresponding elements of G.

6 9 8 7 4,⍳3 → 10(-,⊢)4,⍳3, ¯2 ¯2↓1⊖1⌽ → (⍉1↓⌽)⍣4. Also, for the alternative, 0 1 2 3{⍉∘⌽⍣⍺⊢⍵}¨⊂x can be ⊢∘⍉∘⌽\4⍴⊂x.

@Bubbler 10(-,⊢)4,⍳3 same length but simpler: ⍎¨⍕69874123. shorter with ⎕io←0: 8(-,⊢)3,⍳3

05AB1E, 66 bytes
gÍF3£D¬gÍFε3£}`R«ćªćU«X.Sγ€Ù˜ÐнsθQsʒ0Ê}©gs-4Q®ü‚€OÄO0Q&ˆ€¦}\\¦D}¯O

I'm 100% sure that I can reduce some bytes here, working on it :) Meanwhile, I'll post this basic idea.
Explenation:
gÍF3£D¬gÍFε3£}`R«ćªćU«X.Sγ€Ù˜ÐнsθQsʒ0Ê}©gs-4Q®ü‚€OÄO0Q&ˆ€¦D}\\¦}¯O
              `R«ćªćU«X.Sγ€Ù˜ÐнsθQsʒ0Ê}©gs-4Q®ü‚€OÄO0Q&ˆ                 Expects a 3x3 matrix. We will run this part for each relevant cell in the overall matrix.
                                                                         Pushes 1 to the global array when this cell is order-2 saddle point, pushes 0 otherwise.
                                                                         ----------
gÍ                                                                       number of rows in the matrix minus 2.
  F                                                            }         Loop Rows-2 times
   3£                                                                    Take 3 first rows.
     D¬                                                                  Push itself and the first element (first line)
       gÍ                                                                Size. (number of columns)
         F                                                 }             Loop Cols-2
          ε3£}                                                           Trim first 3 elements from each of the selected 3 rows.
                                                        €¦D              Remove the first element of each row and duplicate it for the next iteration.
                                                            \\¦          Clear remaining elements on stack, remove current first row of the 3 rows, prepare for next iteration.
                                                                         ----------
              `                                                          Push the 3x3 matrix we got from the nested loop in 3 separate values to the stack. Last row on top.
               R                                                         Reverse last row.
                «                                                        Merge with the second row.
                 ćª                                                      Extract head and append
                   ćU                                                    Extract head and save in X
                     «                                                   Merge with the first row. Now all values of the cell are in order clockwise.
                      X.S                                                For each element in the list, put -1 if lower than X (middle of cell), 0 if equal, 1 if greater.
                         γ                                               Split a into chunks of equal adjacent elements. (segment)
                          €Ù˜                                            Uniquify each element and flat the list.
                             Ð                                           Triplicate
                              нsθQ                                       Extract head, extract tail, are they equal?
                                  sʒ0Ê}©                                 Filter (remove zeros from the list), save the filtered list in register C
                                        g                                Size of the filtered list.
                                         s-                              Size of the filtered list - [1 if head was equal to the tail]
                                           4Q                            Is it equal to 4 (segments)? {{Condition I}}
                                             ®ü‚                         Overlapping pairs
                                                €O                       Sum each pair (desired: [-1,1] or [1,-1] will give 0)
                                                  Ä                      Abs(a)
                                                   O0Q                   Is the sum of all sums of pairs equals 0? (which means there was alternating 1/-1) {{Condition II}}
                                                      &                  Does both of the conditions were okay?
                                                       ˆ                 Push the result to the global array.
                                                                         ----------
                                                                ¯O       Push the global array and sum its values to get the number of order-2 saddle points.

Try it online!

Python 2, 254 bytes
lambda m:sum(s(m[i][j:j+3],m[i+1][j:j+3],m[i+2][j+2::-1][:3])for j in range(len(m[0])-2)for i in range(len(m)-2))
t=['-','+']*2
def s(q,(x,m,y),w):a=''.join(' -+'[cmp(m,v)]for v in q+[y]+w+[x]);return[v for v,_ in zip(a,a[-1:]+a)if' '!=v!=_]in(t,t[::-1])

Try it online!

Ruby, 237 218 207 bytes
->a,z=0,i=j=1{l=z+=1if[[*a[i-1][h=j-1,3],(x=a[i])[j+1],*a[i+1][h,3].reverse,x[h]].map{|n|l=n<=>x[j]}.drop_while{|i|i==l}.map{|b|b==l||(l=b)==0?5:l}-[5]]-[[1,-1]*2,[-1,1]*2]==[];x[1+j+=1]||a[1+i+=j=1]?redo:z}

Try it online!


text:
Filthy and Unique
In this question I will talk about programs as strings, this is strings of bytes, not characters.  How your resultant program is rendered or displayed is not important to this challenge, only how it appears in memory matters.
A pristine program is a program \$S\$ that when run does not error, however it will error whenever a continuous substring of size \$n\$, where \$1\leq n < \left|S\right|\$, is removed.
A filthy program is the opposite, it is a program \$S\$ that when run does error, however whenever a continuous substring of size \$n\$, where \$1\leq n < \left|S\right|\$, is removed, it does not error.
For this challenge an error is non-empty output to STDERR.
Your challenge is to write a filthy program that uses as many unique bytes as possible.  This means you will get one point for every unique byte that appears in your code with a larger score being better.  The maximum score is thus 256.

Is it even possible to answer this in languages that involve brackets/parentheses? It would be possible to remove some substring from code so that there would be mismatched brackets.

@JungHwanMin If the language enforces balanced parentheses I would suspect that it would be impossible.

@CatWizard so a filthy program does not error when a continuous substring of characters (i.e. not continuous set of bytes) is removed, correct?

@JungHwanMin Sorry.  It may or may not.  We only care about continuous strings.

What's the intention of the first paragraph of the question ("this is strings of bytes, not characters")? Is it to say individual bytes have to be removable and the program should still work? For eg., if I used π in my program, does it have to work when individual bytes of it (0xcf and 0x80) are removed?

@sundar The intention of the first paragraph is to make clear that it doesn't matter what characters your program encodes, only what is actually encoded.  If you use π in your program you are using two bytes, it doesn't matter that they only display as one character under some encodings, they are separate bytes, and are treated no different than for example a% which is also two bytes.

Does leading or trailing whitespace count towards the bytes?

@ngm Yes it does.

"For this challenge an error is a non-empty output to STDERR". Compiler errors count as well, right?

@Jakob Yes, both compiler errors and runtime errors both count.

This script generates all the programs necessary to check

@ConorO'Brien maybe there is a way to do that with Bash on TIO to test them automatically? I don't know Bash or if there is a try and except construct.

@dylnan Bash can check for exit code, but that won't work for languages which doesn't use exit code to indicate error. However if it's possible to do it natively it's often faster.

Unary, 14 bytes
123456789ABCDE

This encodes the brainfuck program [, which errors due to unmatched brackets.
Removing bytes will result in >, <, +, -, ., , or the empty program, which are valid brainfuck programs.

This is the optimal solution, since any longer solution could be reduced to this solution, which errors

This is also the only solution.

R, 3 bytes
qrt

Try it online!
A name of an object is a valid program in R.
qrt is not the name of anything, so it returns an error.
q is the quit function
qr is the QR decomposition function
rt is the t distribution sampling function
qt is the t distribution inverse CDF
t is the transpose function

@pajonk but "r" is a continuous substring. Removing that leaves "qt"

There is exactly one filthy program in R of length 3, and this is it! (the only single char valid programs are 0-9cqtCDFIT, any program must therefore start with cm, qf, qr, qt, ts or Im. The length three possibilities are qrf,qrm,qrt,qts and tsd and only one of these is filthy (the others can't be extended either to make them filthy as there are no functions rm*,rf*,ts*,sd*)

@Orphevs my bad, misread the challenge.

Note that, following Arnauld's strategy (see 'Polyglot' answer), there are actually 101  filthy programs in R of length 3: this one, plus 100 more of the form 1  2 (where each of the two digits can be substituted with any of the other 9 possible digits).

Jelly, 4 5 6 7 8 10 11 bytes
“a”;⁽PFð+µU

Try it online!
Verify it.
Tries to add a string with an integer.
Some of the possible subprograms:
“a” is a string literal.
“a is the same string literal.
“ is the empty string.
“a”; concatenates "a" with itself.
...too many to enumerate them all.

Fortunately Jelly still allows you to error.

Polyglot, 3 bytes
1 2

Works in:

JavaScript
Ruby
R
Octave
GHCi
Julia

In JavaScript, throws SyntaxError: unexpected token: numeric literal or a similar error.
All other strings are valid numeric literals (1, 2, or 12).

In GHCi this throws
<interactive>:1:1: error:
    • Non type-variable argument in the constraint: Num (t1 -> t2)
      (Use FlexibleContexts to permit this)
    • When checking the inferred type
        it :: forall t1 t2. (Num t1, Num (t1 -> t2)) => t2

This is because it tries to apply 1 to 2 as a function, however it cannot.  When any part of this is removed it simply becomes a numeric literal.

Polyglot: R, Octave, Ruby, the Pythons...

@ngm GHCi as well, however  2 errors in python.

I suspected that it was very generic. I've turned this into community wiki, so feel free to edit with all languages for which this works!

Python 2/3, 3 bytes
4\f2

OR
4\x0c2

Try it online!
In python "\f" is the same as "\x0c" and is a form feed character. This means that it indicates for a printer to go to the next line.
If a python expression starts or ends with \f, it is basically ignored so \f2 is a valid expression.
The 4 and 2 can be any number 0-9. However, for the first byte to be 0 is only valid in Python 2.7.15, as 02 was made a legal declaration of 2.
So the expression itself fails with a Syntax Error, because there are two numbers separated by a whitespace. However, any shortening either puts \f at the beginning or end, where it doesn't matter, or it creates 42 which is valid.
(It is worth noting that in IDLE this file opens looking like "42".)
Form feed explanation source: https://stackoverflow.com/a/26184126

This would be easier to understand if you used the actual code in the source without the \f.  Here is a try it online link from which you can get a pre-formatted answer.

I have added it as a variant for clarification. Also, thank you for the suggestion of the link.

Python 2, 2 bytes
Unexpected character after line continuation character
\0

\ followed by any of 123456789 #
Try it online!
Invalid octal number
08

0 followed by any of 89
Try it online!
Unexpected Indent
 0

  or \t followed by any of 123456789\
Try it online!

Dyalog APL, 5 bytes (SBCS)
~≢0 1

Try it online!
or
test all the possible programs
There sure are better boring answers, but this is the best non-boring one I've found
SBCS is required as Dyalog Classic seems to always have output in STDERR, making it unusable.

Zsh, 2 bytes
:#
Attempt This Online!
Zsh is very good at producing errors, so this challenge is very hard.

: on its own is command which does nothing
# is a comment
:# is a single command, which doesn't exist, and therefore errors. (# is only a comment when it's at the start of a word)


text:
Draw a descendant pyramid (addition)
Challenge
Given a sequence of non-negative integers, create a function that output a descendant pyramid where the children are the sum of both parent numbers.
The result is outputted as an string using tab \t.
Note: trailing tabs on each line are not required
1\t\t2\t\t3\n\t3\t\t5\t\n\t\t8\t\t results in
1       2       3
    3       5
        8

Optionally result can be outputted as an array using an empty position as space.
[[1,,2,,3],
[,3,,5,],
[,,8,,]]

Example:
Given 4,5,7,3,4,2 Output:
4       5       7       3       4       2
    9       12      10      7       6
        21      22      17      13
            43      39      30
                82      69
                    151

Rules

Standard code-golf rules apply
Input can be a string using any separator or an array
Leading/trailing newlines and tabs are permitted (but not required as long as the output is an inverted pyramid)

Test Cases
Input: 1,3,5

1       3       5
    4       8
        12

Input: 9,8,7,6,5

9       8       7       6       5
    17      15      13      11
        32      28      24
            60      52
                112

Input: 5,5,2,5

[[5,,5,,2,,5],
[,10,,7,,7,],
[,,17,,14,,],
[,,,31,,,]]

Input: 3,3,3

[[3,,3,,3],
[,6,,6,],
[,,12,,]]

Winning criteria is code-golf

Note: This challenge is very close to Generate Pascal's triangle. The difference is the custom starting sequence (pascal goes from 1 and in ascendant mode, this from an input and in descendant mode).
Sandbox post

Somewhat related.

non-negative integers do we have to handle 0? There are some golfing possibilities if empty spaces are filled with 0s.

May we return an array with tabs or empty strings/arrays in the empty positions?

@Adám Yes. Anything that represents emptiness

"using an empty position as space" what is an "empty position" here? May these be space characters or negative numbers? I ask since many languages with array-like containers don't have such a concept I believe. EDIT - it seems your answer to Adám probably addresses this.

@JungHwanMin Unfortunately yes, your function/program must handle 0

@JonathanAllan empty position can be an empty space, null, undefined, etc anything but integer

"Leading/trailing newlines and tabs are permitted" - May we include empty result(s) at the bottom in the array output too?

@JonathanAllan trailing newlines and tabs are permitted

@Adám question adjusted to be less generic :)

05AB1E, 15 14 bytes
-1 bytes thanks to Kevin Cruijssen
vD„		ý'	N×ì,ü+

Try it online!

That's a lot of spaces... tabs?

...or zero spaces and a few tabs :p

Indeed, those are tabs :)

gF can be v for -1.

Jelly,  14  13 bytes
14 -> 13 assumes trailing spaces-only entry is allowed in the list format output; if not I shall revert to the 14 (asked)
+ƝƬK€z⁶Zṙ"JC$

A monadic link. Output is a list of lists using space characters as the spaces (includes a single trailing spaces-only entry).
Try it online! (includes a footer to show the list structure since running the monadic link as a full program will print smashed output implicitly.)

APL (Dyalog Unicode), 31 28 bytesSBCS
Tacit prefix function. Uses a single space as empty slot marker. Returns list of lists of numbers/spaces.
⍳∘≢{∊(⍺⍴''),,∘' '¨2+/⍣⍺⊢⍵}¨⊂

Try it online!
⍳∘≢{…}¨⊂ apply the below function for each of
⍳ the ɩndices ∘ of ≢ the tally with
⊂ the entire argument:
 ⊢⍵ yield the right argument (the original input)
 2+/⍣⍺ apply pairwise sum as many times as indicated by the left argument
 ,∘' '¨ append a space to each number
 (…), append that to the following:
  ⍺⍴'' left-argument elements of the empty string (padded with spaces)
 ∊ ϵnlist (flatten)

Wolfram Language (Mathematica), 74 bytes
ArrayPad[Riffle[#,],k++,]&/@NestList[k=0;BlockMap[Tr,#,2,1]&,#,Tr[1^#]-1]&

Try it online!

Husk, 22 bytes
zoΣ~+R"	"oJ"		"msNU¡Ẋ+

Try it online!
Explanation
z(Σ~+R" "(J"  "ms))NU¡Ẋ+  -- example input: [1,2,3]
                     ¡    -- infinitely do and collect in list
                      Ẋ+  -- | sum adjacent
                          -- : [[1,2,3],[3,5],[8],[],[],...
                    U     -- keep up until first repetition: [[1,2,3],[3,5],[8],[]]
z(                )N      -- zip with natural numbers under (example on 1 [1,2,3])
   ~+    (       )        -- | join arguments modified by
     R" "                 -- | | replicate tab: " "
               ms         -- | | show each: ["1","2","3"]
          J"  "           -- | | join with 2 tabs: ["1","  ","2","  ","3"]
                          -- | : [" ","1","  ","2","  ","3"]
  Σ                       -- | concatenate: " 1  2  3"
                          -- : [" 1  2  3","  3  5","   8"]

JavaScript (ES6), 73 bytes
Weird source code ... Anyway, that's code-golf!
Includes leading and trailing whitespace.
f=(a,p=`
`)=>p+a.join`		`+(1/(y=a.shift())?f(a.map(x=>y+(y=x)),p+`	`):'')

Try it online!

Python 3, 101 93 80 bytes
Saved 7 bytes (map(str,x) instead of for in and init y as '') and got rid of the trailing newlines (x and[ instead of print(), thanks to Jo King.
Saved 13 bytes ([*map(sum,zip(x,x[1:]))] instead of [x[j]+x[j+1]for j in range(len(x)-1)]) thanks to ovs.
f=lambda x,y='':x and[y+'		'.join(map(str,x))]+f([*map(sum,zip(x,x[1:]))],y+'	')

Try it online!

@ovs: Ah, cool. I should have realized I could map the sum. Thanks!

Perl 5 -a, 62 bytes
$,="\t\t";do{say"\t"x$i++,@F;map$_+=$F[++$q[@F]],@F}while$#F--

Try it online!

Retina, 35 bytes
+¶<`\d+ *(?=(\d+)?)
    $#1*$.(*_$1*)

Try it online! Explanation:
+

Repeat until the buffer stops changing,
¶<`

Print the contents of the buffer before the substitution, with a trailing newline, and
\d+ *(?=(\d+)?)
    $#1*$.(*_$1*)

Substitute a single number with a pair of tabs, but a number followed by another number with a tab, the sum, and another tab.

Perl 6, 50 48 bytes
{$_,{say "	"x$++~.join("		");$_[1..*]Z+@$_}...0}

Try it online!
Anonymous code block that takes a list of integers and prints the inverted pyramid.

C (clang), 112 109 bytes

-3 from @ceilingcat

j,k;f(*i,c){for(j=c;j;j-=puts("")){for(k=c-j;k--;)putchar(9);for(;++k<j;i[k]+=i[k+1])printf("%d\t\t",i[k]);}}

Try it online!

Red, 151 bytes
func[b][m: length? b repeat n m[loop n - 1[prin"^-"]print replace/all
form b" ""^-^-"c: copy[]repeat i -1 + length? b[append c b/(i) + b/(i + 1)]b: c]]

Try it online!
More readable:
f: func [ b ] [
    m: length? b
    repeat n m [
        loop n - 1 [ prin tab ]
        print replace/all form b " " rejoin [ tab tab ]
        c: copy []
        repeat i (length? b) - 1 [
            append c b/(i) + b/(i + 1)
        ]
        b: c
    ]
]

C# (Visual C# Compiler), 163 bytes
b=>{var s="";var c=b.Length;for(int i=0;i<c;i++){for(int z=0;z<i;z++)s+="\t";for(int x=0;x<c-i;x++){s+=b[x]+"\t\t";b[x]=x==c-i-1?0:b[x]+b[x+1];}s+="\n";}return s;}

Try it online!
Readable:
b =>    {
            var s = "";
            var c = b.Length;
            for (int i = 0; i < c; i++)
            {
                for (int z = 0; z < i; z++)
                    s += "\t";
                for (int x = 0; x < c - i; x++)
                {
                    s += b[x] + "\t\t";
                    b[x] = x == c - i - 1 ? 0 : b[x] + b[x + 1];
                }
                s += "\n";
            }
            return s;
        }

Japt -Rx, 20 18 bytes
The second line includes a trailing tab.
Nc¡=ä+
Ëq' ² iEç'

Try it

Explanation
                  :Implicit input of array U
N                 :The array of inputs (NOT the input array)
 c                :Concatenate
  ¡               :  Map U
    ä+            :    Consecutive sums of U
   =              :    Reassign to U for next iteration
\n                :Reassign the resulting 2D-array to U
Ë                 :Map each array at index E
 q                :  Join with
  '\t             :   Tab
     ²            :   Repeated twice
       i          :  Prepend
          '\t     :   Tab
         ç        :   Repeated
        E         :   E times
                  :Implicitly join with newlines, trim (not strictly necessary) and output.

Vyxal, 18 bytes
2lṠ)↔ðdvj:ẏ$꘍⁋ð9CV

Try it Online!
I think this works? Output format is annoying.
   )↔              # Repeat until no change, collecting values
  Ṡ                # Sums of
2l                 # Consecutive pairs
       vj          # Join each by...
     ðd            # Double spaces
           $꘍      # Pad left with spaces by
         :ẏ        # range(0, len(list)
             ⁋     # Join by newlines
                 V # Replace
              ð    # Spaces
               9C  # With tabs

Python 3, 79 75 70 bytes
Has leading tabs. Prints the required output then prints trailing tabs and newlines forever.
def f(x,y='\n'):print(y,*x,sep='        ');f([*map(sum,zip(x,x[1:]))],y+'   ')

Try it online!

Ruby, 67 bytes
A straightforward recursive solution.
F=->a,n=0{puts ?\t*n+a*"		"
a[0]&&F[a.each_cons(2).map(&:sum),n+1]}

Attempt This Online!