text:
Take a stand against long quine lines
or: Build a vertical quine
Inspired by Take a stand against long lines.
Your task is to build a vertical quine with as short a line length as possible.
Scoring
Shortest line length (excluding newlines) wins, with code-golf criteria as a tie-breaker.
Line length is determined as the longest line in your program excluding the line break character.
For example:
$_=
Q.
P

has a line length of 3 and a byte count of 8, whilst:
Q
$
_
P

Has a line length of 1 and a byte count of 7 (assuming no trailing newline).
Rules
Quines must meet the community definition of a quine.
Standard loopholes are forbidden.

Does the rule of the challenge this is inspired from apply here as well? ("All line breaks must be meaningful. Line breaks that can be removed and adjacent lines directly concatenated without an impact on the output, must be removed.")

@KevinCruijssen No, I wanted this challenge to have a bit more freedom to encourage shorter line lengths! It was the one thing I wanted to change in the other challenge!

Lenguage, line length 0, ≈ 1.01 × 10805 bytes
The source code consists of

10124204951141713202533972929121310016060433092338061822344361345785088607872212687519180665846846689047959498775873817205954910072327976407177053174071436371843670134990737172675632938993247496933911137703773908536875512359091727633452506044935740750830240213878294804481182083555147915724921824921475110508228264569693355158523956426011218344830576542194309867719995259333487662608933990607888012376767799159279952780093033761421596267435996052643805835600325453580090964941176722519904997142820547696122795384058768166716813179490118821654787005844786013890425692181280317909786461426684986082270532414940905922244777135016193088362341771414388821075092853157152933099269703875111747946164773211049512395358715902962437487134522781505709420586981997748912591875626029183292826655753251235587052422561943

linefeeds, which encodes the brainfuck program that follows.
>>++++++++>+++>+++>+>+>+>+>+>+>+>+++>+>+>+>+>+>+>+>+>+++>+>+>+>+>+>+>+>+>++++++++>++++>++++++++>++++>+++++++>++>+++>+>+++>++>+++>+++>+>+>+>+>+>+>+>+>++++>++++>+++++++>+>++++>++++++++>++>+++++++>+++>++++++++>++>+++++++>+++>++++++++>++>+++++++>+++>++++++++>++>+++++++>+++>++++++++>++>+++++++>+++++>+>+>+>+>+>+>+>+>+>+>++++++++>++++>+++++++>+++++++>+>+>+++>+>+>+>++++++++>+++>+++++++>+>+++>+>+++>+>+++>+>++++++++>++++>++++++++>++++>++++++++>++++>++++>+>+++>+++>++>+++++++>+++++++>+>+>+>++++++++>+++>+>++++++++>++++>+>+++>++>+++++++>++>+++++++>++++>++++>++++++++>+++>++++++++>+++>+++>+>++++>++++>++>+++++++>+++>+++>++++++++>++++>+>+++>++>+++++++>++++>++++>+++++++>+++>+++>+++>+++>++++++++>++++>++++>+>+++>+>+++>++>+++++++>+++++++
[
    [->+>+<<]
    >>>>[<<[->+<]>>[-<<+>>]>]
    <<[-[->+<]+>]+++
    [[->>+<<]<]<
]
+>+>+>+
[>]+++>++
[
    [<]++++++++++.[-]
    >[-]>[-]>[-]>[-]
    <+[<<++++++++>>->+>-[<]<]
    ++++++++>++++++++>+++++++>>
]

The source code is mostly identical to @jimmy23013's radiation-softened Lenguage quine, minus the . at the end, with ++++++++++.[-] replacing . to print linefeeds instead of null bytes, and the corresponding changes to the data section on line 1.

I knew it was inevitable! I did want an inclusive question though. I wonder if anyone can beat this...

Lord, this language is the definition of why code-bowling isn't well-received, that's a cool one for sure... Can't believe "Hello World" would require "about 1.75*10**76 yottabytes in ASCII"

I've asked on meta about accepting a theoretical answer.

You can golf more than 99% of the code by using ]++++++++ ++.-->

JavaScript, line length 1, 960 956 928 bytes

[
t
,
r
,
u
,
e
,
f
,
a
,
l
,
s
]
=
!
0
+
[
!
1
]
;
[
,
n
,
d
,
,
q
,
i
]
=
t
.
a
+
t
V
=
[
]
[
f
+
i
+
n
+
d
]
;
[
,
,
,
c
,
,
,
o
,
,
_
,
,
,
,
,
y
,
z
]
=
V
+
0
F
=
V
[
E
=
c
+
o
+
n
+
s
+
t
+
r
+
u
+
c
+
t
+
o
+
r
]
P
=
(
1
+
e
+
2
+
3
-
4
+
t
)
[
2
]
f
=
F
(
r
+
e
+
t
+
u
+
r
+
n
+
_
+
a
+
t
+
o
+
(
0
+
{
}
)
[
3
]
)
(
)
(
3
*
4
+
[
]
[
E
]
[
n
+
a
+
(
0
[
E
]
+
0
)
[
9
+
2
]
+
e
]
)
[
1
]
F
(
a
,
a
+
l
+
e
+
r
+
t
+
y
+
a
+
P
+
q
+
P
+
a
+
P
+
q
+
z
)
`
[
t
,
r
,
u
,
e
,
f
,
a
,
l
,
s
]
=
!
0
+
[
!
1
]
;
[
,
n
,
d
,
,
q
,
i
]
=
t
.
a
+
t
V
=
[
]
[
f
+
i
+
n
+
d
]
;
[
,
,
,
c
,
,
,
o
,
,
_
,
,
,
,
,
y
,
z
]
=
V
+
0
F
=
V
[
E
=
c
+
o
+
n
+
s
+
t
+
r
+
u
+
c
+
t
+
o
+
r
]
P
=
(
1
+
e
+
2
+
3
-
4
+
t
)
[
2
]
f
=
F
(
r
+
e
+
t
+
u
+
r
+
n
+
_
+
a
+
t
+
o
+
(
0
+
{
}
)
[
3
]
)
(
)
(
3
*
4
+
[
]
[
E
]
[
n
+
a
+
(
0
[
E
]
+
0
)
[
9
+
2
]
+
e
]
)
[
1
]
F
(
a
,
a
+
l
+
e
+
r
+
t
+
y
+
a
+
P
+
q
+
P
+
a
+
P
+
q
+
z
)
`
More readable version which also happens to be a quine (extraneous newlines removed):

[t,r,u,e,f,a,l,s]=!0+[!1];[,n,d,,q,i]=t.a+t
V=[][f+i+n+d];[,,,c,,,o,,_,,,,,y,z]=V+0
F=V[E=c+o+n+s+t+r+u+c+t+o+r]
P=(1+e+2+3-4+t)[2]
f=F(r+e+t+u+r+n+_+a+t+o+(0+{})[3])()(3*4+[][E][n+a+(0[E]+0)[9+2]+e])[1]
F(a,a+l+e+r+t+y+a+P+q+P+a+P+q+z)`
[t,r,u,e,f,a,l,s]=!0+[!1];[,n,d,,q,i]=t.a+t
V=[][f+i+n+d];[,,,c,,,o,,_,,,,,y,z]=V+0
F=V[E=c+o+n+s+t+r+u+c+t+o+r]
P=(1+e+2+3-4+t)[2]
f=F(r+e+t+u+r+n+_+a+t+o+(0+{})[3])()(3*4+[][E][n+a+(0[E]+0)[9+2]+e])[1]
F(a,a+l+e+r+t+y+a+P+q+P+a+P+q+z)`
Explanation
Whew. Settle in for a ride here, because this is gonna be a treacherous  journey...
I spent a long time trying to figure out how to solve this challenge with length 1—no built-ins (directly, anyway), keywords, or even arrow functions—before realizing that it is easily possible with JSF***, which can evaluate any JavaScript code while avoiding any multi-byte tokens. But a JSF solution would easily be thousands of bytes long, if not tens or hundreds of thousands. Thanksfully, we aren't limited to just ()[]+!—we have all of ASCII at our disposal!
I decided to start by golfing the essential building blocks of JSF—the characters that can be built up into strings to "unlock more features," so to speak. We can't use strings directly to get characters, as that would require lines of length 3. So instead, we steal a trick from JSF, getting a few chars from literals that can be built up with single-byte tokens:
JSF***   Used here   Value        Chars unlocked
!![]     !0          true         true
![]      !1          false        fals
[][[]]   t.a         undefined    ndi

From these we can expand outward, starting with [].find, which is a Function object. Converting this to a string function find() { ... gives us access to c, o, space (_), and parentheses (y and z). Perhaps more importantly, we now have access to its constructor, the Function function—which, inceptional as it may sound, gives us the ability to execute code by building a string, passing it to Function(), and then calling the function generated.
I should probably mention the overall method used by the program itself. As of 2015, JavaScript has this really cool feature called "tagged templates," which not only allows unescaped newlines in strings, but also lets us call a function with a string literal directly (in a way; myFunc`abc`; is roughly equivalent to myFunc(["abc"])). If we put the function call as the last thing in the program, the general structure will look like this:
code;func`code;func`

All func has to do then is output its argument, followed by a backtick, then its argument again, and a second backtick. Assuming we have the argument in a and a backtick stored in f, we can accomplish this with the code alert(a+f+a+f). However, at the moment, we are missing + and the backtick itself. + (stored in P) isn't hard; we steal another trick from JSF, building the string 1e23, converting to a number, then back to a string, giving "1e+23".
Getting a backtick is a bit more complicated. At first, I tried obtaining String.fromCharCode, but finding a C turned out to be nearly as difficult. Fortunately, atob is easy enough to obtain (Function("return atob")(); b is generated from 0+{}, which gives [object Object]) and can give any ASCII char, if a proper magic string is found. A short script gave me 12A as one of the options, which can conveniently be found in 12Array (a bit shorter to generate, thanks to [].constructor[n+a+m+e]; m is found in 0 .constructor+0: "function Number() { ...").
Finally, we stick everything together. We assign the backtick to variable f, but since we can't use it directly in the function string, we instead set variable q to the letter f and use that instead. This makes our final string a+l+e+r+t+y+a+P+q+P+a+P+q+z, or "alert(a+f+a+f)". We then feed this to Function(), feed the our finished code to the result, and voila, we have a JavaScript quine with no more than one char per line!

My head feels terrible at the moment, so please inquire about any mistakes I've made or things I've missed in this explanation, and I'll get back to you after I've had some rest...

Nice! Although really not a JS programmer, I can guess the gist of this from what I've read about JSFuck, but I'd like an explanation especially of that f= line.

@ØrjanJohansen Sorry, I've been trying to write an explanation for the whole thing, but it's not going very well so I'll just answer your question quickly: it's a convoluted way to set f to a single backtick. The line itself is equivalent to f=atob("12Array")[1]. The other trick is that q is actually set to the letter f in the first line, so that in the F(...) line, I can use it to put the letter f in the evaluated string, since variable f is no longer set to that letter. The a+l+e+r+t+y+a+P+q+P+a+P+q+z is equivalent to "alert(a+f+a+f)".

Great, now I understand it! You might mention what  0+{} and 0[E] stringify to in order to get b and m.

Nice indeed! Much smaller than my attempt, although we used a simar approach!

@DomHastings So long the link doesn't even work ;-)

Well, that's embarrassing!

@ØrjanJohansen Done, thanks for the suggestion.

+1 for being a true quine and not calling Function.toString.

@Neil If you have a length-1 solution that uses Function.toString, I'm all ears, because I couldn't find one myself...

Haskell, line length 6, 400 343 336 bytes
{main=
putStr
$s++(s
>>=(++
":\n")
.show)
++
"[]}";
s='{':
'm':
'a':
'i':
'n':
'=':
'\n':
'p':
'u':
't':
'S':
't':
'r':
'\n':
'$':
's':
'+':
'+':
'(':
's':
'\n':
'>':
'>':
'=':
'(':
'+':
'+':
'\n':
'"':
':':
'\\':
'n':
'"':
')':
'\n':
'.':
's':
'h':
'o':
'w':
')':
'\n':
'+':
'+':
'\n':
'"':
'[':
']':
'}':
'"':
';':
'\n':
's':
'=':
[]}

Try it online!  I'm not aware of a way around putStr, thus the line length of 6. The outer curly braces allow to get rid of the otherwerwise required indention after a newline within a single declaration.

><>, 22 bytes, line length 1
/
v
o
a
o
^
}
-
d
:
"

Try it online!
-6 bytes thanks to Emigna.

CJam, line length 1, 16 13 bytes
"
_
p
"

_
p

Try it online!
It's a small miracle that inserting newlines into the standard quine {"_~"}_~ even shorter standard quine "_p"␊_p does the right thing. (Thanks, Martin!) The trailing newline is necessary.
Explanation (with • as newline)
"•_•p•"        Push that string.
       ••      Do nothing.
         _     Duplicate the string.
          •    Do nothing.
           p   Pop it and print it with quotes and a newline: "•_•p•"•
            •  Do nothing.

On termination, what's left on the stack is printed (•_•p•), yielding total output "•_•p•"••_•p•.

All I have to say is ... •_•

Haskell + CPP, line length 2, 705 237 bytes
m\
a\
i\
n\
=\
p\
u\
t\
S\
t\
r\
$\
(\
:\
"\
\\
\\
\\
n\
"\
)\
=\
<\
<\
s\
+\
+\
s\
h\
o\
w\
 \
s\
;\
s\
=\
"\
m\
a\
i\
n\
=\
p\
u\
t\
S\
t\
r\
$\
(\
:\
\\
"\
\\
\\
\\
\\
\\
\\
n\
\\
"\
)\
=\
<\
<\
s\
+\
+\
s\
h\
o\
w\
 \
s\
;\
s\
=\
"\

Try it online! Using the flag -CPP which enables the C pre-processor allows us to use a backslash at the end of a line to continue it on the next line.
The actual code is main=putStr$(:"\\\n")=<<s++show s;s="<data>".
Edit: A casual -468 bytes thanks to Ørjan Johansen!

It saves a lot of escaping to change that to main=putStr$(:"\\\n")=<<s++show s;s="<data>". Try it online!

Rust, line length: 5, bytes: 301 299
Try it online
Despite how it looks, this isn't an esoteric programming language, there is just a lot of format line noise.
Vertical length of 5 was chosen to be able to use print. I don't think there is a way to print that would have shorter vertical length, declaring C functions uses extern keyword, stdout is 6 bytes long, write is 5 bytes long, no_main is 7 bytes long (main is usually a function ;)).
fn
main
(){
let
t=(
r#"fn
main
(){
let
t=("#
,r#")
;
print
!(
r#"{}
r#"{
}"{}
,r#"{
}"{},
r#"{
}"{}
{}{}{
}{
}""#,
r#"
,t.0,
t.0,
'#',
t.1,
'#',
t.2,
'#',
t.1,
'#',
t.2,
'}'
)"#
)
;
print
!(
r#"{}
r#"{
}"{}
,r#"{
}"{},
r#"{
}"{}
{}{}{
}{
}"#
,t.0,
t.0,
'#',
t.1,
'#',
t.2,
'#',
t.1,
'#',
t.2,
'}'
)}

Isn't it horizontal length?

@anatolyg fixed

Raw string nesting without syntax highlighting makes this impossible to interpret. I don't think cargo fmt would even help here...

@CAD97 If what you want is syntax highlighting, https://play.rust-lang.org/ highlights this correctly which is why I used it instead of TIO for "Try it online" link.

05AB1E, Line length: 1, Byte count: 43
2
"
D
3
4
«
ç
¶
ì
ý
Ô
"
D
3
4
«
ç
¶
ì
ý
Ô

Try it online!

Japt, line length 1, 20 bytes
Based off the standard Japt quine by ETHproductions.

"
i
Q

²
"
i
Q

²

Try it here!

JavaScript (ES6), line length 3, 17 bytes
f=
_=>
`f=
${f
}`

Red, line-length: 10, 49 bytes
s: [prin [
    "s:"
    mold s
    "do s"
]] do s

Try it online!
This in fact is a Rebol quine
Explanation:
Red/Rebol's mold follows the coding style of putting 4 spaces offset.
s: [prin [     ; s is a block; print the following:
    "s:"       ; literal "s:"
    mold s     ; the representation of the block itself - all between []
    "do s"     ; literal "do s"
]] do s        ; evaluate the block

RProgN, 3 bytes, line length 1
0
0

Try it online!
A copy of Dennis' answer here (go upvote him too)
This is a conforms to our current definition of a proper quine, as the first 0 encodes the second 0 and vice-versa.

It's much too bad we haven't come to a consensus on a better definition :-/

@ETHproductions Well, there's some support for this definition.

Perl 5, 259 bytes

$
_
=
p
.
r
.
i
.
n
.
t
.
q
{

'
$
_
=
p
.
r
.
i
.
n
.
t
.
q
{
'
,
&
{
I
.
"
X
0
y
h
~
"
^
"
E
O
0

y
"
.
x
}
(
$
_
,
6
,
-
1
)
,
'
}
;
&
{
I
.
"
X
0
o
k
h
~
"
.
(
Y
|
p
)
^
"
E
O
0
|
f
s
o
"
}
'
}
;
&
{
I
.
"
X
0
o
k
h
~
"
.
(
Y
|
p
)
^
"
E
O
0
|
f
s
o
"
}

Try it online!
Verification.

RProgN 2, L = 1, B = 15 bytes
«
Ø
.
`
-
S
`
.

This is equivilent to the program:
«Ø.`
-S`
.

Breakdown
« first pushes a function representing implicitly the rest of the program to the stack, and then continues execution. Ø. appends an empty string to the function, which stringifies it. This will always stringify like the equivilent program, due to newlines being no-ops. `\n- Removes all newlines from the string, now looking like «Ø.`=S`.. S then converts it to a stack of single characters, and `\n. joins the stack by newlines, returning the expected program.
Try it online!

Underload, line length 1, 20 bytes
(
:
a
S
S
)
:
a
S
S

Try it online!
This is just the standard Underload quine with newlines appended. Requires an implementation like the TIO one which ignores unknown command characters.
The part in () is a string literal put on the stack, : duplicates it, a wraps the top stack entry in parentheses, and S prints.

Javascript (ES6 REPL), full-program, line-length: 3, byte-count: 31
(
f=
_=>
`(
f=
${f
}
)
()`
)
()

This is a port of @kamoroso94's answer to a self-contained full program.
If anybody finds a way to strip off some bytes without adding more to the line-length feel free to comment :)

Note that this still doesn't actually output anything, unless you run it in an REPL. I would call it JavaScript (ES6 REPL)

oh shoot, way to used to chrome's console...

Pip, line length 1, 35 bytes

V
Y
"
[
`
V
Y
`
y
]
.
C
:
3
.
4
"

Try it online!
Based on the shortest known Pip quine, V Y"`V Y`.RPy". The main difficulty in squishing it to line length 1 is RP, which can't be split over two lines. But in this case, all RP (repr) does is wrap the string in double quotes, which we can do directly.
Here's an explanation based on a horizontal version:
V Y"[`V Y`y].C:3. 4"
  Y"               "  Yank this string into the variable y
V                     and eval it
                      The code that is eval'd:
    [      ]           Build a list containing:
     `V Y`              this Pattern object (used for regex, but here useful as a
                          string-like object that doesn't need double quotes)
          y             y, the whole string
               3. 4    Concatenate 3 and 4 to make 34 (since the 2-digit number won't work
                         in the vertical version)
             C:        Convert to ASCII character (: forces the precedence lower than .)
            .          Concatenate the " to the end of each list element
                      The resulting list is printed, concatenated together, with a
                        trailing newline

Befunge-98, 41 bytes
^
@
,
,
a
-
1
*
5
7
|

#
!
a
#
:
,
^
$
"

Try it online!
Really just a normal quine turned sideways, with some extra stuff to print newlines.


text:
Print "Hey Jude" from The Beatles
Your task is to write a program which prints following four verses extracted from the lyrics from The Beatles' song "Hey Jude" (© Sony/ATV Music Publishing LLC):
Hey Jude, don't make it bad\n
Take a sad song and make it better\n
Remember to let her into your heart\n
Then you can start to make it better\n
\n
Hey Jude, don't be afraid\n
You were made to go out and get her\n
The minute you let her under your skin\n
Then you begin to make it better\n
\n
Hey Jude, don't let me down\n
You have found her, now go and get her\n
Remember to let her into your heart\n
Then you can start to make it better\n
\n
Hey Jude, don't make it bad\n
Take a sad song and make it better\n
Remember to let her under your skin\n
Then you'll begin to make it\n
\n

BUT
The only input you are allowed to use to construct these four verses is this list of tokens:
"Hey Jude, don't"
" make it bad"
" be afraid"
" let me down"
"Take a sad song and make it better"
"You"
" were made to go out"
" and get her"
" have found her, now go"
"Remember to"
"The minute you"
" let her"
" into your heart"
" under your skin"
"Then"
" you"
" can start"
"'ll"
" begin"
" to make it"
" better"

Note that some tokens have a space preceded and that enclosing quotes are not part of the tokens. You are free to use any format for the list and to rearrange the order of the tokens.
Your generated output has to exactly match the above four verses. Note that\n is used for newlines and an extra newline is added after each verse. You can use this file (MD5: 4551829c84a370fc5e6eb1d5c854cbec) to check your output against.
You can use following railroad diagram to understand the structure of the verses (each element represents a token):

Shortest code in bytes wins. Happy golfing.

Just to make this clear: my understanding is that the tokens are passed to the program/function and do not contribute to the byte count. Is that correct?

@Arnauld Yes, that's correct.

The part that goes Nah nah nah nah nah nah, nah nah nah, would have easier to compress. ^^

Given that the input is any ordering of a fixed set I think tagging as kolmogorov-complexity makes sense. I've added it, if people disagree then just remove it :)

@Arnauld Related :P

@Arnauld obligatory XKCD https://xkcd.com/851_make_it_better/

It must be hard to sing all those backslashes at the end of every line.

@arminb what did you use to make that diagram? So pretty....

@bonh railroad-diagrams

Ruby: loop { puts 'na' }

Possible duplicate of We're no strangers to code golf, you know the rules, and so do I

You confusingly put two newlines at the end of each line of the song. I recommend you edit one out.

Jelly, 42 bytes
;⁷“Ṙç€ṘḋḷŒø|Ṁ2kḤ⁽⁼SƁẒVṿẎj]ð⁵ṀƒƤ)÷Ƒ¦Ẋ½Iɠ⁻’ṃ

Try it online!
Hardcoding version.
Input:
["Hey Jude, don't", ' make it bad', 'Take a sad song and make it better', 'Remember to', ' let her', ' into your heart', 'Then', ' you', ' can start', ' to make it', ' better', ' be afraid', 'You', ' were made to go out', ' and get her', 'The minute you', ' under your skin', ' begin', ' let me down', ' have found her, now go', "'ll"]

JavaScript (ES6), 108 bytes
a=>`01
4
9bc
efgjk

02
567
abd
efijk

03
587
9bc
efgjk

01
4
9bd
efhij

`.replace(/./g,n=>a[parseInt(n,36)])

Try it online!

Alternate version, 114 bytes
A slightly better compression, but sadly ruined by the larger decompression code.
a=>`835fc3cbbd3
84db3db4bbdb3
85cd1cc3cbbd3
835fc4bbcb3

`.replace(/./g,n=>a[n='0x'+n,i=n%8&&n%8-2+i]+[`
`[n>>3]])

Try it online!

I did not know that the m flag is not required for multi-line template literals. Interesting.

Ruby + -p, 177 136 120 118 115 109 bytes (full program)
$_="abvevjlmvopqtuvvacvfghvklnvopstuvvadvfihvjlmvopqtuvvabvevjlnvoprstv".gsub(/./){|c|(eval$_)[c.ord-97]||$/}

Try it online!
-41 bytes: Switch from using variables to using characters as array indexes
-16 bytes: Switch to a more convenient input format
-1 byte: No space needed between puts and "abv...
-1 byte: Use $/ global instead of ?\n literal
-3 bytes: Use gsub(/./) instead of .chars.map
-6 bytes: Call with -p and make use of $_. Thanks Pavel!
Each character in the magic string represents an index into the input array. I need the variable z so that I only read from STDIN once.
I could save some cost from IO by writing a lambda accepting an array and returning a string. This requires an extra v at the end, because it's not getting a free newline from -p.
Ruby, 162 110 108 105 bytes (function)
->z{"abvevjlmvopqtuvvacvfghvklnvopstuvvadvfihvjlmvopqtuvvabvevjlnvoprstvv".gsub(/./){|c|z[c.ord-97]||$/}}

Try it online!

I haven't been able to find a way to use String#unpack to be shorter than .chars with .ord-97, but there might be one.

Here's a few bytes off: https://tio.run/##VY/NasMwEIRfZTGBJJDEx9JD76XH0EsJIaytta1allL9mVD31euu5JbQk9jZb2a0NlS3eV5dngqsIsV3NURz/fAhRqxj03axV5oVlxURG9n9YxZPIqzzsTi0LlSb8lBuP6d62lBEtbpsT/XBWLF/fDhP06r8mudT8Uw3eAmCdiCMXvtiV8CAPYH0UKFIY0WAjUWZB0UeBmJ21Dy@JhLBoQBndAuoxd1N3pNl6M2E5BzJEi8FgTfQGjAhlyVLy6FdZqHDSNCYwCorO9BmZJg3RxpoqMiyOxV3nCV18AS3JV7dM6TmBpYtC2hzC@exNWuul3pJSM@fvUYNzi/0Wqnl7jaT6b@/Ry1yvuv8ba5eGu3m/fUH

Neat, thanks! Today I learned about -p and $_

Forgive my ignorance, but how would I run this from the command-line or IRB?

@JohnTopley If you want to use IRB, you could copy-paste these three lines one by one. To use the full program from the command line, start here

Java 8, 241 233 141 140 138 bytes
a->{a.add("\n");"01E4E9;<E>?@CDEE02E567E:;=E>?@CDEE03E587E91<E>?@CDEE01E4E91=E>?ABCEE".chars().forEach(i->System.out.print(a.get(i-48)));}

Explanation:
Try it online.
a->{                  // Method with ArrayList<String> parameter and no return-type
 a.add("\n");         //  Add a new-line as last item (index 21) to the input-List
 "01E4E9;<E>?@CDEE02E567E:;=E>?@CDEE03E587E91<E>?@CDEE01E4E91=E>?ABCEE".chars().forEach(i->
                      //  Loop over the bytes of this String above
   System.out.print(  //   Print:
     a.get(i-48)));}  //    The String in the list at index `i-48`

It basically converts the ASCII characters 0 (48) through E (69) to the 0-indexed indices 0 through 21 with the i-48.

05AB1E, 142 68 66 65 bytes
`¶)•7/è¸ĀuVI{è:÷MDS.₁bö¼d@ÉÃƶõî›Λðë’OŒβι"žHƒö>“ÃaÈǝõöÓ∍¿þœθÀ•2ôèJ

Try it online!
-74 bytes thanks to EriktheOutgolfer, using a base-255 compressed string.
-2 bytes by reversing the compressed string to prevent having to concatenate three 0's
-1 byte thanks to EriktheOutgolfer, by switching two items in the input array in order to avoid the leading 0's, and thus removing the Reverse R command.

Python 3, 162 147 144 142 138 127 bytes
lambda k,x=b'ABVCVDEFVGHIJKVVALVMNOVPEWQVGHRJKVASVVMTOV':"".join([(k+['\n',' '])[i-65]for i in x+x[5:16]+x[:4]+b'VDEWQVGHURJ'])

Try It Online
Special thanks to user202729 and Pavel.

Retina 0.8.2, 115 bytes
^
12F5F:<=F?@ADEFF13F678F;<>F?@CDEFF14F698F:<=F?@ADEFF12F5F:<>F?@BCDF¶
{`1(?=.*¶(.*))
$1
^(.*)¶.*
$1
}T`1-E`0-D
F
¶

Try it online! Takes input as a newline-delimited list of strings.

Stax, 59 58 bytes
îòÖ╥╬╬╞:,y╓ønä⌠╦╒ï╦≤x◘‼ε╩ⁿ◙ΓZ►e«qpôr╡"╣Ü≥┤╢┴;╡ÑkAú0:=;m╠╠x

Run and debug it
The corresponding ascii representation of the same program is this.
`ORIpY$T&z{m6Y=>mR)_ .VQ)eN70e[:0yO8j$^RN[ Bp{IN/$|"3^;G#^&lv!`FAx+@]p

`ORIpY$T&z{m6Y=>mR)_ .VQ)eN70e[:0yO8j$^RN[ Bp{IN/$|"3^;G#^&lv!` is a compressed literal with a value of "CDBGBLNOBQRSVWBBCEBHIJBMNPBQRUVWBBCFBHKJBLNOBQRSVWBBCDBGBLNPBQRTUVBB".  The characters represent indexes into the token table.  This program adds another token to represent a newline.  It's not in the input, but added during execution.  The rest of the program works like this.
F           for each character, execute the rest of the program
 A          integer literal 10, character code of newline
  x+        append 10 to the input array
    @       get element at index, using wrap-around
                the list is size 22, and B is 66, so B gets the first token
     ]      wrap the result in a singleton array.
                this effectively turns 10 into "\n"
      p     print without newline

C (gcc) function, 139 bytes
i,m;f(char**s){for(i=0;i<68;)m="AB@E@JLM@OPQTU@@AC@FGH@KLN@OPSTU@@AD@FIH@JLM@OPQTU@@AB@E@JLN@OPRST@@"[i++],printf(m^64?"%s":"\n",s[m-65]);}

Try it online!

Nice. Can you explain the code?

@arminb Nothing too fancy, the long "AB@E..." String contains the indices of the tokens and newlines ABC... = token[012].. '@' = newline,  A token or newline is printed as 'i' iterates through that string.

merge the printf in for

reverse the coding

126 bytes

Red, 133 bytes
foreach c{abzezjlmzopqtuzzaczfghzklnzopstuzzadzfihzjlmzopqtuzzabzezjlnzoprstzz}[prin either c =#"z"["^/"][t/(to-integer c -#"a"+ 1)]]

Try it online!
Ungolfed
t is a block with the list of tokens
s:{abzezjlmzopqtuzzaczfghzklnzopstuzzadzfihzjlmzopqtuzzabzezjlnzoprstzz}
foreach c s[                           ; for each character in s
    prin either c = #"z"               ; if it's a 'z'
        ["^/"]                         ; print CR
        [t/(to-integer c - #"a" + 1)]  ; otherwise find which token to print
]                                      ; by mapping its offset to the alphabet

D, 166 bytes
import std.algorithm,std.range;T f(T)(T[]s){return"abvevjlmvopqtuvvacvfghvklnvopstuvvadvfihvjlmvopqtuvvabvevjlnvoprstvv".map!((int a){return(s~["\n"])[a-97];}).join;}

Try it online!

Mathematica, 102 bytes
""<>Append[#,"
"][[36^^ajikrj7lg8pya7wgtt43pvrilsik1dea1uht6mx3go33m4mjj02hb4wi9w3~IntegerDigits~23]]&

Pure function. Takes a list of strings as input and returns a string as output. Just encodes all the token indices, similarly to other answers.

Ruby, 97 bytes
->a{112.times{|i|$><<a[i%7-1+i%28/7*5]*("0@Xg(44k$,Xg0@Tz"[i/7].ord>>~i%7&1)+$/*(i%7/6+i%28/27)}}

Try it online!
Saved a few bytes with a different approach to most other answers.
The number of possible tokens in each line is as follows
Line number   Tokens
1             4
2             5
3             5
4             7

The magic string contains one character per line, which is interpreted as a bitmap of which of up to 7 available tokens is to be printed for each of the 16 lines of the song.
a[i%7-1+i%28/7*5] iterates through the tokens of each line, shifting by 5 for each new line, and with an offset of 1 to account for the fact that the first line has only 4 tokens.
For lines 1-3 only the 64's through 4's bits are used - not using the 2's and 1's bits avoids printing tokens from the next line. for line 4, all 7 bits from 64's to 1's are used.

Deadfish~, 4275 bytes
{{i}ddd}iic{iii}dc{ii}c{{d}i}ic{iiii}iic{iiii}iiic{dd}iiicic{dddddd}iiic{d}ddc{{i}ddd}ddc{i}icdc{{d}iii}dc{{i}dd}dddc{{d}ii}ddddc{{i}dd}dddc{d}ddc{i}cddddddc{{d}iii}ic{{i}ddd}iiic{i}ic{{d}ii}ddddc{iiiiii}iiiiiicdciiic{{d}i}c{{i}ddd}iiiic{i}iiic{i}cddddddc{{d}iii}ic{iiiiii}iiiiic{dddddd}dddddc{{i}dd}iiic{dd}iiciiic{{d}iii}iic{{i}dd}iiicddddcdc{d}iiic{{d}iii}dc{iiiiii}iiiiic{i}iiic{d}c{{d}iii}iic{{i}dd}dddc{d}ddc{i}cddddddc{{d}iii}ic{{i}ddd}iiic{i}ic{{d}ii}ddddc{iiiiii}iiiiiiciiic{i}iiiiicc{d}dddddc{i}iiic{{d}}ddddc{{i}ddd}iic{ii}dc{i}ddc{d}iic{i}ddc{d}dciiic{i}iiic{{d}ii}ddc{{i}dd}iiiicdddddc{{d}ii}ic{{i}ddd}iiiiiic{d}iiic{i}iiiiic{{d}ii}ddddc{{i}ddd}iicdddc{i}iiic{{d}ii}ddc{{i}ddd}iiiciiiiiciiiiiicdddddc{{d}ii}ic{{i}d}dc{d}ciiiiiicdddc{{d}ii}ddc{{i}ddd}iicdddcddddc{ii}dddciic{{d}}ddddddc{{i}ddd}iiiic{ii}cdddc{i}dc{{d}ii}iic{{i}d}dc{d}ciiiiiic{{d}ii}dddddc{{i}ddd}dddcddc{i}iiic{{d}ii}iic{{i}dd}iiicic{dd}ic{ii}dddciic{{d}ii}ddddc{{i}dd}iiiicdddddc{{d}ii}ic{{i}dd}dddc{d}ddc{i}cddddddc{{d}iii}ic{{i}ddd}iiic{i}ic{{d}ii}ddddc{iiiiii}iiiiiiciiic{i}iiiiicc{d}dddddc{i}iiic{{d}}ddddcc{iiiiii}iic{iii}dc{ii}c{{d}i}ic{iiii}iic{iiii}iiic{dd}iiicic{dddddd}iiic{d}ddc{{i}ddd}ddc{i}icdc{{d}iii}dc{{i}dd}dddc{{d}ii}ddddc{iiiiii}iiiiiiciiic{{d}iii}ic{iiiiii}iiiiiciiiiic{i}iic{dd}iiic{i}ddcdddddc{{d}i}c{{i}dd}dc{ii}iiciiiiiic{{d}ii}dddddc{{i}d}dddc{dd}iic{i}iiic{d}dddc{{d}iii}ic{{i}dd}dddc{d}ddciiicic{{d}iii}ic{{i}dd}iiiicdddddc{{d}ii}ic{{i}ddd}ic{i}ddc{{d}ii}ic{{i}dd}dciiiiiicdc{{d}ii}ddddc{iiiiii}iiiiic{i}iiic{d}c{{d}iii}iic{{i}ddd}icddc{i}iiiiic{{d}ii}ddddc{{i}ddd}iicdddc{i}iiic{{d}}ddddc{{i}ddd}iiiic{ii}cdddc{{d}iii}ic{{i}dd}dddcddddciiiiic{i}dddcdc{d}dddddc{{d}iii}ic{{i}d}dc{d}ciiiiiic{{d}ii}dddddc{{i}ddd}iiiiiic{d}iiic{i}iiiiic{{d}ii}ddddc{{i}ddd}iicdddc{i}iiic{{d}ii}ddc{{i}dd}iiiiic{d}iiic{d}cic{i}iiic{{d}ii}ddc{{i}d}dc{d}ciiiiiicdddc{{d}ii}ddc{{i}dd}iiic{d}iicddciiiiic{{d}}c{{i}ddd}iiiic{ii}cdddc{i}dc{{d}ii}iic{{i}d}dc{d}ciiiiiic{{d}ii}dddddc{iiiiii}iiiiiiciiiciiciiciiiiic{{d}ii}iic{{i}dd}iiiicdddddc{{d}ii}ic{{i}dd}dddc{d}ddc{i}cddddddc{{d}iii}ic{{i}ddd}iiic{i}ic{{d}ii}ddddc{iiiiii}iiiiiiciiic{i}iiiiicc{d}dddddc{i}iiic{{d}}ddddcc{iiiiii}iic{iii}dc{ii}c{{d}i}ic{iiii}iic{iiii}iiic{dd}iiicic{dddddd}iiic{d}ddc{{i}ddd}ddc{i}icdc{{d}iii}dc{{i}dd}dddc{{d}ii}ddddc{{i}ddd}iiiiiic{d}iiic{i}iiiiic{{d}ii}ddddc{{i}dd}dddc{d}iic{{d}iii}ic{{i}ddd}ddc{i}ic{i}ddc{d}ic{{d}}c{{i}dd}dc{ii}iiciiiiiic{{d}ii}dddddc{{i}ddd}iic{d}iiic{ii}ic{dd}iiic{{d}iii}ic{{i}ddd}c{i}dciiiiiic{d}iiic{d}c{{d}iii}iic{{i}ddd}iicdddc{i}iiic{{d}iii}c{d}ddc{{i}dd}ddcic{i}ddc{{d}i}iiic{{i}ddd}ic{i}ddc{{d}ii}ic{iiiiii}iiiiic{i}iiic{d}c{{d}iii}iic{{i}ddd}icddc{i}iiiiic{{d}ii}ddddc{{i}ddd}iicdddc{i}iiic{{d}}ddddc{{i}ddd}iic{ii}dc{i}ddc{d}iic{i}ddc{d}dciiic{i}iiic{{d}ii}ddc{{i}dd}iiiicdddddc{{d}ii}ic{{i}ddd}iiiiiic{d}iiic{i}iiiiic{{d}ii}ddddc{{i}ddd}iicdddc{i}iiic{{d}ii}ddc{{i}ddd}iiiciiiiiciiiiiicdddddc{{d}ii}ic{{i}d}dc{d}ciiiiiicdddc{{d}ii}ddc{{i}ddd}iicdddcddddc{ii}dddciic{{d}}ddddddc{{i}ddd}iiiic{ii}cdddc{i}dc{{d}ii}iic{{i}d}dc{d}ciiiiiic{{d}ii}dddddc{{i}ddd}dddcddc{i}iiic{{d}ii}iic{{i}dd}iiicic{dd}ic{ii}dddciic{{d}ii}ddddc{{i}dd}iiiicdddddc{{d}ii}ic{{i}dd}dddc{d}ddc{i}cddddddc{{d}iii}ic{{i}ddd}iiic{i}ic{{d}ii}ddddc{iiiiii}iiiiiiciiic{i}iiiiicc{d}dddddc{i}iiic{{d}}ddddcc{iiiiii}iic{iii}dc{ii}c{{d}i}ic{iiii}iic{iiii}iiic{dd}iiicic{dddddd}iiic{d}ddc{{i}ddd}ddc{i}icdc{{d}iii}dc{{i}dd}dddc{{d}ii}ddddc{{i}dd}dddc{d}ddc{i}cddddddc{{d}iii}ic{{i}ddd}iiic{i}ic{{d}ii}ddddc{iiiiii}iiiiiicdciiic{{d}i}c{{i}ddd}iiiic{i}iiic{i}cddddddc{{d}iii}ic{iiiiii}iiiiic{dddddd}dddddc{{i}dd}iiic{dd}iiciiic{{d}iii}iic{{i}dd}iiicddddcdc{d}iiic{{d}iii}dc{iiiiii}iiiiic{i}iiic{d}c{{d}iii}iic{{i}dd}dddc{d}ddc{i}cddddddc{{d}iii}ic{{i}ddd}iiic{i}ic{{d}ii}ddddc{iiiiii}iiiiiiciiic{i}iiiiicc{d}dddddc{i}iiic{{d}}ddddc{{i}ddd}iic{ii}dc{i}ddc{d}iic{i}ddc{d}dciiic{i}iiic{{d}ii}ddc{{i}dd}iiiicdddddc{{d}ii}ic{{i}ddd}iiiiiic{d}iiic{i}iiiiic{{d}ii}ddddc{{i}ddd}iicdddc{i}iiic{{d}ii}ddc{{i}dd}iiiiic{d}iiic{d}cic{i}iiic{{d}ii}ddc{{i}d}dc{d}ciiiiiicdddc{{d}ii}ddc{{i}dd}iiic{d}iicddciiiiic{{d}}c{{i}ddd}iiiic{ii}cdddc{i}dc{{d}ii}iic{{i}d}dc{d}ciiiiiic{{d}ii}iic{{i}ddd}dcc{{d}iii}ddddddc{iiiiii}iiiiiiciiiciiciiciiiiic{{d}ii}iic{{i}dd}iiiicdddddc{{d}ii}ic{{i}dd}dddc{d}ddc{i}cddddddc{{d}iii}ic{{i}ddd}iiic{i}ic

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:
Split string on first occurrence of each character
Related.
Given a printable ASCII string, split it into a list of non-empty strings with a new sub-string beginning every time a character, which has not previously been seen in the same case, occurs.
Examples
"mississippi" → ["m","i","ssissi","ppi"]

"P P & C G" → ["P"," P ","& ","C ","G"]

"AAA" → ["AAA"]

"Adam" → ["A","d","a","m"]

"" → []

Anecdote: The result will have between 0 and 95 elements. The 95th sub-string will necessarily continue until the end because at that point, all printable ASCII characters have begun a sub-string, so every additional character will have occurred before and thus cannot cause a new sub-string to begin.

An example containing " and ' seems like a good idea.

Would "" → [""] be acceptable?

Can I return a newline-separated string? Since the input contains only printable ASCII, that would be unambiguous.

Yes, I thought that was a default output format for lists of strings.

@Emigna That just messes with the example output format without bringing any further clarity.

@Arnauld I don't think so

@Arnauld No, [""] isn't a list of non-empty substrings.

Can the input be a list of characters, and the output be a list of lists of characters? ("A","d","d","a","m","s") => (("A"),("d","d"),("a"),("m"),("s"))

@BradGilbertb2gills Yes, that's covered by default I/Os.

Not sure if intentional but your 'P P & C G' → ["P"," P ","& ","C ","G"] example uses single quotes on the left and double quotes on the right.

@cole Neither is part of the string or the output array, so I doubt it matters. They're just delimiters to show the start and end of the input, not part of it, and likewise for the elements of the output.

If outputting as a newline-separated string, can there be a leading/trailing newline?

@wastl Uh, I'll permit it in this case because it cannot indicate empty segments, although it does clash with my earlier ruling of [""] to be invalid. Sigh.

Can there be both leading and trailing newlines?

@JoKing Sure, why not?

Not specified...the first string of input Mississippi would be M i s SI ppi

@RosLuP It is actually indirectly specified in the anecdote. Since there may be up to 95 substrings, and there are only 95 printable ASCII characters, this challenge must be case sensitive. I'll add a clarification anyway.

Shouldn't "Adam" be ["A","da","m"]? I'm not sure why its being split on the second a. (Compare to "Mississippi": there is no break began the first and second s)

@Draco18s which has not previously been seen in the same case

Jelly, 4 bytes
QƤĠị

Try it online!
Explanation
QƤĠị  Input is a string, say s = "adam"
 Ƥ    For each prefix of s: ["a","ad","ada","adam"]
Q     remove duplicates: ["a","ad","ad","adm"]
  Ġ   Group indices by equal values: [[1],[2,3],[4]]
   ị  Index into s: ["a","da","m"]

The internal representation of the strings, which the TIO link displays, is slightly different.

Can someone explain the logic of this solution?  I can see that it does work, but I can't get my head around why it works; like, I wouldn't have thought that indexing back into the original string where the deduped prefixes match would yield the answer.

The list p of nonempty prefixes of s has the same length as s. For each index i, the string p[i] is the prefix of s up to and including s[i]. Two adjacent chars s[i] and s[i+1] should be in the same chunk in the output if s[i+1] already occurred before index i, or in other words, in the prefix p[i]. This is equivalent to p[i] and p[i+1] having the same set of unique characters. I compute with QƤ the unique characters of each prefix p[i].

@Aaron Then with Ġ I group the indices i of this list of strings: indices i and i+1 go in the same chunk if p[i] and p[i+1] have the same unique characters. Finally, with ị I index back to the original string s, essentially grouping it into chunks in the same way as the indices i.

Thank you, that's starting to make a bit more sense for me.  Impressive answer!

Retina, 9 bytes
q1,`.
¶$&

Try it online!
Explanation
Match each character (.), discard repeated matches (q), discard the first match (1,), and insert a linefeed in front of each match ¶$&.

05AB1E, 11 bytes
ÙSk¥sg¸«£õK

Try it online!
Explanation
Ù             # remove duplicates in input
 S            # split to a list of characters
  k           # get the (first) index of each character in the input
   ¥          # calculate delta's
    sg¸«      # append the length of the input
        £     # split the list into pieces of these sizes
         õK   # remove empty string (for the special case "" -> [])

For anyone coming across this answer, ¸« can be ª in the new version of 05AB1E.

C,  75   65  63 bytes
Thanks to @Digital Trauma for saving 10 bytes and thanks to both @gastropner and @l4m2 for saving a byte each!
f(char*s){for(int l[128]={};*s;putchar(*s++))l[*s]++||puts(l);}

Prints a leading newline.
Try it online!
Without a leading newline (71 bytes):
f(char*s){int l[128]={};for(l[*s]=1;*s;putchar(*s++))l[*s]++||puts(l);}

Try it online!

64 bytes

{0} => {} ?

J, 7 bytes
~:<;.1]

Try it online!
Explanation
Nub sieve's chance to shine!
~: <;.1 ]
        ]  Input
~:         Nub sieve (1 if the character is the first instance in string)
    ;.1    Split input on 1s in nub sieve
   <       And box each

I was about to post exactly the same (not surprisingly) answer, it's good that I glanced your submission before that :)

@GalenIvanov I -- and I imagine most other J golfers, too -- relish the chance to use nub sieve or self-classify.

APL (Dyalog Unicode), 8 bytesSBCS
(≢¨∪\)⊆⊢

Try it online!

But, but… Oh my.

I suspected you might have posted this challenge because of the new primitive (⊆). Evidently not :)

It looks like an embarrassed Kirby holding a baby bottle.

Can be just three characters now ≠⊂⊢

05AB1E, 8 bytes
Ùvyy¶ì.;

Try it online!

Always will output 1 preceding newline, which is constant and not indicative of a split, the 10-byte alternative that does not output a preceding newline is Ùvyy¶ì.;}¦, you can try that here. According to Adam a preceding or trailing newline is acceptable.

Input      = mississippi                               | Stack
-----------#-------------------------------------------+----------------------------------
Ù          # Push unique letters of first input.       | ['misp']
 v         # Iterate through each unique letter.       | []
  yy       # Push 2 copies of the letter (or yD)       | ['m','m']
    ¶      # Push a newline char.                      | ['m','m','\n']
     ì     # Prepended to the letter.                  | ['m','\nm']
      .;   # Replace first instance with '\n + letter' | ['\nmississippi']

After each iteration we get:
['\nmississippi'] > ['\nm\nississippi'] > ['\nm\ni\nssissippi'] > ['\nm\ni\nssissi\nppi']

Which is:
m
i
ssissi
ppi

Nice! Beat me by a fair margin ;)

@Emigna this was sitting as a comment on your answer for 2 days then I just posted it b/c no response haha :P.

Weird, haven't seen any notification on that. Different enough for its own answer though :)

@Emigna well, I mean, I deleted it haha.

Skipping the loop saves a byte ÙSD¶ì.;. Not sure why we didn't think of that before :P

Perl 6,  58 52  40 bytes
{$/={};.comb.classify({$+=!$/{$_}++}).sort».value».join}

Try it
*.comb.classify({$+=!(%){$_}++}).sort».value».join

Try it
*.classify({$+=!(%){$_}++}).sort».value

Try it
(input is a list of characters, and output is a list of lists of characters)
Expanded:
*                   # parameter for WhateverCode lambda

  .classify(        # classify that list
    {
        $           # anonymous scalar state variable (accumulator)

      +=            # increment it if:

        !           # Bool invert the following
          (
            %       # anonymous hash state variable
          ){ $_ }++ # look to see if the character was seen already
    }
  ).sort\           # sort the Pairs by key (makes the order correct)
  ».value           # get the value from each Pair

The output from classify is
{ # Hash
  1 => ['m'],
  2 => ['i'],
  3 => ['s','s','i','s','s','i'],
  4 => ['p','p','i'],
}

And .sort just turns it into:
[
  1 => ['m'],
  2 => ['i'],
  3 => ['s','s','i','s','s','i'],
  4 => ['p','p','i'],
]

».value removes the keys
[
  ['m'],
  ['i'],
  ['s','s','i','s','s','i'],
  ['p','p','i'],
]

Why would the keys ever be out of order? Is insertion order not tracked like a HashMap vs. a LinkedHashMap in Java where the order is based on memory vs. insert order?

@MagicOctopusUrn No version of Perl has had ordered Hashes. In fact Perl 5 version 18 made Hashes more randomized which helps make a certain type of denial of service attack less possible, and has also caused buggy user code to expose it's buggy behaviour more often. Now someone could (and likely has) implement a class which does keep track, but that would take more than 5 characters to load and use.

Haskell, 39 bytes
foldl(\s c->s++['\n'|all(/=c)s]++[c])""

Try it online!
Inserts a newline symbol before every character that appears for the first time, resulting in a newline-separated string, with a leading newline. Prepend lines. to produce a list.

Haskell, 55 bytes
(""%)
_%[]=[]
p%s|(a,b)<-span(`elem`s!!0:p)s=a:(a++p)%b

Try it online!
Repeatedly takes the prefix the first character plus the non-unique characters that follow it.

@WheatWizard Oops, yes, lines.

Might want to do tail.lines to remove the extra empty string now that I think about it.

APL (Dyalog), 9 bytes
Thanks, Erik the Outgolfer for saving 1 byte!
⊢⊂⍨⍳∘≢∊⍳⍨

Try it online!
Explanation:
⍳⍨: For each character, get the index of its first occurrence. e.g mississippi -> 1 2 3 3 2 3 3 2 9 9 2
⍳∘≢: The range from 1 to the length of the input.
∊: Membership. e.g 1 2 3 4 5 6 7 8 9 10 11∊1 2 3 3 2 3 3 2 9 9 2 -> 1 1 1 0 0 0 0 0 1 0 0
⊢⊂⍨: Partition the input string with new partitions starting at 1s in the vector above

9 bytes (monadic fg and monadic f∘g behave the same)

Why ∊ instead of =?

At the time of writing, I hadn't considered that the indices would be in the correct positions. Although it is clear that they are

Japt, 11 bytes
¬â r@=iRUbY

Test it online!
Explanation
This was inspired by Magic Octopus Urn's 05AB1E solution.
¬â r@=iRUbY    Implicit: U = input string
¬â             Split U into chars, and keep only the first occurrence of each.
   r@          Reduce; for each char Y in this string...
        UbY      Find the first index of Y in U.
      iR         Insert a newline at this index in U.
     =           Set U to the result.
               As reduce returns the result of the last function call, this gives the
               value of U after the final replacement, which is implicitly printed.

Japt is having an identity crisis here, it's calling itself Ruby for some reason. iRUbY!

Python 2, 81 74 bytes

def f(s):d=sorted(map(s.find,set(s)));print map(lambda a,b:s[a:b],d,d[1:])

Try it online!

Save two with list(set(map(s.find,s)))

@JonathanAllan it's a misleading side-effect, set do not keep order, counter-proof -> s='c'*6+'a'*100+'b'

I know we cannot rely on it in future implementations but I believe given ordered integers we maintain order in the set due to the hash of an integer being the integer (as you have shown the same is not true for other objects -- can you find a word that does not work with my alternative?).

@JonathanAllan not true either

Ah, fair enough, my belief was false!

JavaScript (ES6), 37 bytes
Saved 7 bytes: a leading newline was explicitly allowed (Thanks @Shaggy!)
Takes input as an array of characters. Outputs a newline-separated string.
s=>s.map(c=>s[c]=s[c]?c:`
`+c).join``

Test cases

let f =

s=>s.map(c=>s[c]=s[c]?c:`
`+c).join``

;[
  [..."mississippi"],
  [..."P P & C G"],
  [..."AAA"],
  [..."Adam"],
  [...""]
]
.forEach(s => console.log('{' + f(s) + '}\n'))

Leading newlines are allowed so you can get this down to 37 bytes

brainfuck, 66 bytes
,[>+[<[>+<<-<+>>-]>[>]<<[[+]++++++++++.>>>]<]<[>+<-]>>>[>>]<<-.>,]

Formatted:
,
[
  >+
  [
    <[>+< <-<+>>-]
    >[>]
    <<[[+]++++++++++.>>>]
    <
  ]
  <[>+<-]
  >>>[>>]
  <<-.>,
]

Try it online
The leading newline in the output (which is only printed if the input is non-empty) can be removed at the cost of 5 bytes by replacing the body x of the main (outermost) loop with .>,[x].

Jelly, 6 bytes
ŒQœṗ⁸Ḋ

Try it online!

R, 94 87 bytes
function(s,n=nchar(s),g=substring)g(s,d<-which(!duplicated(g(s,1:n,1:n))),c(d[-1]-1,n))

Try it online!
Returns a (possibly empty) list of substrings.
Thanks to Michael M for saving 7 bytes!

function(s,n=nchar(s),g=substring)g(s,d<-which(!duplicated(g(s,1:n,1:n))),c(d[-1]-1,n)) would be shorter - and of course a bit uglier...

Why substring instead of substr?

@MichaelM Very nice! I still have to add the if(n) in there because substring throws an error for empty string input.

@plannapus substr returns a vector of length equal to its first input while substring returns one of length equal to the longest of its inputs.

@Giuseppe: Dropping the "if(n)" in R 3.4.3 maps the empty input string "" to the empty output string "", which should be fine(?)

@MichaelM oh I see. The strsplit approach needed it and I must have tested a version of that instead of yours. My bad.

It is pure luck that substring("", 1:0, 1:0) does not complaint :)

K4, 19 bytes
Solution:
$[#x;(*:'.=x)_;,]x:

Examples:
q)k)$[#x;(*:'.=x)_;,]x:"mississippi"
,"m"
,"i"
"ssissi"
"ppi"
q)k)$[#x;(*:'.=x)_;,]x:"P P & C G"
,"P"
" P "
"& "
"C "
,"G"
q)k)$[#x;(*:'.=x)_;,]x:"AAA"
"AAA"
q)k)$[#x;(*:'.=x)_;,]x:"Adam"
,"A"
,"d"
,"a"
,"m"
q)k)$[#x;(*:'.=x)_;,]x:""
,[""]

Explanation:
8 bytes is just to handle ""...
$[#x;(*:'.=x)_;,]x: / the solution
                 x: / save input as variable x
$[  ;         ; ]   / $[condition;true;false]
  #x                / length of x ("" has length 0, i.e. false)
             _      / cut right at left indices
     (      )       / do together
          =x        / group x into key/value (char!indices)
         .          / return value (get indices)
      *:'           / first (*:) each
               ,    / enlist, "" => [""]

JavaScript, 61 54 52 bytes
Takes input as an array of characters.
s=>s.map(x=>a[x]?a[y]+=x:a[x]=a[++y]=x,a=[],y=-1)&&a

Try it

o.innerText=JSON.stringify((f=
s=>s.map(x=>a[x]?a[y]+=x:a[x]=a[++y]=x,a=[],y=-1)&&a
)([...i.value=""]));oninput=_=>o.innerText=JSON.stringify(f([...i.value]))
<input id=i>

><>, 22 17 14 bytes
-1 byte thanks to Emigna
i:::a$1g?!o1po

Try it online!
Prints a leading and trailing newline.
It keeps track of which letters have already appeared by putting a copy of the character at that corresponding spot on the second row, and printing a newline if the value fetched from that position was not 1. Ends in an error when it tries to print -1

Great use of g/p! 16 bytes

Perl, 30 bytes
Includes +1 for p
Give input without trailing newline on STDIN. Output is also without trailing newline:
echo -n adam | perl -pE 's%.%$v{$&}+++!pos?$&:$/.$&%eg'; echo

If you don't care about leading and trailing newlines this 25 (+3 for -p because the code contains ') also works:
#!/usr/bin/perl -p
s%%$/x!$v{$'&~v0}++%eg

Great solution as always! Based on the test cases provided, you don't need to name your hash, you can do ${$&}++. It's not as robust, but might suffice for this challenge? Also, there's been a consensus on meta that perl -p doesn't need an additional byte, you just need to have the header as Perl with `-p`  instead of just Perl. I'm trying to remember to do that myself...

@DomHastings The annecdote about at most 95 possible strings quite strongly implies that 1 is valid, in which case the v is needed. Regarding the counting, I mostly follow https://codegolf.meta.stackexchange.com/a/7539/51507 which to me is the most consistent meta post about counting perl.

Always nice to learn from the master. Specifically, in this case, &~v0 for grabbing the first character. Thank you for joining this site and sharing your long expertise.

You can use Strawberry Perl, which uses " instead of ' with -e, and then you can count the -ep as +1 rather than +3. (Tested.)

Redoing your 30 byte solution which does not put in a leading newline, I think you can save by using a negative lookbehind to skip the first newline.  That way, the use of pos can be eliminated, also removing the need for the conditional operator.  Try it online!

Stax, 8 bytes
ç↓‼►▐NVh

Run and debug online
The ascii representation of the same program is this.
c{[Ii=}(m

For each character, it splits when the index of the current character is the current position.
c            copy the input
 {    }(     split the string when the result of the enclosed block is truthy
  [          duplicate the input string under the top of the stack
   I         get the character index of the current character
    i=       is it equal to the iteration index?
        m    print each substring

BQN, 11 6 bytes
⌈`∘⊐⊸⊔

Try it at BQN online!
Explanation
⌈`∘⊐⊸⊔
   ⊐    Classify: replace each letter with a number based on the order of
        their first occurrences
⌈`∘     Scan with maximum: replace each number with the largest number so far
    ⊸⊔  Group the original string into those buckets

A couple of worked examples:
"dodos"            "Mississippi"
⟨ 0 1 0 1 2 ⟩       ⟨ 0 1 2 2 1 2 2 1 3 3 1 ⟩
⟨ 0 1 1 1 2 ⟩       ⟨ 0 1 2 2 2 2 2 2 3 3 3 ⟩
⟨ "d" "odo" "s" ⟩   ⟨ "M" "i" "ssissi" "ppi" ⟩

SNOBOL4 (CSNOBOL4), 115 91 77 bytes
	N =INPUT
S	N LEN(1) . Y	:F(END)
	S =S Y
	N SPAN(S) . OUTPUT REM . N	:(S)
END

Try it online!
Prints the substrings separated by newlines.
Explanation:
line S (for SPLIT) doesn't actually split, but instead extracts the first character of N and saves it (.) to Y. On Failure, it jumps to END. The match should only fail when N is the empty string. Thus, when the input is empty, it jumps directly to END and outputs nothing.
S = S Y concatenates Y onto S.
SPAN(S) greedily matches a run of characters in S, and sends it (.) to OUTPUT, setting (.) N to the REMaining characters of N (if there are any). Then it jumps back to S.

Haskell, 62 bytes
r#c|any(elem c)r=init r++[last r++[c]]|1<2=r++[[c]]
foldl(#)[]

Try it online!

JavaScript (ES6), 68 bytes
s=>s.map(c=>o[c]?t+=c:(t&&m.push(t),t=o[c]=c),t='',o=m=[])&&[...m,t]

Takes input as a list of characters.
Test cases:

let f=
s=>s.map(c=>o[c]?t+=c:(t&&m.push(t),t=o[c]=c),t='',o=m=[])&&[...m,t]

console.log(f([...'mississippi']));
console.log(f([...'P P & C G']));
console.log(f([...'AAA']));
console.log(f([...'Adam']));
console.log(f([...'']));

I had a similar solution and asked if [""] was acceptable for the last test case. But it's not. :-(

Oh, well, you got a much better solution anyway : )

Ruby, 65 62 58 bytes
->s,*a{s.size.times{|i|(i==s.index(c=s[i])?a:a[-1])<<c}
a}

Try it online!
A lambda accepting a string and returning an array of strings.
Approach: For each index, either append the character at that index in s to the result array, or to the last string in the result array. String#index returns the index of the first instance of the argument.
-2 bytes: Initialize a as a splat argument instead of on its own line. Thanks, Value Ink!
-1 byte: Use c=s[i]...c instead of s[i]...s[i]. Thanks, Value Ink!
-4 bytes: Use .times instead of .map

-3 bytes by using some assignment tricks.

Python 2, 47 bytes
lambda s:reduce(lambda r,c:r+'\n'[c in r:]+c,s)

Try it online!
Outputs a newline-separated string. Barely beats the program version:
Python 2, 48 bytes
r=''
for c in input():r+='\n'[c in r:]+c
print r

Try it online!

PHP, 317 bytes
function SplitOnFirstUnique($s){
    $len = strlen($s);
    $output = [];
    $newstring = '';
    for ($i=0; $i < $len ; $i++) {
        $newstring = $newstring.$s[$i];
        if(!in_array($s[$i] , $output  )){
            $output[] = $newstring;
            $newstring = '';
        }
    }
    return $output;
}

Try it online!

Hello, and welcome to PPCG! I've edited your post to our standard format, and added a link to Try It Online so other people can test your code. The aim of Code Golf is to write the shortest code possible, and I can see a couple of ways to make this shorter, like using shorter variable names and leaving out some of the whitespace. You can check out the general tips and PHP tips pages for some more ideas.

Red, 79 bytes
func[s][foreach c next unique/case append s"^@"[print copy/part s s: find s c]]

Try it online!
Ungolfed:
f: func [s] [
    b: next unique/case append s "^@"  ; append `null` to the end of the string, than
                                       ; find the unique characters and
                                       ; store all except the first to b
    foreach c b [                      ; for each character in b
        print copy/part s s: find s c  ; print the part of the string to
                                       ; where the character is found and
                                       ; set the beginning of the string to that position
    ]
]

Java 8, 193 169 155 151 bytes
s->{for(int l=s.length(),i=0,j;i<l;i++)if(s.indexOf(s.charAt(i))==i){for(j=i;++j<l&&s.indexOf(s.charAt(j))!=j;);System.out.println(s.substring(i,j));}}

-14 bytes thanks to @raznagul (for something obvious I somehow missed myself..)
-3 bytes thanks to @O.O.Balance (again for something obvious I somehow missed myself.. :S)
Explanation:
Try it online.
s->{                    // Method with String parameter and no return-type
  for(int l=s.length(), //  The length of the input-String
          i=0,j;        //  Index integers
      i<l;i++)          //  Loop `i` from 0 to `l` (exclusive)
    if(s.indexOf(s.charAt(i))==i){
                        //   If the character at index `i` hasn't occurred yet:
      for(j=i;++j<l     //    Inner loop `j` from `i` to `l` (exclusive),
          &&s.indexOf(s.charAt(j))!=j;);
                        //     as long as the character at index `j` has already occurred
      System.out.println(//    Print:
        s.substring(i,j));}}
                        //     The substring of the input from index `i` to `j` (exclusive)

I don't think you need the if(l<1). If l is 0 the loop shouldn't be executed anyway as 0<0 is false.

@raznagul Not sure how I missed that, but you're complete right!.. >.>

You're setting i=0 twice. You can save 3 bytes by dropping the second one: for(;i<l;i++)

@O.O.Balance Not sure how that happened.. :S But thanks for noticing! :)

PowerShell, 73 bytes
{$r=@();$h=@{};[char[]]$ARGS[0]|%{if(!($h[$_]++)){$r+=""};$r[-1]+=$_};$r}

Usage
PS> & {$r=@();$h=@{};[char[]]$ARGS[0]|%{if(!($h[$_]++)){$r+=""};$r[-1]+=$_};$r} "mississipi" | ConvertTo-Json -Compress
["m","i","ssissi","pi"]

you can save some bytes - Try it online!

Ruby, 40 bytes
->a{i=0
a.slice_when{a.index(_2)==i+=1}}

Attempt This Online!

This isn't reusable - $. isn't reset on every iteration, and it might not be set to 0 if the user uses gets or $<.

@Sʨɠɠan That’s correct.

What I mean is that this is currently invalid: https://codegolf.meta.stackexchange.com/a/4940/92689

On the other hand though, it's perfectly valid to remove the outer [* and ].

@Sʨɠɠan That’s unfortunate. Thanks for the pointer. As for the [*…], without it you get an Enumerator instead of an array. Is that valid?

Yes. https://codegolf.meta.stackexchange.com/a/10753/92689 Ruby's enumerator is basically Python's version of a generator, so it applies.

@Sʨɠɠan Thanks. I've updated my answer.

Perl 5 + -pl, 22 bytes
s@.@$/x!$h{$&}++.$&@ge
Try it online!

APL (Dyalog APL), 3 bytes
≠⊂⊢

Attempt This Online!
≠ the Boolean mask indicating first occurrence of each character…
⊂ splits…
⊢ the argument

Retina 0.8.2, 22 20 19 bytes
1>`(.)(?<!\1.+)
¶$&

Try it online! Edit: Saved 2 3 bytes thanks to @MartinEnder.

@MartinEnder Ah yes, the lookahead was an artefact from a previous iteration that had to deal with overlapping matches, but I don't think I can use the non-word boundary because I need to be able to support all printable ASCII characters.

Oh, right, you can still use a limit though: https://tio.run/##K0otycxL/P/f0C5BQ09Tw95GMcZQT1uT69A2FbX//3Mzi4tBqKAgEwA

Javascript, 200 bytes
My first (I think?) attempt at code golf:
function split(s) {let x=[];let y=[];let z="";let w=1;for(l of s.split('')){if (x.includes(l)){z+=l;}else{w=!w;if (w) {y.push(z);z='';w=0;}z+=l;x.push(l);}}y.push(z);if (y.join('')==0) y=[];return y;}

You can remove almost all the spaces, no?

@Adám Ah, yes. Thanks for that tip. It's now 200 bytes.

Ideas: one-letter function name, remove most remaining spaces, remove trailing semicolons: Try it online!

In general, this may help you.

I would remove the lets and replace function split(s) with s=>. Note: you don't need to name the function unless it's recursive.

You can replace s.split('') with [...s], but I would map through the array instead of looping through it. for(l of [...s]) -> [...s].map(l=>`

I would also replace the if-else with a ternary operator. I know this is your first golfing attempt. I would recommend visiting Tips for golfing in JavaScript :)

Mathematica, 84 bytes
a@{}={};a@b_:=a@b[[;;(c@b=Position[b,Tally[b][[-1,1]]][[1,1]])-1]]~Append~b[[c@b;;]]

Defines a function a. Takes a list of characters as input and returns a list of lists of characters as output. Uses a basic recursive structure.

Perl 5 + -p, 37 bytes
for$a(32..126){$a=chr$a;s/\Q$a/\n$a/}

Run through printable ASCII and insert a newline before the first appearance
Try it online!

For 30 (use a literal newline): eval";y/ -~/~ -}/;s/a/\na/"x95

Lua, 74 bytes
t={}print(((...):gsub(".",load"c=...a=(t[c]or'\\n')..c t[c]=''return a")))

Try it online!
Prints one additional leading newline.

GNU sed, 37 bytes
(includes +1 for -r option)
s/./\n&/g
:a
s/((.).*)\n\2/\1\2/
ta

We start by prepending a newline to every character in the string; then in the loop, we remove those that precede a second or subsequent occurrence.
Note that newline can't occur in the input, as that's the separator between strings.  And it's not classified as a printable character.

C++, 176 bytes
#include<string>
#include<set>
std::string*s(std::string e){auto*r=new std::string[96];std::set<int>u;for(char p:e){if(u.find(p)==u.end())u.insert(p);r[u.size()]+=p;}return r;}

Returns an array of strings, valid strings member of the answer array are not of size 0.
Each call of the function allocate sizeof(std::string)*96, with the pointer returned, and must be delete[]d after usage.
Code to test :
auto tests = {
    "mississippi","P P & C G", "AAA", "Adam",""
};

for (const auto& a : tests) {

    std::string* res = s(a);

    for (int i = 0; i < 96; ++i) {
        if (res[i].size() > 0)
            std::cout << '\"' << res[i] << "\", ";
    }

    delete[] res;
    std::cout << '\n';
}

Would it save bytes to use #define or using for std::string?

using S=std::string should save ~10 bytes.

Oh, in addition, auto can be changed to S as well.

AWK, 63 bytes
func u(v){for(;j++<split(v,A,"");)S[s]=S[s+=m[A[j]]++?0:1]A[j]}

Try it online!
Calling function u() assigns strings to string array S[] which is of size s
TIO link has some functionality in the footer to clear assigned variables.
Might be able to save a byte or two by using FS="", but this is a more general solution.

JavaScript, 105 87 bytes
Changes: replaced poop emojis for tabs (Thanks @Adám !), replaced parenthesis and aposthrophes for template literals
a=[];f=s=>s.split``.map(x=>!a.includes(x)&&a.push(x)?'  '+x:x).join``.split`    `.slice(1);

Takes a string, returns an array of strings.
A big chunk is converting from String->[char]->String->[string]. whitout conversions, this becomes:
a=[];f=s=>s.map(x=>!a.includes(x)&&a.push(x)?'\n'+x:x).join``.slice(1);

takes char array, returns newline separated string (71 bytes).
Also, this is my first post on this stack exchange!

Welcome to the site and nice first post! This is actually 105 bytes in UTF-8, due to the emojis and we hope you'll continue to golf here!

Can't you use a literal tab instead of  to save the extra bytes?

Ohh i thought poop emojis were 2 bytes long... Fixed

PowerShell, 61 bytes
$args|% t*y|%{if(!($r-cmatch"^[$_]")){$r+=,''};$r[-1]+=$_}
$r

Try it online!

Clojure, 111 96 bytes
#(reverse(reduce(fn[[f & r :as R]i](if((set(apply str R))i)(cons(str f i)r)(cons(str i)R)))[]%))

As Jim Carrey would say: Beautiful! :D

Gema, 20 characters
?=${$1;\n}@set{$1;}?

Sample run:
bash-4.4$ gema '?=${$1;\n}@set{$1;}?' <<< 'mississippi'

m
i
ssissi
ppi

Try it online!

Java 8, 159 bytes

134 bytes of lambda + 25 bytes for HashSet import. Rip all linters and IDEs.
import java.util.HashSet;
...
s->{HashSet h=new HashSet();return s.chars().mapToObj(c->(char)c+"").reduce("",(x,y)->x+(!h.isEmpty()&h.add(y)?","+y:y)).split(",");};

Try it online!

Uiua SBCS, 6 bytes
⊜□\+◰.

Try it!
⊜□\+◰.
     .  # duplicate
    ◰   # mark firsts
  \+    # cumulative sum
⊜□      # split

Vyxal, 5 bytes
ÞUÞṗḢ

Try it Online!
  Þṗ  # Partition before
ÞU    # Uniquity mask
    Ḣ # Remove leading empty list

Scala 3, 109 bytes
_.foldLeft(Seq.empty)((l,c)=>if(l.exists(_.contains(c)))l.dropRight(1):+l.last.appended(c)else l:+c.toString)

Attempt This Online!

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

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


text:
Find prime factors of sum of non-composite Fibonacci numbers up to n
The Challenge
Given a number, find the sum of the non-composite numbers in the Fibonacci sequence up to that number, and find the prime factors of the sum.
For example, if you were given 8, the non-composite numbers would be 1, 1, 2, 3, and 5. Adding these up would get 12. The prime factors of 12 are 2, 2 and 3, so your program should return something along the lines of 2, 2, 3 when given 12.
The Objective
This is Code Golf, so the answer with the least amount of bytes wins.

The title reads like something out of a PPCG Markov chain generator. Primes and Fibonacci numbers have been way overdone (see this about primes). This isn't something I'd expect a new user to necessarily know, so a heads up for potential downvotes.

Neim, 8 bytes
fΣ}

Doesn't work on TIO, but works locally.
Explanation:
            Inclusive range [1 .. input]
 f           Fibonacci numbers
           Get elements that are only in both lists
   Σ         Keep each element where running the following is falsy
              Check if composite
     }       Close loop
             Sum
            Prime factors


text:
How many semitones
Guidelines
Task
Given two notes, inputted as strings or lists/arrays, calculate how many semitones apart they are (inclusive of the notes themselves), outputting as a number.
Explanation of a semitone:
A semitone is one step up or down the keyboard. An example is C to C#. As you can see below the note C is on a white note and C# is the black note just one above it. Semitones are the leaps from a black note to the next white note, up or down, except for:

B to C
C to B
E to F
F to E

Examples
'A, C' -> 4
'G, G#' -> 2
'F#, B' -> 6
'Bb, Bb' -> 13

Rules

The largest distance between two notes is 13 semitones.
The second inputted note will always be above the first inputted note.
You can take input as either a string, or an array/list. If you take it as a string, the notes will be comma-separated (e.g. String -> 'A, F', Array -> ['A', 'F']).
You can assume that you will always be given two valid notes.
Sharps will be denoted as # and flats will be denoted as b
Your code must support enharmonic equivalents (e.g. It must support both F# and Gb)
Your code does not need to support notes that are named with, but can be named without a sharp or flat (i.e. You do not need to support E#, or Cb). Bonus points if your code does support it though.
Your code does not need to support double sharps or double flats.
You can assume that if you get the both the same notes, or same pitch (e.g. 'Gb, Gb' or 'A#, Bb'), the second not will be exactly one octave above the first.
This is code golf so the answer with the least amount of bytes wins.

I get 2 for G -> G# because they're both included.

@HyperNeutrino Yep sorry. Mistake on my behalf.

Must we support both F# and Gb or can we assume that we'll only receive one of them?

Do we have to cater for notes like Cb or E#? What about double sharps/flats?

@StewieGriffin Yes your code must support enharmonic equivalents. I've updated the question to make it clearer. Sorry about any confusion.

@Sok No, your code does not need to support notes such as E# or Cb, and it does not need to support double sharps or flats. I've updated the question to make it clearer. Sorry about any confusion.

Such restrictive input format is not well received. Why necessarily comma-separated? Why cannot we take for example two strings?

Just to be clear, when talking from a music theory sense distance in semitones does not include the note you start on. In math it wold be represented as (X, Y] so  C to C# is 1 semitone and C to C is 12 semitones.

@Dom Yes I do know this.

@LuisMendo You CAN take it as two strings, in an array.

This is great - much better than your previous music interval challenge, +1

Amorris re @Dom's note you'll need to change your first point. The largest distance is not 13 semitones, but 12. Apologies for being picky, but we are mods on Music Stack Exchange, so we kinda should be :-)

@RoryAlsop Not sure if you have read the whole challenge, but if you have read it you will realise that it actually is 13 semitones for the scope of this task.

Python 2, 66 bytes
r=1
for s in input():r=cmp(s[1:]+s,s)-ord(s[0])*5/3-r
print-r%12+2

Try it online!

Python 2, 68 bytes
lambda s,t:13-(q(s)-q(t))%12
q=lambda s:ord(s[0])*5/3+cmp(s,s[1:]+s)

Try it online!

Extra points for being able to handle notes like B# and Fb, while still remaining the shortest so far.

JavaScript (ES6), 78 bytes
Saved 1 byte thanks to @Neil
Takes the notes in currying syntax (a)(b).
a=>b=>((g=n=>'0x'+'_46280ab_91735'[parseInt(n+3,36)*2%37%14])(b)-g(a)+23)%12+2

Test cases

let f =

a=>b=>((g=n=>'0x'+'_46280ab_91735'[parseInt(n+3,36)*2%37%14])(b)-g(a)+23)%12+2

console.log(f('A')('C'))   // 4
console.log(f('G')('G#'))  // 2
console.log(f('F#')('B'))  // 6
console.log(f('Bb')('Bb')) // 13

Hash function
The purpose of the hash function is to convert a note into a pointer in a lookup table containing the semitone offsets (C = 0, C# = 1, ..., B = 11), stored in hexadecimal.
We first append a '3' to the note and parse the resulting string in base-36, leading to an integer N. Because '#' is an invalid character, it is simply ignored, along with any character following it.
Then we compute:
H(N) = ((N * 2) MOD 37) MOD 14

Below is a summary of the results.
 note | +'3' | parsed as | base 36->10 |   *2  | %37 | %14 | offset
------+------+-----------+-------------+-------+-----+-----+--------
  C   |  C3  |    c3     |         435 |   870 |  19 |   5 |  0x0
  C#  |  C#3 |    c      |          12 |    24 |  24 |  10 |  0x1
  Db  |  Db3 |    db3    |       17247 | 34494 |  10 |  10 |  0x1
  D   |  D3  |    d3     |         471 |   942 |  17 |   3 |  0x2
  D#  |  D#3 |    d      |          13 |    26 |  26 |  12 |  0x3
  Eb  |  Eb3 |    eb3    |       18543 | 37086 |  12 |  12 |  0x3
  E   |  E3  |    e3     |         507 |  1014 |  15 |   1 |  0x4
  F   |  F3  |    f3     |         543 |  1086 |  13 |  13 |  0x5
  F#  |  F#3 |    f      |          15 |    30 |  30 |   2 |  0x6
  Gb  |  Gb3 |    gb3    |       21135 | 42270 |  16 |   2 |  0x6
  G   |  G3  |    g3     |         579 |  1158 |  11 |  11 |  0x7
  G#  |  G#3 |    g      |          16 |    32 |  32 |   4 |  0x8
  Ab  |  Ab3 |    ab3    |       13359 | 26718 |   4 |   4 |  0x8
  A   |  A3  |    a3     |         363 |   726 |  23 |   9 |  0x9
  A#  |  A#3 |    a      |          10 |    20 |  20 |   6 |  0xa
  Bb  |  Bb3 |    bb3    |       14655 | 29310 |   6 |   6 |  0xa
  B   |  B3  |    b3     |         399 |   798 |  21 |   7 |  0xb

About flats and sharps
Below is the proof that this hash function ensures that a note followed by a '#' gives the same result than the next note followed by a 'b'. In this paragraph, we use the prefix @ for base-36 quantities.
For instance, Db will be converted to @db3 and C# will be converted to @c (see the previous paragraph). We want to prove that:
H(@db3) = H(@c)

Or in the general case, with Y = X + 1:
H(@Yb3) = H(@X)

@b3 is 399 in decimal. Therefore:
H(@Yb3) =
@Yb3 * 2 % 37 % 14 =
(@Y * 36 * 36 + 399) * 2 % 37 % 14 =
((@X + 1) * 36 * 36 + 399) * 2 % 37 % 14 =
(@X * 1296 + 1695) * 2 % 37 % 14

1296 is congruent to 1 modulo 37, so this can be simplified as:
(@X + 1695) * 2 % 37 % 14 =
((@X * 2 % 37 % 14) + (1695 * 2 % 37 % 14)) % 37 % 14 =
((@X * 2 % 37) + 23) % 37 % 14 =
((@X * 2 % 37) + 37 - 14) % 37 % 14 =
@X * 2 % 37 % 14 =
H(@X)

A special case is the transition from G# to Ab, as we'd expect Hb in order to comply with the above formulae. However, this one also works because:
@ab3 * 2 % 37 % 14 = @hb3 * 2 % 37 % 14 = 4

@Neil Thanks! Your optimization saves more bytes than mine.

Huh, I actually found the reverse with my Batch solution...

@Neil Because the sign of the modulo in Batch is the sign of the divisor, I guess?

No, it's the sign of the dividend, as in JS, but it turned out to be a slightly golfier of correcting for the sign of the result which had been inverted due to an earlier golf.

Perl, 39 32 bytes
Includes +1 for p
Give the start and end notes as two lines on STDIN
(echo "A"; echo "C") | perl -pe '$\=(/#/-/b/-$\+5/3*ord)%12+$.}{'; echo

Just the code:
$\=(/#/-/b/-$\+5/3*ord)%12+$.}{

Command line flags are free now

@wastl So I've been told. I'd like to know which meta post though so I can go there and disagree :-)

My comment is a link. Feel free to click it.

Looks like this works very similarly to mine - but awesomely short for Perl, +1

@LevelRiverSt well, this is Ton Hospel.

Japt, 27 bytes
®¬x!b"C#D EF G A"ÃrnJ uC +2

Test it online! Takes input as an array of two strings.
Also works for any amount of sharps or flats on any base note!
Explanation
®¬x!b"C#D EF G A"ÃrnJ uC +2   Let's call the two semitones X and Y.
®                Ã            Map X and Y by
 ¬                              splitting each into characters,
  x                             then taking the sum of
   !b"C#D EF G A"               the 0-based index in this string of each char.
                                C -> 0, D -> 2, E -> 4, F -> 5, G -> 7, A -> 9.
                                # -> 1, adding 1 for each sharp in the note.
                                b -> -1, subtracting 1 for each flat in the note.
                                B also -> -1, which happens to be equivalent to 11 mod 12.
                                The sum will be -2 for Bb, 2 for D, 6 for F#, etc.
                              Now we have a list of the positions of the X and Y.
                  rnJ         Reduce this list with reversed subtraction, starting at -1.
                              This gets the difference Y - (X - (-1)), or (Y - X) - 1.
                      uC      Find the result modulo 12. This is 0 if the notes are 1
                              semitone apart, 11 if they're a full octave apart.
                         +2   Add 2 to the result.

Perl 5 + -p, 66 bytes
s/,/)+0x/;y/B-G/013568/;s/#/+1/g;s/b/-1/g;$_=eval"(-(0x$_-1)%12+2"

Try it online!
Takes comma-separated values.
Does also work for Cb, B#, E#, Fb and multiple #/b.
Explanation:
# input example: 'G,G#'
s/,/)+0x/; # replace separator with )+0x (0x for hex) => 'G)+0xG#'
y/B-G/013568/; # replace keys with numbers (A stays hex 10) => '8)+0x8#'
s/#/+1/g; s/b/-1/g; # replace accidentals with +1/-1 => '8)+0x8+1'
$_ = eval # evaluate => 2
    "(-(0x$_-1)%12+2" # add some math => '(-(0x8)+0x8+1-1)%12+2'

Explanation for eval:
(
    - (0x8) # subtract the first key => -8
    + 0x8 + 1 # add the second key => 1
    - 1 # subtract 1 => 0
) % 12 # mod 12 => 0
+ 2 # add 2 => 2
# I can't use % 12 + 1 because 12 (octave) % 12 + 1 = 1, which is not allowed

Ruby, 56 bytes
->a{a.map!{|s|s.ord*5/3-s[-1].ord/32}
13-(a[0]-a[1])%12}

Try it online!
The letters are parsed according to their ASCII code times 5/3 as follows (this gives the required number of semitones plus an offset of 108)
A    B    C    D    E    F    G
108  110  111  113  115  116  118

The last character (#, b or the letter again) is parsed as its ASCII code divided by 32 as follows
# letter (natural) b
1  { --- 2 --- }   3

This is subtracted from the letter code.
Then the final result is returned as 13-(difference in semitones)%12

Stax, 25 24 bytes
╝─°U┤ƒXz☺=≡eA╕δ┴╬\¿☺zt┼§

Run and debug it online
The corresponding ascii representation of the same program is this.
{h9%H_H32/-c4>-c9>-mrE-v12%^^

Effectively, it calculates the keyboard index of each note using a formula, then calculates the resulting interval.

Start from the base note, A = 2, B = 4, ... G = 14
Calculate the accidental offset 2 - code / 32 where code is the ascii code of the last character.
Add them together.
If the result is > 4, subtract 1 to remove B#.
If the result is > 7, subtract 1 to remove E#.
Modularly subtract the two resulting note indexes, and add 1.

["F#","B"] should be 6.

Thanks.  I changed one half of the calculation without adjusting the other.  It's fixed.

Python 3, 95 bytes
lambda a,b:(g(b)+~g(a))%12+2
g=lambda q:[0,2,3,5,7,8,10][ord(q[0])-65]+" #".find(q.ljust(2)[1])

Try it online!
-14 bytes thanks to user71546

-8 bytes with ord(q[0])-65 replacing "ABCDEFG".find(q[0]) ;)

Oh, -6 more bytes with (g(b)+~g(a))%12+2 replacing 1+((g(b)-g(a))%12or 12)

@user71546 oh cool, thanks!

Batch, 136 135 bytes
@set/ac=0,d=2,e=4,f=5,g=7,a=9,r=24
@call:c %2
:c
@set s=%1
@set s=%s:b=-1%
@set/ar=%s:#=+1%-r
@if not "%2"=="" cmd/cset/a13-r%%12

Explanation: The substitutions in the c subroutine replace # in the note name with +1 and b with -1. As this is case insensitive, Bb becomes -1-1. The variables for C...A (also case insensitive) are therefore chosen to be the appropriate number of semitones away from B=-1. The resulting string is then evaluated, and @xnor's trick of subtracting the result from the value gives the desired effect of subtracting the note values from each other. Edit: Finally I use @Arnauld's trick of subtracting the modulo from 13 to achieve the desired answer, saving 1 byte.

Jelly, 28 bytes
O64_ṠH$2¦ḅ-AḤ’d5ḅ4µ€IḞṃ12FṪ‘

A monadic link accepting a list of two lists of characters and returning an integer.
Try it online! or see all possible cases.
How?
Performs some bizarre arithmetic on the ordinals of the input characters to map the notes onto the integers zero to twelve and then performs a base-decompression as a proxy for modulo by twelve where zero is then replaced by 12 then adds one.
O64_ṠH$2¦ḅ-AḤ’d5ḅ4µ€IḞṃ12FṪ‘ - Main link, list of lists    e.g. [['F','#'],['B']]  ...or [['A','b'],['G','#']]
                  µ€         - for €ach note list          e.g.  ['F','#'] ['B']          ['A','b'] ['G','#']
O                            - { cast to ordinal (vectorises)    [70,35]   [66]           [65,98]   [71,35]
 64                          -   literal 64
   _                         -   subtract (vectorises)           [-6,29]   [-2]           [-1,-34]  [-7,29]
        ¦                    -   sparse application...
       2                     -   ...to indices: [2] (just index 2)
      $                      -   ...do: last two links as a monad:
    Ṡ                        -          sign                     [-6,1]    [-2]           [-1,-1]   [-7,1]
     H                       -          halve                    [-6,-0.5] [-2]           [-1,-0.5] [-7,0.5]
         ḅ-                  -   convert from base -1            5.5       -2             0.5       7.5
           A                 -   absolute value                  5.5       2              0.5       7.5
            Ḥ                -   double                          11.0      4              1.0       15.0
             ’               -   decrement                       10.0      3              0.0       14.0
              d5             -   divmod by 5                     [2.0,2.0] [0,3]          [0.0,0.0] [2.0,4.0]
                ḅ4           -   convert from base 4             10.0      3              0.0       12.0
                             - } -->                             [10.0,3]                 [0.0,12.0]
                    I        - incremental differences           [-7.0]                   [12.0]
                     Ḟ       - floor (vectorises)                [-7]                     [12]
                      ṃ12    - base decompress using [1-12]      [[5]]                    [[1,12]]
                         F   - flatten                           [5]                      [1,12]
                          Ṫ  - tail                              5                        12
                           ‘ - increment                         6                        13

Also at 28 bytes...
A (not so direct) port of xnor's Python 2 answer...
O×5:3z60_Ṡ¥2¦60U1¦Fḅ-‘N%12+2

Try all possible cases

CJam, 67 bytes
l',/~)@)@{ciW*50+_z/}_@\~@@~-@@{ci65- 2*_9>-_3>-}_@\~@@~12+\- 12%+)

Online interpreter: http://cjam.aditsu.net/

Raku, 121 bytes
I write quite a lot of music in EDOs other than 12 so I implemented an option to choose a particular EDO.
{1+(round($^c*log2(3))*([-](map {m:P5/([A-G])(\#*)(b*)/;4613502.comb[$0.ord-65]+7*($1.comb-$2.comb)},($^b,$^a)))%$c||$c)}

No TIO link because TIO has an outdated Rakudo, so here are some examples:
f("A", "C", 12) # => 4
f("Bb", "Bb", 12) # => 13
f("F#", "B", 19) # => 9
f("G", "G#", 31) # => 3
f("C", "Dbb", 31) # => 2


text:
Flatten a Stack Cats program
Stack Cats is a reversible, stack-based language. Its reversible nature makes for somewhat weird loops. This challenge is about the conditional loop (...). When these loops are nested in certain ways, it's possible to transform the code to reduce the nesting depth. Here are the rules (where A and B stand for an arbitrary snippets):

When one loop starts with another loop, we can extract the inner loop to the front: ((A)B) becomes (A)(B).
When one loop ends with another loop, we can extract the inner loop to the end: (B(A)) becomes (B)(A).
Empty loops, (), can be removed from the program entirely. As a corollary (in conjunction with the other rules), ((A)) is equivalent to (A).

The only nested loops that will remain are of the form (A(B)C), where A, B and C are non-empty.
The Challenge
You're given a valid Stack Cats program and your task is to reduce the nesting level of loops as much as possible, leaving no empty loops, using the above transformations.
A valid Stack Cats program...

... consists only of the characters ()/\<>[]{}!"*+-:=ITX^_|.
... has mirror symmetry (e.g. \(]{}!{}[)/ is a valid program, but /|/ isn't).
... has correctly matched and nested () and {} ([], <> and \/ don't necessarily need to be matched as usual, although they'll appear in pairs due to the mirror symmetry requirement).

You can take either a string or a list of characters as input, but output needs to be presented in the same format.
You may write a program or a function and use any of our standard methods of receiving input and providing output. Note that these loopholes are forbidden by default.
This is code-golf, so the shortest valid answer – measured in bytes – wins.
Test Cases
Test cases are two lines each (input and output), separated by empty lines. Note that one output is empty. You also need to support the empty input (which should result in empty output).
(((=+|+=)))
(=+|+=)

({(=+|+=)})
({(=+|+=)})

((\)/)I(\(/))
(\)(/)I(\)(/)

(()()(())()())

((<|>((X((T)))[_]))\^/(([_](((T))X))<|>))
(<|>)(X)(T)([_])(\^/)([_])(T)(X)(<|>)

Just to be sure, loops we have to extract are only indicated by parenthesis (), so an input {{A}B} will remain as is and won't be extracted to {A}{B} as well?

@KevinCruijssen Yes, the transformation is only valid for (...)-type loops.

In the final test case, why is \^/ inside parenthesis?

@KevinCruijssen Those are the outermost parentheses after you extract (<|>((X((T)))[_])) and (([_](((T))X))<|>).

Ah I see. So ((A)B(C)) will become (A)(B)(C) due to both rules 1 and 2 subsequently: ((A)B(C)) → (A)(B(C)) (rule 1) → (A)(B)(C) (rule 2).

@KevinCruijssen Exactly.

Is this possible in Stack Cats? I’ve got a thing for meta-programming

@StanStrum Stack Cats is Turing-complete, so knock yourself out. ;) (But it's not exactly easy to program in, so I'd be absolutely floored if anyone actually manages to solve this in Stack Cats.)

Note that it's possible to convert from C (8cc) to BF, and from BF to SKS, but doing that would be considered a non serious contender.

Retina 0.8.2, 113 107 67 66 bytes
+`\(\)|(\()?(\(((\()|(?<-4>\))|[^()])*(?(4)@)\))(?(1)|(\)))
$5$2$1

Try it online! Includes 3 4 byte saving thanks to @MartinEnder. Explanation:
+`

Repeatedly apply the substitution until there are no matches.
\(\)|

Match an empty loop (in which case nothing is captured so the substitution simply deletes it) or:
(\()?

Optionally match a (. This is captured in group 1 if it matched, but not if it didn't.
(\(

Capture the main body of the match in group 2 and match a (.
(
 (\()
|
 (<-4>\))
|
 [^()]
)*

Repeatedly match either a (, capturing it in group 4, or a ), removing a capture from group 4 (failing if there isn't one), or something else.
(?(4)@)

Ensure that there are no spare captures left in group 4.
\))

End capture group 2 with another ).
(?(1)|(\)))

If capture group 1 was empty, then capture a ) in capture group 5. (So exactly one of those two groups will have a capture).
$5$2$1

Move the bracket captured in either group 1 or group 5 to the other side of group 2. This has the effect of moving the inner loop to the front or the end of the outer loop depending on which side it matched.

Stax v1.0.3+, 76 65 64 62 58 bytesCP437
îÜ•$o,Γ{í]Üf╒9♦╛üΣóç*\$ñ₧└ΦJ♠¥c╥jóu≥3E.╘ⁿ◄◘W₧<¶┼7úê╟┴zç↨aG

70 bytes when unpacked,
{{.((:/Yc{Z{40=+_41=-c^Ci~^Fdy,,\32&jEa:{a:{a4l$c}Md}X!:Rx!:Rc.()z:rgp

Run and debug online!
Explanation
{.((:/Yc{Z{40=+_41=-c^Ci~^Fdy,,\32&jEa:{a:{a4l$c}Md is a block that separates A((B)C)D into four parts and convert it to A(B)(C)D.
X!:Rx!:R executes the block on the input string (step 1), then reflects the string (string reflection in Stax refers to reversing the string plus replacing (translating) (<[{/ with (to) \}]>) ) and execute the block on the string obtained, and then reflect it back (step 2). Step 2 is essentially converting (A(B)) to (A)(B).
c.()z:r remove all empty loops (step 3).
gp is a generator that finds the fix point of an iteration. In this case the string is iterated with the 3-step process until it no longer changes.
Implicit output.

Python 3, 226 223 212 206 bytes
Okay, here is an attempt to solve this in a language that doesn't support recursive regex.
lambda s:g(g(s,*'()'),*')(').replace('()','')
def g(s,t,u):
 m,*a={},;i=v=0
 for c in s:
  i+=1;a+=[i]*(c==t)
  if c==u:*a,x=a;m[x]=i;v=m.get(x+1)
  if v:return g(s[:x]+s[x+1:v]+t+s[v:],t,u)
 return s[::-1]

Try it online!
Edits:

Refactored [::-1] to save 6 bytes, thanks to Mr.Xcoder.

The g function is the basic building block, which finds an occurrence of ((A)B), changes it to (A)(B), then applies itself to the result until no more transformation is possible.
The main steps are:

Apply g to the input normally.
Apply g to the input flipped. This run finds the occurrence of ))A(B( in the reversed input, which effectively handles (A(B)).
Remove any occurrence of ().

The problem is, g has so bad control structure that trying to one-line it made it bloat badly, so I don't think major improvement is possible based on this solution.