text:
Is there a face in this image?
Help, I've been diagnosed with prosopagnosia! This means I'm no longer able to recognise faces.... :(
Can you help me?
The challenge
You will be given an image as a matrix of regular ASCII characters separated by new line characters, and your task is to determine if it contains a face. Faces will look something like the following:
o.o
.7.
___

Of course, people all look different - the only features that virtually everyone has are two eyes, a nose, and a mouth. For this challenge, eyes will be a lower-case o, a nose will be a 7, and the mouth will be a line of underscores _. For this challenge, faces must have all of these features.
To be specific, a face must have two eyes in the same row of the matrix, with a nose centred horizontally between them somewhere between the rows with the eyes and the mouth, and a mouth at the bottom of the face that is a row of underscores that extends all the way from the column of one eye to the other. Since a face must have a horizontally-centred nose, all faces must be an odd number of characters wide. Please note: The nose does not have to be centred vertically so long as it is between the rows of the eyes and mouth (exclusive). No other features of the face matter so long as the face has only two eyes, one nose, and one mouth - the "fill" of the face can be anything but the characters o, 7, or _
The output format is flexible - all you must be able to do is distinguish whether the image from the input has a face. You may use any output values to represent whether an image has a face (e.g. 1 if it does, 0 if it does not)
Examples/Test Cases
...o.....o.
......7....
..._______.

^ contains a face
...o.....o.o.o
......7.....7.
..._______.___

^ contains a face (actually contains two but your program does not need to care about any additional faces)
o.o...o..o
o.7.7._.7.
.._____7__

^ does not contain a face
o.o...o..o
o...7...7.
.._____7__

^ contains a face (notice the two differences between this case and the one above)
o...o
.7...
_____

^ does not contain a face, as the nose is not centred horizontally
..o...o
.......
.......
.......
....7..
.______

^ contains a face formed by the last five columns
,/o[]8o
o198yH3
f_3j`~9
()**&#^
*#&^79%
2______

^ contains a face (the last five columns form a face just like in the previous example, except with different filler characters that make it less human-readable)
o..o.o..o.o...o..o.o.o..o...o.o.o.o.o
......7....o7......7......7......7...
..7...............___......7....___..
____.____.___._.._____.._____._______

^ contains a face (only the 3x3 face in the fifth-last through third-last columns is a face - all the other potential faces break one or more rules)
.....
.o.o.
..7..
.....
.___.

^ contains a face
o7o
...
___

^ does not contain a face
A few extra clarifications
-Faces will never be rotated
-The .'s in the test cases could be any regular ASCII characters other than the three special characters, they are periods just for better readability
-You can assume all matrices will be smaller than 100 x 100
Scoring
This is code-golf. Shortest code wins!

May we output a list of valid faces as truthy and an empty list as falsey? Or has the truthy/falsey output has to be consistent?

@KevinCruijssen since the output format is flexible, I'm going to allow this. So long as the program can tell the difference between a face and no face, then it's fine

@Noodle9 the characters next to the mouth can be anything, including mouth characters. There's an example of this in the sixth test case already

Suggested test case (space is line break): o7o ... ___

@Zgarb good idea

@DanielH. "he "fill" of the face can be anything but the characters o, 7, or _" Doesn't this contradict your comment above: "the characters next to the mouth can be anything, including mouth characters".  Is the mouth an exception to the rule?  I don't see that noted in the question itself.

@Jonah the fill of the face means the characters inside the square of the face itself. Characters outside the face can be anything, which means yes, there could be special characters outside the face that are not part of any faces

Does it mean, in the rectangle recognized as a face, there should be only two o, one 7, and a underline at the bottom? For example, o_o .7. ___ is invalid since there is an extra _ on it.

I must be taller than you; I think an L makes a better nose than a 7, but that means looking down on the face from slightly above right instead of below left.

@tsh Yes, that's bang on.

@Neil I agree having an upwards-pointing nose looks a little odd, but when I was designing this challenged using an L also looked odd for some reason, so I went with a 7

Suggested falsy test case.  One of my earlier solutions was passing all the test cases but incorrectly returning true for this.

05AB1E, 61 60 57 bytes
3тŸãε`I€Œsδùø€Œsδù€`}€`ʒćÁ„ooÅ?sRćÙ'_Qs€Ås7¢y¨J…_7oS¢2ÝQP

Input as a list of lines. Outputs a list of valid faces as truthy, or an empty list [] as falsey. If this is not allowed, the ʒ can be ε and a trailing }à has to be added, to output 1 for truthy and 0 for falsey.
Try it online or verify all test cases. (Sometimes times out for the last biggest test case.)
Explanation:
Step 1: Transform the input into \$n\$ by \$m\$ blocks:
3тŸ              # Push a list in the range [3,100]
   ã             # Create all possible pairs by taking the cartesian product
ε                # Map each pair [m,n] to:
 `               #  Pop and push the m,n separated to the stack
  I              #  Push the input-list
   €             #  For each row:
    Œ            #   Get all substrings
      δ          #  For each list of substrings:
     s ù         #   Keep those of a length equal to `n` (using a swap beforehand)
        ø        #  Zip/transpose; swapping rows/columns
                 #  (we now have a list of columns, each with a width of size `n`)
         €       #  For each column of width `n`:
          Œ      #   Get all sublists
            δ    #  For each list of sublists:
           s ù   #   Keep those of a length equal to `m` (using a swap beforehand)
              €` #  And flatten the list of list of lists of strings one level down
}€`              # After the map: flatten the list of list of strings one level down

Try just this first step online.
Step 2: Keep the \$n\$ by \$m\$ blocks which are valid faces:
ʒ                # Filter the list of blocks by:
 ć               #  Extract the first row; pop and push the remainder-list and first row
                 #  separated to the stack
  Á              #  Rotate the characters in the string once towards the right
   „ooÅ?         #  Check if the string now starts with a leading "oo"
 s               #  Swap to get the remaining list of rows
  R              #  Reverse the list
   ć             #  Extract head again, to get the last row separated to the stack
    Ù            #  Uniquify this string
     '_Q        '#  And check if it's now equal to "_"
 s               #  Swap to get the remaining list of rows
  €              #  For each row:
   Ås            #   Only leave the middle character (or middle 2 for even-sized rows)
     7¢          #  Count the amount of 7s in this list
 y               #  Push the entire block again
  ¨              #  Remove the last row (the mouth)
   J             #  Join everything else together
    …_7oS        #  Push string "_7o" as a list of characters: ["_","7","o"]
         ¢       #  Count each in the joined string
          2Ý     #  Push the list [0,1,2]
            Q    #  Check if the two lists are equal
 P               #  And finally, check if all checks on the stack are truthy
                 # (after which the filtered result is output implicitly)

JavaScript (ES6),  147 ... 140  139 bytes
Returns either false or a truthy value.
s=>(p='',g=k=>s.replace(/[^7o_]/g,0).match(`o${p}${p+=0}o${S=`.{${w=s.search`
`-k}}(0${p+p}.{${w}})*`}${p+7+p+S}__{${k}}`)||w>0&&g(k+2))(2)

Try it online!
How?
We start with \$k=2\$ and \$p\$ set to an empty string.
At each iteration, we first replace all characters in the input string \$s\$ other than "o", "7" or "_" with zeros. This includes linefeeds. So the first test case:
...o.....o.
......7....
..._______.

is turned into:
flat representation: "...o.....o.¶......7....¶..._______."
after replace()    : "000o00000o00000000700000000_______0"

We then attempt to match the 3 parts of a face of width \$k+1\$.
Eyes
An "o" followed by \$k-1\$ zeros, followed by another "o":
`o${p}${p+=0}o`

Followed by the padding string \$S\$ defined as:
`.{${w=s.search('\n')-k}}(0${p+p}.{${w}})*`
 \______________________/ \____________/ |
   right / left padding      k+1 zeros   +--> repeated any
                          + same padding      number of times

Nose
\$k/2\$ zeros, followed by a "7", followed by \$k/2\$ zeros, followed by the same padding string \$S\$ as above:
`${p+7+p+S}`

Mouth
\$k+1\$ underscores:
`__{${k}}`

In case of failure, we try again with \$k+2\$. Or we stop as soon as the variable \$w\$ used to build \$S\$ is less than \$1\$, meaning that the padding string would become inconsistent at the next iteration.
For the first test case, we successively get the following patterns:
o0o.{9}(000.{9})*070.{9}(000.{9})*__{2}
o000o.{7}(00000.{7})*00700.{7}(00000.{7})*__{4}
o00000o.{5}(0000000.{5})*0007000.{5}(0000000.{5})*__{6}

The 3rd one is a match.

Python 3.8, 264 \$\cdots\$ 223 222 bytes
Saved a whopping 16 bytes thanks to Kevin Cruijssen!!!
Saved a byte thanks to Tanmay!!!
import re
b='[^o7_]'
def f(l):
 while l:
  s,p=l.pop(0),1
  while m:=re.compile(f'o{b}+o').search(s,p-1):
   a,p=m.span();d=p-a;e=d//2
   if re.match(f'({b*d})*{b*e}7{b*e}({b*d})*'+'_'*d,''.join(s[a:p]for s in l)):return 1

Try it online!
Inputs a list of strings.
Outputs \$1\$ for a face, None otherwise.
How
Looks for pairs of eyes in each row, starting from the top, by repeatedly removing the top row from the input list. If a pair is found, the columns  forming the pair are taken from the remaining rows and concatenated together. This string is then tested against a regex constructed from the distance separating the eyes to see if we've found a face. If not, we continue scanning the current line, beginning at the stage-left eye, looking for more pairs before moving onto the next row.

You can put the re.compile('o[^o7_]+o') directly at the r.search(s,p-1): to save a couple of bytes. In addition, both d//2 can be d/2. And you can remove the return 0 and use None as falsey result instead. Try it online 248 bytes

@KevinCruijssen Very nice - thanks! :-)

There is a 22 byte solution You had a space in line def f ;-). The tio link is too long to paste it in comment, but here's a link for the tio link :-)

@Tanmay Oops, well spotted - thanks! :D

@Noodle9 You welcome. I was trying to golf your code(It's the first time a did it ;-)) when I went with the cursor to the space. :D

A variable called l should be reason to be exiled from the forum even in code golf.

@Alfe Howdy, you must be new around these here parts if a little thing like that irks you. Just take a look at the answer below! T_T

@Noodle9 Not so new, no ;-)  And my comment was kind of tongue in cheekish.  Still, you could have used e or L or anything except for l which looks like 1, especially in a while l.  It's code golf, not the www.ioccc.org .

@Alfe l is short for list and only FORTRAN programmers use capital letters! :P

Regex (PCRE2), 203 193 177 181 bytes
/((?|^()|^(?:.(?=.*
(\2.)))+){2}(?(8)(?=\8$)(?|()|(?:(?6)(?=.+((?6)\3)\7$))++){2}((?6)|(?!\5)7())\3(?=\7$)|o([^o7_])+o)(?|()|\7(?:.(?=.*
.*(.\7)))+){2}
(?=\2(.*)))+\5.*(?=\8)_+\7$/m

Try it on regex101
Explanation
((?|^()|^(?:.(?=.*\n(\2.)))+){2}(?(8)(?=\8$)(?|()|(?:(?6)(?=.+((?6)\3)\7$))++){2}((?6)|(?!\5)7())\3(?=\7$)|o([^o7_])+o)(?|()|\7(?:.(?=.*\n.*(.\7)))+){2}\n(?=\2(.*)))+
Main loop. Matches everything except for the mouth:
(?|^()|^(?:.(?=.*\n(\2.)))+){2} - on each line, match the padding to the left of the face, while counting a matching number of characters of padding into \2 from the start of the next line. This needs to use a Branch Reset Group (?|...) in order to initialize \2 to empty with ^() before building it up one character at a time with (\2.). The {2} guarantees that both stages will execute exactly once, and do so in the correct order due to each one having a ^ anchor (which matches the start of any line due to the /m flag). Replacing the {2} with + wouldn't work because a loop will immediately terminate after any optional iteration that matches zero characters. Note that in the case of zero padding, the first stage will execute twice in a row.
(?(8)...|...eyes...) - Only allow matching the eyes if we haven't already captured \8, i.e. iterated through the main loop at least once.
(?!\7)o([^o7_])+o - match the eyes, and define the subroutine (?6) to do [^o7_].
(?=\8$)(?|()|(?:(?6)(?=.+((?6)\3)\7$))++){2}((?6)|(?!\5)7())\3(?=\7$) - Match the facial part of a row either containing no facial features, or containing the nose.
(?=\8$) - assert that we're starting at the proper column, which was marked when the previous row was processed
(?|()|(?:(?6)(?=.+((?6)\3)\7$))++){2} - build up the facial part of the row one character at a time on the left and right ends. The right part is built up in \3. Both ends a built towards the center. The ++ ensures this is done the maximum number of times; with an even length both ends would meet, and with an odd length one character is left between them.
This uses a Branch Reset Group and {2} the same way as before, except that we guarantee both stages execute in the correct order differently. The ++ guarantees the second stage won't execute twice. The fact that an empty match would result in (?=\7$) failing to match guarantees that the first stage executes first. The fact that executing the two stages in the wrong order would result in too-long row (with the previous value of \3 tacked in) guarantees the stages execute in the correct order.
((?6)|(?!\5)7()) - match either the absence of a nose or a nose. (?6) matches the absence of a nose, and (?!\5)7() matches a nose; () here sets \5 to mark the fact that we've matched a nose, and (?!\5) prevents matching a nose if we've already done so.
\3 - match the right half of the facial part of the row, which we built up.
(?=\7$) - assert that we're now at the first column directly to the right of the face.
(?|()|\7(?:.(?=.*\n.*(.\7)))+){2} - match the padding to the right of the facial part of this line, while counting a matching number of characters of padding into \7 from the corresponding part of the next line. Uses the same Branch Reset Group {2} trick as before, except that we guarantee both stages execute in the correct order in yet another different way. Sticking a \7 in front of the second stage forces it to match too many characters if it tries to execute the second stage first, because the previous value of \7 will be concatenated to the desired number of characters, which would only match in invalid input that has a line longer than the previous line. And the subsequent \n (seen below) prevents the first stage from executing twice on any valid input, because that would only match on a line shorter than the previous line. Note that in the case of zero padding, the first stage will execute twice in a row.
\n(?=\2(.*)) - match the end of the current line, and capture a marker for the desired starting column of the facial part of the next row in \8.
Upon finishing the main loop, we reach \5.*(?=\8)_+\7$:
\5 - assert that we matched a nose.
.*(?=\8) - skip to the correct starting column, as marked when the previous line was processed.
_+ - match the mouth.
\7$ - assert that the mouth ended at the proper column.
Regex (PCRE2), 363 322 283 199 182 184 186 bytes
This version goes above and beyond the problem statement, allowing the input to have variable-length lines.
/((?|^()|^(?:.(?=.*
(\2.)))+){2}(?=(?(8)(?=\8\9)(?|()|(?:(?6)(?=.+((?6)\3)\9))++){2}((?6)|(?!\5)7())\3(?=\9)|o([^o7_
])+o)(.*))(?|()|\8(?:.(?=.*
\2(\8.)(\C*)))+){2}\7
)+\5.*(?=\8)_+\9$/m

Try it on regex101
Explanation
((?|^()|^(?:.(?=.*\n(\2.)))+){2}(?=(?(8)(?=\8\9)(?|()|(?:(?6)(?=.+((?6)\3)\9))++){2}((?6)|(?!\5)7())\3(?=\9)|o([^o7_\n])+o)(.*))(?|()|\8(?:.(?=.*\n\2(\8.)(\C*)))+){2}\7\n)+
Main loop. Matches everything except for the mouth:
(?|^()|^(?:.(?=.*\n(\2.)))+){2} - on each line, match the padding to the left of the face, while counting a matching number of characters of padding into \2 from the start of the next line. This needs to use a Branch Reset Group (?|...) in order to initialize \2 to empty with ^() before building it up one character at a time with (\2.). The {2} guarantees that both stages will execute exactly once, and do so in the correct order due to each one having a ^ anchor (which matches the start of any line due to the /m flag). Replacing the {2} with + wouldn't work because a loop will immediately terminate after any optional iteration that matches zero characters. Note that in the case of zero padding, the first stage will execute twice in a row.
(?(8)...|...eyes...) - Only allow matching the eyes if we haven't already captured \8, i.e. iterated through the main loop at least once.
o([^o7_\n])+o - match the eyes, and define the subroutine (?6) to do [^o7_\n]. We need to explicitly exclude \n because otherwise the first row of the facing (containing the eyes) could be matched with newline(s) included between the eyes, which if orchestrated just right, could result in fooling the rest of the algorithm into matching a face. An alternative way of preventing this would be to capture \7 using (\C*) instead of (.*) (which a previous version did), i.e. capturing everything to the end of the string (including newlines) instead of just to the end of the current line, but this results in worse golf, because we would also need to do (?=\7).*\n instead of \7\n, costing 6 bytes total.
(?=\8\9)(?|()|(?:(?6)(?=.+((?6)\3)\9))++){2}((?6)|(?!\5)7())\3(?=\9) - Match the facial part of a row either containing no facial features, or containing the nose. (Do this in a lookahead so that we can iterate a second time over the same characters, in order to count them.)
(?=\8\9) - assert that we're starting at the proper column, which was marked when the previous row was processed
(?|()|(?:(?6)(?=.+((?6)\3)\9))++){2} - build up the facial part of the row one character at a time on the left and right ends. The right part is built up in \3. Both ends a built towards the center. The ++ ensures this is done the maximum number of times; with an even length both ends would meet, and with an odd length one character is left between them.
This uses a Branch Reset Group and {2} the same way as before, except that we guarantee both stages execute in the correct order differently. The ++ guarantees the second stage won't execute twice. The fact that an empty match would result in (?=\9) failing to match guarantees that the first stage executes first. The fact that executing the two stages in the wrong order would result in too-long row (with the previous value of \3 tacked in) guarantees the stages execute in the correct order.
((?6)|(?!\5)7()) - match either the absence of a nose or a nose. (?6) matches the absence of a nose, and (?!\5)7()) matches a nose; () here sets \5 to mark the fact that we've matched a nose, and (?!\5) prevents matching a nose if we've already done so.
\3 - match the right half of the facial part of the row, which we built up.
(?=\9) - assert that we're now at the first column directly to the right of the face.
(.*) - capture a marker \7 for the column directly to the right of the facial part of the current line
(?|()|\8(?:.(?=.*\n\2(\8.)(\C*)))+){2} - match the facial part of the current line again, this time to count the characters in it, so as to build up a capture in \8 of a matching number of characters from the facial part of the next line, as a marker for column alignment, and capture in \9 a marker for the column directly to the right of the facial part of that line. Uses the same Branch Reset Group {2} trick as before, and a very similar way of guaranteeing that both stages execute in the correct order. Sticking a \8 in front of the second stage forces it to match too many characters if it tries to execute the second stage first, because the previous value of \8, not having been emptied by running the first stage, will be concatenated to the desired number of characters; this prevents \7\n from matching later. And a match can't result from executing the first stage twice – doing so would match an empty row, but the lookahead that matched the facial row the first time already guaranteed that it's of nonzero length.
\7\n - match the non-facial ending of the current line, ensuring that we ended on the correct column.
Upon finishing the main loop, we reach \5.*(?=\8)_+\9$:
\5 - assert that we matched a nose.
.*(?=\8) - skip to the correct starting column, as marked when the previous line was processed.
_+ - match the mouth.
\9$ - assert that the mouth ended at the proper column.
+2 bytes (184 → 186) to fix a bug found by jaytea

Belated welcome back! Anyway, thanks for using branch reset groups - I had never heard of them before, given that .NET allows you to name multiple capture groups with the same name (or even number) without any difficulty whatsoever.

@Neil Thanks! And that's pretty cool; I didn't know .NET could do that. In PCRE, group names can't begin with a digit, and while the /J flag allows reusing group names, this can only override a value that has already been captured if the duplicate name occurs further left (or at the same point) in the pattern than when it was leftmost previously captured, making it of very limited use. For example, /^(?:(?<a>b)?(?<a>a)\k'a'){2}\k'a'$/J matches aaaaa, aababb, bababb, or babbabb, not aabaaa, baaaaa, or baabaaa.

Retina 0.8.2, 129 120 bytes
T`o7\_p`o7=-
((?<=(.)*)(?(1)\3-7-\3|o((-)*)-\3o).*¶(?>(?<-2>.)*)((?<=(.)*)-\3-\3-.*¶(?>(?<-6>.)*))*){2}(?>(?<-4>==)*)===

Try it online! Outputs 0 if there is no face, otherwise a positive integer number of nonoverlapping faces. Edit: Bug fix for minimal-width faces and saved 9 bytes thanks to @Deadcode. Explanation:
T`o7\_p`o7=-

Transliterate everything other than o, 7 and _ to -. _ gets transliterated to = as that avoids having to quote it again. (I used - as I find spaces confusing.) The next stage then defaults to a match count stage.
(

Group 1 is just here so that it can be repeated.
(?<=(.)*)

Count the current indentation into capture group 2.
(?(1)\3-7-\3|o((-)*)-\3o)

If capture group 1 has already been matched, then match -7- surrounded by capture group 3 (the nose), otherwise match o, a string of -s into capture group 3 and its count into capture group 4, another -, a copy of capture group 3, and a final o (the eyes).
.*¶(?>(?<-2>.)*)

Match until the same amount of indentation on the next line.
((?<=(.)*)-\3-\3-.*¶(?>(?<-6>.)*))*

Optionally match any number of lines containing three -s and two copies of capture group 3 (empty line), keeping track of and advancing to the same amount of indentation on the next line using capture group 6.
){2}

Match this whole group twice.
(?>(?<-4>==)*)===

Match two =s for each - captured in capture group 4, plus a final three =s (mouth). Here as in the previous two cases of balancing groups, the atomic group requires that any available =s are matched against the balancing group, so that the whole regex fails if there aren't three =s left over.

Fails to match a minimum-width face – fixed by changing o((-)+)-\3o to o((-)*)-\3o. Also, -9 bytes by changing (?<-n>.)*(?(n)$) to (?>(?<-n>.)*).

@Deadcode Ah yes, this is safe because the balancing group will always consume the characters that would have been subsequently matched. Thanks!

APL (Dyalog Unicode), 85 77 bytes (SBCS)
Anonymous monadic function taking a matrix of characters as argument.
1∊∊{⍵∘{(⍉3,⍨a⍪⍵⍪⊖a←2↑⍨2 1÷⍨⍺-1)⍷4-'_o7'⍳A}¨0,¨↓∘.=⍨⍳¯2+2⌷⍵}¨1 2∘+¨2 1∘×¨⍳⍴A←⎕

Try it online!
-8 bytes thanks to @Adám
Interesting Bits
This ends up encoding eyes=2, nose=1, underscore=3.
1 2∘+¨2 1∘×¨⍳⍴A←⎕ ⍝ Get at least all sizes (m,n) that fit in A such that
                       ⍝ m is odd and n≥3 (surely this can be done shorter)
                       ⍝ The search arrays are constructed transposed, so m ends
                       ⍝ up being the width
0,¨↓∘.=⍨⍳¯2+2⌷⍵      ⍝ For a given height m, get all nose positions
                       ⍝ e.g. m=3 gives (0 1 0 0)(0 0 1 0)(0 0 0 1)
(2 1÷⍨⍺-1)↑2         ⍝ My favorite expression. Generates one-half of the face
                       ⍝ ⍺ is (m,n), so (2 1÷⍨⍺-1) gives dimension pair ((⍺-1)÷2) (⍺-1)

surely this can be done shorter: Yes, plus a few other golfs.

APL (Dyalog Unicode), 90 85 bytes (SBCS)
Anonymous tacit prefix function taking a character matrix argument. Requires ⎕IO←0 (0-based indexing).
1∊∘∊{(∊¨1↑¨¨⍨1+⍳1,⍨⊣\⍴⍵)∘.⍀{'_'⍪⍨(⊢,0 1↓⌽)' 7',⍨2↑'o',1⍵⍴''}¨⍳⊢/⍴⍵}⍷¨∘⊂' '@(~∊∘'o7_')

Try it online!
This works by brute force; generating all possible faces and looking for them in turn.
' '@() amend with spaces at the locations indicated by the following mask:
 ∊∘'o7_' membership of the set of special symbols
 ~ negate that
This replaces all non-special characters with spaces.
{…}⍷¨∘⊂ mask where each of the following have a top-left corner in the entirety of that:
 ⍴⍵ the shape of the argument (rows, columns)
 ⊢/ the rightmost element of that (columns)
 ⍳ the indices 0…n-1 of that.
 {…}¨ apply the following function on each index:
  1⍵⍴'' create 1-row argument-column matrix of spaces
  'o', prepend a column of eyes
  2↑ append a blank row (lit. take the first two rows)
  ' 7',⍨ append a column consisting of a space above a nose
  (…) apply the following tacit function to that:
   ⌽ mirror the argument (puts the nose column on the left)
   0 1↓ drop no rows but one column (removes the nose column)
   ⊢, prepend the argument (this creates the full eye and nose rows)
  '_'⍪⍨ append a row of underscores (to form the mouth)
This gives us a collection of all possible three-row faces.
 (…)∘.⍀ create all combinations of the following masks expanding (inserting blank rows on zeros) those faces:
  ⍴⍵ the shape of the argument
  ⊣\ two copies of the row-count (lit. cumulative left-argument reduction)
  1,⍨ append a one
  ⍳ the Cartesian coordinates of an array of that size
  1+ increment
  1↑¨¨⍨ for each of each of those, create a mask of length with a single leading one (lit. take that many elements from one)
  ∊¨ ϵnlist (flatten) each
 This gives us all the possible expansion masks
 ∊ ϵnlist (flatten)
1∊∘ is one a member thereof?

Python 3, 213 bytes
Returns False when it finds a face and True when it doesn't.
lambda s:all(re.subn(f"\\n.{{{p}}}[^o_7]{{{g}}}7[^o_7]{{{g}}}",'',x)[1]-1for p in range(len(s))for g in range(len(s))for x in re.findall(f"^.{{{p}}}o[^o_7]{{{2*g-1}}}o([\S\s]+)^.{{{p}}}__{{{2*g}}}",s,8))
import re

The idea is that for each possible face size and indention, we look for eyes and a mouth in correct location (ignoring noses), then make sure there is exactly one nose that is centered.
p is the left padding of the face, g is the gap from face edge to nose, and 8 is the value of re.MULTILINE.
Try it online!

PCRE2, 168 bytes
(?=(?13)(.*))o(?6)*(?=(?13)(.*))o((?=(.*?)(.\5|(?13)\2$)|)([^7o_]|(?!\7|(?5))\4()7)(((?=(?13)(.+\1|(?!.*\2)))\C)+(_+()((.(?=(.*+\C+?)(.\16?$)))*+\15?+)(?10))?)?)++\7\12

https://regex101.com/r/dHsdBq/2
@Deadcode made me do it :P
It's theoretically valid but fails that one test because of catastrophic backtracking.
Bonus: https://regex101.com/r/dHsdBq/3 166 bytes, PCRE1 (dropped both possessive +s in (?13))
The general method: (?13) will jump from the current point to the same position on the very last line of the subject. So, at any point in the face, you can compare what is captured in (?=(?13)(.*)) to that captured at any other point in the face, particularly following the eyes (\1 and \2, in order to determine whether or not you're in the face.
(?=(?13)(.+\1|(?!.*\2)) is therefore true when you're not in a face. The regex goes through face characters one at a time, but consumes at once characters from the end of the face on one line to the start of the face on the next. While doing so, it also optionally tests for a mouth.
(?=(.*?)(.\5|(?13)\2$)|) is used to locate the nose in the middle of the face. It collects in \5 characters from the end of the face on the current line, so that (.*?) finally matches the empty string once the middle of the face is reached.

J, 101 93 99 97 bytes
1 e.[:,>@{@;&(1+i.)/@$(((-:1 2 3*[:#:i:@_1+2^<:,<.@-:,])*2|]){:@$)@((4|'ao7_'&i.)-.0{0:"+);._3"$]

Try it online!

Java (OpenJDK 8), 290 bytes
int D(String[]t){for(int a=0,z=t.length,y=t[0].length();a<z;a++)for(int b=0;b<y;b++)for(int c=b+2;c<y;c+=2)for(int d=a+1;d<z;d++)for(int e=d+1;e<z;e++)if(t[a].charAt(b)=='o'&&t[a].charAt(c)=='o'&&t[d].charAt((b+c)/2)=='7'&&t[e].substring(b,c+1).replace("_","").isEmpty())return 1;return 0;}

Try it online!
Takes a String[] broken at the lines as input and outputs 1 and 0 for true and false

266 bytes

May I know how did you come up with the idea?

@Ticherhas Sure. It uses a literal interpretation of the rules by brute-forcing every single possible place a face could be and returning true upon finding one, here's an explanation I whipped up for each step Then, replace booleans with ints because it's shorter.


text:
Identify the smallest possible tile in the matrix
Challenge
Given a matrix of digits (0-9), find the smallest (in terms of area) rectangular matrix of digits where one or more copies of itself, possibly rotated, can tile the original matrix. Reflection is not allowed (think of a collection of tiles on a wall or floor).
Input can be taken in any reasonable ways to represent a matrix of integers or characters. Output format should be consistent with the input, but output in any orientation (out of four possible rotations) is allowed.
If there are multiple possible tiles of same area, you may output one or all of them. It is guaranteed to be solvable for any possible input, since the entire input matrix is always an option if no smaller tiles can cover it.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
Input:
0 1 2 3 4
5 6 7 8 9
0 1 2 3 4
5 6 7 8 9
0 1 2 3 4
5 6 7 8 9
Output:
0 1 2 3 4
5 6 7 8 9
------------------
Input:
1 1 1
1 1 1
1 1 1
Output:
1
------------------
Input:
1 2 3
4 5 6
7 8 9
Output:
1 2 3
4 5 6
7 8 9
------------------
Input:
1 2 3 4 1
4 5 6 5 2
6 5 4 6 3
3 2 1 3 6
1 2 3 2 5
4 5 6 1 4
Output:
1 2 3
4 5 6
------------------
Input:
0 0 0 0
0 1 0 1
0 0 0 0
0 0 0 0
1 0 1 0
0 0 0 0
Valid Output 1:
0 0 0 0 1 0
Valid Output 2:
0 1 0
0 0 0
Invalid Output (because it is an L-shape, not a rectangular matrix):
0 1 0 0 0
0
------------------
Input: (a hard case, suggested by Arnauld)
1 2 1 2 1 1
1 1 2 1 2 2
2 1 1 2 1 2
1 2 2 1 2 1
2 1 2 1 2 2
Output:
1 2

Suggested test case. My initial version was failing on that one because of a too weak tile insertion test.

@Arnauld Thanks, added. It indeed looks hard.

Are rotations of the tile allowed?

@Anush "rectangular matrix of digits where one or more copies of itself, possibly rotated, can tile the original matrix..." and "output in any orientation (out of four possible rotations) is allowed."

Are non-deterministic programs allowed?

@ghosts_in_the_code Yes, as long as it finishes within finite time with probability 1. Except that I have no idea what you're trying to do...

JavaScript (ES6),  354 352 345  342 bytes
I/O: matrix of integers.
This is quite long but pretty fast -- at least with those test cases.
m=>m[b=P='map']((r,h)=>r[P]((_,w)=>(M=m.slice(~h)[P](r=>r.slice(~w)),a=~w*~h,g=(x,y,F)=>a>b|q.some((r,Y)=>r.some((v,X)=>~v?v^m[Y][X]:![x=X,y=Y]))?0:1/y?[...P+0][P](z=>(F=k=>!M[P]((r,Y)=>r[P]((v,X)=>k^1?q[y-Y][x-X]=v|k:(z|=~(q[y-X]||0)[x-Y],T[X]=T[X]||[])[Y]=v),T=[]))(1)&T.reverse(M=T)|z||g(F())|F(-1)):(o=M,b=a))(q=m[P](r=>r[P](_=>-1)))))&&o

Try it online!
How?
Whatever the tiling is, it is guaranteed that each corner of the matrix is also a corner of the tile that we're looking for. The two outer map() loops extract each possible tile \$M\$ from the bottom-right side of the input matrix \$m\$ and compute its area \$a\$.
m.map((r, h) =>           // for each row r[] at position h in m[]:
  r.map((_, w) =>         //   for each value at position w in r[]:
    (                     //
      M =                 //     build M[]:
        m.slice(~h)       //       keep the last h + 1 rows of m[]
        .map(r =>         //       for each of them:
          r.slice(~w)     //         keep the last w + 1 columns
        ),                //
      a = ~w * ~h,        //     area = (w + 1) * (h + 1)
      ...                 //     attempt to do a tiling with M
    )                     //
  )                       //   end of map()
)                         // end of map()

We build a matrix \$q\$ with the same dimensions as \$m\$, initially filled with \$-1\$.
q = m.map(r => r.map(_ => -1))

At each iteration of the recursive function \$g\$, we look for the position \$(x,y)\$ of the last cell in \$q\$ still set to \$-1\$, going from left to right and from top to bottom.
By definition, this cell has either a cell already set or a border on its right, and ditto below it. So it must be the bottom-right corner of a new tile, such as the cell marked with an 'x' below:

Simultaneously, we test whether there's a cell in \$q\$ whose value is not \$-1\$ and is different from the value in \$m\$ at the same position. If such a tile is found, we abort the recursion.
q.some((r, Y) =>          // for each row r[] at position Y in q[]:
  r.some((v, X) =>        //   for each value v at position X in r[]:
    ~v ?                  //     if v is not equal to -1:
      v ^ m[Y][X]         //       abort if v is not equal to M[Y][X]
    :                     //     else:
      ![x = X, y = Y]     //       set (x, y) = (X, Y)
  )                       //   end of some()
)                         // end of some()

If all cells of \$q\$ are matching the cells of \$m\$ and the area of \$M\$ is less than (or equal to) the best area found so far, we update the output \$o\$ to \$M\$.
Otherwise, we invoke the following code 4 times:
F(1) & T.reverse(M = T) | z || g(F()) | F(-1)

The behavior of the helper function \$F\$ depends on the parameter \$k\$:

If \$k=1\$, it computes the transpose \$T\$ of \$M\$ and checks whether all cells in \$q\$ between \$(x-w,y-h)\$ and \$(x,y)\$ are set to \$-1\$. The result of this test is saved in \$z\$.
If \$k\$ is undefined, it copies the content of \$M\$ to \$q\$ at \$(x-w,y-h)\$.
If \$k=-1\$, it cancels the previous operation by restoring all updated values to \$-1\$.

It is defined as follows:
F = k =>                  // k = parameter
  !M.map((r, Y) =>        // for each row r[] at position Y in M[]:
    r.map((v, X) =>       //   for each value v at position X in r[]:
      k ^ 1 ?             //     if k is not equal to 1:
        q[y - Y][x - X] = //       set q[y - Y][x - X]
          v | k           //       to v if k is undefined, or -1 if k = -1
      :                   //     else:
        ( z |=            //       update z:
            ~( q[y - X]   //         read q at (x - Y, y - X)
              || 0        //
            )[x - Y],     //         set z if it's not equal to -1
          T[X] =          //       compute T by writing v at the
            T[X] || []    //       relevant position
        )[Y] = v          //
    ),                    //   end of inner map()
    T = []                //   initialize T to an empty array
  )                       // end of outer map()

Therefore, the code block mentioned above can be interpreted as follows:
F(1)                      // compute the transpose T[] of M[] and test whether
&                         // M[] can be copied at (x-w, y-h) in q[]
T.reverse(M = T)          // reverse T[] and assign it to M[], which means
|                         // that M[] has been rotated 90° counterclockwise
z ||                      // if z = 0:
  g(F()) |                //   copy M[] to q[] and do a recursive call
  F(-1)                   //   restore q[] to its previous state

J, 195 bytes
A bit long, but blazing fast! There should be some micro-optimizations still left, but I believe there could be an overall better strategy, maybe one without boxes.
((]>@{.@\:[:>./@(*i.@#)[:(#*0*/@,@:=])&>]([:(~.@#~0,@:=(_&e.&,+0+/@,@:>])"2)[:,/|:@|.^:(<4)@[(-~%2*/@,@:>[+&*-~)/@,:"2/(|.~*{.@#&(,/)(#:i.)@$)"2@])&.>^:(<_)<@,:@[)[:(/:*/@:$&>)[:,/<@|:\@|:\)&.:>:

Try it online!
How it works
&.:>:

Add 1 to the matrix, so we can use 0 as a special value.
[:,/<@|:\@|:\

Get all possible tiles that contain the upper left digit.
[:(/:*/@:$&>)

Sort them according to their dimension.
](…)&.>^:(<_)<@,:@[

Use the initial matrix as seed, and execute – with the possible tiles on the left side – until the result does not change, while storing the results:
(|.~*{.@#&(,/)(#:i.)@$)"2@]

Shift the matrices so the first non-zero digit is in the upper left.
|:@|.^:(<4)@[

On the left side, rotate all the tiles.
(-~%2*/@,@:>[+&*-~)/@,:"2/

For each tile and each matrix, pad the tile and matrix to the same size (/@,:"2). The final result will be the subtraction, but we'll do some checks here by setting faulty results to infinity. With this we later don't have to keep track which tile produced which result. We add the signum of the tile and the matrix, then everything should be 1 (or 0, if the rotated tile stuck out and we added some 0 with padding. But it these cases, as every tile is >0, we'll have some negative numbers there.) We divide the subtraction by this check and it's either the original number or infinity.
(_&e.&,+0+/@,@:>])"2

We check if there is infinity in a matrix or a value below 0.
[:(~.@#~0,@:=(…)

And filter these out. The ~. is not necessary, but it reduces duplicates and speeds things quite a lot in the 1 1 1,1 1 1,1 1 1 cases.
[:(#*0*/@,@:=])&>

After the function's result does not change anymore, we have a matrix where each column represents a tile, and each row contains the possible placements for N tiles. We're interested in placements that result in a matrix filled with 0, so we check for them. We now have something like
0 0 0 0 0 0 0 0 0  0 tiles
0 0 0 0 0 0 0 0 1  1 tiles (the right-most tile is the whole matrix)
0 0 1 0 0 0 1 0 0  2 tiles

[:>./@(*i.@#)

We multiple each row with its index and reduce them, so we get for example 0 0 2 0 0 0 2 0 1.
 >@{.@\:

Using this as an index we sort the tiles, take the first one, unpack it and with the decrement we have the final tile.

I never thought writing a single tacit function in J that long. Great job!

APL (Dyalog Unicode), 189 173 bytes
{{A[⍵]⍴⍨⊃⌽⍵}{{⊃⍵[⊃⍋⍴¨⍵]},↑⍵[⍸(~0∊∊)¨⍵]}{⊃((×/⍵)÷⍨⍴,A){⍺≤1:⊂¨↓⍵⋄R←⍵∇⍨⍺-1⋄,{0<≢R:⍵[⍸{((⊢≡∪)⊃,/⍵)∧((1≡⊃∘⍴∘∪)¨↓{A[⍵]}¨⍵)}¨⍵]⋄⍬}R∘.(,∘⊂)↓⍵}⊃⍪/{(,⍳1-⍵-⍴A)∘.+,¯1+⍳⍵}¨⍵(⌽⍵)}¨,⍳⍴A←⍵}

Try it online!
Slow when there are few distinct values in the grid (can't eliminate possibilities quickly).
Enumerates all possible rectangles (not many), then tries adding one at a time, checking for overlap and equal elements.
Explanation
⍳⍴A←⍵    ⍝ Set A to be the given matrix, and generate all dimensions of smaller rectangles
¨,       ⍝ For each smaller dimension (e.g. 5 4):
¨⍵(⌽⍵)     ⍝ Apply the following for both the dimension and its transpose:
  {(,⍳1-⍵-⍴A)∘.+,¯1+⍳⍵}  ⍝ Get all possible vectors of the indices of each cell in each possible translated submatrix

  ((×/⍵)÷⍨⍴,A)     ⍝ The number of these matrices needed to get the right area to tile the grid
  {⍺≤1:...∇⍺-1⋄⍬}  ⍝ Repeat that many times, starting with ⍬ (empty vector):
    R←⍵∇⍨⍺-1       ⍝ Take R to be the result of the previous step
    R∘.(,∘⊂)↓⍵}⊃⍪/ ⍝ Add to R all possible existing submatrix sequences
    ⍵[⍸...]        ⍝ Filter for those that:
     ((⊢≡∪)⊃,/⍵)   ⍝ Have no overlapping tiles and
     ((1≡⊃∘⍴∘∪)¨↓{A[⍵]}¨⍵)  ⍝ Consist of the same sequence of entries
  {⊃⍵[⊃⍋⍴¨⍵]}  ⍝ Get the first possibility, sorted by area
{A[⍵]⍴⍨⊃⌽⍵}  ⍝ Get the corresponding elements from the original matrix, and correct the shape

If you haven't already, check out The APL Orchard, a chat room dedicated for APL-family languages.

source: Stack Exchange

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

sort: votes


text:
Print a tongue twister!
The goal of this challenge is to print the following tongue twister:
She sells seashells by the seashore,
The shells she sells are seashells, I'm sure.
So if she sells seashells on the seashore,
Then I'm sure she sells seashore shells.

This is more complicated than just calling your language's print equivalent. Since there are a lot of repeated words and phrases, you can greatly decrease the size of your code by using other tactics.
Rules:

No querying another website which will respond with the full twister
You must include all the punctuation and line breaks in the original text.
You can end with a trailing newline

This is code-golf, so the shortest code wins!
Good luck!

While there's a long history of natural-language text compression challenges coming down to a few built-in compression tools and tactics, I'm cautiously optimistic that this text's varied repetition and length will lead to some interesting solutions in at least some languages.

Probably just a pet-peeve of mine, but it always annoys me when a sentence ends in a comma, and the sentence on the next line is capitalized regardless. (Although that might also be related to not being able to use a sentence-capitalize builtin, haha. ;p)

It would be easier if the first line used on instead of by.

What I made to find optimal solution(s)

142 bytes is far from being the shortest answer. That would be "my pronoun is monicareinstate"s Bubblegum answer with 78 bytes. Shortest non-eso answer is my 126 bytes PHP as far as I can see.

@Kevin Cruijssen That is the standard convention for typesetting verse in English.  Each line starts with a capital, regardless of sentence structure.  It does not indicate a new sentence.

Python 3, 166 \$\cdots\$ 142 135 bytes
Saved a whopping 13 18 bytes thanks to ovs!!!
Saved 4 bytes thanks to user253751!!!
Saved a byte thanks to branboyer!!!
Saved 7 bytes thanks to dingledooper!!!
Note: There's lots of unprintables in the following code so please avert your eyes if you're sensitive to such things! :D
print("Sh by are,.\nSo if onnore.".translate("| seash|ells|ore,\nThe| sh|e s| I'm sure| the".split("|")))

Try it online!
Based on Netråm's C# answer.

152 bytes with translate and without the d replacement. (There are some unprintables in the string)

147 bytes by using more unprintables and modifying the first replacement.

Is there a reason you can't add " I'm sure" to the dictionary?

@user253751 That wasn't saving any bytes in previous incarnations (in fact it was adding bytes) but is now saving 4 bytes - thanks! :-)

Your string still repeats sea thrice,  you could add that too

@ghosts_in_the_code Unfortunately, that doesn't save any bytes.

142 bytes
How I did it

I know this is an old challenge, but here is a 135 byte solution I found with a brute-forcer.

@dingledooper Never to late to do some golfing - thanks! :D

Retina 0.8.2, 106 103 bytes

S230 by41h012 are30,5.¶So if1230 on4n5123ore1h0.
5
 I'm1ure
4
 the3ore,¶The
3
1eash
2
he10
1
 s
0
ells

Try it online! Explanation: In Retina, a substitution only makes sense if it's long enough l for the number n of repetitions. The substitution saves n(l-1) bytes in the compressed text but costs l+3 bytes in the replacement stages. This gives the minimum length required to be useful as follows:

2 repetitions: length > 5
3 repetitions: length > 3
4 repetitions: length > 3
5 repetitions: length > 2
6+ repetitions: length > 1

Edit: As @Arnauld pointed out, you can count repetitions from the substitution entries as well. This means that although there were only 5 repetitions of space+s in my previous encoded text, there are also 3 repetitions in the substitutions, thus allowing me to save 3 bytes overall. (@Arnauld himself had only spotted 2 of the 3 repetitions.)

Your first line isn't quite right. Here is a 111-byter I came up with, but you might be able to fix this at no cost.

@ovs Ugh, I wonder how far back I accidentally introduced that while golfing...

@ovs well, 106 bytes seems reasonable now. would be 100 bytes if the first line used "on" instead of "by" (see Wikipedia). Try it online!

104 bytes with the patterns I used in my answer (except the last one which would result in +1 byte in Retina).

@Arnauld Nice, but you missed a trick, you still have two of space+s.

Well spotted! :)

@Arnauld I tried to rearrange the digits in your answer but I got it wrong the first time around so you had already updated your answer by the time I finished.

JavaScript (ES6),  142  141 bytes
Saved 1 byte thanks to @Neil
_=>`246 / I'm5ure/he56/ the4ore,
The/5eash/ s/ells`.split`/`.reduce((s,p,i)=>s.split(i).join(p),`S0by35h652 are46,1.
So if50on3n1524ore5h6.`)

Try it online!
Compression steps
"ells" -> "6" (9 occurences, saved: 22 bytes)
She s6 seash6 by the seashore,
The sh6 she s6 are seash6, I'm sure.
So if she s6 seash6 on the seashore,
Then I'm sure she s6 seashore sh6.

" s" -> "5" (17 occurences, saved: 14 bytes)
She565eash6 by the5eashore,
The5h65he56 are5eash6, I'm5ure.
So if5he565eash6 on the5eashore,
Then I'm5ure5he565eashore5h6.

"5eash" -> "4" (6 occurences, saved: 18 bytes)
She5646 by the4ore,
The5h65he56 are46, I'm5ure.
So if5he5646 on the4ore,
Then I'm5ure5he564ore5h6.

" the4ore,\nThe" -> "3" (2 occurences, saved: 10 bytes)
She5646 by35h65he56 are46, I'm5ure.
So if5he5646 on3n I'm5ure5he564ore5h6.

"he56" -> "2" (4 occurences, saved: 7 bytes)
S246 by35h652 are46, I'm5ure.
So if5246 on3n I'm5ure524ore5h6.

" I'm5ure" -> "1" (2 occurences, saved: 5 bytes)
S246 by35h652 are46,1.
So if5246 on3n1524ore5h6.

"246 " -> "0" (2 occurences, saved: 1 byte)
S0by35h652 are46,1.
So if50on3n1524ore5h6.

05AB1E, 91 86 bytes
“SheÌç1€‹€€0,
The¬•s‚ÎÌç€™1,2.
So€¬‚ÎÌç1€‰€€0,
Then2‚ÎÌç0¬•s.“2Ý…½š¬•s#'í™ì“I'mˆ•“ª1ú:

Try it online.
Explanation:
“SheÌç1€‹€€0,
The¬•s‚ÎÌç€™1,2.
So€¬‚ÎÌç1€‰€€0,
Then2‚ÎÌç0¬•s.“  # Push dictionary string "She sells1 by the0,
                 #                         The shells she sells are1,2.
                 #                         So if she sells1 on the0,
                 #                         Then2 she sells0 shells."
2Ý               # Push list [0,1,2]
…½š¬•s           # Push dictionary string "shore shells"
      #          # Split it on spaces: ["shore","shells"]
       'í™ì     '# Prepend dictionary string "sea" in front of both:
                 #  ["seashore","seashells"]
“I'mˆ•“ª        '# Append dictionary string "I'm sure" to this list:
                 #  ["seashore","seashells","I'm sure"]
1ú               # Pad each string with a leading space:
                 #  [" seashore"," seashells"," I'm sure"]
:                # Replace all [0,1,2] with [" seashore"," seashells"," I'm sure"]
                 # (after which the result is output implicitly)

See this 05AB1E tips of mine (section How to use the dictionary?) to understand how the dictionary strings work.

///, 115 bytes
Port of Neil's answer + accepting nph's suggestion.
/3/ I'm4ure//2/4eash//1/he40//0/ells//4/ s/S120 by the2ore,
The4h041 are20,3.
So if4120 on the2ore,
Then3412ore4h0.

Try it online!

126 bytes by using ' s' (notice space) as a substitute.

I've bugfixed my answer; does that help you at all?

I was... maybe @nph was just confirming that it should help you?

@Neil I can't understand nph's behavior... it's bizzare.

@Neil I misunderstood. I thought you were talking to me because I just commented.

Bubblegum, 79 78 bytes
removed trailing newline for -1 byte
The text in the tongue twister has many simple patterns. There are enough of them that even "normal" languages can save bytes. However, the only thing DEFLATE does is compressing simple patterns with little overhead...
00000000: 0bce 4855 284e cdc9 2906 9289 c519 6056  ..HU(N..).....`V
00000010: 52a5 4209 5018 2c90 5f94 aac3 1502 e441  R.B.P.,._......A
00000020: e58a e1ea 138b 5211 7a74 143c d573 158a  ......R.zt.<.s..
00000030: 4b8b 52f5 b882 f315 32d3 800a 310d cecf  K.R.....2...1...
00000040: c334 380f ae13 a105 a602 66ab 1e00       .48.......f...

Try it online!
After "writing" this answer, I finally decided to find a way to view the internal representation details of the string (to be specific, information on what characters are printed literally and what substrings are compressed as repetitions via LZ77). I modified kunzip (which already had some useful logging capabilities) to log only the information I want to see. This is the result:
output 83 S
output 104 h
output 101 e
output 32
output 115 s
output 101 e
output 108 l
output 108 l
output 115 s
len: 3 dist: 6 ( se)
output 97 a
output 115 s
output 104 h
len: 5 dist: 10 (ells )
output 98 b
output 121 y
output 32
output 116 t
len: 3 dist: 23 (he )
len: 5 dist: 17 (seash)
output 111 o
output 114 r
output 101 e
output 44 ,
output 10
output 84 T
len: 3 dist: 14 (he )
len: 7 dist: 28 (shells )
output 115 s
len: 9 dist: 48 (he sells )
output 97 a
output 114 r
output 101 e
len: 10 dist: 52 ( seashells)
output 44 ,
output 32
output 73 I
output 39 '
output 109 m
output 32
output 115 s
output 117 u
output 114 r
output 101 e
output 46 .
output 10
output 83 S
output 111 o
output 32
output 105 i
output 102 f
len: 3 dist: 41 ( sh)
len: 18 dist: 89 (e sells seashells )
output 111 o
output 110 n
len: 18 dist: 89 ( the seashore,
The)
output 110 n
len: 9 dist: 58 ( I'm sure)
len: 10 dist: 51 ( she sells)
len: 8 dist: 34 ( seashor)
len: 8 dist: 118 (e shells)
output 46 .

I think might will be useful for "normal" language answers.

Japt, 108 105 104 96 93 92 bytes
`S230 by41h012 ‡e30,d.
So if1230 4˜123Že1h0.`dd` I'm1¨e`4` e3Že,
T”`3`1Á`2`”10`1" s"0`e¥s

Try it online!
Port of the retina answer to Japt.
Explanation
S230 by41h012 ‡e30,d.
So if1230 4˜123Že1h0.
Decompress into the string literal:
S230 by41h012 are30,d.
So if1230 on4nd123ore1h0.

Then we do replacements with:
d
 d` I'm1¨e`     // "d" with " I'm1ure"
 4` e3Že,\nT”`  // "4" with " the3ore,\nThe"
 3`1Á`          // "3" with "1eash"
 2`”10`         // "2" with "he10"
 1" s"          // "1" with " s"
 0`e¥s          // "0" with "ells"

Stax, 83 bytes
ÇσGª☺Uë\╠╤↑╡V╦⌐∞┐ü9B@♦1ÖFò╫◄«vâ¬♂ƒQn→↨¥p▬♂♥å↓hb½Z╫Éà½♣µ\╩N>.▄┌bæ¼@3▲¡w8╣▐ù☼ve/h{≈ï░

Run and debug it
How?
Unpacked:
`...`'!/|J
`...`      - compressed string "She sells..." with '!' where newlines should be
     '!    - a '!' character
       /   - split the compressed string at '!' characters
        |J - join with newline characters

Maybe making a manual compression using the words will be shorter?

Sometimes using an integer array is shorter.

C# (Visual C# Interactive Compiler), 154 bytes
Write(@"S{0}sea{1} by the {2},
The {1} s{0}are sea{1}, I'm sure.
So if s{0}sea{1} on the {2},
Then I'm sure s{0}{2} {1}.","he sells ","shells","seashore")

Try it online!

Here's some more 154 byte solutions

C# (Visual C# Interactive Compiler), 171 bytes
string a=" she sells ",b="shells",c="seashore",d=a+"sea"+b;Write(@$"She{d[4..]} by the {c},
The {b}{a}are sea{b}, I'm sure.
So if{d} on the {c},
Then I'm sure{a}{c} {b}.")

Try it online!
The @ allows for line breaks inside string literals.

You can save 2 bytes by changing the She{d[4..]} to S{d[2..]}.

You can save 2 more bytes by changing {b}{a} to {b+a} and {a}{c} to {a+c}

PowerShell, 134 133 132 bytes
-1 byte thanks @Titus
see similar by Nail and Arnauld
$d='S0by36h461 are54,2.
So if60on3n2615ore6h4.'
"154 #he64# I'm6ure# the5ore,
The#ells#6eash# s"-split'#'|%{$d=$d-replace$i++,$_}
$d

Try it online!

Lose one more byte by putting " s" last, so you can use it in " seash". Beat my php!

Thanks! You made php great again. :)

Your code inspired me. Excellent shell scripting! I almost wish someone could "bash" me. :D

Down to 130 bytes by changing the split syntax and factorizing re

V (vim), 110 bytes
iS230 by41h012 are30,5.
So if1230 on4n5123ore1h0.Í5/ I'm1ure
Í4/ the3ore,\rThe
Í3/1eash
Í2/he10
Í1/ s
Í0/ells

Try it online!
Port of @Neil's retina answer to V (vim)

ink, 129 130 bytes
-(i){|The shells|So if|Then I'm sure} {S|s}he sells {|are |}sea{|||shore }shells{& {on|by} the seashore,|{, I'm sure.|.->END}}
->i

Try it online!

+1 byte: A period was missing from the end of a line

Explanation
// Thanks to all the new whitespace, this ungolfed code doesn't quite work as is
-(i)                              // A label
{|The shells|So if|Then I'm sure} // A sequence - the first time we get here we print nothing,
                                  // the second time we print "The shells",
                                  // the third time we print "So if", etc
{S|s}                             // Sequences keep outputting their last value once it's been reached
he sells                          // Plain text just gets printed
{|are |}
sea{|||shore }shells
{& {on|by} the seashore,|{, I'm sure.|.->END}}
                                  // {& marks a repeating sequence.
                                  // Instead of getting stuck on its last value, this it starts over.
                                  // On the fourth pass we hit ->END and terminate the program
->i                               // On the other passes, we get here and go back to the start

PHP, 133 126 bytes
<?=strtr("S2 s101 by t203,\nT2414e s1 are01,5.\nSo if4e s101 on t203,\nT2n54e s10341.",[" seash",ells,he,ore," sh"," I'm sure"]);

Try it online. Use PHP < 7.2 to avoid warnings

PowerShell, 158 bytes
Because if bash counts then why not...
$1="seash"
$5="ells"
$4="he s$5 "
$6=" I'm sure"
$2="$1$5"
$3="$1`ore"
"S$4$2 by the $3,`nThe $5 s$4`are $2,$6.`nSo if s$4$2 on the $3,`nThen$6 s$4$3 $5"

Try it online!

? Try it online!

144 bytes

JavaScript (V8), 287 bytes
Trying a different way of compressing it, in a different language. Feedback is appreciated!
function s(){a="kdg by the dj,/nThe g care dg, I'm sure./nSo if cdg on the dj,/nThen I'm sure cdj g.".replace(/c|k/g,function(match){return(match=="c")?"she sells ":"She sells ";});c=a.replace(/d|g/g,function(match){return(match=="d")?"sea":"shells";});return (c.replace(/j/g,"shore"));}

Try it online!

Compressing attempts made it longer, annoyingly. I don't think it can be shorter, but I would appreciate help.

You could use an arrow function in the replacer?

Hey, you asked for some feedback (a bit late, I know), so I worked through how I'd golf this answer: https://gist.github.com/dom111/717ecd767f252b883059b9ecaf63ca67 I'm sure there is still a lot of room for improvement, but I hope it's useful!

Python, 179 176 bytes
print"She sells seashells by the seashore,\nThe shells she sells are seashells, I'm sure.\nSo if she sells seashells on the seashore,\nThen I'm sure she sells seashore shells."

Trivial algorithm, but nobody’s done it yet. I’m working on a better answer in a different language, but I don’t know if it should be posted in another answer or in this one. Shortening advice accepted, but I’m perfectly fine with just hard-coding it for now.

If you do come up with another answer, you should almost always post it separately. You should generally only include multiple answers in one post if they are extremely similar. Good luck!

You have a space you can remove after print, and in Python 2 you can remove the () around the string

PicoLisp, 160 157 146 142 138 bytes
(prin(text"S@1 @2 by the @3,
The @5 s@1 are @2,@4.
So if s@1 @2 on the @3,
Then@4 s@1 @3 @5.""he sells"'seashells'seashore" I'm sure"'shells]

Using the template:
S1 by the 2,
The 5 s1 are 2,4.
So if s1 on the 3,
Then4 s1 3 5.

Where 1 is "he sells", 2 is "seashells", 3 is "seashore", and 4 is " I'm sure"
Ideone It!
{ 14 imaginary interweb points for guessing which syntax highlighting I'm using without peeking }
Common Lisp, 160 bytes
(format t"S~a~a by the ~a,~%The shells s~3:*~Aare ~a, I'm sure.~%So if s~3:*~A~a on the ~a,~%Then I'm sure s~3:*~a~*~a shells.""he sells ""seashells""seashore")

https://ideone.com/n7zVUm

Java 8, 169 160 bytes
v->"".format("S%sells by%s shells she sells are seashells, I'm sure.\nSo if s%1$sells on%2$sn I'm sure s%1$sore shells.","he sells seash"," the seashore,\nThe")

Port of @IgbyLargeman's C# answer, so make sure to upvote him as well!
-9 bytes thanks to @branboyer.
Try it online.
(Simply returning as is would be 174 bytes.)
Explanation:
v->           // Method with empty unused parameter and String return-type
  "".format(  //  Return the following formatted string:
     "S%sells by%s
      shells she sells are seashells, I'm sure.\n
     So if s%1$sells on%2$s
     n I'm sure s%1$sore shells.",
    "he sells seash",
              //   Where the first `%s` and all `%1$s` are replaced with "he sells seash"
    " the seashore,\nThe")
              //   and the second `%s` and all `%2$s` are replaced with " the seashore,\n
                                                                         The"

160 bytes (This can be ported to the C# code as well of course)
I'm attempting to create code that'll find the best solution; that's the best I got right now.

My github link to the finished project for optimizing this problem (could be used with other similar problems).

@branboyer Ah nice, I will keep this comment in mind if a similar KC challenge is posted. A brute-forcer to get the shortest substrings is a nice approach. Thanks.

Husk, 77 bytes
ΓJx'p¨½ΞĿ∫Ẏj5pż¦Sβyεḟ?ṡ,ḣŀḢ¦ṠεΞĿ∫äeŻaŀ`◄,İ'm ṡ→.¶ȮSÏf£2₅Φεḟ?ṡ,ḣnİ'm ṡ→⁸ρΘŀḢ¦.

Try it online!
Better than Bubblegum!
Husk's string compression is pretty good for this task, a straightforward compressed string would be 82 bytes long. Here, we apply just a single substitution to make it shorter.
The compressed string  we use here is
he sells seashpSpells by the seashore,
The shells she sells are seashells, I'm sure.
So if spells on the seashore,
Then I'm sure spore shells.

The structure of the code is:
ΓJx'p¨...
     ¨...  The compressed string
  x'p      split on occurrences of the character 'p'
ΓJ         and joined by interleaving the first substring between the rest

What this does in practice is replacing the character 'p' with "he sells seash" everywhere in the rest of the string.
This substitution was the one that generated the shortest compressed string among the ones I've tried; multiple substitutions are possible but they didn't seem worth the longer payload. The letter 'p' was chosen because it generates words like "spell" and "spore" in the text that can be compressed very well by Husk.

(asking here since the chatroom is locked) What does ƒ do?

Deadfish~, 1313 1234 bytes
iiissiic{ii}icdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}ddsddc{ii}iiic{{d}i}ic{dd}dsdddddc{d}ddcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{ii}}dc{ddd}ddddcdsiiic{ii}cdddc{{d}iii}ic{dd}s{ddd}ic{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}dcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{{iii}ii}ic{ii}dddc{d}dddc{{d}iii}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{d}iii}dc{d}ddc{iiii}ic{ddd}ddddc{{i}ddd}c{{d}ii}iiic{dd}s{ddd}iciicdddc{d}dddc{{ii}}ic{{ii}ii}cdsiic{iii}ddc{{d}ii}ic{{iii}iii}dcdddc{{d}iii}c{dd}s{ddd}ic{d}dcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}ds{d}cdc{{d}ii}iic{dd}dsdddddc{d}ddcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{ii}}dc{ddd}ddddcdsiiic{ii}cdddc{i}dc{{d}ii}iic{iiii}ic{ddd}ddddc{{i}ddd}c{{d}ii}iiic{dd}s{ddd}iciicdddc{d}dddc{{d}iii}ic{dd}s{ddd}ic{d}dcdddc{{d}iii}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{d}iii}ic{dd}s{ddd}ic{d}dcdddc{i}dddcc{i}dddc{{d}iii}ic

Try it online!
Deadfish, the ungolfing language.

It can be outgolfed best if human mind and generators are combined, nicely done!

@Wasif Not actually human mind, my generator implements that, but not actually anything clever :p

Deadfish~, 1216 1196 bytes
iiissiici{ii}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddd{i}ccddd{i}c{{d{{i}}}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cdddcddd{i}ccddd{i}c{{d{{i}}}}c{d{i{i}}}ciii{ii}ci{i{d}}c{iiii{iii}}cdd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cddd{i}ciiicddd{d}cd{{ii}}c{d{{i}}}cdsiiic{ii}cdddci{iii{d}}ciii{dd{i}}cd{d}cdddcddd{i}ccddd{i}c{{d{{i}}}}ciii{dd{i}}cd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddd{i}ccddd{i}c{{d{{i}}}}ci{ii{iii}}cddd{ii}cddd{d}ci{iii{d}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cdddcddd{i}ccddd{i}cd{iii{d}}cdd{d}ci{iiii}c{d{{i}}}c{ddd{i}}cd{dd{ii}}ciii{dd{i}}ciicdddcddd{d}ci{{ii}}c{ii{ii}}cdsiicdd{iii}ci{ii{d}}ciii{ddd{i}}cdddc{iii{d}}ciii{dd{i}}cd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddd{i}ccddd{i}c{{d{{i}}}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cdddcddd{i}ccddd{i}c{{d{{i}}}}cd{dd{i}}cdcii{ii{d}}c{iiii{iii}}cdd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cddd{i}ciiicddd{d}cd{{ii}}c{d{{i}}}cdsiiic{ii}cdddcd{i}cii{ii{d}}ci{iiii}c{d{{i}}}c{ddd{i}}cd{dd{ii}}ciii{dd{i}}ciicdddcddd{d}ci{iii{d}}ciii{dd{i}}cd{d}cdddci{iii{d}}ciii{dd{i}}cdddd{d}cddd{i}ccddd{i}c{{d{{i}}}}ciii{dd{i}}cdddd{d}cddddcdd{ii}cd{d}cddd{i}ciiicddd{d}ci{iii{d}}ciii{dd{i}}cd{d}cdddcddd{i}ccddd{i}ci{iii{d}}c

Try it online!
As long as I didn't mess anything up, this should be the shortest possible without () and printing in loops.

Python 2, 175 158 bytes
thanks @branboyer for the edit!
print"S{0}ells by{1} shells she sells are seashells, I'm sure.\nSo if s{0}ells on{1}n I'm sure s{0}ore shells.".format("he sells seash"," the seashore,\nThe")

Try it online!

158 bytes

156 bytes Sorry to change so quick

FEU, 112 111 bytes
-1 byte thanks to Neil
a/S256 by43h632 are56,1.\nSo if3256 on4n1325ore3h6.
m/1/ I'm3ure/2/he36/3/ s/4/ the5ore,\nThe/5/ seash/6/ells/g

Try it online!
Port of JavaScript answer.

The 0/256 / replacement only makes sense in the JS answer because the 0 is implicit as the match; here it actually costs you a byte.

Scala, 155 bytes
printf("S%2$s by%1$s shells%3$sare seashells, I'm sure.\nSo if s%2$s on%1$sn I'm sure%3$sshells."," the seashore,\nThe","he sells seashells"," she sells ")

Try it online!

Zsh, 128 bytes
<<Z
S${4=${2=he s${1=ells}}${3= seash}$1 }by${5= the$3ore,
The} sh$1 s$2 are$3$1,${6= I'm sure}.
So if s$4on$5n$6 s$2$3ore sh$1.

Try it online!

Deadfish~, 1269 bytes
iiissiic{ii}icdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}ddsddc{ii}iiic{ddddddddd}ic{dd}dsdddddc{d}ddcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{ii}}dc{ddd}ddddcdsiiic{ii}cdddc{ddddddd}ic{dd}s{ddd}ic{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}dcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{{iii}ii}ic{ii}dddc{d}dddc{ddddddd}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{ddddddd}dc{d}ddc{iiii}ic{ddd}ddddc{iiiiiii}c{dddddddd}iiic{dd}s{ddd}iciicdddc{d}dddc{{ii}}ic{{ii}ii}cdsiic{iii}ddc{dddddddd}ic{{iii}iii}dcdddc{ddddddd}c{dd}s{ddd}ic{d}dcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dcdddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}ds{d}cdc{dddddddd}iic{dd}dsdddddc{d}ddcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{{ii}}dc{ddd}ddddcdsiiic{ii}cdddc{i}dc{dddddddd}iic{iiii}ic{ddd}ddddc{iiiiiii}c{dddddddd}iiic{dd}s{ddd}iciicdddc{d}dddc{ddddddd}ic{dd}s{ddd}ic{d}dcdddc{ddddddd}ic{dd}s{ddd}ic{d}ddddc{i}dddcc{i}dddc{{iiii}iii}dc{dd}s{ddd}ic{d}ddddcddddc{ii}ddc{d}dc{i}dddciiic{d}dddc{ddddddd}ic{dd}s{ddd}ic{d}dcdddc{i}dddcc{i}dddc{ddddddd}ic

Try it online!

Knight, 138 bytes
O+S=q+=sS=v" shells"4F" se"=tSvT0"sea"F2"S"+" by"+=p" the seashore,
The"+v+s+" are"+t+=u" I'm sure.
So if"+q+S" onn"3Fp+GuF9+s+Gp 4 9+v"."

Try it online!
Fiiiiiiiine, I'll explain it
Attempt at explaining it
Sorry, the indentation is a little inconsistent...
OUTPUT
 +
  # substitute " s" with "S" for initial capitalization
  SUBSTITUTE(
   = _she_sells_seashells
    + = _she_sells
     # inject " se" into "shells"
     # to get "she sells"
     SUBSTITUTE(
       = _shells " shells"
       4
       0
       " se"
      )
    # inject "sea" to get " seashells"
    = _seashells
       SUBSTITUTE(
        _shells
        1
        0
        "sea"
       )
    )
    0
    2
    "S"
   )
  + " by"
  + = _the_seashore_the " the seashore,\nThe"
  + _shells
  + _she_sells
  + " are"
  + _seashells
  + = _im_sure_so_if "  I'm sure.\nSo if"
  + _she_sells_seashells
  # shorter to inject than concatenate
  # to get " on the seashore,\nThen"
  + SUBSTITUTE(
     " onn"
     3
     0
     _the_seashore_the
    )
  # Extract "I'm sure"
  + GET(
     _im_sure_so_if
     0
     9
    )
  + _she_sells
  # " seashore"
  + GET(
     _the_seashore_the
     4
     9
    )
  + _shells
  : "."

explanation por favor

Even the creator of Knight himself can't decipher my magical code? ¡Ay caramba!

Bash, 156 bytes
i=" I'm sure"
h=" she"
k=lls
l=" seashe"$k
s=" seashore"
e=" se"$k
printf "She$e$l by the$s,
The$h$k$h$e are$l,$i.
So if$h$e$l on the$s,
Then$i$h$e$s$h$k."

An expert can probably save some more here.

Consider using Try it online! - it counts your bytes and also creates MarkDown for you.

151 bytes

zlib, 84 bytes
Hex dump:
00000000: 78 9c 0b ce 48 55 28 4e cd c9 29 06 92 89 c5 19  x...HU(N..).....
00000010: 60 56 52 a5 42 09 58 18 28 90 5f 94 aa c3 15 02  `VR.B.X.(._.....
00000020: e2 41 e4 8a e1 ea 13 8b 52 11 7a 74 14 3c d5 73  .A......R.zt.<.s
00000030: 15 8a 4b 8b 52 f5 b8 82 f3 15 32 d3 90 14 22 0c  ..K.R.....2...".
00000040: ce cf c3 34 38 0f ae 13 5d 4b 7e 11 cc 56 3d 00  ...48...]K~..V=.
00000050: 3c 70 3a e6                                      <p:.

Raw hex:
789c0bce4855284ecdc929069289c519605652a54209581828905f94aac31502e241e48ae1ea138b52117a74143cd573158a4b8b52f5b882f31532d39014220ccecfc334380fae135d4b7e11cc563d003c703ae6

Or generate this file yourself:
openssl zlib < seashells.txt > seashells.zlib

You can decompress this file execute this program with:
openssl zlib -d < seashells.zlib

or, presumably, any of the answers here.

Assuming I remember what header is used by gzip and what header is used by zlib, If you remove the first two bytes, this becomes a Bubblegum answer. (note that I already posted a shorter one)

JavaScript: 195 bytes ...?
console.log(`She ${a='sells'} sea${c='shells'} by the sea${e='shore'},
The ${c} she ${a} are sea${c}, ${d="I'm sure"}.
So if she ${a} sea${c} on the sea${e},
Then ${d} she ${a} sea${e} ${c}.`)

Simplest JavaScript answer possible. Simply defines commonly used words.
Annoyingly, compression made it longer

Just using 'sea' is shorter than '${b}'

Kinda true, let me fix that

Perl 5, 133 bytes
say"S5s0 10 by t513,
T5sh02are 10, 4.
So if210 on t513,
Then 4213 sh0."=~s/\d/(ells,seash," she sells ",ore,"I'm sure","he ")[$&]/ger

Try it online!

Splinter, 150 bytes
I{ECA}H{\ }G{\r\e}F{H\I\'\mC\uG}E{\h\e}D{H\tEB\oG\,\
\TE}C{H\s}B{C\e\a\s\h}A{\e\l\l\s}\SIBAH\b\yDC\hACIH\aGBA\,F\.\
\S\oH\i\fCIBAH\o\nD\nFCIB\oGC\hA\.

Try it online!

Vyxal 3.0.0beta.1, 77 bytes
"dyrΦ<ᶲrᵞjvG#IZᶳ²∵nᶨ₂ᶜ8G6OẠ′zḃṁɠ₉EFḟih←Xᵞᶻ1d²i)`⁰!⌐=x‴¶ᶢ↓•ƓΦ…ᶢɾʀ5ḋỌḄcGᵒıɾᶪ×‴”

Try it online!

This is more complicated than just calling your language's print equivalent.

Is it now.
Simply a single compressed string. No string formatting, no substitutions. Just one string.

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


text:
LeetCode 552: Student Attendance Record II
I'm posting my code for a LeetCode problem copied here. If you have time and would like to golf for a short solution, please do so.
Requirement

It has to only pass the LeetCode's Online Judge, if the language would be available.

If the language is not available, simply we should possibly keep the class Solution as well as the function name.

Languages and Version Notes
Available languages are:

C++ clang 9 Uses the C++17 standard.
Java    13.0.1
Python  2.7.12
Python3 3.8
C   gcc 8.2
C#  8.0
JavaScript 14.3.0
Ruby    2.4.5
Bash    4.3.30
Swift   5.0.1
Go  1.13
Scala   2.13
Kotlin  1.3.10
Rust    1.40.0
PHP 7.2

Thank you!
Problem

Given a positive integer n, return the number of all possible
attendance records with length n, which will be regarded as
rewardable. The answer may be very large, return it after mod 10 ^ 9 + 7.
A student attendance record is a string that only contains the
following three characters:

'A' : Absent.
'L' : Late.
'P' : Present.

A record is regarded as rewardable if it doesn't contain more than one
'A' (absent) or more than two continuous 'L' (late).
Example 1:

Input: n = 2
Output: 8

Explanation:
There are 8 records with length 2 will be regarded as rewardable:

"PP" , "AP", "PA", "LP", "PL", "AL", "LA", "LL"

Only "AA" won't be regarded as rewardable owing to more than one absent times.

Note: The value of n won't exceed 100,000.

Accepted Code
class Solution:
    def checkRecord(self, n):
        MOD = 1000000007
        a = b = d = 1
        c = e = f = 0
        for _ in range(n - 1):
            a, b, c, d, e, f = (a + b + c) % MOD, a, b, (a + b + c + d + e + f) % MOD, d, e

        return (a + b + c + d + e + f) % MOD

Accepted Golf Attempt in Python 3 - 185 bytes - I
class Solution:
    def checkRecord(self,n):
        M=1000000007;a=b=d=1;c=e=f=0
        for _ in range(n-1):a,b,c,d,e,f=(a+b+c)%M,a,b,(a+b+c+d+e+f)%M,d,e
        return(a+b+c+d+e+f)%M

Accepted Golf Attempt in Python 3 - 185 bytes - II
class Solution:
    def checkRecord(self,n):
        M=int(1e9+7);a=b=d=1;c=e=f=0
        for _ in range(n-1):a,b,c,d,e,f=(a+b+c)%M,a,b,(a+b+c+d+e+f)%M,d,e
        return(a+b+c+d+e+f)%M

Reference
In LeetCode's answer template, there is a class usually named Solution with one or more public functions which we are not allowed to rename.

Problem

Discuss

Languages

I guess the solution was originally designed by Stefan Pochmann

I appreciate you being open with crediting the problem LeetCode and providing a link to it. But I still wonder if the site or challenge author would be OK with having the problem here. It also makes a lot of answers be easy to Google.

As a code golf challenge, this has lots of things we consider Things to Avoid on the site, with the lengthy boilerplate names and the programming chestnut of 10^7+9. It's also not ideal that to know if a solution is fast enough to pass I have to run it on another site. As a tips question, this all of course all makes sense to help you with a challenge from elsewhere. I think though that we'd do better to help if you explain how your code works and what you've tried, and limit to your one language.

This surely won't scale to inputs like n=10^6 within the needed runtime, but here's a short and nifty purely integer-arithmetic expression based on generating functions: Try it online!. This is only partly golfed and doesn't have the mod 1e9+7. For larger input n, you'll need L to at least n, and B to at least the output.

If anyone wants it, the generating function (formal power series) is pretty nice: $(1+x+x^2)/(1-x-x^2-x^3)^2$.

Tips:

The first argument self can be renamed to something shorter.
Use while n:n-=1 to loop n times
(Python 2 specific) You can use a single tab for the second level of indentation, instead of 2 spaces.
For this problem, it's sufficiently fast to just mod b every loop, instead of having to mod both a and d.
The part a,b,c,d,e,f=... can be broken into a,b,c=...;d,e,f=..., which allows reusing the updated value a=a+b+c
c,e,f can be initialized to 10**9+7 instead of 0 (found by @xnor).

Python 2, 136 134 131 127 125 bytes
class Solution:
 def checkRecord(_,n):
	a=b=d=1;c=e=f=M=10**9+7
	while n:n-=1;a,b,c=a+b+c,a%M,b;d,e,f=a+d+e+f,d,e
	return d%M

Try it online!

exec('a,b,c=a+b+c,a%M,b;d,e,f=a+d+e+f,d,e;'*n) saves 2 over the while loop. EDIT, actually 6 as it allows inlining too: def checkRecord(_,n):M=10**9+7;a=b=d=1;c=e=f=0;exec('a,b,c=a+b+c,a%M,b;d,e,f=a+d+e+f,d,e;'*n);return d%M.

@JonathanAllan thanks, I did consider using exec, but it's too slow for large n due to the construction of really long  string.

Haven't check this on Leetcode, but it looks like you can initialize c=e=f=M=10**9+7 since we're working mod M anyway.

@xnor That works, thanks!

You don't need more than one space per level of indentation.
Observe that you have (a+b+c+d+e+f) used twice. This code duplication can be avoided by running the loop one more time and using d of the extra iteration
[0]*n is 3 bytes shorter than range(n)
It's not necessary to modulo by 1000000007 each time; you can remove it from the loop and only do it at the end (This takes about 1 second for n=100000 on TIO, which appears to be too slow). After this, M will only be used once, so you can inline it into the one place it was used

Python 3, 136 bytes
class Solution:
 def checkRecord(self,n):
  a=b=d=1;c=e=f=0
  for _ in [0]*n:a,b,c,d,e,f=a+b+c,a,b,a+b+c+d+e+f,d,e
  return d%int(1e9+7)

Try it online!

Or, if the last tip is too slow:
Python 3, 148 bytes
class Solution:
 def checkRecord(self,n):
  M=int(1e9+7);a=b=d=1;c=e=f=0
  for _ in [0]*n:a,b,c,d,e,f=(a+b+c)%M,a,b,(a+b+c+d+e+f)%M,d,e
  return d%M

Try it online!

@pppery you can rename self to something with 1 character, and remove the space after in: for _ in[0]*n. If you switch to Python 2, you can use a single tab instead of 2 spaces for the second level of indent.

@SurculoseSputum This is a [tag:tips] question, so I think that would be better as a separate answer.

@pppery gotcha, I'll post a separate answer.

You can remove the space at in[0] in both your functions.

@KevinCruijssen This is a [tag:tips] question, so that tip should be a separate answer. I will not be editing any other users' golfing suggestions into this answer, because I feel that defeats the point of [tag:tips].

C (gcc), 121 bytes
checkRecord(n){long a=1,b=1,d=1,c=0,e=0,f=0,x,y,m=7+1e9;for(;n--;d=y%m)x=a+b+c,y=x+d+e+f,f=e,e=d,c=b,b=a,a=x%m;return d;}

Try it online!
Slightly golfed less
checkRecord(n){
  long a=1,b=1,d=1,c=0,e=0,f=0,x,y,m=7+1e9;
  for(;n--;d=y%m)
    x=a+b+c,
    y=x+d+e+f,
    f=e,
    e=d,
    c=b,
    b=a,
    a=x%m;
  return d;
}

116 bytes

Python 2, 127 126 119 bytes
class Solution:
 def checkRecord(s,n):
    a=[1,0,0]
    while~n:n-=1;a=[sum(a[:3])]+a;b=a[3]=sum(a[1:7])%(10**9+7)
    return b

Try it online! Somewhat slower than @SurculoseSputum's answer. Edit: Saved 1 byte thanks to @KevinCruijssen. Saved a further 7 bytes thanks to @xnor.
Out of interest, I also wrote a 34-byte solution in Charcoal:
≔Ｅ⁶¬ιηＦＮＵＭη⎇﹪λ³§η⊖λΣ…η⁺³λＩ﹪Ση⁺⁷Ｘφ³

Try it online! Link is to verbose version of code. Explanation:
≔Ｅ⁶¬ιη

Create an array of six elements where only the first element is 1 and the others are all 0.
ＦＮ

Loop over the given number of times.
ＵＭη

Modify the array in-place according to the result of the mapping (the mapping is calculated first, then the array modified).
⎇﹪λ³

For positions 1, 2, 4 and 5:
§η⊖λ

Take the previous element of the previous array.
Σ…η⁺³λ

Otherwise take the sum of the array so far plus the next three elements.
This results in h = [sum(h[0:3]), h[0], h[1], sum(h), h[3], h[4]].
Ｉ﹪Ση⁺⁷Ｘφ³

Take the final sum and reduce modulo 7+1000**3.

You can remove the space at in[0] for -1 in the Python function.

@KevinCruijssen ... I was just pasting that in, but I'll be generous and credit you anyway.

Nice solution, here's a couple more saves: Try it online! (fixed)

119: Try it online!

Does TLE mean it took too long? Ran out of memory?

@Emma You can make it much faster at a cost of 4 bytes by adding [:5]: after the +a.

Java, 137 bytes
long checkRecord(int n){long a=1,b=1,c=0,d=1,e=0,f=0,x,y,m=7+(int)1e9;for(;n-->0;y=x+d+e+f,f=e,e=d,c=b,b=a,a=x%m,d=y%m)x=a+b+c;return d;}

Figured I'd add a Java answer, since it was missing. It's a straightforward port of @ceilingcat's C answer, since I couldn't find anything shorter.
Try it online.

05AB1E, 24 23 bytes
6LΘIFÐÁr3£‚O30Sǝ}O9°7+%

Try it online.
Explanation:
6L                # Push the list [1,2,3,4,5,6]
  Θ               # Check == 1 for each (1 if truthy; 0 if falsey): [1,0,0,0,0,0]
   IF             # Loop the input amount of times:
     Ð            #  Triplicate the list at the top of the stack
      Á           #  Rotate the top list once towards the right: [f,a,b,c,d,e]
       r          #  Reverse the stack so this rotated list is at the bottom
        3£        #  Pop and push the first three items of the top list: [a,b,c]
          ‚       #  Pair it with the full list: [[a,b,c,d,e,f],[a,b,c]]
           O      #  Sum both inner lists: [a+b+c+d+e+f,a+b+c]
            30S   #  Push [3,0]
               ǝ  #  Insert the a+b+c+d+e+f and a+b+c at indices 3 and 0 respectively in
                  #  the rotated list: [a+b+c,a,b,a+b+c+d+e+f,d,e]
    }O            # After the loop, sum the resulting list
      9°          # Push 10 to the power 9: 1000000000
        7+        # Add 7: 1000000007
          %       # Modulo
                  # (after which the result is output implicitly)

x86_64 machine language for Linux, 83 bytes
0x00:  55                push rbp
0x01:  45 31 C0          xor  r8d, r8d
0x04:  31 C9             xor  ecx, ecx
0x06:  53                push rbx
0x07:  6A 01             push 1
0x09:  41 5A             pop  r10
0x0b:  31 DB             xor  ebx, ebx         ; a=b=d=0
0x0d:  4D 89 D1          mov  r9, r10
0x10:  4D 89 D3          mov  r11, r10         ; c=e=f=1
0x13:  BE 07 CA 9A 3B    mov  esi, 0x3b9aca07  ; m=1000000007
0x18:  4B 8D 04 0B       lea  rax, [r11 + r9]
0x1c:  48 01 C8          add  rax, rcx         ; x=a+b+c
0x1f:  48 99             cqo
0x21:  49 8D 0C 02       lea  rcx, [r10 + rax]
0x25:  48 F7 FE          idiv rsi              ; x%=m
0x28:  4C 01 C1          add  rcx, r8
0x2b:  48 01 D9          add  rcx, rbx         ; y=x+d+e+f
0x2e:  4C 89 C3          mov  rbx, r8          ; f=e
0x31:  48 89 C8          mov  rax, rcx         ; e=d
0x34:  4C 89 C9          mov  rcx, r9          ; c=b
0x37:  48 89 D5          mov  rbp, rdx         ; b=a
0x3a:  48 99             cqo
0x3c:  48 F7 FE          idiv rsi              ; y%=m
0x3f:  4D 89 D0          mov  r8, r10
0x42:  4D 89 D9          mov  r9, r11
0x45:  49 89 D2          mov  r10, rdx         ; d=y
0x48:  49 89 EB          mov  r11, rbp         ; a=x
0x4b:  FF CF             dec  edi
0x4d:  75 C9             jne  0x18             ; if( --n ) goto 0x18
0x4f:  92                xchg eax, edx
0x50:  5B                pop  rbx
0x51:  5D                pop  rbp
0x52:  C3                ret                   ; return d

To Try it online!, call the following c code as if it were a function (you may also be able to paste it into one or more 'interview preparation websites' and run it as if it were a c program)
(*checkRecord)()=L"\xc0314555\x6a53c931\x315a4101\xd1894ddb\xbed3894d\x3b9aca07\x0b048d4b\x48c80148\x0c8d4999\xfef74802\x48c1014c\x894cd901\xc88948c3\x48c9894c\x9948d589\x4dfef748\x894dd089\xd28949d9\xffeb8949\x92c975cf\xc35d5b";