text:
Numbers Increase While Letters Decrease
Inspired by this Stack Overflow question: Sorting a list: numbers in ascending, letters in descending. Your task is to solve the following problem and, as this is code-golf, you should do so in as few as bytes as possible.
You should take a list of objects as input containing letters (any reasonable form: string, char, etc) and numbers. You should then sort the numbers into ascending order and the letters into descending order. However, you should keep letters in letter positions and numbers in number positions. For example, if the list is:
[L, D, L, L, D, L]

The output list should be in the form of:
[L, D, L, L, D, L]

Workthrough
Input: ['a', 2, 'b', 1, 'c', 3]

Sort the numbers into ascending order: [1, 2, 3]
Sort the letters into descending order: ['c', 'b', 'a']
Join them back but keep the order the same: ['c', 1', 'b', 2, 'a', 3]

Rules

The list will only contain letters and digits.
The list may be empty.
The list may only contain letters or only digits.
If your language does not support mixed type arrays you may use digit characters instead of numbers. Note that if your language does support this you must use mixed types.
Letters will only be [a-z] or [A-Z], you may choose which one.
Letters are sorted as a being lowest, z being highest i.e. a = 1, z = 26.
Standard loopholes are forbidden.
I/O may be by any standard means including as a string.

Test cases
[5, 'a', 'x', 3, 6, 'b'] -> [3, 'x', 'b', 5, 6, 'a']

[ 3, 2, 1] -> [ 1, 2, 3 ]

[ 'a', 'b', 'c' ] -> [ 'c', 'b', 'a' ]

[] -> []

[ 2, 3, 2, 1 ] -> [1, 2, 2, 3]

As this is code-golf the shortest answer in bytes wins!

Comments are not for extended discussion; this conversation has been moved to chat.

Retina, 10 bytes
O`\d
O^`\D

Try it online!
The O stage in Retina can directly perform the kind of selective sorting required by this challenge.
Here the first line sorts digits while the second line sorts non-digits in reverse.

Python 2, 53 52 51 bytes
-2 bytes thanks to g.rocket
-1 byte thanks to Jonathan Frech
-1 byte thanks to RootTwo
def F(x):n=sorted(x);print[n.pop(-(e>x))for e in x]

Try it online!
The sorted list will have the numbers first and then the chars like [3, 5, 6, 'a', 'b', 'x'], then use e>x to filter what is number and what is char, in python any number is less than a list (input) and a list is less than a string.

This version fails with IndexError: pop index out of range. The former solution did work.

This works though, with 55 bytes too. 1-(e<'\')should be(e<'`')-1`. You just placed them in the wrong order. BTW, you ninja'd me :/ I had this

@Mr.Xcoder thanks for the help c:

save a byte with e<=9

Save two with e>x

Think you can save another one with n.pop(-(e>x))

@RootTwo That does the opposite of the intended behavior.

Saved another byte.

@LyricLy no, RootTwo's golf is right

@pxeger fixed, thanks

APL (Dyalog), 27 26 bytes
Expects characters to be uppercase
(⍋⊃¨⊂)@(~e)(⍒⊃¨⊂)@(e←∊∘⎕A)

Try it online!
This is just two applications of the form f@g, apply the function f on the items indicated by g.
For the first application we use:
 f: ⍒⊃¨⊂ the descending grades (⍒) each pick (⊃¨) from the entire argument (⊂).
 g: (e←∊∘⎕A) members (∊) of (∘) the Alphabet (⎕A), and store (←) this function as e.
For the second application we use:
 f: ⍋⊃¨⊂ the ascending grades (⍋) each pick (⊃¨) from the entire argument (⊂).
 g: (~e) not (~) members of the alphabet (e; the function we stored before)

I think this needs to cover for all integers, so replace the second filter with 83=⎕DR¨⍵

@Uriel Doesn't actually seem to be a requirement, but did save a byte. Also, ⎕DR is not universally 83 for numbers, only for small integers.

is it always 3=10|⎕DR for integers?

@Uriel Yes: 0=UnicodeChar, 1=Boolean, 2=ClassicChar, 3=int, 5=float, 6=pointer, 7=decimal, 9=complex. ⌊0.1×⎕DR gives you the number of bits used to represent each scalar, except for pointers, which depend on the architecture but always are 326. Thus, all numbers are 2|⎕DR.

JavaScript (ES6), 71 51 47 bytes
Saved 20 bytes by just using sort(), as suggested by @JustinMariner
Saved 4 more bytes thanks to @CraigAyre
Using a similar approach as Rod's Python answer:
a=>[...a].map(n=>a.sort()[1/n?'shift':'pop']())

Test cases

let f =

a=>[...a].map(n=>a.sort()[1/n?'shift':'pop']())

console.log(JSON.stringify(f(['a', 2, 'b', 1, 'c', 3]))) // -> ['c', 1', 'b', 2, 'a', 3]
console.log(JSON.stringify(f([5, 'a', 'x', 3, 6, 'b']))) // -> [3, 'x', 'b', 5, 6, 'a']
console.log(JSON.stringify(f([3, 2, 1]))) // -> [ 1, 2, 3 ]
console.log(JSON.stringify(f(['a', 'b', 'c']))) // -> [ 'c', 'b', 'a' ]
console.log(JSON.stringify(f([]))) // -> []
console.log(JSON.stringify(f([2, 3, 2, 1]))) // -> [1, 2, 2, 3]

Am I missing something or couldn't you remove the whole sort function and just use sort() on its own? It seems to sort in the same way without a function (in Chrome/FF/Edge).

@JustinMariner At first, I thought the numeric values could be numbers -- in which case a simple sort() would fail. But since we're limited to digits, you are correct: that does work. Thanks!

Nice solution, could you shift/pop on a.sort() each loop instead of assigning to x?: .map(n=>a.sort()[1/n?'shift':'pop']())

@CraigAyre Good catch!

I'm pretty sure +n can be used instead of 1/n

@ConorO'Brien That would work for the test cases, but the OP confirmed in the comments that the input array may contain zeros.

oh, I see. How about ~n?

@ConorO'Brien Then that would fail for letters: e.g. ~"a" === -1.

R, 83 76 bytes
-7 bytes thanks to Miff
function(n){u=unlist
d=n%in%0:9
n[d]=sort(u(n[d]))
n[!d]=sort(u(n[!d]),T)
n}

This is the same as the below, but it allows for mixed-type input as a list rather than an atomic vector (which would typecast everything as characters with mixed types).
Try it online!
R, 68 61 bytes
-7 bytes thanks to Miff
function(n){d=n%in%0:9
n[d]=sort(n[d])
n[!d]=sort(n[!d],T)
n}

Anonymous function. All digits are cast to characters in this case. n[-d] is the array without the digits. Returns NULL (empty list) on empty input.
Try it online!

You can shave off a few characters with d=n%in%0:9

Japt, 18 15 bytes
Thanks @Shaggy for -3 bytes and for help fixing for arrays with 0s.

c ñc
®¤?Vv :Vo

First line is intentionally left blank.
Try it online! using -Q to view the formatted array.
Explanation
First line is blank to avoid overwriting the input array.
[5, 'a', 'x', 3, 6, 'b']
c ñc

Make a copy by flattening (c) the input array, then sort (ñ) with strings represented by their char code (c). This is stored in V.
[3, 5, 6, 'a', 'b', 'x']
£

Then map the input array by the function...
¤?Vv :Vo

Turn numbers into binary strings (truthy) or strings into "" (falsy) (¤). If truthy, remove from the start of V (v), otherwise remove from the end (o).

15 bytes

@Shaggy Nice, that's really clever. Thanks!

You forgot to switch Vo and Vv around. I'm convinced there has to be a shorter way, without the ternary.

@Shaggy Oh, whoops. And yeah, just if o could remove from the beginning with negative values or something...

JavaScript, 164 162 158 142 bytes
edit 1: 2 bytes less after removing a redundant assignment of v.
edit 2: 4 bytes less thanks to TheLethalCoder.
edit 3: 16 bytes less thanks to brilliant hints from Justin Mariner
x=>eval("n=v=>typeof(v)=='number';l=x.length;for(i=0;i<l;x[i++]=x[m],x[m]=w){for(v=w=x[j=m=i];++j<l;)n(e=x[j])==n(w)&&e<v==n(w)&&(m=j,v=e)}x")

It's my very first time in code-golf, so it can surely be improved... But still, worth a try.
The program performs a variant of selection sort, which only takes into account the values of the same type as the current one (swapping only a number and a number, or a letter and a letter)
Readable form:
x=>eval("
    n=v=>typeof(v)=='number';
    l=x.length;
    for(i=0;i<l;x[i++]=x[m],x[m]=w){
        for(v=w=x[j=m=i];++j<l;)
            n(e=x[j])==n(w) && e<v==n(w) && (m=j,v=e)
    }
    x
")

for(j=i+1;j<l;j++) -> for(j=i++;++j<l;) and remove the increment in the outer loop.

Welcome PPCG too!

@TheLethalCoder if we increment the counters so early, we'll also need to change the lines where i and j are used... But the idea is really smart, I'll think how to make use of it anyway.

You can increment j as I suggested, I didn't see you use i further down just change x[i]=x[m] too x[i++]=x[m]

Ah, sure... Why didn't I think of x[i++]=x[m]... Thanks!

Welcome and nice first answer! I suggest checking out the ES6 Tips, as well as the general JS tips linked there. By using eval to avoid return, moving some assignments and statements around, and moving the typeof check to a helper function, I golfed this down to 142 bytes here.

Jelly, 9 bytes
OÞḢṪOƑ}?Ɱ

Try it online!
Takes input as a flat array (Jelly typically treats strings as char arrays, so [5, 'a', 'x', 3, 6, 'b'] -> [5, ['a'], ['x'], 3, 6, ['b']]. The Footer flattens this array for you).
Similar to PurkkaKoodari's Jelly answer
How it works
OÞḢṪOƑ}?Ɱ - Main link. Takes an array A on the left
 Þ        - Sort by:
O         -   Ordinal
            This shuffles the strings to the end,
             sorting both the strings and the numbers
        Ɱ - Over each element E in A:
       ?  -   If statement:
    OƑ}   -     Condition: E is a number?
  Ḣ       -     Then: Pop and yield the first element of A sorted
   Ṫ      -     Else: Pop and yield the last element of A sorted

Jelly, 14 bytes
FOÞɓṪ}Ḣ}ẇØa$?€

Try it online!
Basically a port of Rod's Python solution.

q/kdb+, 54 53 bytes
Solution:
{x[w,q]:asc[x w:(&)d],desc x q:(&)(~)d:-7=type@/:x;x}

Examples:
q){x[w,q]:asc[x w:(&)d],desc x q:(&)(~)d:-7=type@/:x;x}(5;"a";"x";3;6;"b") / mixed list
3
"x"
"b"
5
6
"a"
q){x[w,q]:asc[x w:(&)d],desc x q:(&)(~)d:-7=type@/:x;x}3 2 1   / simple list
1 2 3
q){x[w,q]:asc[x w:(&)d],desc x q:(&)(~)d:-7=type@/:x;x}"abc"   / simple list
"cba"
q){x[w,q]:asc[x w:(&)d],desc x q:(&)(~)d:-7=type@/:x;x}2 3 2 1 / simple list
1 2 2 3

Explanation:
Find the chars in the list, sort descending, find the longs in the list, sort them ascending, join to get a list of, e.g. ("x";"b";"a";3;5;6), then assign the sorted values back to their original positions in the list, e.g. at 0 3 4 1 2 5.
Golfing is just switching out q keywords (each, where and not) for their k equivalent (which requires them to be wrapped in brackets).
{x[w,q]:asc[x w:where d],desc x q:where not d:-7=type each x;x} / ungolfed
{                                                           ; } / lambda function with 2 statements
                                                 type each x    / return types of elements in mixed list
                                              -7=               / true where item is a long
                                            d:                  / save this bool array in d
                                        not                     / invert
                                  where                         / indices where true (we have chars)
                                q:                              / save these indices in q
                              x                                 / values of x at these indices
                         desc                                   / sort them descending
                        ,                                       / join/contatenate
                where d                                         / indices where we have digits
              w:                                                / save this in w
            x                                                   / values of x at these indices
        asc[           ]                                        / sort them ascending
 x[w,q]:                                                        / assign this list to x at indices w,q
                                                             x  / return x

Edits

-1 byte as don't need square brackets around desc

C++17 (gcc), 219 bytes
#include <variant>
#include <set>
using V=std::variant<char,int>;void f(V*a,V*b){std::set<V>S[2];for(V*c=a;c<b;++c)S[c->index()].insert(*c);auto
C=S->rbegin();auto N=S[1].begin();for(;a<b;++a)*a=(a->index()?*N++:*C++);}

Try it online!
Hardly competitive. But I must support mixed-type arrays? FINE.
Accepts an array of variants in range style, and modifies it in place.  Copies the input into two sorted sets, and then back into the input/output array.

This is interesting. I wouldn't interpret "supporting mixed-type arrays" in this way. Otherwise, I'd have to use an array of void * in C ;) But, yes, interesting to see a solution jumping through such a hoop.

You can save two bytes by removing the spaces in the #includes

Japt, 9 bytes
I knew there had to be a (golfy) way to do this without any sort of conditional :)
Outputs an array of singleton arrays. Replace £ with c@ to output a flat array.
£=ñs)jÓXÌ

Try it
£=ñs)jÓXÎ     :Implicit input of array U
£             :Map each X (or flat map with c@)
 =            :  Reassign to U
  ñ           :    Sort by
   s          :      Converting to string if an integer, slicing if a string (which does nothing to the string if given no arguments)
    )         :  End reassignment
     j        :  Remove (mutating the original) and return the element at modular 0-based index
      Ó       :    Bitwise NOT of the negation of (i.e, decrement)
       XÎ     :    Sign of difference of X with -1 if an integer, last character if a string (resulting in 0 if an integer or -1 if a string)

Haskell, 108 bytes
There may be shorter ways, but I just had to try it with the Lens library.
import Control.Lens
import Data.List
i(!)f=partsOf(traverse.filtered(!'='))%~f.sort
f x=x&i(<)id&i(>)reverse

I could define f to just be the composition of the two i invocations, but I'd still have to apply x to it to avoid a type error from the monomorphism restriction. Note that the type of f is Traversable t => t Char -> t Char so it can be used with Strings which are lists of Chars as well as with arrays of Chars.
Here are the test cases:
*Main> map f ["5ax36b","321","abc","","2321"]
["3xb56a","123","cba","","1223"]

Python, 145 139 130 bytes
6 bytes saved thanks to @officialaimm
9 bytes saved thanks to @Chris_Rands
g=lambda s,a:sorted(x for x in s if(type(x)==str)==a)
def f(s):l,n=g(s,1),g(s,0)[::-1];return[[n,l][type(x)==str].pop()for x in s]

Try it online!

139 bytes

type(x)==str would save some bytes over using isinstance(...) i think

@Chris_Rands thanks!

Mathematica, 203 bytes
(K=Reverse;B=Complement;L=Length;S=Position[#,_Integer];T=Sort@Cases[#,_Integer];G=K@B[#,T];V=B[Range@L@#,Flatten@S];R=K@Sort@#;Table[R[[Min@S[[i]]]]=T[[i]],{i,L@T}];Table[R[[V[[i]]]]=G[[i]],{i,L@G}];R)&

Try it online!

Pyth, 12 11 bytes
KSQm.(Kt>\@

Try it online! or Try the Test Suite.

Explanation
KSQm.(Kt<d\@  - Full program with implicit input.

KSQ           - Assign a variable K to the lexicographically sorted input.
   m          - Map over the input (with a variable d).
    .(K       - Pop the sorted list at this location:
       >\@    - If d is lexicographically lower than '@', at 0 (the first element). Else, at -1 (the last element).

Wait, you don't need to order the entire array, just split in two homogeneous arrays which each should be easily sortable. APL cannot sort mixed arrays either (yet), but I sort each type separately.

@Adám What do you mean by just split in two homogeneous arrays which each should be easily sortable?

As described in the OP's "Workthrough": 1. Make note of which elements are numeric and which are character. 2. Extract all numbers into a separate array and sort that. Do the same for the characters. 3. Put the sorted number back into the number slots. DO the same for the characters.

@Adám If the OP considers this invalid, I will do exactly what you said (This would result in a much, much longer approach)

C (gcc), 125 113 110 bytes
main(i){char*b,*c,s[99];for(gets(c=b=s);*++c||*(c=++b);)i=*b&64,i^*c&64||*c>*b^!i&&(i=*c,*c=*b,*b=i);puts(s);}

Try it online!
Explained:
main(i)
{
    char*b,*c,s[99];

    // slightly modified stupid bubblesort, this line in fact
    // does nested looping with a single for statement
    for(gets(c=b=s);*++c||*(c=++b);)
    // (undefined behavior here, there's no sequence point between accesses to c,
    // so this could go wrong. Works with the gcc version on tio.)

        // determine whether the current b is a letter:
        i=*b&64,

        // for doing anything, b and c must be the same "type":
        i^*c&64

            // when c > b for letter or c <= b for digit
            || *c>*b^!i

            // then swap
            && (i=*c,*c=*b,*b=i);

    puts(s);
}

Letters are expected in uppercase.

05AB1E, 17 bytes
SaJ¹á{R¹þ{«vyay.;

Try it online!

SaJ               # Push 1 if letter 0 else, for all letters in string.
   ¹á{R           # Reverse sort letters from input.
       ¹þ{        # Regular sort digits from input.
          «       # Concatenate those two things.
           v      # For each letter in the sorted string...
            ya    # 0 if digit, 1 if letter.
              y.; # Replace first instance of 0/1 with digit/letter.

Using the sort-by closure actually was worse: Σ©Ç®ai0<*}}¹SaJsvyay.;

Python 3, 77 bytes
This answer is based on the comment that says you can use '1', '2', etc if chars and digits are not comparable in the language.  'a' and 1 are not comparable in Python 3.
def f(s):x=sorted(s,key=lambda c:ord(c)-95);return[x.pop(-(c>'.'))for c in s]

PHP, 66 bytes:
for($a=$argv,sort($a);a&$c=$argv[++$i];)echo$a[$c<A?++$k:--$argc];

takes input from command line arguments, prints a string.
Run with -nr or try it online.
Yields a warning in PHP 7.1; replace a& with ""< to fix.

APL (Dyalog), 26 bytes
a[⍒i][⍋⍋27>i←(⎕a,⌽⍳9)⍳a←⎕]

(uses ⎕IO=1)
Try it online!

Uiua, 24 bytes
⍜▽(⊏⍏.)¬⊃∘⍜▽(⊏⍖.)⊐∵type.

Try it!
⍜▽(⊏⍏.)¬⊃∘⍜▽(⊏⍖.)⊐∵type.
                       .  # duplicate
                 ⊐∵type   # mask of types (0 for number, 1 for character)
          ⍜▽(⊏⍖.)         # descending sort the characters
        ⊃∘                # keep the mask
       ¬                  # not
⍜▽(⊏⍏.)                   # ascending sort the numbers

K (ngn/k), 26 bytes
{x[>i]@<<1>i:x*1 1'`c=@'x}

Derived from @ngn's APL solution
Try it online!

Mathematica, 107 bytes
(s=#;s[[p]]=Sort[s[[p=#&@@@s~($=Position)~_String]],#2~Order~#>0&];s[[c]]=Sort@s[[c=#&@@@s~$~_Integer]];s)&

C# (.NET Core), 171 bytes
a=>{var b=a.Where(x=>x is int).ToList();b.Sort();int i=0,j=0;return a.Select(x=>b.Contains(x)?b[i++]:a.Except(b).OrderByDescending(y=>y).ToList()[j++]);}

Byte count also includes:
using System.Linq;

Try it online!
Explanation:
a =>
{
    var b = a.Where(x => x is int).ToList(); // Filter to only ints and transform to list
    b.Sort();                                // Sort the list
    int i = 0, j = 0;                        // Create index counters
    return a.Select(x =>                     // Replace each input element with
                    b.Contains(x) ?          // If it is in list b:
                    b[i++] :                 // Get the next element from b
                    a.Except(b)              // Otherwise take input and filter out those in b
                     .OrderByDescending(x=>x)// Order them z to a
                     .ToList()[j++]);        // Get the next element

Perl 5, 107 + 1 (-n) = 108 bytes
y/][//d;@a=split/, /;@l=sort grep/\D/,@a;@d=sort grep/\d/,@a;@r=map{/\d/?pop@d:shift@l}@a;$"=", ";say"[@r]"

Try it online!

Ruby, 265 bytes
x.sort_by(&:to_s).select{|a| a.is_a?(String)}.zip(x.map.with_index {|a, i| a.is_a?(String) ? i : nil}.compact).each{|a,i| x[i] = a}
x.sort_by(&:to_s).select{|a| a.is_a?(Integer)}.zip(x.map.with_index {|a, i| a.is_a?(Integer) ? i : nil}.compact).each{|a,i| x[i] = a}

Try it online!
First timer here, My solution is definetly not the best one. But since this is my first answer, I thought in posting just for the fun of it.
Looking foward to see better Ruby answers, to see what is the best approach. I hope I improve in future answers =)
Readable
x = ["c", 1, "a", 3, "b", 2]

b = x.map.with_index {|a, i| a.is_a?(Integer) ? i : nil}.compact
s = x.map.with_index {|a, i| a.is_a?(String) ? i : nil}.compact

o = x.sort_by(&:to_s).select{|a| a.is_a?(Integer)}
d = x.sort_by(&:to_s).select{|a| a.is_a?(String)}

d.zip s
d.zip(s).each {|a, i| x[i] = a}

o.zip b
o.zip(b).each {|a, i| x[i] = a }

p x

Python 3, 91 bytes
def f(s):x=sorted(s,key=lambda c:(type(c)==str,c));return[x.pop(-(type(c)==str))for c in s]

Clojure, 151 bytes
#(map(fn[t c](nth((if(=(type 1)t)vec reverse)(sort((group-by type %)t)))(-(c t)1)))(map type %)(reductions(partial merge-with +)(for[i %]{(type i)1})))

Example:
(def f #( ... ))
(f [5 \a \x 3 6 \b])
; (3 \x \b 5 6 \a)

This calculates the cumulative sum count of integers and characters, and uses it to lookup the correct element from a sorted list of corresponding type's elements.

Zsh, 43 55 70 95 bytes
b=(${(n)@});for i;echo $b[$[#i>64?--k:++j]]

Try it online!
  55bytes
  70bytes
  95bytes
Create a sorted array b, numbers first. Iterate over the arguments. If i is a letter (>ascii #64) then decrement k and print b[k], (e.g. b[-2] is the 2nd to last value). If i is a number, increment j and print b[j].
NB: Previously I forgot to decrease letters. Fixed now, and saved bytes!

Go, 290 bytes
import."sort"
func f(I[]any){J,K:=StringSlice{},IntSlice{}
var L,M[]int
for i,e:=range I{switch e:=e.(type){case string:J,L=append(J,e),append(L,i)
case int:K,M=append(K,e),append(M,i)}}
Sort(Reverse(J))
Sort(K)
x:=len(L)
for i:=0;i<x+len(M);i++{if i<x{I[L[i]]=J[i]}else{I[M[i-x]]=K[i-x]}}}

Attempt This Online!
Explanation
import."sort"                 // boilerplate
func f(I[]any){               // boilerplate
J,K:=StringSlice{},IntSlice{} // J and K store the actual elements
var L,M[]int                  // L and M store their indexes
for i,e:=range I{             // for each element,
switch e:=e.(type){           // switch on their type
case string:J,L=append(J,e),append(L,i) // put strings in J/L
case int:K,M=append(K,e),append(M,i)}}  // put ints in K/M
Sort(Reverse(J))              // sort J reversed (descending)
Sort(K)                       // sort K normally (ascending)
x:=len(L)                     //
for i:=0;i<x+len(M);i++{      // combined loop
if i<x{I[L[i]]=J[i]}          // put the strings back in
else{I[M[i-x]]=K[i-x]}}}      // put the ints back in

Uiua, 21 bytes
⍜⊕□⊐∵(⊏⍖⍣¬⟜∘.)⊐∵type.

Try it!
Takes an array of boxes, where each box contains either a single number or character.
⍜⊕□⊐∵(⊏⍖⍣¬⟜∘.)⊐∵type.
                   ⊐∵type    type of each element; 0 if number, 1 if character
⍜⊕□⊐∵(         )        .   operate on each group...
            ⍣¬⟜∘              for numbers, negate; for characters, identity
         ⊏⍖     .             sort descending by the above

A fun 22 bytes:
⍥(-∶@0⍜▽(⊏⍖.)⊐∵type.)2
⍥(                      )2    do this twice...
                ⊐∵type        type of each element
       ⍜▽(   )        .      keep characters, operate on it, and put it back
                               to the original array:
            ⊏⍖.                 sort descending
  -∶@0                         replace each element with '0' minus that;
                               this changes characters to numbers and vice versa
                               and reverses the sorting order

05AB1E, 14 bytes
{Ivydićˆë¤ˆ¨]¯

Try it online or verify all test cases.
Explanation:
{         # Sort the (implicit) input-list, which will put all sorted digits at the
          # front, and all sorted letters at the end
 I        # Push the input-list again
  v       # For-each over its items `y`:
   ydi    #  If the current character `y` is a digit:
      ć   #   Extract the head of the sorted-list; pop and push remainder-list and first
          #   item separated to the stack
       ˆ  #   Pop and add this first item to the global array
     ë    #  Else (it's a letter instead):
      ¤   #   Get the last item of the sorted list (without popping the list itself)
       ˆ  #   Pop and add this last item to the global array
        ¨ #   And then remove this last item from the list
  ]       # Close both the if-else statement and loop
   ¯      # And push the global array
          # (after which it is output implicitly as result)


text:
Which tetromino is this?
Given an unsigned 16-bit integer N, your task is to determine whether its binary representation mapped inside a 4x4 matrix is matching a tetromino shape, and if so, which shape it is.
Matrix
Each bit of N is mapped inside a 4x4 matrix, from left to right and from top to bottom, starting with the most significant one.
Example:
N = 17600
binary representation: 0100010011000000
matrix: [ [ 0, 1, 0, 0 ],
          [ 0, 1, 0, 0 ],
          [ 1, 1, 0, 0 ],
          [ 0, 0, 0, 0 ] ]

Tetromino shapes
Base shapes
There are 7 tetromino shapes, identified by the letters O, I, S, Z, L, J and T:

Rotations and translations
If a shape is translated and/or rotated within the 4x4 matrix, it is still considered a valid variation of the same tetromino. For instance, 17600, 1136, 2272 and 1604 should all be identified as J tetrominoes:

Don't wrap!
However, the shapes can't wrap around or be shifted beyond any boundary of the matrix. For instance, neither 568 nor 688 should be identified as J tetrominoes (let alone any other shape):

Clarifications and rules

You may take input as an integer, or directly as 16 binary digits in any reasonable format, such as a 2D array, a flat array or a delimited string.
The input is guaranteed to be an unsigned 16-bit integer (or its equivalent representation as an array or a string).
When a valid shape is identified, you must print or return the letter identifying the shape, in either lower or upper case.
If no shape is identified, you must print or return a value that doesn't match any tetromino letter. You may also choose to return nothing at all.
To be considered valid, the matrix must contain the exact tetromino shape without any additional cells (see 1911 and 34953 in the test cases).
This is code-golf, so the shortest answer in bytes wins!

Test cases
You can follow this link to get the test cases as 2D arrays.
0      -> false
50     -> false
51     -> 'O'
1911   -> false
15     -> 'I'
34952  -> 'I'
34953  -> false
1122   -> 'S'
3168   -> 'Z'
785    -> 'L'
1136   -> 'J'
568    -> false
688    -> false
35968  -> 'T'
19520  -> 'T'

Interestingly, I was working on an extremely similar problem the other day before I got distracted creating a technique to use function chains func1 . func2 . func3 in JS :P

Can I take input as the four rows joined with 0, i.e. 1111011110111101111 for 65535?

@ETHproductions That seems fine. I've edited the challenge with a slightly relaxed input format.

I:15,240,3840,4369,8738,17476,34952,61440
J:71,113,142,226,275,550,802,1100,1136,1604,1808,2272,3208,3616,4400,8800,12832,17600,18176,25664,28928,36352,51328,57856
L:23,46,116,232,368,547,736,785,1094,1570,1856,2188,3140,3712,5888,8752,11776,12560,17504,25120,29696,35008,50240,59392
O:51,102,204,816,1632,3264,13056,26112,52224
S:54,108,561,864,1122,1728,2244,8976,13824,17952,27648,35904
T:39,78,114,228,305,562,610,624,1124,1220,1248,1824,2248,3648,4880,8992,9760,9984,17984,19520,19968,29184,35968,58368
Z:99,198,306,612,1224,1584,3168,4896,9792,19584,25344,50688

^ Generated using Lynn's Python 3 answer because it had convenient input / output formats.

688 mino is rather interesting for gamers.

tetrAmino, sorry. domino, trimino, tetramino, pentamino, hexamino and so on.

@Gangnus Tetrominoes is apparently the standard math term. I think the Tetris Company has used the alternate spelling Tetraminoes at some point and is now using Tetriminos, which is trademarked. But I tend to say 'Tetramino' and accidentally used both spellings in my original edit. :-)

@Arnauld Yes, I see. I have got that from a Russian translation of a Martin Gardner book, but it really seems that in English it has O. That translation is the reason why Pazhitnov(author of Tetris) used A, obviously. My excuses.

Am I right in assuming any connected block of exactly four ones is legal? I suspect there's some fairly simple bit trickery solution to this. Identifying the shape might complicate matters a little.

@Arnauld Thanks. Maybe I should make a "does this matrix contain exactly one polyomino" challenge instead. The answers would be completely different.

Jelly,  54 43 42  41 bytes
-1 byte thanks to Erik the Outgolfer (move transpose inside repeated chain)
T€FṀ⁸ṙ€Zµ⁺F
ZU$3Ð¡Ç€ḄṂ“çc3Ð6'G‘i’ị“¥Çıƭ⁵»

A monadic link taking a 2D array of integers (1s and 0s) and returning a lowercase letter oiszljt for the respective tetromino or w if invalid.
Try it Online! or see the test suite.
Also see this program which lists all 1820 possible 2D binary arrays with exactly four bits set along with their outputs, sorted by those outputs.
How?
This first takes all four rotations of the input. Then it shifts the set bits of each as far to the right and then as far to the bottom as possible and converts the results to binary numbers. It then looks up the minimum result in a list of the minimal such representations of each valid tetromino and uses the decremented result to index into the two concatenated dictionary words zoist+jowl, yielding w when no match was found.
T€FṀ⁸ṙ€Zµ⁺F - Link 1, shift set bits right & then down : list of lists of bits
        µ⁺  - perform the following twice, 1st with x=input, then with x=result of that):
T€          -   truthy indexes of €ach
  F         -   flatten into a single list
   Ṁ        -   maximum (the index of the right-most bit)
    ⁸       -   chain's left argument, x
     ṙ€     -   rotate €ach left by that amount
       Z    -   transpose the result
          F - flatten (avoids an € in the main link moving this into here)

ZU$3Ð¡Ç€ḄṂ“çc3Ð6'G‘i’ị“¥Çıƭ⁵» - Main link: list of lists of bits (the integers 0 or 1)
   3Ð¡                        - repeat this 3 times collecting the 4 results:
  $                           -   last two links as a monad:
Z                             -     transpose
 U                            -     upend (reverse each) -- net effect rotate 90° CW
      Ç€                      - call the last link as a monad for €ach
        Ḅ                     - convert from binary (vectorises)
         Ṃ                    - minimum (of the four results)
          “çc3Ð6'G‘           - code-page indexes = [23,99,51,15,54,39,71]
                              -   ...the minimal such results for l,z,o,i,s,t,j shapes
                   i          - 1-based index of minimum in there or 0 if not found
                    ’         - decrement
                      “¥Çıƭ⁵» - compressed words: "zoist"+"jowl" = "zoistjowl"
                     ị        - index into (1 indexed & modular, so -1 yields 'w',
                              -             0 yields 'l', 1 yields 'z', ...)

Previous method (54 bytes)
Fœr0Ḅ“çc3Ðñ'G‘i
;Z$Ḅ©f“¦µ½¿Æ‘ȯ®¬S>2ȧZU$3Ð¡Ç€Ṁ’ị“¥Çıƭ⁵»

A monadic link taking a 2D array of integers (1s and 0s) and returning a lowercase letter oiszljt for the respective tetromino or w if invalid.
Try it online!
This checks there are at least three empty lines (rows+columns) and that certain patterns of bits are not present in any line (specifically the numbers 5,9,10,11, and 13), these together assure the next step wont yield false-positives. It then flattens and then floor-shifts the binary number (by striping trailing zeros before conversion) of each of the four rotations, and looks up the minimal result in a list of numbers, using the decremented result to index into the two concatenated dictionary words zoist+jowl, yielding w when no match was found.

And I knew there was a better way than hardcoding...

btw I think this code depends on a coincidence (because, well, zoistjowl wouldn't normally fit for a string otherwise :p)

What do you mean "depends on a coincidence"? (the dictionary lookup only  saves one byte over ...Ṁị“LZOISTJW anyway)

Hmm...yeah I knew this wouldn't last long...btw I think you stole my ZU$3Ð¡ :p

I was trying to do  same method yesterday after submitting the previous one but think I was a little tired.

Let us continue this discussion in chat.

Python 3, 124 bytes
def f(n):
 while n&4369<n/n:n>>=1
 while n&15<1:n>>=4
 return'TJLZSIO'["rēȣc63ıGtĲȱᄑ@'̢̑@@@@Ȳq".index(chr(n))%7]

Try it online!
Expects an integer n representing a 4 × 4 binary matrix. Throws if no tetromino is found.
Line 2 slides the shape to the right until a 1 is in the rightmost column. (4369 is 0001 0001 0001 0001 in binary.) Line 3 lowers the shape until a 1 is in the bottom row. Together this turns e.g.:
    0 1 0 0        0 0 0 0
    1 1 1 0  into  0 0 0 0
    0 0 0 0        0 0 1 0
    0 0 0 0        0 1 1 1

Then we look for the index of n in this list:
 [114  275  547   99   54   15   51
  305   71  116  306  561 4369   64
   39  802  785   64   64   64   64
  562  113   23]
#   T    J    L    Z    S    I    O

Each column of indices equivalent modulo 7 corresponds to a tetromino shape. 64 (@) is used as a padding value as n cannot be 64 at this point in the code.
NB. An exception is thrown for input 0 by computing n/n instead of 1.

Why does your binary string work? I had problems with that in Python 3, see comments https://codegolf.stackexchange.com/a/85201/53667

Python uses UTF-8 as the default encoding for source code and for text output. But PPM files aren’t read in UTF-8. When you run print("ÿ"), the bytes that get written are c3 bf 0a, not ff 0a, and the PPM image turns into garbage.

APL (Dyalog), 95 94 93 89 87 bytes
-2 thanks to Zacharý
Requires ⎕IO←0 which is default on many systems. Takes Boolean matrix (of any shape!) as argument. Returns nothing if the given number of bits is not four, and a blank line if the four given bits do not form a tetromino.
{4=+/,⍵:'OIZSJLT'/⍨∨/1∊¨(((2 2)4⍴¨1),(0 1⌽¨⊂K⌽2⊖J),(⍳3)⊖¨⊂J←1,⍪K←3↑1)∘.⍷⍵∘{⌽∘⍉⍣⍵⊢⍺}¨⍳4}

Try it online!
Works by creating all four rotations of the input, then looking for each tetromino in each rotation.
{…} anonymous function where the argument is represented by ⍵:
 ,⍵ ravel (flatten) the argument
 +/ sum it
 4= is four equal to that?
 : if so, then (else return nothing):
  ⍳4 first four ɩndices;  [0,1,2,3]
  ⍵∘{…}¨ apply the following function on each, using the input as fixed left argument
   ⍺ the left argument i.e. the input
   ⊢⍺ yield that (separates ⍵ from ⍺)
   ⌽∘⍉⍣⍵ mirror and transpose (i.e. rotate 90°) ⍵ times
  (…)∘.⍷ outer "product", but using Find*, of the following list and the rotations:
   3↑1 take three elements from one, padding with zeros; [1,0,0]
   K← store that as K
   ⍪ table (make into column vector); [[1],[0],[0]]
   1, prepend a one; [[1,1],[1,0],[1,0]] ("J")
   J← store as J
   (…)⊖¨⊂ rotate the entire J vertically, each of the following number of steps:
    ⍳3 first three ɩntegers; [0,1,2]
   we have [[[1,1],[1,0],[1,0]],[[1,0],[1,0],[1,1]],[[1,0],[1,1],[1,0]]] ("J", "L, "T")
   (…), prepend the following list:
    2⊖J rotate J two steps vertically; [[1,0],[1,1],[1,0]] ("T")
    K⌽ rotate the rows of that by 1, 0, and 0 steps respectively; [[0,1],[1,1],[1,0]] ("Z")
    0 1⌽¨⊂ rotate the entire array vertically, no times and once; [[[0,1],[1,1],[1,0]],[[1,0],[1,1],[0,1]]] ("Z", "S")
    (…), prepend the following list:
     (2 2)4⍴¨1 reshape a one into each of a 2×2 matrix and a 4-element list; [[[1,1],[1,1]],[1,1,1,1]] ("O", "I")
  1∊¨ for each, is one a member?
  ∨/ horizontal OR reduction (i.e. across rotations; one Boolean for each shape)
  'OIZSLJT'/⍨ use that to filter the string
* Find returns a Boolean array of same shape as its right argument, with ones indicating the top left corner of all subarrays identical to the left argument.

Would this work? {4=+/,⍵:'OIZSJLT'/⍨∨/1∊¨(((2 2)4⍴¨1),(0 1⌽¨⊂K⌽2⊖J),(⍳3)⊖¨⊂J←1,⍪K←3↑1)∘.⍷⍵∘{⌽∘⍉⍣⍵⊢⍺}¨⍳4}

@Zacharý Yes, thanks, done.

JavaScript (ES6), 242 212 172 164 bytes
x=>[...'OISZLJT'].filter((z,y)=>x.match(`^0*(${'99,33825|15,51|2145,195|561,2115|57,1059|135,71|1073'.split`,`[y].replace(/\d+/g,C=x=>x?x%2+C(x>>1)+x%2:'|')})0*$`))

Was supposed to be just to get the ball rolling, but I'm a little late for that ¯\_(ツ)_/¯
Takes a string of bits, with rows separated by 0s ('0001000110001000000' representing 0001 0011 0010 0000) and returns an array containing the character representing the tetromino, or an array containing nothing.
This works by checking each rotation of tetromino to see if the input at any point contains the tetromino, surrounded entirely by zeroes on either side. Each tetromino is represented by one or more binary numbers:
0 0 0 0   -> 0000 0110 1100 0000
0 1 1 0   -> 0000001100110000000
1 1 0 0   -> 110011
0 0 0 0   -> 51

0 1 0 0   -> 0100 0110 0010 0000
0 1 1 0   -> 0100001100001000000
0 0 1 0   -> 100001100001
0 0 0 0   -> 2145

So to check if the input contains an S tetromino, we simply check whether it contains the binary representation of either 51 or 2145, with only 0s on either side.
A few of the tetrominoes have 4 orientations. If you look at the binary representations of these, each has 2 representations which are simply the mirror of the other two. To save space, the binary representation is built up forward and backward simultaneously with the recursive C function, allowing us to only put two of the orientations in and have the other two implied.

Alternate approach with charcodes:
x=>[...'OISZLJT'].filter((z,y)=>x.match(`^0*(${[...'÷,êÿ,óî,ûÝ,ëúüÏ,çöïþ,ßýíÞ'.split`,`[y]].map(c=>(C=n=>n?'1e'+(n%4+2)%5-0+C(n>>2):'')(c.charCodeAt())).join`|`})0*$`))

Jelly, 53 bytes
ZL0ẋW⁸tZµ⁺ZU$3Ð¡“©©“œ“Ç¿“¦©¦“Æ½‘;Uḃ2$’¤iÐ€Ṁị“÷¶Ė¡µỵỤ»

Try it online!
Full program. Takes a 4x4. Prints m if not a tetromino, otherwise prints lowercase.

Is... is taking an array of arrays of bits legal? That would save me like 40 bytes

@ETHproductions You may take input as an integer, or directly as a 2D array of 4x4 binary digits or a flat array of 16 binary digits.

Huh, serves me right for skimming over the question...

MATL, 60 bytes
Itt6tIl7tl7H15vHe"4:"G@X!HYa]4$v@BIthYaEqY+4=aa]v'OSZLJTI'w)

Input is a binary 4×4 array (matrix), using ; as row separator. Ouput is a letter or empty for no tetromino.
Try it online! Or verify all test cases (output has a dot appended to allow identifying an empty result).
Explanation
The code builds 4 rotations of the input 4×4 array in steps of 90 degrees. Each rotated array is padded with 2 zeros up and down, which transforms it into a 8×4 array. The 4 arrays are vertically concatenated into a 32×4 array. The four rotated arrays within this concatenated array are "isolated" thanks to the zero-padding.
Each of the 7 possible patterns is tested to see if it is present in the 32×4 array. A loop is used for this. Each pattern is defined by two numbers, which expressed in binary give the appropriate 0/1 mask. For example, numbers 3, 6 define the "S" shape.
The 7 sets of 2 numbers are arranged into a 2×7 matrix, from which the loop will pick each column sequentially. The matrix is defined by pushing all numbers to the stack, contatenating them into a vector, and reshaping into a 2-row matrix. Since the "I" shape is defined by number 15 followed by 0, putting it at the end allows the 0 to be implicitly filled by the reshaping function.
The mask is then padded with 3 zeros in the four directions. This is necessary so as to detect unwanted values in the input.
To see if the mask is present in the 32×4 array, the latter is transformed to bipolar form (i.e. −1/1 instead of 0/1) and convolved with the mask. Since the mask has 4 ones, matching occurs if some entry in the convolution result equals 4.
At the end of the loop, 7 false/true results have been obtained, at most one of which is true. This is used to index into a string containing the possible output letters.

Retina, 125 bytes
s`(.*1){5}.*

{s`.*1111.*
I
s`.*111(.{2,4})1.*
$.1
T`234`\LTJ
s`.*11(.{2,4})11.*
$.1
T`2-90`S\OZ4-9
s`.*4.*

O#$`.
$.%`
O#$^`

Try it online! Link includes test cases plus a header to convert from integers to a 4×4 matrix. Explanation:
s`(.*1){5}.*

Delete the input if it contains 5 1s.
{s`.*1111.*
I

Check all rotations of the input (see below). If the input contains four consecutive 1s, it's an I.
s`.*111(.{2,4})1.*
$.1
T`234`\LTJ

If it contains three consecutive 1s plus a 1 on the next line underneath one of the three, then map the number of intermediate characters to the appropriate result letter.
s`.*11(.{2,4})11.*
$.1

Similarly for two adjacent 1s adjacent to two adjacent 1s on the next line.
T`2-90`S\OZ4-9

But also keep count of the number of rotations using the otherwise unused 0s.
s`.*4.*

And give up if too many rotations have been performed.
O#$`.
$.%`
O#$^`

Transpose and reverse the array, thus rotating it.

APL (Dyalog), 66 bytes
{'TIOJSLZ-'[(¯51 144 64,,∘+⍨12J96 ¯48J64)⍳×/(+/-4×⊢)⍵/,0j1⊥¨⍳4 4]}
Try it online!
The arg is a boolean vector.
Computes signed distances of the dots to their centre of gravity as complex numbers (real and imaginary part are ∆x,∆y) and multiplies the complex numbers together. This turns out to be a good enough invariant to distinguish among the tetrominoes.

Interesting method.

Perl 5, 197 + 1 (-p) = 198 bytes
s/(0000)*$//;1while s/(...)0(...)0(...)0(...)0/0${1}0${2}0${3}0${4}/;$_={51,O,15,I,4369,I,54,S,561,S,99,Z,306,Z,547,L,23,L,785,L,116,L,275,J,113,J,802,J,71,J,114,T,562,T,39,T,609,T}->{oct("0b".$_)}

Try it online!
Takes a 16 bit string as input.  Outputs nothing if input is not a single tetromino.
How?
The two substitutions "move" the input shape to the bottom right corner.  The resulting bit string is converted to an integer, then checked for in a hash of valid integers.

source: Stack Exchange

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

sort: votes


text:
Pascal's Alternating Triangle
Pascal's triangle is generated by starting with 1 and having each row formed from successive additions. Here, instead, we're going to form a triangle by alternating  multiplication and addition.
We start row 1 with just a solitary 1. Thereafter, addition is done on the odd rows, and multiplication is done on the even rows (1-indexed). When performing the addition step, assume the spaces outside of the triangle are filled with 0s. When performing the multiplication step, assume that the outside is filled with 1s.
Here's the full triangle down to 7 rows. The * or + on the left shows what step was performed to generate that row.
1                1
2 *            1   1
3 +          1   2   1
4 *        1   2   2   1
5 +      1   3   4   3   1
6 *    1   3  12  12   3   1
7 +  1   4  15  24  15   4   1

Challenge
Given input n, output the nth row of this triangle.
Rules

You may choose to 0-index instead, but then please realize that the addition and multiplication rows must flip-flop, so that the exact same triangle is generated as above. Please state in your submission if you choose to do this.
The input and output can be assumed to fit in your language's native integer type.
The input and output can be given in any convenient format.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
If possible, please include a link to an online testing environment so other people can try out your code!
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Examples
Showing two possible examples of output out of many: a list, or a space separated string.
4
[1, 2, 2, 1]

8
"1 4 60 360 360 60 4 1"

@totallyhuman No, the only thing to stdout should be the nth row.

Pascal, 249 247 233 bytes
Well, this is Pascal's alternating triangle.
1 byte saved thanks to @Mr.Xcoder
function f(n,k:integer):integer;begin if((k<1)or(k>n)or(n=1))then f:=n mod 2 else if n mod 2=0then f:=f(n-1,k-1)*f(n-1,k)else f:=f(n-1,k-1)+f(n-1,k)end;
procedure g(n:integer);var k:integer;begin for k:=1to n do write(f(n,k),' ')end;

Try it online!

248 bytes

Python 2, 97 93 86 81 78 bytes
-4 bytes thanks to Rod. -10 bytes thanks to Halvard Hummel.
f=lambda n:n and[[i+j,i*j][n%2]for i,j in zip([n%2]+f(n-1),f(n-1)+[n%2])]or[1]

0-indexed.
Try it online!

Good job, I had a (much) longer approach. Though I didn't have time to golf it yet.

I guess that map([int.__add__ ,int.__mul__][i%2],[i%2]+a,a+[i%2]) should work (didn't tested)

It don't have a zip, look closer

Rod is right, 94 bytes.

83 bytes

I think I made an error

@HalvardHummel That fails for 5 and 6.

This should be correct

You are allowed to put the "f=" in the header

No, this is recursive. You must include the name.

Ahh, okay. Learn something new every day

The rules allow 0 indexing

Python 2, 96 89 87 bytes

2 bytes Thanks to Mr. Xcoder: s=[1]
A bit different than totallyhuman's answer

s=a=[1]
for i in range(1,input()):a=s+[[k+l,k*l][i%2]for k,l in zip(a[1:],a)]+s
print a

Try it online!

Even shorter as a recursive function

@totallyhuman Thanks.. I rolled it back...

Suddenly exec method is leading :D

87 bytes, declaring [1].

Jelly, 17 12 bytes
µ×+LḂ$?Ḋ1;µ¡

This is a full program (or niladic link) that takes input from STDIN.
Try it online!
How it works
µ×+LḂ$?Ḋ1;µ¡  Main link. No arguments. Implicit argument: 0

          µ¡  Start a monadic chain and apply the ntimes quick to the previous one.
              This reads an integer n from STDIN and executes the previous chain n
              times, with initial argument 0, returning the last result.
µ             Start a monadic chain. Argument: A (array or 0)
       Ḋ          Dequeue; yield A without its first element.
   LḂ$?           If the length of A is odd:
 ×                    Multiply A and dequeued A.
                  Else:
  +                   Add A and dequeued A.
        1;        Prepend a 1 to the result.

Husk, 17 16 bytes
!G₅;1¢e*+
:1Sż⁰t

Try it online!
A 1-indexed solution.
Explanation
The first line is the main function, which calls the helper function on the second line.
The helper function is usually called with ₁, but in this case I'm using the overflowing labels feature of Husk: if you refer to a line N in a program with M < N lines, you get line N mod M with modifier function M / N applied to it.
The second modifier function is flip, so I'm using ₅ to flip the arguments of the helper function with no additional byte cost.
Here is the helper function.
:1Sż⁰t  Takes a function f and a list x.
   ż    Zip preserving elements of longer list
    ⁰   using function f
  S  t  x and its tail,
:1      then prepend 1.

Here is the main function.
!G₅;1¢e*+  Takes a number n.
      e*+  2-element list of the functions * and +
     ¢     repeated infinitely.
 G         Left scan this list
  ₅        using the flipped helper function
   ;1      with initial value [1].
!          Get n'th element.

R, 108 98 bytes
-10 bytes by replacing the actual multiply sign with a plus sign. Please forgive me.
f=function(n){if(n<3)return(rep(1,n))else{v=f(n-1)};if(n%%2)`*`=`+`;return(c(1,v[3:n-2]*v[-1],1))}

Try it online!
Quite pleased with the general method (first time I've aliased a primitive) but I'm sure there's golfing to be done on it yet, especially with the awkward handling of cases where n<3 which leads to a lot of boilerplate.

85 bytes. I really love your solution with \*`=`+``! quite clever. The rest of my improvements are just standard golfing techniques, which I would be happy to explain at your request :)

80 bytes. I took inspiration from your note about handling cases where n<3

CJam, 25 bytes
{1a\{2%!_2$+\{.*}{.+}?}/}

0-indexed.
Try it online!
Explanation
This is an anonymous block that takes the number from the stack and leaves the result on the stack.
1a                        Push [1].
  \                       Bring the number to the top.
   {                 }/   For reach number 0 .. arg-1, do:
    2%!                    Push 0 if even, 1 if odd.
       _                   Copy that.
        2$+                Copy the list so far and prepend the 0 or 1 to it.
           \               Bring the 0 or 1 back to the top.
            {.*}{.+}?      If 1, element-wise multiplication. If 0, element-wise addition.

Wait 2%! should push 1 if even and 0 if odd, no?

Haskell, 76 72 bytes
0-indexed solution:
(p!!)
p=[1]:[zipWith o(e:l)l++[1]|(l,(o,e))<-zip p$cycle[((*),1),((+),0)]]

Try it online!
Explanation
p recursively defines the alternating triangle, the base case/first element of it is [1]
p=[1]:[                                                            ]

It then builds the triangle by taking the previous line (l). To know what to do with it we need to keep track of the correct operator (o) and the corresponding neutral element (e):
                           |(l,(o,e))<-zip p$cycle[((*),1),((+),0)]

From this build the new line by duplicating the line and for one copy we prepend the neutral element, zip them with the operator and append a 1:
       zipWith o(e:l)l++[1]

Mathematica, 92 bytes
(s={i=1};While[i<#,s=Flatten@{1,{Tr/@#,Times@@@#}[[i~Mod~2+1]]&@Partition[s,2,1],1};i++];s)&

Try it online! (in order to work on mathics "Tr" is replaced with "Total")

J, 32 bytes
[:(1,]{::(}.@,-.)(*;+)[)~/2|]-i.

Try it online!

Perl 5, 111 + 2 (-na) = 113 bytes
sub t{($r,$c)=@_;!--$r||!$c||$c>=$r?1:eval"t($r,$c)".($r%2?"*":"+")."t($r,$c-1)"}say map{t($F[0],$_).$"}0..$_-1

Try it online!

Mathematica, 70 bytes
Fold[#2@@@Partition[#,2,1,{-1,1},{}]&,{1},PadRight[{},#,{1##&,Plus}]]&

Try it at the Wolfram sandbox! It doesn't work in Mathics, unfortunately. It's 0-indexed.
Explanation: Partition[#,2,1,{-1,1},{}] takes a list and returns all the two-element sublists, plus 1-element lists for the start and end — e.g., {1,2,3,4} becomes {{1}, {1,2}, {2,3}, {3,4}, {4}}. PadRight[{},#,{1##&,Plus}] makes an alternating list of 1##& (effectively Times) and Plus, whose length is the input number. Then Fold repeatedly applies the partition function with the Pluses and Timeses applied to it, to make the rows of the triangle.

C# (.NET Core), 143 134 128 bytes
-4 bytes thanks to Phaeze
-5 bytes thanks to Zac Faragher
-6 bytes thanks to Kevin Cruijssen
n=>{int[]b={1},c;for(int i=0,j;++i<n;b=c)for(c=new int[i+1],c[0]=c[i]=1,j=0;++j<i;)c[j]=i%2<1?b[j-1]+b[j]:b[j-1]*b[j];return b;}

Try it online!
Explanation:
n =>
{
    int[] b = { 1 }, c;               // Create first layer
    for(int i = 0, j; ++i < n; b = c) // Iterate for every layer, replace last layer with a new one
        for(c = new int[i+1],         // Create new layer
            c[0] = c[i] = 1,          // First and last elements are always 1
            j = 0;
            ++j < i; )                // Replace every element (besides 1st and last)...
                c[j] = i % 2 == 0 ?
                    b[j - 1] + b[j] : // ... with addition...
                    b[j - 1] * b[j];  // ... or multiplication of two from previous layers
    return b;                         // Return latest layer
};

You should be able to change your b array initialization to var b=new[]{1}; and the compiler will determine the array type for you.

Another way to construct the first layer is int[]b={1}; - 11 bytes vs 20 as is or 16 as in @Phaeze 's suggestion

@ZacFaragher and Phaeze thank you!

I know it's been quite a while, but you can golf 6 more bytes: n=>{int[]b={1},c;for(int i=0,j;++i<n;b=c)for(c=new int[i+1],c[0]=c[i]=1,j=0;++j<i;)c[j]=i%2<1?b[j-1]+b[j]:b[j-1]*b[j];return b;}. I've combined c like thisint[]b={1},c;; shortened i%2==0 to i%2<1; And removed the brackets of the loop by putting everything inside.

Great! Thanks @KevinCruijssen

Python 2, 83 bytes
Give some love to exec
0-indexed
l=[1];exec"l[1:]=[[a+b,a*b][len(l)%2]for a,b in zip(l,l[1:])]+[1];"*input()
print l

Try it online!

Pyth, 22 bytes
Saved tons of byte thanks to @FryAmTheEggman! The initial solution is below.
u++1@,+VGtG*VGtGlG1Q[1

Full Test Suite (0-indexed).
Pyth, 40 38 36 35 bytes
This feels waaaaaaaay too reasonably long. Suggestions are welcome.
K]1VStQ=K++]1m@,sd*hded%N2C,KtK]1;K

Test Suite or Try it online!

Using reduce seems to be much shorter. I'm not convinced this is optimal either, I think sub 20 is manageable?

@FryAmTheEggman See my revision history. I said I was trying to find a workaround with reduce u (but couldn't figure it out). Thanks!

If Pyth would have a prepend-append built-in...

TI-Basic (TI-84 Plus CE), 100 bytes
Prompt X
{1→M
For(A,2,X
LM→L
A→dim(M
For(B,2,A–1
If A/2=int(A/2
Then
LL(B–1)LL(B→LM(B
Else
LL(B–1)+LL(B→LM(B
End
End
1→LM(dim(LM
End
LM

1-indexed, prompts user for input and prints a list containing the nth row of Pascal's Alternating Triangle.
While looping: LM is the current row, and LL is the previous row.
TI-Basic is a tokenized language. All tokens used here are one-byte tokens.
I think I can golf this further by modifying M in-place from the end.
Explanation:
Prompt X            # 3 bytes; get user input, store in X
{1→M                # 5 bytes, store the first row into LM
For(A,2,X           # 7 bytes, Loop X-1 times, with A as the counter, starting at 2
LM→L                # 5 bytes, copy list M into list L
A→dim(M             # 5 bytes, extend M by one
For(B,2,A–1         # 9 bytes, for each index B that isn't the first or last...
If A/2=int(A/2      # 10 bytes,    if A is even...
Then                # 2 bytes,     then...
LL(B–1)LL(B→LM(B     # 17 bytes,        the Bth item in this row is the Bth times the (B-1)th of the previous row
Else                # 2 bytes,     else...
LL(B–1)+LL(B→LM(B    # 18 bytes,        the Bth item in this row is the Bth plus the (B-1)th of the previous row
End                 # 2 bytes,     endif
End                 # 2 bytes,  endfor
1→LM(dim(LM         # 9 bytes, the last item is always 1
End                 # 2 bytes, endfor
LM                  # 2 bytes, Implicitly print the final row

Ruby, 83 82 bytes
->n{a=[1];p=0;n.times{a=[p=1-p,*a,p].each_cons(2).map{|x|x.reduce([:+,:*][p])}};a}

Try it online!
This is 0-indexed.

Racket, 116 bytes
(define(t n[i 1][r'(1)])(if(= n 1)r(t(- n 1)(- 1 i)(cons 1(append(map(if(> i 0)* +)(cdr r)(reverse(cdr r)))'(1))))))

Try it online!

JavaScript (ES6), 71 69 66 bytes
f=n=>n?(p=f(n-1),[...p.map((v,i)=>i--?n%2?v*p[i]:v+p[i]:1),1]):[1]

Try it online!
0-indexed.
-3 bytes by @Arnauld

f=n=>n?(p=f(n-1),[...p.map((v,i)=>i--?n%2?v*p[i]:v+p[i]:1),1]):[1]

for (var i = 0; i < 10; ++i) {
  console.log(JSON.stringify(f(i)));
}

Using a ternary should save 3 bytes: i--?n%2?v*p[i]:v+p[i]

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


text:
Bifurcated text
Given a string of ASCII letters (upper and/or lower case), output the raw MathJax required to display that string bifurcating at each character, into superscripts and subscripts. For example, the inputs cat and horse would result in outputs which MathJax renders as the following, respectively:

Note that only one input is required to be taken - these two are listed side by side simply to save vertical space.
Markup meaning

_ indicates a subscript.
^ indicates a superscript.
Braces are required around superscripted or subscripted substrings that contain further superscripting or subscripting in order to prevent them all being at the same level.

Test cases
Test cases are in the format input : output. The first test case shows the empty string as input should result in the empty string as output.
"" : ""
"a" : "a"
"me" : "m_e^e"
"cat" : "c_{a_t^t}^{a_t^t}"
"frog" : "f_{r_{o_g^g}^{o_g^g}}^{r_{o_g^g}^{o_g^g}}"
"horse" : "h_{o_{r_{s_e^e}^{s_e^e}}^{r_{s_e^e}^{s_e^e}}}^{o_{r_{s_e^e}^{s_e^e}}^{r_{s_e^e}^{s_e^e}}}"
"bifurcate" : "b_{i_{f_{u_{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}^{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}}^{u_{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}^{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}}}^{f_{u_{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}^{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}}^{u_{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}^{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}}}}^{i_{f_{u_{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}^{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}}^{u_{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}^{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}}}^{f_{u_{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}^{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}}^{u_{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}^{r_{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}^{c_{a_{t_e^e}^{t_e^e}}^{a_{t_e^e}^{t_e^e}}}}}}}"

You can see how these are rendered by pasting the output into mathurl.com.
No redundant braces
MathJax will happily render markup that has redundant braces. For example, the following will all look identical when rendered: a, {a}, {}{a}, {{{{a}}}}.
However, valid output for this challenge has no redundant braces. Note in particular that single characters in the output are not surrounded by braces.
Order
The order of subscript and superscript is unimportant. The following are equivalent and will be indistinguishable when rendered (and are all equally valid outputs):
c_{a_t^t}^{a_t^t}
c_{a^t_t}^{a_t^t}
c_{a_t^t}^{a^t_t}
c_{a^t_t}^{a^t_t}
c^{a_t^t}_{a_t^t}
c^{a^t_t}_{a_t^t}
c^{a_t^t}_{a^t_t}
c^{a^t_t}_{a^t_t}

Scoring
For each language, the winner is the shortest code in bytes.
Too many notifications? Type  to unsubscript

Too many notifications? Type  to unsubscript huh who said I want to unsubscript or something? It was a test to see if I read the whole post right?

@EriktheOutgolfer no it was just a very bad joke.

Can we just output the compiled pdf result instead?  I would like to write a pure Latex answer.

@WheatWizard that sounds like a different challenge. It wouldn't be valid as an answer here.

Python, 95 90 86 92 82 bytes
10 bytes saved thanks to @ConnerJohnston
f=lambda s:s and s[0]+(s[1:]and'_{0}^{0}'.format(s[2:]and'{'+f(s[1:])+'}'or s[1]))

Try it online!

Wow, that is some crazy recursion.

Some string formatting for 81 bytes (not sure how to TIO link in comments yet):   f=lambda s:s and s[0]+'_{0}^{0}'.format(s[2:]and'{'+f(s[1:])+'}'or s[1:]and s[1])

@ConnerJohnston thanks! you can put tio links with [text](link), but that's really spoiling ;)

79 bytes; and I assume you do not want to use the anonymous function trick, would save 2 bytes though.

CJam (35 bytes)
MqW%{"^{ }_{ }"{AW$,)3e<#<},S/@*+}/

This is a full program. Online demo.
3 bytes work around a bug in the interpreter (see below).
Dissection
M            e# Start building from the empty string
qW%{         e# For each character in the reversed input
  "^{ }_{ }" e#   Take a template
  {          e#   If the accumulator is of length n, remove all characters whose
    A        e#   codepoints are greater than pow(10,
    W$,)3e<  e#                                   min(n+1, 3))
    #<       e#   When the accumulator is the empty string, that's all of them.
  },         e#   When the accumulator is one character, that's {}
             e#   When the accumulator is any longer, it's none of them.
  S/@*       e#   Substitute the accumulator for the spaces.
  +          e#   Append to the new character.
}/

Note that the min(n+1, 3) is to work around a bug in the interpreter: there must be some pattern in the powers of 10 that '} is smaller than, but it's not obvious.

Doesn't appear to work for the empty string (first test case).

@trichoplax, that was due to a subtle difference between GolfScript and CJam which occasionally catches me out. Now fixed at the cost of only one byte by making the code far cleverer than it previously was.

Works perfectly now. Great explanation.

@PeterTaylor (At least in the online demo) It does not work for words with more than four letters.

@dessert, that is very weird, and definitely deserves a bug report against the interpreter. I have added a workaround at a cost of 3 bytes.

JavaScript (ES6), 57 55 bytes
f=([c,...s])=>s+s?c+`_${p=s[1]?`{${f(s)}}`:s}^`+p:c||''

Θ(len(s)) complexity! According to @PeterTaylor, this is actually Θ(2^len(s)), which is still the best possible...

Doesn't appear to work for the empty string (first test case).

@trichoplax Should be fixed now.

Works perfectly now.

What is n in your O(n)? I presume it's the length of the output, but unless you state that it is interpreted by default to be the length of the input, and since the length of the output is exponential in the length of the input it's impossible to implement in polynomial time.

@PeterTaylor I had figured that since the algorithm only takes len(input) steps, that the complexity is len(input)... if that isn't correct I'll just remove it from the post since I don't know how to calculate it, unless you know what the correct complexity is.

If each step were O(1)... But no, the complexity is Theta(2^n)

Mathematica, 72 84 77 76 bytes
a_±b__:={"{",a,"_",±b,"^",±b,"}"};±(a_:""):={"",a,""};""<>Most@Rest@±##&@@#&

Uses CP-1252 (Windows) encoding. Takes a list of characters as input.
Explanation
a_±b__:=

Define the function ±, with 2 or more arguments. Label the first argument a, and second and on b.
{"{",a,"_",±b,"^",±b,"}"}

Create a List equivalent to "{a_±b^±b}" (±b is evaluated again, recursively).
±(a_:""):= ...

Define the function ±, with 1 or 0 arguments. Label the first argumenta, if it exists, and assign "" to a otherwise.
{"",a,""}

Create a List equivalent to "a", padded with empty Strings.
""<>Most@Rest@±##&@@#&

A pure function that applies ± to the input, drops first and last element, and converts List to String.

Haskell, 71 bytes
f[x,y]=x:'_':y:'^':y:[]
f(x:y@(_:_))=x:"_{"++f y++"}^{"++f y++"}"
f x=x

Try it online!
If we just had to output valid code the following would work for 44 bytes:
f[a]=[a]
f(a:b)=a:"_{"++f b++"}^{"++f b++"}"

Try it online!

-5 bytes, based on the 44 bytes version: Try it online!

@jferard Nice! I'll add that to the post.

66 bytes: Try it online!

63 bytes: Try it online!

59 bytes: Try it online!

Perl 5, 54 + 1 (-p) = 55 bytes
s/\{(.)\}/$1/g while s/([a-z])([a-z]+)/$1_{$2}^{$2}/ig

Try it online!
How?
The substitution in the while condition breaks occurrences of multiple letters in the first letter, followed by the rest in braces like this:
abc -> a_{bc}^{bc}

The while loop executes the substitution until no more multi-letter sequences remain.  The substitution inside the loop removes braces from around single letters.

Nice, I was wondering how long it would take for a regex answer to show up

SOGL V0.12, 21 bytes
±K;{╔+;lH?"{ŗ}”}1 ^Ο+

Try it Here!
Explanation:
±                      reverse the string
 K                     take off the first letter - will slowly convert to the output
  ;                    get the rest of the string ontop
   {                   iterate over the rest of the characters
    ╔+                   append "_" to it
      ;                  get the output string ontop
       lH?     }         if it's length - 1 [isn't 0]
          "{ŗ}”            push the string "{ŗ}" where ŗ is replaced by the output string
                1 ^Ο     wrap "^" around with the output string
                    +    prepend to it the current character + "_"

Ruby, 76 73 72 68 67 57 bytes
Use of lambda saving 4 bytes thanks to Tutleman
f=->s{(r=s[1..-1])[0]?s[0]+?_+[r[1]??{+f[r]+?}:r]*2*?^:s}

Try it online!
Ungolfed:
def f(s)
  r = s[1..-1]
  if r.size > 0
    if r.size > 1
      x = "{" + f(r) + "}"
    else
      x = r
    end
    return s[0] + "_" + [x, x].join("^")
  else
    return s
  end
end

Instead of a function, use an anonymous lambda (e.g. ->s{...}), which saves 7 bytes. Then, you can save 2 more bytes by replacing "#{s[0]}_ with s[0]+"_. You can save one further byte by doing inline assignment of '{}' to a variable the first time you use it.

@Tutleman It's recursive (t=f s[1..-1]), so I don't think an anonymous function will work, and I already rearranged the beginning of the string, but I can use the inline assignment.

D'oh! Whoops - I can't believe I missed that. Anyway, it's still shorter to use a (named) lambda: f=->s{...} saves 4 bytes, even accounting for the extra [] you need when making the recursive call.

@Tutleman Oh yeah, changed it. Now if I can come up something better than that .tr mess...

Python 2, 84 bytes
def b(s):q=s and(s[2:]and'{%s}'or'%s')%b(s[1:]);return s[1:]and s[0]+'^%s_'%q+q or s

Try it online!

PHP, 121 bytes
function b($s){return $s[0].($s[1]?'_'.($s[2]?'{'.($b=b(substr($s,1))).'}^{'.$b.'}':"$s[1]^$s[1]"):'');}echo b($argv[1]);

The function itself is 104 bytes and shows a PHP Notice.

Retina, 43 bytes
(.)(.)$
$1¶$2
+`(.)¶(.*)
¶{$1_$2^$2}
¶{|}$

Try it online! Link includes test cases. Explanation:
(.)(.)$
$1¶$2

Get the ball rolling by slicing off the last character. (But if it's the only character, them leave it alone.)
+`(.)¶(.*)
¶{$1_$2^$2}

Move the ¶ character back one step at a time, each time taking the previous result and making it a subscript and superscript of the next character.
¶{|}$

Remove the now redundant ¶ and the outer {}s.

Pyth, 47 bytes
Ljk[hb|&ttbs[\_\{ytb"}^{"ytb\})&tbs[\_htb\^htb;

Try it online!
This is pretty much a straight port of @Uriel's Python answer.  Going to golf it down in a bit.

Java (OpenJDK 8), 121 bytes
s->{int l=s.length;String r=--l<0?"":""+s[l];for(;l-->0;)r="{"+s[l]+"_"+r+"^"+r+"}";return r.replaceAll("^\\{|\\}$","");}

Try it online!

Javascript, 73 Bytes
s=>[...s].reduceRight((m,c)=>`${c}_{${m}}^{${m}}`).replace(/{(.)}/g,'$1')

Explanation
s=>                                  // take the input string
    [...s]                           // split the string into an array
    .reduceRight(                    // reduce the array in reverse order
        (m,c)=>`${c}_{${m}}^{${m}}`  // storing the result of each iteration in the memo m
    )                                // and returning m at the end
    .replace(/{(.)}/g,'$1')          // replace redundant {}

Because there is no specified initial value of m, reduceRight takes the last element of s as the initial value, and begins iterating at index s.length-2.

const f=s=>[...s].reduceRight((m,c)=>`${c}_{${m}}^{${m}}`).replace(/{(.)}/g,'$1');

const input = document.querySelector('#input');
const output = document.querySelector('#output');
output.textContent = f(input.value);
input.addEventListener('keyup', e => output.textContent = f(input.value));
Enter text to bifurcate: <input type="text" id="input" value="cat" />

s=>[...s].reduceRight((m,c)=>`{${c}_${m}^${m}}`).slice(1,-1) is only 60 bytes.

Doesn't appear to work for the empty string (first test case).


text:
Alarm Optimization
My Alarm Clock
I'm American, and so is my (digital) alarm clock. To set the alarm, it starts at the time it was previously. Hitting the hour button moves it up one hour, and hitting the minute button moves it up one minute. Hitting both buttons at the same time resets it to midnight (12:00 am), and counts as two button presses.
When the hours exceed their cap (12), it resets to 1 and toggles the AM/PM light. When the minutes exceed their cap (59), they reset to 0, without affecting the hours.
The Task
Your task is, given a starting time and a target time, to output the optimal number of buttons presses needed to set my alarm to the target time.
You may take input in whatever format suits you best. The only data your program should need is hours and minutes, for both inputs. That means that you, for example, may take data as milliseconds since epoch, and extract the hours and minutes, but you may not encode anything into the year, month, second, etc. Note that while you may, for example, input using "military time" (or regular time for most of the world), but that doesn't change how my clock works.
Examples
1:15 pm -> 2:30 am

You could push down both buttons to reset to 12:00 am, then increment to 2:30 am, which would be 2+2+30 = 34 button presses. You could also increment to 2:30 am, which would be 13+15 = 28 button presses. Therefore, your output is 28.
3:58 am -> 4:02 am

You could reset and increment, which would be 2+4+2 = 8 button presses. You could also increment, which would be 1+4 = 5 button presses. Therefore, your output is 5.
10:55 pm -> 1:00 am

You could reset and increment, which would be 2+1 = 3 button presses. You could also increment, which would be 3+5=8 button presses. Therefore, your output is 3.
1:00 am -> 1:59 pm

You could reset and increment, but that would be three more presses than just incrementing. Therefore, your output is 12+59 =  71.
Test Cases
Current  Target   = Output
1:15pm   2:30am   = 28
3:58am   4:02am   = 5
10:55pm  1:00am   = 3
1:00am   1:59pm   = 71
12:00am  12:00am  = 0
6:51pm   12:00am  = 2
2:01pm   11:00pm  = 25
2:01pm   11:01pm  = 9
12:59am  12:01am  = 2
11:50am  12:00pm  = 11

Sandbox

Holy crap! Pressing the two buttons does reset my (European) alarm clock to 0:00 as well... All these years spent pressing the buttons too many times... O_o

@StepHen, I know you're very relaxed on the input format here, but could you throw an eye at my JS solution, let me know if it's OK to take input like that?

@Arnauld I discovered it by chance as well - since then I've done these mental gymnastics in my head to figure out which was optimal when trying to reset my alarm :P

@Shaggy yup that's fine. Same thing that HyperNeutrino's Python answer is doing

"military time (or regular time for most of the world)"...the term you're looking for is "24-hour time".

@Jakob I know that's the term, but (unless I'm mistaken) very few people would call it that casually, as if you use it it's just regular time - I may be mistaken though.

@Jakob No, the term he's looking for is "regular time". Americans use irregular time, irregular dates, irregular units, etc. etc.

@StepHen I am in the UK and had no idea what you meant by "military time" until Jakob explained it. 24hr time makes perfect sense to me

Husk, 16 bytes
§▼ṁ→(Σz%e24 60z-

Try it online!
Takes arguments as two lists [hours,minutes], for start and end time, in 24h format.
I'm quite happy about how much I was able to golf this one, I find interesting how arguments are managed in this composition of functions.
The function which calculates how many key presses we need if reset is not allowed is the following:
Σz%e24 60z-
         z-    elementwise subtract the two times
 z%e24 60      take the hours difference modulo 24 and the minutes difference modulo 60
Σ              sum the two resulting numbers

The interesting part is that since the rest of this solution can work only with a single list as argument, this one gets partially applied to the first argument of the whole program, "eating" it and leaving only the second argument visible both for itself and the rest of the program.
Next, we compute how many key presses we need if we reset the time to 0:00
ṁ→    take the sum of each element of the list increased by 1

As said before, this operates only on the second argument (the final time), and computes hours+minutes+2, just in a golfier way.
Finally, §▼ is the part that passes the second argument to both functions, and returns the lesser of the two results.

JavaScript (ES6), 73 56 54 52 50 bytes
Uses 24 hour format. Takes input as 4 integers representing the hours & minutes of each time.
(g,l,h,m)=>Math.min(2+h+m,(h-g+24)%24+(m-l+60)%60)

2 bytes saved thanks to Arnauld.

Try it
Enter the times in 24-hour format, with the : separator.

o.innerText=(f=

(g,l,h,m)=>Math.min(2+h+m,(h-g+24)%24+(m-l+60)%60)

)(+(x=(i.value="01:00").split`:`)[0],+x[1],+(y=(j.value="13:59").split`:`)[0],+y[1]);oninput=_=>o.innerText=f(+(x=i.value.split`:`)[0],+x[1],+(y=j.value.split`:`)[0],+y[1])
label,input{font-family:sans-serif;font-size:14px;height:20px;line-height:20px;vertical-align:middle}input{margin:0 5px 0 0;width:100px;}
<label for=i>Current: </label><input id=i type=time><label for=j>Target: </label><input id=j type=time><pre id=o>

Explanation
(To be updated shortly.)
(g,l,h,m)=>

Anonymous function taking the integers as arguments via parameters g, l, h & m, where g & l are, respectively, the hours & minutes of the current time and h & m are the hours & minutes of the target time.
2+h+m

First, we calculate how many button presses are needed if we just reset the clock, which is simply 2 (for the reset) plus the target hour and the target minute.
h-g+24*(h<g)

Next we calculate how many button presses are needed to reach the target hour. We do this by subtracting the current hour from target hour. However, if the current hour is less than the target, this will give us a negative number so we rectify that by adding 24 multiplied by checking if h<g (which returns a boolean but is implicitly cast to integer 1, if true, or 0 if false by the mathematical operations.
+m-l+60*(m<l)

We use a similar formula to calculate the number of presses to get from the current minute to the target minute and add that to the hour presses.
Math.min()

Finally, we get the minimum of the 2 numbers to give us our result.

Could you do (h-g+24)%24+(m-l+60)%60?

Pyth, 29 bytes
This challenge obviously doesn't advantage golfing languages, that's why it's so long. On the other hand, this is improved by the fact that Pyth is Python-based, so we can abuse its negative modulus.
hS,+%-eQ@Q1 60%-@Q2hQ24+2s>Q2

Test Suite. Numbers in Pyth do not support leading zeros.

Jelly, 19 bytes
_⁵%24µ+⁴_⁶%60µ«³+⁴¤

Try it online!
Input as 4 integers (end-hour, end-minute, start-hour, start-minute)

https://i.stack.imgur.com/mYVF7.jpg

@ETHproductions ಠ_ಠ

C# (.NET Core), 56 bytes
(H,M,h,m)=>Math.Min(((h+24-H)%24)+((m+60-M)%60),(2+h+m))

Try it online!
Very similar to the Javascript answer. Bools in C# don't convert easily to numbers, so instead of [diff]+24*(H<h) I did ([diff]+24)%24 which effectively does the same thing.

You can remove the parenthesis around 2+h+m for -2 bytes.

I've created a port of your answer in Java 8, and noticed you can golf an additional four bytes by removing more parenthesis, ending with this (H,M,h,m)=>Math.Min((h+24-H)%24+(m+60-M%60),2+h+m)

Wouldn't you have to make it System.Math.Min ?

Haskell, 41 bytes
(a#b)c d=min(a+b+2)$mod(a-c)24+mod(b-d)60

Pretty straightforward. Takes input as four arguments using 24-hour time: end hour, end minute, start hour, start minute.

Python 3, 43 bytes
lambda a,b,c,d:min((c-a)%24+(d-b)%60,2+c+d)

Try it online!
Input as 4 integers (start-hour, start-minute, end-hour, end-minute)

@StepHen Whoops. Easy fix.

Fails for 2 01 11 00? In your answer, how do you determine if the time is AM or PM, if you don't take that as input?

@Mr.Xcoder; I get 13 for that input using the TIO, which is correct (reset+11<9+59).

@Mr.Xcoder 24 hour time

Ok, ok... I seem to have misunderstood.

@Mr.Xcoder my input spec was very loose, you can do basically whatever you want to get the input

Does % always return a positive number in Python?

@Shaggy it always returns the sign of the right side of the %. 1%24 = 1, 1%-24 = -23. It's very helpful for this question.

Java 8, 54 50 bytes
(h,m,H,M)->Math.min((H-h+24)%24+(M-m+60)%60,H+M+2)

Port of @KamilDrakari's C# answer (after I golfed 2 6 bytes).
Explanation:
Try it here.
(h,m,H,M)->       // Method with four integer parameter and integer return-type
  Math.min(       //  Return the lowest of the following two:
                  //   The hours:
   (H-h           //    Second hours - first hours inputs
       +24)       //    +24 so we won't have negative numbers
           %24    //    mod-24 to get the hours
   +              //   And add the minutes:
    (M-m          //    Second minutes - first minutes inputs
         +60)     //    +60 so we won't have negative numbers
             %60  //    mod-60 to get the minutes
    ,H+M          //  And compare it to the second hours + second minutes inputs
        +2)       //   +2 for the added +24 and +60 to get the positive modulo arguments

Perl 5, 71 +2 (-ap) = 73 bytes
($w,$x,$y,$z)=@F;$_=($r=2+$y+$z)>($c=($y-$w+24)%24+($z-$x+60)%60)?$c:$r

Try it online!
Takes input in 24 hour format (military time), separated by spaces, start time first, end time second: HH MM hh mm

Retina, 106 bytes
\d+
$*
 (1*):(1*)
 24$*1$1:60$*1$2#11$1$2
(1*):(1* )\1(1{24})?
$2
(1*) (1*):\1(1{60})?
$2
(1+)#(?!\1)

\G1

Try it online! Link includes test cases. Takes input as current and desired times in regular 24 hour time with a space separating the two times. Explanation:
\d+
$*

Convert to unary.
 (1*):(1*)
 24$*1$1:60$*1$2#11$1$2

This does two things; it adds 24 hours and 60 minutes to the desired hours and minutes, and it also adds 2 to the sum of the original desired hours and minutes, i.e. the the number of button presses to set using a reset.
(1*):(1* )\1(1{24})?
$2

Subtract the current hours from the desired hours, and subtract the 24 we added on if we can.
(1*) (1*):\1(1{60})?
$2

Similarly for the minutes. This also adds the two results together.
(1+)#(?!\1)

If the number of presses to set using the current time is more than the number of presses to set using a reset, delete it.
\G1

Convert the first remaining number back to decimal.


text:
Kill it With Fire

Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro.

I am an evil farmer, and to drive up the price of wheat in my area, I've decided to burn the fields of all the farmers around me.  I would really like to see the fields go up in flames (so I can use my evil laugh and rub my hands together with glee), but I also don't want to be caught watching, so I need you to simulate the field being incinerated for me.
Your Task:
Write a program or function that takes as input a field, and returns the stages of it burning until the entire field is ash.  A specific section of the field that is on fire is represented by an integer representing the intensity of the flame.  A fire starts at "1" and moves on to "2" and then "3", and so on.  Once a fire reaches "4", it catches any directly (not diagonally) adjacent areas that are flammable on fire.  Once it reaches "8", it burns out on the next iteration, and turns into ash, represented by an "A".  When an area has not yet been touched by fire, it is represented by a "0".  For example, if the field looks like this:
100
000

Your program should output this:
100
000

200
000

300
000

410
100

520
200

630
300

741
410

852
520

A63
630

A74
741

A85
852

AA6
A63

AA7
A74

AA8
A85

AAA
AA6

AAA
AA7

AAA
AA8

AAA
AAA

If you wish, you may replace the above symbols with any set of symbols you choose, as long as they are consistent and distinct from each other.
Input:
The starting position of the field, in any standard form, such as a newlined-delimated string as above.
Output:
The field in every iteration as it burns, either as an array, or as a string delimited by some character.
Test Cases:
0301
000A
555
 |
 v
0301
000A
555

1412
010A
666

2523
020A
777

3634
030A
888

4745
141A
AAA

5856
252A
AAA

6A67
363A
AAA

7A78
474A
AAA

8A8A
585A
AAA

AAAA
6A6A
AAA

AAAA
7A7A
AAA

AAAA
8A8A
AAA

AAAA
AAAA
AAA

Scoring:
This is code-golf, lowest score in bytes wins!

Related

Certainly related, but not a duplicate IMO.

How much can the shape vary? Are the non-rectangular parts always "holes" on the right edge, or can there be spaces in the field?

So something that hits 4 starts a fire in adjacent squares, but something that starts out at 4 or higher doesn't? That's not very realistic.

So the field is not guaranteed to be rectangular ... Can we at least assume that it has no gaps?

"Disclaimer: The story told within this question is entirely fictional, and invented solely for the purpose of providing an intro." -> Starts with "I'm an evil farmer [who wants to do evil stuff]." Very clever. No one will relate the burning fields to you now.

Is it possible for initial ash to separate the field in two, so that part of it will never burn?

So fires more intense than 4 don't spread? Strange.

@laszlok, I know, but it was a mistake in the spec that wasn't caught in the sandbox, and now I have answers, so I can't change it.

@Titus, yes you may.

If the fire not spreading above 4 is too upsetting, imagine that 1-4 is the fire gaining intensity and 5-A represents it burning out.

@Pietu1998, I'm sorry I didn't see your comment up there previously.  Non-rectangular sections are always gaps on the right side.

May we assume the field is at least 3×3? I.e. require smaller fields to be given with surrounding empty slots until at least 3×3 in size?

@Adám, sure you can.

For "The field in every iteration as it burns", can I go beyond the time when everything that would burn has burned to Ash? (as long as the code theoretically handles arbitrarily large fields) Or do I need to detect when no more changes will be made and stop showing new iterations then?

@MarkS., you need to stop showing iterations when no changes will be made.

APL (Dyalog), 52 bytes*
Assumes ⎕IO←0 which is default on many systems. Takes field using 0 for empty slots, 1 for non-burning field, 2 for new fire, 5 for spreading fire, and 10 for ash. Input must be at least 3×3, which isn't a problem as additional rows and columns may be padded with zeros (spaces in OP's format).
{}{1=c←4⊃r←,⍵:1+4∊r/⍨9⍴⍳2⋄10⌊c+×c}⌺3 3⍣{⍺≡⎕←⍵}

Try it online!
My format makes it hard to check for correctness, so here is a version with added pre- and post-processing to translate from and to OP's format.
⍣{…} repeat until:
 ⍺ the next generation
 ≡ is identical to
 ⎕←⍵ the current generation, outputted
{…}⌺3 3 replace each cell with the result of this function applied to its Moore neighborhood:
 ,⍵ ravel (flatten) the argument; gives nine-element list
 r← assign to r
 4⊃ pick the fourth element; the center, i.e. the original cell value
 c← assign to c
 1= is one equal to that?
 : if so, then:
  ⍳2 first to ɩntegers; 0 1
  9⍴ reshape to length nine; 0 1 0 1 0 1 0 1 0
  r/⍨ use that to filter r (this gets just the orthogonal neighbors)
  4∊ is four a member of that? (i.e. will there be a five in the next generation?)
  1+ add one; 1 if not caught fire or 2 if caught fire
 ⋄ else (i.e the current value is 0 or ≥ 2)
  ×c the signum of c
  c+ c plus that (i.e. increase by one if on fire)
  10⌊ minimum of ten and that (as ash doesn't burn on)

* In Dyalog Classic, using ⎕U233A  instead of ⌺.

Small, but doesn't deal with board changes.  Stuck to a 3x3.

@Suamere What? The board doesn't change size, does it?

Sorry, I wasn't clear.  Your answer is awesome, but I am of the understanding that the solution should allow for a variable sized board which may or may not have gaps "on the right".  Gaps in the middle are not required to be handled.  "On the Right" seems to mean a size-15 board would be built as a 4x4, except the right-most bottom piece is missing.  And a size-8 board would be built as a 3x3, except the right-most bottom piece is missing, etc.  That's how I read the challenge requirements.  Your answer is currently the shortest, but only works with a 3x3.

@Suamere OP clearly states that input is 2D. I take input as a numeric matrix and allow "empty" slots anywhere, in the form of zeros. While I require the input to be minimum 3×3 (OP allowed this) I accept input of any larger size. In fact, if you click the here link, you'll see that my second example case is 2×3 with the bottom right cell empty.

Gotcha.  Not sure why, but the Try It Here link has issues (Probably my fault), though your new formatted link works well.  E.G.: fire '0A000\n0A0A0\n0A0A0\n000A1' works perfect on the formatted one, but I can't get an equivalent to work with the first link.  I'm probably doing something wrong. This doesn't work for me: f ↑(0 0 0)(0 1 0)(0 0 0)

@Suamere Try it online! I added your test case to the here link.

Python 3, 232 bytes
def f(j):
 k=[[int(min(9,j[x][y]+(j[x][y]>0)or 3in(lambda k,x,y:[k[i][j]for i,j in[[x-1,y],[x+1,y],[x,y-1],[x,y+1]]if(-1<i<len(k))and(-1<j<len(k[i]))])(j,x,y)))for y in range(len(j[x]))]for x in range(len(j))]
 if k!=j:print(k);f(k)

Try it online!
-3 bytes thanks to officialaimm by merging the other lambda into f (looks messy but saves bytes and that's all we care about)
-8 bytes thanks to Mr. Xoder
-26 bytes thanks to ovs
-6 bytes thanks to ppperry

How do I add a blank space, like that in the example?

JavaScript (ES6), 217 210 207 204 193 192 190 bytes
Saved 2 bytes thanks to @Shaggy's suggestion of using 9 as A.

f=F=>[F,...(t=[],y=0,g=x=>(r=F[y])?(x||(t[y]=[]),r[x]+1)?(t[y][x]=r[x]<8?r[x]+(r[x]>0|[r[x-1],r[x+1],F[y-1]&&F[y-1][x],F[y+1]&&F[y+1][x]].includes(3)):9,g(x+1)):g(0,y++):t)(0)+""!=F?f(t):[]]

// test code
test=s=>{
  var test = document.querySelector("#in").value.split`\n`.map(e => Array.from(e).map(e => parseInt(e)));
  var out = f(test);
  document.querySelector("#out").innerHTML = out.map(e => e.map(e => e.join``).join`\n`).join`\n\n`;
};window.addEventListener("load",test);
<textarea id="in" oninput="test()">0301
0009
555</textarea>

Uses 9 instead of A. Input as a 2D array of integers. Output as an array of such arrays.

Could you save anything by using 9 instead of A?

Simulating the World (in Emoji), 1407 bytes?
Don't you love using an explorable explanation as a programming language? The downside to this is there's usually not a very well defined program, so in this case, I'm using the JSON it exports. (if you have any better ideas, let me know)
{"meta":{"description":"","draw":1,"fps":1,"play":true},"states":[{"id":0,"icon":"0","name":"","actions":[{"sign":">=","num":1,"stateID":"4","actions":[{"stateID":"1","type":"go_to_state"}],"type":"if_neighbor"}],"description":""},{"id":1,"icon":"1","name":"","description":"","actions":[{"stateID":"2","type":"go_to_state"}]},{"id":2,"icon":"2","name":"","description":"","actions":[{"stateID":"3","type":"go_to_state"}]},{"id":3,"icon":"3","name":"","description":"","actions":[{"stateID":"4","type":"go_to_state"}]},{"id":4,"icon":"4","name":"","description":"","actions":[{"stateID":"5","type":"go_to_state"}]},{"id":5,"icon":"5","name":"","description":"","actions":[{"stateID":"6","type":"go_to_state"}]},{"id":6,"icon":"6","name":"","description":"","actions":[{"stateID":"7","type":"go_to_state"}]},{"id":7,"icon":"7","name":"","description":"","actions":[{"stateID":"8","type":"go_to_state"}]},{"id":8,"icon":"8","name":"","description":"","actions":[{"stateID":"9","type":"go_to_state"}]},{"id":9,"icon":"A","name":"","description":"","actions":[]}],"world":{"update":"simultaneous","neighborhood":"neumann","proportions":[{"stateID":0,"parts":100},{"stateID":1,"parts":0},{"stateID":2,"parts":0},{"stateID":3,"parts":0},{"stateID":4,"parts":0},{"stateID":5,"parts":0},{"stateID":6,"parts":0},{"stateID":7,"parts":0},{"stateID":8,"parts":0},{"stateID":9,"parts":0}],"size":{"width":9,"height":9}}}

Try it here or here:

Retina, 103 96 88 bytes
^
¶
;{:`

T`0d`d
(?<=¶(.)*)0(?=4|.*¶(?<-1>.)*(?(1)_)4|(?<=40|¶(?(1)_)(?<-1>.)*4.*¶.*))
1

Try it online! Uses 9 for ash; this can be changed at a cost of 4 bytes using T`1-8`2-8A. Edit: Saved 6 bytes thanks to @MartinEnder. Explanation:
^
¶

Add a separator so that the outputs don't run into each other. (Also helps when matching below.)
;{:`

Don't print the final state (which is the same as the previous state which has already been printed). Repeat until the pass does not change the state. Print the current state before each pass.
T`0d`d

Advance the intensity of all the fire.
(?<=¶(.)*)0(?=4|.*¶(?<-1>.)*(?(1)_)4|(?<=40|¶(?(1)_)(?<-1>.)*4.*¶.*))
1

Light unlit fields as appropriate. Sub-explanation:
(?<=¶(.)*)

Measure the column number of this unlit field.
0

Match the unlit field.
(?=4

Look for a suitable field to the right.
  |.*¶(?<-1>.)*(?(1)_)4

Look for a suitable field in the same column (using a balancing group) in the line below. Note that if the input could be guaranteed rectangular then this could be simplified to |.*¶(?>(?<-1>.)*)4 for a saving of 3 bytes.
  |(?<=40

Look for a suitable field to the left. (Since we're looking from the right-hand side of the field, we see the unlit field as well.)
      |¶(?(1)_)(?<-1>.)*4.*¶.*))

Look for a suitable field in the same column in the line above. Since this is a lookbehind and therefore a right-to-left match, the balancing group condition has to appear before the columns that have been matched by the balancing group.

Perl 5, 365 bytes
@a=map{[/./g]}<>;do{say@$_ for@a;say;my@n=();for$r(0..$#a){$l=$#{$a[$r]};for(0..$l){$t=$a[$r][$_];$n[$r][$_]=($q=$n[$r][$_])>$t?$q:$t==9?9:$t?++$t:0;if($t==4){$n[$r-1][$_]||=1if$r&&$_<$#{$a[$r-1]};$n[$r+1][$_]||=1if$r<$#a&&$_<$#{$a[$r+1]};$n[$r][$_-1]||=1if$_;$n[$r][$_+1]||=1if$_<$l}}}$d=0;for$r(0..$#a){$d||=$a[$r][$_]!=$n[$r++][$_]for 0..$#{$a[$r]}}@a=@n}while$d

Try it online!
Uses '9' instead of 'A' to indicated a burned out location.
Explained
@a=map{[/./g]}<>;   # split input into a 2-D array

do{
say@$_ for@a;say;   # output the current state
my@n=();            # holds the next iteration as it's created
for$r(0..$#a){      # loop through rows
  $l=$#{$a[$r]};    # holder for the length of this row
  for(0..$l){
    $t=$a[$r][$_];  # temporary holder for current value
    $n[$r][$_]=($q=$n[$r][$_])>$t?$q:$t==9?9:$t?++$t:0; #update next iteration
    if($t==4){      # ignite the surrounding area if appropriate
      $n[$r-1][$_]||=1if$r&&$_<$#{$a[$r-1]};
      $n[$r+1][$_]||=1if$r<$#a&&$_<$#{$a[$r+1]};
      $n[$r][$_-1]||=1if$_;
      $n[$r][$_+1]||=1if$_<$l
    }
  }
}
$d=0;              # determine if this generation is different than the previous
for$r(0..$#a){$d||=$a[$r][$_]!=$n[$r++][$_]for 0..$#{$a[$r]}}
@a=@n              # replace master with new generation
}while$d

Octave, 72 69 bytes
a=input(''),do++a(a&a<9);a+=imdilate(a==4,~(z=-1:1)|~z')&~a,until a>8

The input is taken as a 2D array of numbers, and empty spots marked with Inf. 'A' has been replaced with 9. Intermediate results (as array of numbers) implicitly printed .
Try it online!
Explanation:
In a loop the function imdilate (morphological image dilation) from the image package is used to simulate fire propagation.

This works with boards of all sizes, and even with a bunch of holes. E.G.: [0 Inf   0   0   0;0 Inf   0 Inf   0;0 Inf   0 Inf   0;0   0   0 Inf   1] - Very Nice

C (gcc), 308 305 299 297 295 291 bytes
#define F B[i][v]
m(A,B,k,y,m,U,i,v)char**B;{do{for(i=k=y=0;i<A;puts(""),++i)for(v=0;v<(m=strlen(B[i]));F=(U=F)>48&&F<56?F+1:F>55?65:(i+1<A&&B[i+1][v]==51||v+1<m&&B[i][v+1]==51||v-1>-1&&B[i][v-1]==52||i-1>-1&&B[i-1][v]==52)&&U<49?49:F,putchar(U),k+=U<49||U>64,++y,++v);puts("");}while(k-y);}

This program defines a function which takes two inputs, a pointer to an array of strings preceded by its length, as allowed by this I/O default. Outputs to STDOUT with a trailing newline.
Try it online!

Runs forever on input 80.

@aschepler Sorry! I assumed that all the characters must turn into As, but apparently I assumed wrong. Anyways, thanks for the information. It's fixed now.

-6 bytes! Tio Link

@GiacomoGarabello I can't believe I forgot about that tactic. Thanks for reminding me! :)

Haskell, 162 bytes
import Data.List
i x|x<'9'=succ x|1<2=x
f('3':'@':r)="30"++f r
f(x:r)=x:f r
f e=e
a%b=a.b.a.b
g=map(i<$>).(transpose%map(reverse%f))
h x|y<-g x,y/=x=x:h y|1<3=[x]

Try it online! Usage: h takes a field as a list of lines and returns a list of fields. An unburned field is indicated by @ and ash by 9, the different fires are the digits 1 to 8.

f manages the spreading of the fire from left to right by replacing all unburned @ fields which are right to a burning 3 field with 0.
i increments each digit as long as it is less than 9.
g applies f to each line, then reverses the line, applies f again and reverses back. Then the list of of lines is transposed and again on each line and its reverse f is applied.
h applies g to the input until it no longer changes and collects the results.

Fails on input ""@3@1\n@@@9\n555@@@@@@@@@@@@@@@@@@@", as for some reason the long line of @s switches to the top line after the first iteration.  Fixing that would be great, thanks!

@Gryphon The displacement is caused by transposing the character matrix. It works if the other lines are brought to the same length with some character which represents neither a field, fire or ash, e.g. _. If this is not acceptable then I'm afraid I'd have to delete the answer, because it's centered around the usage of transpose and I don't see a way to easily fix it without introducing tons of bytes.

Octave, 212 bytes
function r(f)b=48;f-=b;c=-16;l=f~=-c;d=17;p=@(x)disp(char(x+b));g=@()disp(' ');p(f);g();while~all(any(f(:)==[0 d c],2))m=f>0&l;f(m)+=1;k=conv2(f==4,[0 1 0;1 0 1;0 1 0],'same')&~m&l;f(k)+=1;f(f>8&l)=d;p(f);g();end

To run, specify a character array such as:
f = ['0301','000A','555 '];

... then do:
r(f)

Explanation of the code to follow...
Try it online!
Note: I tried to run this code with tio.run, but I wasn't getting any output.  I had to use another service.

Really just at the moment I want to post an octave answer you answer before me..

PHP, 226 212 210 209 185 177 bytes
for($f=file(m);$f!=$g;print"
")for($g=$f,$y=0;$r=$f[$y++];)for($x=-1;~$c=$r[++$x];$f[$y-1][$x]=$c=="0"?strstr($g[$y-2][$x].$r[$x-1].$f[$y][$x].$r[$x+1],51)/3:min(++$c,9))echo$c;

takes input with a trailing newline from a file named m; 9 for ashes.
Run with -nr or try it online.

first approach: PHP 7.0, 209 bytes
for($f=$g=file(m);trim(join($f),"A
");print"
".join($f=$g))for($y=-1;(a&$c=$r[++$x])||$r=$f[$y-=$x=-1];)for(+$c&&$g[$y][$x]=++$c<9?$c:A,$a=4;$a--;$q=$p)$c-4|($w=&$g[$y+$p=[1,0,-1][$a]])[$q+=$x]!="0"||$w[$q]=1;

takes input with a trailing newline from a file named m.
Run with -nr or try it online.
PHP version notes (for old approach)

for PHP older than 7.0, replace everything after $c-4| with $g[$y+$p=[1,0,-1][$a]][$q+=$x]!="0"||$g[$y+$p][$q]=1;
for PHP older than 5.5, replace [1,0,-1][$a] with $a%2*~-($a&2)
for PHP newer than 7.0, replace a&$c with ""<$c, +$c with 0<$c and $c-4 with $c!=4

doesnt' work for other test cases...http://sandbox.onlinephpfunctions.com/code/d626b3f9eb9026041ce7d1224c3317199dc36b8d

@g19fanatic fixed & golfed. thanks for noticing.

Python 2, 325 Bytes
def f(x):
 while{i for m in x for i in m}>{9,''}:
    yield x;i=0
    for l in x:
     j=0
     for c in l:
        if 0<c<9:x[i][j]+=1
        j+=1
     i+=1
    i=0
    for l in x:
     j=0
     for c in l:
        if c==0 and{1}&{x[k[1]][k[2]]==4for k in[y for y in[[i,i-1,j],[i<len(x)-1,i+1,j],[j,i,j-1],[j<len(l)-1,i,j+1]]if y[0]]}:x[i][j]+=1
        j+=1
     i+=1
 yield x

f takes the input as a 2D array of integers, and empty spots marked with ''. 'A' has been replaced with 9. The function outputs a generator of all the fields over time in the same format.
Try it online!

Octave, 419 312 bytes
M=input('') %take a matrix M as input
[a, b]=size(M); %size M for later
while mean(mean(M))!=9 %while the whole matrix M isn't ashes
M=M+round(M.^0.001); %if there is a nonzero int add 1 to it
for i=1:a %loop over all values of M
for j=1:b
if(M(i,j)==4) %if a value of 4 is found, ignite the zeros around it
if(M(max(i-1,1),j)==0) M(i-1,j)++;end
if(M(min(i+1,a),j)==0) M(i+1,j)++;end
if(M(i,max(j-1,1))==0) M(i,j-1)++;end
if(M(i,min(j+1,b))==0) M(i,j+1)++;end
elseif(M(i,j)==10) M(i,j)--;
end
end
end
M %display the matrix
end

Try it online!
This is my version it works, so now I still need to golf it. I think it can be a lot shorter if I find a way to find the indices of the 4 in a matrix, but I don't know how.
PS: A is a 9 in my code.

Instead of endif endfor and endwhile you can write end

Stencil (∊-mode), 22 bytes
S≡8:'A'⋄0::S⋄(3∊N)⌈S+s

Try it online!
Just like in the test input, use integers separated by spaces for 0-8, ' ' for blank and 'A' for A. Remember to add trailing blanks too.