text:
You've got a book to make!
You work at a virtual, old-fashioned printing press. To help you arrange your monospace letters faster, you decide to make the shortest program possible to help you. Given a string of text and a page size, generate and output each page of the text.
Examples
For example, with a page width of 14, height 7, and some text, here is your book:
14, 7, "Fruits make an extremely good snack due to their utterly scrumptious sweetness. They are also very healthy for you."
+------------+
| Fruits     |
| make an    |
| extremely  |
| good snack |
| due to     |
+------------+

+------------+
| their      |
| utterly    |
| scrumptio- |
| -us        |
| sweetness. |
+------------+

+------------+
| They are   |
| also very  |
| healthy    |
| for you.   |
|            |
+------------+

Here's the basic page setup:
|---i.e.14---|
+------------+ -
| Xxxxxxxxxx | |
| Xxxxxxxxxx | i.
| Xxxxxxxxxx | e.
| Xxxxxxxxxx | 7
| Xxxxxxxxxx | |
+------------+ -

A few things

There is a one-space margin between the page edges and the text.
The width and height include the box edges, if that wasn't clear.
Wraparound only occurs if a word can't fit on a single line.
The program needs to be able to output as many pages as needed, and only that many.
Your program has to support any page size, not just 14 by 7.
This is code golf, so the smallest solution in bytes (any language) wins.
Don't ruin the fun. Standard loopholes are obviously not allowed.

Oh, and, by the way:
+------------+
| May the    |
| best book  |
| publisher  |
| win. Good  |
| Luck!      |
+------------+

+------------+
| Best       |
| program    |
| so far:    |
| Charcoal   |
|            |
+------------+

@rod Oops, fixed.

If you mean for example 14 that’s e.g.

Closely related.

Is hyphenation required?

Do we need to handle 'multi-cuts' on a single word? (like scru-/-mpt-/-ious)

@Arnauld If a word's long enough, then yes.

Suggested test case: 7, 3, Three Is The Magic Number! (yielding 14 pages, each of one line: Th-,-r-,-ee,Is ,The,Ma-,-g-,-i-,-c ,Nu-,-m-,-b-,-e-,-r!)

Python 2, 306 304 283 279 bytes
def f(w,h,s):
 b=[];w-=4;h-=2;H='+-'+'-'*w+'-+';x=l='';s=s.split()
 while s:
	W=s.pop(0)
	if W[w:]:W,s=W[:w-1]+'-',['-'+W[w-1:]]+s
	if len(l+W)<=w-(l>x):l+=' '*(l>x)+W
	else:b+=[l];l=W
 b+=[l]+[x]*h
 while any(b):print'\n'.join([H]+['| %-*s |'%(w,b.pop(0))for _ in' '*h]+[H,x,x])

Try it online!

I think you can use L=len to save 2 bytes total...

FYI (not sure if it needs addressing) the test case I suggested (7, 3, "Three Is The Magic Number!") yields a leading empty page.

@JonathanAllan Thanks, fixed it :)

Charcoal, 105 83 bytes
ＮθＮηＭ⁺η²↑Ｆ⪪Ｓ «Ｗ›Ｌι⁻θ⁴«⊞υ⁺…ι⁻θ⁵-≔⁺-✂ι⁻θ⁵Ｌι¹ι»⊞υι»Ｆυ«¿‹Ｌι±ⅈ «Ｍ⁻⁻⁴ⅈθ¹¿¬﹪ⅉ⊕η«↙↙Ｂθη↘→»»ι

Try it online! Link is to verbose version of code the deverbosifier can't handle the ⅈ and ⅉ nilary operators. If leading blank lines were acceptable, I could get it down to 76 bytes:
≔⁻Ｎ⁴θＭθ→ＮηＦ⪪Ｓ «Ｗ›Ｌιθ«⊞υ⁺…ι⊖θ-≔⁺-✂ι⊖θＬι¹ι»⊞υι»Ｆυ«¿‹⁺ⅈＬιθ «Ｆ¬﹪ⅉ⊕η«⸿↙↙Ｂ⁺θ⁴η»⸿»ι

Explanation:
ＮθＮη

Input the width into q and the height into h.
Ｍ⁺η²↑

Move to a position that will trigger the first box to be drawn, but without generating a top margin.
Ｆ⪪Ｓ «

Loop over all the words in the input string.
Ｗ›Ｌι⁻θ⁴«

Repeat while a word is too wide to fit into a box.
⊞υ⁺…ι⁻θ⁵-

Push as much of the word that will fit plus a trailing hyphen.
≔⁺-✂ι⁻θ⁵Ｌι¹ι»

Prefix a hyphen to the rest of the word.
⊞υι»

Push the rest of the word.
Ｆυ«

Loop over all the hyphenated words.
¿‹Ｌι±ⅈ

Check whether the word fits on the current line.
 «

If so then print a space.
Ｍ⁻⁻⁴ⅈθ¹

Otherwise move to the start of the next line.
¿¬﹪ⅉ⊕η

Check whether we need a new box.
«↙↙Ｂθη↘→»»

If so then draw the box.
ι

Finally, print the word.

Perl 5, 203 182 + 1 (-a) = 183 bytes
$t=($\=-3+shift@F)-2;$h=shift@F}{say$_='+'.'-'x$\.'-+';map{$_="";{$_.=shift@F;s/.{$t}\K..+/-/&&unshift@F,-$&;$_.=$";y///c+length$F[0]<$\&&redo}printf"| %-$\s|
",$_}3..$h;say;@F&&redo

Try it online!

SOGL V0.12, 92 bytes
Aē:b⁾\&?Q¶oQ}cI@*¼|a31žO■
.⁾:0EHC┌*¼+Q,θK;{⁴D@Κ+lc<‽Xd■Flc<‽ø;c⁾{Kh+;}D┌+■d┌Κ}}}■beb⁾%-⁾{ø■}

Try it Here!

Fails with lower widths

@JonathanAllan oh. :/ fixing this to allow multi-cuts is probably gonna be a lot of bytes..

JavaScript (ES8), 242 bytes
Thanks to @Tvde1 for reporting a bug
(s,w,h)=>s.split` `.map(g=s=>l=(l+s)[W=w-5]?s[l&&A(l),l='',w-4]?g('-'+s.slice(W),A(s.slice(0,W)+'-')):s:l?l+' '+s:s,n=o=l='',h-=2,b=`+${'-'.repeat(w-2)}+
`,A=s=>o+=(!n|n++%h?'':b+`
`+b)+`| ${s.padEnd(w-3)}|
`)&&(g=s=>A(s)&&n%h?g(''):b+o+b)(l)

Try it online!
Commented
(s, w, h) =>                        // given s = string, w = width, h = height
  s.split` `                        // get all words by splitting the string on spaces
  .map(g = s =>                     // for each word s:
    l = (l + s)[W = w - 5] ?        //   if the word is too long for the current line:
      s[ l && A(l),                 //     append the line (if not empty)
         l = '',                    //     clear the line
         w - 4 ] ?                  //     if the word itself doesn't fit:
        g(                          //       do a recursive call with:
          '-' + s.slice(W),         //         a hyphen + the next part
          A(s.slice(0, W) + '-')    //         and append the current part + a hyphen
        )                           //       end of recursive call
      :                             //     else:
        s                           //       initialize a new line with this word
    :                               //   else:
      l ?                           //     if the current line is not empty:
        l + ' ' + s                 //       append a space + the word
      :                             //     else:
        s,                          //       initialize a new line with this word
    n = o = l = '',                 //   n = line counter, o = output, l = line
    h -= 2,                         //   adjust h
    b = `+${'-'.repeat(w - 2)}+\n`, //   b = border + linefeed
    A = s =>                        //   A = function that updates the output o:
      o += (                        //     append to o:
        !n | n++ % h ?              //       if we haven't reached an end of page:
          ''                        //         an empty string
        :                           //       else:
          b + `\n` + b              //         bottom border + linefeed + top border
      ) +                           //       followed by
      `| ${s.padEnd(w - 3)}|\n`     //       left border + padded text + right border
  ) &&                              // end of map()
  (g = s =>                         // g = recursive function taking s:
    A(s) &&                         //   append s
    n % h ?                         //   if we haven't reached an end of page:
      g('')                         //     go on with an empty line
    :                               //   else:
      b + o + b                     //     return top border + output + bottom border
  )(l)                              // initial call to g() with the last pending line

Try your example text with 12 and 7, some lines/words are reversed.

@Tvde1 Thanks for reporting this. It should now be fixed.

Jelly, 93 bytes
1,⁴Ṭị⁾+-W,`
ṣ⁶µḊṖs⁴_6¤j⁾--;@Ḣ;Ṫḟ0s⁴_©4¤µ€ẎŒṖK€€µL€>®ẸµÐḟṪ;€⁶x®¤ḣ€®s⁵_2¤Zz⁶x®¤j@€€⁾| ,U¤j@€¢ẎY

A full program taking three arguments (text, width, height) which prints the pages.
Try it online! N.B. Too inefficient to run the example from the OP within the 60 second limit.
(97 bytes if the blank line between pages is actually a requirement)
How?
1,⁴Ṭị⁾+-W,` - Link 1, make header & footer: no arguments
  ⁴         - program's 2nd argument, width
1           - literal one
 ,          - pair = [1,width]
   Ṭ        - untruth = [1,0,0,...,0,0,1] (a 1 at index 1 and index width; 0 elsewhere)
     ⁾+-    - literal list of characters = "+-"
    ị       - index into (1-based & modular) = "+--...--+"
        W   - wrap = ["+---...--+']
          ` - use as both arguments of the dyad:
         ,  - pair = [["+---...--+'],["+---...--+']]

ṣ⁶µḊṖs⁴_6¤j⁾--;@Ḣ;Ṫḟ0s⁴_©4¤µ€ẎŒṖK€€µL€>®ẸµÐḟṪ;€⁶x®¤ḣ€®s⁵_2¤Zz⁶x®¤j@€€⁾| ,U¤j@€¢ẎY

 - Main link. This is long so splitting it up into parts like so:
ṣ⁶µ "A" µ€ "B" µ "C" µÐḟ "D"
ṣ⁶                           - split 1st argument (text) at spaces
  µ "A" µ€                   - for €ach resulting word do "A" (get hyphenated parts)
           "B"               - do "B" (all ways to partition those joining with spaces)
                     µÐḟ     - filter discard if:
               µ "C"         -   do "C" (any parts are too long)
                         "D" - do "D" (format the resulting list into the page-format)

"A" = ḊṖs⁴_6¤j⁾--;@Ḣ;Ṫḟ0s⁴_©4¤ - Hyphenate: list, word     e.g. "Something"
      Ḋ                        - dequeue                        "omething"
       Ṗ                       - pop                            "omethin"
            ¤                  - nilad followed by link(s) as a nilad
         ⁴                     -   program's 2nd argument  e.g. 9  (width)
           6                   -   literal six                  6
          _                    -   subtract                     3
        s                      - split into chunks             ["ome","thi","n"]
              ⁾--              - literal list of characters     "--"
             j                 - join                           "ome--thi--n"
                   Ḣ           - head (word)                    "S"
                 ;@            - concatenate (sw@p arguments)   "Some--thi--n"
                     Ṫ         - tail (word)                    "g"
                    ;          - concatenate                    "Some--thi--ng"
                      ḟ0       - filter out zeros (tail yields 0 for words of length 1)
                             ¤  - nilad followed by link(s) as a nilad:
                         ⁴      -   program's 2nd argument      9
                            4   -   literal four                4
                          _     -   subtract                    5
                           ©    -   copy to register & yield    5
                        s       - split into chunks             ["Some-","-thi-","-ng"]

"B" = ẎŒṖK€€ - Line arrangements: list of lists of hyphen-parts / single words
      Ẏ      - flatten by one (make a list of words and hyphen-parts
             - e.g. [["Not"],["hyph-","-ena-","-ted"]] -> ["Not","hyph-","-ena-","-ted"]
       ŒṖ    - partition e.g. [1,2,3]->[[[1],[2],[3]],[[1],[2,3]],[[1,2],[3]],[[1,2,3]]]
         K€€ - join with spaces for €ach for €ach e.g. ["one","two"]->"one two"

"C" = L€>®Ẹ - Any part too long?: one of the list of lines from "B"
      L€    - length of €ach
         ®  - recall from the register (width minus 4)
        >   - greater than (vectorises) - 1 if so 0 if not
          Ẹ - any truthy? (1 if any too long)

"D" = Ṫ;€⁶x®¤ḣ€®s⁵_2¤Zz⁶x®¤j@€€⁾| ,U¤j@€¢ẎY - Format as pages: list of valid arrangements
      Ṫ                                     - tail (last valid partition is greediest)
            ¤                               - nilad followed by links as a nilad:
         ⁶                                  -   literal space character
           ®                                -   recall from register (width minus 4)
          x                                 -   repeat elements
       ;€                                   - concatenate to €ach
               ®                            - recall from register (width minus 4)
             ḣ€                             - head €ach to index
                    ¤                       - nilad followed by links as a nilad:
                 ⁵                          -   program's 3rd argument, height
                   2                        -   literal two
                  _                         -   subtract
                     Z                      - transpose
                          ¤                 - nilad followed by link(s) as a nilad:

                       ⁶                    -   literal space character
                         ®                  -   recall from register (width minus 4)
                        x                   -   repeat elements

                      z                     - transpose with filler (repeated spaces)
                                    ¤       - nilad followed by link(s) as a nilad:
                               ⁾|<space>    -   literal list of characters = "| "
                                   U        -   upend = " |"
                                  ,         -   pair = ["| "," |"]
                           j@€€             - join for €ach for €ach (sw@p arguments)
                                        ¢   - call last link (1) as a nilad
                                     j@€    - join for €ach (sw@p arguments)
                                         Ẏ  - flatten by one
                                          Y - join with line feeds
                                            - implicit print

PHP, 299 bytes
for($a=explode(" ",$argv[3]);$y|$e=strlen($d=$a[+$i++]);$x||print"|",$x|$e<$w?$e<$w-$x?$x+=$e+print" $d":$i-=!$x=!$y+=print str_pad("",$w-$x)." |
":$y+=print" ".substr($d,0,$w-2)."- |
".!$a[--$i]="-".substr($d,$w-2),$y>$argv[2]-2&&$y=!print"$t
")$y||$y=print$t=str_pad("+",2+$w=$argv[1]-3,"-")."+
";

Run with php -nr '<code>' <width> <height> '<text>' or or try it online.


text:
First and last prime numbers with prime digits of range
Challenge
For a given positive integers range, find the first and last prime number entirely composed of prime number digits, exceptionally including 0 (for the digits, a range of 0-2 should output 2-2). The range is inclusive. If no number is found, the expected output is 0. If there is only one such number, the expected output is that number twice.
Examples

For the range 1–100, the first prime number is 2 and the last is 73 (7 and 3 are prime numbers).
For the range 70–80, the first prime number is 73 and the last is also 73 (Since there is only one correct number in the given range, we return it twice).
For the range 190–200, there is no correct answer, so you return 0.
For the range 2000-2100, the first prime number is 2003 and the last is 2053 (we omit the digit 0, but all the other digits are prime)

This is code-golf, so the shortest code in bytes win!
All standard loopholes apply.
Input

You are free to accept two integers as input however you may see fit, stack, function argument(s), CLI argument, stdin.
You must only receive two integers.

Output

You must either return the result (a tuple, an array, multi-return if your language supports it), leave it on the stack, or print it (in this case, they must be separated somehow).
The order of the outputs is irrelevant.
You are allowed leading/trailing brackets and newlines.
You must return two numbers, if there is an answer, even if they are the same.
You must return 0 if there is no answer.

Just to make sure, if I'm returning a list of integers when there are answers, I can return a list containing just 0 when there are no answers? I don't need to return 0 instead of [0]?

Python 2, 123 bytes
def f(a,b):r=[i for i in range(a,b+1)if(set(`i`)<=set('02357'))>any(i%k<1for k in range(3,i))];return len(r)and(r[0],r[-1])

Try it online!

122 bytes in Python 3

Perl 6, 105 94 90 86 bytes
{my @b=grep {is-prime all($_,|.comb>>.Int Xor 2)},$^a..$^b;say @b??"@b[0] @b[*-1]"!!0}

JavaScript (ES6), 83 bytes
Takes the range [a-b] in currying syntax (a)(b). Returns either a 2-element array or 0.
n=>g=(m,a=0)=>n>m?a:g(m-1,(P=d=>m%--d?P(d):d>1|/[14689]/.test(m))(m)?a:[m,a[1]||m])

Test cases

let f =

n=>g=(m,a=0)=>n>m?a:g(m-1,(P=d=>m%--d?P(d):d>1|/[14689]/.test(m))(m)?a:[m,a[1]||m])

console.log(f(1)(100))
console.log(f(70)(80))
console.log(f(190)(200))

Mathematica, 91 bytes
If[(s=Select[Range@##,(p=PrimeQ)@#&&And@@((p@#||#<1)&/@IntegerDigits@#)&])!={},MinMax@s,0]&

Try it online!

Pyth, 24 bytes
Using my initial approach turns out to be shorter.
.x,eKfP#I_M-+TjT;0}EQhKZ

Try it here!
(I was just updating to 23 but Steven beat me to it)
?KfP#I_M-+TjT;0}FQhM_BK0

Try it here!
Natually, hM_BK can be replaced by ,hKeK.
25 bytes
.x,eKf.AmP_|d2+TjT;}EQhKZ

Try it here!
26 bytes
|>2.<f.AmP_|d2+TjT;*2}EQ1Z

Try it here!
|>2.<fP#I_M|R2+TjT;*2}EQ1Z

Try it here!

How they work
.x,eKfP#I_M-+TjT;0}EQhKZ ~ Full program. Q, E = first, second inputs

.x                     Z ~ Try-catch block. If the code errors, output 0.
     f            }EQ    ~ Filter the range [E ... Q] for (uses a variable T):
            +TjT;          ~ Append T to the list of its digits.
           -     0         ~ Remove the zeros.
         _M                ~ Multiply each by -1 (for primality testing).
        I                  ~ Check if the result is invariant over...
      P#                   ~ Removing non-prime items.
    K                    ~ Assigned the filtered range to a variable K.
  ,e                     ~ Pair the last element of K with...
                     hK  ~ Its first element.

|>2.<f.AmP_|d2+TjT;*2}EQ1Z ~ Full program.

                   *2}EQ   ~ Inclusive range, repeated twice..
     f                     ~ Filter, using T as the current number.
                jT;        ~ Base-10 digits of T.
              +T           ~ Concatenated with T.
        mP_|d2             ~ Prime check after performing OR 2 (makes 0 be treated as prime)
      .A                   ~ Do all satisfy this condition?
   .<                   1  ~ Rotate by one place cyclically to the left.
 >2                        ~ Last two elements (ignored if there aren't enough)
|                        Z ~ Logical or with 0.

Outgolfed by 1, and I think there's still more to save

This one doesn't return two instances of [73] in the [70, 80] test case.

Outgolfed you back by 1, now at 25.

@StevenH. Outgolfed you back by 1, now at 24.

The competition's getting intense... at 23!

I am going to bed now, continuing this  tomorrow evening ;D (though I think our solutions are slowly tending towards optimality)

Brachylog, 16 bytes
⟦₂{ṗṗᵐ}ˢ⟨⌋≡⌉⟩|∧0

Try it online!
The completely non-sensical "return 0 if there's no prime" makes us lose 3 bytes (|∧0) for no reason (it would return false. if we didnt add them)
Explanation
⟦₂                Range from the smallest element of the input to the biggest
  {   }ˢ          Select on that range:
   ṗ                Numbers that are primes
    ṗᵐ              And whose digits are primes
        ⟨   ⟩     Fork on this new list:
         ⌋          Minimum
           ⌉        maximum
          ≡         Do nothing and return [Minimum, Maximum]
             |∧0  If all of this fails (i.e. the list after selection is empty), return 0

Invalid because it doesn't handle the digit 0 as being prime (as specified in the challenge). Thus, it fails for [2000, 2100]

Jelly, 14 bytes
æRµDo2ÆPẠµÐf.ị

Try it online!
How it works

æRµDo2ÆPẠµÐf.ị ~ Full program.

æR             ~ Inclusive prime range.
  µ      µÐf   ~ Only keep those which satisfy a condition.
   Do2ÆPẠ      ~ The filter condition:
   D             ~ The decimal digits of the current number.
    o2           ~ Logical or with 2 (maps 0 to 2 and any other digit to itself).
      ÆP         ~ Is prime (element-wise)?
        Ạ        ~ Check whether all the digits satisfy the condition.
            .ị ~ Get the element at modular index 0.5. Some details:
                 ~ Jelly is 1-indexed, so 1 gives us the first element, whilst 0
                   gives us the last element.
                 ~ If the ceil and the floor of the given number N don't match,
                   then Jelly returns the items at indexes floor(N) and ceil(N).
                 ~ If the list is empty, this yields 0, hence it is very convenient.

If taking the whole range would be allowed (although I think it should not be), then 12 bytes:
Do2,ÆPȦµÐf.ị

Try it online!

13 bytes Although it isn't super similar. Should I just post it myself? You can take it if you want but let me know if you're going to keep your solution.

OP says For a given positive integers range. I'll ask to clarify

@dylnan note that your version is invalid nonetheless (0 is the exception from the challenge, because it should be treated as a prime digit for some reason). Anyway, I posted a shorter and valid version

Oh I thought the 0 is prime rule had been changed

Mathematica 85 Bytes
I know there is already a similar answer, but the approach here is quite different.
MinMax@Cases[Range@##,x_/;PrimeQ@x&&DisjointQ@@IntegerDigits/@{x,14689}]/.{_,∞}->0&

This 83 character answer will paste and run in Mathematica.  The TIO site doesn't know how to interpret ∞.

Jelly, 14 bytes
Do2ÆPẠ
æRÇÐf.ị

Try it online!
æRÇÐf.ị            Main link
æR                 Prime range
   Ðf              Filter the range with...
  Ç                The helper link
      ị            At index (decimal, returns [xs[floor], xs[ceil]], otherwise 0)
     .             0.5

Do2ÆPẠ             Helper link
D                  For each decimal
 o2                Replace 0s with 2s, an actual prime prime (could be 3, 5, or 7).
   ÆP              Filter primes (1 if true, 0 if false)
     Ạ             Check if all are true

Thanks to Erik the Outgolfer for the help fixing a bug.
Thanks to Mr. Xcoder for the .ị trick.

Would ṙ-ḣ2 work for Ḣ,Ṫ to fix it (might have to modify a little more)?

@Zacharý that gives the output in the wrong order, though. And it doesn't seem to work :\

@Mr.Xcoder The Jelly room led me to the same solution. Thanks!

.ị might work as well (kind of stolen from Mr. XCoder)

You're right! That's nice.

Ruby, 87 bytes
->a,b{(z=(a..b).select{|x|(2...x).none?{|r|x%r<1}&&/[14689]/!~"%d"%x})[0]?(z.minmax):0}

Try it online!

CJam, 36 bytes
),>{mp},{s{_!\~mp|}%1-!},_{_0=\W=}0?

Try it online!

Perl 6,  68 66 65 61  58 bytes
{($_=($^a..$^b).grep({.is-prime&&/^<[02357]>+$/})[0,*-1])[1]??$_!!0}

Try it
{($_=($^a..$^b).grep({.is-prime&&!/<[14689]>/})[0,*-1])[1]??$_!!0}

Try it
{($_=($^a..$^b).grep({.is-prime*!/<[14689]>/})[0,*-1])[1]??$_!!0}

Try it
{($_=($^a..$^b).grep({.is-prime*!/<[14689]>/}))??.[0,*-1]!!0}

Try it
{($_=grep {.is-prime*!/<[14689]>/},$^a..$^b)??.[0,*-1]!!0}

Try it
Expanded:
{  # bare block lambda with two placeholder parameters ｢$a｣ and ｢$b｣

  (
    $_ =  # store the list in ｢$_｣ for later use

      grep {
          .is-prime

        *              # True * True == 1 (all others equal 0)

          !/<[14689]>/ # doesn't contain a non-prime other than 0
      },

      $^a .. $^b       # inclusive Range

  )            # is the list Truish (not empty)
  ?? .[0,*-1]  # if so output the first and last values (from ｢$_｣)
  !! 0         # otherwise return 0
}

Perl 5, 79 + 2 (-ap) = 81 bytes
map{$f=0|sqrt;1while$_%$f--;$s||=$_,$\=-$_ if!$f&&!/[14689]/}$F[0]..$F[1];$_=$s

Try it online!

Java 8, 165 164 163 152 bytes
(a,b)->{for(;a<=b&p(a);a++);for(;b>a&p(b);b--);return a>b?"0":a+" "+b;}boolean p(int n){int i=1;for(;n%++i%n>0;);return!(n+"").matches("[02357]+")|i<n;}

-1 byte thanks to @ceilingcat.
Explanation:
Try it online.
(a,b)->{           // Method with two integer parameters and String return-type
                   //  (Input `a` is the lowest input, input `b` is the highest input)
  for(;a<=b        //  Increase `a` as long as it's smaller than or equal to `b`,
       &p(a);a++); //  and it's not a prime, and not all of its digits are prime-digits
  for(;b>a         //  Decrease `b` as long as it's larger than `a`,
       &p(b);b--); //  and it's not a prime, and not all of its digits are prime-digits
  return a>b?      //  If `a` is now larger than `b`:
    "0"            //   Return 0, because nothing is found
   :               //  Else:
    a+" "+b;}      //   Return the resulting `a` and `b`

// Separated method that'll result in true if the integer is NOT a prime number,
// or any of its digits are NOT prime numbers (excluding 0)
boolean p(int n){int i=1;for(;n%++i%n>0;);return!(n+"").matches("[02357]+")|i<n;}

@ceilingcat Thanks. Been able to save 11 more bytes by using a different prime checker that only works for positive integers.

Clean, 142 131 125 bytes
import StdEnv
@a b#l=[n\\n<-[a..b]|and[gcd p n<2&&or[c==k\\k<-:"02357"]\\p<-[1..n-1],c<-:toString n]]
|l>[]=[hd l,last l]=[0]

Ungolfed:
import StdEnv
fn start finish
    # primes
        = [ n
            \\
            n <- [start..finish]
            | and [ gcd p n == 1 && isMember c ['0','2','3','5','7']
                \\
                p <- [1..n-1],
                c <-: toString n
            ]
        ]
    | isEmpty primes
        = [0]
    = [hd primes, last primes]

Try it online!

Pyth, 28 25 23 bytes
.xhM_BfP#I_M #+TjT;}FQ0

Test suite. Returns [2003,2053] for the last test case, since 2053 is prime.

Haha, invalid. Returns [0, 0] instead of 0

Ah, shoot.  I'll fix that.

@Mr.Xcoder Fixed!

God damn it I was just updating with 23 too

I thought you said you were going to bed... You tricky you :P

I strived to outgolf you first, it’s just too fun :-)

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:
A regex to match three consecutive integers iff the third integer is the sum of the first two
Write a regular expression which matches a given string consisting of three non-negative, space-separated integers if and only if the last integer is the sum of the previous two. Answers may be for integers of any numeral system with radix between 2 and 10.
Test cases
These should fail:
0 1 2
10 20 1000

These should match:
10 20 30
28657 46368 75025
0 0 0

Rules
Your answer should consist of a single regex, without any additional code (except, optionally, a list of regex modifiers required to make your solution work). You must not use features of your language's regex flavour that allow you to invoke code in the hosting language (e.g. Perl's e modifier).
Please specify your regex flavour in your answer.
This is regex golf, so the shortest regex in bytes wins. If your language requires delimiters (usually /.../) to denote regular expressions, don't count the delimiters themselves. If your solution requires modifiers, add one byte per modifier.
Credits to Martin Ender and jaytea for the regex-golfing rules.

I have reason to believe it's possible based on the solution of Martin Ender for finding and incrementing integers with regex.

You can use any regex flavour which existed before this challenge this rule doesn't reflect current consensus, which says that languages (and therefore regex flavors) created or updated after the challenge has been posted can still compete.

Related. (I suspect answers to this will look somewhat similar to jimmy's .NET answer there.)

@EriktheOutgolfer really there is consensus that languages created after the challenge can COMPETE? That's totally nonsense

@edc65 As of half a year ago.

Perl 5's /e modifier only applies to substitutions, and is not the only way to run external code. Also this disqualifies Perl 6 entirely as a regex is just a method with additional syntax. (The reason is it makes regexes easier to read and write) As a result all of the features needed in archaic regexes aren't needed (or included) as you just put in Perl 6 code. (meaning it probably isn't possible to do this challenge if you just limit to regex specific code) /^(\d+)**3%' '$ <?{$0[2]==[+] $0[0,1]}>/ or /^(\d+)' '(\d+)' '(\d+)$ <?{$2==$0+$1}>/ or /^(\d+)' '(\d+){}" {$0+$1}"$/

Perl/PCRE: 2,685 bytes
^(?!(?!0*+(?=(\d*?)((?:(?=\d+ 0*+(\d*?)(\d(?(4)\4)) 0*(\d*?)(\d\6?+)$)\d)+) )(?=(?(?!\1(?:(?=\d+ 0*\3((\7?+)\d))(?=\d(\d* 0*\3\8))(?=0\9[9]|1\9[8]|2\9[7]|3\9[6]|4\9[5]|5\9[4]|6\9[3]|7\9[2]|8\9[1]|9\9[0])\d)*+(?=\d(\d* 0*\3\8?+))(?=[5-9]\10[5-9]|1\10[9]|2\10[89]|3\10[7-9]|4\10[6-9]|6\10[4]|7\10[34]|8\10[2-4]|9\10[1-4]))(?=\d+ \d+ 0*\1\3\6$)|(?(?!.*+\3)\d+ )(?=\d*(\2|\4)( .*?0*+)\d+$)(?(?=9*\11 )(?:9(?=\d*\12[1](\13?+0)))*?(?=\11 )\11\12[1]\13?+\6$|(?:(\d)(?=\d*\12(\15?+\14)))*(?=\d(\d*\12\15?+))(?=0\16[1]|1\16[2]|2\16[3]|3\16[4]|4\16[5]|5\16[6]|6\16[7]|7\16[8]|8\16[9])\d(?:9(?=\d*\12\15?+\d(\17?+0)))*?\11\12\15?+\d\17?+\6$)))\1(?:(?=(\d)\d* 0*+\3((\19?+)\d)\d* 0*+\5((\21?+)\d))(?=\d(\d* 0*+\3\20)\d(\d* 0*+\5\22))(?(?!\18(?:(?=\d+ 0*+\3\19((\25?+)\d))(?=\d(\d* 0*+\3\19\26))(?=0\27[9]|1\27[8]|2\27[7]|3\27[6]|4\27[5]|5\27[4]|6\27[3]|7\27[2]|8\27[1]|9\27[0])\d)*+(?=\d(\d* 0*+\3\19\26?+))(?=[5-9]\28[5-9]|1\28[9]|2\28[89]|3\28[7-9]|4\28[6-9]|6\28[4]|7\28[34]|8\28[2-4]|9\28[1-4]))(?=1\23(?:1\24[2]|2\24[3]|3\24[4]|4\24[5]|5\24[6]|6\24[7]|7\24[8]|8\24[9]|9\24[0])|2\23(?:1\24[3]|2\24[4]|3\24[5]|4\24[6]|5\24[7]|6\24[8]|7\24[9]|8\24[0]|9\24[1])|3\23(?:1\24[4]|2\24[5]|3\24[6]|4\24[7]|5\24[8]|6\24[9]|7\24[0]|8\24[1]|9\24[2])|4\23(?:1\24[5]|2\24[6]|3\24[7]|4\24[8]|5\24[9]|6\24[0]|7\24[1]|8\24[2]|9\24[3])|5\23(?:1\24[6]|2\24[7]|3\24[8]|4\24[9]|5\24[0]|6\24[1]|7\24[2]|8\24[3]|9\24[4])|6\23(?:1\24[7]|2\24[8]|3\24[9]|4\24[0]|5\24[1]|6\24[2]|7\24[3]|8\24[4]|9\24[5])|7\23(?:1\24[8]|2\24[9]|3\24[0]|4\24[1]|5\24[2]|6\24[3]|7\24[4]|8\24[5]|9\24[6])|8\23(?:1\24[9]|2\24[0]|3\24[1]|4\24[2]|5\24[3]|6\24[4]|7\24[5]|8\24[6]|9\24[7])|9\23(?:1\24[0]|2\24[1]|3\24[2]|4\24[3]|5\24[4]|6\24[5]|7\24[6]|8\24[7]|9\24[8])|0\23(\d)\24\29|(\d)\23[0]\24\30)|(?=1\23(?:0\24[2]|1\24[3]|2\24[4]|3\24[5]|4\24[6]|5\24[7]|6\24[8]|7\24[9]|8\24[0]|9\24[1])|2\23(?:0\24[3]|1\24[4]|2\24[5]|3\24[6]|4\24[7]|5\24[8]|6\24[9]|7\24[0]|8\24[1]|9\24[2])|3\23(?:0\24[4]|1\24[5]|2\24[6]|3\24[7]|4\24[8]|5\24[9]|6\24[0]|7\24[1]|8\24[2]|9\24[3])|4\23(?:0\24[5]|1\24[6]|2\24[7]|3\24[8]|4\24[9]|5\24[0]|6\24[1]|7\24[2]|8\24[3]|9\24[4])|5\23(?:0\24[6]|1\24[7]|2\24[8]|3\24[9]|4\24[0]|5\24[1]|6\24[2]|7\24[3]|8\24[4]|9\24[5])|6\23(?:0\24[7]|1\24[8]|2\24[9]|3\24[0]|4\24[1]|5\24[2]|6\24[3]|7\24[4]|8\24[5]|9\24[6])|7\23(?:0\24[8]|1\24[9]|2\24[0]|3\24[1]|4\24[2]|5\24[3]|6\24[4]|7\24[5]|8\24[6]|9\24[7])|8\23(?:0\24[9]|1\24[0]|2\24[1]|3\24[2]|4\24[3]|5\24[4]|6\24[5]|7\24[6]|8\24[7]|9\24[8])|9\23(?:0\24[0]|1\24[1]|2\24[2]|3\24[3]|4\24[4]|5\24[5]|6\24[6]|7\24[7]|8\24[8]|9\24[9])|0\23(?:0\24[1]|1\24[2]|2\24[3]|3\24[4]|4\24[5]|5\24[6]|6\24[7]|7\24[8]|8\24[9]|9\24[0])))\d)+\ |^0+\ 0*(\d+)\ 0*\g{-1}$|^0*(\d+)\ 0+\ 0*\g{-1}$)).+
Try it online!
I've been on the prowl for difficult challenges after a hiatus from regex, and just happened to stumble across this doozy. Verifying addition (with Perl/PCRE) is something I've thought about before, but promptly dismissed as either impossible or beyond my ability. However, I took another crack at it now and I'm quite thrilled to say that I've actually done it!
I didn't really golf this other than considering short algorithms and overall matching technique when I wrote it. I'm just really happy I got it done :D
If people are interested, I could add comments and explain how it works.
Edit: I made a detailed post on my blog about this, with explanations and comments :) enjoy: http://www.drregex.com/2018/09/a-regex-i-submitted-to-reddit-climbed.html

Definitely interested in some explanations !

@etene I edited the post with a link to a thorough write-up :D

Thank you, that will be an interesting read !

.NET flavour, 139 111 106 + 1 = 107 bytes
Needs the RightToLeft modifier r. Input in binary.
(?(2)!)^\5 \7 ((?(2)()(?(2)!)(?<-2>){2})(0|(?<-2>1))(?<=(((0|(?<2>1)|\b)(?=.*(?<=(\5).*))?\7?) \d*){2}))+$

Try it online! (Using Retina.)
Yay for balancing groups. I'll explain this later...
Decimal version, 340 243 + 1 = 244 bytes
(?(2)!)^\5 \7 ((?(2)()(?(2)!)(?<-2>){10})(0|(?<-2>1|(?<-2>2|(?<-2>3|(?<-2>4|(?<-2>5|(?<-2>6|(?<-2>7|(?<-2>8|(?<-2>9))))))))))(?<=(((0|(?<2>1|(?<2>2|(?<2>3|(?<2>4|(?<2>5|(?<2>6|(?<2>7|(?<2>8|(?<2>9)))))))))|\b)(?=.*(?<=(\5).*))?\7?) \d*){2}))+$

Try it online!

"I'll explain this later" How much later?

@Οurous much later as it turns out.

.NET, 96 bytes
^\4 \6((?(2)()(?(2)^)(?<-2>){2}| ?)(0|(?<-2>1))(?<=((0|(?<2>1)|)\4?) .*((0|(?<2>1)|)\6?) .*))+$

Flag: r
Try it online!
Decimal version, 238 bytes
^\5 \6(?<-6>)((?(2)()(?(2)^)(?<-2>){10}| ?)((?<-2>[1469]|(?<-2>[27]))|[0358])(?([5-9])(?<-2>){5})(?([3489])(?<-2>){3})(?<=(((((?=[5-9](?<2>){5}|)(?=[3489](?<2>){3}|)((?<2>[1469]|(?<2>[27]))|.))?(?( .*)\6?(?<-6>)?|\5?(?<-5>)))) .*){2}))+$

Flag: r
Try it online!
Similar to Martin's answer.

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


text:
Visualize Merge Sort
Merge sort is a sorting algorithm which works by splitting a given list in half, recursively sorting both smaller lists, and merging them back together to one sorted list. The base case of the recursion is arriving at a singleton list, which cannot be split further but is per definition already sorted.
The execution of the algorithm on the list [1,7,6,3,3,2,5] can be visualized in the following way:
       [1,7,6,3,3,2,5]
       /             \      split
   [1,7,6,3]       [3,2,5]
    /     \        /    \   split
 [1,7]   [6,3]   [3,2]  [5]
 /   \   /   \   /   \   |  split
[1] [7] [6] [3] [3] [2] [5]
 \   /   \   /   \   /   |  merge
 [1,7]   [3,6]   [2,3]  [5]
    \     /         \   /   merge
   [1,3,6,7]       [2,3,5]
       \             /      merge
       [1,2,3,3,5,6,7]

The Task
Write a program or function which takes a list of integers in any reasonable way as input and visualizes the different partitions of this list while being sorted by a merge sort algorithm. This means you don't have to output a graph like above, but just the lists are fine:
[1,7,6,3,3,2,5]
[1,7,6,3][3,2,5]
[1,7][6,3][3,2][5]
[1][7][6][3][3][2][5]
[1,7][3,6][2,3][5]
[1,3,6,7][2,3,5]
[1,2,3,3,5,6,7]

Furthermore, any reasonable list notation is fine, therefore the following would also be a valid output:
1 7 6 3 3 2 5
1 7 6 3|3 2 5
1 7|6 3|3 2|5
1|7|6|3|3|2|5
1 7|3 6|2 3|5
1 3 6 7|2 3 5
1 2 3 3 5 6 7

Finally, the way to split a list in two smaller lists is up to you as long as the length of both resulting lists differs at most by one. That means instead of splitting [3,2,4,3,7] into [3,2,4] and [3,7], you could also split by taking elements at even and odd indexes ([3,4,7] and [2,3]) or even randomize the split every time.
This is code-golf, so the shortest code in any language measured in bytes wins.
Test cases
As noted above, the actual format and the way to split lists in half is up to you.
[10,2]
[10][2]
[2,10]

[4,17,1,32]
[4,17][1,32]
[4][17][1][32]
[4,17][1,32]
[1,4,17,32]

[6,5,4,3,2,1]
[6,5,4][3,2,1]
[6,5][4][3,2][1]
[6][5][4][3][2][1]
[5,6][4][2,3][1] <- Important: This step cannot be [5,6][3,4][1,2], because 3 and 4 are on different branches in the the tree
[4,5,6][1,2,3]
[1,2,3,4,5,6]

Is it a requirement to actually implement merge sort, or only visualize it?

@JungHwanMin The program needs to be able to handle arbitrary integer lists, but you are not required to actually implement merge sort.

What's the difference between implementing and visualizing merge sort if at the end of the visualization you have a sorted list?

@dylnan You can use another sorting algorithm or a built in sort function to do the sorting...

Some golfing idea: the bottom half of the result can be generated by sorting each sublist in the first half and reversing the order.

is 321,3/21,3/2/1,23/1,123 allowed?

@JungHwan Min Just sort the whole array holding the spliting shuffle the array and cut by half

@Arnauld The [[1,2],[3],[4,5],[6]] stage is actually the correct solution, as merge sort is working recursively. That is if we start with [1,2,3,4,5,6] and split it into [1,2,3] and [4,5,6], then those lists are independently processed until they are merged in the final step.

@l4m2 Ok, final try for an answer: 1. you need delimiters because also integers >9 should be supported. 2. This is not valid for the same reason as given in my comment above. If we split into [3] and [2,1], then those are on different branches, so we can't merge [3] and [2] after [2,1] is split into [2] and [1].

Can the input be split into non-contiguous sublists? One answer seems to do that.

@Zgarb Finally, the way to split a list in two smaller lists is up to you as long as the length of both resulting lists differs at most by one. Does this answer your question or am I misunderstanding it?

In fact the sentence after that answers my question exactly. Sorry for missing that. :P

Few days ago there was a Jelly answer. Where is it now?

@jimifiki It was deleted because it did not work for some testcases, e.g.  [1,2,3,4,5,6]: Try it online!

Haskell, 137 128 127 125 121 109 106 bytes
(-2)+(-4)=(-6) bytes thanks to nimi! Changing it to collect all the steps in a list (again due to nimi) saves 12 more bytes.
Another 3 bytes due to Laikoni, with pattern guard binding and a clever use of list comprehension to encode the guard.
import Data.List
g x|y<-x>>=h=x:[z|x/=y,z<-g y++[sort<$>x]]
h[a]=[[a]]
h x=foldr(\x[b,a]->[x:a,b])[[],[]]x

Try it online!
Splitting the lists into the odd and the even positioned elements is a shorter code than into the two sequential halves, because we're spared having to measure the length, then.
Works by "printing" the lists, then recursing with the split lists (x >>= h) if there actually was any splitting done, and "printing" the sorted lists; starting with the one input list; assuming the non-empty input. And instead of actual printing, just collecting them in a list.
The list produced by g[[6,5..1]], printed line-by-line, is:
[[6,5,4,3,2,1]]
[[6,4,2],[5,3,1]]
[[6,2],[4],[5,1],[3]]
[[6],[2],[4],[5],[1],[3]]
[[2,6],[4],[1,5],[3]]
[[2,4,6],[1,3,5]]
[[1,2,3,4,5,6]]

... p=print and three times p. Try it online!

@nimi great, again, and many thanks! now it really looks golfed. :)

Instead of printing within function g you can collect all steps in a list and return it. Try it online!

@nimi this is sufficiently different, maybe you should post it as yours instead? and I'm never sure about the rules, isn't the mapM_ print essential part of the visualizing here and thus should be counted?

I don't think that we have a proper definition of "visualizing". More general the challenges asks for "outputting" the lists and per our defaults this can be done via a return value of a function. Other answers, e.g. 1, 2 do it this way, too. -- I don't think my suggestion is that much different, it just collects the intermediate lists instead of printing them. Feel free to edit it in.

Returning from a function instead printing is totally fine.

g x|y<-x>>=h=x:[z|x/=y,z<-g y++[sort<$>x]] saves some more bytes.

Wolfram Language (Mathematica), 146 127 111 102 bytes
Join[u=Most[#/.a:{_,b=__Integer}:>TakeDrop[a,;;;;2]&~FixedPointList~#],Reverse@Most@u/.a:{b}:>Sort@a]&

Try it online!
Returns a List that contains the steps.
Explanation
#/.a:{_,b=__Integer}:>TakeDrop[a,;;;;2]&

In an input, split all Lists containing 2 or more integers in half. The first sublist has the odd-indexed elements (1-indexed), and the second one has the even-indexed elements.
u=Most[... &~FixedPointList~#]

Repeat that until nothing changes (i.e. all sublists are length-1). Keep all intermediate results. Store this (the List of all steps) in u.
Reverse@Most@u

Drop the last element of u and reverse it.
... /.a:{b}:>Sort@a

From the result above, sort all occurrences of a list of integers.

Clean, 228 206 168 157 140 121 104 bytes
Builds the list of stages from the ends inwards, using the fact that the n-th element from the end is the sorted version of the n-th element from the beginning.
Idea from JungHwan Min's comment
import StdEnv
@u#(a,b)=splitAt(length u/2)u
=if(a>[])[[u]:[x++y\\y<- @b&x<- @a++ @a++ @a]][]++[[sort u]]

Try it online!

Charcoal, 145 133 123 122 bytes
≔⟦⪪Ｓ ⟧θＷ⊖Ｌ§θ⁰«⟦⪫Ｅθ⪫κ ¦|⟧≔ＥＥ⊗Ｌθ§θ÷λ²✂κ﹪λ²Ｌκ²θ»⟦⪫ΦＥθ⪫ι ι|⟧Ｗ⊖Ｌθ«≔⮌θη≔⟦⟧θＷη«≔⊟ηε≔⟦⟧ζＦ⊟η«≔εδ≔⟦⟧εＦδ⊞⎇‹ＩμＩλζεμ⊞ζλ»⊞θ⁺ζε»⟦⪫Ｅθ⪫κ ¦|

Try it online! Link is to verbose version of code. Still having to work around Charcoal bugs... Edit: Saved 5 bytes by using a double Map as a poor man's array comprehension. Saved 4 bytes by using Pop to double iterate over an array. Saved 3 bytes by using concatenation instead of Push. Saved 10 bytes by coming up with a golfier while condition that also avoids a Charcoal bug. Saved 1 byte by discovering that Charcoal does indeed have a filter operator. Explanation:
≔⟦⪪Ｓ ⟧θ

Split the input on spaces, and then wrap the result in an outer array, saving that to q.
Ｗ⊖Ｌ§θ⁰«

Repeat while the first element of q has more than one element. (The first element of q always has the most elements because of the way the lists are divided into two.)
⟦⪫Ｅθ⪫κ ¦|⟧

Print the elements of q joined with spaces and vertical lines. (The array causes the result to print on its own line. There are other ways of achieving this for the same byte count.)
≔ＥＥ⊗Ｌθ§θ÷λ²✂κ﹪λ²Ｌκ²θ»

Create a list by duplicating each element of q, then map over that list and take half of each list (using the alternate element approach), saving the result back in q.
⟦⪫ΦＥθ⪫ι ι|⟧

Print the elements of q joined with spaces and vertical lines. Actually, at this point the elements of q are either empty or single-element lists, so joining them just converts them to empty strings or their elements. The empty strings would add unnecessary trailing lines so they are filtered out. A flatten operator would have been golfier though (something like ⟦⪫Σθ|⟧).
Ｗ⊖Ｌθ«

Repeat while q has more than one element. (The following code requires an even number of elements.)
≔⮌θη≔⟦⟧θ

Copy q to h, but reversed (see below), and reset q to an empty list.
Ｗη«

Repeat until h is empty.
≔⊟ηε

Extract the next element of h into e. (Pop extracts from the end, which is why I have to reverse q.)
≔⟦⟧ζ

Initialise z to an empty list.
Ｆ⊟η«

Loop over the elements of the next element of h.
≔εδ≔⟦⟧ε

Copy e to d and reset e to an empty list.
Ｆδ

Loop over the elements of d.
⊞⎇‹ＩμＩλζεμ

Push them to z or e depending on whether they are smaller than the current element of the next element of h.
⊞ζλ»

Push the current element of the next element of h to z.
⊞θ⁺ζε»

Concatenate z with any elements remaining in e and push that to q. This completes the merge of two elements of h.
⟦⪫Ｅθ⪫κ ¦|

Print the elements of q joined with spaces and vertical lines.

Hang on. There's another bug? :/

@ASCII-only No, this was the while (...Map(...)...) bug I already told you about.

Python 2, 145 144 bytes
Idea from JungHwan Min's comment
-1 byte thanks to Jonathan Frech

p=input()
l=[[p]]
i=0
while 2**i<len(p):l[i+1:i+1]=[sum([[x[1::2],x[::2]][len(x)<2:]for x in l[i]],[]),map(sorted,l[i])];i+=1
for s in l:print s

Try it online!

I am not entirely sure, though you may be able to use <2 instead of ==1.

Husk, 14 bytes
S+ȯ†O↔hUmfL¡ṁ½

Takes an array containing a single array.
Try it online!
Explanation
S+ȯ†O↔hUmfL¡ṁ½  Implicit input, say A = [[4,17,32,1]].
           ¡    Iterate this function on A:
            ṁ½   Split each array in two, concatenate results: [[4,17],[32,1]]
                Result is [[[4,17,32,1]],
                           [[4,17],[32,1]],
                           [[4],[17],[32],[1]],
                           [[4],[],[17],[],[32],[],[1],[]],
                           ...
        mfL     Map filter by length, removing empty arrays.
                Result is [[[4,17,32,1]],
                           [[4,17],[32,1]],
                           [[4],[17],[32],[1]],
                           [[4],[17],[32],[1]],
                           ...
       U        Longest prefix of unique elements:
                       P = [[[4,17,32,1]],[[4,17],[32,1]],[[4],[17],[32],[1]]]
      h         Remove last element: [[[4,17,32,1]],[[4,17],[32,1]]]
     ↔          Reverse: [[[4,17],[32,1]],[[4,17,32,1]]]
   †O           Sort each inner array: [[[4,17],[1,32]],[[1,4,17,32]]]
S+ȯ             Concatenate to P:
                           [[[4,17,32,1]],
                            [[4,17],[32,1]],
                            [[4],[17],[32],[1]],
                            [[4,17],[1,32]],
                            [[1,4,17,32]]]
                Implicitly print.

The built-in ½ takes an array and splits it at the middle.
If its length is odd, the first part is longer by one element.
A singleton array [a] results in [[a],[]] and an empty array [] gives [[],[]], so it's necessary to remove the empty arrays before applying U.

JavaScript (ES6), 145 bytes
f=a=>a.join`|`+(a[0][1]?`
${f([].concat(...a.map(b=>b[1]?[b.slice(0,c=-b.length/2),b.slice(c)]:[b])))}
`+a.map(b=>b.sort((x,y)=>x-y)).join`|`:``)

Takes input as an array within an array, i.e. f([[6,5,4,3,2,1]]). Works by generating the first and last lines of the output, then splitting and calling itself again, until every sub-array has length 1. Here's a basic demonstration of how it works:
f([[6,5,4,3,2,1]]):
  6,5,4,3,2,1
  f([[6,5,4],[3,2,1]]):
    6,5,4|3,2,1
    f([[6,5],[4],[3,2],[1]]):
      6,5|4|3,2|1
      f([[6],[5],[4],[3],[2],[1]]):
        6|5|4|3|2|1
      end f
      5,6|4|2,3|1
    end f
    4,5,6|1,2,3
  end f
  1,2,3,4,5,6
end f

So, was there a point where there were three answers tied on 145 bytes?

Stax, 116(÷3>) 38 29 bytesCP437
-9 bytes per comment by @recursive. Now the input is given as a singleton whose only element is an array of the numbers to be sorted.
ƒ3s}óºE/ßB╢↕êb∩áαπüµrL╞¶è,te+

Try it online!
Unpacked version with 35 bytes:
{c{Jm'|*Pc{2Mm:f{fc{Dm$wW{{eoJm'|*P

Explanation
The code can be splitted to two parts. The first part visualizes splitting and the second visualizes merging.
Code for visualizing splitting:
{                      w    Do the following while the block generates a true value
 c                          Copy current nested array for printing
  {Jm                       Use spaces to join elements in each part
     '|*                    And join different parts with vertical bar
        P                   Pop and print

         c                  Copy current nested array for splitting
          {2Mm              Separate each element of the array to two smaller parts with almost the same size
                                That is, if the number of elements is even, partition it evenly.
                                Otherwise, the first part will have one more element than the second.
              :f            Flatten the array once
                {f          Remove elements that are empty arrays

                  c         Copy the result for checking
                   {Dm$     Is the array solely composed of singletons?
                            If yes, ends the loop.

The code for visualizing merging:
W              Execute the rest of the program until the stack is empty
 {{eoJm        For each part, sort by numeric value, then join with space
       '|*     Join the parts with vertical bar
          P    Pop and print the result

Old version, actually building the nested list structure.
{{cc0+=!{x!}Mm',*:}}Xd;%v:2^^{;s~{c^;<~sc%v,*{2M{s^y!svsm}M}YZ!x!Q,dmU@e;%v:2^{;%v:2^-N~0{c;={scc0+=Cc%v!C:f{o}{scc0+=C{s^y!svsm}?}Y!cx!P,dcm

cc0+= is used thrice in the code to check whether the top of stack is a scalar or an array.
{{cc0+=!{x!}Mm',*:}}X builds a block that recursively calls itself to output a nested array of numbers properly. (Default output in Stax vectorizes a nested array before printing).
{                  }X    Store the code block in X
 {           m           Map each element in the list with block
  cc                     Make two copies of the element
    0+                   + 0. If the element is a scalar, nothing will change
                              If the element is an array, the element 0 will be appended
      =!{  }M            If the element has changed after the `0+` operation
                             Which means it is an array
         x!              Recursively execute the whole code block on the element

              ',*        Join the mapped elements with comma
                 :}      Bracerizes the final result

There are two other blocks that performs the splitting and the merging, respectively. They are too verbose and I don't care to explain (there are a little bit more information in the historical version of this post but don't expect too much).

Very nice improvement.  I don't totally understand it yet, but I think cH! can be used in place of cH%!.

{Nd}M can be replaced by T also.

I made some more adaptations.  https://staxlang.xyz/#c=%C6%923s%7D%C3%B3%C2%BAE%2F%C3%9FB%E2%95%A2%E2%86%95%C3%AAb%E2%88%A9%C3%A1%CE%B1%CF%80%C3%BC%C2%B5rL%E2%95%9E%C2%B6%C3%A8%2Cte%2B&i=%5B%5B6%2C5%2C4%2C3%2C2%2C1%5D%5D%0A%5B%5B10%2C2%5D%5D%0A%5B%5B4%2C17%2C1%2C32%5D%5D&a=1&m=2
The Husk answer takes input as an array in an array, so I guess that's legal.

I found a solution that should be 2 ascii characters shorter, but I discovered a bug in array transpose.  Specifically, it mutates the array rows.  I'll add it to the backlog for 1.0.4

OK. I look forward to the update.


text:
Sample the Pareto Distribution
The Pareto Distribution is a probability distribution that comes up a lot in nature. It has lots of special properties, such as an infinite mean. In this challenge, you will output a number sampled from this distribution.
The Pareto Distribution is defined to be greater than or equal to x with probability 1/x, for all x greater than or equal to 1.
Therefore, a number sampled from this distribution is greater than or equal to 1 with probability 1, greater than or equal to 2 with probability exactly 1/2, greater than or equal to 3 with probability exactly 1/3, greater than or equal to 11.4 with probability exactly 1/11.4, and so on.
Since you will sample this distribution, your program or function will take no input, and output a random number, with the above probabilities. However, if your program doesn't perfectly match the above probabilities due to floating-point impression, that's OK. See the bottom of the challenge for more details.
(This is called the Pareto Distribution with alpha 1 and lower bound 1, to be exact)
Here's 10 example draws from this distribution:
1.1540029602790338
52.86156818209856
3.003306506971116
1.4875532217142287
1.3604286212876546
57.5263129600285
1.3139866916055676
20.25125817471419
2.8105749663695208
1.1528212409680156

Notice how 5 of them are below 2, and 5 are above 2. Since this is the average result, it could have been higher or lower, of course.
Your answer only needs to be correct up to the limits of your floating point type, real number type, or whatever else you use, but you must be able to represent numbers at at least 3 decimal digits of precision, and represent numbers up to 1,000,000. If you're not sure whether something is OK, feel free to ask.
This is code golf.

Details about imprecision:

For each range [a, b], where 1 <= a < b, the ideal probability that the sample would fall in that range is 1/a - 1/b. The probability that your program produces a number in that range must be with 0.001 of 1/a - 1/b.  If X is the output of your program, it is required that |P(a <= X <= b) - (1/a - 1/b)| < 0.001.
Note that by applying the above rule with a=1 and b sufficiently large, it is the case that your program must output a number greater than or equal to 1 with at least probability 0.999. The rest of the time it may crash, output Infinity, or do whatever else.

I'm fairly certain that the existing submissions of the form 1/1-x or 1/x, where x is a random float in [0, 1) or (0, 1) or [0, 1], all satisfy this requirement.

Let us continue this discussion in chat.

Note to everyone: issacg has added some rules that allow some imprecisions, therefore most answers here are longer than necessary. [sorry for comment abuse too, but that is what would happen when OP change question significantly]

MATL, 3 bytes
1r/

Try it online! Or estimate the resulting probabilities by running it 10000 times.
Explanation
1    % Push 1
r    % Push random number uniformly distributed on the open interval (0,1)
/    % Divide. Implicitly display

After the clarification and edit in the OP, this answer conforms to the rules of the challenge

Actually, 4 bytes
G1-ì

Try it online!
Explanation:
G1-ì
G     random()
 1-   1-random()
   ì  1/(1-random())

R, 10 bytes
1/runif(1)

Pretty straightforward.

Note that runif never returns 0 or 1 in the default case so there are no problems with this.

Yes, thanks. And I didn't thought of it when entering this answer but you can indeed verify the distribution if needed.

This doesn't work - a Pareto distribution produces 1 with positive probability. Since runif(1) won't ever produce a 1, 1/runif(1) will never be 1.

@Mego that is incorrect. The Pareto distribution is absolutely continuous and thus has measure 0 for any number.

@Therkel Theoretically, yes. However, because we are in the realm of floats, it's a discrete distribution over the set of floats in [1, +Inf).

@Mego Am I misreading OP "This random number must be above 1 with probability 1"?

@plannapus I commented on the OP with a request for clarification. By the definition of a Pareto distribution with x_m = alpha = 1, the support (the range for which the probability density function has positive values, aka the possible outputs for the distribution) is [1, +Inf).

@Mego OK that may be quicksand for me (given i know close to nothing about floating point), but i actually think that while the probability of runif giving 1 is null, the probability of 1/runif to give 1 is not, because of floating point accuracy (i. e. typically 1/0.9999999 returns 1 in R).

@plannapus Hmm... That's a good point. Floats make this entirely too complicated.

@Mego 1 must appear with probability zero: The Pareto Distribution is defined to be above x with probability 1/x, for all x greater than or equal to 1. i.e., Pr(X>x)=1/x which implies Pr(X>1)=1, and in turn Pr(X==1)=0.

@Giuseppe For any continuous distribution, Pr(X=x) = 0. That is not the same thing as "x will never be output". However, since we're working with floats, this is a discrete distribution, and so all floats x in [1, +Inf) have Pr(X=x) > 0.

TI-Basic, 2 bytes
rand^-1      (AB 0C in hex)

For anyone who is wondering, rand returns a random value in (0,1]. "Due to specifics of the random number generating algorithm, the smallest number possible to generate is slightly greater than 0. The largest number possible is actually 1 ..." (source). For example, seeding rand with 196164532 yields 1.

Strangely, the equivalent code wouldn't work on a TI-89 series calculator. Even though their random number generators are nearly identically implemented, a TI-89 will return 0 whenever a TI-83+ would return 0.99999999999889.

TI-Basic developers knew in advance this challenge will happen...? It seems to win this time.

@user202729 Avoiding 0 and 1 makes rand more useful as a subroutine for the calculator's other commands, which is probably why TI made this design decision. For example, randNorm(0,1 returns -7.02129... with seed 196164532. Using the RNG algorithm without the adjustment would give a value of 1e99, which is an unreasonable value for a normally-distributed variable to have.

@user202729 Yeah, actually I just time traveled a bit to get it all done. Definitely worth it for these upvotes.

R, 12 bytes
exp(rexp(1))

Try it online!
Verify the distribution
This takes a different approach, exploiting the fact that if Y~exp(alpha), then X=x_m*e^Y is a Pareto with parameters x_m,alpha. Since both parameters are 1, and the default rate parameter for rexp is 1, this results in the appropriate Pareto distribution.
While this answer is a fairly R- specific approach, it's sadly less golfy than plannapus'.
R, 14 bytes
1/rbeta(1,1,1)

Try it online!
Even less golfy, but another way of getting at the answer.
Another property of the exponential distribution is that if X ~ Exp(λ) then e^−X ~ Beta(λ, 1), hence 1/Beta(1,1) is a Pareto(1,1).
Additionally, a keen observer would recall that if X ~ Beta(a,b) and a=b=1, then X~Unif(0,1), so this truly is 1/runif(1).

I have no idea. But the reality is, there is a huge confusion about what is allowed and what is not on this challenge.

@user202729 that's fair, but those who have been raising concerns with regards to that would at least have commented, so the downvote is (in my opinion) unlikely to be related to that. EDIT: mystery downvoter has removed the downvote.

I downvoted because I thought using R on a challenge like this was trivial, but I was a little trigger-happy. I realize that this uses a different method than most of the other answers, so I removed my downvote.

@KSmarts The "trivial" answer in R wasn't used by anybody actually: actuar::rpareto(1,1,1), because it is longer :)

For info, there are ca. 20 distributions hard-coded in base R, but Pareto is not one of them, hence the need to either use a work-around or an additional package.

@KSmarts ah, thanks. It would have been trivial if R had a pareto distribution built-in, but apparently the developers didn't feel the need to include one, since this is a perfectly good workaround, for anyone who bothers to learn distributions. :)

Charcoal, 10 bytes
Ｉ∕Ｘφ²⊕‽Ｘφ²

Try it online!
Link is to the verbose version:
Print(Cast(Divide(Power(f, 2), ++(Random(Power(f, 2))))));

Comments:

Charcoal only has methods to get random integer numbers, so in order to get a random floating-point number between 0 and 1 we have to get a random integer between 0 and N and divide by N.
Previous version of this answer that used the 1/(1-R) formula: In this case, N is set to 1000000 as the OP asks it to be the minimum. To get this number Charcoal provides a preset variable f=1000. So just calculating f^2 we get 1000000. In the event that the random number is 999999 (the maximum), 1/(1-0.999999)=1000000.
Neil's tip (saving 3 bytes): If I have 1/(1-R/N) where R is a random number between 0 and N, it is the same as just calculate N/(N-R). But considering that the random integers N-R and R have the same probability to occur, that is the same as just calculating N/R (being R in this last case a number between 1 and N inclusive to avoid division by zero).

10 bytes

@Neil please wait a moment while I try to understand what your code does... :-)

Actually I don't need MapAssignRight any more, 10 bytes! works.

@Neil assimilation of your code completed! Answer edited. :-D

Mathematica, 10 bytes
1/Random[]

Try it online!
-4 bytes from M.Stern

This may be invalid...

This has the potential to fail, because RandomReal outputs a real number in the closed range [0, 1]. Thus, division by 0 is possible. You’ll need to manipulate the random value in order to remove that possibility.

@Mego where exactly did you find that info?

@Jenny_mathy The linked Mathematica.SE question in the first comment.

@Mego what is the probability to get 0?

Jenny_mathy: According to the proposal on meta, the burden of proof should be on the person claiming to have a valid answer - it's your work to prove that it's valid, not to ask @Mego to provide an invalid test case. Also because float are discrete the probability to get 0 is nonzero.

@Jenny_mathy Mathematica uses floating-point numbers for Reals, according to the documentation. The precision of the floats is unspecified, but assuming double-precision (the norm for many langauges), there is a 1/(2^62 - 2^52 - 1) = 1/4607182418800017407 chance of failure (as I computed in chat). The reason this answer appears singled out is because other answers that use randoms from [0, 1] have been fixed already (like the JS one). I've commented on all others that can fail to my knowledge.

Let us continue this discussion in chat.

Back to the topic, I do not believe there is a possibility of getting a zero using this function.  Mathematica will in fact produce numbers less than $MinMachineNumber.  Try this: Table[RandomReal[{0, $MinMachineNumber}], 100].  Turns out Mathematica is smart enough to abandon machine numbers and switch over to arbitrary precision numbers.  LOL.

Min@Table[RandomReal[{0,$MinMachineNumber}],10^7] yields 3.750405396*10^-315

What do you think about Random? It's superseded but still working.

Haskell, 61 56  bytes
The function randomIO :: IO Float produces random numbers in the interval [0,1), so transforming them using x -> 1/(1-x) will produce pareto realizations.
import System.Random
randomIO>>=print.(1/).((1::Float)-)

Try it online!

Moving the type annotation saves a few bytes: randomIO>>=print.((1::Float)/)

And as functions are allowed, I'd say you can drop the main=.

Appranetly the range is [0,1) according to this answer

@flawr Whoops, you're right! I forgot how floats work temporarily.

Well anyway, thanks for commenting, I would not have had any idea:)

Excel, 9 bytes
=1/rand()

Yay, Excel is (semi-)competitive for a change!

Also works in LibreOffice Calc :)

You can change this to google sheets for -1 Bytes (=1/Rand()

Ruby, 14 8 bytes
p 1/rand

Trivial program, I don't think it can get any shorter.

Note to everyone: issacg has added some rules that allow some imprecisions, therefore most answers here are longer than necessary.

Excel VBA, 6 Bytes
Anonymous VBE immediate window function that takes no input and outputs to the VBE immediate window
?1/Rnd

JavaScript REPL, 15 19 bytes
1/Math.random()

This will not yield correct results if Math.random() returns 0

Probably 1/(1-Math.random())?

Fixed using u*29's solution

You need _=> at the start to make this a function; snippets aren't allowed.

It's a full program using console running

@Mr. Xcoder be above x with probability 1/x the 'above' not sure if include itself. If not when rnd=0 it return Inf, seems allowed

@l4m2 According to the definition of a Pareto distribution, the support is [1, +Inf). Therefore, all reals >= 1 must have a positive probability.

Changed back ^^^

Python, 41 bytes
lambda:1/(1-random())
from random import*

Try it online!

Using the builtin is actually longer:
Python, 43 bytes
lambda:paretovariate(1)
from random import*

Try it online!
Both solutions work in both Python 2 and Python 3.

Full programs are shorter for tasks which don't use input, using print saves a byte.

J, 5 bytes
%-.?0

How ot works:
?0 generates a random value greater than 0 and less than 1
-. subtract from 1
%  reciprocal
Try it online!

Note to everyone: issacg has added some rules that allow some imprecisions, therefore most answers here are longer than necessary.

Japt, 6 bytes
1/1-Mr is the same length but this felt a little less boring!
°T/aMr

Try it

Explanation
Increment (°) zero (T) and divide by (/) its absolute difference (a) with Math.random().

Note to everyone: issacg has added some rules that allow some imprecisions, therefore most answers here are longer than necessary.

Red, 19 bytes
1 /(1 - random 1.0)

Try it online!

Note to everyone: issacg has added some rules that allow some imprecisions, therefore most answers here are longer than necessary.

Java 8, 22 18 bytes
v->1/Math.random()

(Old answer before the rules changed: v->1/(1-Math.random()))
Try it here.

APL (Dyalog), 5 bytes
÷1-?0

Try it online!
How?
 ÷   1-     ?0
1÷  (1-  random 0..1)

Note to everyone: issacg has added some rules that allow some imprecisions, therefore most answers here are longer than necessary.

Jelly, 5 bytes
Jelly also doesn't have random float, so this uses x/n where x is an random integer in range [1, n] (inclusive) to emulate a random float in range (0, 1]. In this program n is set to be 108.
ȷ8µ÷X

Try it online!
Explanation
ȷ8     Literal 10^8.
  µ    New monad.
   ÷   Divide by
    X  random integer.

Enlist, 3 bytes
ØXİ

Try it online!
Enlist beats Jelly! (TI-Basic not yet)
Explanation
  İ    The inverse of...
ØX     a random float in [0, 1)

Of course this has nonzero probability of take the inverse of 0.

Would the Enlist solution not fail if ØX returned 0? (Disclaimer: I don't know Enlist at all!)

@Shaggy your program must output a number greater than or equal to 1 with at least probability 0.999. The rest of the time it may crash (from the challenge rules)

IBM/Lotus Notes Formula, 13 bytes
1/(1-@Random)

Sample (10 runs)

Note to everyone: issacg has added some rules that allow some imprecisions, therefore most answers here are longer than necessary.

Not sure I could make this much shorter whatever rule changes are made :)

Pyt, 2 bytes
ṛ⅟

Explanation:
ṛ           Random number in [0,1)
 ⅟          Multiplicative inverse
            Implicit print

Try it online!

Pyth, 4 bytes
c1O0

Try it here!
Alternative: c1h_O0.

c1tOZ is 5, does it not work?

@Dave Doesn’t work, that returns negative values. I need 1-n not n-1

Does Pyth not have a constant for 100?

@Shaggy I wish it did. Unfortunately, no constant for 100 AFAIK

J, 9 Bytes
p=:%@?@0:

I couldn't figure out how to make it take no input, since p=:%?0 would evaluate immediately and remain fixed. Because of this its sort of long.
How it works:
p=:        | Define the verb p
       0:  | Constant function. Returns 0 regardless of input.
     ?@    | When applied to 0, returns a random float in the range (0,1)
   %@      | Reciprocal

Evaluated 20 times:
    p"0 i.20
1.27056 1.86233 1.05387 16.8991 5.77882 3.42535 12.8681 17.4852 2.09133 1.82233 2.28139 1.58133 1.79701 1.09794 1.18695 1.07028 3.38721 2.88339 2.06632 2.0793

Clean, 91 bytes
import StdEnv,Math.Random,System.Time
Start w=1.0/(1.0-hd(genRandReal(toInt(fst(time w)))))

Clean doesn't like random numbers.
Because the random generator (a Mersenne Twister) needs to be given a seed, I have to take the system timestamp to get something that differs passively per-run, and to do anything IO-related I need to use a whole Start declaration because it's the only place to obtain a World.
Try it online!


text:
Declare a Code Golf Winner
Normally, I'd open with some flavor text here about being bored and/or lazy but looking through the stack-exchange-api questions that would be far from original. So instead I'm going to open with a meta and self-referential flavor text describing this lack of originality that then describes itself and how meta and self-referential it is.
Challenge
Write a program that takes in the ID for some question on PPCG, and uses the SE API to grab the answers and select the winner.
You may assume that it is a code-golf question, and the following answer format:
# Language, [<s>XXX</s>] YYY bytes

[Thanks to @user1 for saving XX bytes!]
[Thanks to @user2 for saving YY bytes!]

print "badly formatted but easier to tally like this"

To clarify:

It might have 1 or more attributions or crossed out past scores, and it might not.
The attributions and crossed-out scores are not necessarily correlated; one can appear without the other.
If there are no attributions, then the code will start 2 newlines after the heading.

Anyway, you can either extract the length in the beginning or count the length of the code at the end. For the former, only use the last score. For the latter, don't count the attributions. You can assume that the two will match up.
Your program should spit out the ID for the answer with the fewest bytes. Your program should also do this in the fewest bytes possible, as the shortest answer in bytes will win.
Note: yes, I have seen Write code to determine the accepted answer, but that challenge has submissions voting on the winner whereas this is code golf with a specific task and an explicit winner independent of other answers.

@Mr.Xcoder if there aren't any answers, then you can return falsey or error.

Sandbox.

Can you please add some test cases (as pointed out in the sandbox, a comment you might have chosen to ignore) --- Might be somewhat hard, because nearly no answers use that format, given that Try it online! or Explanation... are usually among the last lines?

@Mr.Xcoder and they're formatted. Actually, I'd suggest just replacing the request with STDIN on your TIO links.

Will we have to handle bytes being a link? (codepage)

@RecursiveCo. No, you don't have to.

JavaScript, 283 bytes
n=>fetch(`https://api.stackexchange.com/2.2/questions/${n}/answers?site=codegolf&filter=!*SU8CGYZitCB.D*(BDVIficKj7nFMLLDij64nVID)N9aK3GmR9kT4IzT*5iO_1y3iZ)6W.G*`).then(r=>r.json()).then(s=>alert(s.items.sort((a,b)=>(g=s=>s.match(/\d+(?= bytes)/)[0])(a.body)-g(b.body))[0].answer_id))

Run on a subdomain of stackexchange.com.

You're allowed to run on api.stackexchange.com - there's a meta post somewhere.


text:
String Permutations - case and order
Challenge
For any string that is composed of alphabetical characters of any case, make a function that returns a list of all of it's variations, order and case-wise empty strings returns empty list.
Test Cases

"" -> []
"a" -> ['a', 'A']
"ab" -> ['ab', 'Ab', 'aB', 'AB', 'ba', 'Ba', 'bA', 'BA']
"abc" -> ['abc', 'Abc', 'aBc', 'ABc', 'abC', 'AbC', 'aBC', 'ABC', 'bac', 'baC', 'bAc', 'bAC', 'Bac', 'BaC', 'BAc', 'BAC', 'CBa', 'CBA', 'cba', 'cbA', 'cBa', 'cBA', 'Cba', 'CbA', 'caB', 'cAb', 'cAB', 'cab', 'CaB', 'CAb', 'CAB', 'Cab', 'Acb', 'AcB', 'acb', 'acB', 'aCb', 'aCB', 'ACb', 'ACB', 'Bca', 'BcA', 'bca', 'bcA', 'bCa', 'bCA', 'BCa', 'BCA']
'aa' -> ['aa', 'Aa', 'aA', 'AA']  (for duplicate letters extra, duplicate permutations are allowed if necessary)
As the permutations rack up quickly you only need to handle up to 4 ASCII letter chars.
This is code-golf, so the shortest code in bytes wins!

Why is this getting reopen votes? It's an exact dupe...

This uses place variation too

A couple questions. What should the input 'aa' give? Also, for the output format, since each permutation is of known length, do we need delimiters between all of them?

This seems like a combination of two problems, permutations and case-variants lol

I still don’t understand why people want this closed.

@dylnan I will let the answerer decide that, but  aa, aA, Aa, and AA are required

Python 2, 89 bytes
lambda s:map(list,map(permutations,product(*zip(s.swapcase(),s))))
from itertools import*

Try it online!
Doesn't work in Python 3. Swap case idea from HyperNeutrino.

You can golf this a tad with replacing "list" with "set".  Uglier output, but it works fine.

Jelly, 9 bytes
żŒsp/Œ!€Ẏ

Try it online!
Explanation
żŒsp/Œ!€Ẏ  Main Link
ż          zip each character with
 Œs        its case swapped
   p/      reduce over cartesian product
       €   for each sublist
     Œ!    find all permutations
        Ẏ  flatten by one layer

Lol I always get beat by a lot on my 12+ byte answers. Although if you're not doing ŒṘ or removing duplicates I might take mine out...

@dylnan I personally think that's unecessary. OP didn't specify so just leave it out unless OP specifies :P

Updated! @dylnan

Jelly, 11 bytes
Œu,ŒlZŒpŒ!€

Try it online!
16 bytes if we need formatting and no repeated permutations.
Œu,ŒlZŒpŒ!€;/QŒṘ

Try it online!
This is assuming (a) we need delimiters between the permutations (achieved by ŒṘ at the end) and (b) the input 'aa'-->['AA','Aa','aA','aa'] and doesn't count the two 'a's as unique, which would give the same answer but each permutation would appear twice.
Explanation
Œu,ŒlZŒpŒ!€;/QŒṘ   Main link
Œu                 Upper case. 'aB'->'AB'
   Œl              Lower case. 'aB'->'ab'
  ,                Pair dyad. -> [['A','B'],['a','b']]
     Z             Zip the columns. -> [['A','a'],['B','b']]
      Œp           Cartesian product of the elements in the outermost list. -> [['A','B'],['A','b'],['a','B'],['a','b']]
        Œ!€        The permutations applied at €ach element in the list. -> [[['A','B'],['B','A']],[['A','b'],...
                   The rest is deleting duplicates and formatting.
           ;/      Concatenates the lists of permutations. In Essentially flattens the list by one level.
             Q     Remove repeated elements
              ŒṘ   Print in Python's string format

JavaScript (ES6), 169 bytes
I/O format: arrays of characters.
a=>(r=[],P=(a,m=[])=>a.map((_,i)=>P(b=[...a],[...m,...b.splice(i,1)]))>[]||(g=i=>i>>m.length||g(-~i,r.push(m.map((c,j)=>c[`to${i>>j&1?'Upp':'Low'}erCase`]()))))())(a)&&r

Not the right tool for the job... Still, there's probably a golfier way.
Demo

let f =

a=>(r=[],P=(a,m=[])=>a.map((_,i)=>P(b=[...a],[...m,...b.splice(i,1)]))>[]||(g=i=>i>>m.length||g(-~i,r.push(m.map((c,j)=>c[`to${i>>j&1?'Upp':'Low'}erCase`]()))))())(a)&&r

f([...'abc']).forEach(a => console.log(a.join('')))


text:
Make a Plain PIE!
(2 Jan 2018) Because of the winning criteria I am going to accept the Jelly answer, but I am also giving upvotes to all other answers which all use astounding methods as well
Introduction
There are lots of challenges asking for a shortest program to calculate mathematical constants. I saw some with restrictions like banning the literals 3.14 and π etc. However, there seems no such challenges using the number of distinct characters as one of the criteria.
The Challenge
Make a Plain PIE using the fewest kinds and least amount of ingredients but still yummy enough
Write a code that calculates π*e to at least 10 decimal places, that uses as FEW distinct characters (and de facto numeric literal characters) and as short as possible.
This challenge is not banning numeric literals; instead they are discouraged. Numeric literals are seasonings ;)
Requirements

The code must be a full program receiving no inputs and outputting the result, or a function which can be called with no arguments either outputting or returning the result. Lambdas are allowed.
The result must start with 8.5397342226 and must be in a numeric type. There should only be one output/return in the main program/function. Sub-functions are allowed.

Restrictions

String-to-number conversion functions that trivially turn the string literal to a number it represents are not allowed unless explicitly declared and implemented within the code. Also, NO implicit conversions from strings to numbers.

eg. eval, Number(), parseInt() and "string" * 1
Character-code functions and length functions like ord, String.charCodeAt(n) and String.length are allowed because they do not trivially convert the string into the corresponding number.

Use of the following built-ins are not allowed:

Mathematical constants, or any built-in functions that evaluates to those constants directly

eg. Math.PI in JS, žs in 05AB1E (because it evaluates to π directly)

Trigonometric functions and the exponential function, unless explicitly defined and implemented in the code.

eg. Math.atan and Math.exp in JS
Built-in power functions and exponentiation operators (eg. ** or ^) are allowed, given that they receive 2 arguments/operands (WLOG a and b) and returns ab

The length of each run of numeric literal used must not be longer than 5 (eg. 12345 allowed (but not encouraged), but 123456 is not allowed).
Standard loopholes apply.

Scoring

The scoring is divided into three parts:

Distinctness: Scored by counting the number of distinct characters used. Uppercase and lowercase are counted separately. However, the following characters must each be counted as 10 characters:

Hexadecimal digits: 0123456789abcdefABCDEF
Decimal points: .
Any other single characters that may be used as numeric literals (applicable in golfing languages)

Size: Scored by the length of the code in bytes.
Accuracy: Scored by the number of correct digits counting from the decimal point. Any digits after the first wrong digit are not counted. For fairness, a maximum of 15 digits are counted. The value of π*e according to WolframAlpha is 8.539734222673567(06546...).

The total score is calculated by (Distinctness * Size) / Accuracy

Winning Criteria
The answer with the lowest score wins. If tied then the candidate answer which is posted earlier wins.
For non-golfing languages, the score can be calculated using the following snippet (For some golfing languages, the snippet does not work since this checks for UTF-8 length of the code only):

$(document).ready(() => {
 $("#calculate").on("click", () => {
  var count = {};
  var distinct = 0;
  var nonnums = 0;
  var numerals = 0;
  var length = 0;
  for (const c of [...$("#code").val()]) {
   count[c]++;
   if (c.charCodeAt(0) <= 0x7F)
    length += 1;
   else if (c.charCodeAt(0) <= 0x3FF)
    length += 2;
   else if (c.charCodeAt(0) >= 0xD800 && c.charCodeAt(0) <= 0xDFFF)
    length += 4;
   else
    length += 3;
  }
  for (const c in count) {
   if ("0123456789abcdefABCDEF.".indexOf(c) == -1) {
    nonnums += 1;
    distinct += 1;
   }
   else {
    numerals += 1;
    distinct += 10;
   }
  }

  var output = $("#output").val();
  var match = /^8\.(5397342226(7(3(5(67?)?)?)?)?)/.exec(output);
  if (match == null)
   $("#result").html("The result does not have 10-digit accuracy!");
  else {
   var accuracy = match[1].length;
   $("#result").html(`
    Size        : ${length} bytes

    Distinctness: ${distinct} (Numerals: ${numerals}, Non-numerals: ${nonnums})

    Accuracy    : ${accuracy} decimal places

    Score       : ${(distinct * length / accuracy).toFixed(2)}
   `);
  }
 });
});

Calculator for Non-esoteric Programming Languages (BASIC-like, C-like, Python, Ruby, etc.)

Code:
<textarea cols=50 rows=10 id="code"></textarea>

Output: <input id="output">

<input type="button" id="calculate" value="Calculate Score">

Example
Submission
JavaScript(ES6), S=141, D=49, A=12, 575.75pt
(t=()=>{for(f=o=9/9;++o<9999;)f+=o**-(9>>9/9);return (f*(9*9+9))**(9/9/(9>>9/9))},u=()=>{for(f=o=r=9/9;++o<99;){f+=r;r/=o}return f})=>t()*u()

Output: 8.53973422267302
Scoring
Size        : 141 bytes
Distinctness: 49 (Numerals: 3 (use of "9", "e" and "f")), Non-numerals: 19)
Accuracy    : 12 decimal places
Score       : 575.75

[tag:code-challenge] because [tag:code-golf] is specifically for challenges where the sole scoring consideration is number of bytes for the interpreter to obtain the desired result.

@HyperNeutrino Thank you for the reminder, the clarification and the edit ;)

What exactly do you mean by "must be a numerical type"? Also, this prevents certain languages from participating so I'd recommend you consider removing that (somewhat vague) restriction.

Sandbox.

@HyperNeutrino I would say the phrase is to prevent codes which output of the string "8.5397342226..." directly (especially output digit by digit). I am expecting the calculation of the value.

@user71546 That does stop a couple of languages from participating where math isn't really a thing, but it's up to you to decide; those languages could offer something creative or interesting but it might also make the challenge less interesting in the long run. Up to you to decide of course!

@WheatWizard Thank you for the question. I have added some examples and clarified that chararcter-code extraction functions and length functions like ord and String.length are permitted because it does not trivially convert the string literal into a number.

There's a slightly-more-competitive-than-usual Unary answer out there...

Your question should include the actual value of πe to 15 digits.

I secretly hoped that this question would involve the Proto-Indo-European language in some way :(

@Lynn Added the actual value to Scoring > Accuracy. The actual value to 15 dp has been in the snippet code, inside the regex, though.

Jelly, 11 × 38 ÷ 10 = 41.8
“Þẹjuụ’÷ȷ10

Try it online!
Explanation
“Þẹjuụ’÷ȷ10  Main Link
“Þẹjuụ’      85397342226
       ÷     Divided by
        ȷ10  1e10

Since ȷ can be used as 1000 if used separately, I will count it as a single-character numeric literal :)

BTW “ seems to mark a string literal. The answer is invalid if built-in or implicit string-to-number conversion is used as per restrictions.

@user71546 Is built-in integer compression forbidden then? That should be specified separately because in this case “ denotes a number literal, not a string literal.

11 × 101 ÷ 10 = 111.1. Works in binary too!

@JungHwanMin Hm interesting! I wonder, does that work for the general case? I'd think so but I'm not sure.

never mind 11*11=121 but 11*11=1001

@HyperNeutrino should work for any base, since in base x, the expression is (x + 1)(x^2 + 1)/x == x^2 + x + 1 + 1/x, which is true for nonzero x.

@JungHwanMin That's true. I was actually talking not about which base but rather the specific digits, but then I counter-exampled myself :P But hm interesting, you're right in every base it should work.

@HyperNeutrino I would say this is a special case that I missed because the literal does not end with ” so it does not contribute to be a string.

Btw the first 7 characters are only counted as 10 each if they can be used separately as a numeric literal, so the score can be lower.

@user71546 Oh cool, thanks for specifying!

Hm, I don't know if “Þẹjuụ’ is valid, since one may say that it's a numeric literal, since you don't use any other functions to obtain the number from it. Another opinion would however be that this is a string that isn't directly converted to an integer but decompressed, so, in that case, it's perfectly valid.

@EriktheOutgolfer The OP's comments seem to indicate that I can count it as regular characters because none of the characters can be used as a numerical literal on its own, and since it's decompression, it doesn't count in this case.

Mathematica, (18*226)/15 = 271
only 1s
N[1+1+1+1+1+1+1+1+1/(1+1/(1+1/(1+1+1+1+1+1/(1+1/(1+1+1+1/(1+1/(1+1+1+1+1/(1+1+1+1+1+1+1+1+1+1+1+1+1/(1+1+1+1/(1+1+1/(1+1/(1+1+1+1+1+1/(1+1+1/(1+1+1+1+1+1+1+1+1+1+1+1+1/(1+1/(1+1)))))))))))))))),1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1]

Try it online!
Mathematica, 244
1s & 2s
N[2+2+2+2+1/(1+1/(1+1/(1+2+2+1/(1+1/(1+2+1/(1+1/(2+2+1/(12+1/(1+2+1/(2+1/(1+1/(1+2+2+1/(2+1/(12+1/(1+1/(1+1)))))))))))))))),12+2+2]

Try it online!

WOW, only 1s and 6s. btw the parentheses surrouding 6-1 can be removed for -4 bytes

updated. only 1s

Quick explanation: Continued fraction approach.

you people are mind-meltingly clever!!! it makes me angry at myself!!

For what it’s worth, this translates to 1+1+1+1+1+1+1+1+1÷1+1÷1+1÷1+1+1+1+1+1÷1+1÷1+1+1+1÷1+1÷1+1+1+1+1÷1+1+1+1+1+1+1+1+1+1+1+1+1÷1+1+1+1÷1+1+1÷1+1÷1+1+1+1+1+1÷1+1+1÷1+1+1+1+1+1+1+1+1+1+1+1+1÷1+1÷1+1 in APL, scoring 12×159÷15 = 127.2 points.

Mathematica, 257.6
N[2Integrate[Sqrt[1-n^2],{n,-1,1}],22]Sum[1/n!,{n,0,22}]

Try it online!
Mathematica, 276
this is accurate to 4095 digits
N[2Integrate[Sqrt[1-n^2],{n,-1,1}],2^12]Sum[1/n!,{n,0,2^12}]

Try it online!

Would it save any points to replace 1/n! with n!^-1?

no... it is (6960)/15=276 (this one) vs (6861)/15=276.533 (yours)

Imperative Tampio, 2206.46
K:lla on h:t.K:n z on riippuen siitä,onko sen h:iden määrä nolla,joko nolla tai sen ensimmäinen h lisättynä uuden K:n,jonka h:t ovat sen h:t toisesta alkaen eikä muuta,z:aan jaettuna kymmenellä.Kun iso sivu avautuu,se näyttää uuden K:n,jonka h:ita ovat kolme lisättynä viiteen,viisi,kolme,neljä lisättynä viiteen,7,kolme,neljä,kaksi,kaksi,kaksi,kuusi,7,kolme,viisi ja 7 eikä muuta,z:n.

K:lla on h:t.K:n z on riippuen siitä,onko sen h:iden määrä nolla,joko nolla tai sen ensimmäinen h lisättynä uuden K:n,jonka h:t ovat sen h:t toisesta alkaen eikä muuta,z:aan jaettuna kymmenellä.Kun iso sivu avautuu,se näyttää uuden K:n,jonka h:ita ovat kolme lisättynä viiteen,viisi,kolme,neljä lisättynä viiteen,7,kolme,neljä,kaksi,kaksi,kaksi,kuusi,7,kolme,viisi ja 7 eikä muuta,z:n.

Online version
Tampio has an advantage that number literals can be written using letters instead of digits. I also noticed that the interpreter thinks that one-letter words are nouns, so I can use them as identifiers. Of course, this language is so verbose that it won't help it to win any challenge.
Ungolfed:

Listalla on alkiot.
Listan lukuarvo on
riippuen siitä, onko sen alkioiden määrä nolla,

joko nolla
tai sen ensimmäinen alkio lisättynä uuden listan, jonka alkiot ovat sen alkiot toisesta alkaen eikä muuta, lukuarvoon jaettuna kymmenellä.

Kun nykyinen sivu avautuu,

se näyttää uuden listan, jonka alkioita ovat 8,5,3,9,7,3,4,2,2,2,6,7,3,5 ja 7 eikä muuta, lukuarvon.

APL, 6×124÷15 = 49.6 points
zz+zz+zz+zz+÷z+÷z+÷z+zz+zz+÷z+÷z+zz+÷z+÷zz+zz+÷zz+zz+zz+zz+zz+zz+÷z+zz+÷zz+÷z+÷z+zz+zz+÷zz+÷zz+zz+zz+zz+zz+zz+÷z+÷zz←z+z←⍴⍴⍬

Try it online! (Paste in the code then hit Ctrl+Enter.)
Assigns 1 to z, then abbreviates z+z to zz, and then approximates the continued fraction of πe as 8+1/(1+1/(1+1/(5+1/(1+1/(3+1/(1+1/(4+1/(10+1/(3+1/(2+1/(1+1/(5+1/(2+1/(12+1/(1+1/2)))))))))))))))  (inspired by Jenny_mathy’s Mathematica answer).
1 is computed as ⍴⍴⍬: the dimensions vector (1) of the dimensions vector (0) of the empty vector (⍬).
Because of APL’s ÷ reciprocal operator and right-to-left grouping rules, this representation doesn’t even need parentheses. We use 6 distinct non-numeric symbols: z+÷←⍴⍬

This code should work in any APL dialect; the only important thing is that there is one where

the answer is printed to 15 figures by default;
the glyphs are encoded as one byte each (i.e. source code is in some custom APL codepage, not UTF-8).

Graham reports that APL+Win fits the bill.

Well, this works in Dyalog APL which TIO supports! (note how I put ⎕← to show the output, don't count that)

Also, can you please specify what APL dialect you're using? If you're using Dyalog, then you have a precision of 9 decimals, not 15. If you're using ngn/apl, then you should count the bytes in Unicode.

Hm… There are enough APL implementations out there that I’d expect one of them to support both an APL SBCS and 15-digit precision by default. I’ll wait for Adám to chime in!

This works in my APL+WIN which is not Unicode and produces the answer 8.539734222673568

Further to the above I would be surprised if the precision in Dyalog is limited to 9 decimals. In APL+WIN it is controlled via ⎕PP which by default is 10 but can be set up to 17. In APLX again the default is 10 max 15.

Desmos, 199 bytes, Score = 199*(3*10+22)/11 = 940.73
h=g(\left\{\right\}+\left\{\right\})\int_{-\left\{\right\}}^{\left\{\right\}}\sqrt{\left\{\right\}-x^{\left\{\right\}+\left\{\right\}}}dx
\int_{\left\{\right\}}^{g}\left\{\right\}/xdx~\left\{\right\}

Try it on Desmos! Stores the result in variable h.
Calculates the exact values of \$\pi\$ and \$e\$ using integrals, and multiplies them together. This should theoretically yield a perfect score of 0, but Desmos only displays values to a precision of 11 decimal digits. Also, this code does not use the characters 0123456789, instead opting for strings of \left\{\right\}, which are condition-less piecewise functions that evaluate to 1.
Equivalent equations:
\$h=2g\int_{-1}^{1}\sqrt{1-x^2}dx\$ (\$e\$ * area of circle with radius 1)
\$\int_{1}^{g}\frac{1}{x}dx\sim1\$ (\$e\$ is the unique positive real value of \$c\$ such that \$\int_{1}^{c}\frac{1}{x}dx=1\$; the \$\sim\$ tells Desmos that the equation is a regression, and therefore needs to solve for g)

51.81818 score, there is definitely room for more improvement.

Swift, 116 * 39 / 14 ≈ 323.14 114 * 39 / 14 ≈ 317.57
print(2+2+2+2+1/(1+1/(1+1/(2+2+1+1/(1+1/(2+1+1/(1+1/(2+2+1/(12+1/(2+1+1/(2+1/(1+1/(2+2+1+1/(2+1/12.2))))))))))))))

Try it online!
Uses a continued fraction to approximate π*e to 14 decimal places

Pyt, 22*73/11=146 22*72/11=144 23*53/11 22*39/11=78
1⁺1⁺⁺⁺⁺⁺^ř⁻Đ!⇹1⁺*⁺‼/Ʃ1⁺*1⁺⁺1⁺⁺⁺⁺*ř⁻!⅟Ʃ*

Uses approximations for π and e, respectively.
Per the codepage (which is in the interpreter2 file), each character is one byte.
Explanation (stuff in brackets is what is used from the stack):
1⁺1⁺⁺⁺⁺⁺^ř⁻Đ!⇹1⁺*⁺‼/Ʃ1⁺*           makes π

1⁺1⁺⁺⁺⁺⁺^         makes 64
(64)ř             makes a list [1,2,...,64]
([1,...,64])⁻     subtracts one from each element in the list
([0,...,63])Đ     duplicates list (on top of stack twice)
([0,...,63])!     performs element-wise factorial
([...],[...])⇹    swaps top two items on the stack
([...])1⁺*⁺       doubles all values in list and adds one
([...])‼          element-wise double factorial
([...],[...])/    divides element-wise
([...])Ʃ          sums all elements in the list (approximately π/2)
(π/2)1⁺*          doubles (yields π)

1⁺⁺1⁺⁺⁺⁺*ř⁻!⅟Ʃ

1⁺⁺1⁺⁺⁺⁺*         makes 15
         ř⁻       makes a list [0,1,...,14]
           !      Takes the factorial of each element in the list
            ⅟     Finds the multiplicative inverse of each element
             Ʃ    Sums the list (e)

(π,e)*              multiplies
                    (implicit print)

Try it online!


text:
Tips for Golfing in Standard ML
Standard ML (or golfier: SML) is a general-purpose, modular, functional programming language with compile-time type checking and type inference. (from Wikipedia)
Though you almost certainly will never win a code golf challenge with SML, (ab-) using it for golfing can nevertheless be quite fun (<- keyword for function declaration). So without further ado ...
What tips do you have for golfing in Standard ML?
Please only post tips which are somewhat unique to SML. General golfing tips belong to Tips for golfing in all languages.

I don't use haskell but I believe the syntax for basics is quite similar, so https://codegolf.stackexchange.com/questions/19255/tips-for-golfing-in-haskell broadly applies

Use symbolic identifiers
From The Definition of Standard Ml (revised) [PDF], Section 2.4:

An identifier is either alphanumeric: any sequence of letters,
digits, primes (') and underbars (_) starting with a letter or
prime, or symbolic:  any non-empty sequence of the following symbols:
!  %  &  $  #  +  -  /  :  <  =  >  ?  @  \  ~  ‘  ^  |  *

In either case, however, reserved words are excluded. This means that for
example # and | are not identifiers, but ## and |=| are identifiers.

The important part (concerning golfing) is that you do not need white space between symbolic identifiers and alphanumeric identifiers or keywords.
Example
fun f a b c=if b then a else c

By replacing f by $ and b by !, we can save 6 bytes:
fun$a!c=if!then a else c

Note, however, that a symbolic identifier needs white space when next to other symbols. That's why we cannot replace a and c in the above example to get to the same byte count:
fun f$b!=if b then$else!    (* syntax error because != is parsed as one token *)

List functions
Lists are the standard data structure usually used recursively with :: constructor. Indexing must be done using nth.
Short and maybe useful functions are

@: append
hd: head, but also try pattern matching
tl: all but head
last: tail
take: first n elements
drop: drop first n elements and return
rev: reverse

Higher order functions:

map: map
foldr, foldl: fold and reverse fold
filter: filter
exists, all: exists, all bool cond

Be aware that using functions from a structure requires either to open the structure (open List) or to qualify the functions (List.exists). However, the following list functions are also available at top level: @, app, foldl, foldr, hd, length, map, null, rev, tl.

Pattern matching in functions
Concise way to extract the values and write cases for recursive functions. Case statements are probably too long.
Extracting values:
fn(x,y)=>x+y   (* lambda fn *)
fun f x y=x+y  (* curried bound function *)

Recursive function with base case (this basic list sum is equivalent to foldl op+ 0):
fun f(x::L)=x+f L|f _=0

Use wildcard matching instead of explicit matching
This broadly applies to any pattern matching construct with a fallthrough or wildcard: in some situations you can use the wildcard to match a pattern instead of an explicit pattern.
Empty list example (with formatting for clarity):
fun f([]) = 0
  | f(x::L) = x + f L

versus matching with wildcard saving a byte:
fun f(x::L) = x + f L
  | f(_) = 0

Also note that the wildcard does not need parentheses and only needs a space when preceded by an alphanumeric identifier. That is, the last line can be |f _=0 or also | $_=0 when f is renamed to $. Likewise, fun f _x=x works, but fun x_=x does not.