text:
Am I a golfy array?
Definition and Rules
A golfy array is an array of integers, where each element is higher than or equal to the arithmetic mean of all the previous elements. Your task is to determine whether an array of positive integers given as input is golfy or not.

You do not need to handle the empty list.

Default loopholes apply.

Standard Input and Output methods apply.

You can choose any two distinct non-empty values. They must be consistent, and must comply with all other decision-problem rules. This is code-golf, shortest code in each language wins!

Test Cases & Example
For example the following array:
[1, 4, 3, 8, 6]

Is a golfy array, because each term is higher than the arithmetic mean of those preceding it. Let's work it out step-by-step:

Number -> Preceding elements -> Average -> Follows the rule?

1      -> []                 -> 0.0     -> 1 ≥ 0.0   (True)
4      -> [1]                -> 1.0     -> 4 ≥ 1.0   (True)
3      -> [1, 4]             -> 2.5     -> 3 ≥ 2.5   (True)
8      -> [1, 4, 3]          -> 2.(6)   -> 8 ≥ 2.(6) (True)
6      -> [1, 4, 3, 8]       -> 4.0     -> 6 ≥ 4.0   (True)

All the elements respect the condition, thus this is a golfy array. Note that for the purpose of this challenge, we will assume that the average of an empty list ([]) is 0.
More test cases:

Input -> Output

[3]                 -> True
[2, 12]             -> True
[1, 4, 3, 8, 6]     -> True
[1, 2, 3, 4, 5]     -> True
[6, 6, 6, 6, 6]     -> True
[3, 2]              -> False
[4, 5, 6, 4]        -> False
[4, 2, 1, 5, 7]     -> False
[45, 45, 46, 43]    -> False
[32, 9, 15, 19, 10] -> False

Note that this is Puzzle 1 from CodeGolf-Hackathon and is also posted on Anarchy Golf (that one is broken) - Reposted by histocrat, but I am the original author on both sites, and thus allowed to repost them here.

Is the input always a list of positive integers?

@KellyLowder Yes.

It's a fun problem, I was thinking of reposting it on Anarchy Golf with more test cases but thought you might be working on that.

@histocrat Go ahead and repost it on Anarchy Golf, I should have thought about the things that could be exploited first. I am rather glad you find it interesting (Btw please ping me here and give a link if you repost it).

@Mr.Xcoder http://golf.shinh.org/p.rb?Golfy+Arrays+with+test+cases

Hmm, having 0 as the average of an empty sub-list (to handle the first element) sounds strange. I guess using "all elements after the first" in the first sentence would be a better wording.

Is there a test case that works if you compare current term against average of previous terms, but doesn't if you compare current term against average of terms up to (and including) that term? My solution does the latter, (but|and) passes all test cases...

@histocrat Ok, thanks for letting me know you reposted it! (Heh, now I can compete too :P)

@streetster Those are equivalent. Sum/i > x is the same as Sum > xi is the same as Sum+x > x(i+1) is the same as (Sum+x)/(i+1) > x.

Python 2, 37 bytes
def g(a):sum(a)>len(a)*a.pop()or g(a)

Try it online!
Outputs via exit code: crashes (exit code 1) for golfy arrays, just exits with exit code 0 for non-golfy arrays. ovs and Jonathan Frech saved 3 bytes.
Python 2, 44 bytes
f=lambda a:a and sum(a)<=len(a)*a.pop()*f(a)

Try it online!
A more traditional variant, which returns True for golfy arrays, else False. Jonathan Frech saved 2 bytes.

I think a==[]or can be a and.

That’s actually clever — it comes out to sum(a)<=len(a)*a.pop()*[] for the base case, which is always true as int < list!

39 bytes as a function which crashes for truthy inputs.

@ovs 37 bytes using an imperative function.

Jelly, 6 5 bytes
<ÆmƤE

Try it online!
How it works
<ÆmƤE  Main link. Argument: A (integer array)

 ÆmƤ   Compute the arithmetic means (Æm) of all prefixes (Ƥ) of A.
<      Perform element-wise comparison. Note that the leftmost comparison always
       yields 0, as n is equal to the arithmetic mean of [n].
    E  Test if all elements of the resulting array are equal, which is true if and
       only if all comparisons yielded 0.

cairdcoinheringaahing's 6-byter (alternative): ÆmƤµ⁼Ṣ

@Mr.Xcoder Golfed!

Wow that's brilliant :-)

JavaScript (ES6), 33 32 bytes
a=>a.some(e=>e*++i<(s+=e),s=i=0)

Code also works on negative values such as[-3, -2]. Returns false for a golfy array, true for other arrays. Edit: Saved 1 byte thanks to @JustinMariner.

You can drop the ! since the spec only asks for two different values, so returning false when it's a golfy array is fine.

Wolfram Language (Mathematica), 35 bytes
Max[Accumulate@#-Range@Tr[1^#]#]>0&

Try it online!
Outputs False for golfy arrays and True otherwise.

I see the false/true relationship is reversed but that's OK

MATL, 9 8 bytes
tYstf/<a

Outputs 0 for golfy arrays, 1 otherwise.
Try it online!
Explanation
Consider input [1, 4, 3, 8, 6].
t    % Implicit input. Duplicate
     % STACK: [1, 4, 3, 8, 6], [1, 4, 3, 8, 6]
Ys   % Cumulative sum
     % STACK: [1, 4, 3, 8, 6], [1, 5, 8, 16, 22]
t    % Duplicate
     % STACK: [1, 4, 3, 8, 6], [1, 5, 8, 16, 22], [1, 5, 8, 16, 22]
f    % Find: indices of nonzeros. Gives [1, 2, ..., n], where n is input size
     % STACK: [1, 4, 3, 8, 6], [1, 5, 8, 16, 22], [1, 2, 3, 4, 5]
/    % Divide, element-wise
     % STACK: [1, 4, 3, 8, 6], [1, 2.5, 2.6667, 4, 4.4]
<    % Less than?, element-wise
     % STACK: [0, 0, 0, 0, 0]
a    % Any: true if and only there is some nonzero. Implicit display
     % STACK: 0

Haskell, 53 50 48 bytes
and.(z(<=).scanl1(+)<*>z(*)[1..].tail)
z=zipWith

Try it online!
Edit: -3 bytes thanks to Zgarb!
Explanation
The above point-free version is equivalent to the following program:
f s = and $ zipWith(<=) (scanl1(+)s) (zipWith(*)[1..](tail s))

Given an input s=[1,4,3,8,6], scanl1(+)s computes the prefix sums [1,5,8,16,22] and zipWith(*)[1..](tail s) drops the first element and multiplies all other elements with their index: [4,6,24,24]. The list is now golfy if pairwise the prefix sums are smaller or equal to the elements times index, which can be checked by zipping both lists with (<=) and checking that all results are True with and.

You can avoid the type error like this.

@Zgarb In hindsight this is the obvious solution. Thanks for pointing out!

C# (Visual C# Compiler), 71 + 18 = 89 bytes
x=>x.Select((n,i)=>new{n,i}).Skip(1).All(y=>x.Take(y.i).Average()<=y.n)

additional 18 bytes for using System.Linq;
Try it online!

Welcome to the site! :)

Generally speaking, import statements are not considered free in code golf. Because this requires the statement using System.Linq; it would actually be 89 bytes, sometimes expressed as "71 + 18 = 89" to show that 18 bytes are required but not part of the solution while still having the final count be the last number in the title line (which is helpful for some automatic parsers).

C (gcc), 62 60 62 bytes

Removed two superfluous parentheses.
Added two bytes to fix function's reusability (b=).

f(A,S,k,b)int*A;{for(S=k=b=0;*A;S+=*A++)b+=!(S<=*A*k++);b=!b;}

Try it online!

05AB1E, 5 bytes
ηÅA÷W

Try it online!
Extensive help from Dennis and Adnan got to this reduced version. Also a bug was fixed to make this possible, thanks again you guys. I take little credit for this answer.

05AB1E, 10 bytes
ηεÅA}ü.S_P

Try it online!

Long because DgsO/ is the equivalent of "mean" in 05AB1E.
Apparently ÅA is arithmetic mean.

To compute the means, I'd use +\÷J (divide cumulative sum by indices) in Jelly. Is it not that easy in 05AB1E? Edit: Nevermind.

@Dennis ah, cumulative sum in 05AB1E is ü+ then there's really no divie by indices other than g to get array length, L to push 1,2,...,n and divide to get the mean, which is still essentially 5 bytes.

.S_ is a LONG way to go for <=, if anyone has any ideas lmk.

Would ÷W work instead of ü.S_P?

The ε..}-wrapper is not necessary as ÅA vectorizes automatically

@Adnan I don't think it does it correctly though.

@Dennis I'm not sure how that compares consecutive means, that divides by the original input and takes the minimum. Unless you're pointing out a mathematical property that I don't know

a ÷ b = 0 if and only if a < b. The first quotient is always 1, so the minimum will by 1 if all a >= b** and 0 if some a < b.

Oh, @Adnan just fixed the vectorization of ÅA, so ηÅA÷W works now.

APL (Dyalog), 10 bytes
This is an anonymous tacit prefix function (called a monadic train in APL terms).
∧/⊢≥+\÷⍳∘≢

Try all the test cases on TIO!
Is it
 ∧/ all-true that
 ⊢ the elements
 ≥ are greater than or equal to
 +\ the cumulative sums
 ÷ divided by
  ⍳ the integers 1 through
  ∘ the
  ≢ number of elements
?

APL has a symbol for "the"??

@user2390246 ∘ binds together things the same way "the" binds together in "count the cats". It is really called Compose.

APL (Dyalog), 15 bytes
∧/⊢≥((+/÷≢)¨,\)

Try it online!
How?
            ,\  all prefixes
           ¨    for each
      +/÷≢      calculate arithmetic mean
  ⊢≥            element wise comparison
∧/              logically and the result

PowerShell, 60 bytes
param($a)$o=1;$a|%{$o*=$_-ge($a[0..$i++]-join'+'|iex)/$i};$o

Try it online!
Takes input as a literal array (e.g., @(1, 4, 3, 8, 6)) into $a. Sets our $output variable to be 1. Then loops through $a. Each iteration, we're (ab)using PowerShell's implicit casting to *= the result of a Boolean comparison against our $output. The Boolean is whether the current value $_ is -greater-than-or-equal to the previous terms $a[0..$i++] added together (-join'+'|iex) divided by how many terms we've already seen $i. So, if any step along the way is false, then $o will get multiplied by 0. Otherwise, it will remain 1 throughout.
We then simply place $o onto the pipeline and output is implicit. 1 for truthy and 0 for falsey.

Perl 5, 27 +2 (-ap) bytes
$_=!grep$_*++$n<($s+=$_),@F

Try It Online

Matlab and Octave, 41 36 bytes
5 bytes saved thx to Luis Mendo
all([a inf]>=[0 cumsum(a)./find(a)])

Try it online!

@LuisMendo That would break it if any element of a is zero. But that's a handy trick nonetheless in similar situations, have to keep that one in mind.

Reading is difficult! Thx!

Happens to me all the time :-)

C# (.NET Core), 74 bytes
x=>{for(int i=1,s=0;i<x.Count;)if(x[i]<(s+=x[i-1])/i++)return 0;return 1;}

Try it online!
Returns 0 for false and 1 for true.
3 Bytes longer than core of chryslovelaces answer. But in total several Bytes  shorter because my variant doesn't need any using statements.

Cubix, 35 bytes
/I?/\+psu0^.\)*sqs;-\;;U;O1.....?@^

Try it online!
Not the most efficient use of space (6 no-ops in the code) Produces no output for a golfy array, 1 for a not-golfy array.
Expands to the following cube:
      / I ?
      / \ +
      p s u
0 ^ . \ ) * s q s ; - \
; ; U ; O 1 . . . . . ?
@ ^ . . . . . . . . . .
      . . .
      . . .
      . . .

Explanation forthcoming, but it basically ports something like Luis Mendo's MATL answer or Dennis' Julia answer.
Watch it run!

SQL (MySQL), 68 bytes
select min(n>=(select ifnull(avg(n),1)from t s where s.i<t.i))from t

Try it online!
Returns 1 for golfy arrays, and 0 otherwise. Takes input from a named table, t. In order to create t, run:
CREATE TABLE t(i SERIAL,n INT)

and to load the values:
truncate table t;insert into t(n)values(3),(2);

Husk, 5 bytes
Λ<mAḣ

Try it online!
Modification of Mr. Xcoder's solution from the linked repository.
-1, a sweet victory using all2!
Husk, 8 7 bytes
ΛΓ·<Aṫ↔

Try it online!
Took me long enough to use Γ here.(more than a year!)

Factor, 26 bytes
[ dup cum-mean v>= vall? ]

Try it online!
Explanation
Factor has some pretty great words for this.
         ! { 1 4 3 8 6 }
dup      ! { 1 4 3 8 6 } { 1 4 3 8 6 }
cum-mean ! { 1 4 3 8 6 } { 1 2+1/2 2+2/3 4 4+2/5 }
v>=      ! { t t t t t }
vall?    ! t

Python 2, 52 bytes
lambda A:all(k*j>=sum(A[:j])for j,k in enumerate(A))

Try it online!
Python 2, 50 48 44 42 bytes

Saved two bytes by inlining and using and.
Saved two bytes thanks to Mr. Xcoder by chaining assignment S=k=0.
Saved two bytes by using or and the comparison's boolean value as k's increment value.
Saved two bytes thanks to ovs; raising a NameError by using an undefined variable instead of a ZeroDivisionError.

S=k=0
for j in input():k+=S<=j*k or J;S+=j

Try it online!

46 bytes for your alternative version.

@Mr.Xcoder Thanks.

42 bytes

@ovs Thanks; neat one-byte way to raise an exception.

Ruby, 30 bytes
->a{0until a.pop*a.size<a.sum}

Try it online!
Inspired by Lynn's answer. Throws NoMethodError for golfy, returns nil otherwise.

q/kdb+, 14 bytes
Solution:
min x>=avgs x:

Examples:
q)min x>=avgs x:1 4 3 8 6
1b                           / truthy
q)min x>=avgs x:4 2 1 5 7
0b                           / falsey

Explanation:
Fairly simple with the avgs built-in:
min x>=avgs x: / solution
            x: / store input in variable x
       avgs    / calculate running averages
    x>=        / array comparison, x greater than running average
min            / take minimum of list of booleans

Julia 0.6, 29 bytes
!x=any(find(x).*x.<cumsum(x))

Returns false or true.
Try it online!

Add++, 54 bytes
D,g,@@#,BFB
D,k,@,¦+AbL/
D,f,@,dbLR$€g€k0b]$+ABcB]£>ª!

Try it online!
Unoriginal version, 30 bytes
D,f,@,¬+AbLRBcB/@0@B]ABcB]£>ª!

Try it online!
Both output 1 for golfy arrays and 0 otherwise
How they work
The first version was created by me, without checking any other solutions. The second was inspired by Dennis' comment, so I'm less happy with it.
The first version
Here, we define our main function \$f\$ that computes the golfiness of our input array, \$A\$. First, we need to yield the suffixes of \$A\$, which is done by first generating the range \$B := [1, ... \vert{A}\vert]\$, where \$\vert{A}\vert\$ denotes the length of \$A\$. This is done with the code dbLR$, which leaves \$[B, A]\$ as the stack. We then iterate the dyadic function \$g\$ over these two lists. Being dyadic, the function binds its left argument as \$A\$ for each iterated element. It then iterates over the range \$B\$, which each element from \$B\$ being the right argument provided to \$g\$. \$g\$ is defined as
D,g,@@#,BFB

which is a dyadic function (i.e. takes \$2\$ arguments), and pushes its arguments to the stack in reversed order (#) before execution. BF then flattens the two arguments. We'll assume that the arguments are \$A\$ and \$e \in x\$. This leaves the stack as \$[...A, e]\$, where \$...\$ represents an array splat. Finally, B takes the first \$e\$ elements of \$A\$ and returns a list containing those elements.
Note : The function names \$g\$ and \$k\$ aren't chosen randomly. If the commands given to an operator (such as €) doesn't currently have a function (which g and k don't), then the named functions are searched for a matching function. This saves \$2\$ bytes, as normally the function would have to wrapped in {...} to be recognised as a user-defined function. At the time of writing, the currently unused single byte commands are I, K, U, Y, Z, g, k, l, u and w.
When \$g\$ is applied over the elements of a range \$x\$, this returns a list of prefixes for \$A\$. We then map our second helper function \$k\$ over each of these prefixes. \$k\$ is defined as
D,k,@,¦+AbL/

which is the standard implementation of the arithmetic mean. ¦+ calculates the sum of the argument, AbL calculates its length, then / divides the sum by the length. This calculates the arithmetic mean of each prefix, yielding a new array, \$C\$.
Unfortunately, \$C\$ contains the mean of \$A\$ as its final element, and does not include the mean of the empty list, \$0\$. Therefore, we would have to remove the final element, and prepend a \$0\$, but popping can be skipped, saving two bytes, for reasons explained in a second. Instead, we push \$[0]\$ underneath \$C\$ with 0b]$, then concatenate the two arrays forming a new array, \$C^+\$.
Now, we need to check each element as being less than its corresponding element in \$A\$. We push \$A\$ once again and zip the two arrays together with ABcB]. This is the reason we don't need to pop the final element: Bc is implemented with Python's zip function, which truncates the longer arrays to fit the length of the shortest array. Here, this removes the final element of \$C^+\$ when creating the pairs.
Finally, we starmap \$p \in A, q \in C^+; p < q \equiv \neg(p \ge q)\$ over each pair \$p, q\$ to obtain an array of all \$0\$s if the array is golfy, and array containing at least a single \$1\$ if otherwise. We then check that all elements are falsey i.e. are equal to \$0\$ with ª! and return that value.
The second version
This takes advantage of Dennis' approach to remove \$24\$ bytes, by eliminating the helper functions. Given our input array of \$A\$, we first compute the cumulative sums with ¬+, i.e the array created from \$[A_0, A_0+A_1, A_0+A_1+A_2, ..., A_0+...+A_i]\$. We then generate Jelly's equivalent of J (indicies), by calculating the range \$B := [1 ... \vert{A}\vert]\$ where \$\vert{A}\vert\$ once again means the length of the array.
Next, we divide each element in \$A\$ by the corresponding index in \$B\$ with BcB/ and prepend \$0\$ with @0@B]. This results in a new array, \$C^+\$, defined as
$$C^+ := [0, A_0, \frac{A_0+A_1}{2}, \frac{A_0+A_1+A_2}{3}, ..., \frac{A_0+...+A_i}{i+1}]$$
The final part is identical to the first version: we push and zip \$A\$ with \$C^+\$, then starmap inequality over each pair before asserting that all elements in the resulting array were falsy.

R, 38 34 bytes
function(x)any(cumsum(x)/seq(x)>x)

Try it online!

very nice. Dunno why there wasn't an R answer before...

You were all saving an easy one for me.

instead of defining y in the function arguments, using cumsum(x) directly is 4 bytes shorter. It's a shame cummean doesn't exist in base R.

Vyxal, 5 bytes
Kvṁ<≈

Try it Online!
Porting jelly got me feeling like yeet.
Explained
Kvṁ<≈
K     # prefixes of the input
 vṁ   # the mean of each of those prefixes
   <  # is the input less than each of those means?
    ≈ # and is everything the same?

Desmos, 55 bytes

f(l)=\sum_{n=2}^{l.\length}\{l[1...n-1].\mean>l[n],0\}

Outputs 0 for golfy array, and a positive integer otherwise.
Try It On Desmos!
Try It On Desmos! - Prettified

Scala, 109 bytes
Golfed version, try it online!
def f(a:List[Int]):Boolean={a match{case Nil=>true;case _=>a.sum<=(a.length*a.last*(if(f(a.init))1 else 0))}}

Ungolfed version
object Main {
  def f(a: List[Int]): Boolean = {
    a match {
      case Nil => true
      case _ => a.sum <= (a.length * a.last * (if(f(a.init)) 1 else 0))
    }
  }

  def main(args: Array[String]): Unit = {
    assert(f(List(3)) == true)
    assert(f(List(2, 12)) == true)
    assert(f(List(1, 4, 3, 8, 6)) == true)
    assert(f(List(1, 2, 3, 4, 5)) == true)
    assert(f(List(6, 6, 6, 6, 6)) == true)
    assert(f(List(3, 2)) == false)
    assert(f(List(4, 5, 6, 4)) == false)
    assert(f(List(4, 2, 1, 5, 7)) == false)
    assert(f(List(45, 45, 46, 43)) == false)
    assert(f(List(32, 9, 15, 19, 10)) == false)

    println("No assertion errors.")
  }
}

Pyth, 11 10 bytes
-1 byte thanks to Mr. Xcoder
.A.egb.O<Q

Try it online!

7 bytes: SI.OM._ (port of cairdcoinheringaahing's solution from Jelly, by Erik the Outgolfer), or 10 bytes using your approach: .A.egb.O<Q

Post the port as yourself, it's a totally different approach!

Java (OpenJDK 8), 96 bytes
I know it's not a good golfing language, but I still gave it a go!
Input array as first argument of comma separated ints to test.
Returns 1 for true, 0 for false.
a->{int i=1,j,r=1,s=0;for(;i<a.length;i++,s=0){for(j=0;j<i;s+=a[j++]);r=s/i>a[i]?0:r;}return r;}

Try it online!

Java 7, 100 bytes
Golfed:
int g(int[]a){int i=1,m=0,s=m,r=1;for(;i<a.length;){s+=a[i-1];m=s/i;r-=a[i++]<m&&r>0?1:0;}return r;}

Ungolfed:
int golfy(int[]a)
{
    int i = 1, m = 0, s = m, r = 1;
    for (; i < a.length;)
    {
        s += a[i-1];
        m = s / i;
        r -= a[i++] < m && r>0? 1 : 0;
    }
    return r;
}

Try it online
Returns 0 for ungolfy and 1 for golfy arrays. Slightly longer than java 8 answer.

PHP, 44 bytes
while($n=$argv[++$i])$n<($s+=$n)/$i&&die(1);

takes input from command line arguments, exits with 0 (ok) for a golfy array, with 1 else.
Run with -nr or try it online.

J, 19 bytes
[:*/[>:[:}:0,+/\%#\

+/\ % #\ averages of the prefixes: #\ produces 1..n
}:0, add 0 to the beginning and remove the last
[>: is the original list element by element >= to the shifted list of averages?
*/ are all the elements greater, ie, the previous list is all 1s?
Try it online!

AWK, 39 bytes
{for(;i++*$i>=s&&i<=NF;s+=$i);$0=i>NF}1

Try it online!
Note that the TIO link has 5 extra bytes i=s=0 to allow for multi-line input.

Japt, 10 bytes
Came up with two 10 byte solutions, can't seem to improve on that.
eÈ¨U¯Y x÷Y

Try it

Explanation
               :Implicit input of array U
eÈ             :Is every element, at 0-based index Y
  ¨            :Greater than or equal to
   U¯Y         :U sliced from index 0 to index Y
        ÷Y     :Divide each element by Y
       x       :Reduce by addition

Alternative
eÈ*°Y¨(T±X

Try it
               :Implicit input of array U
eÈ             :Is every element X (at 0-based index Y)
  *°Y          :Multiplied by Y incremented by 1
     ¨         :Greater than or equal to
      (T±X     :T (initially 0) incremented by X

Kotlin, 51 bytes
foldIndexed(0,{i,s,e->if(s<0||s>e*i)-1 else s+e})>0

Try it online!

(69 bytes with entire declaration of extension function)

fun List<Int>.g()=foldIndexed(0,{i,s,e->if(s<0||s>e*i)-1 else s+e})>0

This should be enclosed in a lambda

Arturo, 33 bytes
$=>[0v:0some?&'x['v+x x<v//<=1+]]

Try it
Returns false for true and true for false.
$=>[             ; a function, assign input to &
    0            ; push 0 to the stack, this represents the current count of elements
    v:0          ; assign 0 to v, this represents the running average
    some?&'x[    ; is there any x in the input that...
        'v+x     ; add x to v in place
        1+       ; add 1 to value on top of the stack
        <=       ; duplicate top of stack
        x<v//    ; is x less than v divided by top of stack?
    ]            ; end some?
]                ; end function

Thunno 2, 5 bytes
ƒ€m<ạ

Try it online!
Port of Dennis's Jelly answer.
Explanation
ƒ€m<ạ  # Implicit input
ƒ      # Prefixes of the input
 €m    # Mean of each prefix
   <   # Input is less than this?
    ạ  # All equal (all are 0?)
       # Implicit output


text:
Create a universal integer sequence
Definition
Let's call an (infinite) integer sequence universal if it contains every finite integer sequence as a contiguous subsequence.
In other words, the integer sequence (a1, a2, …) is universal if and only if, for each finite integer sequence (b1, …, bn), there is an offset k such that (ak+1, …, ak+n) = (b1, …, bn).
The sequence of positive prime numbers, for example, is not universal, among others for the following reasons.

It doesn't contain any negative integers, 1, or composite numbers.
Although it contains 3, it does not contain the contiguous subsequence (3, 3, 3).
Although it contains 2 and 5, it does not contain the contiguous subsequence (2, 5).
Although it contains the contiguous subsequence (7, 11, 13), it does not contain the contiguous subsequence (13, 11, 7).

Task
Pick any single universal integer sequence (a1, a2, …) and implement it in a programming language of your choice, abiding to the following rules.

You can submit a full program or a function.
You have three options for I/O:

Take no input and print or return the entire sequence.
Take an index n as input and print or return an.
Take an index n as input and print or return (a1, …, an).

For I/O options 2 and 3, you may use 0-based indexing if you prefer.
Your submission must be deterministic: if run multiple times with the same input, it must produce the same output.

In addition, unless it's immediately obvious, please prove that the sequence you picked is universal. Your proof may not depend on unproven conjectures.
Standard code-golf rules apply. May the shortest code in bytes win!

Your proof may not depend on unproven conjectures. I thought that's implied :p

and how you would save a list of numbers in a number?

Husk, 5 bytes
This prints an infinite list
ΣṖ…İ±

Try it online! or find the first index of your sequence. (Takes a lot of memory for most sequences)
Explanation:
   İ±   Infinite list [1,-1,2,-2,3,-3,4,-4,5,-5...]
  …     Rangify       [1,0,-1,0,1,2,1,0,-1,-2,...]
 Ṗ      Powerset
Σ       Concatenate

In Husk Ṗ behaves nicely for infinite lists. You can see it's behaviour here

You might want to elaborate on how Q works. (I think I got it, but I'm not sure.)

@Dennis turns out I wanted Ṗ, not Q

Python 2, 49 46 43 bytes
def f(n):d=len(`n`);return n/d**(n%d)%d-d/2

f(n) returns an only. This uses the smallest digit of n in base d to extract one of the higher digits.
Try it online! This script (courtesy of Dennis) takes any finite sequence and gives you an n where that sequence begins.
Explanation
n/d**(n%d)%d-d/2
     (n%d)         least significant digit of n
n/d**(   )%d       get n%d-th digit of n
            -d/2   offset to get negative values

For example, for n in the range 3141592650 to 3141592659, d=10 and the last digit of n selects one of the other digits. Then we add -d/2 to get negative values.
n%d:       0  1  2  3  4  5  6  7  8  9
f(n)+d/2:  0  5  6  2  9  5  1  4  1  3
f(n):     -5  0  1 -3  4  0 -4 -1 -4 -2

Standalone alternative, also 43 bytes:
n=input();d=len(`n`);print n/d**(n%d)%d-d/2

You can use len(`n`) instead of len(str(n)).

Thanks @Dennis. I can add more explanation if anyone needs it.

I wrote a function that, given a finite sequence, finds an offset in your sequence. Try it online!

This is very cool.

Nice. Only thing is it'll break upwards of n=2**63-1 since the representation gets an L appended (str(n) would address that for three bytes if it's necessary).

The extra L would just increase d by 1, @JonathanAllan. The code works for any d as long as it grows much more slowly than n.

@Dennis, I've incorporated your inverter into the answer. Note there's a bug for long lists like [0]*49, which I have fixed.

The increase of d by 1 is exactly what breaks it. (I don't know but think it should work in theory and given unbounded resources.)

Can you explain what is broken @JonathanAllan? The current TIO snippet shows f working for n well above 10**1000.

Ah I think I see what you mean -- the method will still work with the 'hiccup'?

Brachylog 2, 11 bytes
≜~×-₂ᵐ~ȧᵐ≜∋

Try it online!
I also tried an algorithm using additive partitions on a list, but it wasn't any shorter. This is a generator that produces an infinite stream of integers as output; the TIO link has a header to print the first ten thousand of them.
Explanation
The program starts off by trying all possible integers in sequence (≜ tries all remaining possibilities, for integers by default). That's 0, 1, -1, 2, -2, etc. (although the negative integers don't reach the end of the program). This is the only "infinite" step of the program; all the others are finite.
~× then generates all possible factorisations of the integer, treating different orders as different, and using only values from 2 upwards (so there are only finitely many); note that composite numbers are allowed in the factorisation, not just primes. This means that all possible sequences of integers ≥ 2 will be generated by this step at some point in the execution of the function (as such a sequence necessarily has some product, and that product will be generated at some point by the initial ≜).
We then need to map the set of those sequences onto the set of all integer sequences, which is done in two steps: subtracting 2 (-₂) from each element (ᵐ), giving us the set of all nonnegative integer sequences, then taking plus or minus (~ȧ, i.e. "a value whose absolute value is") each element (ᵐ). The latter step is obviously nondeterministic, so Brachylog treats it as a generator, generating all possible lists whose elements are plus or minus the corresponding element of the input list. This means that we now have a generator for all possible integer sequences, and it generates them in an order that means they're all generated (specifically, the order that you get if you take the absolute value of each element, add 2 to each element, and then order by the product of the resulting elements).
Unfortunately, the question wants a single sequence, not a sequence of sequences, so we need two more commands. First, ≜ requests Brachylog to explicitly generate the sequence of sequences strictly (as opposed to producing a data structure describing the concept of a sequence generated via this method, and not actually generating the sequences until necessary); this both happens to make the program faster in this case, and ensures that the output is produced in the requested order. Finally, ∋ causes the generator to output the elements of the individual sequences one at a time (moving onto the next sequence once it's output all elements of the previous one).
The end result: each possible integer sequence gets generated and output, one element at a time, and all concatenated together into a single universal sequence.

ais523… is that you!?

If it's not them, it's a hell of a coincidence, considering posts from their deleted account show the same account number.

Pyth - 11 bytes
nth power cartesian product of [-n, n], for all n.
.V1js^}_bbb

Try it online here (finitely).

Python 2, 100 99 bytes

Saved one byte thanks to ovs; iterating over an itertools built-in to indefinitely loop.

from itertools import*
for n in count():
 for P in permutations(range(-n,n)*n):
	for p in P:print p

Try it online!
Indefinitely prints all permutations of the n-times repeated integer range [-n; n) for all nonnegative integers n.
You can search for the first offset k for any subsequence using this modified version.

while~0:. Heh heh...

99 bytes using itertools.count

@ovs Thanks; did not know of that built-in.

Perl 6, 91 bytes
loop (my$i=1;;$i++){my@n=(-$i..$i);my@m=@n;loop (my$k=1;$k <$i;$k++){@m=@m X@n;};print @m;}

Try it online!
This uses a similar method to some of the other answers. It uses Cartesian products to print the elements of (-1,0,1), then all ordered pairs of the elements in (-2,-1,0,1,2), then all ordered triplets of the elements in (-3,-2,-1,0,1,2,3), etc.
I'm new to Perl, so there might be more golfing that could be done.
More readable version:
loop (my $i = 1; ; $i++) {
  my @n = (-$i..$i);
  my @m = @n;
  loop (my $k=1; $k <$i; $k++) {
    @m = @m X @n;
  }
  print @m;
}

source: Stack Exchange

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

sort: votes


text:
The prime frog
The "prime frog" is a strange animal that jumps between integers, until it arrives on 3 or 19...

Your program should accept an integer n as input and output the result of the below algorithm (3 or 19).
For a given integer n >= 2:

Let f be the position of the frog. It is initially set to n
if f = 3 or f = 19 : the frog stops jumping - halt the program and output f.
if f is prime : the frog jumps to the position 2×f-1. Go back to step 2.
if f is composite : let d be f's biggest prime divisor. The frog jumps to the position f-d. Go back to step 2.

Examples:
An example with n = 5:
5 > 9 > 6 > 3 stop

The program should output 3.
Another example with n = 23:
23 > 45 > 40 > 35 > 28 > 21 > 14 > 7 > 13 > 25 > 20 > 15 > 10 > 5 > 9 > 6 > 3 stop

Again, the program should output 3.
Test cases:
10 => 3
74 => 19
94 => 3
417 => 3
991 => 19
9983 => 19

You can assume 1 < n < 1000000 (I have checked the program ends for these values).

A comment on why I've chosen 3 and 19 as stop criteria : once the frog arrives on one of these numbers, it starts to loop back after a few iterations. 3 and 19 form two distinct loops. It seems all integers eventually arrive to the 3 loop or the 19 loop.

3 loop is [3 5 9 6 3] and 19 loop is [19 37 73 145 116 87 58 29 57 38 19]

Cool Collatz variation.

I wonder whether there is a mathematical proof or something alike on the topic

@SuperChafouin I wonder if there's higher primes that fall into a loop.

@kamoroso94 I haven't checked for bigger values. For n < 1000000, 62% of numbers return 3 and 38% return 19.

If we cannot prove that the frog always comes to 3 or 19, we could change item 2. in the algorithm to say that if the frog has entered any loop (encountered a position it has seen before), then it ceases the jumping and returns the smallest member of that loop.

@Jeppe That was my original algorithm, it would stop whenever it entered a loop. As I noticed it was always the 3-loop or the 19-loop, I thought it would be funnier for golfing to add 3 and 19 as stop conditions.

@SuperChafouin what should the program do if reaches neither 3 nor 19? Or can we assume the input will?

@PyRulez If it reaches that, you should probably tell the OP.

@KeyuGan Maybe this would be a good thing to post about on Math.SE.

Hold true for first 10^8 primes

@Abigail Absolutely! If there is a number that never loops, then the frog will tend towards positive infinity; however, I do not see how the frog could ever realize that this was the case, so I do not see how that would change the frog "rules". But it would still be very interesting if someone could prove that all frog sequences are bounded (the prime frog halting problem).

please add link to math.se if someone posts it there.

Python 2, 101 93 92 90 88 87 85 bytes
import sympy
n=input()
while~16&n-3:m=max(sympy.factorint(n));n-=[1-n,m][m<n]
print n

Try it online!

while~16&n!=3 saves a byte.

Oh, ~16&n-3 even works!

C (gcc),  87  65 bytes
i,k;f(n){for(i=n;i>1;)for(k=i;k%--i;);n=~16&n-3?f(n-k?:n+n-1):n;}

Try it online!
Explanation:
i,k;
f(n)
{
    for (i=n; i>1;)              // Loop until `k` is prime (the largest positive
                                 // `i` inequal to `k` that divides `k` is 1).
        for (k=i; k%--i;);       // Find the largest factor `k`

    n =                          // Returning like this is undefined behaviour,
                                 // but happens to work with gcc. This can be
                                 // replaced with `return` at the cost of 4 bytes.

        ~16&n-3                  // If `n` is 3 or 19, this expression equals 0 and
                                 // the algorithm halts. Otherwise the function
                                 // calls itself to perform the next iteration.

        ? f(n-k ?: n+n-1)        // If `n-k` is non-zero, n is not prime.
                                 // In this case call `f` with the value of `n-k`.
                                 // (Omitting the second `n-k` between `?` and `:`
                                 // is a gcc extension)
                                 // Otherwise call `f` with `2*n-1`.

        : n;                     // All done, `n` is returned.
}

Portable version (72 bytes):
i,k;f(n){for(i=n;i>1;)for(k=i;k%--i;);return~16&n-3?f(n-k?n-k:n+n-1):n;}

Try it online!
With more appropriate variable names:
f,r;o(g){for(f=g;f>1;)for(r=f;r%--f;);g=~16&g-3?o(g-r?:g+g-1):g;}

Try it online!

Totally love the play with the word frog and your variables. +1.

Retina, 63 62 bytes
Thanks to Neil for saving 1 byte.
{`^(11+)(?<!^\2+(11+))(?=\1+$)

^(?!(11+)\1+$|111$|1{19}$)1
$_

Try it online!
Input and output in unary (the test suite uses decimal for convenience). This solution gets incredibly slow for larger inputs. The 9983 test case times out on TIO.
Explanation
Due to the {, both stages of the program are simply run in a loop until they no longer affect the string. We alternate between a stage processing composites and a stage processing primes. That lets us avoid an actual conditional (which doesn't really exist in Retina). If the current value is the wrong kind for the stage, the stage simply does nothing.
^(11+)(?<!^\2+(11+))(?=\1+$)

This processes composites. We match a potential divisor with (11+), but then we check that it's not composite with (?<!^\2+(11+)), so we only consider prime factors. Due to the greediness of +, this prioritise the largest factor. Then we check that this potential divisor is an actual divisor by trying to match the rest of the string with repetitions of it, (?=\1+$). This divisor is simply removed from the string, which is how you subtract something in unary.
^(?!(11+)\1+$|111$|1{19}$)1
$_

This processes primes, except 3 and 19. The negative lookahead makes sure that the input is not composite, not 3 and not 19. Then we match a single 1 and replace it with the entire string. This is a unary form of computing n - 1 + n, which of course is 2n-1.
Once we hit 3 or 19, neither stage can match the string and it will no longer be changed.

Isn't 1$' the same as $_?

@Neil Yes......

Jelly, 12 bytes
_ÆfṂoḤ’$µÐḶṂ

Try it online!
How it works
_ÆfṂoḤ’$µÐḶṂ  Maink link. Argument: n

        µ     Combine the links to the left into a chain.
         ÐḶ   Repeatedly call the chain monadically until the results are no longer
              unique. Yield the loop, i.e., the first occurrence of the first
              repeated integer, up to and excluding the repetition.
              Let's call the argument of the chain k.
_Æf             Subtract all prime factors of k from k.
   Ṃ            Take the minimum of the differences. This yields 0 iff k is prime.
     Ḥ’$        Compute 2k-1.
    o           Take the logical OR of the results.
              The result is now a rotation of either [3, 5, 9, 6] or
              [19, 37, 73, 145, 116, 87, 58, 29, 57, 38].
          Ṃ   Take the minimum, yielding either 3 or 19.

Wolfram Language (Mathematica), 65 66 68 bytes
#//.i:Except[3|19]:>If[PrimeQ@i,2i-1,i-#&@@Last@FactorInteger@i]&

-1 bytes, thanks to Misha Lavrov!
-2 bytes, thanks to Martin!

Try it online!
Inspired by the tip. Basically, it just recreates the algorithm.
//. is RepeatedReplace and /; is Condition. So, the code will replace i_ (a single quantity) with If[PrimeQ@i,2i-1,i-#&@@Last@FactorInteger@i], until i!=3&&!=19 evaluates True.
Benchmark:

fun fact: this code would not work for larger numbers like 10000000010 because maximum number of iterations is 2^16 (= 65536)

A slightly shorter way to check for 3 and 19 is #//.i:Except[3|19]:>If[PrimeQ@i,2i-1,i-#&@@Last@FactorInteger@i]&

@MishaLavrov but the result is incorrect?

@KeyuGan For me, the two functions give exactly the same result for integers 1 through 1000.

Possibly the issue you're having is unprintable characters inserted when you copy and paste from the comments, which sometimes happens.

Husk, 15 bytes
Ω€p57§|o←DṠ-o→p

Try it online!
Explanation
Ω€p57§|o←DṠ-o→p  Implicit input n.
Ω                Do this to n until
 €p57            you get a prime factor of 57 (which are 3 and 19):
            o→p   Take last element of the prime factors of n
          Ṡ-      and subtract it from n,
     §|           or if this gives 0 (so n is prime),
       o←D        double and decrement n.

05AB1E, 19 18 17 bytes
[ÐƵηfså#pi·<ëDfθ-

Try it online!
Explanation
[      #            # loop until
 Ð   så             # a copy of the current value is contained in
  Ƶηf               # the unique prime factors of 171
        pi          # if the current value is prime
          ·<        # double and decrement
            ë   -   # else subtract
             Dfθ    # the largest prime factor of a copy of the current value

+1 for having an actual frog in your source code <ë

For 57991 more than 1 minute

@RosLuP: You're better off running very long test cases offline ;)

JavaScript (ES6), 73 71 69 bytes
f=n=>57%n?f(n-(g=(k,d=1)=>++d<k?k%d?g(k,d):g(k/d):d<n?d:1-n)(n)):n%38

Test cases

f=n=>57%n?f(n-(g=(k,d=1)=>++d<k?k%d?g(k,d):g(k/d):d<n?d:1-n)(n)):n%38

console.log('10   -> ' + f(10))   // 3
console.log('74   -> ' + f(74))   // 19
console.log('94   -> ' + f(94))   // 3
console.log('417  -> ' + f(417))  // 3
console.log('991  -> ' + f(991))  // 19
console.log('9983 -> ' + f(9983)) // 19

Formatted and commented
f = n =>                 // given n
  57 % n ?               // if n is neither 3, 19 or 57 (and assuming that n is > 1):
    f(                   //   do a recursive call to f() with:
      n -                //     n minus
      (g = (k, d = 1) => //     the result of the recursive function g():
        ++d < k ?        //       increment d; if d is less than k:
          k % d ?        //         if d is not a divisor of k:
            g(k, d)      //           recursive call to g() with k and d unchanged
          :              //         else:
            g(k / d)     //           recursive call to g() with k = k / d, d = 1
        :                //       else, d is now the highest prime divisor of n:
          d < n ?        //         if d is less than n:
            d            //           n is composite: return d, which results in f(n - d)
          :              //         else:
            1 - n        //           n is prime: return 1 - n, which results in f(2n - 1)
      )(n)               //     initial call to g()
    )                    //   end of recursive call to f()
  :                      // else:
    n % 38               //   return n % 38 (gives 19 as expected if n = 57)

Smart, using 57%n and n%38 instead of n==3|n==19. Saved 1 byte in my Java answer as well, so thanks!

In ideone 57991 input generate prog.js:2:26 InternalError: too much recursion

In tio f=n=>57%n?f(n-(g=(k,d=1)=>++d<k?k%d?g(k,d):g(k/d):d<n?d:1-n)(n)):n%38
print(f(57991))
generate stop program not output, it seems to me

@RosLuP This is a code-golf challenge without any specific constraint. The current consensus is that speed or memory limitations (such as the call stack size) can be disregarded unless explicitly stated otherwise in the question. I take it for granted that the 1000000 limit is just informative because the sequence was not tested beyond that. Incidentally, your 70-byte solution is perfectly fine and is probably more relevant than the 93-byte version for a code-golf challenge.

Jelly, 23 19 bytes
-4 bytes from miles. Still longer than 05AB1E, though.
Ḥ’$_Æf$ÆP?Ṫµḟ3,19$¿

Try it online!

Ḥ’$_Æf$ÆP?Ṫµḟ3,19$¿ using a while loop instead and some re-ordering

Python 2, 110 105 103 101 bytes
-2 bytes thanks to @Lynn
f=lambda n,i=2,k=0:i/n and(n*(n&~16==3)or f((2*i-1,k-i)[k>0]))or n%i and f(n,i+1,k)or f(n/i,2,k or n)

Try it online!

Python 2, 116 112 105 bytes
f=lambda n,i=2:i/n*i or n%i and f(n,i+1)or f(n/i)
n=input()
while~16&n-3:n=[2*n-1,n-f(n)][f(n)<n]
print n

Try it online!

…n*(n&~16==3)or… saves 2 bytes.

For input 57991 sys.setrecursionlimit(20000)

MATL, 22 21 bytes
Thanks to @Giuseppe for removing 1 byte!
`tZp?Eq}tYfX>-]tI19h-

Try it online! Or verify all test cases.
Explanation
`           % Do...while
  t         %   Duplicate. Takes (implicit) input the first time
  Zp        %   Is it prime?
  ?         %   If so
    Eq      %     Times 2, minus 1
  }         %   Else
    t       %     Duplicate
    YfX>-   %     Prime divisors, maximum, subtract
  ]         %   End
  t         %   Duplicate
  I19h      %   Push array [3 19]
  -         %   Subtract, element-wise. The result is truthy if and only if
            %   it doesn't contain any zero
            % End (implicit). Next iteraton if top of the stack is truthy
            % Display (implicit)

Haskell - 154 bytes
f 3=3
f 19=19
f n
 |(c==[1])=f$2*n-1
 |True=f$n-head c
 where c=z n;v b=reverse[x|x<-[1..(b-1)],b`rem`x==0];z j=case v j of[1]->[1];s->filter((==[1]).v)$s

Probably missing some golf tricks here, this is my first attempt at haskell golf.

Hello and welcome to the site.  You don't need the newlines and spaces for pattern guards.  You can also use 1>0 for True most times but often it might be better to use an assignment, for example c<-z n.

[x|x<-[b-1,b-2..1],rem b x==0] is also short than reverse[x|x<-[1..(b-1)],bremx==0].

And one last thing, if you would like to discuss haskell golfing you can join us in Of Monads and Men.

Neim, 17 16 bytes
ͻY÷DΞᚫ<#D

Explanation:
ͻ                   Start infinite loop
 D                  Duplicate
  Y                 Push 57
                   Prime factors: [3 19]
                   If the second-to-top of stack is in the list
      ÷             Break the loop
       D            Duplicate
        Ξᚫ<       If prime, double and decrement
            #D   Otherwise, subtract the largest prime factor

Try it online!

Java 8, 140 135 134 94 bytes
n->{for(int f,t,m=0;57%n>0;n=f>n?2*n-1:n-m)for(t=n,f=1;f++<t;)for(;t%f<1;t/=m=f);return n%38;}

-5 bytes converting recursive Java 7 method to Java 8 lambda with loop.
-1 byte implicit thanks to @Arnauld's JavaScript answer by changing n!=3&n!=19 and return n; to 57%n>0 and return n%38;.
I think it should be possible to somehow combine the two loops and check if n is a prime, and get it's largest prime factor at the same time, but I can't figure it out (yet). So this will be the initial version for now.
-40 whopping bytes thanks to @Nevay, by doing what I couldn't do: combining the loops to check for primes and largest prime factor at once.
Explanation:
Try it here (executes even 999999 in under 1 second).
n->{                  // Method with integer as both parameter and return-type
  for(int f,          //  Flag-integer
          t,          //  Temp-integer
          m=1;        //  Max prime factor integer, starting at 0
      57%n>0;         //  Loop (1) as long as `n` is not 3, not 19 and not 57:
      n=f>n?          //    After every iteration: if `f` is larger than `n`:
         2*n-1        //     Change `n` to `2*n-1`
        :             //    Else:
         n-m)         //     Change `n` to `n-m`
    for(t=n,          //   Reset `t` to `n`
        f=1;          //   Reset `f` to 1
        f++<t;)       //   Inner loop (2) from 2 to `t` (inclusive)
      for(;t%f<1;     //    Inner loop (3) as long as `t` is divisible by `f`
        t/=m=f;       //     Set `m` to `f`, and set `t` to `t/f`
      );              //    End of inner loop (3)
                      //   End of inner loop (2) (implicit / single-line body)
                      //  End of loop (1) (implicit / single-line body)
  return n%38;        //  Return `n%38`, which is now either 3 or 19
}                     // End of method

1 character short of being a C# polyglot :(

@IanH. Hehe, yes, that's usually the case: n=> instead of n->. And sometimes lowercase/uppercase calls. ;)

94 bytes: n->{for(int f,t,m=0;57%n>0;n=f>n?2*n-1:n-m)for(t=n,f=1;f++<t;)for(;t%f<1;)t/=m=f;return n%38;}

@Nevay Thanks! I just knew it should be possible to combine the loops, but couldn't figure it out. A whopping 40 bytes saved thanks to you!

R + numbers, 102 99 bytes
function(n){while(!n%in%c(3,19))n="if"(isPrime(n),2*n-1,n-max(primeFactors(n)))
n}
library(numbers)

Try it online!
R isn't known for short built-ins, and even the packages follow suit!

Bash, 73 bytes
((57%$1))&&$0 $[(x=$1-`factor $1|sed 's/.* //'`)?x:2*$1-1]||echo $[$1%38]

Try it online! Modified slightly to work on TIO.
Recursively calls its own script file using $0, which does not work in TIO because it must be ran as ./filename.sh. Accepts input as command-line argument.
Uses the same modulus trick as @Arnauld's JS answer.
Test Cases
$ for t in 5 23 10 74 94 417 991 9983;{ echo -n "$t -> "; ./prime-frog.sh $t; }
5 -> 3
23 -> 3
10 -> 3
74 -> 19
94 -> 3
417 -> 3
991 -> 19
9983 -> 19

Python 3, 97 bytes
f=lambda n:n*(n&-17==3)or f(n-max(k*all(n%k<k%j for j in range(2,k))for k in range(n+1))or 2*n-1)

Try it online!

For 57991 input 1 minute was not sufficient

Pyth, 19 bytes
.W!/P57H?P_ZtyZ-ZeP

Verify all the test cases!
The Husk answer inspired me to save 2 bytes (,3 19 to P57).
How this works

.W!/P57H?P_ZtyZ-ZeP  - Full program.

.W                   - Functional while. While A(value) is truthy, value = B(value). Returns the last value.
    P57              - The prime factors of 57 ([3, 19]).
   /   H             - Count the occurences of the current value.
  !                  - Logical NOT. 0 -> Truthy, anything else -> Falsy.
        ?P_Z         - If the current value is prime, then:
            tyZ        - Double the current value, decrement.
               -ZeP    - Else, Subtract the maximal prime factor of the current value from itself.
                     - Print implicitly.

PowerShell, 150 126 bytes
for($n="$args";57%$n){$a=$n;$d=for($i=2;$a-gt1){if(!($a%$i)){$i;$a/=$i}else{$i++}};if($n-in$d){$n+=$n-1}else{$n-=$d[-1]}}$n%38

Try it online! (warning: slow for bigger numbers)
Iterative method. PowerShell doesn't have any prime factorization built-ins, so this borrows code from my answer on Prime Factors Buddies.
First is our for loop. The setup sets $n to be the input value, and the conditional keeps the loop going so long as 57%$n is non-zero (thanks to Arnauld for that trick). Inside the loop we first get a list of prime factors of $a (set to $n). This is the code borrowed from Prime Factors Buddies. If the input $a is already prime, this will return just $a (important later). That (potentially just $a) gets stored into $d.
Next is an if/else conditional. For the if part, we check whether $n is -in $d. If it is, that means that $n is prime, so we take $n=2*$n-1 or $n+=$n-1. Otherwise, it's composite, so we need to find the largest prime factor. That means we need to take the last one [-1] of $d and subtract that from $n with $n-=. This works because we're looping up from 2 and thus the last element of $d is already going to be the largest.
Once we're done looping, we just place $n%38 (again, thanks Arnauld) on the pipeline and output is implicit.

APL (Dyalog Unicode), 113 90 59 bytes
⎕CY 'dfns'
g←{1pco ⍵:f(2×⍵)-1⋄f⍵-⊃⌽3pco ⍵}
f←{⍵∊3 19:⍵⋄g ⍵}

Try it online!
TIO works with values up to ~3200. Tested on my PC for the last test case. To test on TIO, just add f value to the bottom of the code.
Doesn't apply anymore, thanks to @Adám for pointing out that my primality checking algorithm was really bad and supplying me with a replacement; also for the 23 byte save.
Edited to fix byte count.
How it works
⎕CY 'dfns'                      # Imports every Defined Function, which is shorter than importing just the function I used (pco).

g←{1pco ⍵:f(2×⍵)-1⋄f⍵-⊃⌽3pco ⍵}
g←                              # define g as
   1pco ⍵:                      # if the argument ⍵ is prime
          f(2×⍵)-1              # Call f over 2×⍵-1
                  ⋄f            # else, call f over
                    ⊃           # the first element of the
                      3pco ⍵    # list of prime factors of ⍵
                     ⌽          # reversed

f←{⍵∊3 19:⍵⋄g ⍵}
f←                              # Define f as
   ⍵     :                      # if the argument ⍵
    ∊                           # is in
     3 19                       # the list [3, 19]
          ⍵                     # return the argument ⍵
           ⋄                    # else
            g ⍵                 # call g over the argument ⍵

Axiom, 93 bytes
h(n)==(repeat(n=3 or n=19 or n<2=>break;prime? n=>(n:=2*n-1);n:=n-last(factors(n)).factor);n)

test:
(4) -> [[i,h(i)] for i in [10,74,94,417,991,9983]]
   (4)  [[10,3],[74,19],[94,3],[417,3],[991,19],[9983,19]]
                                                  Type: List List Integer

There would be 68 bytes function
q x==(n<4=>3;n=19=>n;prime? n=>q(2*n-1);q(n-last(factors n).factor))

but for n=57991 (if I remember well) it goes out the stack space reserved.

Python 2, 93 bytes
Port from TFeld's answer without external libs.
n=input()
while~16&n-3:
 f=n;i=2
 while i<f:
	if f%i:i+=1
	else:f/=i
 n-=[1-n,f][f<n]
print n

Try it online!

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


text:
How compute WPA key?
WPA2, the actual encryption standard that secures all modern wifi networks, has been cracked... This challenge has nothing to do with the way that the WPA2 was cracked, however is is about computing the 64-digit hexadecimal key that corresponds to a given WPA-PSK pass-phrase.
A wireless network with WPA-PSK encryption requires a pass-phrase to be entered to get access to the network. Most wireless drivers accept the pass-phrase as a string of at most 63 characters, and internally convert the pass-phrase to a 256-bit key. However, some systems also allow the key to be entered directly in the form of 64 hexadecimal digits. So the challenge is to calculate the 64-digit hexadecimal key that corresponds to a given pass-phrase.
The hexadecimal key is computed from the pass-phrase and the network SSID (an SSID is a unique ID that consists of 32 characters).
Details of the calculation
For WPA-PSK encryption, the binary key is derived from the pass-phrase according to the following formula: Key = PBKDF2(pass-phrase, SSID, 4096, 256)
The function PBKDF2 is a standardized method to derive a key from a pass-phrase.
It is specified in RFC2898 with a clear explanation on how to compute it.
The function needs an underlying pseudo-random function.
In the case of WPA, the underlying function is HMAC-SHA1.
SHA1 is a function that computes a 160-bit hash from an arbitrary amount of input data.
It is clearly explained in RFC3174.
HMAC is a standardized method to turn a cryptographic hash function into a keyed message authentication function.
It is specified in RFC2104.
To summarize, the key derivation process involves iterating a HMAC-SHA1 function 4096 times, and then doing that again to produce more key bits.
Inputs

SSID a string of at most 32 characters (e.g. stackexchange)
pass-phrase a string of at most 63 characters (e.g. <ra(<@2tAc<$)

Output any reasonable output of the 64 hexadecimal digits

e.g.
24343f69e98d3c08236a6db407584227cf2d1222b050e48f0cf25dee6563cd55
it is the result of the previous inputs

This is code-golf, so please make your program as short as possible!

Just to double check, is 24343f69e98d3c08236a6db407584227cf2d1222b050e48f0cf25dee6563cd55 the output of the inputs stackexchange and <ra(<@2tAc<$? And are we allowed to output bytes instead of hexadecimal digits?

@Okx Yes it is a complete example

Downvoted because output format is too strict.

Can you add a walk-through of how stackexchange and <ra(<@2tAc<$ become 24343f69e98d3c08236a6db407584227cf2d1222b050e48f0cf25dee6563cd55?

@Okx is it okay for you for a less restricted output?

@mdahmoune Output formats on challenges should generally be flexible, because adding bytes just to conform to the output format is annyoing

@Okx I edited the challenge

I like the challenge (from an infosec enthusiast's perspective) but I think it's too restrictive language-wise. Most golflangs just don't have a built-in SHA algorithm, so you'd have to implement that, to be able to create the HMAC function, and only then you'd be able to make a function to solve the challenge, which is both very convoluted and kinda misses the point of codegolfing.

@J.Salle how can make the challenge more accessible for other languages?

@J.Salle many golfing langs can't access the internet or read JSON easily, and yet we post [tag:stack-exchange-api] challenges, besides, I think implementing the algorithm is part of the fun, and having a challenge which golfing langs may not win is always refreshing...

I think it's a good challenge, so I'm not downvoting this challenge, but I'm not upvoting it, either. Ideally, challenges should be self-contained with no external links required. While it's very unlikely that the IETF will go away anytime soon, and I don't expect the entire algorithms to be spelled out here, some of the explanation from the RFCs could be migrated over to here to make the challenge even better.

@AdmBorkBork please feel free to edit the challenge...

@ close voters -- so, what makes this challenge "too broad"? Is it too broad for requiring "too much work" in languages that don't have PBKDF-2 in their standard libraries? I'd personally like to see a submission in such a language (or, maybe, provide one myself) :o

C# (.NET Core) lambda expression, 88 82 81 bytes
Takes input as byte arrays (curried, see comments), returns key as byte array.
p=>s=>new System.Security.Cryptography.Rfc2898DeriveBytes(p,s,4096).GetBytes(32);

Try it online!

@someone as I/O is relaxed, I have a complete new version operating on byte arrays ... updating.

You could just do System.Security.Cryptography.Rfc2898DeriveBytes and save on the using-statement.

82 bytes.

@Emigna thanks, that was kind of silly ;)

Use currying to save one more byte (Func<byte[],Func<byte[],byte[]>> f = p=>s=>...; call as f(p)(s)).

@someone is there some reference about the scoring rules for lambda expressions? I know currying and will happily use it, but think it's a bit silly to spend a lot more bytes for the type information -- is this information definitely not to be scored?

I didn't yet see anyone complaining about currying, so it should be okay.

currying is used and referenced in the tips section:https://codegolf.stackexchange.com/a/85053/15214 (btw I use your answer as example)

Java, 192 88 + 36 = 124 bytes
36 bytes for import de.rtner.security.auth.spi.*;
a is the SSID taken as a byte array, b is the password taken as a string. Outputs byte array. Requires PBKDF2.
a->b->new PBKDF2Engine(new PBKDF2Parameters("HmacSHA1","UTF-8",a,4096)).deriveKey(b,32);

Old answer:
Takes SSID as char array and password as byte array. Outputs byte array.
a->b->{try{return javax.crypto.SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1").generateSecret(new javax.crypto.spec.PBEKeySpec(a,b,4096,256)).getEncoded();}catch(Exception e){return null;}}

Try it online!

Why do you need to catch the exception?

@someone SecretKeyFactory#getInstance throws NoSuchAlgorithmException

Does java require a try-catch for everything that throws exceptions?

@someone Yes, If it's declared in the method. Not always though, for example you can get a NullPointerException if you do something like String s = null; s.isEmpty(); (which will throw a NPE) which doesn't need to be caught (but still can be), as in the String#isEmpty method declaration, it doesn't say it throws NullPointerException.


text:
Fill the steps (randomly)!
This is Hole-9 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here.

Given a simple (rectangular, non-jagged) Boolean array (of one or more dimensions) return a list of thusly shaped arrays where the first array is identical to the input and the last is all-true. All intermediary steps must have one more truth than its neighbor to the left (but otherwise be identical). For each step, the bit that is changed must be pseudo-randomly chosen (and you may take a seed if necessary).
Examples
[0] gives [[0],[1]]
[[0]] gives [[[0]],[[1]]]
[[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]] gives [[[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]],[[1,1,1],[1,1,1],[1,1,1]]]]
The following examples' results may of course vary due to randomness; these are just examples of valid output:
[0,1,0,0] gives [[0,1,0,0],[1,1,0,0],[1,1,0,1],[1,1,1,1]]
[[0,1,0],[0,0,1]] gives [[[0,1,0],[0,0,1]],[[1,1,0],[0,0,1]],[[1,1,0],[0,1,1]],[[1,1,1],[0,1,1]],[[1,1,1],[1,1,1]]]
[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]] gives [[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,1,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0]],[[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0],[0,0,0,0,1,0,0,0],[0,0,0,0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1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,0,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[1,1,1,1,1,1,1,1],[0,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]],[[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1],[1,1,1,1,1,1,1,1]]]

These challenges have really made me start to question the decisions the R/S developers made...

@Giuseppe R/S developers?

R (and S-plus) is an implementation of S, so a lot of the base R functions operate the way that S specifies them, or are maintained to allow compatibility with S (or worse, S-plus). I'm not sure who to blame for some of the unexpected behaviors I've encountered while attempting to solve some of these challenges!

Jelly, 12 bytes
F¬0TX$¦ÐĿ¬ṁ€

Try it online!
How it works
F¬0TX$¦ÐĿ¬ṁ€  Main link. Argument: A (array)

F             Flatten A.
 ¬            Negate all Booleans in the result.
       DĿ     Repeatedly call the link to the left until the results are no longer
              unique. Yield the array of all unique results.
      ¦         Sparse application:
   TX$            Pseudo-randomly select an index of a 1.
  0               Replace the element at that index with 0.
         ¬    Once again negate all Booleans.
          ṁ€  Shape each flat array in the result like A.

Python 2, 197 bytes
import random,copy
A=[input()]
while"0"in`A[-1]`:
 A+=copy.deepcopy(A[-1]),
 while~0:
	j="A[-1]"
	while[]<eval(j):j+="[%s]"%random.randint(0,~-len(eval(j)))
	if eval(j)<1:exec"%s=1"%j;break
print A

Try it online!

Wolfram Language (Mathematica), 61 bytes
FoldList[ReplacePart[#,#2->1]&,#,RandomSample@Position[#,0]]&

Try it online!
Explanation
Position[#,0]

Find all positions of 0s in the nested array.
RandomSample@...

Shuffle the list of positions.
FoldList[...&,#,...]

Fold the function on the left over the shuffled list of positions, using the input as the starting value, and collect all steps of the fold operation in the result.
ReplacePart[#,#2->1]

Set the value at the given position to 1.

R, 93 82 74 bytes
function(a)Reduce(function(x,y){x[y]=T;x},sample(as.list(which(!a))),a,,T)

Try it online!
Takes an R logical array and returns a list of logical arrays.
The nasty sample(as.list(which(!a))) is to prevent an edge case in sample. When a contains exactly one FALSE value at index i, sample returns a random permutation of 1:i rather than a random sample of size 1 containing only the value i, so I used as.list to prevent which(!a) from being numeric.
The R documentation for sample is mildly apologetic about this behavior:

If x has length 1, is numeric (in the sense of is.numeric) and x >= 1, sampling via sample takes place from 1:x. Note that this convenience feature may lead to undesired behaviour when x is of varying length in calls such as sample(x).

Perl 5, 78 + 1 (-p) = 79 bytes
while(@a=/0/g){$o.="$_,";for$i(0..rand@a){/0/g}substr$_,-1+pos,1,1}$_="[$o$_]"

Try it online!
Array?  What array?  It's just a long string.

Jelly, 19 bytes
F¬TṬ€$$o€$ṁ€µX$ÐĿṖṖ

Try it online!
Probably could be shorter
Explanation
F¬TṬ€$$o€$ṁ€µX$ÐĿṖṖ  Main Link
               ÐĿ    While results are unique:
F                    Flatten the array
     $$              3 links will form a monad
 ¬                   Logical NOT on each element
  T                  Find indices of 1s (0s in the original)
    €                For each 0 in the original
   Ṭ                 Make an array of all 0s containing one 1 there
         $           2 links will form a monad
        €            For each of the mask arrays
       o             Vectorizing logical OR it with the original (flat) array
           €         For each of these subarrays
          ṁ          Reshape it to the original array's shape
            µ        Start a new monadic chain, using the list of possible next steps as the argument
              $      2 links will form a monad
             X       Pick a random element
                 ṖṖ  Remove the last two elements (0 and '' which are selected by X when the list is empty)

Python 2, 134 132 129 bytes
from random import*
a=input()
print a;l=list(`a`)
while'0'in l:l[choice([i for i,c in enumerate(l)if'0'==c])]='1';print''.join(l)

Try it online!


text:
Munge my password
Common words should still be avoided to be used as passwords. This challenge is about coding a very simple program that munges a given password (Modify Until Not Guessed Easily).
Input
A word, which is a string written in the alphabet abcdefghijklmnopqrstuvwxyz. It does not matter if the letters are lowercase or uppercase.
Munging

Change any repeated sequence of a same letter to itself preceded by the number of times the letter was repeated (LLLL with 4L)
Change the first a with @
Change the first b with 8
Change the first c with (
Change the first d with 6
Change the first e with 3
Change the first f with #
Change the first g with 9
Change the first h with #
Change the first i with 1
Change the second i with !
Change the first k with <
Change the first l with 1
Change the second l with i
Change the first o with 0
Change the first q with 9
Change the first s with 5
Change the second s with $
Change the first t with +
Change the first v with >
Change the second v with <
Change the first w with uu
Change the second w with 2u
Change the first x with %
Change the first y with ?

Rule 1 must be applied the needed number of times until it is not possible to apply it more. After that the rest of the rules are applied.
Output The munged word
Examples

codegolf    --> (0639o1#
programming --> pr09r@2m1ng
puzzles     --> pu2z135
passwords   --> p@25uu0r6$
wwww        --> 4uu
aaaaaaaaaaa --> 11a
lllolllolll --> 3103io3l
jjjmjjjj --> 3jm4j

This is code-golf, so please make your program as short as possible!
Nothing in this post should be used as password ideas or as any part of password practices.

The very fact that programs like this are possible means that the attacker could write them and munge the password (and try the various munges) just as easily (even easier because they often have access to better hardware). So just for safety's sake I will say: nothing in this post should be used as password ideas or as any part of password practices.

I recommend making that disclaimer bold and duplicating it at the top. You can never be too careful...

Java 8, 237 321 319 280 247 241 240 237 bytes
s->{for(int a[]=new int[26],i=0,l=s.length,t,x;i<l;i+=t){for(t=0;++t+i<l&&s[i]==s[t+i];);System.out.print((t>1?t+"":"")+(++a[x=s[i]-65]>2?s[i]:"@8(63#9#1J<1MN0P9R5+U>u%?ZABCDEFGH!JKiMNOPQR$TU<2XYZ".charAt(x+26*~-a[x])+(x==22?"u":"")));}}

+84 bytes because the rules got changes.. (EDIT: Finally back to my initial 237 bytes.) Replacing WWWW with 222W is easy in Java, but with 4W not.. If only Java had a way to use the regex capture-group for something.. Getting the length with "$1".length(), replacing the match itself with "$1".replace(...), converting the match to an integer with new Integer("$1"), or using something similar as Retina (i.e. s.replaceAll("(?=(.)\\1)(\\1)+","$#2$1")) or JavaScript (i.e. s.replaceAll("(.)\\1+",m->m.length()+m.charAt(0))) would be my number 1 thing I'd like to see in Java in the future to benefit codegolfing.. >.> I think this is the 10th+ time I hate Java can't do anything with the capture-group match..
-78 bytes thanks to @OlivierGrégoire.
I/O is uppercase.
Explanation:
Try it here.
s->{                           // Method with String parameter and no return-type
  for(int a[]=new int[26],     //  Array with 26x 0
          i=0,                 //  Index-integer, starting at 0
          l=s.length,          //  Length
          t,x;                 //  Temp integers
      i<l;                     //  Loop (1) over the characters of the input
      i+=t){                   //    After every iteration: Increase `i` by `t`
    for(t=0;++                 //   Reset `t` to 1
        t+i<l                  //   Inner loop (2) from `t+i` to `l` (exclusive)
        &&s[i]==s[t+i];        //   as long as the `i`'th and `t+i`'th characters are equal
    );                         //   End of inner loop (2)
    System.out.print(          //   Print:
     (t>1?t+"":"")             //    If `t` is larger than 1: print `t`
     +(++a[x=s[i]-65]>2?       //    +If the current character occurs for the third time:
       s[i]                    //      Simply print the character
      :                        //     Else:
       "@8(63#9#1J<1MN0P9R5+U>u%?ZABCDEFGH!JKiMNOPQR$TU<2XYZ".charAt(x
                               //      Print the converted character at position `x`
        +26*~-a[x])            //       + 26 if it's the second time occurring
       +(x==22?"u":"")));      //      And also print an additional "u" if it's 'W'
  }                            //  End of loop (1)
}                              // End of method

JavaScript (ES6), 147 bytes
s=>[[/(.)\1+/g,m=>m.length+m[0]],..."a@b8c(d6e3f#g9h#i1k<l1o0q9s5t+v>x%y?i!lis$v<".match(/../g),["w","uu"],["w","2u"]].map(r=>s=s.replace(...r))&&s

Test Cases

f=
s=>[[/(.)\1+/g,m=>m.length+m[0]],..."a@b8c(d6e3f#g9h#i1k<l1o0q9s5t+v>x%y?i!lis$v<".match(/../g),["w","uu"],["w","2u"]].map(r=>s=s.replace(...r))&&s

;["codegolf","programming","puzzles","passwords","aabaa","www","lllolllolll","jmnpruz"]
.forEach(t=>console.log(t,"->",f(t)))
.as-console-wrapper{max-height:100%!important}

Explanation
Runs through a series of replacements on the input string, s, in the order specified by the challenge. Each item in the series is an array or string, with two items, that is then spread (...r) and passed to s.replace().
s=>[
    [/(.)\1+/g, m=>m.length + m[0]],// first replacement: transform repeated letters
                                    // into run-length encoding

                                    // string split into length-2 partitions and
                                    // spread into the main array
    ..."a@b8c(d6e3f#g9h#i1k<l1o0q9s5t+v>x%y?i!lis$v<".match(/../g),
                                    // next replacements: all single-char replacements.
                                    // "second" versions are placed at the end so they
                                    //    replace the second instance of that char

    ["w","uu"],["w","2u"]           // last replacements: the two "w" replacements
]
.map(r=> s = s.replace(...r))       // run all replacements, updating s as we go
&& s                                // and return the final string

Very good answer

05AB1E, 69 bytes
-9 bytes thanks to Emigna
γvygD≠×yÙ}J.•k®zĀÒĀ+ÎÍ=ëµι
•"@8(63#9#1<1095+>%?!i$<"ø'w„uu„2u‚â«vy`.;

Try it online!

You could use 'w„uu„2u‚â

Plz could you verify result for wwww as input?

@mdahmoune It outputs 4uu

@Emigna Cartesian product, good idea.

First part can be γvygD≠×yÙ}J

You also don't need €S

@Emigna Yeah, it was left in from something I had before

Thanx for the update ;)

Perl 5, 152 + 1 (-p) = 153 bytes
s/(.)\1+/(length$&).$1/ge;%k='a@b8c(d6e3f#g9h#i1j!k<l1mio0q9r5s$t+u>v<x%y?'=~/./g;for$i(sort keys%k){$r=$k{$i};$i=~y/jmru/ilsv/;s/$i/$r/}s/w/uu/;s/w/2u/

Try it online!

Plz what do you mean by (-p)?

@mdahmoune -p is used as an argument to perl at the commandline that automatically reads input from STDIN and prints the contents of $_ at the end of the script. TIO allows that option, and since perl -pe<code> is 1 more byte than perl -e<code> it's counted as one additional byte.

I think you've made a typo, shouldn't the ~ between j~k be an ! instead? Currently it replaced the second occurrence of i with a ~ instead of a !.

@Xcali #testingonproduction

@NieDzejkob There's no better place.  That's the only way you know it will work in production.

Probably not the most golfed it could be, but it works.
-6 bytes thanks to ovs
-77 Bytes thanks to  NieDzejkob and Jonathan French
Python 3, 329 323 bytes 246 bytes
import re;n=input()
for a in re.finditer('(\w)\\1+',n):b=a.group();n=n.replace(b,str(len(b))+b[0],1)
for A,B,C in[('abcdefghikloqstvxyw','@8(63#9#1<1095+>%?','uu'),('ilsvw','!i$<','2u')]:
	for a,b in zip(A,list(B)+[C]):n=n.replace(a,b,1)
print(n)

Try it online!

I think you may drop .lower()

That makes sense, I wasn't sure whether I needed to handle uppercase or not.

321 bytes.

320 bytes.

Actually, your answer doesn't work. jjjmjjjj should output 3jm4j but outputs 3jm3jj. Edit: 258 bytes with this problem fixed

@NieDzejkob 255 bytes.

@JonathanFrech 246 bytes except the Python 2 starts getting really similar and I posted a link there with it ported to Python 3 for 192 bytes.

Retina, 166 124 bytes
(.)\1+
$.&$1
([a-y])(?<!\1.+)
¶$&
¶w
uu
T`l¶`@8(63#9#1j<\1mn0\p9r5+u>\w%?_`¶.
([ilsvw])(?<!\1.+)
¶$&
¶w
2u
T`i\lsv¶`!i$<_`¶.

Try it online! Explanation:
(.)\1+
$.&$1

Replace a run of repeated letters with the length and the letter.
([a-y])(?<!\1.+)
¶$&

Match the first occurrence of the letters a to y and mark them with a placeholder.
¶w
uu

Fix the first occurrence of w.
T`l¶`@8(63#9#1j<\1mn0\p9r5+u>\w%?_`¶.

Fix the first occurrence of all the other letters from a to y and delete the placeholders.
([ilsvw])(?<!\1.+)
¶$&

Mark the (originally) second occurrence of the letters i, l, s, v, or w with a placeholder.
¶w
2u

Fix the second occurrence of w.
T`i\lsv¶`!i$<_`¶.

Fix the second occurrence of the other four letters.

Do you think it’s possible to golf it further?

@mdahmoune Yes, I think I can save 33 bytes.

I up-voted your answer :)
it will be great if your save the 33 bytes ;)

@mdahmoune Good news, I actually saved 42 bytes!

Great, your code is the second shortest ;)

Haskell, 221 218 213 bytes
($(f<$>words"w2u li i! s$ v< a@ b8 c( d6 e3 f# g9 h# i1 k< l1 o0 q9 s5 t+ v> wuu x% y?")++[r]).foldr($)
f(a:b)(h:t)|a==h=b++t|1>0=h:f(a:b)t
f _ s=s
r(a:b)|(p,q)<-span(==a)b=[c|c<-show$1+length p,p>[]]++a:r q
r s=s

Try it online!
Abuses foldr to run the string through a sequence of string transformations backwards. The  sequence "starts" with r which does the repetition count replacement by using span to break the tail of the string when it stops being equal to the head. If the first part of that is non-empty it's a repetition so we print the length +1. Next we curry an argument into f for each character replacement in (reverse) order. The replacements are encoded as a single string with the first character being the character to be replaced and the rest as the string (since the w replacements are multiple characters) to go in its place. I put these encoded strings in one big string separated by spaces so that words can break it into a list for me.
EDIT: Thanks @Laikoni for saving me 5 bytes! That was a clever use of $ I didn't think of. I also didn't know that <- trick.

Thanx for detailed explanation ;)

You can use (p,q)<-span(==a)b instead of let(p,q)=span(==a)b and p>[]  instead of p/=[].

Save two more bytes by making m pointfree: ($(f<$>words"w2u ... y?")++[r]).foldr($) Try it online!

R, 224 219 bytes
function(s,K=function(x)el(strsplit(x,"")),u=rle(K(s)))
Reduce(function(x,y)sub(K('abcdefghiiklloqsstvvwwxy')[y],c(K('@8(63#9#1!<1i095$+><'),'uu','2u',K('%?'))[y],x),1:24,paste0(gsub("1","",paste(u$l)),u$v,collapse=""))

Try it online!
Nasty, but the main part is the iterative substitution in the Reduce. sub changes only the first occurrence of the match.
Thanks to JayCe for pointing out a nice golf!

Good job :)))))

save 1 byte by rearranging args. Doesn't make a huge difference I know ;)

@JayCe I found some more bytes :-)

Lua, 173 bytes
s=...for c,r in("uua@b8c(d6e3f#g9h#i1i!jjk<l1limmnno0ppq9rrs5s$t+v>v<wuuw2ux%y?zz"):gmatch"(.)(.u?)"do s=s:gsub(c..c.."+",function(p)return#p..c end):gsub(c,r,1)end print(s)

Try it online!
Ungolfed and explained:
s = ...

--This string contains every character to replace, followed by
--the character(s) it should be replaced with.
--
--It also contains all characters for which repeated sequences
--of them should be replaced by "<number><character>". That is,
--all letters in the alphabet. This way, a single loop can do
--both the "replace repeated characters" and "encode characters"
--operations, saving a for loop iterating over the alphabet.
--
--Characters that shouldn't be replaced will be replaced with
--themselves.
--
--In order to avoid matching half of the "replace u with u"
--command as the replace part of another command, "uu" is placed
--at the beginning of the string. This ensures that only the
--2-character replacements for "w" get an extra "u".

cmdstring = "uua@b8c(d6e3f#g9h#i1i!jjk<l1limmnno0ppq9rrs5s$t+v>v<wuuw2ux%y?zz"

--Iterate over all the search/replace commands.
--The character to replace is in the "c" variable, the string to
--replace it with is in "r".
--
--Due to the dummy search/replace commands (i.e. "mm") placed
--in the string, this loop will also iterate over all letters
--of the alphabet.

for c,r in cmdstring:gmatch("(.)(.u?)") do

	--First, replace any occurences of the current letter
	--multiple times in a row with "<number><letter>".
	s = s:gsub(c..c.."+", function(p)
		return #p .. c
	end)

	--Then, replace the first occurence of the letter
	--with the replacement from the command string.
	s = s:gsub(c, r, 1)
end

print(s)

Lol lua :) good job

C# (.NET Core), 317, 289, 279 Bytes
p=>{string r="",l=r,h=r,c="a@b8c(d6e3f#g9h#i1i!k<l1lio0q9s5s$t+v>v<wuw2x%y?";int i=0,n=p.Length,d,a=1;for(;i<n;i++){h=p[i]+"";if(h==p[(i==n-1?i:i+1)]+""&&i!=n-1)a++;else{d=c.IndexOf(h);if(d>=0&&d%2<1){l=c[d+1]+"";h=l=="u"?"uu":l;c=c.Remove(d,2);}r+=a>1?a+""+h:h;a=1;}}return r;};

Try it Online!
I hope it's ok to receive a char array as an input and not a string.
Ungolfed:
string result = "", casesCharReplacement = result, currentChar = result, cases = "a@b8c(d6e3f#g9h#i1i!k<l1lio0q9s5s$t+v>v<wuw2x%y?";
int i = 0, n = pas.Length, casesIndex, charAmounts = 1;

// For every char in the pass.
for (; i < n; i++)
{
    currentChar = pas[i] + "";
    // if the next char is equal to the current and its not the end of the string then add a +1 to the repeated letter.
    if (currentChar == (pas[(i == n - 1 ? i : i + 1)] + "") && i != n - 1)
        charAmounts++;
    else
    {
        // Finished reading repeated chars (N+Char).
        casesIndex = cases.IndexOf(currentChar);
        // Look for the replacement character: only if the index is an even position, otherwise I could mess up with letters like 'i'.
        if (casesIndex >= 0 && casesIndex % 2 < 1)
        {
            casesCharReplacement = cases[casesIndex + 1]+"";
            // Add the **** +u
            currentChar = casesCharReplacement == "u"?"uu": casesCharReplacement;
            // Remove the 2 replacement characters (ex: a@) as I won't need them anymore.
            cases = cases.Remove(casesIndex, 2);
        }
        // if the amount of letters founded is =1 then only the letter, otherwise number and the letter already replaced with the cases.
        result += charAmounts > 1 ? charAmounts + ""+currentChar : currentChar;
        charAmounts = 1;
    }
}
return result;

Yes it’s ok :) for the input

C++, 571 495 478 444 bytes
-127 bytes thanks to Zacharý
#include<string>
#define F r.find(
#define U(S,n)p=F s(S)+b[i]);if(p-size_t(-1)){b.replace(i,1,r.substr(p+n+1,F'/',n+p)-p-2));r.replace(p+1,F'/',p+1)-p,"");}
#define V(A)i<A.size();++i,c
using s=std::string;s m(s a){s b,r="/a@/b8/c(/d6/e3/f#/g9/h#/i1//i!/k</l1//li/o0/q9/s5//s$/t+/v>/wuu//w2u/x%/y?/";int c=1,i=0;for(;V(a)=1){for(;a[i]==a[i+1]&&1+V(a)++);b+=(c-1?std::to_string(c):"")+a[i];}for(i=0;V(b)){auto U("/",1)else{U("//",2)}}return b;}

the "/a@/b8/c(/d6/e3/f#/g9/h#/i1//i!/k</l1//li/o0/q9/s5//s$/t+/v>/wuu//w2u/x%/y?/" string is used to transform from one character to others. 1 / means that the first "next char" should be replaced by what follow the next /, 2 means that the second "next char" should be replaced by what follows.
Try it online

Great, could you please add a tio.run link ?

@mdahmoune TIO link is added, with the code to test for your test cases :)

494 bytes, and update the TIO link accordingly if you change it.

@Zacharý You need to put a space between the macro name and the macro content, otherwise, it throws an error when compiling with C++ 17. Also, do you know how to delete a TIO link ? ( since the old one is useless )

You can't delete a TiO link. But you can remove the reference to it in your answer.

479 bytes, and if you update the post, update the TIO link accordingly.

Replace p!=size_t(-1) with p-size_t(-1) to save one byte (ofc update the TIO link afterwards)

Somehow ... there's more left: 474 bytes

446 bytes

444 bytes

Perl 5, 123 bytes
122 bytes code + 1 for -p.
Developed independently from @Xcali's answer, but using a very similar process.
s/(.)\1+/$&=~y!!!c.$1/ge;eval"s/$1/$2/"while'a@b8c(d6e3f#g9h#i1i!k<l1lio0q9s5t+v>v<x%y?'=~/(.)(.)/g;s/s/\$/;s/w/uu/;s;w;2u

Try it online!

Python 2, 220 216 194 190 188 bytes
import re
S=re.sub(r'(.)\1+',lambda m:`len(m.group(0))`+m.group(1),input())
for a,b in zip('abcdefghiiklloqsstvvxyww',list('@8(63#9#1!<1i095$+><%?')+['uu','2u']):S=S.replace(a,b,1)
print S

Try it online!
Python 3, 187 bytes
import re
S=re.sub(r'(.)\1+',lambda m:str(len(m.group(0)))+m.group(1),input())
for a,b in zip('abcdefghiiklloqsstvvxyww',[*'@8(63#9#1!<1i095$+><%?','uu','2u']):S=S.replace(a,b,1)
print(S)

Try it online!

Thanx Tfeld 192 bytes https://tio.run/##NY3NisIwFEb3fYoMjtx7aShGUUbx7x26HAVTjRomTTJpYtWX7xR0FgfO4Vt8/hGvzo67TtfehciCyspVUEWTKgyABe1EDtzIujpJVi8ORlmsi0twyeOI6JD/hyCurU8RibKzC0zyimnLntojyOp4UufLVesfY9xv08Tb7f4ADtsvnE0G84H4WAo9mk8/8/VyuAHKvxHafk8JiL903Ot@Ua7KIihv5FFh/8AFZT5oG1nZddC2rXsDfw

Great golfing ;)

186 bytes. You can also easily port this to Python 3 in 192 bytes, but I don't think it should be a separate answer.

@NieDzejkob It seems as though your golfed Python 2 version produces a different output than the OP's current version or your Python 3 version.

@JomathanFrech sorry, as always testing on production. 188 bytes

Pip, 103 102 bytes
aR:`(.)\1+`#_.B
Fm"abcdefghiiklloqsstvvwwxy"Z"@8(63#9#1!<1i095$+><WU%?"I#Ya@?@maRA:ym@1aR'W"uu"R'U"2u"

Try it online!
Explanation
The code does three steps of transformation:
aR:`(.)\1+`#_.B  Process runs of identical letters

a                1st cmdline argument
 R:              Do this replacement and assign back to a:
   `(.)\1+`       This regex (matches 2 or more of same character in a row)
           #_.B   Replace with callback function: concatenate (length of full match) and
                  (first capture group)
                  Note: #_.B is a shortcut form for {#a.b}

Fm"..."Z"..."I#Ya@?@maRA:ym@1  Do the bulk of rules 2-25

  "..."                        String of letters to replace
       Z"..."                  Zip with string of characters to replace with
Fm                             For each m in the zipped list:
                   @m           First item of m is letter to replace
                a@?             Find its index in a, or nil if it isn't in a
               Y                Yank that into y
             I#                 If len of that is truthy:*
                     aRA:        Replace character in a at...
                         y        index y...
                          m@1     with second item of m

aR'W"uu"R'U"2u"  Clean up substitution
                 In the previous step, the replacements each had to be a single character.
                 This doesn't work for uu and 2u, so we use W and U instead (safe, since
                 uppercase letters won't be in the input) and replace them here with the
                 correct substitutions.
aR'W"uu"         In a, replace W with uu
        R'U"2u"  and U with 2u
                 and print the result (implicit)

* We need to test whether a@?m@0 is nil. It's not enough to test that it's truthy, since 0 is a legitimate index that is falsey. Pip doesn't have a short builtin way to test if a value is nil, but testing its length works well enough in this case: any number will have length at least 1 (truthy), and nil has length of nil (falsey).

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