text:
Look mom! I made my own (Base 10) numeral system!
We've all done it, well, maybe not, but making your own alien language and numbering system is a staple of especially fantasy writing, but is mostly just a fun activity.
The task is simple, take two inputs:

An ordered list input of 10 [ten] unique 'numerals' (any printable
ASCII character) and interpret them, in order, as the values 0, 1,
2, 3,...,9
+There are exceptions to what can be a numeral here. Arithmetic operators (+, -, *, /), Parentheses, and spaces cannot be used as one of the numerals.
An arithmetic problem using only those 'numerals'

And output the equivalent integer result in the given form.
Here's an example:
INPUT

abcdefghij

bcd + efg + hij

OUTPUT

bdgi

In the example, the input list (you may choose which form the list comes in) of 'abcdefghij' corresponds to '0123456789' just as 'hjkloiwdfp' would also correspond 1 to 1 with '0123456789' where instead of 'a' associating with zero, 'h' does. The arithmetic following 'translates' to 123 + 456 + 789, which equals 1368. This must then be outputted in the form we gave it, so b (which represents 1) d (for 2) g (for 6) and i (for 8).
TEST CASES
abcdefghij
abc + def - ghij

-gedc

qwertyuiop
qwerty / uiop

e

%y83l;[=9|
(83l * 9) + 8%

y9|8

MORE RULES

Standard
Loopholes
are forbidden!
This is code golf, so shortest answers in bytes wins.
Must be a full program or function taking the inputs and outputs in whatever format works best for you. (Just cannot add additioal information in the inputs, just 'numerals' and the expression.
Use any language you'd like (as long as it complies with other rules)

@AdmBorkBork I should change that! Mistake!

Yes, @Veskah, I should have specified (will edit after this comment). This is my first post here, so some mistakes certainly were made! I'll address space as well.

The 2nd test case suggests that the final output is rounded, otherwise the result would be q.ioiopewioyetqorw.... If so, what kind of rounding should be applied?

Can we use proper mathematical symbols instead of * and /?

@Arnauld Round to nearest integer. I should have been more clear, thanks for your comment.

@Adám What did you have in mind? I'm trying to limit the number of symbols you can use as they are exceptions to what can be in the numeral system.

@BillW please edit the challenge to clarify that we need to round to the nearest integer. Thanks!

Welcome to the site! How does the / operator work? From the example it seems to be some integer approximation of division but explaining it in the post is preferable to having to guess from incomplete examples.  Similarly to what extent must - be supported can the input ever contain two or more -s in a row or a - after another operator?  A firm definition of what the input might look like rather than a vague intuition would be very nice.

To add to @SriotchilismO'Zaic 's point, we also have a sandbox for your benefit and ours; the intent is to let the community help refine challenges before they are posted. Nice idea for a challenge, though!

@BillW You know, the normal symbols: × for multiplication and ÷ for division.

Different languages are likely to evaluate the same equation differently, I'm not sure there is any way around it. For example, T-SQL returns 1 for 5/3, not 2, due to integer division (not rounding). This doesn't invalidate the challenge, but you may have to allow different acceptable answers for the same test case (see my T-SQL answer below).

@BradC I thought that was implied. Same thing goes for order of execution.

@Giuseppe Wow, I have browsed this stack for a long while and never knew of that! Would have definitely been helpful, especially as the first time poster (long time listener) that I am. Will keep note for next time! Thanks for your comment and answer.

Oh I just realized, the values starting with 0 were screwing up my math because they were being treated as octal...

Bill for the last time go play outside! - Mom

An interesting variation on this would be one that supports any number base, depending on the length of the first string in the input...

05AB1E, 10 9 bytes
žh‡.Eò¹Åв

(Now) outputs as a list of characters.
Try it online or verify all test cases.
Explanation:
  ‡        # Transliterate the second (implicit) input, replacing every character of
           # the first (implicit) input with:
žh         # The builtin "0123456789"
   .E      # Then evaluate it as Elixir code
     ò     # Round it to the nearest integer
      ¹Åв  # And change it back by using a custom base-conversion with the first input as
           # base (which results in a character list)
           # (after which that result is output implicitly)

The new version of 05AB1E is build is build in Elixir. The .E function will call call_unary(fn x -> {result, _} = Code.eval_string(to_string(x)); result end, a), where the Code.eval_string is an Elixir builtin.
Note that the legacy version of 05AB1E won't work for this, because it is build in Python. The numbers with leading 0s won't be evaluated:
See all test cases in the legacy version (which uses the 10-byte version because the Åв builtin is new).

R, 58 bytes
function(d,s,`[`=chartr)'0-9'[d,eval(parse(t=d['0-9',s]))]

Try it online!
Uses character translation chartr to swap the digits, parses and evals the expression, and then chartrs back to the original digits.
If rounding to nearest integer is required, this is
R, 65 bytes
function(d,s,`[`=chartr)'0-9'[d,round(eval(parse(t=d['0-9',s])))]

Try it online!

Using [ as a shorter name for a function with 3 parameters is very smart. Well done.

T-SQL, 117 bytes
DECLARE @ CHAR(99)
SELECT @='SELECT TRANSLATE('+TRANSLATE(e,c,'0123456789')+',''0123456789'','''+c+''')'FROM t
EXEC(@)

Line breaks are for readability only.
Input is via a pre-existing table t with text columns c (characters) and e (equation), per our IO rules.
Uses the SQL 2017 function TRANSLATE to switch between characters and generate a string that contains not only the equation, but the code to translate back to the original characters:
SELECT TRANSLATE(123 + 456 + 789,'0123456789','abcdefghij')

This string is then evaluated using EXEC().
There may be some characters (such as a single quote ') that would break this code; I haven't tested all possible ASCII characters.
Per the challenge, I am evaluating the expression as given, subject to how my language interprets those operators. As such, the second test case returns 1 (w), and not 2 (e), due to integer division.

Perl 6, 38 bytes
{*.trans($_=>^10).EVAL.trans(^10=>$_)}

Try it online!
I'm not sure how the rounding is supposed to work. If it rounds at the end then I can add .round for +6 bytes. If the behaviour of / should be different then it may be longer. Takes input curried like f(arithmetic)(numerals)(arithmetic).
Explanation:
{                                    }  # Anonymous codeblock
 *                                      # Returning a whatever lambda
  .trans($_=>^10)       # That translates the numerals to digits
                 .EVAL  # Evaluates the result as code
                      .trans(^10=>$_)   # And translates it back again

Stax, 74 66 65 bytes
┼ö8Q#xóπcM~oÖ÷╦├mî☼yº─▐4ç≥e╘o▄ê‼ø_k╜ø8%N╫ ╗e<.╗P[─╛èA±!xêj«w╠°{B♪

Run and debug it
Stax does not do well here, lacking a true "eval" instruction.  It has one that's called "eval" in the docs, but it only works on literal values, not full expressions.

This might not obey operator precidence. Not sure if that is required though?  https://staxlang.xyz/#p=c59438512378a2e3634d7e6f99f6cbc36d8c0f79a7c4de3487f265d46fdc8813005f6bbd0038254ed720bb653c2ebb505bc4be8a41f12178886aae77ccf87b420d&i=0123456789%0A5+%2B+5+%2F+10&a=1&m=1

@dana: Good point.   I didn't consider that.  A fix is likely to cost some bytes, so I'll wait for some clarification before trying to change that behavior.

Bash, 97 bytes
IFS=''
read S
read O
A=`echo "$O"|tr "$S" 0-9`
printf %0.f `bc<<<"(${A[@]##0})+0.5"`|tr 0-9 "$S"

Could be less if we could truncate, rather than round. Also tricky to handle leading zeroes (as in test case #2) since Bash interprets numbers starting with 0 as octal.

What is the consensus on using utilities like "bc" and "tr" for golfing?

I'm no expert, but I think those types of answers are typically submitted as something like "bash + coreutils"

@Giuseppe tr is part of the coreutils, while bc is not. Nevertheless, bc is a very common tool. Every other command in this answer is bash.

-7 bytes stolen from @CM's answer, reducing '0123456789' to '0-9'

Defining T is no longer advantageous: $T is only one byte shorter than 0-9, you only use it twice, and you spend 8 bytes to define it.

@ruds: Thanks! -6 bytes thanks to you.

Perl 5 -p, 63 bytes
$p=<>;eval"y/$p/0-9/";s/\b0+\B//g;$_=int.5+eval;eval"y/0-9/$p/"

Try it online!
Takes the expression on the first line of input and the translation list on the second.

Bean, 94 90 bytes
Hexdump
00000000: 53d0 80d6 d800 d3d0 80a0 1f20 8047 53a0  SÐ.ÖØ.ÓÐ. . .GS
00000010: 1753 d080 d3d0 80a0 5e20 800a a181 8100  .SÐ.ÓÐ. ^ ..¡...
00000020: 40a0 5f52 cac3 4da0 6580 53d0 80a0 5d20  @ _RÊÃM e.SÐ. ]
00000030: 8089 205f a065 205f 2080 0aa1 8181 0123  .. _ e _ ..¡...#
00000040: 0058 0020 800a a181 8102 40a0 6550 84a0  .X. ..¡...@ eP.
00000050: 5d20 652e dce2 b02b dc64                 ] e.Üâ°+Üd

JavaScript
`${Math.round(
  eval(
    b.replace(
      /./g,
      c => ~(i = a.indexOf(c)) ? i : c
    ).replace(
      /\b0+/g,
      ''
    )
  )
)}`.replace(
  /\d/g,
  i => a[i]
)

Explanation
This program implicitly assigns the first and second lines of input as strings to the variables a and b respectively.
Each character c on line b is replaced with the respective index i of the character found on line a, or itself if it is not found.
Then it removes each sequence of one or more 0s preceded by a boundary from the resulting string. This is to prevent eval() from evaluating any sequence of digits starting with 0 as an octal literal.
After eval() and Math.round(), the result is coerced back into a string and each digit character i is replaced by the corresponding character from line a at index i.
Test Cases
Demo
abcdefghij
abcd + efg + hij

bdgi

Demo
abcdefghij
abc + def - ghij

-gedc

Demo
qwertyuiop
qwerty / uiop

e

Demo
%y83l;[=9|
(83l * 9) + 8%

y9|8

Perl 5, 130 bytes
sub f{eval sprintf"'%.0f'=~y/%s/%s/r",eval(eval(sprintf"\$_[1]=~y/%s/%s/r",@r=map"\Q$_",$_[0],'0123456789')=~s,\b0,,gr),reverse@r}

Try it online!
Maybe that double eval somehow can be turned into s/.../.../geer.

Charcoal, 14 bytes
⍘ＵＶ⭆η⎇№θι⌕θιιθ

Try it online! Link is to verbose version of code. Note: Expression is evaluated according to Python 3 semantics, so for instance leading zeros on non-zero numbers are illegal. Explanation:
   ⭆η           Map over expression's characters and join
        ι       Current character
      №θ        Count matches in first input
     ⎇          If non-zero
         ⌕θι    Replace with position in first input
            ι   Otherwise keep character unchanged
 ＵＶ             Evaluate as Python 3
⍘            θ  Convert to base using first input as digits

Unfortunately leading 0s don't work in Python, which is present in the test cases.

Python 3, 167 bytes
import re
a=[*enumerate(input())]
e=input()
for i,c in a:e=re.sub(c,str(i),e)
e=str(round(eval(re.sub(r'\b0+(?!\b)','',e))))
for i,c in a:e=re.sub(str(i),c,e)
print(e)

Try it online!
Room for improvement...

Still fails on the last test case: https://tio.run/##dYyxCoMwFAD3fEU6SF40lIKLtoR@iHaI9pUGNIZnUhD672kE1950w3F@C@/F1SnZ2S8UOCEzuivRxRnJBATrfAwg5YOhPpy9FuJWjdw6bq6oCc9rHGBUayCwUqHM7e60RPcE/JgJjoZEP1wquJ/6QQolRG4zf4bHbtyHnqwLgDKlYmvq6dbp9ssgGy95K3nFm@IH

Lua, 162 151 150 bytes

-11 bytes thanks to my idea of using load instead of function(...) end
-1 byte by omitting newline

l,p=...print(((math.ceil(load('return '..p:gsub('.',load'n=l:find(...,1,1)return n and n-1'))()-0.5)..''):gsub('%d',load'c=...+1 return l:sub(c,c)')))

Try it online!
Not shortest thing in the world (Lua forces you to be fancy quite hard, especially by huge keywords), but was pretty fun to create. Full program taking input as arguments and printing result.
Explanation
Introduction
l,p=...

Assign values from arguments to variables. Our dictionary is l and expression is p.
Following expression is quite hard to understand because it have a weird order of execution, so I'll explain it step-by-step:
Converting to normal numbers
p:gsub('.',
load'n=l:find(...,1,1)return n and n-1')

Perform replacement on expression string: take each symbol and pass it to function (load proved itself to be shorted than normal declaration here).
Function finds position of occurrence in dict string for passed symbol using find. ... is first (and only) argument here as we're in vaarg function (any loaded one is) that is our current symbol. Following arguments are required to make find ignore special symbols (1 is just short value which evaluates as true when converted to boolean): starting position (one is default here) and plain, which actually disables pattern handling. Without those program fails on third test case due to % being special.
If match is found, subtract one as Lua strings (and arrays btw) are 1-based. If no match is found, it will return nothing, resulting in no replacement being done.
Solving
math.ceil(load('return '..ABOVE)()-0.5)

Prepend return to our expression to let it return result, calculate it by compiling as Lua function and calling it, perform rounding (this turned other way around to make it shorter).
It the end we get a numerical solution to our problem, only converting it back remains.
Making it crazy again
(ABOVE..'')
:gsub('%d',load'c=...+1 return l:sub(c,c)')

First line is a short way to convert number to string, so now we can call string methods in a short way. Let's do so!
Now gsub is called again to replace everything back to insanity. This time %d is used instead of . as replacement pattern as our function may and must process only numbers (. would result to error on negative numbers). This time function (loaded again to save bytes) first adds 1 to its first (and only) vaargument, converting it to position in dict string, then returns character from it at that position.
Hooray, almost there!
Dramatic finale, or Why Brackets Matter
print((ABOVE))

Well… why two pairs of brackets anyways? It's time to talk about parall… eh, multiple return in Lua. Thing is that one function may return few values from one call (look at this meta question for more examples).
Here, last gsub returned two values: answer string we need and amount of replacements done (count of digits actually, but who cares). If it wasn't for internal pair, both string and number would be printed, screwing us up. So here we sacrifice two bytes to omit second result and finally print product of this insanity factory.

Well, I've enjoyed explaining almost as much as golfing in first place, hope you got what's going on here.

Note: it passes all of testcases, but probably rounds incorrectly in others. If you can find one, I'm going to fix it.

Python 3, 137 bytes
A non-regex approach using str.translate and str.maketrans to replace the characters. I lost a lot of characters on trimming the leading zeros...
lambda s,t,d='0123456789',e=str.translate,m=str.maketrans:e(str(round(eval(' '.join(c.lstrip('0')for c in e(t,m(s,d)).split())))),m(d,s))

Try it online!

Wolfram Language (Mathematica), 121 bytes
I define a pure function with two arguments. Since some functions are repeated I save them in a variable to save a few characters. This code simply does some string replacements and then uses ToExpression to evaluate the expression with the Wolfram kernel.
(r=Thread[StringPartition[#,1]->(t=ToString)/@Range[0,9]];u[(u=StringReplace)[#2,r]//ToExpression//Round//t,Reverse/@r])&

Try it online!


text:
Help me sub-divide a time signature
This challenge is based on a video in which Andrew Huang discusses unusual time signatures...
https://www.youtube.com/watch?v=JQk-1IXRfew
In it, he advises that you can understand time signatures by dividing them into 3's and 2's. So you count to a small number a few times, instead of counting to a large number.
Here's the pattern he builds which repeats after 19 steps:

5 groups of 3
2 groups of 2

This is how it looks:
#..#..#..#..#..#.#.

Actually, as you'd play each beat alternatively, the accented beats move from left to right, because there's an odd number of steps. So now this pattern is:
R..L..R..L..R..L.L.
L..R..L..R..L..R.R.

If we reduce this to an algorithm, it can be described like this.
Step 1: where are the accents

From your number of steps, start by taking groups of 3 from the start until there's 4 or fewer steps remaining.

E.g. for a pattern 8 steps long.
8 steps - take three, 5 steps remaining
#..

5 steps - take 3, 2 steps remaining
#..#..

Once we're down to 4 steps or fewer, there's 3 possibilities.

4 steps - 2 groups of 2
3 steps - 1 group of 3
2 steps - 1 group of 2

So from our above example:
#..#..#.

Step 2: Which hand are the accents on
Let's assume that each individual step will be played on alternate hands, starting with the right.
So for 8 steps, the (underlying) pattern will go
rlrlrlrl

The pattern we output will only tell use which hand the accents are on. With the above example:
R..L..R.

That's fine, it's repeatable.
but
If it's an odd number, you've got the same hand for both the first and last steps, and you can't keep alternating when you repeat the pattern. Instead, the second pattern will be on the other hand. Here's the pattern on an 11 step pattern.
R..L..R..L.
L..R..L..R.

To clarify, if the pattern length is odd, we need to see the repeated, alternated pattern. If the length is even, we only need to see it once.
Hopefully that's clear enough:

The Rules

It's code golf, go for the shortest code.
Your code will accept one pattern, a positive integer higher than 1.
It will output some text describing a pattern diagram, as described above.
Any language you like.
Please include a link to an online interpreter.

Test cases
2
R.

3
R..
L..

4
R.R.

7
R..L.L.
L..R.R.

9
R..L..R..
L..R..L..

10
R..L..R.R.

19
R..L..R..L..R..L.L.
L..R..L..R..L..R.R.

22
R..L..R..L..R..L..R.R.

Retina 0.8.2, 66 bytes
.+
$*
1
RL
^(.+)RL\1$
$1R¶L$1
^(.+)\1$
$1
(.)(..?)(?!.\b)
$1$.2$*.

Try it online! Link includes test cases. Explanation:
.+
$*

Convert the input to unary.
1
RL

Alternate between hands.
^(.+)RL\1$
$1R¶L$1

If there are an odd number of beats then divide the output in the middle.
^(.+)\1$
$1

But if there are an even number of beats then just use one copy.
(.)(..?)(?!.\b)
$1$.2$*.

Try to match groups of three beats, but without leaving a lone beat at the end, and replace the offbeats with .s.

Jelly, 25 bytes
Ṗ;’m3Ṭ»¬€ḤÐe,N$ṫḂṚị“LR.”Y

A monadic Link accepting an integer greater than one which yields a list of characters.
Try it online!
How?
Ṗ;’m3Ṭ»¬€ḤÐe,N$ṫḂṚị“LR.”Y - Link: integer (>1), N     e.g. 13
Ṗ                         - popped range (N)               [1,2,3,4,5,6,7,8,9,10,11,12]
  ’                       - decrement (N)                  12
 ;                        - concatenate                    [1,2,3,4,5,6,7,8,9,10,11,12,12]
    3                     - literal three
   m                      - modulo slice                   [1,    4,    7,    10,      12]
     Ṭ                    - un-truth                       [1,0,0,1,0,0,1,0,0, 1, 0 ,1]
                          -                                     ...12th entry is a 1 ^
        €                 - for each of [1..N]:
       ¬                  -   logical NOT                  [0,0,0,0,0,0,0,0,0, 0, 0, 0, 0]
      »                   - maximum                        [1,0,0,1,0,0,1,0,0, 1, 0 ,1, 0]
          Ðe              - for entries at even indices:
         Ḥ                -   double                       [1,0,0,2,0,0,1,0,0, 2, 0, 2, 0]
              $           - last two links as a monad:
             N            -   negate                       [-1,0,0,-2,0,0,-1,0,0,-2,0,-2,0]
            ,             -   pair                         [[1,0,0,2,...],[-1,0,0,-2,...]]
                Ḃ         - modulo 2 (N)                   1
               ṫ          - tail from index                [[1,0,0,2,...],[-1,0,0,-2,...]]
                          -    ...Jelly indexing is 1-based & modular
                          -       so 0 would have resulted in [[-1,0,0,-2,...]]
                 Ṛ        - reverse                        [[-1,0,0,-2,...],[1,0,0,2,...]]
                          -    ...which for a list of length 1 is a no-op
                   “LR.”  - literal list of characters     ['L', 'R', '.']
                  ị       - index into (1-based & modular) ["R..L..R..L.L.","L..R..L..R.R."]
                        Y - join with newlines             "R..L..R..L.L.\nL..R..L..R.R."
                          -    ...which is just the entry for a list of length 1

05AB1E (legacy), 47 43 42 41 40 bytes
„RL×2äIÈ.£εÐ3äн€3sg3%i2TSǝR}£εćsg'.×«]J»

Not too happy with it..
Switched to the legacy version to save a byte (the legacy version replaces the values when using €, whereas the new version leaves them in the list: Try €3 in the legacy or try €3 in the new version).
-1 byte thanks to @Grimy.
Try it online or verify all test cases.
Explanation:
„RL×          # Repeat "RL" the (implicit) input-integer amount of times
    2ä        # Divide it into 2 equal halves
      IÈ      # Check if the input-integer is even (1 if truthy; 0 if falsey)
        .£    # And remove that many items
              # Some examples of what we now have:
              #  7 → ["RLRLRLR","LRLRLRL"]
              #  9 → ["RLRLRLRLR","LRLRLRLRL"]
              #  10 → ["RLRLRLRLRL"]
ε             # Map each string in this list to:
 Ð            #  Triplicate the string
  3ä          #  Divide the string into 3 equal parts
    н         #  And only leave the first one
     €3       #  And convert each value to a 3
              #  (basically a golf from my previous ceil(length/3) amount of 3s list)
 sg           #  Swap to take the string again, and get its length
   3%i     }  #  If this length modulo-3 is exactly 1:
      2TSǝ    #   Replace the first two items (at indices 0 and 1) with 2s
          R   #   And reverse it: [3,3,3,...,2,2]
 £            #  Split the string according to this list
              #  Some examples again:
              #   ["RLRLRLR","LRLRLRL"] → [["RLR","LR","LR"],["LRL","RL","RL"]]
              #   ["RLRLRLRLR","LRLRLRLRL"] → [["RLR","LRL","RLR"],["LRL","RLR","LRL"]]
              #   ["RLRLRLRLRL"] → [["RLR","LRLR","RL","RL"]
 ε            #  Then map each inner substring to:
  ć           #   Extract head; pop and push remainder and head
   sg         #   Swap to get the remainder, and get it's length (either 1 or 2)
     '.×     '#   Create a string with that many "."
        «     #   And merge it to the extracted head
]             # After both the inner and outer map:
 J            # Join each inner list together to a single string
  »           # And then join the strings by newlines
              # (after which the result is output implicitly)

I made another 05AB1E answer with a very different approach (still WIP).

JavaScript (ES6),  84 81 78  75 bytes
f=(n,x,N)=>n?'RL.'[!--n|N%3%(3-!~-n)?2:N&1^x]+f(n,x,-~N):N&!x?`
`+f(N,1):''

Try it online!
Commented
f = (               // f is a recursive function taking:
  n,                //   n = input
  x,                //   x = flag set to 1 if we're processing the 2nd row
  N                 //   N = counter incremented each time n is decremented
) =>                //
  n ?               // if n is not 0:
    'RL.'[          //   output the next character:
      !--n |        //     decrement n; if this is the last character
      N % 3 %       //     or N mod 3 is either
      (3 - !~-n) ?  //     odd if n = 1 or not equal to 0 otherwise:
        2           //       output '.'
      :             //     else:
        N & 1 ^ x   //       output either 'L' or 'R' depending on N and x
    ] +             //   end of character output
    f(n, x, -~N)    //   append the result of a recursive call with N+1
  :                 // else:
    N & !x ?        //   if x = 0 and N is odd:
      `\n` +        //     append a linefeed
      f(N, 1)       //     and restart with x = 1
    :               //   else:
      ''            //     stop recursion

Julia 1.0, 83 80 75 bytes
n->(f(r,s,h='R'-6s)=r∈0:2:4 ? "$h."^(r>>1) : "$h.."*f(r-3,1-s)).(n,0:n%2)

Try it online!

05AB1E, 28 27 26 25 bytes
Éƒ¶IÅœRΣP}θRv„LR¼¾èyG¼'.J

-1 byte thanks to Kevin Cruijssen
Try it online!
Explanation:
A signature subdivision can be seen as an integer partition. For example, #..#.#. is the partition [3, 2, 2] of 7.
A remarkable property of the subdivisions specified by this challenge is that
they maximize product. For example, 3*2*2 = 12, and no other partition of 7 has a product > 12 (only [3, 4] ties it). This can be proved true in the general case.
Éƒ                  # loop (input%2) + 1 times

¶                   # newline
 IÅœ                # integer partitions of the input
    R               # reverse, so that [2, 2, 3, ..., 3] comes after [3, ..., 3, 4]
     ΣP}            # sort by product (stable sort)
        θ           # take the last element
         R          # reverse it, so that the 2s are at the end

v                   # for each integer y in the partition
 „LR                # literal string "LR"
    ¼¾è             # increment counter_variable, then use it to index into "LR"
       yG           # loop y-1 times
         ¼          # increment counter_variable
          '.        # literal "."
            J       # join all the strings in the stack

Oh, I like the Åœʒ4‹P}θ! I thought about using partitioning with a filter on the length somehow, but couldn't get it to work. This is a lot better than that though. :) And nice approach in general!

27 bytes by joining and implicitly printing.

@KevinCruijssen since you liked Åœʒ4‹P}θ, you're gonna love ÅœRΣP}θ

Oh, you're indeed right, I love that one. Nice use of reversing and using the stable sort. :D Unfortunately I can't upvote again. But I just noticed you've posted the other answer for which I said you should post it yourself, so I've upvoted that one instead. ;)

source: Stack Exchange

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

sort: votes


text:
Self-Contained Generator Function (JavaScript)
Create a function that takes in a generator function as its only parameter, and returns an object that can be used as both as a generator and a generator function for said generator. The idea is to be able to create an object that behaves like a generator (that is, it follows the iteration protocols) but also has the ability to restart itself.
For the rules:

SelfGenerator is the function you're creating.
sg is the return value of SelfGenerator.
genFunc is the parameter passed into SelfGenerator.

Rules:

sg must have a start method that returns a generator that behaves the same as the generator that would be returned by genFunc.
sg.start must accept parameters that will be used to create the generator it returns such that it is the same as the generator returned by passing those parameters into genFunc.
After sg.start(...params) has been executed, if genFunc(...params)[prop] is callable, then sg[prop] is also callable and will return the same value.
sg.start(...params).next(value); let a = sg.next(); and sg.start(...params); sg.next(value); let a = sg.next(); must end up with the same value for a.
smallest source code wins

Example:
let sg = SelfGenerator(function*(n) {
    yield n;
    yield n + 1;
    yield n + 2;
});

sg.start(1);         // Generator
sg.next();           // {value: 1, done: false}
sg.next();           // {value: 2, done: false}
sg.start(10).next(); // {value: 10, done: false}
sg.next();           // {value: 11, done: false}

Welcome to the site! You have tagged this [tag:code-golf] and [tag:javascript] but you have not mentioned either of those things in the body of the question.  Is it meant to be code-golf?  Is this meant to be Javascript only?  Your question is also lacking on expectations for answers.  The sentence at the top is a good start and the test cases are helpful but this really needs a thorough explanation of what makes an answer valid or invalid.

I will also mention that in general challenges that restrict to a single language without good reason are not well received here.  A good reason is usually that the concepts at play in the challenge only fit well in and are clear the language and extending them to other languages tends to be vague or unclear.

@SriotchilismO'Zaic sorry, I thought they would be implied the code-golf and javascript would be implied, I'll incorporate your suggestions.

@SriotchilismO'Zaic Well I have no idea how this challenge would apply to other languages. I did it in JavaScript because accomplishing this in JavaScript specifically was a fun challenge and required decent knowledge of how js object behave.

@SriotchilismO'Zaic I would say that it's perfectly justified to place such a restriction here. Many languages don't even have a concept of functions, much less generators and objects, and trying to phrase this in a language-agnostic way would be next to impossible.

What does sg must also behave as a superset of the generator returned by sg.start mean?  Is this statement covered by the testcase?

@tsh I mean that if you wanted to treat sg as a generator and only use generator methods on it, it would behave exactly the same as the generator, but it also may have behaviour of its own outside the scope of a generator, e.g., the start method.
Edit: after you've called sg.start at least once.

Sorry I didn't catch your idea. Could you please add this required behavior to testcase? Should we invoke sg.next()? And what should be returned if so?

@tsh sg.start(...params).next() (just sg.next() if start has already been called) should return the same thing as argFunc(...params).next()

Should we only support the given code? Or should sg be a real generator? For example, should (function*(){}()).next.apply(sg) work?

@tsh No that needn't work, I have updated the rules to be more clear.

Let us continue this discussion in chat.

It's not clear to me how multiple invocations should behave: a generator function should allow the creation of independent generators, but what if the wrapped generator has side-effects?

@PeterTaylor I don't know what you mean, show me an example in the chat.

var n=0; function* gen() { while (true) yield n++; } var sg = SelfGenerator(gen); var it1 = sg.start(); it1.next(); var it2 = sg.start(); it2.next(); console.log(it1.next());

@PeterTaylor I don't care how it1 behaves after sg.start() has been called again. The point is to have an object that behaves like a generator but can reset itself.

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


text:
Does this Foo machine halt?
Determining whether a Turing machine halts is well known to be undecidable, but that's not necessarily true for simpler machines.
A Foo machine is a machine with a finite tape, where each cell on the tape has an integer or the halt symbol h, e.g.
2 h 1 -1
The instruction pointer starts by pointing to the first cell:
2 h 1 -1
^

At every step, the instruction pointer moves forward by the number it points to, then negates that number. So, after one step, it would move forward 2 cells, and turn the 2 into a -2:
-2 h 1 -1
     ^

The Foo machine keeps doing this until the instruction pointer is pointing to the halt symbol (h). So, here is the full execution of this program:
2 h 1 -1
^

-2 h 1 -1
     ^

-2 h -1 -1
         ^

-2 h -1 1
      ^

-2 h 1 1
   ^

The tape is also circular, so if the instruction pointer moves off of one side of the tape, it goes to the other side, e.g.:
3 h 1 3
^
-3 h 1 3
       ^
-3 h 1 -3
     ^
-3 h -1 -3
         ^
-3 h -1 3
 ^
3 h -1 3
  ^

One interesting thing about these Foo machines is that some do not halt, e.g.:
1 2 h 2
^
-1 2 h 2
   ^
-1 -2 h 2
        ^
-1 -2 h -2
    ^
-1 2 h -2
        ^
-1 2 h 2
   ^

This program will continue looping in those last four states forever.
So, write a program which determines if a Foo machine halts or not! You can use any (reasonable) input format you like for the Foo machines, and you can choose to use 0 as the halt symbol. You can use any two distinct outputs for the case where it does halt and the case where it doesn't. Your program must, of course, output an answer in a finite amount of time for all valid inputs.
This is code-golf, so try to make your program as short as possible!
Test cases
2 h 1 -1
Halts
3 h 1 3
Halts
h
Halts
1 1 1 1 h
Halts
2 1 3 2 1 2 h
Halts
3 2 1 1 4 h
Halts
1 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 h -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36
Halts

2 h
Does not halt
1 2 h 2
Does not halt
8 1 2 3 3 4 8 4 3 2 h
Does not halt
1 2 4 3 h 2 4 5 3
Does not halt
3 1 h 3 1 1
Does not halt
1 2 h 42
Does not halt

Just so I'm sure, about the algorithm to resolve this. I'm not that of an algorithm master so I prefer asking before going in the wrong direction. Will a non-halting Foo machine always get back to its exact original state? Or are there "chaotic-behaviored" non-halting machines?

@V.Courtois All non-halting Foo machines will end up in a loop of states, because there are only finitely many possible states a Foo machine can be in (there are n possible places the instruction pointer can be, and 2^n possible tape configurations). Each state has one and only one "next state". So, if a Foo machine ends up back in a state it's already been in, it'll just keep looping. Because there are only finitely many states, it can't keep chaotically jumping around between states because it'll end up eventually going to one it's already been in.

Okay, good to know. Thanks! I'll have to write an answer using this now. Or something else, I'm still thinking.

Oh no, if I do it like that I have to keep track of all the states (first non-halting test case) because it loops with a known position which is not the start position.

In the end, I still did it this way.

Suggested test case: 1 2 h 42 (does not halt)

Is there a maximum value for the step-size? Or can it (theoretically) be arbitrary large?

@KevinCruijssen The step size can be any integer (but you can ignore integer overflow).

Thanks @Arnauld you just broke my answer xD. Good thing I haven't published it yet.

Suggested test case: 3 2 1 1 4 h. This one halts but requires more iterations than twice the number of elements.

Suggested trivial test case 2 h, which does not halt.

Suggested extra-long test case: 1 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 h -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36, which halts after 786430 steps.

C# (Visual C# Interactive Compiler), 71 bytes
x=>{for(int i=0,k=0,f=x.Count;i++<1<<f;k%=f)k-=(x[k]*=-1)%f-f;i/=x[k];}

Try it online!
I don't know if the following is valid, since it requires a custom delegate with a signature of unsafe delegate System.Action<int> D(int* a);
 and has to be wrapped in an unsafe block to be used, but here it is anyways:
C# (.NET Core), 64 bytes
x=>f=>{for(int i=0,k=0;i++<1<<f;k%=f)k-=(x[k]*=-1)%f-f;k/=x[k];}

Try it online!
This function takes in an int* and returns a Action; in other words, it is a curried function. The only reason I use pointers is because of codegolf.meta.stackexchange.com/a/13262/84206, which allows me to save bytes by already having a variable already defined with the length of the array.
Saved 9 bytes thanks to @someone

Golfed your code by 2 bytes: https://tio.run/##fZBBS8UwDIDv@xVhIGyu021VeNh1HhRReAdvHh7vMEfLK3200HY6GPvts91kz5MNSZOPNE3S2byzYn7pVVe/7YV1tVCuQZ9anxtO54E2owcgaIGkV06HmyfdK0e4NgkRWVaXdc2JpInMh4M8Zjy94mnwrmleEsNcbxSEmNKCTDOJvloDjlkHFBT7PhzH1VaoQCXKywlFK8ALwFtcbF6JVrmQKmSiYKuF3v57tjLhz2orslueYy93aOcV/xa7ZAdWLPf9n8ZwaAUFG5qfSORXw9rulIRJJQi1jJuO8G78KhOZEvgwwrG9UCzhPoZHiF/bs7MxPED8rJkFpR2cPIpTv7Mf

@IQuick143 Nice catch, thanks

I'm not sure if there are any edge cases for which it won't work, but without breaking any of the current test cases you could replace 1<<f with 2*f to save a byte.

If what I say in my comment above is correct, 2 bytes can actually be saved like this: int k=0,f=x.Count,i=f;for(;i-->-f;

Fails for the suggested test case of Arnauld: 1 2 h 42. The +f in the +f)%f isn't larger enough to make the index positive in that case. Should probably be something like +max*f)%f, but will see if I can find something else to fix it.. My ported Java answer is deleted for now (my two golfs above still stand, though).

77 bytes with horrible LINQ magic and Arnauld's fix. I have no idea how does this solution work, so I may have broken it.

@Arnauld Ah nice, that's just 1 byte longer. :) Fixed it in my Java answer.

@someone The 1<< can be 2* in your version. PS: For an explanation of this method, see my ported Java answer. (I don't think you've broken it, so nice golf!)

71; I don't see why you need unsafe

@someone You need unsafe because you are dealing with pointers

63 bytes via a normal sane 1-byte golf and changing IO to error/no error. Link to link

@someone It seems I have been pretty rusty lately, missing these easy golfs; I really need to golf more!

Jelly, 15 11 bytes
N1¦ṙ⁸ḢƊÐLḢẸ

Try it online!
A monadic link that takes the input as a list of integers using 0 to mean halt. Returns 0 for halting inputs and 1 for those that don’t halt.
Avoids the issue of needing to work out number of iterations because of the use of ÐL which will loop until no new result seen.
Thanks to @JonathanAllan for saving a byte!
Explanation
      ƊÐL   | Loop the following as a monad until the result has been seen before:
N1¦         | - Negate the first element
   ṙ⁸       | - Rotate left by each of the elements
     Ḣ      | - Take just the result of rotating by the first element
         Ḣ  | Finally take the first element
          Ẹ | And check if non-zero

Save a byte by rotating by all the entries and then just keeping the first result: N1¦ṙ⁸ḢƊÐLḢẸ

Python 3, 63 89 bytes
def f(x):
 for i in range(2**len(x)):a=x[0];x[0]=-a;b=a%len(x);x=x[b:]+x[:b]
 return a==0

Try it online!
Also works for Python 2; a byte can be saved in Python 2 by replacing return with print and having the function print to stdout instead of returning. R turns True for halting and False for non-halting.
Thanks to @Neil and @Arnauld for noting that I needed to check longer for halting. Thanks to @Jitse for pointing out a problem with [2,0]. Thanks to @mypetlion for noting that the absolute of the tape values could exceed the tape length.

OK, I'll bite: how do you know x+x is enough?

@Neil It's actually not enough. A counter-example is [ 3, 2, 1, 1, 4, 0 ], which does halt in more than 12 iterations.

Wouldnt len(x)*x be sufficient?

Also, it doesn't seem to work for [2,0]

@Jitse len(x)*x would not work. For instance, [8,7,6,5,7,4,0,3,6] halts in more than $9^2$ iterations.

Isn't 2**len(x) still a bit short of the maximum? I calculate the number of states as n*(2**n) (with n=len(x)-1).

The machine 1 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 h -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 halts after 786430 steps.

@O.O.Balance I see what you mean, since each state can have a pointer in each cell... however, I feel likes there's some other limit applied by the fact that each cell can only possibllly transition to two other cells. As a side note: nothing in the challenge says there has to be a halting state in the input

More generally, if you take a machine of the shape 1, -1, -2, -3, ..., -(p-1)such that 2 is a primitive root modulo the prime p, and replace the middle cell with the halt command, then the resulting machine will require at least 2**((p-1)/2) steps to halt.

@Jitse Fixed at a cost of 2 bytes

This doesn't work for cases of a tape having a value that's larger than the length of the tape. [10,0,1,-1] should return True because it's functionally the same as [2,0,1,-1], but it returns False.

Python 3, 91 bytes
def f(a):
	s={0,};i=0
	while{(*a,)}-s:s|={(*a,)};a[i]*=-1;i-=a[i];i%=len(a)
	return a[i]==0

Try it online!
-40 bytes thanks to JoKing and Jitse

@JoKing 109 bytes by doing the variable assignments in the first line.

92 bytes by changing tuple conversion to starred expansion, not starting with an empty set and rephrasing the while condition.

@JoKing Damn, I never learn :p. 93 bytes then.

91 bytes

Perl 6, 46 43 36 bytes
{$_.=rotate(.[0]*=-1)xx 2**$_;!.[0]}

Try it online!
Represents halt by 0 and returns true if the machine halts. This repeats the logic 2**(length n) times, where if the pointer ends up on the halt cell, it stays there, otherwise it will be on a non-halt cell. This works because there are only 2**n possible states (ignoring halt cells) for the Foo machine to be in, since each non-halt cell has only two states. Okay yes, there are states than that, but due to the limited possible transitions between pointers (and therefore states) there will be less than 2**$_ states... I think
Explanation
{                                  }  # Anonymous codeblock
                     xx 2**$_         # Repeat 2**len(n) times
            .[0]*=-1                  # Negate the first element
 $_.=rotate(        )                 # Rotate the list by that value
                             ;!.[0]   # Return if the first element is 0

The state of the Foo machine also includes the location of the pointer, not just the signs of each cell.

Sketch of a proof for a Foo machine with tape a_1 ... a_n 0 . Consider an n-cube of the signs of each cell with directed edges (= an iteration of Foo) between vertices (= states), visiting the same vertex via any loop of edges will result in the IP being in the same position it started with. Proof: In a loop, the IP travels in each dimension an even number of times, ie the IP changes by k×(a_j + (-a_j)) % n ≡ 0 for each dimension, hence it always returns to the same position, only ever seeing 1 state out of n states for each vertex, ie a total max of 2^n states (= number of vertices of cube).

Just an empirical result, but brute-forcing the longest cycle among halting machines on a tape of length $n$ suggests that a tighter upper bound is $\lfloor2^n.log(n)/n\rceil$.

Java 8, 78 79 73 bytes
a->{int k=0,l=a.length,i=0;for(;i++<1<<l;k%=l)k-=(a[k]*=-1)%l-l;k/=a[k];}

Straight-forward port of @EmbodimentOfIgnorance's C# .NET answer, so make sure to upvote him!
Thanks to @Arnauld for finding two bugs (which also applies to some other answers).
Results in an java.lang.ArithmeticException: / by zero error when it's able to halt, or no error if not.
Try it online.
Explanation:
a->{                   // Method with integer-array as parameter and no return-type
  int k=0,             //  Index integer, starting at 0
      l=a.length,      //  The length `l` of the input-array
  i=0;for(;i++<1<<l;   //  Loop 2^length amount of times:
          k%=l)        //    After every iteration: take mod `l` of `k`
    k-=                //   Decrease `k` by:
       (a[k]*=-1)      //    Negate the value at index `k` first
                 %l    //    Then take modulo `l` of this
                   -l; //    And then subtract `l` from it
                       //  (NOTE: the modulo `l` and minus `l` are used for wrapping
                       //  and/or converting negative indices to positive ones
  k/=a[k];}            //  After the loop: divide `k` by the `k`'th value,
                       //  which will result in an division by 0 error if are halting

Just wondering, are you allowed to take the length as an additional argument? The default for IO post on meta doesn't say so, and the only reason my second answer takes a length is because it takes in a int*(from https://codegolf.meta.stackexchange.com/a/13262/84206)

@EmbodimentofIgnorance Ah, when I saw your answer I assumed there was some kind of of meta rule that allowed the length to be taken as additional input, but that only applies to pointers. Thanks for letting me know. I've removed the length parameter (but still use the error/no-error to determine the result).

05AB1E, 14 13 bytes
goFć©(š®._}®_

Try it online!
Takes the input as a list of integers with 0 as the halting instruction. Returns 1 for halting and 0 for not halting.
Thanks to @KevinCruijssen for saving 2 bytes!

Oh nice, so that's what your Jelly answer does! Great use of the rotate and ć! I was waiting for an explanation in the hope to golf my answer, but you beat me to it, haha. ;p -1 byte by doing the same golf as my answer though: g·F to «v (Try it online.)

And one additional -1 by using ©® instead of the DŠs: «vć©(š®._}®_ (Try it online.)

As Arnauld noted on your Python answer, looping two times the length isn't enough. So you can change the «v to goF.

@KevinCruijssen thanks

Haskell, 79 bytes
s x|m<-length x,let g(n:p)=(drop<>take)(mod n m)(-n:p)=iterate g x!!(2^m)!!0==0

Try it online!
Returns True for halting machines, and False otherwise.  Input in the form of a list, with 0 representing a halting state.
Assumes a version of GHC greater than 8.4 (released Feb 2018).

JavaScript (Node.js), 71 67 bytes
x=>{for(p=l=x.length,i=2**l;i--;)p+=l-(x[p%l]*=-1)%l;return!x[p%l]}

Basically the same as @EmbodimentOfIgnorance's C# .NET answer
4 byte save thanks to @Arnaud
Try it online!
JavaScript (Node.js), 61 bytes
x=>{for(p=l=x.length,i=2**l;i--;p+=l-(x[p%l]*=-1)%l)x[p%l].f}

This version uses undefined as a halting symbol and throws a TypeError: Cannot read property 'f' of undefined when the machine halts and terminates quietly when the machine doesn't halt.
Try it online!

Charcoal, 28 bytes
≔⁰ηＦＸ²Ｌθ«§≔θη±§θη≧⁻§θηη»¬§θη

Try it online! Link is to verbose version of code. Outputs using Charcoal's default Boolean output, which is - for true and nothing for false. Explanation:
≔⁰η

Initialise the instruction pointer.
ＦＸ²Ｌθ«

Loop as many times as there are theoretically possible states.
§≔θη±§θη

Negate the value at the instruction pointer.
≧⁻§θηη

Subtract the new value from the instruction pointer. Charcoal's array accesses are cyclic so this automatically emulates Foo's circular tape.
»¬§θη

At the end of the loop, output whether the program halted.

Perl 5 -ap, 88 bytes
for(;$F[$i]&&!$k{"$i|$F[$i]"};$i=($i+$F[$i])%@F){$k{"$i|$F[$i]"}=1;$F[$i]*=-1}$_=!$F[$i]

Try it online!

Pyth, 12 bytes
!hu.<+_hGtGh

Test suite!
Uses the straight-forward approach. Recurse until we see the list twice in an identical state. For programs that halt, the list will eventually have a leading 0 because that's where the recursion stops. For programs that don't halt, the list won't begin with the 0,  but rather be in a state from
which the process would be periodic and therefore the Foo machine wouldn't halt.

Attache, 40 bytes
Not@&N@Periodic[{On[0,`-,_]&Rotate!_@0}]

Try it online!
Explanation
{On[0,`-,_]&Rotate!_@0}

This performs a single iteration of the Foo machine; it negates the first member, then rotates the array by the (original, non-negated) first element of the array.
Periodic will apply this function until a duplicate result is accumulated. A machine either halts, or goes into a trivial infinite loop. If it halts, the first element will be 0. Otherwise, it will be non-zero.
&N is a golfy way of obtaining the first element of a numeric array. Then, Not returns true for 0 (halting machines) and false for anything else (non halting machines).

Scala, 156 bytes
Still golfable IMO, but I'm okay with it for now. Returns 0 for non-halting Foos and 1 for halting Foos. Takes the input in a as an Array[Int], so h is taken as 0.
var u=Seq[Array[Int]]()//Keep track of all states
var i=0//Index
while(u.forall(_.deep!=a.deep)){if(a(i)==0)return 1//Check if we are in a previously encountered step ; Halt
u:+=a.clone//Add current state in the tracker
var k=i//Stock temp index
i=(a(i)+i)%a.length//Move index to next step
if(i<0)i+=a.length//Modulus operator in Scala can return a negative value...
a(k)*=(-1)}//Change sign of last seen index
0//Returns 0 if we met a previous step

It is pretty long to run (around 4 seconds for all the test cases) because of the multiple full-array lookups I did, plus the .deep that create copies... But you can still try it online.

Stax, 11 bytes
Ç₧┬òE▐tµ|⌡1

Run and debug it
It takes input in the form of an integer array, with 0 representing halt.
It outputs 1 for a halting and 0 for a non-halting machine.


text:
Dropsort with a Twist
This is my first attempt at a Code Golf question.  If it needs obvious edits, please feel free to make them.
Below is a description of the basic Dropsort algorithm.

Dropsort is run on a list of numbers by examining the numbers in sequence, beginning with the second number in the list. If the number being examined is less than the number before it, drop it from the list. Otherwise, it is in sorted order, so keep it. Then move to the next number.
After a single pass of this algorithm, the list will only contain numbers that are at least as large as the previous number in the list. In other words, the list will be sorted!

For example, given a list of numbers 1,65,40,155,120,122, the 40,120,122 numbers will be dropped, leaving 1,65,155 in the sorted list.
Let's implement a new sorting algorithm called DropSortTwist.
This sort is identical to Dropsort except that a number (including the first number) that would be kept in Dropsort may optionally be dropped instead.  DropSortTwist must return (one of) the longest possible sorted list.
For example, using the same list of numbers as above, DropSortTwist must return either 1,65,120,122 or 1,40,120,122.  In both cases the 155 number is dropped to achieve a sorted list of length 4, one greater than the Dropsort list.
In this task, you will be given a list of integers as input (STDIN or function argument, you are required to support at least the range of 8-bit signed integers.)  You must return the longest possible increasing subsequence.
You may assume that the list is non-empty.
This is code golf, so the shortest program wins.
Test Cases
input                    output
1 65 40 155 120 122      1 65 120 122  [or]  1 40 120 122
5 1 2 2 3 4              1 2 2 3 4

Welcome to the site!  If I understood this correctly you want the Longest increasing subsequence?  While the motivations for the challenge are nice it would be best if you could describe the task without relying on users to follow to other links.

@SriotchilismO'Zaic:  Thank you!  I have tried to clarify the question and reduce the links.

Probable dupe, but it is an older question with a different output format (length of subsequence) and some restrictions on time

@Joking:  Good find!  I agree that it is a dupe.  Is it preferred that I delete my question, or just wait and let it get marked as a duplicate?

@James It is preferred if you let it get marked duplicate.

I disagree that this is a dupe. The timing restriction is very significant. I'd expect all serious answers to this question to fail the timing requirements of the older one (my answer sure does).

Agreed, I do not think this is a dupe of that dupe target since that one restricts the input domain to [1,999] and implements a "must execute this (1000 entry test case) in a 'timely manner'" restriction, making competitive answers unlikely to be transferable in either direction.

I also disagree that it's a dupe. Returning the length of the sequence vs returning the sequence is a bit different problem.

@SriotchilismO'Zaic As per the comments above, this is not a dupe. I have a 6-byte answer that works here that would be invalid for the linked question

@NickKennedy Fair enough.  I have gone ahead and reopened it.  I had pretty much ignored the time restriction since it was vague enough I figured it wasn't really a restriction, but it seems that that is not how other people see it.  Thanks.

May we return more than one subsequence?

Jelly, 6 bytes
ŒPṢƑƇṪ

Try it online!
How?
Pretty much the same approach as Grimy's 05AB1E entry
ŒPṢƑƇṪ - Link: list of integers
ŒP     - power-set (all subsequences, from shortest to longest)
    Ƈ  - filter keep those which are:
   Ƒ   -   invariant when:
  Ṣ    -     sorted
     Ṫ - tail

05AB1E, 8 bytes
æʒD{Q}éθ

Try it online!
æ           # list of subsequences
 ʒD{Q}      # filter, keep only the sorted subsequences
      é     # sort by length
       θ    # get the last (longest) one

Japt -h, 9 bytes
à ñÊf_eZñ

Try it

Python 2, 89 83 bytes
f=lambda A:A>sorted(A)and max([f(A[:i]+A[i+1:])for i in range(len(A))],key=len)or A

Try it online!

Stax, 9 bytes
éÑ<┬Θ╡Lφ0

Run and debug it
Naive approach: powerset, filter for sorted, sort on length, get tail.

Ruby, 63 bytes
->a{s=a.size;s-=1until r=a.combination(s).find{|e|e==e.sort};r}

Try it online!
->a{                                    # Anonymous Proc taking array input
    s=a.size;                           # Get array size

        until                           # Loop until the following condition is non-nil:
              r=a.combination(s)        #   Get all subsequences with length s
                    .find{|e|e==e.sort} #   Find a subsequence that is sorted, else nil
    s-=1                                # Reduce s by 1

    r                                   # Implicit return the found subsequence
}

Wolfram Language (Mathematica), 37 bytes
Select[Reverse@Subsets@#,OrderedQ,1]&

Try it online!
The elements of Subsets[ ] are ordered from shortest to longest, so reversing it puts longer subsets first. Then, select the first one which is ordered.


text:
Write an interpreter for *
The task is simple. Write an interpreter for the language *.
Here's a bigger link to the wiki.
There are only three valid * programs:

* Prints "Hello World"
 *  Prints a random number between 0 and 2,147,483,647
*+* Runs forever.

The third case must be an infinite loop according to the specifications in this question
Input:

The input can be taken via any acceptable input method by our standard I/O rules
It will always be one of the above programs

Output:

The first case should print exactly Hello World, with or without a trailing line break.
For the second case, if your language's integer maximum is smaller than 2,147,483,647, use your language's integer maximum
The first and second cases can print to any acceptable output by our standard I/O rules.
The third case should not give any output.

Scoring:
As this is code-golf, the shortest answer, in bytes, wins.

When you say 'between 0 and 2,147,483,647', is that inclusive or exclusive? (E.g., is 0 a valid output?)

@Chas the linked wiki has interpreters in Java & JS which include 0.

For the random number generation, can the program output whitespace in addition to the number?

Changing the spec after posting a challenge and invalidating existing solutions is an automatic -1 from me.

For languages that don't have a built-in way of generating a random number, is there an acceptable way to satisfy the "print a random number" requirement?

If our language's integers have no, or a higher, maximum may we use a higher upper bound?

@JonathanAllan No, you may not.

@Shaggy I'm not seeing any rule changes in the wiki for the question, only a space to a non-breaking space (check the markdown tab), because the SE markdown renderer wasn't rendering it, but looking at the original revisision, it's clear it should be normal spaces, and the "hack' is only done for SE markdown renderer issues

*, 0 bytes

Since * has no way of reading input, the default rules allow specifying that the input must be given by concatenating it onto the program.
(... I think. There's an "at least twice as many upvotes as downvotes" condition that I don't have the rep to verify).

Your linked meta is indeed a currently accepted site standard (+31 -7).

@A__: It looks to me like it must have been designed specifically to satisfy someone's proposed definition of 'programming language' ("You can write hello world!" "You can write an infinite loop!" "You can write a program that doesn't always do the same thing!").

I believe that technically Malbolge is not a programming language either then.

Malbolge is programming language for finite automata, the same as *, and, for example, Befunge-93.
Therefore Malbolge is formal programming language, the same as *, technically the same as recursively enumerable languages when it comes to programming language definition (albeit formal languages are less powerful).

Downvote from me, because honestly, this answer is so boring it's actually already a Standard Loophole, even if we ignore the question whether * is a programming language

I added the same exact answer, because searching for * to see if someone else had already done it was too hard (181 results), haha! You know, just in case anyone doesn't believe you that this indeed works, you can always add a TIO link :p Here's one!

R, 69 bytes
switch(scan(,""),"*"="Hello, World!"," * "=sample(2^31,1)-1,repeat{})

Try it online!
switch tries to match the named arguments and if there's no match, selects the first unnamed one after the first, which in this case is the infinite loop repeat{}.

Jelly,  21  20 bytes
ḊOSØ%HX’¤“½,⁾ẇṭ»¹Ḃ¿?

A monadic Link accepting a list of characters.
Try it online!
vL’... also works (see below).
How?
ḊOSØ%HX’¤“½,⁾ẇṭ»¹Ḃ¿? - Link: list of characters   e.g.: "*"        or  " * "    or  "*+*"
Ḋ                    - dequeue                          ""             "* "         "+*"
 O                   - to ordinals                      []             [42,32]      [43,42]
  S                  - sum                              0              74           85
                   ? - if...
                  ¿  - ...if-condition: while...
                 Ḃ   -    ...while-condition: modulo 2  0              0            1
                ¹    -    ...while-true-do: identity                                85
                     -                                  0              74           (looping)
        ¤            - ...then: nilad followed by link(s) as a nilad:
   Ø%                -    literal 2^32                                 2^32
     H               -    half                                         2^31
      X              -    random integer in [1,n]                      RND[1,2^31]
       ’             -    decrement                                    RND[0,2^31)
         “½,⁾ẇṭ»     - ...else: dictionary words        "Hello World"

Alternative
vL’... - Link: list of characters                 e.g.: "*"        or  " * "    or  "*+*"
 L     - length                                         1              3            3
v      - evaluate (left) as Jelly code with input (right)
       -                                                1^1            3^3          (3^3+3)^3
       -                                                1              27           27000
  ’    - decrement                                      0              26           26999
   ... - continue as above                              "Hello World"  RND[0,2^31)  (looping)

C (gcc), 66 63 bytes
Thanks to attinat for the -3 bytes.
I only have to check the second character: if the LSB is set, it's a + (thus the program is "*+*") and the program loops. After that, if it's a NUL, the program was "*" and we display Hello World; otherwise, it displays a random value (" * ", the only other option left.)
f(char*s){for(s++;*s&1;);printf(*s?"%d":"Hello World",rand());}

Try it online!

63 bytes

Shave a byte: f(char*s){*++s&1?f(s-1):printf(*s?"%d":"Hello World",rand());}

Pedantic note: rand is not guaranteed to return a sufficiently large value; RAND_MAX and INT_MAX are not guaranteed to be the same (and are not on real world compilers, e.g. Visual Studio's RAND_MAX is 32767, while INT_MAX is [on modern x86 derived systems] the 2147483647 value specified in the OP's question).

@ShadowRanger that is completely true, but considering that >90% of all C-based CGCC entries rely on undefined and unspecified behaviour I'm not worried about that! I also didn't feel like implementing a code-golfed LCG today. :-)

Keg, -lp, -ir 30 26 25 24 20 19 bytes
!1=[_“H%c¡“| =[~.|{

-1 byte using flags
Try it online!
Answer History
?!1=[_“H%c¡“| =[~.|{

Try it online!
Shortened Hello World to dictionary string
!1=[_Hello World| =[~.|{

Try it online!
I never ceased to be amazed at the power of Keg. Credits to user EdgyNerd for another byte saved.
Prior Versions
_!0=[Hello World|\*=[~.|{

Try it online!
Credit to user A__ for the extra byte saved.
Old version
?!1=[_Hello World| =[__~|{

Essentially, takes the input program and:

Checks to see if the input length is 1, printing "Hello World" if true
Checks to see if the last character is a space, and prints a random number
Otherwise runs an infinite loop

Then implicitly print the stack.
?                               #Get input from the user
 !1=                            #Compare the stack's length to 1
    [_Hello World           #Push "Hello, World!" to the stack
                     | =        #See if top item is a space
                        [__~|{  #If so, generate a random number, otherwise, infinite loop.

4 bytes saved due to the fact that hello world doesnt need punctuation.
Try it online! Old version
Try it online! New version

You can cut off 4 bytes, you don't need the comma or exclamation mark in "Hello World".

Now I have to learn another unpopular language in order to answer challenges here normally.

-1 bytes: TIO. I am glad that I did not lose my ability to golf in Keg.

@A__ Enjoying Keg being on TIO?

The Keg rule: no Keg answer can reach >3 votes.

Wow, was just about to try and do a Keg answer, but you beat me to it, +1

@A__ too true! Hopefully this one is an exception to that rule!

@EdgyNerd go ahead, I'd like to see how other people approach this problem!

24 bytes :)

@EdgyNerd Next stop 23 bytes!

Amazing! You beat Jelly by 1 byte! (Keg is winning here :) )

Python 2, 103 93 89 87 bytes
I combined my earlier answer with Chas Browns's answer and got something a few bytes shorter.
The random number will be between 0 and 2**31-1 inclusive.
from random import*
i=input()
while'*'<i:1
print["Hello World",randrange(2**31)][i<'!']

Try it online!
Previous versions:
103 bytes
from random import*
exec['print"Hello World"','while 1:1','print randint(0,2**31-1)'][cmp(input(),'*')]

93 bytes
from random import*
i=cmp(input(),'*')
while i>0:1
print["Hello World",randint(0,2**31-1)][i]

Save 2 bytes by replacing randint(0,2**31-1) with randrange(2**31).

while'*'<i saves 2

Save another byte by changing randrange(2**31) to getrandbits(31) (the latter returns long, not int, but print will print the str form, not the repr form, so the trailing L won't be there).

Relatively inexperienced with site, so quick clarification: Are you allowed to require your input to be quoted? i=input() only works if the inputs are quoted, if you just input plain */ * /*+*, it would die with a SyntaxError (because input includes an implicit eval); you'd need to input '*'/' * '/'*+*' (or equivalent with double-quotes instead). I didn't see anything obvious on the standard I/O rules that would allow this, which might mean you'd need to use raw_input(), costing four bytes.

@ShadowRanger input() takes a string as input and evaluates it. I'm not really adding to the input, I'm merely taking a string as input, and strings have quotes. This is pretty standard, in the same way that I can take an array like [1,2,3] instead of as a delimited string that I then have to split and parse. The goal of the site is not to make input strict, it's to make I/O easy so we can focus code on the challenge at hand.

Late, but you can save 25 bytes by removing the import and using id(i)%2**31

@famous1622 I don't think that's uniformly random.

@mbomb007 doesn't have to be uniformly random, as it's still a random number between 0 and 2**31-1 which fits the challenge description

@famous1622 https://codegolf.meta.stackexchange.com/a/1325/34718

Japt, 22/25 bytes
The first solution is for the original spec which had *<space> as the second programme and the other is for the updated spec which arbitrarily changed it to <space>*</space>, with thanks to EoI for the suggested "fix".
Both throw an overflow error upon entering the infinite loop of the third programme but, theoretically, with enough memory (which we may assume for the purposes of code-golf), would run forever.
Å?¢?ß:2pHÉ ö:`HÁM Wld

Try programme 1Try programme 2Try programme 3
Å?UÎ>S?ß:2pHÉ ö:`HÁM Wld

Try programme 1Try programme 2Try programme 3

I think the second program is "[SPACE][SPACE]", not "[SPACE]", so your program doesn't work

@EmbodimentofIgnorance, at the time I posted, the second programme in the spec was *<space>. Don't have time to update now.

You can fix it in three bytes with UÌ>S instead of ¢ on the second ternary

@Downvoter, please have the courtesy to leave a comment.

PowerShell, 60, 56 bytes
switch($args){*{'Hello World'}' * '{random}*+*{for(){}}}

Pretty dumb version, the only golfing technique here is omitting Get- in Get-Random.
UPD. Stripped down to 56 bytes by removing quotes, thanks to veskah!

Try it online! (Hello World)
Try it online! (random number)
Try it online! (infinite loop)

56 stripping out the quotes

JavaScript (ES7), 66 bytes
s=>s[1]?s<'!'?Math.random()*2**31|0:eval(`for(;;);`):'Hello World'

Try it online! (Hello World)
Try it online! (random number)
Try it online! (infinite loop)

Would x=(z=>x())&&x() not work for -1byte from the infinite loop code, assuming a browser with no max call stack size?

@GezaKerecsenyi We could just call ourself (like this) but I'm not sure that would be acceptable.

that's fair. I wonder if there is some obscure browser out there that just keeps going (at least, until RAM runs out)

@Arnauld, theoretically, that would run forever given infinite memory, which we may assume for code golf.

Python 2, 91 89 88 bytes
from random import*
def f(p):
 while'*'<p:p
 print['Hello World',getrandbits(31)][p<'!']

Try it online!
2 bytes thanks to Jonathan Allan; 1 byte thx to ShadowRanger.

while'*'<p saves 2

getrandbits(31) saves a byte over randrange(2**31).

Nice! Didn't know about getrandbits...

Jelly, 23 21 bytes
OS¹Ḃ¿ịØ%HX’;““½,⁾ẇṭ»¤

Try it online!
A monadic link taking a single argument and returning Hello World, a random 31 bit integer or looping infinitely as per the spec.
All options: *  *  *+*
Explanation
O                     | Convert to codepoints
 S                    | Sum
  ¹Ḃ¿                 | Loop the identity function while odd
     ị              ¤ | Index into the following as a nilad:
      Ø%              | - 2 ** 32
        H             | - Halved
         X            | - Random integer in the range 1..2**31
          ’           | - Decrease by 1
           ;          | - Concatenated to:
            ““½,⁾ẇṭ»  |   - "", "Hello World"

Befunge-93, 54 bytes
~"*"-_~1+#^_"dlroW olleH">:#,_@.%*2**:*::*88:*`0:?1#+<

Try it online!
Annotated:
~"*"-                      _                ~1+                   #^_        "dlroW olleH">:#,_    @      .%*2**:*::*88:   *`0:             ?1#+<
Compare first      If equal, go right       Compare second       If equal,        Output          Exit    Modulo by 2^31   If less than      Add 1
character to       Otherwise, go left       character to       loop forever   "Hello World"                 and output     0, multiply     a random amount
'*'                and wrap around          -1 (EOF)                                                                         by 0            of times

The randomness is not uniform. At each increment there is a 50% chance to stop incrementing.

///, 72 bytes
/+*/+*// */a random number between 0 and 0//*/"Hello World"/

Try it online!
Here I go again, adding another cheating entry. Was I really going write my own pseudo-random generator just for this though... and in ///?!
Instead, I interpreted the Print instruction very literally, as a good minion should. Everything after Print is outputted:

* Prints "Hello World"

* → "Hello World", yes, even with the quotation marks. Otherwise, I'd admit to being aware of the quotation-marks-denote-literal-string convention, which wasn't explicitly stated in the question, and doesn't exist in the language with which I'm submitting. And then I wouldn't be able to cheat with the "Print a random number" part. So, I'm feigning ignorance... Shhh, don't tell!

 *  Prints a random number between 0 and 2,147,483,647

* → a random number between 0 and 0. Lucky for me, although they didn't add the whole non-deterministic, different-number-every-time shtick in the rules, they did say "if our language's integer maximum is smaller than 2,147,483,647" we can use our language's "integer maximum" instead, so I did... There are no integer types in ///, only strings. So the integer maximum is 0, sort of... Well, it shaves off a few bytes!

*+* Runs Forever

*+* → . There's no Print instruction in this one so I can interpret it like a normal human. Replacing a pattern with itself (or another string containing itself), is the standard way to loop forever, and it's as succinct as it gets!

Note
To golf it a bit, /// looks for +* &  * rather than the whole thing. This works just as well. For the infinite loop, nothing ever prints because the replacing never stops, so you'll never find out that it's prepending an infinitely long list of * to the beginning every time it replaces. As for printing 'a random number,' we just don't replace one of the spaces, leaving a trailing space at the end of the output. Luckily, this hurts no one and is not noticeable. Plus, how's an ignoramus like me to know how many of the trailing spaces at the end of the Print instruction, until the margin, were on purpose :p

Sorry, this question seems to have provoked a mischievous mood from me today!

Java (JDK), 83 bytes
s->{for(s=s.intern();s=="*+*";);return"*"==s?"Hello World":(-1>>>1)*Math.random();}

Try it online!

PHP, 51 bytes
for(;'*'<$l=$argn[1];);echo$l?rand():'Hello World';

Try it online! (Hello World)
Try it online! (Random Number)
Try it online! (Infinite Loop)
Takes second character of input which can be '', '*' or '+'. In case of '+' the '*'<'+' will be true and the loop will be infinite, else, after the loop, "Hello World" or a random number is shown. The rand() automatically outputs a number between 0 and getrandmax() which uses defined RAND_MAX in standard C library and by default is 2147483647 on most platforms/environments, including TIO.

APL (Dyalog Unicode), 39 bytesSBCS
Anonymous prefix lambda.
{'+'∊⍵:∇⍵⋄' '∊⍵:⌊2E31×?0⋄'Hello World'}

Try it online!
{ "dfn"; ⍵ is the argument:
 '+'∊⍵: if plus is a member of the argument:
  ∇⍵ tail recurse on argument
 ' '∊⍵ if space is a member of the argument:
  ?0 random float (0–1)
  2E31× scale to (0–2³¹)
  ⌊ floor
 'Hello World' else return the string

05AB1E, 21 bytes
'*KgDi[ë<ižIL<Ωë”Ÿ™‚ï

Try it online. (NOTE: The random buildin is pretty slow with big lists, so it might take awhile before the result is given.)
Explanation:
'*K           '# Remove all "*" from the (implicit) input
   g           # Get the length of what's remain (either 0, 1, or 2)
    D          # Duplicate this length
     i         # If the length is exactly 1:
      [        #  Start an infinite loop
     ë<i       # Else-if the length is 2:
        žI     #  Push builtin 2147483648
          L    #  Create a list in the range [1,2147483648]
           <   #  Decrease each by 1 to make the range [0,2147483647]
            Ω  #  Pop and push a random value from the list
               #  (after which the top of the stack is output implicitly as result)
     ë         # Else:
      ”Ÿ™‚ï    #  Push dictionary string "Hello World"
               #  (after which the top of the stack is output implicitly as result)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ”Ÿ™‚ï is "Hello World".

Brachylog, 26 23 bytes
l₃∈&hṢ∧2^₃₁-₁ṙw∨Ḥ⊇ᶠ³⁶tw

Try it online!
Takes the program as a string through the input variable, and ignores the output variable. Heavily exploits the guarantee that the input is only ever one of the three valid programs: any length-three input will behave like either " * " or "*+*" depending on whether or not the first character is a space, and any other input will behave like "*".
l₃                         The input has length 3
  ∈                        and is an element of something,
   &h                      and the input's first element
     Ṣ                     is a space
  ∈                        (if not, try some other thing it's an element of),
      ∧2^₃₁-₁              so take 2,147,483,647 and
             ṙw            print a random number between 0 and it inclusive.
               ∨           If the input's length isn't 3,
                Ḥ⊇ᶠ³⁶tw    print the 36th subsequence of "Hello, World!".

Oops, wrong "Hello World"--fixing now

Perl 5 -p, 43 39 bytes
$_=/ /?0|rand~0:/\+/?redo:"Hello World"

Try it online!

C# (Visual C# Interactive Compiler), 71 bytes
s=>{for(;s=="*+*";);return"*"==s?"Hello World":new Random().Next()+"";}

Try it online!

Ruby -n, 47 bytes
puts~/ /?rand(1<<31):~/\+/?loop{}:"Hello World"

Try it online!

Wolfram Language (Mathematica), 65 bytes
#/.{"*"->"Hello World"," * "->RandomInteger[2^31-1],_:>0~Do~∞}&

Try it online!

Pyth, 32 bytes
It/Jw\*#;?tlJOhC*4\ÿ"Hello World

Try it online!
Explanation (Python-ish)
I                                   # if
  /Jw\*                             #    (J:=input()).count("*"))
 t                                  #                             - 1:
       #;                           #     try: while True: pass;except: break;
         ?                          # if (ternary)
           lJ                       #    len(J):
             O                      #     randInt(0,                    )
               C                    #                int(     , 256)
                *4\ÿ                #                    4*"ÿ"
              h                     #                                + 1
                    "Hello World    # else: (implicitly) print "Hello World"

This prints a number between 0 and 2^32, not 0 and 2^31. A shorter way to write hC*4\ÿ is ^2 32, but in order for the solution to be correct, you should use ^2 31 instead. Also, use z instead of Jw, saves 1 more byte. And your explanation skips the line with t right before lJ.

Also, you can detect the "loop forever" command by checking whether the input contains any + character, saves 1 byte because you don't need to decrement it.

JavaScript, 62 Bytes, no infinite recursive
s=>s[1]?eval("while(s>'!');Math.random()*2**31"):'Hello World'

JavaScript (V8), 79 bytes
-2 bytes thanks VFDan
s=>eval([`"Hello World"`,`Math.random()*2**31|0`,`for(;;);`][s.lastIndexOf`*`])

Try it online!

You can shave off two bytes by turning s.lastIndexOf('*') into s.lastIndexOf\*``

Pip, 39 35 bytes
IaQ'*P"Hello World"EIsQ@aPRRmE{T0a}

Try it online!
Simple if else based program, prints random integer between 0 and 1000.

Vyxal, 16 bytes
×=[kh|tð=[k×ʀ℅|{

Try it Online! The 5 flag is just so that you don't have to wait as long for it to timeout. Even at the default 60 second timeout, this times out on  * , but you can see that it works by replacing k× with a smaller number.
Currently, this beats all other answers.
Explanation:
                  # Implicit input
×=[               # If input = "*":
   kh             #   Push "Hello World"
     |tð=[        # Else if last character of input = " ":
          k×      #   Push 2147483648
            ʀ     #   Range [0, 2147483648]
             ℅    #   Random integer from range
              |   #     Else:
               {  #       While True:  (Infinite loop)
                  # Implicit output

You can save two bytes in comparisons

Add++, 78 bytes
z:"Hello World"
`y
xR2147483647
x:?
a:"*"
b:" * "
c:"*+*"
Ix=a,Oz
Ix=b,O
Wx=c,

Try it online!
Explanation
z:"Hello World"	; Set z = "Hello World"
`y		; Set y as the active variable
xR2147483647	; Set y to a random number between 0 and 2147483647
x:?		; Set x to the input
a:"*"		; Set a = "*"
b:" * "		; Set b = " * "
c:"*+*"		; Set c = "*+*"
Ix=a,		; If x == a then...
	Oz	;	...output z
Ix=b,		; If x == b then...
	O	;	...output y
Wx=c,		; While x == c then...
		;	...do nothing

Charcoal, 30 bytes
Ｗ№θ*Ｆ⁼θ*≔Hello Worldθ∨θＩ‽Ｘ²¦³¹

Try it online! Link is to verbose version of code. Abuses Charcoal's default input format which splits on spaces if there is only one line, thus the random number input actually looks like three inputs. Explanation:
Ｗ№θ*

Repeat while the first input contains a *.
Ｆ⁼θ*

If the first input is a * only...
≔Hello Worldθ

... then replace it with Hello World, thus causing the loop to terminate. *+* doesn't get replaced, resulting in an infinite loop.
∨θ

If the first input is not empty then output it.
Ｉ‽Ｘ²¦³¹

But if it is empty then output a random integer in the desired range.

Commodore BASIC (VIC-20, C64, TheC64Mini etc) - 170 tokenize BASIC bytes
 0a%=32767:goS9:b$=leF(b$,len(b$)-1):ifb$="*"tH?"hello world
 1ifb$=" * "tH?int(rN(ti)*a%)
 2ifb$="*+*"tHfOi=.to1:i=.:nE
 3end
 9b$="":fOi=.to1:geta$:i=-(a$=cH(13)):b$=b$+a$:?a$;:nE:reT

I think to do this more accurately, I'll have to delve into the weird world of 6502 assembly language, but this is a first draft.
First point, the INPUT keyword in Commodore BASIC ignores white spaces, so the sub-routine at line 9 is a quick-and-dirty way to accept keyboard entries including spaces.
Second point, Commodore BASIC integers have a range of 16-bit signed, so -32768 to +32767 source - so I've kept the random number generated to 0 - 32767 inclusive

Wren, 143 135 bytes
I am not a good golfer... The RNG generates the same value each time because it is a pseudo-random number generator.
Fn.new{|a|
import"random"for Random
if(a=="*+*"){
while(1){}
}else System.write(a[0]==" "?Random.new(9).int((1<<31)-1):"Hello World")
}

Try it online!

Kotlin, 78 bytes
{print(if(it<"*")(0..2147483647).random()else{while(it>"*"){}
"Hello World"})}

Try it online!

VBScript, 147 bytes
Sub m(s)
randomize:i=0
if s="*" then msgbox "Hello World"
if s=" * " then msgbox int(2147483647*Rnd)
if s="*+*" then
do
loop while 1
end if
end sub

Crystal, 75 bytes
puts case gets;when"*";"Hello World"when/\+/;loop{}else;rand 2147483647;end

Try it online!

05AB1E, 21 bytes
['*›_#}gi„Ÿ™‚ï™ëžIL<Ω

Try it online!  *  times out on TIO as the code generates the list [1, 2, 3, ..., 2147483648], subtracts 1 from each element, and picks a random element from the list. This is required as the only sources of randomness in 05AB1E are Ω/.R (random pick) and .r (random shuffle), but no pure RNGs.
['*›_#}gi„Ÿ™‚ï™ëžIL<Ω  # full program
     #                 # break out of...
[                      # infinite loop...
     #                 # if...
                       # implicit input...
   ›                   # does...
    _                  # not...
   ›                   # come after...
 '*                    # literal...
   ›                   # in lexicographical order
      }                # end infinite loop
        i              # if...
       g               # length of...
                       # implicit input...
        i              # is 1...
         „Ÿ™‚ï         # then push "hello world"...
              ™        # in title case
               ë       # else...
                    Ω  # pick a random element from...
                  L    # [1, 2, 3, ...,
                žI     # ..., 2147483648]...
                       # (implicit) with each element...
                   <   # decremented
                       # implicit output


text:
Bucket interpreter
Create a program that interprets the programming language Bucket.
Bucket works on two buckets: the first can hold A and the second can hold B units of liquid. The things you can do with these buckets are:
f: fill bucket A
F: fill bucket B
e: empty bucket A
E: empty bucket B
p: pour units of liquid from A to B until one is empty or the other is full, whichever happens first
P: same as the command p, but from B to A
o: output the value of bucket A
O: output the value of bucket B
These examples assume A is less than or equal to B in the tuple (A,B), which is the main tuple determining which variant of the language is to be interpreted. A is the lesser-or-equal value of a bucket here and B is the larger-or-equal value: substitute as you need.
Your program should ask for 3 inputs:

the element A in the tuple (A,B):
the element B in (A,B):
the program to interpret.

The tuple (A,B) determines which variant of the language Bucket is interpreted.
As a general rule, make sure the first two inputs can range from 0 to 2,147,483,647.
Any characters in the third input other than fFeEpPoO do not need to be handled. Assume no characters other than these will be in the source.
Any commands equal to pouring more liquid in any bucket than it can hold do not need to be handled.
Assume the program will never try to pour liquid from an empty bucket.
This is code golf, so the shortest solution wins.
Any programs made before I changed the specifications to be correct are now non-competing.

Thank you very much for requesting implementations of my language! (Although USACO invented it before me)

Oh, in the Bucket spec, pouring more liquid in any bucket than it can hold should output nothing.

Link because the link in the challenge was deleted and there is no description of Bucket.

No problem, A__. I found out about the language today and I thought I'd try it. Surprisingly, it's a good idea.

pouring more liquid in any bucket than it can hold should cause no error -> may we also assume that the program will never try to pour liquid from an empty bucket?

Assume the program will never try to pour liquid from an empty bucket. If this happens, still no error output. - the second sentence is redundant, if we may assume no such input.

@Arnauld When you try to pour liquid from an empty bucket, it already fullfills part of the condition "until the former is empty or the latter is full (whichever one happens first)" in the esolangs.org spec. So, the pouring stops.

@A__ The thing is that challenges should be self-contained.

Some test cases would be nice.

I've VTC as unclear until Roman's point has been explicitly addressed (as an answer has already been posted implementing Bucket's p and P)... I understand that, as it is, the self-contained post is actually clear, but think the point is worth addressing that much that it'd be nice to stop answers coming in in the interim.

I corrected it. Any answers made in the interim period where my spec was wrong are no longer competing.

Close vote retracted.

Stax, 50 bytes
╖z≈]Y`Zîú¬♣↑e█■X▲håR⌐├~@»3é±óè♂╓_§8F|╢╖r╥ë$%6Æ▲¡↓!

Run and debug it
Unpacked and ungolfed it looks like this.  You can nearly see some kind of structure in it even if you don't know stax.  It loops over the program, and dispatches to a block based on the index of the instruction in the literal "fFeEpPo".  Capital O gives an index of -1.
sYdZZF
  "fFeEpPo"I
  {xs}
  {dy}
  {Z}
  {d0}
  {+cyG}
  {+cxGs}
  {nP}
  {Q}
  8l@!
}tc~-,

Wolfram Language (Mathematica), 212 170 166 164 159 157 155 153 bytes
A_~J~B_=Fold[Switch[{a,b}=#;#2,3,Echo@a;#,4,#+Min[a,B-b]z,5|6,{#2A-5A,b},7,Echo@b;#,8,#-Min[b,A-a]z,_,{a,#2B-9B}]&,z={-1,1};0z,ToCharacterCode@#~Mod~12]&

Try it online!
Calling J[A,B] returns an interpreter for the (A,B)-bucket system, which can be applied to a program with J[A,B]["prog"]. The "o" and "O" commands print using Echo, and the return value of the program is the final bucket state.
The program is a big Switch statement folded over the character codes (modulo 12) of the program, step-wise updating the contents of the buckets. Dispatching the Switch takes a shortcut by defaulting to E|F (9|10), as the spec says that there are no characters to be expected other than "fFeEpPoO".
Debugging is done by replacing Fold with FoldList, so that the return value of the program becomes the sequence of bucket states traversed during program execution. Un-golfed version:
J[A_,B_][prog_] :=
  FoldList[                (* debug version                                             *)
    Switch[{a,b}=#;        (* initialize a and b to the current bucket contents         *)
           #2,             (* switch as a function of the next character in the program *)
      "f", {A,b},          (* f: fill first bucket, leave second bucket unchanged       *)
      "F", {a,B},          (* F: fill second bucket, leave first bucket unchanged       *)
      "e", {0,b},          (* e: empty first bucket, leave second bucket unchanged      *)
      "E", {a,0},          (* E: empty second bucket, leave first bucket unchanged      *)
      "p", {a,b}+{-1,1}*Min[a,B-b],  (* p: pour first bucket into second bucket         *)
      "P", {a,b}+{1,-1}*Min[b,A-a],  (* P: pour second bucket into first bucket         *)
      "o", Echo@a;{a,b},   (* o: print contents of first bucket                         *)
      "O", Echo@b;{a,b}]&, (* O: print contents of second bucket                        *)
    {0,0},                 (* start with both buckets empty                             *)
    Characters[prog]]      (* fold over the characters in the program string            *)

Try it online!

Perl 5, 194 bytes
$x='if(e>$B-E){e-=$B-E;E=$B}l{E+=e;e=0}';$y=y/eEAB/EeBA/r;($A,$B,$_)=<>;s/[^fepo]//gi;s/e/$&=0;/gi;s/o/say$&|0;/gi;s/F/O=$B;/g;s/f/o=$A;/g;s/p/$x/g;s/P/$y/g;s'e|o'$a'g;s'E|O'$b'g;s/l/else/g;eval

Try it online!

Changed it to match.

JavaScript (Node.js), 129 bytes
Takes input as ([b, a])(code) where code is a string. Returns an array of output values.
B=>c=>Buffer(c).map(h=j=>(i=j>>5&1,k=j&3)?k>2?o.push(b[i]):b[i]=~-k*B[i]:b[i]&&b[k=i^1]<B[k]&&h(j,b[i]--,b[k]++),b=[0,0],o=[])&&o

Try it online!
Commented
B => c =>                 // B = [b, a]; c = code string
  Buffer(c)               // turn c into a buffer
  .map(h = j =>           // for each ASCII code j:
    ( i = j >> 5 & 1,     //   i = 1 for lower case, 0 for upper case
      k = j & 3           //   k = 0 for 'p', 1 for 'e', 2 for 'f', 3 for 'o'
    ) ?                   //   if k is not 0:
      k > 2 ?             //     if k = 3:
        o.push(b[i])      //       push b[i] in o[]
      :                   //     else:
        b[i] = ~-k * B[i] //       set b[i] to B[i] if k = 2, or 0 if k = 1
    :                     //   else (k = 0):
      b[i] &&             //     if b[i] is not empty
      b[k = i ^ 1] < B[k] //     and the other bucket b[k] is not full:
      && h(               //       do recursive calls
        j,                //       to pour as much as possible,
        b[i]--,           //       decrementing b[i]
        b[k]++            //       and incrementing b[k] at each iteration
      ),                  //
    b = [0, 0],           //   start with b = [0, 0]
    o = []                //   and initialize o[] to an empty array
  ) && o                  // end of map(); return o[]

Charcoal, 66 bytes
ＮθＮηＦ⁺eEＳ≡ιf≔θζF≔ηεe≔⁰ζE≔⁰εpＦ∧ζ‹εη«≦⊖ζ≦⊕ε»PＦ∧η‹ζθ«≦⊖ε≦⊕ζ»o⟦Ｉζ⟧O⟦Ｉε

Try it online! Link is to verbose version of code. Implements the variant of Bucket specified in the question. For the original version, the Ｆs can be changed to Ｗs for the same byte count:
ＮθＮηＦ⁺eEＳ≡ιf≔θζF≔ηεe≔⁰ζE≔⁰εpＷ∧ζ‹εη«≦⊖ζ≦⊕ε»PＷ∧η‹ζθ«≦⊖ε≦⊕ζ»o⟦Ｉζ⟧O⟦Ｉε

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

Input the sizes of the buckets.
Ｆ⁺eEＳ

Loop over the commands, but prepend eE so that the buckets are in a known state.
≡ι

Switch over the current command.
f≔θζ

If f then fill the first bucket.
F≔ηε

If F then fill the second bucket.
e≔⁰ζ

If e then empty the first bucket.
E≔⁰ε

If E then empty the second bucket.
pＷ∧ζ‹εη«≦⊖ζ≦⊕ε»

If p then pour a unit from the first bucket to the second until the first becomes empty or the second becomes full. (Interestingly this seems to be the golfiest way to express the concept in Charcoal.)
PＷ∧η‹ζθ«≦⊖ε≦⊕ζ»

If P then pour a unit from the second bucket to the first until the second becomes empty or the first becomes full.
o⟦Ｉζ⟧

If o then output the first bucket on its own line.
O⟦Ｉε

If O then output the second bucket on its own line. (The ⟧ is implicit, as is the skipping of unrecognised characters in the input.)

@JonathanAllan Well, I guess I can change the while (bool) into a for (bool) for the same byte count.

Retina 0.8.2, 184 bytes
\d+
$*1,
[^FfEePpOo](?=.*$)

{`(1+),1*¶((.+¶)f|F)
$1,$1¶$3
,1*¶((.+¶)e|E)
,¶$2
(1?)(¶\1(1*)1*,\3)¶p
$2$1¶
^((1*)(1?)1*,\2)(¶1+,1*)\3¶P
$1$3$4¶
}s`,(1*)(¶(.+¶)o|¶O)(.*)
,$1$3¶$4¶$.1
3A`

Try it online! Implements the variant of Bucket specified in the question. For the original version, the ?s can be changed to *s for the same byte count:
\d+
$*1,
[^FfEePpOo](?=.*$)

{`(1+),1*¶((.+¶)f|F)
$1,$1¶$3
,1*¶((.+¶)e|E)
,¶$2
(1*)(¶\1(1*)1*,\3)¶p
$2$1¶
^((1*)(1*)1*,\2)(¶1+,1*)\3¶P
$1$3$4¶
}s`,(1*)(¶(.+¶)o|¶O)(.*)
,$1$3¶$4¶$.1
3A`

Try it online! Explanation:
\d+
$*1,

Convert the sizes to unary and add separators to provide space for the current values.
[^FfEePpOo](?=.*$)

Delete unrecognised commands.
{`
}

Loop over the commands.
(1+),1*¶(F|(.+¶)f)
$1,$1¶$3

For f or F, fill the appropriate bucket by copying its size.
,1*¶((.+¶)e|E)
,¶$2

For e or E, empty the appropriate bucket.
(1*)(¶\1(1*)1*,\3)¶p
$2$1¶

For p, pour from the first bucket to the second, taking care not to overflow it. $1 = amount to pour, $3 = amount already in second bucket.
^((1*)(1*)1*,\2)(¶1+,1*)\3¶P
$1$3$4¶

For P, pour from the second bucket to the first, taking care not to overflow it. $2 = amount already in first bucket, $3 = amount to pour.
}s`,(1*)(¶(.+¶)o|¶O)(.*)
,$1$3¶$4¶$.1

For o or O, convert the appropriate bucket to decimal and append it to the end.
3A`

Delete the input at the end of the loop.

Python 2, 194 152 bytes
def f(A,B,s,a=0,b=0):
 while s:c='fFeEoOpP'.find(s[0]);W='a,b,A,B=b,a,B,A;'*c;exec W+['a=A','a=0','print a','v=min(a,B-b);a-=v;b+=v'][c/2]+';'+W;s=s[1:]

Try it online!
c is even when the command deals with the A bucket (feop) and odd when it deals with the B bucket (FEOP). So W creates a string which, when exec'd, swaps the roles of A and B either an even number of times (i.e., no effect), or an odd number of times (same as a single swap).
This allows the code to only list the commands once instead of twice - if needed, we swap A and B then execute the A based command, and then swap again if needed, to get both A and B functionalities.