text:
Partitioning Digits into Distinct Integers
Given a sequence of base-10 digits, output the longest list of integers that contains all the digits exactly once, in the order in which they appeared in the input, without repeating any integers.
Examples
Input: 12345
Output: [1, 2, 3, 4, 5]

Input: 12123
Output: [1, 2, 12, 3]

Input: 10010
Output: [100, 1, 0]

Input: 35353
Output: [35, 3, 53] or [3, 5, 353]

Input: 988382
Output: [9, 88, 3, 8, 2]

Rules

Use any convenient formats for input and output
You must support input sequences of up to 10,000 digits long.
You must support integers of 18 decimal digits or more (This will fit in 64-bit integers, though you may want work with strings anyway)
You may assume that the input given can be made into a sequences where the 18-digit number requirement is possible.
If there is more than one possible longest sequence, you may output any one of them.
Numbers in the output sequence may not be zero-padded.
Zero is a valid element, but it can, of course, only be used once in the output.
There is no time or complexity requirement.
Shortest code wins.

I made a small edit to clarify the challenge a little bit, roll back if you don't agree!

Another interesting example would be 10010.

Suggested test case: 988382 -> [ 9, 88, 3, 8, 2 ].

Is 0 zero padded, or Is that detail up to us?

"You must support digit streams of up to ten thousand digits long" I think a long test case in order.

Also, what is the time limit for long test cases?

@JoKing how do you manage to get negative numbers from a stream of digits? I guess zero is of particular concern though.

You must support digit streams of up to ten thousand digits long: Did you mean digit streams of up to ten thousands? (i.e. 5 digits long)

One final question: Assuming you did mean 10k digits completing in something like 30-60 seconds -- do you know for certain there is an efficient algorithm that enables this?

@Jonah The purpose of the ten thousand digit requirement is just to emphasize the need for a complete algorithm rather than a fast one - similar to the "must work for arbitrarily long inputs" without actually requiring arbitrarily long inputs. Putting bounds on the problem opens the door to certain kinds of amusing solutions, such as circuits.

@Jonah - no complexity or time requirements since I suspect this problem might not be in P

Suggested test cases:
1001000 → [ 10, 0, 1000 ] ...and:
100100010 → [100, 1000, 1, 0]

Is [12, 1, 2, 3] an acceptable output for 12123?

@cairdcoinheringaahing Yes. ("If there is more than one possible longest sequence, you may output any one of them.")

Jelly, 14 bytes
ŒṖḌD$ƑƇḌQƑƇLÞṪ

Try it online!
A monadic link taking a list of base-10 digits and returning a list of integers.
Added a byte (and switched to numbers) because of the zero padding issue.
Added 5 bytes to fix a further issue with zeros pointed out by @KevinCruijssen - thanks!
Explanation
ŒṖ             | Partitions of list
  ḌD$ƑƇ        | Keep only those invariant when converted to integers and back to lists of digits
       Ḍ       | Convert from lists of lists of lists of decimal digits to lists of lists of integers
        QƑƇ    | Keep only those invariant when uniquified
           LÞ  | Sort by ascending length
             Ṫ | Tail

Just like my now deleted 05AB1E answer it fails for 10010010. It uses partition [100,10,01,0] and the 01 becomes 1.

@KevinCruijssen fixed I think

Ah, smart! I could do something similar to fix my 05AB1E answer. :D EDIT: I'll leave my answer deleted, since Grimmy already posted the fixed answer (as I said he could when I deleted my answer).

Perl 6, 49 bytes
{m:ex/(0|<![0]>.+)+<!{$0>set ~<<$0}>/.max(+*[0])}

Try it online!
Outputs a regex match with a list of submatches as the integers.
Explanation:
{                                               }  # Anonymous code block
 m:ex/                              /    # Match all
      (          )+                        # Series of
       0|                                  # Zero or
         <![0]>.+                          # Numbers not starting with zero
                   <!{$0          }>     # Where the series is not
                        >set ~<<$0       # Larger than the set of itself
                                     .max(+*[0])   # Return the maximum by length of series

05AB1E, 10 bytes
.œʒÙïJQ}éθ

Try it online!

Ah, I see you've already posted. In that case I'll leave my answer deleted. Was about to add the ï to it to fix both my programs after the tip of NickKennedy.

Ruby, 115 112 114 bytes
Takes input as a string. A recursive function that takes a string and a list of previously-used numbers; it gets all substrings that start with the first character, and for each gets the result of the recursive call on the rest of the string. It then decides what the longest string that still matches is.
f=->s,*e{(1..l=s.size).map{|i|*q=x=s[0,i];q-e==[]||x=~/^0./?[]:q+f[s[i,l],*q+e]}.max_by{|i|s==i*''?i.size: 0}||[]}

Try it online!

Shouldn't 1001000 return 10,0,1000? Your return 100,1000.

@KjetilS. you are right. Fixing

JavaScript (ES6), 100 bytes
Takes input as a string.
f=([v,...a],p=o=[],c='')=>(v&&f(a,p,c+v),c?p.includes(c)|[+c]!=c||f(a,[...p,c],v):p[o.length]?o=p:o)

Try it online!
Commented
f = (                    // f is a recursive function taking:
  [v,                    //   v   = next digit
     ...a],              //   a[] = array of remaining digits
  p = o = [],            //   p[] = current list, o[] = best list
  c = ''                 //   c   = current pattern
) => (                   //
  v &&                   // if v is defined:
    f(a, p, c + v),      //   do a recursive call with c + v
  c ?                    // if c is not empty:
    p.includes(c) |      //   unless p[] already includes c
    [+c] != c ||         //   or c has leading zeros:
      f(a, [...p, c], v) //     do a recursive call with c appended to p[]
  :                      // else:
    p[o.length] ? o = p  //   update o[] to p[] if p[] is longer than o[]
                : o      //   or just return o[] unchanged otherwise
)                        //

Perl 5, 119 bytes
sub f{($s=$_=shift)=~/\b(\d+)\b.*\b\1\b/?push@_,grep!/\b0\d/,map$s=~s/^((.*?,){$_}.*?),/$1/r,0..y/,//:return$s while@_}

Try it online!
sub f {
  ($s=$_=shift)                               #get next trial
    =~ /\b(\d+)\b.*\b\1\b/                    #duplicate exist in trial?
    ? push @_,                                #if so, add trials
           grep !/\b0\d/,                     #without zero-leading
           map $s=~s/^((.*?,){$_}.*?),/$1/r,  #remove nth comma
           0 .. y/,//                         #that many trials (-1)
    : return $s                               #answer = 1st w.o. duplicate
        while @_                              #while trials left
}

Passes:
12345     → 1,2,3,4,5
12123     → 12,1,2,3
10010     → 100,1,0
35353     → 353,5,3
988382    → 9,88,3,8,2
1001000   → 10,0,1000
100100010 → 100,1000,1,0

Burlesque, 24 bytes
PppPsu5cb{++pP==}f[:U_[~

Try it online!
Not necessarily the best method, think I could probably save on some loading.
Pp    #Save number (as str) for later use
pP    #Load number
su    #Find all substrings of number
5cb   #Find all combinations of substrings of length 5 (as list of list of str)
{
 ++   #Concatenate all strings
 pP   #Load number
 ==   #Is equal
}f[   #Filter for all substring combinations where
       the concatenation is the same as original number
:U_   #Filter for all elements unique
[~    #Take the last one

Charcoal, 55 bytes
⊞υ⟦ωＳ⟧Ｆυ«≔⊟ιθＦＬθＦ∧Ｉ§θκ¬№ι…θκ⊞υ⁺ι⟦…θκ✂θκ⟧⊞ιθ»⊟Φυ⁼Ｌι⌈ＥυＬλ

Try it online! Link is to verbose version of code. Outputs each integer preceded by a newline. Explanation:
⊞υ⟦ωＳ⟧Ｆυ«

Perform a breadth-first search starting from the input and having only seen the empty string before.
≔⊟ιθ

Temporarily separate the current suffix from the list of previously seen integers.
ＦＬθ

Loop over the potential new suffixes. (The next integer is then the current suffix with the new suffix removed.)
Ｆ∧Ｉ§θκ¬№ι…θκ

Check that the new suffix does not begin with zero and the next integer has not already been seen.
⊞υ⁺ι⟦…θκ✂θκ⟧

If so then create a new entry including the next integer and the new suffix.
⊞ιθ»

Restore the suffix for the entry in case no suffixes were valid.
⊟Φυ⁼Ｌι⌈ＥυＬλ

Print the last entry of those with the longest length.

@Jonah Optimising for code golf tends to result in inefficient algorithms. I'm sure it could do long streams given sufficient resources. As for your sidenode, I try to code in verbose mode, but that's not always possible e.g. a cat program whose reverse is a reversal program.

PHP, 380 338 287 279 bytes
<?php $s=array_fill(0,$n=strlen($u=$argv[1]),0);$m=[];g:if(array_sum($s)==$n){$b=[];$p=0;$k=1;foreach($s as$c){$c&&($b[]=substr($u,$p,$c))[0]==0&&$c>1&&$k=0;$p+=$c;}if($k&&array_unique($b)==$b&&$b>$m)$m=$b;}for($i=0;;){if(++$s[$i]<=$n)goto g;$s[$i++]=0;$i==$n&&die(print_r($m));}

Try it online!
Ungolfed
<?php
$input= $argv[1];

$len=strlen($input);
$counts=array_fill(0,$len,0); // enumerator - basically a counter to base input-length, where each digit represents substring length
$max=0;
$max_sub=[];
do {
    // add up size of all substring lengths
    $size=0;
    for($i=0;$i<$len;$i++) {
        $size+=$counts[$i];
    }

    // size matches string length
    if ($size==$len){
        $subs=[];
        $pos=0;

        // get the substrings and ensure constraints
        $ok=true;
        for ($i=0;$i<$len;$i++) {
            //exclude zero length substrings
            if ($counts[$i]>0) {
                $sub = $subs[] = substr($input, $pos, $counts[$i]);
                if ($sub[0]=='0' && $counts[$i]>1) {
                    $ok=false;
                    break;
                }
                $pos+=$counts[$i];
            }
        }

        // makes sure no repeated substrings
        for($i=0;$i<count($subs);$i++){
            for($j=0;$j<$i;$j++){
                if($subs[$i]==$subs[$j]) {
                    $ok=false;
                    break(2);
                }
            }
        }

        // if all ok, then check this has maximal number of substrings
        if ($ok) {
            if (count($subs)>$max) {
                $max=count($subs);
                $max_sub=$subs;
            }
        }
    }

    // increment counter
    for($i=0;$i<$len;$i++) {
        $counts[$i]++;
        if ($counts[$i]<=$len) {
            break;
        }
        $counts[$i]=0;
    }

// counter hasn't reached the end
} while ($i<$len);

echo json_encode($max_sub);


text:
Partial tq interpreter
In this task you are expected to provide a list output given an input tq program. The tq programs will not contain whitespace inside them.
What is tq, in the first place?
tq is a lazy-evaluated language that is designed with the idea that array items should be accessable during the definition of them. In tq, there is no explicit separator of an array, only special arrangements of monadic/dyadic functions and nilads.
The following program is a program printing [123] (Pretend that tq doesn't support strings because we aren't dealing with them in this case):
123

This defines a list with the first item being the number 123, after which all items in the list will be outputted inside a list.
In tq, numbers are supported to allow multiple-digits. So this defines a list with 2 items:
12+12,5

In this test case, you are expected to output the list [24,5]. Let's explain it step by step.
12+12   # This evaluates 12 + 12 in the current item in the list, returning 24
     ,  # A separator. This separates two items when they could be potentially
        # ambiguous when they are applied without a separator.
      5 # This evaluates 5 in the current item in the list, returning 5
        # The comma is simply a no-op that doesn't require parsing.

So you think that tq is not hard at all to implement? Well, remember that tq also has a special feature of accessing the items in an array before the array is defined!
555th123

We introduce two new atoms:

t (tail) means access the last item in the list
h (head) means access the first item in the list

Therefore our list is going to yield:
[555,123,555,123]

Now take a look at this program:
555ps123

We introduce 2 more atoms:

p Yield the next item before (previous) the current position
s Yield the next item after (succeeding)the current position

This yields the list:
[555,555,123,123]

A quick reference of the tq language
Just assume that you only have two operands for the operators.

[0-9] starts a number. Numbers will only be positive integers, i.e. no decimals and negative numbers.
, This is a separator of different items when it is given that two consecutive indexes will be ambiguous with each other without a separator. In tq all of the remaining characters can act as a separator, but in this case it is a good idea to implement only , for the ease of your implementation.
+ and * These are arithmetic operators. Usually in tq, they may be applied multiple times, e.g. 1+2+3, but in your implementation, input will be provided so that this will not happen and only 1+2 will happen (there will not be applications multiple times).
t return the last item in the list. If the code is t1,2,3 it shall return [3,1,2,3].
h return the first item in the list. If the code is 1,2,3h it shall return [1,2,3,1].
p returns the item before the current item. If the code is 0,1,p,3,4 the code shall return [0,1,1,3,4].
s returns the item after the current item. If the code is 0,1,s,3,4 the code shall return [0,1,3,3,4].

Additional rules (with some examples)

You also have to implement multiple hops. E.g. 1th should yield [1,1,1]
If you know that something is going to form a loop, e.g. 1sp2, the cells that form the loop should be removed. Therefore the previous example will yield [1,2].
Out of bounds indexing will yield the closest index of the indexed item that is a number. E.g. 1,2s should yield [1,2,2]
If any possible indexing fails, you may do whatever operation you prefer.

More test cases

4p*p will yield [4,16]
1p+s2 will yield [1,3,2]
1,2,3h+t4,5,6 will yield [1,2,3,7,4,5,6]
3ppss6 will yield [3,3,3,6,6,6]

Is an expression such as t+3 possible?

Also, is an expression such as 3+t possible?

Jelly, 131 bytes
+Ø+o+2$};;1N;Ø½“spth+*”żF
ṣ”,µeþØD,Øa¤Ḥ2¦SSƝ>2k)Ẏµe€⁾+*oḊ$k)µJç€LyⱮ"ƲVḢf?€€ØDAƑƇ.ị;@Ʋµṙ-+;×ɗị@ƭ/$¹L’$?¹Nị⁸¹L’$?ɗAƑ?€AƑ?F¥€`ÐLAƑƇFṖṖ

Try it online!
A full program taking a tq program string as its input and returning a list of integers. Still needs more golfing, but seems to work ok. Doesn’t use eval except for converting numbers from string to integer (which wouldn’t be an eval in most languages).

Python 3, 536 522 bytes
def f(c):
 D={"t":"o[n]","h":"o[0]","p":"o[i-1]","s":"o[i+1]"};o=[];T="";A=o.append;l=type;n=-1
 for C in c:
  if C==",":A(T);T=""
  elif C in"0123456789":
   if"o"in T:
    A(T);T=C
   else:T+=C
  elif C in"htps":
   if T and T[n]in"+*":T+=D[C]
   else:
    if T:A(T)
    T=D[C]
  else:
   T+=C
 if T:A(T)
 if D['s']in o[n]:o[n]=o[n].replace("i+1","i-1")
 while not all([l(m)==int for m in o]):
  for i in range(len(o)):
   x=o[i]
   try:x=eval(str(o[i]))
   except:pass
   if l(x)is str:continue
   else:o[i]=x
 return o

Try it online!
Ungolfed:
def tq(code):
    corresp = {"t":"output[-1]","h":"output[0]","p":"output[i-1]","s":"output[i+1]"}
    output = []
    temp = ""
    for char in code:
        if char == ",":
            output.append(temp)
            temp = ""

        elif char in "0123456789":
            if "h" in temp or "t" in temp or "p" in temp or "s" in temp:
                output.append(temp)
                temp = char
            else:
                temp += char

        elif char in "htps":
            if temp and temp[-1] in "+*":
                temp += corresp[char]
            else:
                if temp:
                    output.append(temp)
                temp = corresp[char]

        else:
            temp += char
    if temp:
        output.append(temp)
    if 'output[i+1]' in output[-1]:
        output[-1] = output[-1].replace("i+1","i-1")
    while not all([type(m) == int for m in output]):
        for i in range(len(output)):
            x = output[i]
            try: x = eval(str(output[i]))
            except: pass
            if type(x) is str:
                continue
            else:
                output[i] = x
    return output

Somehow, by fixing a bug, I was able to remove 14 bytes. I've well and truly broken code golf now.
Anyhow, this takes the program, parses it into evalable chunks and then
evals them.

True, but then it would be a longer answer.

Fails on t5p*p

Seems to fail on t2p*2

JavaScript (ES6),  269 263  262 bytes
v=>(F=r=>r+''==(h=(i,d)=>r[i]?1/r[i]?i:h(i+d,d):h,L=r.length-1,r=r.map((s,i)=>1/(x=eval((s+'').replace(/[h-t]/g,c=>` +r[${c<'i'?0:c>'s'?L:c>F?++i<L?i:h(L,-1):i?i-1:h(0,1)}]`)))?x:s))?r.filter(x=>1/x):F(r))(v.split(/,|((?:\d+|.)(?:[+*](?:\d+|.))?)/).filter(v=>v))

Try it online!
Test cases borrowed from Nick's answer.
How?
We first split the input into tokens with the following regular expression:
+---------------------------> either a comma (discarded)
|                             or the following group (captured):
|        +------------------>   1st operand:
|        |                        a number or a single non-numeric character
|        |                      which may be followed by:
|        |       +---------->     an operator
|        |       |       +-->     and a 2nd operand
|     ___|_    __|_   ___|_
,|((?:\d+|.)(?:[+*](?:\d+|.))?)

Example:
"12,3p*4h" --> [ '12', undefined, '3', 'p*4', 'h' ]

Empty or undefined elements are removed with filter(v => v).
The result is passed to the main function \$F\$ which recursively attempts to replace expressions with numeric values until no further modification is possible.
F = r =>                             // F is a function taking a list of tokens r[]
  r + '' == (                        // test whether r[] is modified by this iteration
    h = (i, d) =>                    // h is a function taking i = position, d = direction
      r[i] ?                         //   if r[i] is defined:
        1 / r[i] ? i                 //     if r[i] is numeric, return i
                 : h(i + d, d)       //     otherwise, add d to i and try again
      :                              //   else:
        h,                           //     return a non-numeric value
      L = r.length - 1,              // L = index of last element in r[]
      r = r.map((s, i) =>            // for each element s at position i in r[]:
        1 / (                        //
          x = eval((s + '').replace( //   evaluate s
            /[h-t]/g,                //   where letters are replaced with
            c => ` +r[${             //   " +r[index]" where the index is:
              c < 'i' ? 0 :          //     'h' -> 0
              c > 's' ? L :          //     't' -> L
              c > F ?                //     's' ->
                ++i < L ? i          //       i + 1 if this is not the last item
                        : h(L, -1)   //       or the first preceding number
              :                      //     'p' ->
                i ? i - 1            //       i - 1 if this is not the first item
                  : h(0, 1)          //       or the first following number
            }]`))                    //
        ) ? x : s                    //   yield x if it's numeric or s otherwise
      )                              // end of map()
  ) ?                                // if r[] is unchanged:
    r.filter(x => 1 / x)             //   return it with non-numeric items removed
  :                                  // else:
    F(r)                             //   do a recursive call

APL(Dyalog Unicode), 174 bytes SBCS
a←('t'⎕R'a[≢a]')¨('h'⎕R'a[1]')¨','(≠⊆⊢)'[^,\d]([+×][^,\d]){0,1}'⎕R',&,'⊢⎕
a←{'s'⎕R(x,'+1]')⊢'p'⎕R((x←'a[',⍕⊃⌽⍵),'-1]')⊢⊃⍵}¨↓a,⍪⍳≢a
t/⍨(⊢≢⍕)¨t←⊃¨{a⊢←{0::⍵⋄⍎⍕∘⍎⍣(≢a)⊢⍵}¨a⋄a}⍣≡a

Try it on APLgolf!
A tradfn submission which takes a string from STDIN.

source: Stack Exchange

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

sort: votes


text:
Generate a Nine-Ball Pool rack
Introduction
Nine-Ball is a popular pool game played casually and as a competitive sport.
There is one of each numbered ball, with the numbers 1 to 9.
The game starts with all 9 of the balls in a diamond shaped rack, like so:
  1
 2 3
4 9 6
 5 7
  8

The 1 ball is always at the front of the diamond, and the 9 ball is always in the middle, with all the other balls placed randomly (the "X"s in this diagram):
  1
 X X
X 9 X
 X X
  X

Challenge
Your challenge, given no input, is to generate and output random 9-ball pool racks in the text format of the examples. Extra surrounding whitespace is allowed.
Output may be through any convenient method, standard loopholes apply. A new rack MUST be generated on each run, you cannot just produce a single randomly-chosen rack every time. Extra surrounding whitespace is allowed.
Example Outputs
  1
 2 3
4 9 5
 6 7
  8

  1
 8 3
2 9 7
 4 6
  5

  1
 2 8
3 9 7
 5 4
  6

Least bytes per language wins.

Since there are 7! combinations, strictly you don't mean "A new rack MUST be generated on each run", merely "you cannot just produce a single randomly-chosen rack every time."

Should all possible outputs have nonzero probability? Or should they all be equally likely?

@smci yeah, that was what I meant.

@LuisMendo Doesn't really matter? Not sure honestly

@nihilazo It does matter. You need to specify what you allow. Otherwise people can for example pick between two possible outputs at random. Right now you only say it can't be just one output

Okay let's require that the code be capable of generating all of the 7! possible results. (I don't see how requiring them to be equiprobable makes things harder, but someone might think of something)

I've been playing nine-ball casually for decades, and I've never seen anyone rack it in any order but the "right" one (your first example output). So while I now know they don't have be done that way, I doubt I'm going to throw them in any other order now :)

R, 61 bytes
cat(paste0(c("  1
 ","","
","9 ","
 ","","
  "),sample(2:8)))

Try it online!
Prints alternately the proper whitespace/newline (with 1 and 9 included) and elements of a random permutation of \$\{2,\ldots,8\}\$.

Python 3, 91 87 bytes
from random import*
print("  1\n %d %d\n%d 9 %d\n %d %d\n%3d"%(*sample(range(2,9),7),))

Try it online!
-4 bytes thanks to xnor (final \n  %d -> \n%3d and tuple(...) -> (*...,))

You can save a few bytes using a justified string format and using tuple unpacking: https://tio.run/##K6gsycjPM/7/P60oP1ehKDEvBUhl5hbkF5VocRUUZeaVaCgpKBjG5CmopgBRTB6QsgQz4ALGKUqqGlrFibkFOakaQBPSUzWMdCw1dcw1dTQ1//8HAA

Very nice, thanks. That tuple() call was really bothering me so this makes me happy.

Bash or any Bourne Shell, with modern coreutils, 54 52 bytes
printf '  1
 %s %s
%s 9 %s
 %s %s
  %s' `shuf -i2-8`

Try it online!
-2 bytes thanks to @dzaima (use shuf -i option for an implicit seq)
Originally:

printf '  1
 %s %s
%s 9 %s
 %s %s
  %s' `seq 2 8|shuf`

Try it online!
I saved one byte by not including a newline at the end of the source, and another by not including one at the end of the output.
Explanation:
seq 2 8 outputs 2 3 4 5 6 7 8 on separate lines.
|shuf randomly reorders them.  (This is what needs modern coreutils.)
printf <formatstring> <args> does a C-like printf of the arguments with the format string.

JavaScript (ES6), 89 bytes
_=>`  1
 X X
X 9 X
 X X
  X`.replace(/X/g,g=_=>m^(m|=1<<(i=Math.random()*9|0))?i:g(),m=3)

Try it online!
How?
We replace each "X" in the template with a random integer \$0\le i<9\$ such that the \$i\$-th bit in the bitmask \$m\$ is not already set, and we simultaneously update \$m\$.
We start with \$m=3_{10}=000000011_2\$ so that \$0\$ and \$1\$ are never chosen.

Charcoal, 27 25 bytes
Ｆ⁷⊞υ‽⁻Ｅ⁷⁺²κυ↖⪪⁺⪫⪪⪫υω⁴9¦1³

Try it online! Link is to verbose version of code. Explanation:
Ｆ⁷

Loop 7 times.
⊞υ‽⁻Ｅ⁷⁺²κυ

Create a list of the integers from 2 to 8, perform set difference with the list of integers collected so far, select a random integer, and push it to the empty list. This shuffles the integers from 2 to 8.
⁺⪫⪪⪫υω⁴9¦1

Concatenate the integers, insert a 9 after the fourth, and append a 1. Edit: Saved 2 bytes by using @JonathanAllan's trick to insert the 9.
↖⪪...³

Split the string into a 3×3 grid and print it diagonally thus achieving the desired output.

Python 3, 128 bytes
from random import*
l=[1]+sample(range(2,9),7)
l.insert(4,9)
for i in[1,2,3,2,1]:print(f"{' '.join(map(str,l[:i])):^5}");l=l[i:]

Try it online!
Unfortunately not even close to the straightforward solution, but I spent so much time on this that I still wanted to share it.
Ungolfed:
from random import *

# Generate random sampling and ensure 1st element is 1
l = [1] + sample(range(2, 9), 7)
# Ensure 5th element is 9
l.insert(4, 9)

for i in [1, 2, 3, 2, 1]: # Numbers of digits per row
    # Take i numbers from the beginning of l, join them with spaces
    # Then center the resulting string in a field of length 5 and print
    print(f"{' '.join(map(str,l[:i])):^5}")
    # Drop the just printed numbers
    l = l[i:]

It can be shortened but then it no longer makes use of the nifty :^5 format specifier:
Python 3, 112 bytes
from random import*
l=[1]+sample(range(2,9),7)
l.insert(4,9)
for i in[1,2,3,2,1]:print(' '*(3-i),*l[:i]);l=l[i:]

Try it online!
A funny one without insert which bounces the 9 into the middle by slicing with a step size of 2:
Python 3, 115 bytes
from random import*
l=[1]+sample(range(2,9),7)+[9]
for i in[2,4,6,4,2]:print(' '*(3-i//2),*l[:i:2]);l=l[i:]+l[1::2]

Try it online!

Kotlin, 102 95 93 92 bytes
{List(7){it+2}.shuffled().fold("  1\n XX\nX9 X\n XX\n  X"){s,c->s.replaceFirst("X", "$c ")}}

Try it online!

Ruby, 66 52 bytes
$><<"  1
 %d %d
%d 9 %d
 %d %d
  %d"%[*2..8].shuffle

Try it online!
Also quite a boring answer, similar to the Perl and Bash solutions.
Saved 14 bytes thanks to Value Ink!

52 bytes using printf formatting

Jelly, 24 bytes
7ẊŻŒHj8‘;€⁶⁽¦ỵD¤œṖz⁶ZṚ€Y

A full program which prints the result.
Try it online!
How?
7ẊŻŒHj8‘;€⁶⁽¦ỵD¤œṖz⁶ZṚ€Y - Main Link: no arguments
7                        - seven
 Ẋ                       - shuffle (implicit range [1..7])
  Ż                      - prepend a zero
   ŒH                    - split in half
     j8                  - join with an eight
       ‘                 - increment (vectorises)
        ;€               - concatenate each with:
          ⁶              -   a space character
                œṖ       - partition before indices:
               ¤         -   nilad followed by link(s) as a nilad:
           ⁽¦ỵ           -     2479
              D          -     digits -> [2,4,7,9]
                  z⁶     - transpose with space filler
                    Z    - transpose
                     Ṛ€  - reverse each
                       Y - join with newline characters
                         - implicit, smashing print

Perl 6, 51 bytes
printf '  1
 %s %s
%s 9 %s
 %s %s
  %s',pick *,2..8

Try it online!
I'm not really happy with how boring this solution is.

Boring is good, it just means the language is well suited to the task :)

PowerShell, 60 bytes
'  1
 {0} {1}
{2} 9 {3}
 {4} {5}
  {6}'-f(2..8|Sort{Random})

Try it online!
-17 bytes thank you @Veskah for cleaning up whitespaces
Originally:
'
   1
 {0}  {1}
{2}  9  {3}
 {4}  {5}
   {6}
' -f (2..8 | Sort {Get-Random})

60 bytes by optimizing whitespace

Jelly, 28 26 bytes
4>þ`ṚŒḄYṣ1µ7ẊŻs4j8‘;€⁶ż@o⁶

Try it online!
A full program that takes no arguments and outputs a pool rack.
Explanation
4>þ`                       | Outer table using 1,2,3,4 on both sides and > as the the function [0,1,1,1],[0,0,1,1],[0,0,0,1],[0,0,0,0]
    Ṛ                      | Reverse [0,0,0,0],[0,0,0,1],[0,0,1,1],[0,1,1,1]
     ŒḄ                    | Bounce [0,0,0,0],[0,0,0,1],[0,0,1,1],[0,1,1,1],[0,0,1,1],[0,0,0,1],[0,0,0,0]
       Y                   | Join with newlines
        ṣ1                 | Split at 1s
          µ                | Start a new monadic chain
           7Ẋ              | Shuffle list of 1..7
             Ż             | Prepend with zero
              s4           | Split into pieces of length 4
                j8         | Join with 8
                  ‘        | Increment by 1
                   ;€⁶     | Append space to each
                      ż@   | Zip with list generated above
                        o⁶ | Replace 0s with spaces

Can you give any explanation of how this works?

@nihilazo done, please see above

7ẊŻs4j8‘;€⁶ snap! (except I halved)

Perl 5, 62 bytes
printf"  1
 %d %d
%d 9 %d
 %d %d
  %d",sort{int(rand 3)-1}2..8

Try it online!

05AB1E, 18 16 bytes
Y8L.r1†9ª•26Ià•Λ

-2 bytes thanks to @Grimmy by using a fixed length of 2 with some directions duplicated.
Try it online.
Explanation:
Y            # Push 2
8L           # Push a list in the range [1,8]
  .r         # Randomly shuffle it
    1†       # Filter the 1 to the front
      9ª     # Append a trailing 9 (i.e. [1,3,4,8,5,2,6,7,9])
•26Ià•       # Push compressed integer 33557713
Λ            # And use the Canvas builtin with those three values

See this 05AB1E tip of mine (section How to compress large integers?) to understand why •26Ià• is 33557713.
Canvas explanation:
The Canvas builtin takes three arguments:
1. The lengths of the lines to 'draw', which in this case is the fixed length of 2.
2. The string to 'draw', which in this case is the list [1,#,#,#,#,#,#,#,9] (where the # are random digits in the range [2,8]).
3. The directions, which in this case is 33557713. These will be the directions [↘,↘,↙,↙,↖,↖,↗,↘].
With these arguments, it will draw as follows (let's take the random list [1,3,4,8,5,2,6,7,9] as example here):
2 characters (1,3) in direction 3 (↘):
1
 3

2-1 characters (4) in direction 3 (↘):
1
 3
  4

2-1 characters (8) in direction 5 (↙):
1
 3
  4
 8

2-1 characters (5) in direction 5 (↙):
1
 3
  4
 8
5

2-1 characters (2) in direction 7 (↖):
 1
  3
   4
2 8
 5

2-1 characters (6) in direction 7 (↖):
  1
   3
6   4
 2 8
  5

2-1 characters (7) in direction 1 (↗):
  1
 7 3
6   4
 2 8
  5

2-1 characters (9) in direction 3 (↘):
  1
 7 3
6 9 4
 2 8
  5

NOTE: Since we use a fixed length of 2, the directions are leading in drawing the Canvas. So the trailing 3 in the directions 33557713 is mandatory for outputting the 9 here, whereas my previous 18-byter used the leading 3 with implicit wraparound to output the 9, since the lengths-list were leading for drawing instead.
See this 05AB1E tip of mine for a more in-depth explanation of the Canvas builtin.

That is much shorter than what I had using » and .c. You can still save 2 bytes with Y8L.r1†9ª•26Ià•Λ. Happy new year! (:

@Grimmy Ah, of course. Duplicating the directions and using a single length of 2. Thanks! And happy New Year to you as well! :)

Dyalog APL Extended, 38 bytes
{5 5⍴(~2⊤29010619)⍀∊⍕¨∊,∘9¨@4⊢1,1+?⍨7}

Try it online!

Red, 90 bytes
t: random[2 3 4 5 6 7 8]foreach c{  1
 ; ;
; 9 ;
 ; ;
  ;}[prin either c >#":"[take t][c]]

Try it online!

SAS, 160 Bytes
data;array j[9](1:9);do i=1to 1e4;l=int(2+7*ranuni(0));m=int(2+7*ranuni(0));n=j[l];j[l]=j[m];j[m]=n;end;put+2j[1]/+1j[2]j[3]/j[4]j[9]j[5]/+1j[6]j[7]/+2j[8];run;

Ungolfed:
data _null_;
  array j[9] (1:9);       **Define and populate an array;
  do i = 1 to 1e4;        **Iterate ten thousand times;
    l=int(2+7*ranuni(0)); **make a random int;
    m=int(2+7*ranuni(0)); **make another random int;
    n=j[l];               **save num in first slot;
    j[l]=j[m];            **swap second to first slot;
    j[m]=n;               **swap original first to second slot;
  end;
  put +2j[1]/+1j[2]j[3]/j[4]j[9]j[5]/+1j[6]j[7]/+2j[8];
                          **outputs the string, / is linebreak, +# is shift over, always adds one space;
run;

If I wanted to do it a bit "better" but longer, I would use rand("integer",2,8);, as that is a better random number distribution, but 1 char longer each line...
I'm pretty sure PROC IML would be much smaller, as that would be more similar to the R/Python implementation. Base SAS has tools to sort rows randomly, but not columns/variables.  I figure doing 10,000 random swaps is sufficiently randomized here (probably as random as any of the other implementations, anyway); could easily do 1 billion random swaps for no more characters, but 10k seems enough.

C (GCC) 161 158 bytes
-3 bytes from ceilingcat
#define B,b[i++]
b[]=L"";main(a,t,i){srand(time(0));for(i=b;--i;b[a]=t)*b=b[a=rand(t=*b)%7];printf("  1\n %d %d\n%d 9 %d\n %d %d\n  %d"B B B B B B B);}

L"" has non-printing characters that I can't get to show in SE is equivalent to {2,3,4,5,6,7,8}
this code makes the assumption that the address of b is at least 14 in order to guarantee all results are possible
Try it online!

152 bytes

APL, 37 chars/bytes
2⌽t⌽↑⍕¨((t←1 2 3 2 1)/⍳5)⊆1,5⌽9,1+?⍨7

permutation of numbers from 2 to 8
1+?⍨7

add leading 9, shift 5 positions to the left, add leading 1
1,5⌽9,

replicate numbers from 1 to 5, 1-2-3-2-1 times respectively
(t←1 2 3 2 1)/⍳5

make 5 nested vectors of length 1-2-3-2-1 respectively
((t←1 2 3 2 1)/⍳5)⊆

transform numerical arrays into char vectors
⍕¨

nested vectors into matrix
↑

shift each line 1-2-3-2-1 positions to the left respectively, and then 2 more for every line
2⌽t⌽

https://tio.run/##SyzI0U2pTMzJT////1Hf1EdtE4we9ewtAeJHbRMf9U49tEJDowQoaqhgpGAMxIaa@o96N5tqPupqM9QxBSqz1DHUtn/Uu8L8/38A

PHP, 83 81 bytes
83 bytes
<?=($l=range(2,8))&&shuffle($l)?vsprintf("  1\n %d%2d\n%d 9 %d\n%2d%2d\n%3d",$l):0;

Try it online!

81 bytes
Splitting code into 2 fragments to save 2 characters. Thanks for the comment @manatwork.
<?$l=range(2,8);shuffle($l)?><?=vsprintf("  1\n %d%2d\n%d 9 %d\n%2d%2d\n%3d",$l);

Try it online!

The challenge says “you cannot just produce a single randomly-chosen rack every time”.

@manatwork, sorry, i have corrected.

Splitting the code in 2 PHP fragments would help save 2 characters: Try it online!

@manatwork, hmm, an interesting idea, thank you :)

Keg, 62 bytes
2345678(~z%|&(~z%|')&^)  ,,1.
, ,. ,.
,. ,9. ,.
, ,. ,.
,  ,,.

Try it online!
Remove the z%' s for -4 bytes but a really long execution time.
This:

Pushes the numbers 2-8 onto the stack.
Shuffles everything in a very interesting way.
Prints out the required shape.

Vyxal, 42 32 bytes
`  1
 % %
% 9 %
 % %
  %`7ɾ1+Ṗ℅%

Try it Online!
-10 thanks to lyxal.

-10 bytes

@lyxal Nice! Replacing!

Java 10, 140 139 bytes
v->{var r="  1\n x x\nx 9 x\n x x\n  x";for(int d=9,m=3;m<511;r=r.replaceFirst("x",d+""))for(;m==(m|=1<<(d*=Math.random()));d=9);return r;}

Port of @Arnauld's JavaScript answer, so make sure to upvote him as well!
Try it online.
Explanation:
v->{                // Method with empty unused parameter and String return-type
  var r="  1\n x x\nx 9 x\n x x\n  x";
                    //  Result-String, starting at:
                    //  "  1
                    //    x x
                    //   x 9 x
                    //    x x
                    //     x"
  for(int d=9,      //  Temp integer for the random digit, starting at 9
          m=3;      //  Bit-mask `m`, starting at 3 (binary 000000011)
          m<511     //  Loop as long as `m` is not 511 yet (binary 111111111):
          ;         //    After every iteration:
           r=r.replaceFirst("x",d+""))
                    //     Replace the first "x" with digit `d`
    for(;m==        //   Inner loop as long as `m` is unchanged after
            (m|=    //   `m` is bitwise-ORed with:
                1<< //    2 to the power
                   (d*=Math.random()));
                    //    a random digit in the range [0,9)
      d=9);         //     After every iteration: reset `d` to 9 again
  return r;}        //  And finally return the result-String

C (gcc), 139 bytes
char a[7],c;r(){for(srand(time(0));c=rand()%7,a[c]++;);c+=2;}f(){printf("  1\n %d %d\n%d 9 %d\n %d %d\n  %d",r(),r(),r(),r(),r(),r(),r());}

Generates a random number 0-6, tests if that number has been generated before, and if not, prints it.
Try it online!

131 bytes

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


text:
When is Hannukah?
Input
The input will be a year between 1583 and 2239.  We just want to know when Hannukah was or will be in that year. This is information used by millions of people every year and put in calendars across the world. What could be easier?
Output
The Gregorian date of the first evening of Hannukah that year. That is the day before the first full day of Hannukah.  Your code should output the month and day of the month in any easy to understand human readable form of your choice.
Examples
1583    December 9
2013    November 27
2014    December 16
2015    December 6
2016    December 24
2017    December 12
2018    December 2
2019    December 22
2020    December 10
2021    November 28
2022    December 18
2023    December 7
2024    December 25
2025    December 14
2026    December 4
2027    December 24
2028    December 12
2029    December 1
2030    December 20
2031    December 9
2032    November 27
2033    December 16
2239    December 21

It could hardly be simpler. We start with a couple of definitions:
We define a new inline notation for the division remainder of \$x\$ when divided by \$y\$: $$(x|y)=x \bmod y$$
For any year Gregorian year \$y\$, the Golden Number,
$$G(y) = (y|19) + 1$$
For example, \$G(1996)=2\$ because \$(1996|19)=1\$.
To find \$H(y)\$, the first evening of Hannukah in the year \$y\$, we need to find \$R(y)\$ and \$R(y+1)\$, the day of September where Rosh Hashanah falls in \$y\$ and in \$y+1\$. Note that September \$n\$ where \$n≥31\$ is actually October \$n-30\$.
$$R(y)=⌊N(y)⌋ + P(y)$$ where \$⌊x⌋\$ denotes \$x-(x|1)\$, the integer part of \$x\$, and
$$N(y)= \Bigl \lfloor \frac{y}{100} \Bigr \rfloor - \Bigl \lfloor \frac{y}{400} \Bigr \rfloor - 2 + \frac{765433}{492480}\big(12G(y)|19\big) + \frac{(y|4)}4 - \frac{313y+89081}{98496}$$
We define \$D_y(n)\$ as the day of the week (with Sunday being \$0\$) that September \$n\$ falls on in the year \$y\$. Further, Rosh Hashanah has to be postponed by a number of days which is
$$P(y)=\begin{cases}
1,  &  \text{if } D_y\big(\lfloor N(y)\rfloor \big)\in\{0,3,5\}  &  (1)\\
1,  &  \text{if } D_y\big(\lfloor N(y)\rfloor\big)=1
 \text{ and } (N(y)|1)≥\frac{23269}{25920}
 \text{ and } \big(12G(y)|19\big)>11  &  (2)\\
2,  &  \text{if } D_y\big(\lfloor N(y)\rfloor \big)=2 \text{ and } (N(y)|1)≥\frac{1367}{2160} \text{ and } (12G(y)|19)>6  &  (3)\\
0,  &  \text{otherwise}  &  (4)
\end{cases}$$
For example, in \$y=1996\$, \$G(y)=2\$, so the \$N(y)\approx13.5239\$. However, since September 13 in 1996 was a Friday, by Rule \$(1)\$, we must postpone by \$P(y)=1\$ day, so Rosh Hashanah falls on Saturday, September 14.
Let \$L(y)\$ be the number of days between September \$R(y)\$ in the year \$y\$ and September \$R(y+1)\$ in year \$y+1\$.
The first evening of Hannukah is:
$$
H(y)=\begin{cases}
83\text{ days after }R(y) & \text{if } L(y)\in\{355,385\}\\
82\text{ days after }R(y) & \text{otherwise}
\end{cases}
$$
Notes and thanks
Your code may not access the Internet to get the answer using e.g. an online Hebrew calendar calculator.
Thank you to @Adám for pointing me to the rules and for a great deal of help. To keep things simple, this challenge assumes the location to be Jerusalem.
For those now intrigued by the math of the Hebrew calendar, see https://docs.microsoft.com/en-us/dotnet/api/system.globalization.hebrewcalendar?view=netframework-4.8 .

Why the downvote?

I don't know Hannukah, just curious. I see the number 19 and 12 in the formula. Is that means it has some relationship with moon phase?

@tsh Yes. See e.g. https://en.m.wikipedia.org/wiki/Hebrew_calendar

Are we allowed to return a different date format depending on the year, or do the results have to be consistent?

@Adam That's fine. It just has to be easily human readable.

JavaScript (ES6),  188 ... 168  160 bytes
Assumes that the system is set up to UTC time (as the TIO servers are)
Returns a Date instance.
y=>(D=d=>new Date(y,8,n+=d))(((g=y=>D((n=80,d=D((3*-~(y/100)>>2)+1.554*(x=12*-~y%19)+y%4/4-y/314.6-.9).getDay())%2+2*(n%!d>.63&x>6))/864e5)(++y)-g(--y)+5)%30<1)

Try it online!
Or test it against a more literal implementation
How?
The approximations described below are guaranteed to work for \$665\le y\le 5510\$, which is a significantly larger interval than the requested one.

Instead of computing:
$$k=\left\lfloor\frac{y}{100}\right\rfloor-\left\lfloor\frac{y}{400}\right\rfloor-2$$
we compute \$k+2\$ with:
3 * -~(y / 100) >> 2

This off-by-two error is left uncorrected. We just need to adjust the final offset accordingly, as well as the tests about the day of the week. It has no impact on \$L(y)\$.
An offset of \$80\$ days is added right away to all date calculations, which introduces an additional shift of \$3\$ more days (\$80\bmod7\$) in the days of the week.
Therefore, the index \$d\$ for the day of the week is \$5\$ for Sunday, \$6\$ for Monday, \$0\$ for Tuesday, \$1\$ for Wednesday, \$2\$ for Thursday, \$3\$ for Friday, or \$4\$ for Saturday.
Very conveniently, it leads to the following properties:

rule \$(1)\$ for \$P(y)\$: the day is either Sunday, Wednesday or Friday iff \$d\$ is odd
rule \$(3)\$ for \$P(y)\$: the day is Tuesday iff \$d=0\$

We use \$1.554\$ as an approximation of \$\dfrac{765433}{492480}\$.
We use \$\dfrac{y}{314.6}+0.9\$ as an approximation of \$\dfrac{313y+89081}{98496}\$.
The test about \$D_y(\lfloor N(y)\rfloor)\$ being equal to \$1\$ is ignored entirely, as the result cancels out with the other criteria.
We use \$0.63\$ as an approximation of \$\dfrac{1367}{2160}\$.
Instead of testing \$L(y)\in\{355,385\}\$, we test \$\big(L(Y)+5\big)\bmod30=0\$.

Definitely tweetable :)  Thank you for having the first answer.

I really like your description. Who knows, it might become the new way to calculate the date!

@Anush It still doesn't fit within the historical limit of 140 characters, but it's getting closer. ;)

C# (Visual C# Interactive Compiler), 108 bytes
An alternate version suggested by @Adám, with a distinct output format for the edge case 2239.
using System.Globalization;string f(int y)=>y<2239?new DateTime(y+3761,3,24,new HebrewCalendar())+"":"1221";

Try it online!

C# (Visual C# Interactive Compiler),  134 130 122  121 bytes
Saved 8 bytes thanks to @Hedi
Saved 1 byte thanks to @Adám
My first C# program either... \o/
Returns a DateTime instance.
using System.Globalization;dynamic f(int y)=>y<2239?new DateTime(y+3761,3,24,new HebrewCalendar()):new DateTime(y,12,21);

Try it online!

Tweetability at 140 characters!   (Could you add the two remaining test cases too please.)

@Anush Oops... Seems like this only works up to $y=2238$. I'll probably have to add a patch for the last year.

@Anush Patch and test cases added.

@Arnauld are you missing the use of c in the case 2239 in new DateTime(y,12,21) ? If not you can save some bytes like this : using System.Globalization;DateTime f(int y)=>y<2239?new DateTime(y+3761,3,24,new HebrewCalendar()):new DateTime(y,12,21);

Does this mean C# has a built-in for the Hebrew Calendar?!

@Hedi For the year 2239, we just return a hardcoded date in the Gregorian calendar. So I'm indeed using HebrewCalendar() only once in this new version and I don't need c anymore. Thanks!

@Adám Thanks for the dynamic tip! Using a different output format for the year 2239 seems a bit abusive, though.

@Arnauld Explicitly approved by OP.

108

APL (Dyalog Unicode), 86 85 bytesSBCS
Now that Arnauld has posted his C# solution, I can reveal my equivalent anonymous tacit prefix function.
⎕NEW{⎕USING←'System'⋄0::1221⋄⍺⍺DateTime((3761+⍵)3 24,⍺⍺Globalization.HebrewCalendar)}

Can't try it online as this only works under Windows. (.NET Core support is planned for this year!)
⎕NEW{…} function derived from monadic operator with ⎕NEW (create new instance of object) as operand:
 ⎕USING←'System' make the members of .NET's root namespace's immediately available
 ⋄0::1221 upon any error, return this number
 ⋄ Try:
  ⍺⍺DateTime(…) create a new DateTime object with the following constructor arguments:
   ⍺⍺Globalization.HebrewCalendar create a new HebrewCalendar object
   (…)3 4, prepend the list ending with […,3,4] where the first element is:
    3761+⍵ the argument adjusted for the difference between the civil and Hebrew calendars' years

Perl 5, 313 278 bytes
sub f{sub t{timegm_nocheck(0,0,0,pop,8,pop)}$Y=pop;eval'(R,N,Q)=map{X=12*(_%19+1)%19;N=1.554*X-2.9-_/314.4+_%4/4+_/100%99-_/400%9;I=intN;D=t(_,I)/86400%7;M=N-I;P=D=~/[361]/||D==4&&M>1?1:D==5&&M>=.63&&X>6?2:0;t(_,I+P),I+P}Y,Y+1;t(Y,N+82+((Q-R)/432e3)=~/1|7$/)'=~s/[A-Z_]/\$$&/gr}

Try it online!
Based on @Arnauld's javascript answer.
Slightly ungolfed:
sub f{
  sub t{timegm_nocheck(0,0,0,pop,8,pop)}            #xth sep y => secs after jan 1 1970
  $Y=pop;                                           #input year
  eval'                                             #eval code string to use code without $
    (R,N,Q) = map {                                 #R,N=rosh for curr Y. Q for Y+1
      X=12*(_%19+1)%19;
      N=1.554*X-2.9-_/314.4+_%4/4+_/100%99-_/400%9; #%99 cuts decimals, int() for small nums
      I=intN;
      D=t(_,I)/86400%7;                             #D=weekday - 4, 3=sun 6=wed 8=1=fri ...
      M=N-I;                                        #M=N%1 (perl dont support
      P=D=~/[361]/||D==4&&M>1?1:D==5&&M>=.63&&X>6?2:0;
      t(_,I+P),I+P
    }
    Y, Y+1;
    t(Y,N+82+((Q-R)/432e3)=~/1|7$/)
  ' =~ s/[A-Z_]/\$$&/gr                             #inserts $ before every uppercase A-Z and _
}


text:
Write a program that sees the New Year in itself
Write the smallest program that maps strings injectively to outputs and maps itself to 2020.
To be clear, your program \$p\$ must have the following properties:

every possible input string \$s\$ has a well-defined output \$p(s)\$,
for every pair of strings \$s\$ and \$t\$ with \$s\neq t\$, it holds that \$p(s)\neq p(t)\$, and
\$p(p)=2020\$.

Be sure to explain why your submission satisfies properties 1 and 2. For property 3, the output can be a string or any type of number.
Edit 1: Programs need to be proper quine variants. Reading the source code is not allowed.
Edit 2: Note that as a consequence of property 2, it holds that \$p(s)\neq p(p)\$ for every \$s\neq p\$.

every possible input string Can we support only ASCII?

@LuisMendo - yes, provided ASCII is the alphabet of the language that your program is written in.

Do programs need to be proper quine variants or is reading the source code allowed?

Is a function acceptable or must we write a full program?

@FlipTack - Thanks for the clarifying question. No reading the source code. I edited the post to reflect this.

@RobinRyder - A function is acceptable.

How do any of these requirements imply being a quine?  If you wrote a whole program that (for example) reads from stdin, you'd get p(p) by running ./my_program < my_source.c with the user feeding the program a copy of the source (as opposed to any other input), right?  Or for a function, just uint32_t map(char *).  Except uint32_t can't work- by the pigeonhole principle that would only allow 2^32 possible input strings, not arbitrary length.  Or did you mean that if you want your source code as a constant to compare against, you'd need a quine technique to embed it?

awk, 4 bytes
The structure of an awk program is pattern { action }. If pattern evaluates to true, { action } is performed. If { action } is omitted, the default is to output the current input record.
Code:
2020

As 2020 always evaluates to true, the program always prints it's input, therefore satisfying properties 1. and 2. When the input is the program itself it satisfies property 3. \$p(p)=2020\$ — even \$p(p)=p\$.
Some test cases:
$ echo 2020 | awk '2020'
2020
$ echo 0 | awk '2020'
0
$ echo "" | awk '2020'

$ echo foo | awk '2020'
foo

Would've been more glorious back in the good old days:
$ echo 1 | awk '1'
1

polyglot with perl5 -p

Nice James, thank you for sharing the same :)

Also polyglot with Perl 6 -p.

In some other stack-based languages, like Golfscript, the code 20 would suffice since it auto-concatenates the stack to print out on output.

JavaScript (ES6), 23 bytes
Returns either the input string with a leading \$0\$, or \$2020\$ if the input is the program.
f=s=>s=='f='+f?2020:0+s

Try it online!

JavaScript (Node.js), 76 bytes
Generates a unique BigInt by using each byte of the input string, then applies a XOR to the result in such a way that \$f(f)=2020\$.
f=s=>(g=s=>Buffer(s).every(b=>t=t<<8n|BigInt(b),t=1n)&&t)(s)^g('f='+f)^2020n

Try it online!

The first one does not match criteria 2, as it will output the same result for different input strings

@Skyler Please note that the input is a string and so is 0+s. If a and b are 2 distinct strings, so are 0+a and 0+b.

I think this doesn't satisfy the "do not read the source code" condition, right?

@TomášZato-ReinstateMonica Last time I checked, I think Dennis' answer about that was the most upvoted, but it seems like we still don't have a clear concensus. (Also, this requirement did not exist at the time I answered the challenge.)

You can check the revision change on https://codegolf.stackexchange.com/revisions/197679/2 which was at 2020-01-04 19:36:35Z while this answer was posted on 2020-01-04 17:08:36Z - almost 2 hours and a half after this answer was posted. On that edit, the tag "quine" as added as well.

Python 3.8 (pre-release), 81 60 59 57 56 bytes
-21 Thanks to Jo King
Outputs 2020 if the input matches the program, otherwise the input concatenated to itself 5 time (eg. abc becomes abcabcabcabcabc)
exec(a:='print(5*[i:=input(),404][i=="exec(a:=%r)"%a])')

Try it online!

Python 2, 56 bytes
Outputs 2020 if the input matches the program, otherwise the input concatenated to itself 5 time (eg. abc becomes abcabcabcabcabc)
a='i=input();print 5*[i,404][i=="a=%r;exec a"%a]';exec a

Try it online!

Python 3.8 (pre-release), 77 67 65 bytes
-10 Thanks to Jo King
Outputs 2020 if the input matches the program, otherwise the input concatenated to itself 5 time (eg. abc becomes abcabcabcabcabc)
lambda s:5*[s,404][s==(a:='lambda s:5*[s,404][s==(a:=%r)%%a]')%a]

Try it online!

Ruby -n, 45 bytes
Based on one of the classic Ruby quines, _="_=%p;puts _%%_";puts _%_. Prints 2020 if the input is the source, otherwise prints the Ruby representation of the input (encapsulated in quotes, various characters like " and \ are escaped, etc.)
_="_=%p;p$_==_%%_ ?2020:$_";p$_==_%_ ?2020:$_

Try it online!

GolfScript, 2 bytes
20

This is a refined solution to James Brown's solutions.
If the input is 20 [source code], prints 2020 - otherwise prints [string]+20, which is unique and easily reversible.
Try it online!

Jelly, 16 bytes
“Ṿ;⁾v`³⁽¥ŒṾ⁼?”v`

Try it online!
A full program that takes a string as its input. It outputs an unevaluated Jelly version of the input unless provided with itself, in which case it outputs 2020.
Thanks to @JonathanAllan for pointing out a flaw in my original version!
Explanation
 “Ṿ;⁾v`³⁽¥ŒṾ⁼?”v` | Evaluate as Jelly code the following, using itself as the argument:
  Ṿ               | - Unevaluate (effectively wraps string back into “”
   ;⁾v`           | - Append "v`"
       ³    ⁼?    | - If equal to the program’s argument:
        ⁽¥Œ       | - Then: 2020 (compressed integer)
           Ṿ      | - Else: Unevaluated version of the program’s original argument

Hmm, not sure it's valid without bracketing or something - TIO EDIT - how about this?

@JonathanAllan I don’t follow. Although it will follow standard Jelly implicit printing rules, the output should still be unique for any given input. The question doesn’t seem to put any further criteria on what the output consists of. Thanks for your suggestion; while it works, I’m still not sure why I can’t just continue to use O.

There is an s (ߤ) for which p(s) = p(p) (2020)

Oh I see. I now also follow your comment to the question. For now, I’ll update to your version if that’s ok. Thanks!

@JonathanAllan I’ve gone with Ṿ which should work ok. Any thoughts?

Was just about to suggest it!

@RobinRyder only when provided as an integer. When provided as a string (which is the spec), it yields “2020” which != 2020

@NickKennedy Right, I had missed that input was restricted to strings.

Raku, 47 bytes
<say "<$_>~~.EVAL"eq($!=get)??2020!!@$!>~~.EVAL

Try it online!
Outputs 2020 if the input matches the program, otherwise the input surrounded in brackets.

C (gcc), 190 196 194 192 180 176 bytes
Thanks to Jo King for pointing out a bug.
Trailing newline seems accepted in some other answers, so will use that to fix a bug pointed out by NieDzejkob. (Also -12 bytes thanks to the same.)
-4 bytes thanks to @ceilingcat.
Assumes little-endian, ASCII, sizeof(int) >= 4, all the good stuff.
Outputs the input string preceded by a dollar sign, unless given its own source code, in which case it outputs 2020.
*s="*s=%c%s%1$c,u[99]={'0202'};f(int*t){puts(bcmp(u+2,t,sprintf(u+2,s,34,s))?putchar(36),t:u);}",u[99]={'0202'};f(int*t){puts(bcmp(u+2,t,sprintf(u+2,s,34,s))?putchar(36),t:u);}

Try it online!

which is a different output than the empty string

The requirement is that no two distinct inputs should have the same output.

@JoKing Good point! (Hopefully) Corrected now.

@NieDzejkob The number will vary between implementations no doubt. Cheers!

@gastropner Now 2020 corresponds to the input of the old program...

172 bytes

@NieDzejkob Hopefully fixed. The 182 bytes one works only if sizeof(int) == sizeof(char*) (or by luck).

@gastropner Ok, then 180 bytes

@ceilingcat Neato!

05AB1E, 28 bytes
"34çìD«QiŽ7ìëû"34çìD«QiŽ7ìëû

Try it online or verify a few more test cases.
Explanation:
"34çìD«QiŽ7ìëû"            # Push this string
               34ç         # Push 34, and convert it to a character: '"'
                  ì        # Prepend it in front of the string
                   D«      # Append a copy of the string to itself
                     Qi    # If it's equal to the (implicit) input:
                       Ž7ì #  Push compressed integer 2020
                      ë    # Else:
                       û   #  Palindromize the (implicit) input
                           # (after which the result is output implicitly)

See this 05AB1E tip of mine (section How to compress large integers?) to understand why Ž7ì is 2020.

Might work ... only problem is an empty string?

@ExpiredData The м should be K, otherwise any input containing only characters of the input (i.e. DD) would also result in 2020. But apart from that the empty string is indeed a problem I'm not sure how to overcome. :(

@ExpiredData the empty string is far from the only problem. Appending the code to any string doesn't change the output (example). It seems highly unlikely you can make something injective with either м or K, since those fundamentally lose information.

Yeah @Grimmy thanks great point

Java 10, 128 bytes
s->{var t="s->{var t=%c%s%1$c;t=t.format(t,34,t);return t.equals(s)?2020:0+s;}";t=t.format(t,34,t);return t.equals(s)?2020:0+s;}

Try it online.
Explanation:
quine part of the explanation:

var t contains the unformatted source code
%s is used to input this String into itself with t.format(...)
%c, %1$c, and the 34 are used to format the double quotes
t.format(t,34,t) puts it all together

Challenge part of the explanation:

t.equals(s) checks if the input-String is equal to the source code
?2020: if it is, return 2020 as result
:0+s: if not, return the input-String with a prepended 0 as result instead

Pyth, 26 23 bytes
Outputs 2020 if the input matches the program, otherwise the input concatenated to itself 2020 time (eg. ab becomes ababab...ababab)
*2020|qjN B"*2020|qjN B

Try it online!
Explanation
*2020|qjN B"*2020|qjN B
          B"*2020|qjN B : Evaluates to ("*2020|qjN B", "*2020|qjN B")
       jN               : join with '"' as seperator (will be source code)
     |q                 : True if source is equal to input else input
*2020                   : Multiply by 2020 (i.e. True -> 2020, input -> 2020 * input)

Pyth, 21 bytes
Not sure if the following solution is valid, it will only work if the year is 2020.
*.d3|qjN B"*.d3|qjN B

Try it online!

J, 56 bytes
".a=.}:0 :0
echo@>2020[^:(]-:'".a=.}:0 :0',LF,a&[)1!:1[3

Try it online!
A full program. Unless provided with itself prints each character on a separate line.

Japt, 24 bytes
OvA="¶`OvA=`+Q+A?2020:U³

Try it online!
Explanation
Outputs 2020 if the input matches the program, otherwise the input 3 times (eg. ab becomes ababab)
OvA="¶`OvA=`+Q+A?2020:U³
  A="¶`OvA=`+Q+A?2020:U³  // Set value of A to "¶`OvA=`+Q+A?2020:U³"
Ov                        // Evaluate A as japt code
      `OvA=`+Q+A          // Concatenate "OvA=", '"' and A (Q = '"')
     ¶          ?2020:U³  // If equal to input then 2020 else input concatenated to itself 3 times


text:
Dissect a word and arrange all its letters in alphabetical order
Question
Write a program to accept one string on the console only and print back its letters arranged in alphabetical order. The string must only have the following characters:

0123456789abcdefghijklmnopqrstuvwxyz

Rules
The ascending alphabetical order is defined in the given string.
All repeated characters must be printed.
If the string contains characters other than the ones mentioned above, it must display "Invalid input".
This is code-golf, so shortest answer in bytes wins.
Standard loopholes are forbidden.
A null string "" will output "Invalid input".
Your program must be executable and not a function or snippet.
Boilerplate is not required.
Examples
"dragon"--> adgnor
"skoda3ferrari"--> 3aadefikorrrs
"ferret"--> eefrrt
"werewolf92"--> 29eeflorww
"@hog"--> Invalid input
"gTa5"--> Invalid input
"  l "--> Invalid input
""--> Invalid input

Edit: The double quotes are given for clarification.
May the force be with you. Good luck!

Any particular reason for the input being restricted to the console? Why not allow a function taking an argument?

What if my function is executable without boilerplate?

What is boilerplate?

Now your post is self-contradictory: as an argument vs not a function

Boilerplate is additional code necessary to actually run one's main code.

Input will be restricted to the console. Boilerplate is not required.

@a'_' No, unless it has characters outside the set.

Suggested additional test cases: "ABC" and ""

Invalid input for "" and also and whitespace

@RileyJones Why is "" invalid? It has no characters outside the set.

Just so. No specific reason.

@RileyJones Since that is an additional rule which cannot be inferred from the other rules, you should be explicit about it. Do not rely on a test case to specify the challenge.

Does "console input" included passing the string as argument?

no, only console input

Is the Invalid input mandatory to be with titlecased Invalid and lowercase input, or is Invalid Input or invalid input or INVALID INPUT valid as well? Several answers are using Invalid Input right now.

Hi! I've downvoted this post as it goes against several site conventions (allowable I/O methods, allowed to be programs or functions, and input parsing) without really providing justification for those decisions (e.g., input parsing as a core component of the challenge).

Hi Riley, thank you for your challenge. Please do stick around, and answer a few challenges to get to know the site better. It would be a good idea to post your next challenge to the sandbox (see link at top right of screen) for review before it goes live. @AdmBorkBork I applaud you for explaining the reason for your downvote, and I don't disagree with your reasons. On the other hand I think all of us need to be a bit more welcoming and lenient with new contributors lest they are put off using the site in future.

05AB1E, 16 15 bytes
-1 byte thanks to Kevin Cruijssen
žKlsSåßi{ë”Í¼î®

Try it online!

Your Input is titlecased as well now.

@KevinCruijssen Yeah, several other answers titlecase Input, so I assumed it wasn't an issue

Ah ok. Btw, you can also save a byte by changing {ÐžKlм‚õ¢≠i to žKlsSåßi{ë: verify all test cases.

@a'_' I had already stated that in my first comment. :) And I've asked OP about it, but no response yet. It's easy to fix in 2 bytes though, by changing the ”Í¼î® to „Í¼î®.ª: try it online.

Python 3.8 (pre-release), 77 75 74 88 bytes
import re
print(*re.match('[0-9a-z]+$',i:=input())and sorted(i)or'Invalid input',sep='')

Try it online!

Fails on input that contains only numbers. Input 123 outputs Invalid input.

Also fails on lowercase characters outside of the given alphabet. For example ú does not output Invalid input.

@mypetlion Fixed

@a'_' Fixed now

APL (Dyalog Extended), 37 bytesSBCS
{0∊(≢⍵),⍵∊⎕D,⌊⎕A:'Invalid input'⋄∧⍵}⍞

Try it online!
⍞ prompt for text input from the console
{…} apply the following anonymous lambda to that:
 ⎕A the uppercase Alphabet
 ⌊ Lowercase that
 ⎕D, prepend the digits
 ⍵∊ for each character of the argument, indicate if it is a member thereof
 (…), prepend the following:
  ≢⍵ the tally of characters in the argument
 0∊…: if zero is a member thereof:
  'Invalid input' return (and implicitly print) this message
 ⋄ else:
  ∧⍵ sort the argument ascending

Burlesque, 37 bytes
><JJann!/^zz!=||{vv"Invalid Input"}if

Try it online!
><                    # Sort input string
JJ                    # Duplicate twice
ann!                  # Not alphanumeric
/^                    # Swap and duplicate (sorted string)
zz!=                  # Lowercased not equal to original (i.e. contains uppercase)
||                    # Or
{vv"Invalid Input"}if # If not alphanumeric or lowercase drop sorted list
                        and output invalid input

The first Burlesque answer after 2 years!

I've recently been trying to learn it for a bit of fun. I looked at it several years ago and decided I'd go for befunge instead. Finally decided to give it a go for this year's advent of code.

x86-16 machine code, IBM PC-DOS, 81 80 bytes
Binary:
00000000: b40a ba4f 01cd 218b f2ad 8bd6 8acc 8be9  ...O..!.........
00000010: 938b f28b fe51 ad3c 307c 0c3c 397e 0e3c  .....Q.<0|.<9~.<
00000020: 617c 043c 7a7e 06ba 4201 59eb 103a c47c  a|.<z~..B.Y..:.|
00000030: 0286 c4ab 4e4f e2de 59e2 d688 1bb4 09cd  ....NO..Y.......
00000040: 21c3 496e 7661 6c69 6420 696e 7075 7424  !.Invalid input$

Build and test DISSECT.COM using xxd -r
Unassembled listing:
B4 0A           MOV  AH, 0AH            ; DOS read buffered input from STDIN
BA 014F R       MOV  DX, OFFSET BUF     ; load buffer pointer
CD 21           INT  21H                ; get STDIN input
8B F2           MOV  SI, DX             ; buffer pointer into SI
AD              LODSW                   ; load char count into AH
8B D6           MOV  DX, SI             ; save start of string
8A CC           MOV  CL, AH             ; string length into CX
8B E9           MOV  BP, CX             ; save string length for later display
            OUTER_LOOP:
8B F2           MOV  SI, DX             ; reset SI to beginning of buffer
8B FE           MOV  DI, SI             ; reset DI to beginning of buffer
51              PUSH CX                 ; save outer loop counter
            INNER_LOOP:
AD              LODSW                   ; load next two chars into AH/AL
3C 30           CMP  AL, '0'            ; is char < '0' ?
7C 0C           JL   INVALID            ; if so, not valid
3C 39           CMP  AL, '9'            ; is char <= '9'?
7E 0E           JLE  VALID              ; if so, valid
3C 61           CMP  AL, 'a'            ; is char < 'a'?
7C 04           JL   INVALID            ; if so, not valid
3C 7A           CMP  AL, 'z'            ; is char <= 'z'?
7E 06           JLE  VALID              ; if so, valid
            INVALID:
BA 0142 R       MOV  DX, OFFSET INV     ; load address of "invalid" string
59              POP  CX                 ; discard saved counter
EB 11           JMP  OUTPUT             ; display "invalid" string
            VALID:
3A C4           CMP  AL, AH             ; compare chars
7C 02           JL   NO_SWAP            ; if AL < AH, do not swap
86 C4           XCHG AL, AH             ; otherwise, swap chars
            NO_SWAP:
AB              STOSW                   ; store chars back to buffer
4E              DEC  SI                 ; adjust SI to previous char
4F              DEC  DI                 ; adjust DI to previous char
E2 DE           LOOP INNER_LOOP         ; loop inner iterations
59              POP  CX                 ; restore outer loop counter
E2 D6           LOOP OUTER_LOOP         ; loop outer
C6 03 24        MOV  BYTE PTR[BP+DI],'$'; add string terminator
            OUTPUT:
B4 09           MOV  AH, 09H            ; DOS display string function
CD 21           INT  21H                ; write output to console
C3              RET                     ; exit to DOS

INV DB "Invalid input"                  ; "invalid" message string
BUF DB '$'                               ; buffer size is 36 bytes, also string terminator

Standalone PC DOS executable.  Implements a simple bubble sort algorithm.
Input via console/STDIN, output to console/STDOUT.

GolfScript, 37 bytes
.$\58,48>123,97>+-!*"Invalid input"or

Try it online!
Explanation
Whoa. Maybe I shouldn't have done this..
.                                     # Make 2 copies of the input,
 $                                    # One is the sorted copy of the input,
  \58,48>123,97>+-!                   # Another is whether all of input is in the
                                      # lowercase alphanumeric range
                   *                  # Multiply them:
                                      #     If the input contains invalid characters,
                                      #     e.g. @hog, this multiplies the sorted copy by 0.
                                      # ----If the input is a null string,
                                      #     The input multiplies 0 by the null string,
                                      #     which is still the null string.
                                      # ----If the input is a valid string,
                                      #     e.g. dragon, the input multiplies the
                                      #     sorted copy by 1 (because everything is
                                      #     inside the range)
                    "Invalid input"or # Do a "logical magic":
                                      #     If the input is 0 or the null string,
                                      #         returns "Invalid input"
                                      #     Otherwise, this returns the
                                      #         sorted copy of the input.

# Further explanation of the code snippet
# \                 # Swap the stack so that an unused copy of the input emerges
#  58,              # Generate a range and drop the last: 0 to ASCII ':'
                    # (The previous character is '9')
#     48>           # Select everything that is larger than 48 (ASCII '0')
#        123,97>    # Same thing with generating 'a' to 'z'
#               +   # Join the inputs together
#                -  # Set subtraction: subtract this string from the fresh unused input
#                   # This results in everything that isn't alphanumeric
#                 ! # Negate the string. If the string has something,
#                   # it turns to 0. Otherwise it turns to 1.
```

But now it doesn't

Keg, 35 bytes
₳0a&᠀:(⑴|⑻-)⒃᠀⒃¬+[Invalid input|¿÷⑭

Nice to see Keg still "up to par" with Golfscript! No regrets about the bad pun

Red, 86 bytes
func[s][a: charset[#"0"-#"9"#"a"-#"z"]either parse sort s[some a][s]["Invalid input"]]

Try it online!

Jelly, 18 bytes
ɠfƑØBŒl¤ȧṢȯ“4{ẉṄi»

Try it online!
A full program that reads its input from STDIN and outputs to STDOUT.
If the input validation and requirement to use STDIN were removed, this would be a single byte: Ṣ

Perl 5 -pF//, 45 bytes
$_=/^[a-z\d]+$/?join"",sort@F:"Invalid Input"

Try it online!

C++ (clang), 223 \$\cdots\$ 182 170 bytes
Saved 8 a whopping 20 bytes thanks to ceilingcat!!!
#import<bits/stdc++.h>
int main(){std::string s,i="Invalid input";getline(std::cin,s);sort(begin(s),end(s));for(int c:s)s=c<48|c>122|c>57&c<97?i:s;std::cout<<(s[0]?s:i);}

Try it online!
A program that reads a single string from stdin (handling all invalid cases) and outputs to stdout.

PHP, 92 bytes
$a=str_split($s=$argn);sort($a);echo preg_match('/^[a-z\d]+$/',$s)?join($a):'Invalid input';

Try it online!

Charcoal, 37 bytes
≔⁺⭆χιβη¿∨¬θ⊙θ¬№ηιInvalid inputＦηＦ№θιι

Try it online! Link is to verbose version of code. Explanation:
≔⁺⭆χιβη

Concatenate the digits with the lowercase letters.
¿∨¬θ⊙θ¬№ηι

If the input is empty or contains a character not in the digit letter string, ...
Invalid input

... then output the required error message, ...
Ｆη

... else for each digit and lowercase letter...
Ｆ№θιι

... output each time it appears in the input.


text:
How many ACUs do I have?
Posted from sandbox
The Intro
What is an ACU? This challenge is based on the concept of money and since this is an international community, we all use different currencies, so in keeping with our spirit of inclusiveness, I have invented a new currency called Arbitrary Currency Units (ACUs) specifically for this challenge. In reality, the challenge is the same whether we are using Dollars, Pounds, Euros, Bitcoins, Lao Kip or Baked Beans.
The Idea
It's New Year. We all have ideas about how we can improve things in the coming year. Mine is to save some money but randomly putting money aside quickly becomes uninteresting so I am following up on something I read on a news site last year. Each week, I put the amount of ACUs equal to the week number into a tin and after 52 weeks I will have saved ACU 1378. That's enough for a nice golfing holiday somewhere in 2021!
The Problem
I need an incentive to keep me going with this so I need to know how much I have or will have in the tin on any given date during 2020. For example, if I enter a date before today I want to know how much was in the tin on that date. For a date after today I want to know how much I will have if I stay with the plan.
The Challenge
Write a program or function which will, when given any date in 2020 (apart from 30-31 Dec - see "The Details"), output the number of ACUs that are in my tin.
The Details

Each week in 2020 consists of exactly 7 days.
The first week of the year starts on 1 January 2020.
We are considering only weeks that are completely within 2020. The last week ends on 2020-12-29 so there are exactly 52 weeks and 30/31 December are not included.
Each week I will put a number of ACUs equal to the week number into my tin on the first day of the week, that is on the 1st January I will put 1 ACU into the tin, on the 8th January I will put 2 ACUs, etc. I will at no point take any ACUs out of the tin.

The Rules

Program or function - your choice.
Input in whatever convenient format but it must be a date. I have a feeling that accepting a day-of-year input may trivialise this challenge but I am open to other opinions on this.
Output however you like but it must be a number of ACUs or a string representation of same.
We are only talking about complete weeks in 2020 so you can assume that the input will not include 30 or 31 December. It's up to you how you deal with it if it does.
Don't forget that in 2020 February has 29 days.
Usual loopholes barred and this is code golf so the shortest program/function in each language will be the winner. All languages welcome and I will not be accepting an answer as per current consensus. Upvotes will decide who wins.

A small Python script that generates the expected output for each week is available here Try it online!. The output can also be printed to stick on the side of your tin if you decide to do the same :)

Related.

I hadn't seen that when I was searching for duplicates and it wasn't picked up in sandbox. Maybe not good enough search terms!. Do you consider it to be a duplicate? If so I will delete it.

I don't think it's a duplicate of this one. Yet, it's closely related to several other challenges about triangular numbers.

As long as it is different enough I'll leave it here. Thanks for the feedback and I'm looking forward to your Javascript answer ;)

Can you provide Unix timestamps in the Python script?

This looks like a chameleon challenge combining the one @Arnauld noted and this one: Related

Can we round the answers to the date of Jan 1 2020 if it's not more than a day?

@JL2210 I'm not sure that I understand the question but please feel free to try it.

So do we have to have negative money or just 0?

Is it necessary to support weeks beyond 2020?

Are we allowed to receive input as the number of seconds since 1-1-20 @ 0:00 A.M.?

@JL2210 The tin starts empty and accumulates ACU starting on the 1st Jan so no negative money. Input must be a date.

@schuelermine No. The challenge is specific to 2020. At the end of the year you will remove all of the money, buy something nice then start again on 1 Jan 2021.

@ElPedro Dates on my system are essentially just numbers of seconds since 1st Jan 1970, and I think that what I did satisfies acceptable input rules. Please take a look at my solution. (also I meant negative money for before 2020, but you've made it clear we don't have to support that)

@JL2210 OK, I see what you mean. That's fine.

If accepting a number of seconds since 2020/01/01 is OK, the challenge basically becomes a dupe of this one, with just an additional division... :/

@Arnauld Hmm...very good point. This is why I initially said date only and not number of days. Sorry JL2210, in view of Arnaulds observation I am going to have to revert to date input only.

@ElPedro Alright, revised solution. Please take a look.

APL (Dyalog Extended), 20 19 bytesSBCS
Anonymous tacit prefix function taking [year,month,day] as argument.
2!∘⌊7÷⍨43816-⍨⌂days

Try it online!
⌂days calculate the number of days since 1899-12-31
43816-⍨ subtract 43816; days since 2019 12 18, i.e 14 days weeks extra
7÷⍨ divide by 7; weeks since 2019 12 18, i.e two weeks extra
⌊ floor; whole weeks since 2019 12 18, i.e two weeks extra
∘
2! count the number of ways to choose 2 out of that many
In other words, if \$d(x)\$ is the number of days since 1899-12-31, then the answer is
$${\Big\lfloor{d(x)-43816\over7}\Big\rfloor\choose2}=
{\Big\lfloor{d(x)-43823\over7}\Big\rfloor-1\choose2}=
\sum_{n=1}^{\big\lfloor\frac{d(x)-43823}7\big\rfloor}n$$

It doesn' matter how long I hang out here, I will never understand your APL answers :) +1

@ElPedro That's by staying here here on the main site, but if you start hanging out in the APL Orchard you'll understand very soon.

Thanks. I may well give that a try. Looking to learn something new. This may be it. I think I may need a new keyboard to find all of those strange symbols though :)

@FryAmTheEggman Yes, fixing now.

R, 56 34 bytes
function(d)sum(1:format(d-2,"%V"))

Try it online!
A function taking an R Date as its argument and returning a number. Works because 2019-12-30 was a Monday, strftime(,"%V") returns the ISO week number and then calculates the relevant triangular number.
Thanks to @Giuseppe for saving 17 bytes, and @RobinRyder a further 3!

as.double is shorter than as.integer by a whopping one byte.

sum the first x integers instead -- 39 bytes.

@Giuseppe impressive! I didn’t know : coerced from string.

You can use d-2 instead of d+1461 for -3 bytes. It works because the last 2 days of 2019 are counted as being in week 1 of 2020 (at least on my OS).

Yes, : is weird; I don't think I've ever used it for its interaction between factors, but the docs say: Non-numeric arguments are coerced internally (hence without dispatching methods) to numeric—complex values will have their imaginary parts discarded with a warning.

Perl 6, 33 bytes
{[+] 1..Date.new(24,|@_).week[1]}

Try it online!
Takes input as month,day. This initialises a date in the year 24 (since that year starts on Monday and is a leap year), and calculates the sum of the range of 1 to the current week number.

Awesome but why 24? My Perl is not so good. Sorry.

@ElPedro I use the year 24 since the first week of that year starts on the first of January (assuming Monday is the first day of the week), and the year is a leap year

Very smart idea. Unfortunately I can only upvote once.

JavaScript (ES6),  53  51 bytes
Takes input as (month)(day).
This is longer than my other answer but does not use any date built-in.
m=>g=d=>--m?g(d+31+~m%9%2-(m==2)):~(d=~-d/7)*~-~d/2

Try it online!
Commented version
m =>               // m = month
g = d =>           // g is a recursive function taking the day d
  --m ?            // decrement m; if it's not equal to 0:
    g(             //   do a recursive call:
      d + 31       //     add 31
      + ~m % 9 % 2 //     subtract 1 if (m + 1) mod 9 is odd
                   //     to account for the August -> July transition
      - (m == 2)   //     subtract 1 if m = 2, for February
    )              //   end of recursive call
  :                // else:
    ~(             //   compute the triangular number
      d = ~-d / 7  //   using d' = (d - 1) / 7:
    ) *            //     -floor(d' + 1) *
    ~-~d           //     -floor(d' + 2)
    / 2            //     / 2

JavaScript (ES6),  61 50 49  47 bytes
Assumes that the system is set up to UTC time (as the TIO servers are)
Takes input as (month)(day).
m=>d=>(n=new Date(68,m-1,d+738)/6048e5|0)*-~n/2

Try it online!
How?
Given the month \$m\$ and the day \$d\$, we generate the corresponding date in \$1968\$ (the closest leap year before Epoch) with an additional offset of \$738\$ days.
new Date(68, m - 1, d + 738)

We implicitly coerce this value to a number of milliseconds and divide it by:
$$7\times24\times60\times60\times1000=604800000$$
We discard the decimal part of the result to turn it into a 1-based week index \$n\$ in \$1970\$ (Epoch's year) which is consistent with the week index in \$2020\$.
\$738\$ is the sum of:

a leap year (\$366\$ days) to reach 1969
a non-leap year (\$365\$ days) to reach 1970
a week (\$7\$ days) to go from 0-indexed to 1-indexed

Finally, we return the \$n\$th triangular number \$\dfrac{n(n+1)}{2}\$.

Your explanations are always well good to read. Care to give one for this because I have no idea what is happening here :-/

@ElPedro Done. :)

05AB1E, 20 19 bytes
•Σ₁t•ºS₂+6šI£O+7÷LO

-1 byte thanks to @Arnauld.
Input in the order month, day, year (although the year is ignored).
Try it online.
Explanation:
•Σ₁t•                # Push compressed integer 5354545
     º               # Mirror it: 53545455454535
      S              # Convert it to a list of digits: [5,3,5,4,5,4,5,5,4,5,4,5,3,5]
       ₂+            # Add 26 to each: [31,29,31,30,31,30,31,31,30,31,30,31,29,31]
         6š          # Prepend a 6: [6,31,29,31,30,31,30,31,31,30,31,30,31,29,31]
           I£        # Leave the first month-input items of this list
             O       # And sum those
              +      # Add it to the (implicit) day-input
               7÷    # Integer-divide it by 7
                 L   # Pop and push a list in the range [1,n]
                  O  # And sum that list
                     # (after which the result is output implicitly)

See this 05AB1E tip of mine (section How to compress large integers?) to understand why •Σ₁t• is 5354545.

Alternative 19s: •Σ₁t•ºS₂+IšI£O7/îLO (swapped inputs) or •ë˜¿•ºS₂+I£O+7÷3-LO.

Red, 38 bytes
func[d][(t: pick d - 2 14)*(t + 1)/ 2]

Try it online!
Takes input as a date in any reasonable format: dd-mm-yyyy, yyyy-mm-dd, dd-MMM-yyyy. Red's date datatype fourteenth field holds the week nember.

Python 3.8 (pre-release), 94 \$\cdots\$ 82 77 bytes
lambda d:(n:=(date(*d)-date(2020,1,1)).days//7+1)*-~n/2
from datetime import*

Try it online!
Function takes date as a (year, month, day) tuple and returns the number of ACUs. Tests ported from Arnauld's answer.

I really do like the idea but "Output however you like but it must be a number of ACUs or a string representation of same". Upvoted before the change and won't retract.

@ElPedro Sorry, don't understand. The function returns the number of ACUs as stated.

Sorry also. When I go to TIO it shows True for each input. Sorry if I am missing something.

@ElPedro Those are tests to see if the function returns the expected number of ACUs, If so True is printed, if not False would be printed. I'll change them to print output beside expected output.

@ElPedro Ok, they now print the returned value and the expected value.

Perfect! That's good enogh for me :)

Let us continue this discussion in chat.

Perl 5 -ap -MTime::Local -MTime::Piece, 61 bytes
$_=($w=(gmtime timegm 0,0,0,$F[0],$F[1]-1,24)->week)*($w+1)/2

Try it online!

Ruby, 42 bytes
A function that takes the month and date.
Time#yday returns the day of the year.
->m,d{k=1+~-Time.gm(4,m,d).yday/7;k*-~k/2}

Try it online!

Nice. I need to get into Ruby. I went the Python way.

PowerShell, 48 bytes

Thanks to @mazzy
(1..(((Date|% DayOfYear)/7)+1)|measure -sum).sum

Try it online!
Originally 76 bytes
[Linq.Enumerable]::Sum([Linq.Enumerable]::Range(1,(Get-Date).DayOfYear/7+1))

Try it online!

perhaps you will find it interesting Tips for golfing in PowerShell. in addition, powershell has shorter ways for many linq methods. so your code can be represented as [this is not the shortest powershell code]

@mazzy Thank you for this comment. I love that I've started doing this sort of thing. Its an eye-opener every time I see code that is simpler, shorter and faster than what I could think of :-)

C (gcc), 34 32 38 34 32 bytes
g(n){n=n/604800-2607;n=n*-~n/2;}

Takes as input the number of seconds since January 1st, 1970 (the Unix epoch) at 0:00 AM UTC time.
Explanation:
n=n/604800-2607;

Divide by number of seconds in a week and subtract the number of weeks from Jan 1 1970 to Jan 1 2020 minus one so we don't have to increment later.
n=n*-~n/2;

Return the n'th triangle number. This is equivalent to the ACU calculation but without any builtin language constructs or loops. Due to TIO's calling convention I can assign to the first argument instead of using return.
-2 bytes thanks to Arnauld!
+6 bytes thanks to Arnauld and ElPedro! (:P)
-4 bytes thanks (indirectly) to ceilingcat!
-2 more bytes thanks to ceilingcat!
Try it online!

(n+1) can be turned into -~n. That said, I don't think this input format complies with it must be a date.

@Arnauld It seems that the OP disagrees, unless you're implying that I need a date structure in which case my language doesn't provide one.

There's no need to use a structure. Other answers that are not using date built-ins are just taking the day, the month and the year as separate arguments (like here, here, here, etc.) It is perfectly fine to ignore the year, though.

@Arnauld Alright, revised solution.

@ceilingcat Argh, forgot to change the TIO link. Fixed and I can squeeze a few more bytes out.

PHP, 67 59 57 bytes
<?=(($d=(int)(date(z,strtotime($argv[1]))/7+1))+$d*$d)/2;

Try it online!

Jelly, 23 21 bytes
“¢(Y’b3+29ÄŻ⁸ị++6:7RS

Try it online!
A full program taking the date as three arguments: month, day, year. Alternatively a dyadic link taking the month as its left and day as its right argument. (The year is ignored in any case.) Jelly has no date type, so this needs to generate the cumulative month lengths.

C# (Visual C# Interactive Compiler), 44 bytes
x=>Enumerable.Range(1,x.DayOfYear/7+1).Sum()

Try it online!

TI-BASIC, 26 25 bytes
∑(X,X,1,1+int(7⁻¹(1+dbd(1.012,Ans

Hooray for built-ins!
Input is the compressed version of the end date in the form MM.DDYY or DDMM.YY where MM is the month (e.g. 01), DD is the day (e.g. 24) and YY is the year (in this case, 20).
Input is in Ans.
Output is the wanted result as specified in the challenge.
Update:
In my attempt to fix the code, I somehow made it shorter.
Explanation:
∑(X,X,1,1+int(7⁻¹(1+dbd(1.012,Ans

                    dbd(1.012,Ans  ;difference in days between 1Jan2020 and the
                                   ;  compressed input
                  1+               ;add one to allow 1Jan2020 to be an input
              7⁻¹(                 ;multiply by 1/7
          int(                     ;truncate
        1+                         ;convert week index from 0-indexed to 1-indexed
∑(X,X,1, ...                       ;summation of X from 1 to the above
                                   ;implicit print of Ans

Examples:
1.2420:prgmCDGF28
               6
2.2920:prgmCDGF28
              36
1.3120:prgmCDGF28
              10
1.0120:prgmCDGF28
               1

Note: TI-BASIC is a tokenized language.  Character count does not equal byte count.

Java, 24 characters/bytes
c->c.get(3)*-~c.get(3)/2

Try it online

This is an instance of ToIntFunction as a Lambda function.
c is a reference to a Calendar object.
c.get(3) returns the week of year field (Calendar.WEEK_OF_YEAR == 3)
x*-~x/2 is the triangle number calculation.

Looks good but can you add a link to an online interpreter so we can see the results?

@ElPedro I added a link to try it online.

The calendar should be 2020, not 2019 (change the loop start to be 1, not 0). Additionally, your week won't be starting on 1st January, but the 28th of December

Can you either fix your answer or delete it until you have done so?


text:
Recreate a simplified version of the card game L.L.A.M.A
In LLAMA, you want to dump cards from your hand as quickly as you can, but you might not be able to play what you want.
Each player starts a round with six cards in hand; the deck consists of llama cards and cards numbered 1-6, with eight copies of each. On a turn, the active player can play a card or draw a card. To play a card, you must play the same number as the top card of the discard pile or one number higher (for simplicity, we will follow the rule that if you can play a card of the same number, you will play that card, if not, play the higher card). If a 6 is on the discard pile, you can play a 6 or a llama, and if a llama is on top, you can play another llama or a 1. If you cannot play any cards, you must draw a card.
The round ends when one player empties their hand, who is pronounced as the winner of that round.
Some specifications:
1. The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted)
2. If a player draws a card, they may not play the drawn card in the same round again, i.e. their turn ends after drawing a card.
3. We will play the game with four players.
The output should list the turns taken by each player in the following fashion:
1 - 1
2 - 1
3 - 1
4 - 2
1 - 3
2 - draw
3 - 3
4 - 4
.
.
.
1 - 6
2 - llama
game over, 2 wins.

As always in code-golf, the program with the lowest number of bytes wins.
Edits:
In response to the comments, here are a few additional specifications.

The output may have any format as long as it contains the player number and their action.
The llama card should be a string composed only of letters, no numbers allowed.
At the start of a game, there is a single card on the discard pile, i.e. player 1 cannot play any card.
If the draw deck is empty, the played cards should be reshuffled. As the official rules of the game do not specify what should happen if all cards are drawn and there are no cards in the discard pile, this case does not need to be accounted for.
There is no input, i.e. the shuffled deck and dealing the hand cards must all be done in the program.

Since you mentioned code-golf at the bottom, I've added the tag for it. As for the actual challenge with the game of four players, do we take input, or do we output a random game after randomly shuffling and giving each player six cards when we run the program? As for "The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted)", "7" is a string. ;) I assume you want to say the llama card can be any string except for numbers? Maybe it's better to only allow letters [a-zA-Z] for the llama card (i.e. "A")?

Also, is the output format flexible, or is that example mandatory and we should also output game over, # wins.? Would it be allowed to simply output a list of pairs (i.e. your example would be [[1,1],[2,1],[3,1],[4,2],[1,3],[2,"draw"],[3,3],[4,4],...,[1,6],[2,"llama"]])?

I feel like "1. The llama cards may have any name, but must be stored as a string (e.g. simply using the value 7 as the llama card is not permitted)" adds nothing to the challenge except making it awkward or impossible in some languages.

@JonathanAllan the existence of llama cards does indeed not change anything about the game mechanics, but as it is a part of the official card game, we will include it here despite the added difficulty to code it.

I have no idea about the game, only this specification ...my comment above is regarding the seemingly arbitrary restriction to a string for the llama card (and not allowing say 7 or 0), which, since we take no input and "The output may have any format as long as it contains the player number and their action" seems somewhat moot. I'd suggest allowing anything which cannot be confused with the other cards (on a slightly separate note I'd also suggest allowing 0-indexing of players and cards).

Having answered the OP I concur with @Johnathan. It's a nontrivial problem and it's code golf. Adding the llama and 1-base restriction just added more bytes on top of an already quite big code golf program. Be nice to be able to 0-base or 1-base the players id too. And to be able to output player and card/draw more freely (eg player space card/draw).

Jelly, 94 bytes
Ḣ_þⱮOƑƇ€}ṪṪʋ%7ż⁸ʋṢF,Ḣ;€2¦@¥¥¥F;1ịḢɗ}ɗ,;€”d$}ɗḢ€ḢỊƊ?ṭ€1¦⁸
56Ẋ%7s32s"31,6Ṛç/Ẉ€Ȧ$Ð¿Ṫ€⁺⁺Ḋo”l4R¤ṁżƊ

Try it online!
A set of links which when run niladically returns a list of pairs of [player number, move] where move is l 1 2 3 4 5 6 d. l represents llama and d draw.

Python 3.8 (pre-release), 401 \$\cdots\$ 347 345 bytes
from random import*
d=[*range(7)]*8
shuffle(d)
p=[[d.pop()for i in[1]*6]for j in[1]*4]
o=[*range(1,7)]+['l']
h=[]
s=d.pop()
def g(a):p[n].remove(a);h.append(s);print(f"{n+1}-{o[a]}")
n=3
while all(p):
 n=-~n%4
 if s in p[n]:g(s)
 elif(t:=-~s%7)in p[n]:g(t);s=t
 else:
  if not d:d=h;h=[];shuffle(d)
  p[n]+=[d.pop()];print(f"{n+1}-d")
print(n+1)

Try it online!

Prints player-card for each move.
player is 1 to 4.
card is 1 to 6 or l for llama or d for draw.
Simply prints winner's number at the end.

Charcoal, 127 121 bytes
Ｆl123456Ｆ⁸⊞υι≔⟦⟧θＷυ«≔‽υι⊞θι≔Φυ⁻λ⌕υιυ»≔Ｅ⁴Ｅ⁶⊟θη≔⊟θζ≔⁰εＷ⌊η«≔§ηεδＩ⊕ε-¿⊙δ›²﹪⁻ΣκΣζ⁷«Ｆ¬№δζ≔⎇⁼6ζlＩ⊕Σζζ§≔ηεΦδ⁻λ⌕δζζ»«⊞δ⊟θd»⸿≔﹪⊕ε⁴ε

Try it online! Link is to verbose version of code. Outputs l for llama and d for draw. Winner is person who last played a card. Explanation:
Ｆl123456Ｆ⁸⊞υι≔⟦⟧θＷυ«≔‽υι⊞θι≔Φυ⁻λ⌕υιυ»

Create and shuffle the deck.
≔Ｅ⁴Ｅ⁶⊟θη≔⊟θζ

Deal.
≔⁰ε

Start with player 1.
Ｗ⌊η«

Repeat until someone wins.
≔§ηεδ

Get the current player's hand.
Ｉ⊕ε-

Output the current player.
¿⊙δ›²﹪⁻ΣκΣζ⁷«

If they have a playable card:
Ｆ¬№δζ

if they don't have a matching card,
≔⎇⁼6ζlＩ⊕Σζζ

then increment the last discard, rolling over to l for llama;
§≔ηεΦδ⁻λ⌕δζ

remove the playable card from their hand;
ζ

and print their play.
»«⊞δ⊟θd»

Otherwise draw a card and print that action.
⸿

Move to the start of the next line.
≔﹪⊕ε⁴ε

Update to the next player.