text:
Conway's Prime Game
Specifically, Conway's PRIMEGAME.
This is an algorithm devised by John H. Conway to generate primes using a sequence of 14 rational numbers:
 A   B   C   D   E   F   G   H   I   J   K   L   M   N
17  78  19  23  29  77  95  77   1  11  13  15  15  55
--  --  --  --  --  --  --  --  --  --  --  --  --  --
91  85  51  38  33  29  23  19  17  13  11  14   2   1

For example, F is the fraction 77/29.
So here's how the algorithm finds the prime numbers. Starting with the number 2, find the first entry in the sequence that when multiplied together produces an integer. Here it's M, 15/2, which produces 15. Then, for that integer 15, find the first entry in the sequence that when multiplied produces an integer. That is the last one, N, or 55/1, which yields 825. Write down the corresponding sequence. (The astute among you may recognize this as a FRACTRAN program.)
After some iterations, you'll get the following:
2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132, 116, 308, 364, 68, 4 ...

Note that the last item listed is 4, or 2^2. Behold our first prime number (the 2 exponent) generated with this algorithm! Eventually, the sequence will look like the following:
2 ... 2^2 ... 2^3 ... 2^5 ... 2^7 ... etc.

Thus, yielding the prime numbers. This is OEIS A007542.
The Challenge
Given an input number n, either zero- or one-indexed (your choice), either output the first n numbers of this sequence, or output the nth number of this sequence.
Examples
The below examples are outputting the nth term of the zero-indexed sequence.
 n   output
 5   2275
19   4
40   408

Rules

If applicable, you can assume that the input/output will fit in your language's native Integer type.
The input and output can be given by any convenient method.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Perhaps Conway's prime game would be a more descriptive name for this challenge than Let's Play a Game. That would make it easier to find this challenge back in the future.

Can the output be a float? 408.0 instead of  408 for example.

Unfortunately we don't have a (canonical) "Interpret Fractran" challenge. The one on Stack Overflow is locked.

@dylnan Sure, that's fine.

FRACTRAN, 99 bytes
17/2821 78/2635 19/1581 23/1178 29/1023 77/899 95/713 77/589 1/527 11/403 13/341 15/434 15/62 55/31

Try it online!
The program takes 2*31^n as an input, which is used as the initial state.
All the fractions in the original FRACTRAN program have been divided by 31 (the first unused prime register), so the program stops at the nth iteration.

Cheeky answer. ;-)

Python 3, 173 165 153 145 144 136 135 127 126 125 108 107 104 bytes
f=lambda n:2>>n*2or[f(n-1)*t//d for t,d in zip(b"NM_M\r7",b"[U3&!\r")if f(n-1)*t%d<1][0]

Try it online!

-30 bytes thanks to Jonathan Frech!
-3 bytes thanks to Lynn!

2>>n*2 is 2 for n==0 and 0 otherwise.
103 bytes if we can return floats.

Using Python 2; 153 bytes.

@JonathanFrech Cool, nice trick. Thanks!

Staying in Python 3, 146 bytes!

144 bytes.

Thanks again, you did more than I did now!

I'm trying to work this in

136 bytes? (Surprisingly performant compared to the other versions.)

Nice. Now there are only two references to f(n-1) which improves the speed a lot

135 bytes.

@JonathanFrech What's the reasoning behind orb(b)-3? I didn't translate out all the bytes, but is one of them invalid for a string?

@MorganThrapp I investigated and found that one of the values encodes to an \r which can't be in a string literal but I escaped it by writing in \r into the source code and saved a byte. Thanks for asking because I wouldn't have found that otherwise!

@MorganThrapp Then another 18 bytes

if f(~-n)*t%d<1 gets you down to 104!

@MorganThrapp It was ord(b)-3, because when adding 1, one character still was the backslash \\; shifting the string over by two more places did not require escaping. Using bitstrings and escaping chr(13), as dylnan now did, however, elegantly resolves that issue.

Jelly, 49 43 bytes
×“×NŒçøM_M¢¿ÆÐÐ7‘“[U3&!øçŒ×Æ¿Ç£¢‘:@xḍɗḢ
2Ç¡

Try it online!

-6 bytes thanks to miles

Pity that 0ọ0¤ is inf, otherwise you could have reduced this to 42 bytes...

Python 3, 107 bytes
f=lambda n,k=2:n and f(n-1,[k*a//b for a,b in zip(b"NM_M\r7",b"[U3&!\r")if k*a%b<1][0])or k

Try it online!
Encodes the list of fractions by ziping two bytestrings containing unprintable low-ASCII characters.
If n is zero, we return the argument k; otherwise we recurse with new parameters. Our new k is the first value k*a//b corresponding to some fraction  (a, b) in the list such that k*a//b is an integer, i.e. k*a%b<1.

MATL, 50 bytes
Hi:"'0m26<l~l *,..V'31-*'{uSFA=731-+."!'32-&\w~)1)

Try it online!

Guess which parts of the code are string literals and which are actual statements...

Hi: ... aww, "Hello" to you too, code. :-)

J, 116 110 bytes
g=.3 :0
((1047856500267924709512946135x%&(96#.inv])5405040820893044303890643137x)([:({.@I.@(=<.){[)*)])^:y 2
)

Try it online!
0-indexed; returns the n-th number
Some bytes can be saved by making the verb tacit, but I have problems making  ^: work.
Explanation:
J describes the rational numbers in the form NrD, where N is the numerator and D is the denominator, for example 17r91 78r85 19r51 23r38... I created 2 separate lists for the numerators and denominators and made 2 base-96 numbers from them.
1047856500267924709512946135x%&(96#.inv])5405040820893044303890643137x converts the base-96 numbers to lists and constructs a list of fractions by divinding the two lists.
   1047856500267924709512946135x%&(96#.inv])5405040820893044303890643137x
17r91 78r85 19r51 23r38 29r33 77r29 95r23 77r19 1r17 11r13 13r11 15r14 15r2 55

2 start with 2
^:y repeat the verb on its left n times (y is the argument to the function)
] the right argument (starts at 2, and then uses the result of each iteration)
* multiply the list of fractions by the right argument
(=<.) are the results integer (compare each number with its floor)
{.@I.@ finds the index I. of the first {. of the integers
{[ uses the index to retrieve the number

62 bytes: ('0m26<l~l *,..V'%&(31x-~3&u:)'ztRE@<620,*-! ')&(0{*#~0=1|*)2:

@miles Thanks, I think you must post your solution, it's way better than mine.

05AB1E,  44  43 bytes
0-indexed
2sF•Ë₁ǝßÌ?ƒ¥"h2ÔδD‡béαA5À>,•тв2ä`Š*s‰ʒθ_}нн

Try it online!
Explanation
2                                             # initialize stack with 2
 sF                                           # input times do:
   •Ë₁ǝßÌ?ƒ¥"h2ÔδD‡béαA5À>,•                  # push a base-255 compressed large number
                            тв                # convert to a list of base-100 digits
                              2ä`             # split in 2 parts to stack
                                 Š            # move denominators to bottom of stack
                                  *           # multiply the last result by the numerators
                                   s‰         # divmod with denominators
                                     ʒθ_}     # filter, keep only those with mod result 0
                                         нн   # get the div result

The large number pushed is 17781923297795770111131515559185513833292319171311140201

JavaScript (Node.js), 106 95 bytes

thanks to @Arnauld and @Neil for reducing by 11 bytes

(n,N=2,I=13,B=Buffer(`[U3&!\rNM_M\r7`))=>n--?f(n,N/B.find(x=>N%x<!!++I)*B[I]):N

Try it online!

Managed to squeeze out a couple of bytes but can't help thinking I'm missing something: Try it online!

@Neil There's no need to use the spread operator on Buffer. Also, I think it's safe to put all data in a single buffer: 95 bytes.

@Arnauld The OP used the spread operator (I'm unfamiliar with Buffer so I didn't know any better) but that's a great move with the single Buffer!

@Arnauld correct, updated :)

Pari/GP, 121 bytes
n->a=2;for(i=1,n,a=[x|x<-a*[17/91,78/85,19/51,23/38,29/33,77/29,95/23,77/19,1/17,11/13,13/11,15/14,15/2,55],x\1==x][1]);a

Try it online!

Retina, 213 bytes
K`17/91¶78/85¶19/51¶23/38¶29/33¶77/29¶95/23¶77/19¶1/17¶11/13¶13/11¶15/2¶1/7¶55/1¶17/91¶78/85¶19/51¶23/38¶29/33¶77/29¶95/23¶77/19¶1/17¶11/13¶13/11¶15/2¶1/7¶55/1¶2
\d+
*
"$+"+`((_+)/(_+)¶(.+¶)*)(\3)+$
$1$#5*$2
r`_\G

Try it online! Explanation:
K`17/91¶78/85¶19/51¶23/38¶29/33¶77/29¶95/23¶77/19¶1/17¶11/13¶13/11¶15/2¶1/7¶55/1¶17/91¶78/85¶19/51¶23/38¶29/33¶77/29¶95/23¶77/19¶1/17¶11/13¶13/11¶15/2¶1/7¶55/1¶2

Replace the input with a list of all the fractions, plus the initial integer.
\d+
*

Convert everything to unary.
"$+"+`

Repeat the substitution the number of times given by the original input.
((_+)/(_+)¶(.+¶)*)(\3)+$

Find a denominator that evenly divides the integer.
$1$#5*$2

Replace the integer with the result of the division multiplied by the numerator.
r`_\G

Convert the integer to decimal and output the result.

Attache, 81 bytes
Nest<~{Find[Integral,_*&`//=>Chop[Ords!"0zmt2R6E<@l<~6l2 0*,,*.-.!V "-31,2]]},2~>

Try it online! Outputs a fraction over 1. For example, input 5 returns 2275/1. This can be fixed with plus 2 bytes by prepending N@ to the program.
Explanation
This is a curried function, which curries Nest  with two predefined arguments:
{Find[Integral,_*&`//=>Chop[Ords!"0zmt2R6E<@l<~6l2 0*,,*.-.!V "-31,2]]}

and 2. This last argument is simply the initial seed, and the argument that is passed to this function is the number of iterations to nest the given function.
The following is used to encode PRIMEGAME:
&`//=>Chop[Ords!"0zmt2R6E<@l<~6l2 0*,,*.-.!V "-31,2]]

This is evaluated as such:
A> "0zmt2R6E<@l<~6l2 0*,,*.-.!V "
"0zmt2R6E<@l<~6l2 0*,,*.-.!V "
A> Ords!"0zmt2R6E<@l<~6l2 0*,,*.-.!V "
[48, 122, 109, 116, 50, 82, 54, 69, 60, 64, 108, 60, 126, 54, 108, 50, 32, 48, 42, 44, 44, 42, 46, 45, 46, 33, 86, 32]
A> Ords!"0zmt2R6E<@l<~6l2 0*,,*.-.!V "-31
[17, 91, 78, 85, 19, 51, 23, 38, 29, 33, 77, 29, 95, 23, 77, 19, 1, 17, 11, 13, 13, 11, 15, 14, 15, 2, 55, 1]
A> Chop[Ords!"0zmt2R6E<@l<~6l2 0*,,*.-.!V "-31,2]
 17 91
 78 85
 19 51
 23 38
 29 33
 77 29
 95 23
 77 19
  1 17
 11 13
 13 11
 15 14
 15  2
 55  1
A> &`//=>Chop[Ords!"0zmt2R6E<@l<~6l2 0*,,*.-.!V "-31,2]
[(17/91), (78/85), (19/51), (23/38), (29/33), (77/29), (95/23), (77/19), (1/17), (11/13), (13/11), (15/14), (15/2), (55/1)]

Let's replace this expression with G in the explanation. Our first function becomes:
{Find[Integral,_*G]}

This performs a single iteration of FRACTRAN code over _, the input to the function. It Finds an Integral member (one which is an integer) of the array _*G, which is the input _ multiplied with each member of G. Nest simply applies this transformation the given number of times.
Attache, 42 bytes
I implemented parts of the $langs library, being inspired by this challenge, so I mark this section non-competing.
Needs[$langs]2&FRACTRAN_EXAMPLES.prime.run

This simply queries the list of FRACTRAN_EXAMPLES I have. Each example is a FractranExample instance, which calls the inbuilt FRACTRAN function. The prime example is Conway's PRIMEGAME.

F# (Mono), 215 bytes
let q m=
 let rec i x y=
  if y=m then x
  else[17;91;78;85;19;51;23;38;29;33;77;29;95;23;77;19;1;17;11;13;13;11;15;14;15;2;55;1]|>List.chunkBySize 2|>List.find(fun[n;d]->x*n%d=0)|>fun[n;d]->i(x*n/d)(y+1)
 i 2 0

Try it online!

PHP, 183 bytes (189 with "php" tag)
Golfed :
$t=2;for(;@$i++<$argv[1];){foreach([17/91,78/85,19/51,23/38,29/33,77/29,95/23,77/19,1/17,11/13,13/11,15/14,15/2,55/1]as$n){$a=$t*$n;if(preg_match('/^\d+$/',$a)){$t=$a;break;}}}echo$t;

Ungolfed:
<?php
$t=2;
for(;@$i++<$argv[1];){
    foreach([17/91,78/85,19/51,23/38,29/33,77/29,95/23,77/19,1/17,11/13,13/11,15/14,15/2,55/1] as $n){
        $a=$t*$n;
        if(preg_match('/^\d+$/',$a)){
            $t=$a;break;
        }
    }
}
echo $t;

Try it online!

MMIX, 84 bytes (14 instrs + 28 data bytes)
jxd (everything from 5b553326 ([U3&) on is data)
00000000: e3010002 f7010000 5a000002 f8020000  ẉ¢¡£ẋ¢¡¡Z¡¡£ẏ£¡¡
00000010: f402000a 83030200 1e040103 feff0006  ṡ£¡½³¤£¡œ¥¢¤“”¡©
00000020: 23020201 5bfffffc 8303020d 1a010304  #££¢[””‘³¤£Æȷ¢¤¥
00000030: 27000001 f1fffff5 5b553326 211d1713  '¡¡¢ȯ””ṫ[U3&!øçŒ
00000040: 110d0b0e 0201114e 13171d4d 5f4d010b  ×Æ¿Ç£¢×NŒçøM_M¢¿
00000050: 0d0f0f37                             ÆĐĐ7

Disassembly and explanation:
primegm SET  $1,2           // i = 2
        PUT  rD,0           // prep for division
0H      PBNZ $0,1F          // loop: if(steps) goto pass
        POP  2,0            // return i
1H      GETA $2,0F          // pass: den = &denoms
1H      LDBU $3,$2          // try: d = *den
        DIVU $4,$1,$3       // n = i / d
        GET  $255,rR        // r = i % d
        ADDU $2,$2,1        // den++
        PBNZ $255,1B        // if(r) goto try
        LDBU $3,$2,13       // d = den[13] (the numerator)
        MULU $1,$3,$4       // i = n * d
        SUBU $0,$0,1        // steps--
        JMP  0B             // goto loop
0H      BYTE 91,85,51,38,33,29,23,19,17,13,11,14,2,1    // denoms: [BYTES]
        BYTE 17,78,19,23,29,77,95,77,1,11,13,15,15,55   // nums: [BYTES]

It's quite useful that every single numerator and denominator fits into one byte. Else I'd have needed to use much more space to fit them.


text:
Simple String Reflection
Let's start by defining a reflection of a character in a string:

Given a string with distinct lowercase alphabetical letters with no spaces such
  as abcdefg, define a reflection of a letter in the string c as
  moving it (without changing the order of any other letter) to a new
  place in the string such that the number of letters originally to the
  right of it is now the number of letters to the left of it.

Thus, a reflection of the letter c in abcdefg would be abdecfg. Explanation: there were 4 letters to the right of c and now, there are 4 letters to the left of c.
Some more examples:

Reflecting the character e in myfriend would form the string myefrind
Reflecting the character a in axyz would form the string xyza.
Reflecting the character b in abc would form the string abc.
Reflecting the character d in d would form the string d.
Reflecting the character e in ef would form the string fe.

For more information or to try out some test cases, here is a (somewhat long) program I wrote in C++.
The Challenge
Given a string with distinct lowercase letters, go through each character alphabetically and "reflect" it in the string.
Clarifications: The letters in the string are from a-z, there are no spaces, the letters are unique, and the string is at least 1 letter long and at most 26 letters long.
Examples

Input: dcba. Output: dcba.

Reason: First, reflect the a as it is the character in the string that comes earliest in the alphabet. You will get adcb. Then, reflect the b as it comes next in the alphabet, to get badc. Then, reflect the c to get cbad, and then the d to get dcba.

Input: myface. Output: fyecma.

Hint: Go through the letters in the order a, c, e, f, m, y.

Input: a. Output: a.

Input: acb. Output: bac.

Input: cwmfjordbankglyphsvextquiz. Output: ieabhqzugdltkfnvpjxsormycw.

Scoring

The input and output can be given by any convenient method.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
Accepting ~100 hours after posting.

Current Winner

 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

Could anyone give me insight as to whether this puzzle is okay? It's my second one here (my first was closed as off-topic...whoops). I tried to make it really complete, but I'm not sure if I'm missing anything. I'd really like to improve and have fun on this SE! Thanks guys :D

This looks good. I might give a few longer examples (in particular, it might be good for the first examples section to present more than what are seemingly edge cases).

@EsolangingFruit Okay, thank you so much for your comment! I really appreciate it. Will do :D

Clarification request: "the letters are unique" means each letter occurs only once in input, is that correct?

Can we take the input and output in uppercase instead of lowercase?

@NL628 By the way, if you want to get insight on a challenge before posting it here, then post it in the Sandbox.

@GPS That is correct.

@EriktheOutgolfer Oh no! Was I supposed to post there instead? Aiyaa sorry about that...I'm really sorry :(

@KevinCruijssen I would prefer it to be in lowercase, but if you think of a really cool one, I'll edit the question to allow either ALL uppercase or ALL lowercase.

@NL628 No, nobody ever has to post it there, it's just a recommendation.

Okay @EriktheOutgolfer Thank you so much!

Brain-Flak, 188 bytes
<>((((()()()){}){}()){}){(({}[()])<({}[(((((()()()()()){}){}){})()){}{}])<>{<>(({})<({}<>({}<>))((){[()](<{}>)}{}){{}(<({}<([]<<>{({}<>)<>}<>>){({}[()]<({}<>)<>>)}{}>)>)}{}>)<>}<>{}<>>)}<>

Try it online!
In addition to the reflections described in the challenge specification, this code also reverses the string exactly 26 times.  This has no effect on the final output.
# Push 26
<>((((()()()){}){}()){})

# Do 26 times:
{(({}[()])<

  # Subtract 122 from counter to get negative lowercase letter
  ({}[(((((()()()()()){}){}){})()){}{}])

  # For each character in string:
  <>{

    # Keep a copy of pivot letter on the third stack
    <>(({})<

    # Move next letter to other stack and compare to pivot
    ({}<>({}<>))

    # If letters are equal:
    ((){[()](<{}>)}{}){

      # Keep current letter separate from this transformation
      {}(<({}<

      # While keeping a copy of current stack height:
      ([]<

        # Move all letters to one stack
        <>{({}<>)<>}<>

      >)

      # Move a number of letters equal to old stack height back
      {({}[()]<({}<>)<>>)}{}

      >)>)

    }{}>)<>

  }

  # Destroy pivot letter
  <>{}<>

>)}

# Switch stack for output
<>

Wow that's pretty amazing. I can't even understand it :O +1

05AB1E, 20 17 bytes
{vð.øy¡€áÂ€gsJ£yý

Try it online!
Explanation
With example for the first iteration of myface
{v                  # for each char y in sorted input
  ð.ø               # surround current string with spaces
                    # STACK: ' myface '
     y¡             # split at current letter
                    # STACK: [' myf', 'ce ']
       €á           # remove non-letters
                    # STACK: ['myf','ce']
         Â€g        # get the length of each string in the pair, reversed
                    # STACK: ['myf','ce'], [2,3]
            sJ      # join the pair back to a string
              £     # split into 2 pieces of the calculated sizes
                    # STACK: ['my','fce']
               yý   # join on the current char y
                    # STACK: 'myafce'

The string is surrounded with spaces each iteration as splitting on the first or last letter of the string would result in a length-1 list otherwise and the merge wouldn't include that letter.

17 bytes?!??!! AMAZING..yet mnemonic is beating you by just one byte :P

Mmmm... Wow, only thing I could see is removing the surround with spaces. Seems odd we can't find another alternative to that.

@MagicOctopusUrn: It's the shortest way I've found of handling a split of the first or last character. It does feel like a lot of bytes just for that though

Pyth, 18 16 19 16 bytes
VSQ=QXx_QN-QNN)Q

Try it here
Explanation
VSQ=QXx_QN-QNN)Q
VSQ           )       For each character (N) in the sorted input (Q)...
          -QN         ... remove the character from Q...
      x_QN            ... get the reflected position...
     X       N        ... insert N...
   =Q                 ... and save the result into Q.
               Q      Output the final result.

Wow 16 bytes? I would upvote, but sadly I've reached my daily voting limit. Will do in 6 hours :P

Python 3, 80 73 bytes
Thanks to Esolanging Fruit for reminding me that functions can return by modifying their argument.
lambda x:[x.insert(len(x)+~x.index(i),x.remove(i)or i)for i in sorted(x)]

Try it online!
Takes input as a list of characters.

Wow I wrote an answer in C++ and Python 3 also. My Python 3 answer was exactly twice as long as yours... +1

Python 2, 70 bytes
def f(t):
 for c in sorted(t):i=t.index(c);l=len(t)+~i;t[l:l]=t.pop(i)

Try it online!
Modifies the input list

JavaScript, 85 80 79 bytes
-6 bytes thanks to @DanielIndie
a=>[...a].sort().map(i=>a.splice(s=a.indexOf(i),1)&&a.splice(a.length-s,0,i))&&a

Try it online!

this doesnt "compile" a is a string and you use splice

@DanielIndie Input should be passed as an array of characters, just like Jo King's Python solution.

80 bytes

you dont return anything from that function, or print it

@DanielIndie Functions can return by modifying their arguments.

79 bytes

You can save 4 bytes by changing a.length-s to -s|1e9.

@RickHitchcock Wait, how does that work?

If the first parameter to splice is a negative number, it's taken from the end.  So a.length-s is the same as -s unless s is zero.  In that case, we use 1e9, which will be treated as the length of the array.

Any number between -1 and -512 bitwise or'd with 1e9 won't change.

Ruby, 51 bytes
->s{s.sort.map{|c|s.insert~s.index(c),s.delete(c)}}

Try it online!
Takes an array of chars
Returns by modifying the input

Java 8, 140 96 92 88 87 85 bytes
s->{for(char c=9;++c>0;){int i=s.indexOf(c);if(i>=0)s.add(s.size()+~i,s.remove(i));}}

-44 bytes creating a port of @TFeld's Python 2 answer.
-6 bytes thanks to @OlivierGrégoire.
Modifies the input List instead of creating a new one.
Explanation:
Try it online.
s->{                     // Method with ArrayList<Character> parameter and no return-type
  for(char c=9;++c>0;){  //  Loop over all characters known
                         //  (except for the first 9 unprintables)
    int i=s.indexOf(c);  //   Index of the character, or -1 of it isn't present
    if(i>=0)             //   If the current character is present in the List
      s.add(s.size()+~i,s.remove(i));}}
                         //    Change the position of this character to index `l-i-1`,
                         //    (where `l` is the size of the input-List)

s->{for(char c=96;++c<123;){int i=s.indexOf(c);if(i>=0)s.add(s.size()+~i,s.remove(i));}}

@OlivierGrégoire Thanks. And 1 more looping over more than just the alphabet characters. :)

Well, if you go that road, for(char c=9;++c>1;) is better ;-)

@OlivierGrégoire Ah of course, char also wraps around like Integer.MAX_VALUE + 1 == Integer.MIN_VALUE.. Smart!

@OlivierGrégoire s is an ArrayList, so indexOf will be of generic type T (which is Character for this input list).

Pffff... That's it: mixed the input type in my golfs... My bad. sorry. Deleting all my comments

Retina 0.8.2, 61 bytes
$
a
{`(.)(.*)\1$
$2$.`$*_$1$1
+`(.)_(_*.)
$2$1
}T`_l`l!`.$
!

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

Start the loop at a.
{`(.)(.*)\1$
$2$.`$*_$1$1

If the input contains the current letter, move it to the end, with a string of _s representing its original position.
+`(.)_(_*.)
$2$1

For each _ move the letter back one character.
}T`_l`l!`.$

Increment the letter. After z change it to a ! so it doesn't match anything and the loop ends.
!

Delete the !.

R, 73 72 69 bytes
function(s){for(x in sort(s))s=append(s[x!=s],x,match(x,rev(s))-1);s}

Try it online!
Inputs and outputs a vector of characters.

ew, using c as a variable name? that's awful, even for code golf!

Well, I can obviously change it, but I am really surprised to see that it could bother anybody here. I actually tend to give priority to preserving some sense in variable names (like c for char) rather than unused built-ins.

well, when looking for an improvement (which, I didn't) I found myself trying to use c, and it was awful when I couldn't figure out what was happening. I typically use K or k or even C just to avoid problems like that, but I totally get it. append is def the right tool for the job.

Oh, I see, sorry about that, will try to avoid setting such "traps" in future.

Red, 96 94 bytes
2 bytes saved thanks to Kevin Cruijssen
func[x][foreach c sort copy x[i:(length? x)+ 1 - index? find x c insert at replace x c""i c]x]

Try it online!
More readable:
f: func[x][
    foreach c sort copy x[                  ; for each symbol in the sorted input
       i: (length? x) + 1 - index? find x c ; find its index and reflect it
       insert at replace x c "" i c         ; remove it by replacing it with an empty char
                                            ; and insert the symbol at its new index
    ]
    x                                       ; return the transformed string
]

You can save 2 bytes by changing find x c replace x c""insert at x i c to find x c insert at replace x c""i c to get rid of an x and space.

@Kevin Cruijssen Thank you, Kevin, it's much better now!

Japt, 23 22 bytes
¬n rÈ+S kY iYJ-XbY)x}U
¬n                     // Split the input into chars and sort it.
   r                }U // Then reduce the result with initial value of the input.
    È+S                // Append a space for replacing edge cases and
        kY             // remove the current char from the string.
           iY          // Insert it back
             J-XbY     // at the calculated index,
                  )x   // and remove the unnecessary space once we're done.

Saved one byte thanks to Oliver.
Try it online!

Nice one. You can replace ,É with J

@Oliver Thanks a lot, I still forget to use the default variables every now and then, that's very handy.

Jelly,  12  11 bytes
W;ṢḟṁUṣ¥jʋ/

A monadic link accepting a list of characters and returning a list of characters.
Try it online!
How?
W;ṢḟṁUṣ¥jʋ/ - Link: list of characters V  e.g. "myface"  ...i.e. ['m','y','f','a','c','e']
W           - wrap V in a list                 ["myface"]
  Ṣ         - sort V                           ['a','c','e','f','m','y']
 ;          - concatenate                      ["myface",'a','c','e','f','m','y']
          / - reduce with:
         ʋ  -   last four links as a dyad:
            -   (i.e. start with "myface" on the left and 'a' on the right
            -         2nd iteration has that result on the left and 'c' on the right
            -         and so-forth)            e.g. left = myface, right = 'a'
   ḟ        -     filter out (right from left)      "myfce"
       ¥    -     last two links as a dyad:
     U      -       upend left                      "ecafym"
      ṣ     -       split at occurrences of right   ["ec","fym"]
    ṁ       -     mould (ḟ(x,y)) like (Uṣ¥(x,y))    ["my","fce"]
         j  -   join with right                   "myafce"

Ok well this one pretty much wrecks everything else...

Well I think that's what Jelly is for - I half expect Dennis (Jelly's creator) to submit a shorter one!

Lol that's pretty amazing :P but I can't upvote b/c I used up my daily vote count..rip

...I think there may be a way to save a byte by use of ḟ(filter out) but I have not managed it yet.

...Beyond my comprehension :O

looks like, time-wise, it's O(n log n) in the length of the input since it first uses Python's sorted and then runs through n iterations of what appear to be less complex operations (flattening, splitting at found indices, joining, reversing). -- and Python's sorted is O(n log n).

Oh lol okay thanks! :D

Perl 5 -p, 37 bytes
#!/usr/bin/perl -p
for$a(a..z){s/$a//&&s/.{@{-}}$/$a$&/}

Try it online!

Vyxal, 15 12 10 bytes
s(n/₌ṅtLnṀ

Thanks to @AndrovT and @TheThonnu!
Try it Online!

I don't think the first : is needed, since inputs are reusable

@TheThonnu Yes that works!

It actually doesn't work on the rest of the test cases and it doesn't work if you add the : either :(

Yes needs correction!

Hope this works (o_o)

@AndrovT link is duplicated, don't see your answer!

oops, 10 this time for real

Aha, thanks! I I thought of ₌  but put it in wrong place (

@lesobrod yep, well done!

C (clang), 164 162 bytes
y,n,a,b,c,p,i;f(char*s,l){for(i=0;p=0,++i<123;p<l&&(y=s[p],n=l+~p,a=p+1,b=p,n<p&&(a=n,b=n+1),c=l+~(2*(n<p?n:p)),memmove(s+b,s+a,c),s[n]=y))while(s[p]^i&&p<l)p++;}

Try it online!
f() takes char-array containing input string and length of this array as parameters and performs required reflections in place.
callf() does pretty-printing.
Credits
-2 bytes. @Kevin. Thanks

You can remove the space at char *s and change i=96 to i=9 to save 2 bytes.

Good catch.. we needn't start from a. Thanks

144 bytes

Perl, 74 70 bytes
84 80 bytes including invocation as unix filter
for$c(a..z){if($p=1+index$_,$c){substr$_,$p-1,1,"";substr$_,-$p,0,$c}}

$ echo -e 'dcba\nmyface\na\nacb\ncwmfjordbankglyphsvextquiz' |
> perl -pE'for$c(a..z){if($p=1+index$_,$c){substr$_,$p-1,1,"";substr$_,-$p,0,$c}}'
dcba
fyecma
a
bac
ieabhqzugdltkfnvpjxsormycw

Haskell, 87 bytes
s#c|(h,_:t)<-span(/=c)s,(v,w)<-splitAt(length t)$h++t=v++c:w|1<2=s
f s=foldl(#)s['a'..]

Try it online!
f s=foldl(#)s['a'..]         -- fold the function '#' into all characters from 'a'
                              -- with the starting value of the input string s
s#c=                          -- in each step (s: result so far, c: next char)
   (h,_:t)<-span(/=c)s        -- let 'h' be the substring before 'c' and
                              -- 't' the substring after 'c'. the pattern match
                              -- fails if there's no 'c' in 's'
   (v,w)<-splitAt(length t)$h++t
                              -- split the string 'h++t' at index length of t
   =v++c:w                    -- return 'v' followed by 'c' followed by 'w'
   |1<2=s                     -- if there's no 'c' in 's', return 's' unchanged

Why does this halt? Shouldn't folding over an infinite list cause an infinite loop? Shouldn't it be f s=foldl(#)s['a'..'z']?

@user1472751: ['a'..] is not infinite, because Char belongs to class Bounded. A list with ..] of Bounded values stops at maxBound.  Try: print  [False ..].

SNOBOL4 (CSNOBOL4), 132 128 bytes
	DEFINE('I(I)')
I	U =&LCASE
N	U LEN(1) . K REM . U	:F(RETURN)
	I ARB @S K	:F(N)
	I K =
	I ARB . L RPOS(S) REM . R
	I =L K R	:(N)

Try it online!
Straightforward implementation of the required algorithm. Saved a few bytes by switching to a function rather than a full program; the explanation remains the same, more or less.
	I =INPUT			;* read input
	U =&LCASE			;* alias for lowercase letters (it started out as uppercase)
N	U LEN(1) . K REM . U	:F(O)	;* set K to the next lowercase letter, and when empty, goto O
	I ARB @S K	:F(N)		;* set S to the number of letters before K, or goto N
	I K =				;* remove K
	I ARB . L RPOS(S) REM . R	;* set R to the last S characters of I and L to the others
	I =L K R	:(N)		;* recombine the string and goto N
O	OUTPUT =I			;* print new string
END

APL+WIN, 63 bytes
Prompts for input string
l←s[⍋⎕av⍳s←,⎕]⋄⍎∊(⍴s)⍴⊂'s←(n←⌽~s=↑l)\s~↑l⋄((~n)/s)←↑l⋄l←1↓l⋄'⋄s

Explanation:
l←s[⍋⎕av⍳s←,⎕] sort characters into alphabetical order

⍎∊(⍴s)⍴⊂'....' create an implicit loop for each character

s←(n←⌽~s=↑l)\s~↑l⋄((~n)/s)←↑l do the relection for first character in l

l←1↓l drop the first character in l

s display the result

⋄ statement separator

source: Stack Exchange

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

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

sort: votes


text:
Number of surjections
Task
Given 2 positive integers n and k, where n > k, output the number of surjections from a set of n distinguishable elements to a set of k distinguishable elements.
Definition
A function f: S → T is called a surjection if for every t∈T there is s∈S such that f(s) = t.
Example
When n=3 and k=2, the output is 6, since there are 6 surjections from {1,2,3} to {1,2}:

1↦1, 2↦1, 3↦2
1↦1, 2↦2, 3↦1
1↦1, 2↦2, 3↦2
1↦2, 2↦1, 3↦1
1↦2, 2↦1, 3↦2
1↦2, 2↦2, 3↦1

Testcases
n k output
5 3 150
8 4 40824
9 8 1451520

Reference

OEIS A019538

Scoring
This is code-golf. Shortest answer in bytes wins.
Standard loopholes apply.

A definition of surjection would be nice.

Is it intentional that n cannot equal k?

@Dennis I like to exclude every possible edge case from my challenges

That seems like an important edge case to include. My guess is that most answers that work for n>k will also work for n==k but it might allow for some sneaky golfing somewhere

@ whoever voted to close what is your reason?

Jelly, 5 4 bytes
ṗṬML

This is an O(kn) brute force solution.
Try it online!
How it works
ṗṬML  Main link. Left argument: k. Right argument: n.

ṗ     Cartesian power; yield the list of all n-tuples over {1, ..., k}.
      Each tuple represents a (not necessarily surjective) function from
      {1, ..., n} to {1, ..., k}.
 Ṭ    Apply the "untruth" atom to each tuple.
      Ṭ maps a list of indices to an array with 1's at those indices, and exactly
      as many zeroes as needed to build the array.
      Examples:
           [1, 2, 3, 3, 3] -> [1, 1, 1]
           [1, 3, 5]       -> [1, 0, 1, 0, 1]
           [2, 6, 2, 4, 4] -> [0, 1, 0, 1, 0, 1]
  M   Yield all indices of maximal elements, i.e., all indices of [1] * k.
   L  Take the length.

Haskell, 48 bytes
s(_,1)=1
s(1,_)=0
s(m,n)=n*(s(m-1,n-1)+s(m-1,n))

Try it online!
Why is the surjection count s(m,n)=n*s(m-1,n-1)+n*s(m-1,n)?
in order to harvest n images, i can either

squeeze a singleton [m] creation into any of
the n boundaries surrounding n-1 groups
or add my new m into any of n already existing groups of [1..m-1]

Haskell, 38 bytes
m#n|n<2=1|m<2=0|o<-m-1=n*(o#(n-1)+o#n)

Try it online!

38 bytes by using an infix operator: Try it online!

Lean, 66 bytes
def s:_->nat->nat|(m+1)(n+1):=(n+1)*(s m n+s m(n+1))|0 0:=1|_ _:=0

Try it online!

Proof of correctness
Try it online!

Explanation
Let us ungolf the function:
def s : nat->nat->nat
| (m+1) (n+1) := (n+1)*(s m n + s m (n+1))
| 0     0     := 1
| _     _     := 0

The function is defined by pattern matching and recursion, both of which have built-in support.
We define s(m+1, n+1) = (n+1) * (s(m, n) + s(m, n+1) and s(0, 0) = 1, which leaves open s(m+1, 0) and s(0, n+1), both of which are defined to be 0 by the last case.
Lean uses lamdba calculus syntax, so s m n is s(m, n).

Now, the proof of correctness: I stated it in two ways:
def correctness : ∀ m n, fin (s m n) ≃ { f : fin m → fin n // function.surjective f } :=
λ m, nat.rec_on m (λ n, nat.cases_on n s_zero_zero (λ n, s_zero_succ n)) $
λ m ih n, nat.cases_on n (s_succ_zero m) $ λ n,
calc fin (s (nat.succ m) (nat.succ n))
   ≃ (fin (n + 1) × (fin (s m n + s m (n + 1)))) :
  (fin_prod _ _).symm
... ≃ (fin (n + 1) × (fin (s m n) ⊕ fin (s m (n + 1)))) :
  equiv.prod_congr (equiv.refl _) (fin_sum _ _).symm
... ≃ (fin (n + 1) × ({f : fin m → fin n // function.surjective f} ⊕
         {f : fin m → fin (n + 1) // function.surjective f})) :
  equiv.prod_congr (equiv.refl _) (equiv.sum_congr (ih n) (ih (n + 1)))
... ≃ {f // function.surjective f} : s_aux m n

def correctness_2 (m n : nat) : s m n = fintype.card { f : fin m → fin n // function.surjective f } :=
by rw fintype.of_equiv_card (correctness m n); simp

The first one is what is really going on: a bijection between [0 ... s(m, n)-1] and the surjections from [0 ... m-1] onto [0 ... n-1].
The second one is how it is usually stated, that s(m, n) is the cardinality of the surjections from [0 ... m-1] onto [0 ... n-1].

Lean uses type theory as its foundation (instead of set theory). In type theory, every object has a type that is inherent to it. nat is the type of natural numbers, and the statement that 0 is a natural number is expressed as 0 : nat. We say that 0 is of type nat, and that nat has 0 as an inhabitant.
Propositions (statements / assertions) are also types: their inhabitant is a proof of the proposition.

def: We are going to introduce a definition (because a bijection is really a function, not just a proposition).
correctness: the name of the definition
∀ m n: for every m and n (Lean automatically infers that their type is nat, because of what follows).
fin (s m n) is the type of natural numbers that is smaller than s m n. To make an inhabitant, one provides a natural number and a proof that it is smaller than s m n.
A ≃ B: bijection between the type A and the type B. Saying bijection is misleading, as one actually has to provide the inverse function.
{ f : fin m → fin n // function.surjective f } the type of surjections from fin m to fin n. This syntax builds a subtype from the type fin m → fin n, i.e. the type of functions from fin m to fin n. The syntax is { var : base type // proposition about var }.
λ m : ∀ var, proposition / type involving var is really a function that takes var as an input, so λ m introduces the input. ∀ m n, is short-hand for ∀ m, ∀ n,
nat.rec_on m: do recursion on m. To define something for m, define the thing for 0 and then given the thing for k, build the thing for k+1. One would notice that this is similar to induction, and indeed this is a result of the Church-Howard correspondence. The syntax is nat.rec_on var (thing when var is 0) (for all k, given "thing when k is k", build thing when var is "k+1").

Heh, this is getting long and I'm only on the third line of correctness...

J, 19 bytes
-/@(^~*]!0{])],i.@-

Try it online!
Explanation
-/@(^~*]!0{])],i.@-  Input: n (LHS), k (RHS)
                  -  Negate k
               i.@   Range [k-1, k-2, ..., 0]
             ]       Get RHS
              ,      Join, forms [k, k-1, ..., 0]
   (        )        Dyad between n (LHS), [k, k-1, ..., 0] (RHS)
           ]           Get RHS
         0{            Select value at index 0
       ]               Get RHS
        !              Binomial coefficient
    ^~                 Raise each in RHS to power of n
      *                Multiply
-/@                  Reduce from right to left using subtraction (forms alternating sum)

-/@(^~*]!0{])]-i.

Husk, 7 bytes
#`¦ḣ¹π²

Try it online!
Explanation
#`¦ḣ¹π²  Inputs: n (²), implicit k (¹)
     π²  Cartesian power of [1..k] to n
#        Count if:
   ḣ¹      Range [1..k]
 `¦        Is a subset

Python 2, 56 53 50 bytes
f=lambda n,k:n/k and(1/k or f(n-1,k-1)+f(n-1,k))*k

Try it online!
-3 bytes thanks to H.PWiz.
-3 bytes thanks to Dennis.

If n<k not all k can be mapped onto thus there are no surjections. n/k and takes care of this.
Taking f(0,0)=1 gives us the only nonzero base case we need. 1/k or achieves this.

R, 49 bytes
function(n,k,j=0:k)((-1)^(k-j)*j^n)%*%choose(k,j)

Try it online!
Implements one of the formulas by Mario Catalani:
T(n, k) = Sum_{j=0..k} (-1)^(k-j)*j^n*binomial(k, j)

or alternately:
T(n, k) = Sum_{j=0..k} (-1)^j*binomial(k, j)*(k-j)^n

which yields the same byte count in R.

Ruby, 46 bytes
f=->n,k{k>n ?0:k+n<1?1:k*(f[n-=1,k]+f[n,k-1])}

Try it online!
Standard recursive approach...

Brain-Flak, 142 bytes
({}<({}()){({}[(())]<<>{({}({})<>)<>}{}>)}{}>)<>{<>(({}<>)<{({}[()]<([])({([{}]()({}))([{}]({}))}{}[{}])>)}{}({}<>)>)<>}<>{}{}{({}<>[{}])<>}<>

Try it online!
This uses the standard inclusion-exclusion formula.
I can't write up a full explanation at this time, but here's a high-level explanation:
# Compute k-th row of Pascal's triangle
({}<({}()){({}[(())]<<>{({}({})<>)<>}{}>)}{}>)<>

# Multiply each element by n^j (and reverse to other stack)
{<>(({}<>)<{({}[()]<([])({([{}]()({}))([{}]({}))}{}[{}])>)}{}({}<>)>)<>}

# Compute alternating sum
<>{}{}{({}<>[{}])<>}<>

Pari/GP, 38 bytes
(n,k)->Pol(exp(x+O(x^n))-1)^k*n!\x^n%x

Try it online!
Using the formula by Vladimir Kruchinin on OEIS:
E.g.f.: (exp(x)-1)^k = sum T(n,k)x^n/n!

JavaScript (Node.js), 43 bytes
T=(n,k)=>n<k?0:k+n<1||k*(T(--n,k)+T(n,k-1))

Try it online!

05AB1E, 10 bytes
sLsãʒêgQ}g

Try it online!
Explanation
sLsã       # Cartesian product of range(k) repeated n times
    ʒ   }  # Filter by ...
     êgQ   # Connected uniquified length == k  (every item in range(k) appears at least once)
         g # Count

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


text:
Fill out my Bubble Sheet
Today was AP exam registration day at my school, and while I was meticulously bubbling in the pages and pages of information required, the idea for this challenge hit me. So, given a string of letters and numbers, output an appropriately filled out bubble chart.
Rules:

For each character in the input string, replace that character in the corresponding column with a # or @ or any other reasonable symbol (if your language can handle it, the Unicode character 'full_block': █ looks really good)
A space is represented by a blank column (see examples)
Valid input will be a string which is made up of only uppercase letters, numerical digits, and spaces.
Input will be of a length with a minimum of 1, and a maximum of 32 characters.
Output must be UPPERCASE
If the input length is less than the maximum length of 32, your program must still output the remaining blank columns
Your program doesn’t have to handle lowercase input the same as if they were uppercase, but bonus points if it can.

Board Format:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
00000000000000000000000000000000
11111111111111111111111111111111
22222222222222222222222222222222
33333333333333333333333333333333
44444444444444444444444444444444
55555555555555555555555555555555
66666666666666666666666666666666
77777777777777777777777777777777
88888888888888888888888888888888
99999999999999999999999999999999

Examples:
CODE GOLF ->

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
█CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DD█DDDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEE█EEEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFFFFF█FFFFFFFFFFFFFFFFFFFFFFF
GGGGG█GGGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
LLLLLLL█LLLLLLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM
NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN
O█OOOO█OOOOOOOOOOOOOOOOOOOOOOOOO
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP
QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ
RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU
VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
00000000000000000000000000000000
11111111111111111111111111111111
22222222222222222222222222222222
33333333333333333333333333333333
44444444444444444444444444444444
55555555555555555555555555555555
66666666666666666666666666666666
77777777777777777777777777777777
88888888888888888888888888888888
99999999999999999999999999999999

ABCDEFGHIJKLMNOPQRSTUVWXYZ012345 ->

@AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
B@BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
CC@CCCCCCCCCCCCCCCCCCCCCCCCCCCCC
DDD@DDDDDDDDDDDDDDDDDDDDDDDDDDDD
EEEE@EEEEEEEEEEEEEEEEEEEEEEEEEEE
FFFFF@FFFFFFFFFFFFFFFFFFFFFFFFFF
GGGGGG@GGGGGGGGGGGGGGGGGGGGGGGGG
HHHHHHH@HHHHHHHHHHHHHHHHHHHHHHHH
IIIIIIII@IIIIIIIIIIIIIIIIIIIIIII
JJJJJJJJJ@JJJJJJJJJJJJJJJJJJJJJJ
KKKKKKKKKK@KKKKKKKKKKKKKKKKKKKKK
LLLLLLLLLLL@LLLLLLLLLLLLLLLLLLLL
MMMMMMMMMMMM@MMMMMMMMMMMMMMMMMMM
NNNNNNNNNNNNN@NNNNNNNNNNNNNNNNNN
OOOOOOOOOOOOOO@OOOOOOOOOOOOOOOOO
PPPPPPPPPPPPPPP@PPPPPPPPPPPPPPPP
QQQQQQQQQQQQQQQQ@QQQQQQQQQQQQQQQ
RRRRRRRRRRRRRRRRR@RRRRRRRRRRRRRR
SSSSSSSSSSSSSSSSSS@SSSSSSSSSSSSS
TTTTTTTTTTTTTTTTTTT@TTTTTTTTTTTT
UUUUUUUUUUUUUUUUUUUU@UUUUUUUUUUU
VVVVVVVVVVVVVVVVVVVVV@VVVVVVVVVV
WWWWWWWWWWWWWWWWWWWWWW@WWWWWWWWW
XXXXXXXXXXXXXXXXXXXXXXX@XXXXXXXX
YYYYYYYYYYYYYYYYYYYYYYYY@YYYYYYY
ZZZZZZZZZZZZZZZZZZZZZZZZZ@ZZZZZZ
00000000000000000000000000@00000
111111111111111111111111111@1111
2222222222222222222222222222@222
33333333333333333333333333333@33
444444444444444444444444444444@4
5555555555555555555555555555555@
66666666666666666666666666666666
77777777777777777777777777777777
88888888888888888888888888888888
99999999999999999999999999999999

ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ->^^^

And of course, this is code-golf, so shortest answer wins

Input validation is generally discouraged, so you could just have the input match [A-Z0-9]{1,32} and allow any behavior for inputs not matching that.

How ridiculously annoying is the fact that '0' comes before 'A' in ASCII code >:( lol

"Valid input will be a string which is made up of the characters that appear on the bubble sheet as well as spaces" but you also state "Any character other than the capital letters, spaces, and numerical digits, or over the 32 character limit should be ignored", so which one is it?

@Cowsquack by ignored, I mean it shouldn’t be considered at all. For example if the input was $COW the first column would have C marked.

But according to the first statement, you say that $ will not appear in inputs

@Cowsquack you’re right, I over unnecessarily complicated it. I’ll make things more clear

Now that you removed digits and innalid chars from the specs, you may want to also remove them from the examples.

@Titus oh crap I didn’t realize I had done that

@JonathanAllan yes I’m so sorry I edited the wording and forgot to include the digits again

Is trailing whitespace allowed?

Your program doesn’t have to handle lowercase input the same as if they were uppercase, but bonus points if it can. - What exactly does this mean? Do we get to remove some bytes from the byte count?

Ruby, 62 bytes
->s{[*?A..?Z,*?0..?9].map{|c|(0..31).map{|i|c==s[i]??@:c}*''}}

Try it online!
Returns array of strings. Could be golfed further by discarding string joins and returning a 2D array of characters as is usually the norm, but I'm not sure if it is allowed here.

Husk, 23 bytes
mż§?'#|=⁰mR32¤+…"AZ""09

Try it online or try it with the fancy █ character (but an invalid bytecount)!
Unfortunately I wasn't able to merge the two maps into one (except with using parentheses, costing 24 bytes)..
Explanation
mż§?'#|=⁰mR32¤+…"AZ""09"  -- expects string as argument, eg. "FOO"
             ¤            -- with the two strings "AZ" "09" ..
               …          -- | fill ranges: "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                          -- |              "0123456789"
              +           -- .. and concatenate: "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
          m               -- map the following (eg. with 'X')
                          -- | replicate 32 times: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
                          -- : ["A…A","B…B",…,"Z…Z","0…0",…"9…9"]
m                         -- map the following (eg. with "F…")
 ż      ⁰                 -- | zipWith (keeping elements of longer list) argument ("FOO")
  §?   =                  -- | | if elements are equal
    '#                    -- | | | then use '#'
      |                   -- | | | else use the first character
                          -- | : ["#FF…F"]
                          -- : ["A…A",…,"#FF…F",…,"O##O…O",…,"9…9"]

C (gcc), 132 126 bytes
char*s="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",*_,*a;f(char*x){for(_=s;*_;++_,puts(""))for(a=s;*a;)putchar(x[a++-s]-*_?*_:64);}

Try it online!
Thanks to Jonathan Frech for saving 6 bytes.

puts("") is equivalent to putchar(10).

++a)putchar((x[a-s]-*_)?*_:64); -> )putchar(x[a++-s]-*_?*_:64);.

If you are willing to bend the rules a little, you could also golf 64 to 1.

If you do, the putchar call could be golfed to putchar(*_*(*_!=a[x-s]));.

Normally I'd be okay with bending the rules for that... but 1 is a very different beast from a filled rectangle or an @ sign. The other changes are useful though - will update.

By the way, I think your code is partially erroneous, as the X row ends with an @ character.

Though unprintable characters are more box-like than an @.

I suppose... also that bug is due to memory having data in it... we read past the end of s... I think I can save some characters with different indexing.

yeah... it'd be shorter if we could be shorter... as it stands we have to take a string padded to the right length... char*s="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",*_,*a;f(char*x){for(_=s;*_;++_,puts(""))for(a=x;*a;)putchar(*a++-*_?*_:64);}

Charcoal, 21 bytes
Ｅ⁺α⭆…αχκ⭆…◨θφ³²⎇⁼ιλ#ι

Try it online! Link is to verbose version of code. Explanation:
  α  α                  Uppercase alphabet predefined variable
      χ                 Predefined variable 10
    …                   Chop to length
   ⭆                    Map over characters and join
       κ                Current index
 ⁺                      Concatenate
Ｅ                       Map over characters into array
           θ            Input string
            φ           Predefined variable 1000
          ◨             Right pad to length
             ³²         Literal 32
         …              Chop to length
        ⭆               Map over characters and join
                 ι  ι   Current outer character
                  λ     Current inner character
                ⁼       Equals
                   #    Literal `#`
               ⎇        Ternary
                        Implicitly print each result on its own line

Previous version with input validation, 34 32 bytes. Edit: saved 2 bytes thanks to @ASCII-only.
≔⁺α⭆…αχκαＥα⭆…◨Φθ∨⁼ι №αιφ³²⎇⁼ιλ#ι

Try it online! Link is to verbose version of code.

:/ you appear to be missing a close paren at the end

This looks like it works. (Wolfram StringReplace) On a side note, a replace builtin would be really handy right

Never mind, I don't know what I was doing. 27 bytes - you don't need the Cast

Also, re: the pad with arbitrary character you were asking about before: do you think that would be useful enough to add as a builtin? or maybe as a two-character builtin?

23

@ASCII-only There used to be an input validation rule, which makes my answer longer than it needs to be, but thanks for the tips about a) avoiding the Cast on the StringMap b) padding to 1000 and then moulding to 32.

:O That's really short, and oh yeah I remember seeing the rule when I scrolled up

Jelly,  18  17 bytes
ØA;ØDWẋ32ɓ,€⁶y"ZY

Uses a space character. To use a # replace ⁶ with ”# for a cost of one byte.
Try it online!
How?
ØA;ØDWẋ32ɓ,€⁶y"ZY - Main Link: list of characters, S   e.g.  ['S','P','A','M']
ØA                - upper-case alphabet characters           ['A','B',...,'Z']
   ØD             - digit characters                         ['0','1',...,'9']
  ;               - concatenate                              ['A','B',...,'Z','0','1',...,'9']
     W            - wrap in a list                           [['A','B',...,'Z','0','1',...,'9']]
      ẋ32         - repeat 32 times                          [['A','B',...,'Z','0','1',...,'9'],...,['A','B',...,'Z','0','1',...,'9']]
         ɓ        - start a new dyadic chain with that on the right
            ⁶     - space character                          ' '
          ,€      - pair €ach of S with a space              [['S',' '],['P',' '],['A',' '],['M',' ']]
              "   - zip with:
             y    -   translate (replace 'S' with ' ' in 1st, 'P' with ' ' in 2nd, ...) -- Note: zip is a zip-longest, so trailing lists remain
                Z  - transpose
                 Y - join with line-feeds
                   - implicit print

I can save one byte.

Welp, I also got ³Ḣ,⁶yØA;ØD¤µ32Ð¡ZY at 18 which I feel may also be improvable! Going out though...

So, obviously, that's not the byte I'm referring to. :) Try harder...

Amazing I managed to golf on mobile 17 bytes

Mine was actually this, but congrats!

Red, 177 bytes
func[s][m: copy[]foreach c a:"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"[insert/dup r: copy"^/"c 32 append m r]j: 0
foreach c s[j: j + 1 if c <>#" "[m/(index? find a c)/(j): #"@"]]m]

Try it online!
More readable:
f: func[s][
    m: copy[]
    a:"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    foreach c a[
        insert/dup r: copy "^/" c 32
        append m r
    ]
    j: 0
    foreach c s[
        j: j + 1
        if c <>#" "[m/(index? find a c)/(j): #"@"]
    ]
    m
]

R, 104 bytes
function(S,o=""){for(i in 1:32)o=paste0(o,`[<-`(x<-c(LETTERS,1:9),x==substr(S,i,i),"@"))
cat(o,sep="
")}

Try it online!

Node.js, 85 bytes
Port to Node.js suggested by @DanielIndie
f=(s,x=544,c=Buffer([48+x/32%43]))=>x<1696?(s[x&31]==c?'@':c)+[`
`[++x&31]]+f(s,x):''

Try it online!

JavaScript (ES6), 103 98 bytes
f=(s,x=544,n=x>>5,c=String.fromCharCode(48+n%43))=>n<53?(s[x&31]==c?'@':c)+[`
`[++x&31]]+f(s,x):''

Try it online!

90 bytes how about this?

@DanielIndie Thanks! Added. (We don't really need this +"", do we?)

I never know if we need to convert or not so i dont think about it :P but yes, you dont actually need it :)

@DanielIndie Ah, now we can just use x/32 to save 2 more bytes, since Buffer is coercing to integers.

f=(s,x=561,c=Buffer([48+x/33%43]))=>x<1749?(s[x++%33]==c?'@':x%33?c:`\n`)+f(s,x):''

C++14, 319 bytes 237
This is my first time doing this, in the worst possible CodeGolf Language :P
char c;string k="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",s;int main(){map<char,vc>g;g[' ']=vc(32,' ');for(char c:k)g[c]=vc(32,c);getline(cin,s);for(int i=0;i<s.length();i++)g[s[i]][i]='@';for(char d:k){for(char x:g[d])cout<<x;cout<<'\n';}}

Try it Online!

Question: Do I need to include the header?

If it's needed to run the code, it needs to be in your answer.  That said, you can remove pretty much all the whitespace and have this answer still work.

Could I rewrite this as a function with parameters, instead of a main()?

@NL628 yes you can. See tips for golfing in C++ for more help. EDIT: switched link to C++

You can also drop your function's return argument's type.

By the way, I would not say that C++ is the worst possible language to golf in. Try to write your next answer in Java and you will see why.

@Jonathan Frech LOL what about fortran?

@NL628 You have a point there ...

COBOL anyone? I've never written a line of code in it, but using COBOL for code golf might be an interesting challenge.

APL+WIN, 56 bytes
Prompts for input string and uses # character as identifier:
m←⍉32 36⍴⎕av[(65+⍳26),48+⍳10]⋄((,m[;1]∘.=32↑⎕)/,m)←'#'⋄m

Explanation:
m←⍉32 36⍴⎕av[(65+⍳26),48+⍳10] create the table

32↑⎕ pad the input string to 32 characters with spaces

(,m[;1]∘.=32↑⎕) use outer product with = to identify characters in table

((,m[;1]∘.=32↑⎕)/,m)←'#' replace characters with #

m display table

⋄ statement separator

Perl 5 -F, 47 bytes
//,say map{$F[$_]eq$'?'*':$'}0..31for A..Z,0..9

Try it online!

Haskell, 86 bytes
For a much nicer approach (and less bytes), see Laikoni's solution!
f x=(x#).(<$[1..32])<$>['A'..'Z']++['0'..'9']
(a:b)#(u:v)=last(u:['#'|a==u]):b#v
_#w=w

Try it online!
Alternatively for the same byte count we could use:
(a:b)#(u:v)|a==u='#':b#v|0<3=u:b#v

Try it online!
Explanation / Ungolfed
The operator (#) is very similar to zipWith however the function is hardcoded, st. it uses # if two characters are equal and otherwise it keeps the second one, ungolfed:
(a:b) # (u:v)
   | a == u    = '#' : b # v
   | otherwise =  u  : b # v

If the first list is exhausted it just appends the remaining elements of the second one:
_ # w = w

With that helper we only need to generate the string "A..Z0..9", replicate each element 32 times and zip the input with each string, ungolfed:
f x = map ((x#) . replicate 32) (['A'..'Z'] ++ ['0'..'9'])

85 bytes: Try it online!

@Laikoni: Shame that it's just 1 byte less, this is a really clever usage of max. I think you should post that as your own solution since it's very different from my solution.

I posted a 74 byte version.

Haskell, 74 bytes
f x=[do a<-take 32$x++cycle" ";max[c]['~'|a==c]|c<-['A'..'Z']++['0'..'9']]

Try it online! An input string x is padded with spaces to a length of 32 with take 32$x++cycle" ". For each character c from A to Z and 0 to 9, we look at the characters a from the padded input string and replace them by ~ when a and c are equal and by c otherwise. This is achieved by max[c]['~'|a==c], which is e.g. max "A" "~" = "~" when a = c = 'A', and max "A" "" = "A" when c = 'A' and a = 'B'. Because this yields a singleton string instead of a char, the do-notation is used which concatenates the singleton strings into one string.
Based on BMO's Haskell solution.

Python 2, 138 bytes
Supports both upper and lower case chars and leaves an unfilled column for spaces.
def f(s):
 s=s.upper()
 for j in"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789":print"".join(j if(len(s)<=i)or(s[i]!=j)else'@'for i in range(32))

If the bonus isn't worth it, then I'll go for 125 bytes and only support upper case inputs:
def f(s):
 for j in"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789":print"".join(j if(len(s)<=i)or(s[i]!=j)else'@'for i in range(32))

Stax, 15 bytes
╛dδÑ-═E↑\≈Fà±AG

Run and debug it
It uses '#' to indicate a filled bubble.
Unpacked, ungolfed, and commented, it looks like this.
32(     right-pad or truncate to 32
{       begin block for mapping
  VAVd+ "A..Z0..9"
  s'#+  move input character to top of stack and append "#". e.g. "C#"
  |t    translate; replace the first character with the second in string
m       perform map using block
Mm      transpose array of arrays and output each line

Run this one

Retina, 64 bytes
$
36*
L`.{36}
.
36*@$&¶
Y`@`Ld
(.)(.*)\1
@$2
N$`\S
$.%`
L`.{32}

Try it online!

$
36*
L`.{36}

Pads the inputs string on the right with spaces to 36 characters
.
36*@$&¶
Y`@`Ld

Then, put each character on its own line and add ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 before it.
(.)(.*)\1
@$2

Match a pair of the same character on the same line, which there is one if and only if the character for that line matches one of ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789. Replace the first with @ and remove the second.
N$`\S
$.%`

The only unmatched lines are ones with spaces, so the non-space characters is a 36×36 square block. Transpose it.
L`.{32}

Only keep the first 32 characters in each line

Pyth, 23 20 bytes
j.Tm:s+r1GUTdN.[Qd32

Try it here
Explanation
j.Tm:s+r1GUTdN.[Qd32
              .[Qd32      Pad the input to 32 characters.
   m                      For each character...
     s+r1GUT              ... get the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"...
    :       dN            ... with the character replaced by a '"'.
j.T                       Transpose the lines and print them all.

Python 2, 103 96 94 bytes
-7 bytes thanks to Mnemonic
-2 bytes thanks to Jonathan Frech
Uses ' as the symbol
i,l=input(),17;exec"k=chr(l%43+48);print''.join(`k`[i[x:][:1]!=k]for x in range(32));l+=1;"*36

Try it online!

C (gcc), 124 bytes
f(s,b,x,y)char*s,b[33];{sprintf(b,"%-32.32s",s);for(x=0;++x<36;puts(""))for(y=x+21+43*(x<27),s=b;*s;putchar(*s++==y?35:y));}

Try it online!
Instead of a hard-coded array, I replaced it with a lookup function instead. Fortunately the ASCII character set has contiguous alphabetic and numeric ranges (I'm looking at you, EBCDIC!) As well, I made sure to keep the output to exactly 32 characters using sprintf(): if this wasn't a requirement of the task, the function would be 97 bytes:
f(s,i,x,y)char*s,*i;{for(x=0;++x<36;puts(""))for(y=x+21+43*(x<27),i=s;*i;putchar(*i++==y?35:y));}

Try it online!

106 bytes

CJam, 31 bytes
q32Se]{'[,65>A,s+S+_@#St);}%zN*

Try it online! Uses spaces as the "hole" character.

If trailing whitespace is allowed, then this works for 29 bytes:
q32Se]{'[,65>A,s+S+_@#St}%zN*

Try it online!

Here's a 34-byte variation that uses the Unicode full block (█) instead:
q32Se]{'[,65>A,s+S+_@#'█t);}%zN*

Try it online!

Explanation
q                                Input.
    e]                           Pad to a length of
 32                                32
                                 with
   S                               spaces.
      {                   }%     For each character:
                                   Get the uppercase alphabet by
            >                        dropping the first
          65                           65
                                     elements of
         ,                             the range of characters below
       '[                                '['.
                +                  Append
               s                     the string version
              ,                        of the range of numbers below
             A                           10.
                  +                Append
                 S                   a space.
                     #             Find the index of
                    @                the character.
                       t           Set this index to
                      S              a space
                   _               in the original array.
                        );         Drop the space at the end.
                                   Yield this modified array.
                                 End for. The result is an array of arrays of characters.
                            z    Transpose this array, turning rows into columns.
                             N*  Join the result on newlines.

05AB1E, 19 bytes
RтúR32£vžKuÙyð:})ø»

Try it online!
Explanation
R                     # reverse
 тú                   # prepend 100 zeroes
   R                  # reverse
    32£        }      # take the first 32 characters
       v              # for each character
        žK            # push a string of [a-zA-Z0-9]
          uÙ          # upper case and remove duplicates
            yð:       # replace current character with space
                )ø    # transpose
                  »   # join by newline

a[b] doesn't work like you want it here, does it :P?

@MagicOctopusUrn: Unfortunately not. That was my first thought as well, but modular indexing is not our friend in this case :P

MATL, 21 bytes
1Y24Y2vjO33(32:)y=~*c

Uses a space as marker character.
Try it online!
Explanation
1Y2     % Push 'AB...YZ'
4Y2     % Push '01...89'
v       % Concatenate into a 36×1 column vector of chars
j       % Push unevaluated input: string of length n, or equivalently 1×n
        % row vector of chars
O33(    % Write 0 at position 33. This automatically writes a 0 at postions
        % n+1, n+2, ..., 32 too
32:)    % Keep only the first 32 entries: gives a 1×32 row vector
y       % Duplicate from below: pushes a copy of the 36 ×1 column vector
=~      % Test for non-equal entries, with broadcast. Gives a 33×32 matrix
        % containing 0 for matching entries, and 1 otherwise
*       % Multiply this matrix by the 1×32 row vector, with broadcast. This
        % changes each 1 into the corresponding character in the input
c       % Convert to char. Implicitly display. Char 0 is displayed as space

Java 10, 120 118 117 bytes
s->{var r="";for(char c=65,i;c<91&c!=58;r+="\n",c+=c<90?1:-42)for(i=0;i<32;i++)r+=i<s.length&&s[i]==c?35:c;return r;}

Try it online (for TIO I've used '█' (9608 instead of 35) for better visibility).
Explanation:
s->{                   // Method with character-array parameter and String return-type
  var r="";            //  Result-String, starting empty
  for(char c=65,i;     //  Start character `c` at 'A'
      c<91&c!=58       //  Loop as long as `c` is 'Z' or smaller, and is not '9'
      ;                //    After every iteration:
       r+="\n",        //     Append a new-line to the result-String
       c+=c<90?        //     If `c` is not 'Z' yet
           1           //      Go to the next character ASCII-value-wise
          :            //     Else:
           -42)        //      Change the 'Z' to '0'
    for(i=0;i<32;i++)  //    Inner loop `i` in the range [0,32)
      r+=i<s.length    //     If we're not at the end of the input array yet,
         &&s[i]==c?    //     and the characters in the column and array are the same
          35           //      Append the filler-character '#'
         :             //     Else:
          c;           //      Append the current character instead
  return r;}           //  Return the result-String

Common Lisp, 150 bytes
(setq s(format nil"~32a"(read-line)))(map nil(lambda(i)(map nil(lambda(j)(princ(if(eq i j)#\# i)))s)(princ"
"))"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

Try it online!
Explanation
;; pad input to 32 spaces on the right
(setq s(format nil"~32a"(read-line)))
;; for each character in bubble sheet, for each character in input:
;; if characters are equal print "#"
;; else print bubble sheet character
(map nil(lambda(i)(map nil(lambda(j)(princ(if(eq i j)#\# i)))s)(princ"
"))"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")

Tcl, 153 145 bytes
Thanks @sergiol for -8 bytes
lmap i [split ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ""] {puts [join [lmap j [split [format %-32s [join $argv ""]] ""] {expr {$i==$j?"#":$i}}] ""]}

Try it online!
Explanation
# for i in list of choices
lmap i [split ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ""] {
    # print string of
    puts [join
        # list of
        [lmap j
             # for each character in first argument padded to 32 characters
             [split [format %-32s [join $argv ""]] ""]
             # return "#" if current choice and current character are equal, else current choice
             {expr {$i==$j?"#":$i}}
        ]
        ""
    ]
}

152

@sergiol :| yes it is. 146?

145

Prolog (SWI), 235 229 228 222 214 198 173 167 165 bytes
-6 bytes thanks to @Cows quack, -6 bytes thanks to @
                            0                                                                                '

X*[H|T]:-(H=X->write(#);writef("%n",[X])),X*T;nl.
_+[].
X+[H|T]:-H*X,X+T.
?-read(X),swritef(Y,"%32l",[X]),string_codes(Y,Z),Z+`ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`.

Try it online!
Explanation
% if head = bubble char, write "#", else write bubble char, then while tail is non-empty, recurse.
% if tail is empty then print newline
X*[H|T]:-(H=X->write(#);writef("%n",[X])),X*T;nl.
% if list is empty, then do nothing. this prevents t from being called with invalid X
_+[].
% call t, then recurse for each char in list
X+[H|T]:-H*X,X+T.
% read, pad input to 32 chars, and convert input to list
?-read(X),swritef(Y,"%32l",[X]),string_codes(Y,Z),Z+`ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789`.

SNOBOL4 (CSNOBOL4), 155 150 bytes
	I =INPUT
	U =&UCASE '0123456789'
N	U LEN(1) . K REM . U	:F(END)
	O =DUPL(K,32)
	X =
S	I LEN(X) @X K	:F(O)
	O POS(X) K =' '	:S(S)
O	OUTPUT =O	:(N)
END

Try it online!
Explanation:
	I =INPUT			;* read input
	U =&UCASE '0123456789'		;* U = uppercase concat digits
N	U LEN(1) . K REM . U	:F(END)	;* while U not empty, pop first letter as K
	O =DUPL(K,32)			;* dup K 32 times
	X =				;* set position to 0
S	I LEN(X) @X K	:F(O)		;* find the next occurrence of K and save (index - 1) as X
	O POS(X) K =' '	:S(S)		;* replace the X'th occurrence of K with space. If that's before character 32, goto S, else proceed to next line
O	OUTPUT =O	:(N)		;* output the string and goto N
END

PHP, 63 61 bytes
for($c=A;$p<891;)echo$argn[$p++%33]!=$c?$p%33?$c:"
".!$c++:█;

Run as pipe with -nR or try it online.
changed specs (with digits), 80 74 bytes:
for($c=A;$p<1188;)echo$argn[$p++%33]!=="$c"?$p%33?$c:"
".(++$c<B&&$c=0):█;

++$c<B is false for all letters up to Z and for all non-negative numbers.
Z incremented is AA; in that case $c is set to 0 to loop through the digits.
&& casts the whole expression to false, . casts that to the empty string.
Try it online

SOGL V0.12, 19 bytes
,M↕+'»m{Z²²+;╗ŗ}⁰№I

Try it Here!

Octave, 61 bytes
@(s)[((a=[30:55 13:22]'*~~(o=1:32)).*(a+35~=[s o](o)))+35 '']

Try it online!
The function works as follows:
@(s)[                                                     ''] %Anonymous function, taking string, outputting character array
         [30:55 13:22]'                                       %Creates the board alphabet ('A':'Z' '0':'9']) but minus 35 (value of '#')
                       *~~(o=1:32)                            %Matrix multiplication by an array of 32 1's to form the 2D board. Saves 1:32 for later.
      (a=                         )                           %Saves the board mimus 32 to a for use later.
                                            [s o](o)          %Ensures the input is 32 characters long. Missing chars replaced by 1:32 (not in board)
                                     (a+35~=        )         %Compares against board (a+35 as a=board-35). Makes 2D array where matches = 0, others = 1.
     (                             .*                )+35     %Element=wise multiplication, forcing matches to 0. Then add 35 resulting in board with #'s

Perl 6, 57 bytes
{map {<<$^c█>>[.comb[^32]Xeq$c].join},|('A'..'Z'),|^10}

Try it online!

F#, 250 bytes
let b(a:string)=
 let r=List.append['A'..'Z']['0'..'9']
 let mutable d=Map.empty
 for c in r do d<-Map.add c (Array.create 32 c)d
 for i=0 to a.Length-1 do if d.ContainsKey a.[i] then d.[a.[i]].[i]<-'█'
 for c in r do new string(d.[c])|>printfn"%s"

Try it online!


text:
Word Search Solver
I got to wondering yesterday if I could write a program to comb through a given word search and output the answers. It was actually surprisingly easy. Now I wonder just how small we can get.
Rules

Your first input is a string or collection of n lines, each of which is n characters long
Your second input is a list of words in any format to find in the puzzle
All words in the search list are guaranteed to be in the puzzle
Words can be oriented in any of the four cardinal directions, as well as diagonally both forwards and backwards
Only uppercase A-Z characters will be present in the puzzle
Your code must find every word in the the search string, and output the coordinate position of the starting letter, where 0,0 is the top left character.
In the event that you locate more than one instance of the same word, you may handle it however you like. Output it multiple times, or only once, it's up to you

Examples/Test Cases
Given the following board:
ABCD
EFGH
IJKL
MNOP

And the following search string:
ABCD,CGKO,POMN,NJF,AFKP,CFI,LGB,MJGD

Your program should output the following, in any order:
ABCD at 0,0
CGKO at 0,2
PONM at 3,3
NJF at 3,1
AFKP at 0,0
CFI at 0,2
LGB at 2,3
MJGD at 3,0

As always, shortest answer wins

Welcome to PPCG! Nice first challenge!

Similar, the only real difference seem to be the inclusion of the location in the output.

@NL628 Yes, all search words are guaranteed to be in the puzzle. If there is more than one occurence, you can either output it both times or ignore it the second, it's up to you.

@JonathanAllan Great idea. I will update it as you suggested.

@RickHitchcock Yes it should :)

@JonathanAllan I addressed this seconds before you posted your question, but yes, every word is guaranteed to be present, and you may output any coordinate you wish, as many as you want.

Will letters appear on the board more than once?

@Oliver They definitely could. The example is just that - an example. The algorithm should be able to solve any word search

Can the coordinates be 1-indexed?

Can I take the input as a function parameter? Do I have to read it from stdin?

JavaScript (Node.js), 154 152 150 141 bytes

thanks to Arnauld for reducing by 2 bytes

returns array of locations (it was a string with new lines before)
(b,w)=>w.map(s=>[...b].map((_,p)=>[1,-1,r=b.search`
`,-r,~r,++r,-~r,~r].map(d=>[...s].every((c,i)=>c==b[p+d*i])?s+=" at "+[p/r|0,p%r]:0))&&s)

Try it online!

Python 2, 213 bytes
lambda a,W:[(w,i,j)for w in W for i in R(L(a))for j in R(L(a[0]))for U in R(9)if U-4and g(i,j,U/3-1,U%3-1,a).find(w)==0]
g=lambda i,j,u,v,a,s='':L(a)>i>=0<=j<L(a[0])and g(i+u,j+v,u,v,a,s+a[i][j])or s
L=len;R=range

Try it online!
g takes a starting location i,j and a direction u,v and via recursion extracts the string starting at that location in that direction.
f then visits each starting location i,j and direction U/3-1,U%3-1 and checks each word w to see if the resulting string starts with w.

Python 3, 149 147 bytes
def g(b,w):h=b.find('\n')+1;return[f'{y} at {i//h},{i%h}'for y in w for i in range(len(b))for d in(1,h+1,h,h-1,-1,~h,-h,1-h)if y==b[i::d][:len(y)]]

Try it online!
Ungolfed version
def g(b,w):
    h = b.find('\n') + 1                              # width of a row plus the '\n'
    a = []
    for y in w:                                       # iterate over the words
        for i in range(len(b)):                       #   iterate over the game board
            for d in(1,h+1,h,h-1,-1,~h,-h,1-h):       #     for each possible direction
                if y==b[i::d][:len(y)]:               #       see if the word matches
                    a.append(f'{y} at {i//h},{i%h}')
    return a

The main idea is that b[i::d] selects a slice from the game board.  The slice starts as position i and extends in the direction d.  For example, d = h+1 corresponds to the southeast diagonal, whereas d = ~h, which is the same as -h-1, corresponds to the northwest diagonal.  [:len(y)]  chops the slice off at the same length as the word being searched.


text:
Simple Factorial Challenge
In light of today's date...
A factorial of a number n, is the product of all the numbers from 1 to n inclusive.
The Challenge
Given an integer n where 0 <= n <= 420, find the sum of the digits of n!. It's that simple :P
Notes: I feel like this challenge isn't too simple, as some languages have a very hard time storing numbers that are fairly large. Also, coding a BigInteger datatype is fairly straightforward, but hard to golf.

Examples

Input: 100. Output: 648.
Input: 200. Output: 1404.
Input: 420. Output: 3672.

Scoring

The input and output can be given by any convenient method.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

EDIT: Ok, I guess it's actually easy...take a look at the Jelly answer below. Anyways, I guess we all know which one's going to be accepted. But, I'd still like to see some interesting ideas and tricks to this problem!

This is A004152 in the OEIS.

@NL628: Typically, people are trying to get the smallest byte count for a particular language. So yes, Jelly in this case has very short result; but that hardly makes the results for other languages less fun or interesting for most afficianados of PPCG!

I'd like this better without the arbitrary restriction of 42<=n<=420

Today is Apr 21 for me. Nothing special.

@JoKing The lower bound doesn't make much sense, but having an explicit upper bound (up to which all submissions must work, regardless of native types) is a good thing.

Please don't accept an arbitrary answer. The accepted answer is the answer that wins the challenge.

Ah okay, sorry about that

Alternatively if you don't like it, just don't accept any answer. It's up to you. Anyway... what should be returned if n == -1?

Ahhh I originally had n >= 42 but ppl told me to delete it. I'll replace it with n = 0

0 <= n <= 420 heh

Why did you accept the Pyt answer when the Neim answer was first?

Neim, 2 bytes

Explanation: Factorial ; sum .
This outgolfs 3-byte answers as the sum command is able to implicitly convert to a list.
Try it online!

(old problem) JavaScript (Node.js), 99 94 92 88 86 83 80 78 bytes
f=(x,t=[...21+Array(999)])=>x?f(s=x-1,t.map(d=>-s+(s+=(t=~~d*x+t/10|0)%10))):s

Try it online!
well, first language without large number support
Thank Arnauld for 4 bytes
f = (x, t = ['2', '1', ...','.repeat(998)]) => // init x, t=1
  x ?
    f( // recursive x':=x-1, t'=t*x
      s = x-1, // s init to 0 when x==1, in next recursion just return
      t.map (
        b = // init b to NaN
        d =>
          -s + ( //  to return the added value
            s+= ( // -s + (s + k) == k
              b=
                ~~d*x+b/10 | 0
                // ~~d converts ',' to 0
                // b is initally NaN, after first iteration
                // it's zero, then the last digit sum result with carry
            ) % 10
          )
      )
    )
:
  s // the sum from x==1

ps. it doesn't work for 0, but the original question says >=42

Umm no, it says <= 420  ...

First version "Given an integer n where 42 <= n <= 420, find the sum of the digits of n!"

Nice this is what I was looking for...a language that doesn't have the capability of storing massive amounts of digits. Could you explain how it works?

Wolfram Language (Mathematica), 24 bytes
Total@IntegerDigits[#!]&

Try it online!

Haskell, 42 40 38 bytes
f n=sum[read[d]|d<-show$product[1..n]]

Try it online!
Thanks to @Laikoni for saving 2 bytes with list comprehension.

38 bytes: f n=sum[read[d]|d<-show$product[1..n]].

05AB1E, 3 bytes
!SO

Try it online!
Explanation
!     # factorial of input
 S    # split to list of digits
  O   # sum

I really think O on a string/non-list should be digit sum. It's come up enough in these non-important challenges.

Attache, 11 bytes
Sum@List@`!

Try it online!
Sums the List of digits in the factorial (!) of the input. Anonymous function.

Pari/GP, 16 bytes
n->sumdigits(n!)

Try it online!

When evaluated on 42000000, gives 1311426180 (takes under three minutes on my machine). The number has 310,936,107 digits. The average contribution per digit is 4.34, a bit under the "ideal" 4.5, which is likely related to the long string of zero digits in the end.

J, 13 11bytes
1#.,.&.":@!

Try it online!
Explanation:
! calculate the factorial
@ and
,.&.": convert it to a list of digits (convert to string ":, ravel ,. and convert each char back to number)
1#. find their sum by base-1 conversion

Perl 6, 21 bytes
{[*](2..$_).comb.sum}

Try it
Expanded:
{  # bare block lambda with implicit parameter ｢$_｣

  [*](       # reduce using &infix:« * »

    2 .. $_  # Range starting at 2 (slight optimization over 1)

  ).comb     # split the result into digits
  .sum       # find the sum of those digits
}

R + gmp, 66 bytes
sum(strtoi(el(strsplit(paste(gamma(gmp::as.bigz(scan())+1)),""))))

Try it online!
gmp is one of the several BigInteger packages available on CRAN.

sum(utf8ToInt(as.character(gmp::factorialZ(scan())))-48) should do the trick as well

Python 2, 51 bytes
f=lambda L,p=1:0**L*sum(map(eval,`p`))or f(L-1,p*L)

Try it online!
We'd like to write map(int,`p`), but since repr(p) might have a trailing L, that won't work.
Ordinarily, we'd resort to map(int,str(p)) and lose three bytes.
Here, can we name our counting-down variable L, and write map(eval,`p`). Since L is 0 when we compute the result, the digit sum is unaffected.

Jelly, 3 bytes
!DS

Try it online!
!DS        - main link, taking an integer  e.g. 9
!          - factorial                     -->  362880
 D         - convert to decimal            -->  [3,6,2,8,8,0]
  S        - sum of list                   -->  27

...you can't be serious...

DENNIS WHAT DID YOU DO

@NL628 Python 3 has bigint support, Jelly inherits that.

Python 2, 52 54 52 bytes
f=lambda n,r=1:1/n*sum(map(int,str(r)))or f(n-1,n*r)

Try it online!
-2 bytes thx to Kirill L.

Could you tell me how to make this challenger harder? I'm kind of struggling right now...

I believe you need the f= as this is a recursive lambda

@Giuseppe: Quite right! Thx.

@NL628 don't make the challenge harder after posting it.  That said, if you're looking for some hard challenges for the future, look into mathematical subjects like graph theory, or sets.

@NL628 Also, you can post it to the Sandbox where it can be refined before posting it to main.

@ChasBrown, You can get your 52 bytes back by replacing one of the conditionals with an arithmetical trick.

Bash + GNU utilities, 36

6 bytes saved thanks to @Cowsquack

seq -s* $1|bc|sed 's/\B\|\\/+&/g'|bc

Try it online!

Try combining the substitutions into 's/\B\|\\/+&/g' https://tio.run/##RcqxCoMwFIXh3ac4iK1gCblKt0IHnyOLmmvrklRPxrx76lI6/fDxzxPfZY0HkjItExVbwCDoRc4I7oM84GP1ObaQVtQXwjxRo/n9FTXBmD8U6g7DDk2f5yVTPVpaN7rsnL1d7as9ufgYtHwB

@Cowsquack - very good - thanks!

Pyt, 2 bytes
!Ś

Try it online!
Explanation:
      Implicit input
!     Factorial
Ś     Sum of digits
      Implicit output

Octave with Symbolic Package, 43 42 bytes
@(s)sum(char(sym(['factorial(' s 41]))-48)

Anonymous function that takes the input as a string and outputs a nubmer.
Try it online!

Charcoal, 7 bytes
ＩΣΠ…¹⊕Ｎ

Try it online! Link is to verbose version of code. Explanation:
      Ｎ Input as a number
     ⊕  Increment
    ¹   Literal 1
   …    Range
  Π     Product
 Σ      Sum (of digits)
Ｉ       Cast to string
        Implicitly print

InclusiveRange(1, InputNumber()) also works but the explanation is prettier this way.

Elixir, 54 bytes
fn n->Enum.sum Integer.digits Enum.reduce 1..n,&*/2end

Try it online!
Ungolfed:
def sum_factorial(n) do
  # factorial
  Enum.reduce(1..n, fn(x, acc) -> x * acc end)
  # sum digits
  |> Integer.digits
  |> Enum.sum

C (gcc), 107 bytes
f(x){int a[999]={1},i,c;
for(;x;--x)for(c=i=0;i<999;)c=(a[i]=a[i]*x+c)/10,a[i++]%=10;
for(;i--;)x+=a[i];
i=x;}

Try it online!

a[i++]%=10 into the for

c;f(x){int a[999]={1},i;for(;x;--x)for(i=0;i<999;a[i++]%=10)c=(a[i]=a[i]*x+c)/10;for(;i--;)x+=a[i];i=x;}

c;i;f(x){int a[999]={x},n;for(;--x;)for(i=n=0;i<999;n+=a[i++]%=10)c=(a[i]=a[i]*x+c)/10;i=n;}

104 bytes

@l4m2 why the i=n part then? c;n;f(x){int a[999]={x},i;for(;--x;)for(i=n=0;i<999;n+=a[i++]%=10)c=(a[i]=a[i]*x+c)/10;} Though fails for x=0 now that the lower bound has been edited out of the challenge.

@l4m2 and one less: c;n;f(x){for(int a[999]={x},i;--x;)for(i=n=0;i<999;n+=a[i++]%=10)c=(a[i]=a[i]*x+c)/10;} (87)

@RomanOdaisky i=n because i didn't know if the ret value is correct without it. with gastropner's it's c;n;f(x){for(int a[999]={x},i;--x;)for(i=n=0;i<999;n+=a[i++]%=10)c=a[i]=a[i]*x+c/10;} (85)

Husk, 3 bytes
ΣdΠ

Try it online!
Explanation
ΣdΠ  Implicit input
  Π  Factorial
 d   Convert to list of digits
Σ    Sum

Ruby, 33 bytes
->n{(2..n).inject(:*).digits.sum}

Try it online!

Tcl, 78 bytes
proc S n {proc F n {expr $n?($n)*\[F $n-1]:1}
expr [join [split [F $n] ""] +]}

Try it online!

Stax, 4 bytes
║▼⌡è

Run and debug it at staxlang.xyz!
Unpacked (5 bytes) and explanation
|FE|+
|F       Implicit input. Factorial.
  E      Array of decimal digits.
   |+    Sum of list. Implicit print.

Python, 75 bytes
import math
print(sum(map(int,list(str(math.factorial(int(input())))))))

Ceylon, 98 bytes
import ceylon.whole{l=one}Integer q(Integer n)=>sum({0,*product({l,*(l:n)}).string*.offset('0')});

Try it online
Explanation:
This is quite long, because we need to convince the compiler that we are not doing bogus stuff.
import ceylon.whole { l = one } // 1

Integer q(Integer n) => // 2
    sum({0,*product({l,*(l:n)}).string *.offset('0')});
//  |   |   |       |    '3' || |    | | |         |||
//  |   |   |       '--4-----'| |    | 7 |         |||
//  |   |   '----5------------' '-6--'   '--8------'||
//  |   |   '----------------9---------------------'||
//  |   '----------------10-------------------------'|
//  '------------------------11----------------------'

Import the value one from the package ceylon.whole,
and give it locally the name l (small L, not the digit 1 – though I choose this alias for its similarity to 1). (This alias import costs two bytes here, but saves two bytes for each of the two usages).
Define a function q from Integer to Integer, which maps
each parameter n to the result of the following expression (calculated in steps 3 to 11). Top-level functions always need a type declaration. For local ones we could replace the return type by function, which wouldn't have saved anything here. (For inline functions, we sometimes can omit both types and the keyword, if they can be inferred from context.)
This is a short syntax for measure(one, n), which returns either the empty sequence [] if n is non-positive, or a Range<Whole> starting from one and having size n (i.e. all numbers from 1 to n, assuming n is a positive integer).  Type: []|Range<Whole>, which is a subtype of {Whole*} (possibly empty iterable of Whole).
This is an iterable enumeration, with one as the first element and then all the elements of one:n (the * here expands the iterable). This has type {Whole+}, and has the only purpose to make sure the compiler knows it is non-empty. We could have used [...] instead of {...} for a tuple enumeration (which is non-lazy). No difference here apart from performance. We could have written this (l:n).follow(l), but that is longer.
Calculate the product of all those numbers, type Whole. product needs a non-empty iterable as a parameter to work (as the product of nothing is not defineable in a type-independent way).
Get the string representation of the result of step 5. (The .string attribute exists for all classes, and Whole implements it in the expected way, using decimal digits.) – type String, which is also a {Character*} (possibly empty iterable of characters).
The *. operator for iterables applies the the following attribute or method call to each element of the iterable and collects the result in a sequence. It can be seen as syntactic sugar for .collect(c => c.offset('0')). This is non-lazily evaluated, there is also .map(...) which is lazy.
The offset method of Character just calculates the difference between the unicode code points, returning an Integer.
This takes advantage of the fact that the ten decimal digits are sequential starting with 0 in ASCII (and thus unicode).
This whole thing has now type [Integer*] (possibly empty sequence of integers – because the string is possibly empty for the compiler).
Same trick again as step 4, we make it an {Integer+} (nonempty iterable) by prepending a 0 (which has no effect on the following sum).
Sum it all up.

CJam, 11 8 bytes
there is in fact a better way to get a list of digits
lim!Ab:+

Try it online!
Explanation:
li          input, convert to integer
  m!        factorial
    Ab      convert to array of digits in base 10
      :+    sum

Original solution:
lim!`1/:i:+

Explanation:
li              input converted to integer
  m!            factorial
    `           convert to string
     1/         split into pieces of length 1
       :i       convert back to integer
         :+     sum

Java 10, 135 bytes
n->{var r=java.math.BigInteger.ONE;for(;!n.equals(r.ZERO);n=n.subtract(r.ONE))r=r.multiply(n);return(r+"").chars().map(c->c-48).sum();}

Explanation:
Try it online.
n->{                         // Method with BigInteger parameter and integer return-type
  var r=java.math.BigInteger.ONE;
                             //  BigInteger, starting at 1
  for(;!n.equals(r.ZERO);    //  Loop as long as `n` is not 0 yet
      n=n.subtract(r.ONE))   //    After every iteration: subtract 1 from `n`
    r=r.multiply(n);         //   Multiply `r` by `n`
  return(r+"").chars()       //  Loop over the characters of `r`
              .map(c->c-48)  //   Convert them to digits
              .sum();}       //   And return the sum of those digits


text:
All Light All Light All Light!
This challenge is completely ripped offheavily inspired by All Light, developed by Soulgit Games.
Challenge
You are an electrician, and it's your job to wire up all the lights to the battery.

The lights and battery are laid out in a grid.
You can connect a light or battery to the nearest light or battery to its north, south, east, and west.
The battery can have any number of connections.
Each light specifies how many connections it requires. You must make exactly that many connections to that light.
You can create single connections or double connections between two lights (or light and battery).
Wires cannot cross.
There must be a path from each light to the battery.
At least one valid solution is guaranteed to exist.

Given the position of the battery and each light, and the number of connections each light requires, output the connections between them that admit these properties.
Win Condition
This is code-golf, so the shortest code in each language wins.
Test Cases
I/O is flexible as usual.
For input I will be using a 2d array the size of the grid which stores positive integers for lights, zeros for blank spaces, and -1 for the battery. Another good choice might be a list of lights, where a light is a tuple containing the light's position and number of required connections.
For output I will be using a list of connections, where a connection is a tuple containing the starting position and ending position. If a connection is doubled then I will have 2 of them in the list (another option is to include this parameter in the tuple). Another good option could be some sort of grid layout.
If you are using a coordinate system you may specify the starting index and where you index from. My examples will be 0-indexed and use (0, 0) as the top left corner (row, column). (I am using {} simply to introduce another type of delimiter so it is easier to read, not because they are sets.)
Here is a graphical view of the test cases: Tests 1-12
Test 1:
[-1 | 0 | 1 ] => [{(0, 0), (0, 2)}]
Test 2:
[-1 | 0 | 2 ] => [{(0, 0), (0, 2)}, {(0, 0), (0, 2)}]
Test 3:
[-1 ]
 [ 0 ] => [{(0, 0), (2, 0)), ((0, 0), (2, 0)}]
 [ 2 ]
Test 4:
[ 1 | 0 |-1 | 0 | 2 ] => [{(0, 0), (0, 2)}, {(0, 2), (0, 4)}, {(0, 2), (0, 4)}]
Test 5:
[ 2 ]
[ 0 ]
[-1 ] => [{(0, 0), (2, 0)}, {(0, 0), (2, 0)}, {(2, 0), (4, 0)}]
[ 0 ]
[ 1 ]
Test 6:
[ 1 | 0 | 0 ]
[ 0 | 0 | 0 ] => [{(0, 0), (2, 0)}, {(2, 0), (2, 2)}]
[ 2 | 0 |-1 ]
Test 7:
[ 4 | 0 | 0 |-1 ]
[ 0 | 0 | 0 | 0 ] => [{(0, 0), (0, 3)}, {(0, 0), (0, 3)},
[ 2 | 0 | 0 | 0 ]     {(0, 0), (3, 0)}, {(0, 0), (3, 0)}]
Test 8:
[ 2 | 0 |-1 | 0 | 2 ]   [{(0, 0), (0, 2)}, {(0, 0), (0, 2)},
[ 0 | 0 | 0 | 0 | 0 ] =>  {(0, 2), (0, 4)}, {(0, 2), (0, 4)},
[ 0 | 0 | 1 | 0 | 0 ]     {(0, 2), (2, 2)}]
Test 9:
[ 0 | 0 | 2 | 0 | 0 ]
[ 0 | 0 | 0 | 0 | 0 ]
[ 1 | 0 |-1 | 0 | 1 ] => [{(0, 2), (2, 2)}, {(0, 2), (2, 2)}, {(2, 0), (2, 2)},
[ 0 | 0 | 0 | 0 | 0 ]     {(4, 2), (2, 2)}, {(2, 4), (2, 2)}, {(2, 4), (2, 2)}]
[ 0 | 0 | 2 | 0 | 0 ]
Test 10:
[-1 | 2 | 3 | 2 ] => [{(0, 0), (0, 3)}, {(0, 0), (0, 3)},
                       {(0, 0), (0, 3)}, {(0, 0), (0, 3)}]
Test 11:
[-1 | 0 | 0 | 0 ]
[ 3 | 0 | 0 | 0 ]
[ 3 | 0 | 0 | 3 ] => [{(0, 0), (1, 0)}, {(1, 0), (2, 0)}, {(1, 0), (2, 0)},
[ 0 | 0 | 0 | 0 ]     {(2, 0), (2, 3)}, {(2, 3), (4, 3)}, {(2, 3), (4, 3)}]
[ 0 | 0 | 0 | 2 ]
Test 12:
[ 2 | 0 | 0 ]   [{(0, 0), (1, 0)}, {(0, 0), (1, 0)}, {(1, 0), (1, 1)},
[ 3 |-1 | 0 ] =>  {(1, 1), (2, 1)}, {(1, 1), (2, 1)}, {(2, 0), (2, 1)},
[ 2 | 5 | 1 ]     {(2, 0), (2, 1)}, {(2, 1), (2, 2)}]

Sandbox

I suggest having a test case such that there exists a solution satisfy every condition except "There must be a path from each light to the battery.". For example [1 | -1] [1 1].

Somewhat reminds me of the Blossom algorithm.

@user202729 I guarantee that the input has a solution satisfying all the conditions

I'd like a graphical explanation (a picture of the connections for one example). I'm a visual person, so looking at the description and I/O examples isn't as helpful.

@mbomb007 Here is a graphical view of the test cases: Inputs 1-12. Would you like me to draw out the outputs as well or is this good?

This seems similar to a Hashi puzzle. I think many of the same steps to solving either of them are the same.

Heh, test-battery

JavaScript (Node.js), 393 391 378 bytes
a=>(R=[],f=(a,[x,...y],z,Y)=>x?f(a.map(t=>[...t]),y,z,Y)||f(a,y,[...z,x],Y.map(p=>p.map(q=>q-Y[x[0]][x[1]]?q:Y[x[2]][x[3]])),--a[x[0]][x[1]],--a[x[2]][x[3]]):/[1-9]/.test(a)|Y.some(t=>t.some(u=>u-Y[I][J]&&u))?0:z)(a=a.map(A=(b,i)=>b.map((x,j)=>x&&(A[i]+1&&R.push([i,A[i],i,j]),f[j]+1&&R.push([f[j],j,i,j]),A[I=i]=j,f[J=j]=i,x/=x>0))),[...R,...R],C=[],a.map(p=>p.map(q=>q&&++C)))

Try it online!
a=>(
    a=a.map(
        A=(b,i)=>
            b.map(
                (x,j)=>
                    x&&(                                  // A[i]+1 <==> A[i] is NOT NaN
                        A[i]+1&&R.push([i,A[i],i,j]),     // Use A and f to store last
                        f[j]+1&&R.push([f[j],j,i,j]),     // existance of row and column
                        A[I=i]=j,f[J=j]=i,x/=x>0          // -1 => -Inf, +n => n
                    )
            ),
            R=[],
            f=([x,...y],z,Y)=>
                x?
                    f(
                        y,[...z,x],
                        Y.map(p=>p.map(q=>q-Y[x[0]][x[1]]?q:Y[x[2]][x[3]])), // merge
                        --a[x[0]][x[1]],--a[x[2]][x[3]]
                    )||
                    f(y,z,Y,++a[x[0]][x[1]],++a[x[2]][x[3]])
                :
                    /[1-9]/.test(a)|
                    Y.some(t=>t.some(u=>u-Y[I][J]&&u)) // not totally merged
                    ?0:z
    ),f)([...R,...R],[],a.map(p=>p.map(q=>q&&++C),C=0)
)

Fails for this test case.

Is there a shortcut for /[1-9]/ in JavaScript RegEx?

@Zacharý I don't think so. Usually [0-9] is used

Silly me! I thought that's what you wrote

@Zacharý What??

I though you wrote [0-9] in the regex...

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