text:
ASCII art reflection
In this challenge, you will be given a text block, and you need to perform reflection on the text.
Input:

A string to be reflected. The text may not be supplied as an array whose elements are the lines of text. For example, "ab\ncd" and ['a','b','\n','c','d'] are allowed, but ['ab','cd'] or [['a','b'],['c','d']] are not. You can assume that all of the lines have the same number of characters (padded with whitespace where needed).
A boolean where True indicates Y reflection and False indicates X reflection

The two inputs can be passed in any order.
Output:
The reflected string. The characters do not change, only their position. The resulting image block should be aligned to the top left (the first row and column must each contain a non-whitespace character). Trailing whitespace (on any of the lines) is allowed.
Test cases:
False
  o /
--|/
  |
 / \

/ o
 /|--
  |
 \ /

True
  o /
--|/
  |
 / \

 / \
  |
--|/
  o /

True
text

text

False
text

txet

True
P
P
C
G

G
C
P
P

False
P
P
C
G

P
P
C
G

True
abcde
fghij
kl mn
opqrs
tuvwx

tuvwx
opqrs
kl mn
fghij
abcde

This is a code-golf, so answer with the shortest answer in your favorite language!

Can we take the boolean in any format (eg. 1 and 0) or we must use True and False?

@TùxCräftîñg any truthy/falsy value is fine.

@PeterTaylor I don't see how this is unclear even for languages where strings are arrays. In that case it maens that you can't have subarrays for each line, you must have a flat list of characters.

@PeterTaylor I'm specifically disallowing arrays, where each element in the array is a line of text.  Aka, "ab\ncd" is fine, ["a","b","\n","c","d"] is fine, but ["ab","cd"] or [["a","b"], ["c","d"]] is not

Putting each line in an array is not allowed For some languages that would be the only way, if they don't allow multiline strings

@PeterTaylor is that better?

@LuisMendo If a language natural string representation can't contain an \n I would go as far as to say that it's not a string representation.

Are extra trailing spaces allowed in output lines?

@LuisMendo yes.

So i'm confused, doesn't that Array rule disallow any use of string splitting?

@Phaeze it's a restriction on how you input the string, not on what you can do with the string.

@NathanMerrill Ok, thanks for the clarification.

Can you clarify the boolean input a bit? Do I get to pick any two values, one of which is falsey and the other of which is truthy, and make my program work with those; or should my program handle all falsey values one way and all truthy values the other way?

Also, a lot of the answers seem to assume the input is rectangular (all lines are padded to the same length using spaces). Is that assumption okay? Either way, you should clarify this in the question.

@Lynn bah, I should have come up with better test cases for that.  Yes, that assumption is fine.

@NathanMerrill I'd recommend adhering to the default definitions of Truthy/Falsey

Are you sure you did not get "X-reflection" and "Y-reflection" mixed up? Because for the True test cases, it looks like the input string is reflected across the X axis and not the Y axis.

@R.Kap I'm not reflecting across the axises, but in the Y direction or the X direction.

@NathanMerrill Ah, I see. I got a bit confused there. Thanks for the clarification.

@NathanMerrill Is this output okay for test case # 1?

@R.Kap no, its not.

Well then, in that case, @Lynn's answer is invalid as his/her answer outputs that exact thing for test case # 1.

Actually then, in that case, 3 answers are invalid, namely Lynn's Jelly and Python answers and LeakyNun's Pyth answer.

@R.Kap It seems that you're allowed to require rectangular input.

@Neil Okay. But then, why did Nathan Merrill say this output is not okay for test case # 1? Also, if that is indeed true, OP should at least say it in the post. Otherwise, I am just assuming that the input won't necessarily be rectangular.

@R.Kap because that's not valid output.  However, if its generated using input that the program doesn't support, then its not a valid test case

@NathanMerrill just to clarify Lynn's earlier comment, just 1/0 is acceptable as truthy/falsy input?  Meaning my program doesn't have to handle anything that's truthy, only the 1 or the 0?

@nmjcman101 correct.

C#, 168 144 141 120 Bytes
using System.Linq;i=>y=>string.Join("\n",y?i.Split('\n').Reverse():i.Split('\n').Select(x=>string.Concat(x.Reverse())));

New version utilizes the obvious string.Join overload that takes an IEnumerable, the first solution was using it inadvertently I was just able to use it for the else side of the ternary as well.
Update:
New version is an anonymous lambda and uses currying to save 21 bytes total. This changes usage to be f("text")(false) where f is the anonymous function.
Ungolfed:
using System.Linq;

//Using currying to save one byte
input => IsYReflect =>
         //Lambda makes return implicit
         string.Join("\n", IsYReflect
            //Y Reflect, just need to reverse the array
            ? input.Split('\n').Reverse()
            //X Reflect, reverse each line into an IEnumerable
            : input.Split('\n').Select(x => string.Concat(x.Reverse())));

Scott Kaye left a comment that has since been removed that triggered me to try some new things and shave off 24 bytes.

C#6 expression bodied function saves another 3 bytes

Pyke, 7 bytes
!I_)ncX

Try it here!
!I )    - if not boolean:
  _     -  input = reversed(input)
    nc  - input.split("\n")
      X - splat(input)
        -  (print lines backwards)

Brainfuck, 143 140 131 bytes
,[,[---------->+<[>-]>[->]<,]<[[<]>[++++++++++.>]++++++++++.<[<]<]],[---------->+<[++++++++++>-]>[-<<[.<]++++++++++.[>]>>]<,]<[.<]

Beats C#.
The challenge was easy enough for Brainfuck, and I apparently was tired enough to just have to do it.
Takes the boolean as a 0x00 (falsy) or any other (truthy) byte in the start of the input, then a rectangle-padded string.
Outputs a trailing newline for the Y flip, and none for the X flip.
Requires an interpreter that supports memory locations to the left of the start (unsure if still required) and gives EOF as 0x00. One such interpreter is here. Obviously doesn't support null bytes in the input because of that.
The code has a lot of blocks with 10 +'s or -'s; those can probably be reduced.
Commented version
, get mode
[ check truthy input
    ,[ loop thru input
        ---------- subtract newline
        >+ set flag
        < go back to char
        [ was not newline
            > move to flag
            - reset flag
        ]
        > move to flag or one past flag
        [ hit flag; was newline
            - reset flag
            > skip a cell
        ]
        < go to next position
        , read next input
    ]
    < find end of line
    [ loop thru lines
        [<]> find start of line
        [ loop thru line
            ++++++++++ add newline back
            . print this cell
            > go to next cell
        ]
        ++++++++++ change to newline
        . print newline
        <[<]< find end of previous line
    ]
]
,[ loop thru any input left
    ---------- subtract newline
    >+ set flag
    < go back to char
    [ was not newline
        ++++++++++ add newline back
        > move to flag
        - reset flag
    ]
    > move to flag or one past flag
    [ hit flag; was newline
        - clear flag
        < go back to char
        < go back to line chars
        [ loop thru line
            . print this cell
            < go to previous cell
        ]
        ++++++++++. print newline
        [>]>> find empty cell
    ]
    < go to next position
    , read next input
]
< go to line
[ loop thru line
    . print this cell
    < go to previous cell
]

32-bit x86 machine code, 76 bytes
In hex:
31c031c9495789f7fcf2aef7d15192b00a89f7f2ae5829f7f7f787f95f4b89c3741287d94b534b8a041eaa75f95b01dea4e2f2c348f7e101c6b00a5651f3a4595e29ce4f4b0f44c3aa75f0c3

Input: EBX: direction flag (0/1), ESI: input string, EDI: output buffer. Input is required to be rectangular.
0:  31 c0               xor eax,eax         ;EAX=0
2:  31 c9               xor ecx,ecx
4:  49                  dec ecx             ;ECX=(uint)-1
5:  57                  push edi
6:  89 f7               mov edi,esi
8:  fc                  cld
9:  f2 ae               repne scasb         ;Scan input string for terminating NULL
b:  f7 d1               not ecx             ;ECX==<input string length (including NULL)>
d:  51                  push ecx
e:  92                  xchg edx,eax        ;EDX=0
f:  b0 0a               mov al,0x0a         ;'\n'
11: 89 f7               mov edi,esi
13: f2 ae               repne scasb         ;Scan input string for the first newline
15: 58                  pop eax             ;EAX==<input string length (including NULL)>
16: 29 f7               sub edi,esi         ;EDI==<single line length (including '\n')>
18: f7 f7               div edi             ;EAX==<# of lines>
1a: 87 f9               xchg ecx,edi        ;ECX=EDI
1c: 5f                  pop edi             ;EDI=<dest buffer>
1d: 4b                  dec ebx             ;Test input flag (0/1)
1e: 89 c3               mov ebx,eax         ;EBX=<# of lines>
20: 74 12               je _vertical
22: 87 d9               xchg ecx,ebx        ;Horisontal flip, exchange ECX & EBX so we can use LOOP
24: 4b                  dec ebx             ;EBX=<single line length (excluding '\n')>
_hfouter:
25: 53                  push ebx
_hfinner:
26: 4b                  dec ebx             ;Decrement inner loop counter
27: 8a 04 1e            mov al,[esi+ebx]    ;AL=ESI[EBX]
2a: aa                  stosb               ;*EDI++=AL
2b: 75 f9               jne _hfinner        ;EBX==0 => break
2d: 5b                  pop ebx
2e: 01 de               add esi,ebx         ;*ESI=='\n' (\0 on the last line)
30: a4                  movsb               ;*EDI++=*ESI++, ESI now points to the next line
31: e2 f2               loop _hfouter       ;--ECX==0 => break
33: c3                  ret                 ;Nothing more to do here
_vertical:
34: 48                  dec eax             ;# of strings less one
35: f7 e1               mul ecx             ;Line length (including '\n')
37: 01 c6               add esi,eax         ;ESI+=ECX*(EAX-1), ESI now points to the beginning of the last line
39: b0 0a               mov al,0x0a         ;'\n'
_vfloop:
3b: 56                  push esi
3c: 51                  push ecx
3d: f3 a4               rep movsb           ;Copy the whole line to the output including newline/NULL at the end
3f: 59                  pop ecx
40: 5e                  pop esi
41: 29 ce               sub esi,ecx         ;Set ESI to the beginning of the previous line
43: 4f                  dec edi             ;*EDI=='\n' (0 on the first iteration), should overwrite it with correct value
44: 4b                  dec ebx             ;Decrement loop counter
45: 0f 44 c3            cmove eax,ebx       ;if (EBX==0) EAX=EBX, this clears EAX on the last iteration
48: aa                  stosb               ;*EDI++=EBX?'\n':0
49: 75 f0               jne _vfloop         ;EBX==0 => break
4b: c3                  ret

Haskell, 51 49 45 bytes
r=reverse
f b=unlines.last(map r:[r|b]).lines

Usage example:
f True "abc\ndef\nghi\njkl"
"jkl\nghi\ndef\nabc\n"

f False "abc\ndef\nghi\njkl"
"cba\nfed\nihg\nlkj\n"

Split into lines, either reverse the lines (True) or reverse each line (False) and join into a single string again. In case of a True input, map r:[r|b] is a list of two functions [<reverse each line>, <reverse lines>] and for a False input a list with one function [<reverse each line>]. last picks the last element of this list.

Jelly, 8 bytes
ṣ⁷ṚU⁴?j⁷

Try it here.
ṣ⁷         Split over newlines.
  ṚU⁴?     If ⁴ (2nd argument), then Ṛ (reverse rank ∞), else U (reverse rank 1).
      j⁷   Join with newlines.

Python, 56 bytes
lambda s,r:'\n'.join(s[::2*bool(r)-1].split('\n')[::-1])

Call with a string s and any truthy/falsey value r.

It doesn't work that way. Your program has to either take any truthy value, or take only True, which could also be 1. You cannot restrict input to be only 0 or 2.

Yeah, I didn't think through my answer.  @mbomb007 is correct here, it needs to work for any truthy/falsy value for your language.

@NathanMerrill Just an FYI, you can avoid stuff like the 3 byte answer by saying that the input should not encode any additional information. This would have allowed the second answer (which I thought was rather clever), but of course what you would like to see is up to you.

This answer is invalid according to OP as it outputs this for test case # 1 when it should instead be outputting what is given in the post for that test case (i.e. space padded to the length of the first line).

Python 3.5, 61 bytes:
lambda f,j:[print(r[::-1])for r in j[::[1,-1][f]].split('\n')]

A simple anonymous lambda function that assumes rectangular input. Call it by by first naming the function, and then calling it wrapped inside print(). In other words, if the function were named H, call it like print(H(<Bool value>, <String>)), where <Bool Value> is any true or false value (i.e. 0/1, true/false, etc.) and <String> is the input string.
See it in Action! (repl.it)
Here is another version with the same length that also assumes rectangular input, but this time a named function, i.e. you don't have to name it first nor wrap it inside print():
def J(f,j):[print(r[::-1])for r in j[::[1,-1][f]].split('\n')]

Simply call this one likeJ(<Bool Value>,<String>).
See this in Action! (repl.it)
However, I'm not the one to stop there. Although we are allowed to assume rectangular input, I also created a version that does not assume that type of input. Therefore, it will space-pad all of the lines to the same length based on the line with the maximum length if and only if the <Bool> input is False, as only a X-reflection will result in the string being "flipped". Now, without further ado, here is the non-rectangular assuming version with a length of 134 129 bytes in the form of a normal function:
def J(f,j):print('\n'.join([' '*((max([len(i)for i in j.split('\n')])-len(r))*(not f))+r[::-1]for r in j[::[1,-1][f]].split('\n')]))

See this Last One in Action! (repl.it)

Brachylog, 26 24 16 bytes
t1,?h@nr~@nw|hrw

Expects a list containing the string and the boolean 1 or 0, e.g.
run_from_file('code.bl',["P
|    P
|    C
|    G":1]).

Explanation
t1,              If the tail of the input is 1
   ?h@n              Split the string on \n
       r             Reverse the resulting list
        ~@n          Join the list of strings with \n
           w         Write to STDOUT
|                Or
hr                   Reverse the string
  w                  Write to STDOUT

MATL, 11 bytes
10&Ybc2i-&P

Try it online!
The first input is the multiline string. Since MATL doesn't recognize \n as linefeed, the multiline string should be defined as a concatenation of substrings, or individual characters, and 10 (ASCII for line feed, which is interpreted as a character). Concatenation in MATL is [... ...] or [..., ...] (commas are optional). So for example, input can be as follows (concatenation of a string, linefeed, and another string):
['first line' 10 'second']

or equivalently (concatenation of individual characters)
['f' 'i' 'r' 's' 't' ' ' 'l' 'i' 'n' 'e' 10 's' 'e' 'c' 'o' 'n' 'd']

or (same with commas)
['f', 'i', 'r', 's', 't', ' ', 'l', 'i', 'n', 'e', 10, 's', 'e', 'c', 'o', 'n', 'd']

The second input can be entered as 1/0 or equivalently as T/F for true/false respectively.
Explanation
10     % Push 10 (ASCII for linefeed)
&Yb    % Take input string implicitly. Split at linefeeds. Gives a cell array
c      % Convert to a 2D char array, right-padding with spaces
i~Q    % Input Boolean value. Negate and add 1. Gives 1/2 for true/false resp.
&P     % Flip along that dimension (1: vertically; 2: horizontally). Display implicitly

It really doesn't make sense that this doesn't work

@Fatalize It's because of how MATL and MATLAB read the input. Each line is a different input

Pyth, 10 bytes
j?Q_.z_M.z

Test suite.
j?Q_.z_M.z  first line evaluated as Q, all other lines as .z
 ?Q         if Q:
   _.z         yield reverse(.z)
      _M.z  else: yield map(reverse, .z)
j           join by newlines

Julia, 59 bytes
x\y=(y=split(y,'
');! =reverse;join(x?!y:[!a for a=y],'
'))

Try it online!

Perl, 35 bytes
34 bytes code + 1 for -n.
Requires the input lines be padded with spaces. 13 (!) bytes saved thanks to @Dada.
print/T/?reverse<>:map~~reverse,<>

Usage
perl -ne 'print/T/?reverse<>:map~~reverse,<>' <<< 'False
  o /
--|/
  |
 / \ '

/ o
 /|--
  |
 \ /

 perl -ne 'print/T/?reverse<>:map~~reverse,<>' <<< 'True
  o /
--|/
  |
 / \ '
 / \
  |
--|/
  o /

perl -ne 'print/T/?reverse<>:map~~reverse,<>' should save you 13 bytes :-)

@Dada that is indeed a big saving! No idea why I wouldn't have done that but I'll update, thanks!

APL (Dyalog Unicode), 9 11 9 bytes (SBCS)
Fixed answer but only had to add 2 bytes and kept it the same length thanks to @Adám
⌽[⎕]⎕FMT⎕

Try it online!
Takes a character vector using \r as a separator through STDIN first, then 1 or 0. Requires 0-indexing.
⎕ accepts input. ⎕FMT formats it into a character matrix because of \r. ⌽[⎕] reflects that over either the x- or y-axis, depending on the second input. With 0-indexing, ⌽[0] or just ⌽ reflects over the x-axis, ⌽[1] or ⊖ over the y-axis.

It would seem that your input format is prohibited. However, if you take input as a string with \rs then ⎕FMT will give you a matrix. Also, look into ⌽[ax] with ⎕IO←0.

Using a full program, you can save 2 bytes: ⌽[⎕]⎕FMT⎕

Also, you have to set ⎕IO←0 to abide by the truthy/falsey rule.

Tends to be the case with older challenges.

I would be a good idea to add this use of ⎕FMT to the [tag:tips] thread.

@Razetime You can just add an answer.

⌽[2] is not the same as ⍉

⍉ never reflects over a single axis, so it cannot be expressed as ⌽[ax].

⍉ is actually "reorder axes", by default (i.e monadically) into reverse order.

JavaScript (ES 6) 83 bytes
(c,b)=>(p=c.split`
`)&&(b?p.reverse():p.map(a=>a.split``.reverse().join``)).join`
`

f=(c,b)=>(p=c.split`
`)&&(b?p.reverse():p.map(a=>a.split``.reverse().join``)).join`
`

f("abcde\nfghij\nkl mn\nopqrs\ntuvwx",1)

c="
  o /
--|/
  |
 / \
";

f(c,1)
" / \
   |
 --|/
   o / "

f(c,0)
"/ o
  /|--
   |
  \ / "

I see a different output for f(c,0) when I try - maybe your c doesn't have all the spaces in the right places.

Is the trailing white space after the first "o /" significant?

@PeterMortensen & Neil: I'm pretty sure that's from my copy-pasting. The javascript console puts your beginning " on the first line and makes everything look terrible so I formatted it a bit when I pasted in here.  Very likely I have a bug too.

Bash + common linux utils, 16
(($1))&&tac||rev

Boolean value (zero or non-zero) passed as a command-line parameter.  I/O of text block via STDIN/STDOUT.  Assumes that all lines are the same length, as indicated in the comments.

C (Ansi), 193 Bytes
Golfed:
i,y,x;main(g,o,p)char**o;{p=(o[1][0]=='t');while(o[2][++i]!='\n');p?y=(strlen(o[2])-1)/i:(x=i);do do printf("%c",o[2][x+y*i]);while(p?++x<i:x-->0);while(p?x=0,y--:++y<(x=i-1,strlen(o[2])/i));}

Ungolfed:
i,y,x;
main(g,o,p)char**o;{
    p=(o[1][0]=='t');
    while(o[2][++i]!='\n');
    p?y=(strlen(o[2])-1)/i:(x=i);
    do{
        do{
            printf("%c",o[2][x+y*i]);
        }while(p?++x<i:x-->0);
    }while(p?x=0,y--:++y<(x=i-1,strlen(o[2])/i));
}

Usage:
Compilation Arguments:
gcc -O3 -ansi

Example Input:
Input is a t or not t for true of false followed by a newspace lead and trailed string.
./reverseString t "
truck
ducky
quack
moose
"

Example Output:
moose
quack
ducky
truck

J, 29 bytes
}:@,@(,.&LF@{|."1,:|.)>@cutLF

LHS input is the boolean where 0 is false and 1 is true. RHS is the string input.

Java 99 bytes
public String[] reverse(String[]a){
  int i=-1,j=a.length;
  for(;++i<--j;){
    String b=a[i];
    a[i]=a[j];
    a[j]=b;
  }
  return a;
}

Golfed:
String[] e(String[]a){int i=-1,j=a.length;for(;++i<--j;){String b=a[i];a[i]=a[j];a[j]=b;}return a;}

05AB1E, 10 bytes
U|XiRë€R}»

Explanation
U          Remove the first input line and store it in variable X
 |         Aggregate the rest of the input into an array
  XiR      If x is true, revert the array
     ë€R   Else revert each element
        }  End if
         » Join everything with newlines and implicitly display

Try it online!

8 bytes (U|X to |ć and €R to í) Perhaps these builtins weren't available when you posted your answer, but they are still available in the legacy version of 05AB1E regardless. :)

Charcoal, 6 bytes
θ¿η‖↓‖

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

Mathematica, 70 bytes
If[#,Reverse,StringReverse]@ImportString[#2,l="Lines"]~ExportString~l&

Anonymous function, takes a boolean value as first argument (explicitly True or False in Mathematica) and the (multiline) string as the second argument. Imports the string as a list of strings corresponding to the lines of the multiline string (the string is NOT passed to the function as an array). If True, reverse the list. If False StringReverse the list, which automatically is applied to each element in turn. Then export the list as a string, where each element is a new line.

JavaScript (ES6), 76
s=>b=>(s=s.split`
`,b?s.reverse():s.map(r=>[...r].reverse().join``)).join`
`

F=s=>b=>(s=s.split`
`,b?s.reverse():s.map(r=>[...r].reverse().join``)).join`
`

function test()
{
  var rows=I.value, r

  // Trim trailing newlines, pad to blank
  rows=rows.split('\n')
  while(!(r=rows.pop()));
  rows.push(r)
  var maxlen=Math.max(...rows.map(r=>r.length))
  rows=rows.map(r=>r+' '.repeat(maxlen-r.length)).join`\n`

  var t1=F(rows)(false)
  var t2=F(rows)(true)

  O.textContent = 'False\n'+t1+'\n\nTrue\n'+t2
}

test()
#I { width:50%; height:10em }
<textarea id=I>
  o /
--|/
  |
 / \
</textarea>
<button onclick=test()>Go</button>
<pre id=O></pre>

Vim, 33 bytes
Changed previous V answer to Vim.  Any V answer would be way different, so it wasn't really fair.
DgJ:if@"
g/^/m0
el
se ri
en
cG"

Try it online!
Hexdump
00000000: 4467 4a3a 6966 4022 0a67 2f5e 2f6d 300a  DgJ:if@".g/^/m0.
00000010: 656c 0a73 6520 7269 0a65 6e0a 6347 1222  el.se ri.en.cG."
00000020: 08                                       .

You could probably save a bunch of bytes with this mapping

05AB1E, 8 bytes
|ćiRëí}»

Try it online!
|ćiRëí}»  # full program
       »  # join...
|         # list of lines in input...
 ć        # excluding the first element...
   R      # reversed...
  i       # if...
 ć        # first element of...
|         # list of lines in input...
  i       # is truthy...
    ë     # else...
     í    # with each element in list reversed...
       »  # by newlines
      }   # end if statement
          # implicit output


text:
Runs of Digits in Pi
Your goal is to output the strictly increasing sequence of consecutive, identical digits of pi (π). Each term in the sequence must be one digit longer than the previous. So 3 (0th digit of pi) is the first time a run of digits occurs (length 1). The next to occur is 33 (digits 24 and 25 of pi). Of course, this sequence requires the digits of pi to be in base 10.
The ones known so far, and the first six all occur within the first 800 digits:
3
33
111
9999
99999
999999
3333333
44444444
777777777
6666666666
... (not in first 2 billion digits)

Note that the consecutive nines all occur together, in the same run, so if the next larger run you found happened to be 1000 consecutive 0s, this would fill in multiple terms of the sequence.
I have not found any more terms with my program. I know there are no more terms within the first 50000 digits or more. My program was taking too long with 500000 digits, so I gave up.
Reference Implementation
You may:

Output the sequence forever
Take an integer n and find the first n numbers in the sequence
Take an integer n and find the numbers in the sequence contained in the first n digits of pi.

Make sure to specify which one your code does. The number n may be zero or one indexed.
Inspired by this mathoverflow question.

Related - that runs of 9s caused headaches for many answers :P

Are you allowed to start output with the empty sequence?

Also, the next term of the sequence appears to be 3333333 in digits 10^-710100 through 10^-710106. The value for n = 8 does not appear in the first 5 000 000 digits.

Do we have to do it for base 10, or can we choose our base (integer>1)? (I'm thinking this may help....)

@msh210 I want to do that exact thing, except I can't figure out how to implement the formula to find the nth digit of π...

@msh210 It must be base 10.

@R.Kap Just Google "nth digit of pi". Here's the Spigot algorithm that I used.

Two more terms: 44444444 at digits 10^-22931745 through 10^-22931752 and 777777777 at digits 10^-24658601 through 10^-24658609. The value for n = 10 does not appear in the first 100 000 000 digits.

One more term: 6666666666 at 10^-386980412. The 11th term does not appear in the first 2 000 000 000 digits.

@primo How long did that take to find?

@mbomb007 400m took only 38 minutes, surprisingly. I've updated the code in my answer.

Mathematica, 85 bytes
FromDigits/@DeleteDuplicatesBy[Join@@Subsets/@Split@RealDigits[Pi,10,#][[1]],Length]&

Anonymous function. Takes n as input, and returns the elements of the sequence in the first n digits of π. Output is in the form of {0, 3, 33, 111, ...}.

Python 2, 110 bytes
n=input()
x=p=7*n|1
while~-p:x=p/2*x/p+2*10**n;p-=2
l=m=0
for c in`x`:
 l=l*(p==c)+1;p=c
 if l>m:m=l;print p*l

The maximum number of digits to check is taken as from stdin. 10,000 digits finishes in about 2s with PyPy 5.3.
Sample Usage
$ echo 10000 | pypy pi-runs.py
3
33
111
9999
99999
999999

Something Useful
from sys import argv
from gmpy2 import mpz

def pibs(a, b):
  if a == b:
    if a == 0:
      return (1, 1, 1123)
    p = a*(a*(32*a-48)+22)-3
    q = a*a*a*24893568
    t = 21460*a+1123
    return (p, -q, p*t)
  m = (a+b) >> 1
  p1, q1, t1 = pibs(a, m)
  p2, q2, t2 = pibs(m+1, b)
  return (p1*p2, q1*q2, q2*t1 + p1*t2)

if __name__ == '__main__':
  from sys import argv
  digits = int(argv[1])

  pi_terms = mpz(digits*0.16975227728583067)
  p, q, t = pibs(0, pi_terms)

  z = mpz(10)**digits
  pi = 3528*q*z/t

  l=m=0
  x=0
  for c in str(pi):
   l=l*(p==c)+1;p=c
   if l>m:m=l;print x,p*l
   x+=1

I've switched from Chudnovsky to Ramanujan 39 for this. Chudnovsky ran out of memory on my system shortly after 100 million digits, but Ramanujan made it all the way to 400 million, in only about 38 minutes. I think this is another case were slower growth rate of terms wins out in the end, at least on a system with limited resources.
Sample Usage
$ python pi-ramanujan39-runs.py 400000000
0 3
25 33
155 111
765 9999
766 99999
767 999999
710106 3333333
22931752 44444444
24658609 777777777
386980421 6666666666

Faster Unbounded Generators
The reference implementation given in the problem description is interesting. It uses an unbounded generator, taken directly from the paper Unbounded Spigot Algorithms for the Digits of Pi. According to the author, the implementations provided are "deliberately obscure", so I decided to make fresh implementations of all three algorithms listed by the author, without deliberate obfuscation. I've also added a fourth, based on Ramanujan #39.
try:
  from gmpy2 import mpz
except:
  mpz = long

def g1_ref():
  # Leibniz/Euler, reference
  q, r, t = mpz(1), mpz(0), mpz(1)
  i, j = 1, 3
  while True:
    n = (q+r)/t
    if n*t > 4*q+r-t:
      yield n
      q, r = 10*q, 10*(r-n*t)
    q, r, t = q*i, (2*q+r)*j, t*j
    i += 1; j += 2

def g1_md():
  # Leibniz/Euler, multi-digit
  q, r, t = mpz(1), mpz(0), mpz(1)
  i, j = 1, 3
  z = mpz(10)**10
  while True:
    n = (q+r)/t
    if n*t > 4*q+r-t:
      for d in digits(n, i>34 and 10 or 1): yield d
      q, r = z*q, z*(r-n*t)
    u, v, x = 1, 0, 1
    for k in range(33):
      u, v, x = u*i, (2*u+v)*j, x*j
      i += 1; j += 2
    q, r, t = q*u, q*v+r*x, t*x

def g2_md():
  # Lambert, multi-digit
  q, r, s, t = mpz(0), mpz(4), mpz(1), mpz(0)
  i, j, k = 1, 1, 1
  z = mpz(10)**49
  while True:
    n = (q+r)/(s+t)
    if n == q/s:
      for d in digits(n, i>65 and 49 or 1): yield d
      q, r = z*(q-n*s), z*(r-n*t)
    u, v, w, x = 1, 0, 0, 1
    for l in range(64):
      u, v, w, x = u*j+v, u*k, w*j+x, w*k
      i += 1; j += 2; k += j
    q, r, s, t = q*u+r*w, q*v+r*x, s*u+t*w, s*v+t*x

def g3_ref():
  # Gosper, reference
  q, r, t = mpz(1), mpz(180), mpz(60)
  i = 2
  while True:
    u, y = i*(i*27+27)+6, (q+r)/t
    yield y
    q, r, t, i = 10*q*i*(2*i-1), 10*u*(q*(5*i-2)+r-y*t), t*u, i+1

def g3_md():
  # Gosper, multi-digit
  q, r, t = mpz(1), mpz(0), mpz(1)
  i, j = 1, 60
  z = mpz(10)**50
  while True:
    n = (q+r)/t
    if n*t > 6*i*q+r-t:
      for d in digits(n, i>38 and 50 or 1): yield d
      q, r = z*q, z*(r-n*t)
    u, v, x = 1, 0, 1
    for k in range(37):
      u, v, x = u*i*(2*i-1), j*(u*(5*i-2)+v), x*j
      i += 1; j += 54*i
    q, r, t = q*u, q*v+r*x, t*x

def g4_md():
  # Ramanujan 39, multi-digit
  q, r, s ,t = mpz(0), mpz(3528), mpz(1), mpz(0)
  i = 1
  z = mpz(10)**3511
  while True:
    n = (q+r)/(s+t)
    if n == (22583*i*q+r)/(22583*i*s+t):
      for d in digits(n, i>597 and 3511 or 1): yield d
      q, r = z*(q-n*s), z*(r-n*t)
    u, v, x = mpz(1), mpz(0), mpz(1)
    for k in range(596):
      c, d, f = i*(i*(i*32-48)+22)-3, 21460*i-20337, -i*i*i*24893568
      u, v, x = u*c, (u*d+v)*f, x*f
      i += 1
    q, r, s, t = q*u, q*v+r*x, s*u, s*v+t*x

def digits(x, n):
  o = []
  for k in range(n):
    x, r = divmod(x, 10)
    o.append(r)
  return reversed(o)

Notes
Above are 6 implementations: the two reference implementations provided by the author (denoted _ref), and four that compute terms in batches, generating multiple digits at once (_md). All implementations have been confirmed to 100,000 digits. When choosing batch sizes, I chose values that slowly lose precision over time. For example, g1_md generates 10 digits per batch, with 33 iterations. However, this will only produce ~9.93 correct digits. When precision runs out the check condition will fail, triggering an extra batch to be run. This seems to be more performant than slowly gainly extra, unneeded precision over time.

g1 (Leibniz/Euler)
An extra variable j is kept, representing 2*i+1. The author does the same in the reference implementation. Calculating n separately is far simpler (and less obscure), because it uses the current values of q, r and t, rather than the next.
g2 (Lambert)
The check n == q/s is admittedly quite lax. That should read n == (q*(k+2*j+4)+r)/(s*(k+2*j+4)+t), where j is 2*i-1 and k is i*i. At higher iterations, the r and t terms become increasingly less significant. As is, it's good for the first 100,000 digits, so it's probably good for all. The author provides no reference implementation.
g3 (Gosper)
The author conjectures that it is unnecessary to check that n will not change in subsequent iterations, and that it only serves to slow the algorithm. While probably true, the generator is holding onto ~13% more correct digits than it has currently generated, which seems somewhat wasteful. I've added the check back in, and wait until 50 digits are correct, generating them all at once, with a noticable gain in performance.
g4 (Ramanujan 39)
Calculated as

Unfortunately, s doesn't zero out, due to the initial (3528 ÷) composition, but it's still significantly faster than g3. Convergence is ~5.89 digits per term, 3511 digits are generated at a time. If that's a bit much, generating 271 digits per 46 iterations is also a decent choice.

Timings
Taken on my system, for purposes of comparison only. Times are listed in seconds. If a timing took longer than 10 minutes, I didn't run any further tests.
            |  g1_ref |  g1_md  |  g2_md  |  g3_ref |  g3_md  |  g4_md
------------+---------+---------+---------+---------+---------+--------
    10,000  |  1.645  |  0.229  |  0.093  |  0.312  |  0.062  |  0.062
    20,000  |  6.859  |  0.937  |  0.234  |  1.140  |  0.250  |  0.109
    50,000  |  55.62  |  5.546  |  1.437  |  9.703  |  1.468  |  0.234
   100,000  |  247.9  |  24.42  |  5.812  |  39.32  |  5.765  |  0.593
   200,000  |  2,158  |  158.7  |  25.73  |  174.5  |  33.62  |  2.156
   500,000  |    -    |  1,270  |  215.5  |  3,173  |  874.8  |  13.51
 1,000,000  |    -    |    -    |  1,019  |    -    |    -    |  58.02

It's interesting that g2 eventually overtakes g3, despite a slower rate of convergence. I suspect this is because the operands grow at a significantly slower rate, winning out in the long run. The fastest implmentation g4_md is approximately 235x faster than the g3_ref implmentation on 500,000 digits. That said, there's still a significant overhead to streaming digits in this way. Calculating all digits directly using Ramanujan 39 (python source) is approximately 10x as fast.
Why not Chudnovsky?
The Chudnovsky algorithm requires a full precision square root, which I'm honestly not sure how to work in - assuming it could be at all. Ramanujan 39 is somewhat special in this regard. However, the method does seem like it might be conducive to Machin-like formulas, such as those used by y-cruncher, so that might be an avenue worth exploring.

TIL Ideone supports Pypy. So is the 2nd program built for speed?

@mbomb007 "So is the 2nd program built for speed?" It is. I think the challenge would have been equally as interesting as a [tag:fastest-code].

Same. I considered both. Idk how people feel about re-posting under a different tag. It might be more useful if it's to be added to the OEIS (which doesn't contain this sequence)

Python 2, 298 bytes
Note, the code for generating pi is taken from the OP's implementation.
def p():
 q,r,t,j=1,180,60,2
 while 1:
  u,y=3*(3*j+1)*(3*j+2),(q*(27*j-12)+5*r)//(5*t)
  yield y
  q,r,t,j=10*q*j*(2*j-1),10*u*(q*(5*j-2)+r-y*t),t*u,j+1
p=p()
c=r=0
d=[0]
while 1:
 t=p.next()
 if t==d[len(d)-1]:d.append(t)
 else:d=[t]
 if len(d)>r:r=len(d);print"".join([`int(x)`for x in d])
 c+=1

My first attempt at golfing in Python. Outputs the sequence forever.

Could you please explain how you calculate π here? You, of course, calculate pi, right?

Can't test right now, but aren't you calculating π forever there?

@TuukkaX doesn't appear so as it has a yield which stops it, but I'm not very good at python

Downgoat is correct - it uses a generator function.

I'm obviously no good at Python either - I always thought // was a Python 3 operator.

Oh, right. Didn't look at the p.next() there.

I wrote all the code, I didn't look at your implementation except the p part

Haskell, 231 bytes
import Data.List
g(q,r,t,k,n,l)|4*q+r-t<n*t=n:g(10*q,10*(r-n*t),t,k,div(10*(3*q+r))t-10*n,l)|0<1=g(q*k,(2*q+r)*l,t*l,k+1,div(q*(7*k+2)+r*l)(t*l),l+2)
p=nubBy(\x y->length x==length y).concatMap inits.group$g(1,0,1,1,3,3)

This uses the Unbounded Spigot Algorithms for the Digits of Pi by Jeremy Gibbons, 2004. The result is p. Technically, it should support infinite output sequences, but that may take a while (and is bounded by your memory).

Python 3.5, 278 263 bytes:
import decimal,re;decimal.getcontext().prec=int(input());D=decimal.Decimal;a=p=1;b,t=1/D(2).sqrt(),1/D(4)
for i in[1]*50:z=(a+b)/2;b=(a*b).sqrt();t-=p*(a-z)**2;a=z;p*=2;pi=(z*2)**2/(4*t);i=0;C=lambda r:re.search(r'(\d)\1{%s}'%r,str(pi))
while C(i):print(C(i));i+=1

This takes in n as an input for the first n digits of π and then outputs the members of the sequence in those first n digits. Now, this uses Python's built in decimal module to go beyond Python's floating-point limitations, and then sets the precision, or epsilon, to however much the user inputs. Then, to calculate π, this goes through 50 iterations using the efficient Gausse-Legendre algorithm, since the algorithm apparently doubles the number of correct digits each time, and therefore, in 50 iterations, we can get up to 2^50 or 1,125,899,906,842,624 correct digits. Finally, after the calculations are done, it uses a regular expression with string formatting in a while loop to find and print re match objects (which I hope is okay) for all continuous, recurring digits 1 digit longer than in the previous iteration through the loop.
I was able to use this algorithm to successfully and accurately calculate π up to 10,000,000 (ten million) digits, which took about 4 hours and 12 minutes to complete. The following was the final output:
<_sre.SRE_Match object; span=(0, 1), match='3'>
<_sre.SRE_Match object; span=(25, 27), match='33'>
<_sre.SRE_Match object; span=(154, 157), match='111'>
<_sre.SRE_Match object; span=(763, 767), match='9999'>
<_sre.SRE_Match object; span=(763, 768), match='99999'>
<_sre.SRE_Match object; span=(763, 769), match='999999'>
<_sre.SRE_Match object; span=(710101, 710108), match='3333333'>

So, I can confidently say that the 8th number in the sequence does not even occur within the first 10 million digits! π is one random number...

source: Stack Exchange

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

sort: votes


text:
Is case sensitivity important? Part II: reality check
In this question Tom learned that, in general, there are many motivations to choose to include case sensitivity in his programming language, because the possible combinations for a variable name are much more than what's possible with a case insensitive programming language for a name of the same length.
But, as a more meticulous person than him pointed out, even with case sensitivity, many combinations like A_18__cDfG are wasted anyway because no one will ever use them, so Tom decided to be an even more meticulous person and to redo the calculation of the difference of possibilities of variable names between a case sensitive programming language and a case insensitive programming language only counting the variable names that are likely to be used.
The Challenge
Write a function (or a full program if your language doesn't support them) that takes an input n and returns (or outputs) the difference between the number of possible, valid combinations for a variable name of length n with case sensitivity and a variable name of the same length without case sensitivity.
Valid names
You must only count names in which:

The first character is either an alphabet letter or an underscore, but never a digit;
If there are digits, they must appear at the end of the name, so that x1 and arraysize12 are valid but iam6feettall isn't;
If underscores are present, they must appear at the beginning of the name, like in __private and _VERSION but unlike in __init__ or some_variable;
For case sensitive names, variables like HeLlObOyS aren't counted. A name must be either all uppercase (HELLOBOYS) or all lowercase (helloboys);
There must be at least one alphabetic character. This means _________a9999999999 is valid but __ or _4 arent't.

Rules

Regexs are, of course, allowed;
Blame Tom's meticulousness.

Testcases
Input (lenght of the varable name) -> Output (differences in valid combinations)
0 -> 0 (no combinations for both cases: 0 - 0 = 0)
1 -> 26
2 -> 962
3 -> 27898
4 -> 754234
5 -> 19898970
6 -> 520262106

Scoring
It's again code golf. Shortes program in bytes wins.
Reference, non-competing Lua implementation
Since the test cases may be wrong, I've been asked to include it, so here it is:
local case = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_0123456789"

local function isvalid(s)  --checks if a string s is valid AND only suitable for case sensitive
    if s:upper() == s then --if the string is all uppercase, it's also valid for case unsensitive
        return false
    end
    return (s:match"^_*[%w]+[%d]*$" --checks if it matchs the underscore-character-digit sequence
            and s:lower() == s)     --checks if it's all lowercase
            and true                --trasforms to boolean value
end

local function each(s, n) --recursive function called for character at position 2..n
    if n == 0 then
        if isvalid(s) then
            return 1
        end
        return 0
    else
        local total = 0
        for i = 1, #case do
            total = total + each(s..case:sub(i, i), n - 1)
        end
        return total
    end
end

local function diff(n) --the actual function
    local total = 0
    if n > 0 then
        for s = 1, #case - 10 do --loops for character at position 1, which can't be a digit
            total = total + each(case:sub(s, s), n - 1)
        end
    end
    print(string.format("%.0f", total)) --prints the result in non-scientific notation
end

@Zeta Tom's programming language's naming conventions don't allow that :-p it's to keep the challenge not too complicated.

I'm not sure whether the difference for 2 is correct. Valid names are either _<character>, <character><digit> or <character><character>. Without case sensitivity, we have 26 + 26 * 10 + 26 * 26 = 962 combinations. With case sensitivity, we have 52 + 2 * 26 * 26 + 52 * 10 = 1924 combinations. The difference is 962, but you state 926. Typo?

@Zeta actually, yes. Thanks for correcting me.

It's computationally impossible to have the execution time stay less than 2^n minutes as n increases, since each character adds more than double the previous number of names.

@Pietu1998 I'm removing the limit

@user6245072: I'm still not sure about your test cases. There are 27898 valid case-insensitive combinations for n = 3, and 55796 for case-sensitive ones. See answer below. Perhaps you want to add your own solution as reference?

%w matches alphanumerics, so your pattern allows for e.g. iam6feettall. Use %a for letters.

@Pietu1998 * facepalm *

@Pietu1998 That fixed everything. Thanks.

@Pietu1998: Err, it's easily possible to have the execution time less than 2^n minutes. Well, unless you start to create every valid string…

@Zeta well, now that I think of it, does seem simple with the mathematical approach.

Haskell, 41 bytes
d n=sum[26^a*10^k|a<-[1..n],k<-[0..n-a]]

Runtime: O(k*n²), where k depends on the size of the resulting numbers.
Results
ghci> forM_ [0..100] $ \n -> printf "%3d: %d\n" n (d n)
  0: 0
  1: 26
  2: 962
  3: 27898
  4: 754234
  5: 19898970
  6: 520262106
  7: 13555703642
  8: 352737183578
  9: 9174055661914
 10: 238554336098650
 11: 6202701627453786
 12: 161273131202687322
 13: 4193130300158759258
 14: 109021676693016629594
 15: 2834566482907321258330
 16: 73698757444479241605466
 17: 1916167982445349170631002
 18: 49820370432467967325294938
 19: 1295329660133056039346557274
 20: 33678571452348345911899378010
 21: 875642860649945882598272717146
 22: 22766714405787481836443979534682
 23: 591934574839363416636432356790618
 24: 15390298948712337721436130165444954
 25: 400147772695409669646228273190457690
 26: 10403842090369540299690823991840788826
 27: 270499894352496936680850312676749398362
 28: 7032997253193809242590997018484373246298
 29: 182857928583327929196254811369482593292634
 30: 4754306143169415047991513984495436314497370
 31: 123611959722433680136668252485770233065820506
 32: 3213910952783564572442263453518914948600222042
 33: 83561684772375567772387738680380677552494661978
 34: 2172603804081793650970970094578786505253750100314
 35: 56487698906126923814134111347937338025486391497050
 36: 1468680171559302908056375783935259677551535067812186
 37: 38185684460541904498354659271205640505228800652005722
 38: 992827795974089805846110029940235542024837705841037658
 39: 25813522695326337840887749667335012981534669240755867994
 40: 671151590078484812751970380239599226408790289148541456730
 41: 17449941342040605420440118775118468775517436406750966763866
 42: 453698474893055743820331977041969077052342235464414024749402
 43: 11796160347219449368217520291980084892249787010963653532373338
 44: 306700169027705683862544416480371096087383351173943880730595674
 45: 7974204394720347783315043717378537387160856019411429787884376410
 46: 207329314262729042395080025540730860955071145393586063373882675546
 47: 5390562170830955102560969552947891273720738669122126536609838453082
 48: 140154616441604832669474097265534062005628094286064178840744688669018
 49: 3644020027481725649435215417792774501035219340326557538748250794283354
 50: 94744520714524866885604489751501025915804591737379384896343409540256090
 51: 2463357538577646539028605622427915562699808274060752896193817536935547226
 52: 64047296003018810014772635072014693519083904014468464189928144849213116762
 53: 1665229696078489060384377400761270920385070393265068957827020654968429924698
 54: 43295972098040715569996701308681932818900719113780681792391425918068066931034
 55: 1125695274549058604819943122914619142180307585847186615491065962758658629095770
 56: 29268077138275523725318810084668986585576886120915740891656603920614013245378906
 57: 760970005595163616858291951090282540113887928032698152071960590824853233268740442
 58: 19785220145474254038315619617236234931849975017739040842759864250335072953876140378
 59: 514415723782330604996206398937030997116988239350103950800645359397600785689668538714
 60: 13374808818340595729901369261251694813930583111991591609705668233226509316820270895450
 61: 347745029276855488977435629681432954051084049800670270741236262952778131126215932170586
 62: 9041370761198242713413326660606145694217074183706315928161031725661120298170503125324122
 63: 235075639791154310548746496064648676938532817665253103021075713756078016641321970147316058
 64: 6111966634570012074267408926569754489290742148185469567436857446546917321563260112719106394
 65: 158911132498820313930952632379702505610448184741711097642247182499108739249533651819585655130
 66: 4131689444969328162204768444761154034760541692173377427587315633865716109376763836198115922266
 67: 107423925569202532217323979592678893792662972885396702006159095369397507732684748630039902867802
 68: 2793022064799265837650423469698540127498126183909203141049025368493224089938692353269926363451738
 69: 72618573684780911778911010215050932203840169670528170556163548469712715227294890073906974338634074
 70: 1888082915804303706251686265620213126188733300322621323349141149101419484798556030810470221693374810
 71: 49090155810911896362543842906414430169795954697277043295966558765525795493651345689961114652916633946
 72: 1276344051083709305426139915569664073303583711018092014584019416792559571723823876827877869864721371482
 73: 33184945328176441941079637804840154794782065375359281268073393725495437753708309686413713505371644547418
 74: 862808578532587490468070582926132913553222588648230201858797125751770270485304940735645440028551647121754
 75: 22433023041847274752169835156082344641272676193742874137217614158434915921506817348015670329631231714054490
 76: 583258599088029143556415714058169849561978469926203616456546857008196702848066139937296317459300913454305626
 77: 15164723576288757732466808565512704977500329106970182916759107171102003162938608527258593142830712638700835162
 78: 394282812983507701044137022703333218303897445670113644724625675337540971125292710597612310602487417495110603098
 79: 10251353137571200227147562590286692564790222476311843651729156447664954138146499364426808964553561743761764569434
 80: 266535181576851205905836627347454295573434673272996823833846956528177696480697872363985921967281494226694767694170
 81: 6929914720998131353551752311033814573798190393986806308568909758621508997387033570352522860038207738782952848937306
 82: 180177782745951415192345560086879207807641839132545852911680542613048122820951761718054483249882290097245662961258842
 83: 4684622351394736795000984562258859691887576706335081064592582996828140082233634693558305453385828431417276125881618778
 84: 121800181136263156670025598618730354877965883253600996568296046806420531026963390921404830676920428105738068161810977114
 85: 3166804709542842073420665564086989255716001853482514799664586105855822695589937052845414486488820019638078661095974293850
 86: 82336922448113893908937304666261720937504937079434273680168127641140278974227252262869665537598209399478934077384220528986
 87: 2140759983650961241632369921322804747264017252954180004573260207558536142218797447723500192866442333275341174900878622642522
 88: 55659759574924992282441617954392923457753337465697569007793654285410828586577622529699893903416389554047759436311733077594458
 89: 1447153748948049799343482066814216010190475662997025683091523900309570432139907074661086130377715017294130634232993948906344794
 90: 37625997472649294782930533737169616267841256126811556649268510296937720124526472830077128278709479338536285378946731560453853530
 91: 978275934288881664356193877166410022992761548185989361769870156609269612126577182470894224135335351690832308741503909460689080666
 92: 25435174291510923273261040806326660598100689141724612294905512960729898804179895633132138716407608032850528916167990534866804986202
 93: 661314531579284005104787060964493175553506806573728808556432225867866257797566175350324495515486697743002640709256642795425818530138
 94: 17194177821061384132724463585076822564420065859805837911356126761453411591625609447997325772291543030206957547329561601569960170672474
 95: 447048623347595987450836053211997386675210601243840674584148184686677590271154734536819358968469007674269785119457490529707853326373210
 96: 11623264207037495673721737383511932053558364521228746428076741690742506235938911986846192222069083088419903301994783642661293075374592346
 97: 302204869382974887516765171971310233392546366440836296018884172848194051023300600546889886662685049187806374740753263598082508848628289882
 98: 7857326603957347075435894471254066068206494416350632585379877382941934215494704503108025942118700167771854632148473742439034118953224425818
 99: 204290491702891023961333256252605717773371743714005336108765700845379178491751205969697563383975093250957109324749206192303775981672723960154
100: 5311552784275166622994664662567748662107694225453027627716797110868747529674420244101025536872241313413773731332368249888787064412379711852890
(0.72 secs, 632,190,360 bytes)

Ungolfed
difference :: Integer -> Integer
difference n = sum [ 26 ^ alpha * 10 ^ digits
                   | alphas <- [1 .. n]
                   , digits <- [0 .. n - alphas]
                   ]

Explanation
All valid names have the structure, namely [underscore]alpha[alpha][digit]. We have at least one alphabet letter, arbitrary many underscores, and arbitrary many digits (as long as the resulting string has the correct length). The position of those is fixed by Tom's rules.
The number of valid case-insenstive combinations can be calculated as follows (a is the number of alphabet letters, u the number of underscores):
$$
c(n) = \sum_{a=1}^n \sum_{u=0}{n-a} 26^a \cdot 10^{n - a - u}
$$

The number of valid case-sensitive combinations can be calculated similarly, we just add \sum_{\{L,U\}}:
$$
C(n) = \sum_{\{L,U\} \sum_{a=1}^n \sum_{u=0}{n-a} 26^a \cdot 10^{n - a - u} \\
     = 2 \sum_{a=1}^n \sum_{u=0}{n-a} 26^a \cdot 10^{n - a - u}
$$

The difference C(n) - c(n) is… c(n):

So all we have to do is to find out is the count of case-insensitive variants.

I posted the reference implementation. It loops over each case sensitive possibility. If it is all lowercase (like __varaiablename123) then it's only a case sensitive variable. + 1 to the total. If it's all uppercase(VARIABLENAME) it can be either case sensitive and case insensitive. + 1 to the total, - 1 to the total. If it's mixed, it's not suitable for either case sensitive variables and case unsensitive. So + 0 to the total. That's what I thought when implementing it.

exactly. If I remember correctly, string.sub(str, i) matches everything from i to the end of the string, so I use string.sub(str, i, i) to match only one.

+1 for the overly complicated math proof. Correct me if I'm wrong but isn't it sufficient to say that since the case-sensitive names have to be all uppercase or all lowercase, there are just twice as many combinations possible?

@PatrickRoberts: Ayup. The original proof was "well, if case doesn't matter, we only have to count lower case, if case matters, they have to choose one of two cases, therefore, there are twice as many".  However, the numbers in the original version didn't agree, and I suspected an error on my side, rather than on OPs.

JavaScript (ES7), 55 bytes
n=>[...Array(n)].reduce(r=>r+26**++i*(10**n---1)/9,i=0)

I get the same results as @Zeta does. I started along similar lines although I simplified sum(10**[0..n-i]) to (10**(n+1-i)-1)/9.

How could you get the same results? JavaScript's integer precision is only guaranteed for 53 bits.

@PatrickRoberts At the time, Zeta disagreed with the test cases that were there, and I agreed with him rather than them.

Oh, alright. That makes more sense

Pyth, 25 18 16 bytes
sm*^26ds^LTh-QdS

Try it online. Test suite.
I also get the same results as @Zeta.

05AB1E, 18 14 bytes
Lv1¹y->×26ym*O

Explanation
Lv               # for each n in range(1,input)
  1¹y->×         # push 1 repeated (input-n+1) nr of times
        26ym     # 26^n
            *    # multiply the ones by the power of 26
             O   # sum and implicitly print

Try it online

Racket, 91 82 Bytes
Old solution (based off @Zeta's solution):
(λ(n)(for*/sum([i(in-range 1(+ 1 n))][j(in-range(+ 1(- n i)))])(*(expt 26 i)(expt 10 j))))

New solution (thanks to Neil's solution):
(λ(n)(for/sum([i(in-range 1(+ 1 n))])(*(expt 26 i)(/(-(expt 10(-(+ n 1)i))1)9))))

Emacs lisp, 106 bytes
(defmath f(n)(let((r 0))(for((k 1(1+ n)))(setq r(+ r(*(^ 26 k)(/(1-(^ 10(- n k -1)))9)))))(calc-eval r)))

Creates a function called calcFunc-f. Pretty much the first (Emacs) lisp I've written, uses Neil's optimization.

Wow. That's a lot different than what I saw written in Common Lisp.

@user6245072 I have no idea whether it's idiomatic. I use the (included) calc package, since it supports arbitrary large numbers.

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


text:
Calculate A190810
Your task is pretty simple, calculate the n-th element of A190810.
Elements of A190810 are calculated according to these rules:

The first element is 1
The sequence is increasing
If x occurs in the sequence, then 2x+1 and 3x-1 also do

You can use 1-based or 0-based indexing, but if you use 0-based indexing, please say it in the answer.
Test cases
a(1) = 1
a(2) = 2
a(3) = 3
a(4) = 5
a(5) = 7
a(10) = 17
a(20) = 50
a(30) = 95
a(55) = 255

Since this is code-golf, the shortest answer in bytes wins!

You should add larger test cases.

Can we use zero-based indexing?

@Pietu1998 Yeah, i'll clarify that

Can you explain this a little more clearly? I'm a native English speaker and I have no idea what "... and if x is in a then 2x+1 and 3x-1 are in a." is supposed to mean.

@cat x ϵ A → (2*x) + 1 ϵ A and x ϵ A → (3*x)-1 ϵ A, where ϵ means "is a member of" and → can be understood as "implies".

A000027 also satisfies all three rules unless you also specify that 1 is the only element not generated by rule 3.

Implied condition: The sequence does not contain numbers not required by the other rules. (Otherwise $a(i)=i$ would be a valid sequence)

And you get free Mathematica and Haskell answers to start from :)

Jelly, 16 bytes
×3’;Ḥ‘$;
1Ç¡ṢQ³ị

Very inefficient. Try it online!
How it works
1Ç¡ṢQ³ị   Main link. Argument: n (integer)

1         Set the return value to 1.
 Ç¡       Execute the helper link n times.
   Ṣ      Sort the resulting array.
    Q     Unique; deduplicate the sorted array.
     ³ị   Retrieve its n-th element.

×3’;Ḥ‘$;  Helper link. Argument: A (array)

×3        Multiply all elements of A by 3.
  ’       Decrement the resulting products.
      $   Combine the two links to the left into a monadic chain.
    Ḥ     Unhalve; multiply all elements of A by 2.
     ‘    Increment the resulting products.
   ;      Concatenate 3A-1 and 2A+1.
       ;  Concatenate the result with A.

That may be 16 characters, but I don't know of any encoding that represents that in less than 30 bytes.

Jelly has it's own codepage which allows for these characters being 1 byte each.

Python 2, 88 83 72 bytes
You may want to read the programs in this answer in reverse order...
Slower and shorter still, thanks to Dennis:
L=1,;exec'L+=2*L[0]+1,3*L[0]-1;L=sorted(set(L))[1:];'*input()
print L[0]

Try it online

This doesn't run as fast, but is shorter (83 bytes.) By sorting and removing duplicates each iteration, as well as removing the first element, I remove the need for an index into the list. The result is simply the first element after n iterations.
I may have out-golfed Dennis. :D
L=[1]
n=input()
while n:L+=[2*L[0]+1,3*L[0]-1];n-=1;L=sorted(set(L))[1:]
print L[0]

Try it online

This version below (88 bytes) runs really fast, finding the 500000th element in about two seconds.
It's pretty simple. Compute elements of the list until there are three times more elements than n, since every element added may add at most 2 more unique elements. Then remove duplicates, sort, and print the nth element (zero-indexed.)
L=[1]
i=0
n=input()
while len(L)<3*n:L+=[2*L[i]+1,3*L[i]-1];i+=1
print sorted(set(L))[n]

Try it online

Python 2, 59 bytes
t={1}
exec'm=min(t);t=t-{m}|{2*m+1,3*m-1};'*input()
print m

Based on @mbomb007's Python answer. Test it on Ideone.

"One does not simply outgolf Dennis"... I wish I'd thought of using set literals. It seems so obvious now. Is this answer even faster than my "fast" program if you change from executing a string to actual code?

Nope. It's slower. Set operations are more expensive.

Yeah, min is O(n) while list indexing is O(1), so this solution is at least O(n²)...

Haskell, 76 73 69 bytes
a#b=mod a b<1&&t(div a b)
t x=x<2||(x-1)#2||(x+1)#3
(filter t[1..]!!)

Uses a 0-based index. Usage example: (filter t[1..]!!) 54 -> 255.
Instead of building the list by repeatedly inserting 2x+1 and 3x-1 as seen in most other answers, I go through all integers and check if they can reduced to 1 by repeatedly applying (x-1) / 2 or (x+1) / 3 if divisible.

That doesn't really define a function or a valid code snippet, does it?

@Zeta The last line evaluates to an unnamed function.

@Zgarb Which is an error in a Haskell file, and no interpreter I'm aware off supports this kind of feature. So, please, enlighten me, how is a user supposed to use this without modifying the code above in any way? Or could you point me to a meta post that allows this kind of code?

(I'm aware of http://meta.codegolf.stackexchange.com/questions/1501/should-function-literals-be-allowed-when-a-function-is-asked-for/1503#1503, but that considers a single expression, where the code above isn't a single expression).

@Zgarb I think for the last line, assign it to a binding (like f=filter t[1..]!!), because I don't think this is correct.

@TùxCräftîñg On this Meta post, it was determined that additional helper functions are acceptable by default in this situation. This is also the format that I usually see for Haskell answers here. Of course, you as the challenge author have the final authority.

@Zgarb If this is acceptable, so you don't need to change it.

@TùxCräftîñg: there's also this meta post, which also allows unnamed functions that depend on definitions made outside the function body.

Haskell, 77 74 bytes
import Data.List
i=insert
f(x:y)=x:f(i(2*x+1)$i(3*x-1)y)
a=(!!)(nub$f[1])

This provides a function a for the n-th entry. It's zero indexed. Alternatively, a=nub$f[1] will create the whole list (lazily).
It's a list-variant of Reinhard Zumkeller's Set code.

Why not y instead of xs to save two bytes? Also, I believe that you may be able to cut down the last line to something like (!!)$nub.f[1]

@MichaelKlein: I'm just too used to (x:xs), completely forgot that, thanks.

Pyth, 20 19 bytes
hutS{+G,hyhGt*3hGQ0

Try it online. Test suite.
Uses zero-based indexing.

@Jakube Thanks. I wonder how I didn't figure that out when I tried just 1 and it obviously didn't work.

Python 2, 88 84 bytes
g=lambda k:g(k%2*k/2)|g(k%3/2*-~k/3)if k>1else k
f=lambda n,k=1:n and-~f(n-g(k),k+1)

Test it on Ideone.

You're a pro at turning something simple into something unreadable.

Brachylog, 45 bytes
:1-I,?:?*:1ydo:Im.
1.|:1-:1&I(:3*:1-.;I*:1+.)

Computes N = 1000 in about 6 seconds on my machine.
This is 1-indexed, e.g.
run_from_file('code.brachylog',1000,Z).
Z = 13961 .

Explanation

Main predicate:
:1-I,               I = Input - 1
     ?:?*           Square the Input
         :1y        Find the first Input*Input valid outputs of predicate 1
            do      Remove duplicates and order
              :Im.  Output is the Ith element

Predicate 1:
1.                  Input = Output = 1
|                   Or
:1-:1&I             I is the output of predicate 1 called with Input - 1 as input
       (
         :3*:1-.      Output is 3*I-1
       ;            Or
         I*:1+.       Output is 2*I+1
       )

You may note that we don't pass any input to predicate 1 when we call y - Yield. Because of constraint propagation, it will find the right input once reaching the 1. clause which will propagate the correct input values.

05AB1E, 18 17 bytes
Uses CP-1252 encoding.
$FÐ·>s3*<)˜Ù}ï{¹è

Explanation
$                  # initialize with 1
 F          }      # input number of times do
  Ð                # triplicate current list/number
   ·>              # double one copy and add 1
     s3*<          # multiply one copy by 3 and subtract 1
         )˜Ù       # combine the 3 lists to 1 list and remove duplicates
             ï{    # convert list to int and sort
               ¹è  # take the element from the list at index input

Try it online for small numbers
Very slow.
Uses 0-based indexing.

JavaScript (ES6), 63 bytes
f=(n,a=[1],i=0)=>a[i++]?--n?f(n,a,a[i*2]=a[i*3-2]=1):i:f(n,a,i)

Probably gives up quickly due to the recursion.

MATL, 19, 18 17 bytes
1w:"tEQy3*qvSu]G)

This is an extremely inefficient algorithm. The online interpreter runs out of memory for inputs greater than 13.
One byte saved, thanks to Luis Mendo!
Try it online!
This version is longer, but more efficient (21 bytes)
1`tEQy3*qvSutnG3*<]G)

Try it online
Explanation:
The logical way to do it, is to add elements to the array until it is long enough to grab the i'th element. That's how the efficient one works. The golfy (and inefficient) way to do it, is to just increase the array size i times.
So first, we define the start array: 1. Then we swap the top two elements, so that input is on top. w. Now, we loop through the input with :". So i times:
t             %Duplicate our starting (or current) array.
 EQ           %Double it and increment
   y          %Push our starting array again
    3*q       %Multiply by 3 and decrement
       v      %Concatenate these two arrays and the starting array
        Su    %Sort them and remove all duplicate elements.

Now, we have a gigantic array of the sequence. (Way more than is needed to calculate) So we stop looping, ], and grab the i'th number from this array with G) (1-indexed)

@LuisMendo Thanks for the tip! How would you rewrite this with a while loop instead of the for loop? (Maybe that would be a better question for the MATL chat room)

It could be done this way: 1\tEQy3*qvuStnG<]G). The loop condition is tnG<` (exit when the array already has the required size)

Not sure how much cheating it is, but in the for-loop version you can take the input in unary as a string and remove the :

Clojure, 114 108 bytes
#(loop[a(sorted-set 1)n 1](let[x(first a)](if(= n %)x(recur(conj(disj a x)(+(* 2 x)1)(-(* 3 x)1))(inc n)))))

I wouldn't be surprised if this could be golfed/reduced by a significant amount but set's not supporting nth really hurt my train of thought.
Try the online
Version with spaces:
#(loop [a (sorted-set 1)
        n 1]
  (let [x (first a)]
    (if (= n %)
      x
      (recur (conj (disj a x) (+ (* 2 x) 1) (- (* 3 x) 1)) (inc n))
      )))

Retina, 57
^.+
$*¶¶1
¶¶(1(1*))
¶1$1$1¶$2$1$1
O`
}`(¶1+)\1\b
$1
G2`
1

Try it online!
0-indexed. Follows the frequently used algorithm: remove the minimum value from the current set, call it x, and add 2x+1 and 3x-1 to the set a number of times equal to the input, then the leading number is the result. The "set" in Retina is just a list that is repeatedly sorted and made to contain only unique elements. There are some sneaky bits added to the algorithm for golf, which I will explain once I've had some more time.
Big thanks to Martin for golfing off around 20 bytes!

C++, 102 bytes
[](int i){int t;map<int,int>k;for(k[1];i--;k.erase(t))t=k.begin()->first,k[t*2+1],k[t*3-1];return t;};

This lambda function requires #include <map> and using std::map.
The map here is just a collection of keys; their values are ignored. I use map in order to benefit from the terse code for insertion:
k[1]; // inserts the key 1 into the map

Thanks to the sorted order of map, the smallest element is  extracted by k.begin()->first.

Slightly shorter (97) using set and initializer lists: [](int i){int t;set<int>k{1};for(;i--;k.erase(t))t=*k.begin(),k.insert({t*2+1,t*3-1});return t;};.

Actually, 27 bytes
╗1#╜`;;2*1+)3*1@-#++╔S`n╜@E

Try it online!
This program uses 0-based indexing. The approach is very brute-force, so don't expect it to work in the online interpreter for larger inputs.
Explanation:
╗1#╜`;;2*1+)3*1@-#++╔S`n╜@E
╗                            save input (n) in register 0
 1#                          push [1]
   ╜                         push n
    `;;2*1+)3*1@-#++╔S`n     do the following n times:
     ;;                        make two copies of the list
       2*1+                    apply 2x+1 to each element in one copy
           )3*1@-              and 3x-1 to each element in the other copy
                 #             workaround for a weird list bug
                  ++           append those two lists to the original list
                    ╔S         uniquify and sort
                        ╜@E  get the nth element (0-indexed)

Ruby, 70 bytes
->n{a=*1
n.times{a<n{
    # Magical, golfy way of initializing an array. Equivalent to a = [1].
    a=*1
    n.times{
        # Generate the next element in the sequence, by...
        a<<
            # ... finding the minimal term that will appear at some point.
            a.map{|i|
                ([2*i+1,3*i-1]-a).min||1.0/0
            }.min
    }
    # We generated n+1 elements, so we'll take the *second* to last one.
    a[-2]
}

That *1 trick is neat

CJam (25 bytes)
ri1a1${{_2*)1$3*(}%_&}*$=

Online demo. Note that this uses zero-based indexing.
This uses a similar approach to most: apply the transforms n times and then sort and extract the nth item. As a nod to efficiency the deduplication is applied inside the loop and the sorting is applied outside the loop.

22: 1ari{(_2*)\3*(@||$}*0= (Also a lot more efficient.)

Retina, 48 bytes
.+
$*
+1`^(((!*)!(!|\3)(?=\3!1))*!)1|\b
!$1
-2`.

Try it online!
Inspired by nimi's answer I thought I'd try a different approach for Retina, making use of the regex engine's backtracking to figure out if any given (unary) number is in the sequence or not. It turns out this can be determined with a 27 byte regex, but making use of it costs a few more, but it still ends up shorter than the generative approach.
Here's an alternative 48-byte solution:
.+
$*
{`1\b
1!
}T`1``1((!*)!(!|\2)(?=!\2$))*!$
!

And using unary I/O we can do 42 bytes, but I'm trying to avoid that and the other Retina answer uses decimal as well:
1\b
1!
}T`1``1((!*)!(!|\2)(?=!\2$))*!$
!
1

Perl, 173 132 bytes +1 for -n = 133
sub c{my$a=pop;return($a==1||($a%2&&c(($a-1)/2))?1:$a%3!=2?0:$a%3==2?c(($a+1)/3):1)}while($#b<$_){$i++;@b=(@b,$i)if c$i}say$b[$_-1];

Ungolfed:
my @array = ();
my $n = <>;
sub chk {
    my $a = shift;
    return 1 if ($a == 1);
    if ($a % 2 == 0) {
        if ($a % 3 != 2) {
            return 0;
        } else {
            return chk(($a + 1) / 3);
        }
    } else {
        if (chk(($a - 1) / 2) == 0) {
            if ($a % 3 != 2) {
                return 0;
            } else {
                return chk(($a + 1) / 3);
            }
        } else {
            return 1
        }
    }
}
my $i = 1;
while ($#array < $n-1) {
    push(@array,$i) if (chk($i) == 1);
    $i++;
}
print $array[$n];

I can probably do better if I thought more about it, but this is what I came up with after just a few minutes.  My first time golfing, so this was pretty fun!
Thanks to @Dada and @TùxCräftîñg (and a bunch of minor byte-optimizations) for -40 bytes

I think you can drop the spaces after the mys, the return and the print (Can't test, don't have perl)

@TùxCräftîñg is right about the return. The print can be replace by a say. Most of the my aren't needed (you need only the one before $a in the function I think. Don't initialize nor declare @b. You can probably drop the initialisation of $i if you do $i++ at the start of the while instead of at the end. pop is shorter than shift. Keep in mind than there is much more to perl golfing than just removing whitespaces and newlines...

Factor, 73 bytes
[ { } 1 rot [ { 2 3 } n*v { 1 -1 } v+ union natural-sort unclip ] times ]

Try it online!
Found a hidden golfing gem unclip which, given an array, returns rest first on the stack. It is especially helpful that first is on top of the stack. Using the unclip-ed state as the loop invariant, I could save a byte from swap vs. rot and six bytes from saving first at the end.
[                          ! anonymous lambda
  { } 1 rot [ ... ] times  ! setup stack as ( rest min ) and call n times...
    { 2 3 } n*v            !   ( rest {2*min,3*min} )
    { 1 -1 } v+            !   ( rest {2*min+1,3*min-1} )
    union natural-sort     !   set union of rest and next two numbers, sorted
    unclip                 !   extract first item (= next min)
]

J, 31 bytes
{1(]]/:~@~.@,3&*,&:<:2*>:)^:[~]

Uses zero-based indexing. Very memory-inefficient.
Explanation
{1(]]/:~@~.@,3&*,&:<:2*>:)^:[~]  Input: n
                              ]  Identity function, gets n
 1                               The constant 1
  (                      )^:[~   Repeat n times with an initial array a = [1]
                       >:          Increment each in a
                     2*            Multiply by 2 to get 2a+2
             3&*                   Multiply each in a by 3 to get 3a
                 &:<:              Decrement both x and y to get 2a+1 and 3a-1
                ,                  Join them
    ]                              Identity function, gets a
            ,                      Join a with 2a+1 and 3a-1
         ~.@                       Take the distinct values
     /:~@                          Sort up
   ]                               Return the sorted list
{                                Select the value from the list at index n and return it

Octave, 68 bytes
function r=a(n)s=1;for(i=1:n)r=s(i);s=union(s,[r*2+1 r*3-1]);end;end

You can remove the final ;end

On the version I use, at least (4.0.0) you cannot...

JavaScript (ES6), 58
n=>(a=>{for(;n;)a[++i]?a[i-~i]=a[3*i-1]=--n:0})([i=0,1])|i

Less golfed
n=>{
  a=[];
  a[1] = 1;
  for(i = 0; n;)
  {
    ++i
    if (a[i])
    {
      a[2*i+1] = 1;
      a[3*i-1] = 1;
      --n;
    }
  }
  return i
}

Test
About time and memory: element 500000 in ~20 sec and 300MB used by my FireFox 64 bit alpha

F=
n=>(a=>{for(;n;)a[++i]?a[i-~i]=a[3*i-1]=--n:0})([i=0,1])|i

function test() {
  var n=+I.value, t0=+new Date
  O.textContent = F(n)
  console.log((+new Date-t0)/1000,'sec')
}

test()
#I { width:5em}
<input id=I type=number value=10 oninput="test()">

Husk, 17 bytes
!OuΞ¡ṁ§eo←*3o→D;1

Try it online!
There should be a shorter way using set difference.
This answer creates all the possibilities, merges them and deduplicates.

Perl 5 -p, 82 bytes
$;{1}++;map@;{$_*2+1,$_*3-1}=1,keys%;while$_*3>keys%;;$_=(sort{$a-$b}keys%;)[$_-1]

Try it online!

TI-Basic, 74 bytes
Input N
{1→A
For(I,1,N
1+2ʟA(I
If min(Ans≠ʟA
augment(ʟA,{Ans→A
3ʟA(I)-1
If min(Ans≠ʟA
augment(ʟA,{Ans→A
End
SortA(ʟA
ʟA(N

Uses 1-based indexing. Output is stored in Ans and is displayed.

Wolfram Language (Mathematica), 37 bytes
Nest[Union[#,2#+1,3#-1]&,{1},#][[#]]&

Try it online!

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


text:
Thwart Lepton compression
Dropbox recently released Lepton (GitHub), a method that losslessly compresses JPEG images round-trip, saving an average of 22%.

Because of the pigeonhole principle, any general compression algorithm cannot be guaranteed to result in a smaller file (general because it doesn't apply to inputs constrained to a specific format). Lepton exploits common characteristics about JPEGs, which if subverted, might pigeonhole it to produce a file larger than the source.
Requirements
Write a program that generates:

A valid JPEG/JFIF image,
with a size between 0.5 MB and 1 MB,
no smaller than 256 × 256 px,
no larger than 4096 × 4096 px,
recognizable by Lepton (it can successfully "compress" to a .lep image), and
decompresses to an identical .jpg (as the input).
APPx, COM, and other metadata, non-graphical marker sections are restricted in the JPEG (injecting arbitrary amounts of random bytes into the image to asymptotically approach 1:1 compression is lame.)

an APP0 JFIF marker is permitted but no thumbnail is allowed (should be exactly 16 bytes)
tl;dr If you're not intentionally shoving metadata into an EXIF segment and you disable any sort of thumbnail your language library of choice wants to put into the image, that should be OK.

Post the code and image.
If you want to write a program that produces a Lepton image that when converted yields a JPEG meeting the criteria, that's fine. It must remain identical across arbitrarily many JPEG → Lepton → JPEG → ... cycles.
Scoring
The byte size of the Lepton image divided by the source JPEG image. Higher (worse Lepton compression) is better. Run Lepton with default flags and switches.

Getting Lepton
A 5-second crash-course to build Lepton:
git clone https://github.com/dropbox/lepton.git
cd lepton
./autogen.sh && ./configure && make

# fish shell: ./autogen.sh ;and ./configure ;and make

Then ./lepton --help should tell you things.

I think this could be retooled to a code golf challenge where you write code that generates an image that fails compression by at least some constant. Actually, it may just suffice to just put an upper bound on the code size that's much smaller than the size to hardcode the jpeg, but big enough for an reasonable program.

Is there any reason to expect that uniformly random pixels aren't the best answer?

@feersum you mean just like my example?

Also, because JPEG is a lossy format, there are many, many ways (e.g. "quality" among other things) to compress a given image. Each JPEG file includes a couple tables that dictate how the rest of the image is decoded, and those tables can basically be whatever. If you save a BMP image in different programs, it'll probably be identical. If you save a JPG in different programs, unless they use the same back-end library, probably not.

@feersum uniformly random input to a JPEG compressor doesn't result in uniformly random output, and that output is what lepton works on. If you can come up with an input that causes a JPEG compressor to produce uniformly random output, that would probably be useful here and elsewhere.

@Sparr Why would you have to use compression? I don't know anything about JPEG format but I would think there is some tool that allows saving in it without trying to compress it.

@feersum most image file formats include a form of compression (PPM and some BMP files being counterexamples to a degree, audio: WAV). Some can be lossless (PNG, GIF, audio: FLAC) or lossy (JPG, audio: MP3).

@feersum you're suggesting saving the jpeg with enough quality/detail that it's lossless? that's doable, but lepton isn't particularly applicable to that situation.

@Sparr that might be good for the challenge. Intentionally inflating the quality is an interesting tack.

Sure you're not missing ./configure in your steps? ./autogen.sh && ./configure && make?

BTW, mozjpeg already did implement arithmetic coding long time ago.

Python 3 + mozjpeg + /dev/urandom, 720×720: avg. score 102%
Depends on the mozjpeg package, the code assumes it's installed into /usr/local/opt/mozjpeg. (on OS X it's trivial to install, just run brew install mozjpeg)
Also it depends on /dev/urandom special file, it's used for generating random data.
The code simply feeds random data to mozjpeg compressor (in TGA format, because cjpeg understands it and it has very simple header), and lets it create an optimized jpeg file. Quality is set to the maximum because it makes DCT coefficients the least compressable, and it doesn't matter much what algorithm is used to compress uncompressable data.
I checked that the jpeg->lepton->jpeg cycle is lossless — it is true.
import subprocess
from subprocess import PIPE

c_mozjpeg_path = '/usr/local/opt/mozjpeg/bin/cjpeg'
cjpeg_params = '-quality 100 -dc-scan-opt 2 -dct float -targa'
image_size = 720

def write_random_tga_image(w, h, of, rf):
    def wb(value, size):
        of.write(int.to_bytes(value, size, 'little'))

    wb(0, 2)
    wb(3, 1)
    wb(0, 9)
    wb(w, 2)
    wb(h, 2)
    wb(8, 1)
    wb(0, 1)

    data_size = w * h
    while data_size > 0:
        data_size -= of.write(rf.read(data_size))

def main():
    with open('/dev/urandom', 'rb') as rf:
        with open('oops.jpg', 'wb') as f:
            p = subprocess.Popen((c_mozjpeg_path,) + tuple(cjpeg_params.split(' ')), stdin=PIPE, stdout=f)
            write_random_tga_image(image_size, image_size, p.stdin, rf)
            p.communicate()

if __name__ == '__main__':
    main()

Code is not golfed, obviously.
Example image:
Fun fact: generated JPEG file is larger than the source uncompressed TGA image, even though JPEG uses lossy compression.
Fun fact 2: Imgur (the default image hosting for SO) does very bad job at this file — for some reason it recompresses it to lower quality, even though it's less than 1MB. So I used Github to upload the example image.
Fun fact 3: In general, mozjpeg indeed does better JPEG compression while staying compatible with existing JPEG decoders. And it also has tool to losslessly optimize JPEG files, too — jpegtran.

I could use a cross-platform RNG (SystemRandom class for example) but I were too lazy. It's trivial and it should give similar results.

Naive Noise, 1024 × 1024: score 85.55%
A compliant example in Python to get the ball rolling. Not optimized in any way; probable shortcomings:

No idea what the default quality setting is.
Each 8x8 block has practically the exact same average value (~50%) to the one adjacent to it: Lepton says that they use that information to save space.
Totally default quantization and Huffman tables (whatever the library decides to use).

import numpy as np
from PIL import Image

np.random.seed(0) # make sure it's repeatable.

size = 1024

imgr = np.random.randint(0, 0xFF, (size, size, 3)).astype('uint8')
pimg = Image.fromarray(imgr)
pimg.save('noise.jpg')

Then some bash to do the thing:
./lepton noise.jpg noise.lep 2>\dev\null # vomits out a lot of technobabble
./lepton noise.lep noise-out.jpg 2>\dev\null

diff -qs noise.jpg noise-out.jpg

SIZE1=$(stat -f "%z" noise.jpg) # http://superuser.com/a/570920/18931
SIZE2=$(stat -f "%z" noise.lep)
RATIO=$(bc <<< "scale=4; $SIZE2/$SIZE1")
echo "$SIZE2/$SIZE1 = $RATIO"

# Files noise.jpg and noise-out.jpg are identical
# 538817/629769 = .8555


text:
Stock Time Machine
Stock Time Machine
You've gained access to a dataset, tomorrowStocks, which contains the stock prices from your favorite business on the NASDAQ. This dataset is a container indexed by minutes past opening. Each index contains the price of the stock at that time.
// Assume the stock market opens at 9:30AM EDT
// tomorrowStocks[] contains the prices of your target stock.
// If the stock is $22 @ 10:30AM EDT
tomorrowStocks[60] == 22

Output
Your task is to determine the best possible outcome of 1 purchase and 1 sale of 1 stock from the given dataset.
Gotchas

You must buy and sell exactly 1 stock.
You may not buy and sell in the same time slot.
You must buy before you sell.

Test Data
[1,2,3,4,5]    # 4
[1,99,2,105]   # 104
[99,1,99,100]  # 99
[99,1,1,2,1,3] # 2
[5,4,3,3,1]    # 0
[5,4,3,1]      # -1
[5,2,1]        # -1
[5,4,1]        # -1
[55,45,20,1]   # -10
[5,1]          # -4
[10,7,5,1]     # -2
[7]            # Invalid input -- assume size >= 2

This is a code-golf; submit the shortest answer in your favorite language!

Welcome to PPCG, nice first question! :)

Can we assume the output is deterministic (i.e. There is always one solution that is definitively the best, and no ties)

@SpeedyNinja -- Not sure I understand, but I'm leaning towards no under the assumption that you're asking if you can ignore inputs like [5,5,5,5,3,3].

Too bad the interpreter for a language I'm building isn't finished yet, as it should be able to solve this in 4 bytes... I need to finish that asap so I can't miss out on so many good questions!

@MrDuk I can imagine a situation where there are two equally valuable solutions to a sequence, can we assume that such a situation will never happen?

@SpeedyNinja This is actually in the test cases. In test case [5,4,3,1] you can either but for 5 and sell for 4 or buy for 4 and sell for 3 to get the optimal result of -1.

@Fawful You could add your answer as non-competing later. I would definetly be interested in seeing it

@CocoaBean, I'll let you know once I have it working.  I also realized that I could golf off an additional byte, so when everything is functional the solution should be 3 bytes.

05AB1E, 4 bytes
Using FryAmTheEggman's approach. Code:
¥ŒOà

Explanation:
¥     # Calculate the increments of the array.
 Œ    # Get all substring of the array.
  O   # Sum the arrays in the array.
   à  # Get the largest sum and implicitly print that.

Uses the CP-1252 encoding. Try it online!.

Dammit I tried 4 golfing languages and forgot about 05AB1E. That'll learn me for next time :P

Python 2, 46 bytes
f=lambda x:-min(x.pop(0)-max(x),x[1:]and-f(x))

Test it on Ideone.
How it works
This is a recursive approach that takes advantage of Python 2's beautifully perverse mixed-type comparisons.
The best possible outcome is either the difference of the maximum of the list with its first element removed and that first element, or another difference that does not involve the first element.
After extracting the first element with x.pop(0) (which permanently removes it from x), we compute x.pop(0)-max(x). Note that this difference has the "wrong" sign.
If the updated list x still contains at least two elements, x[1:] yields a non-empty list, and and replaces it with the negative of a recursive call, computed as -f(x). Once there are too few elements to continue, x[1:]and-f(x) evaluates to an empty list.
To select the maximal outcome, we take the minimum of the difference and the negative of the recursive call (or []). Since all integers are strictly less than [], min will simply return its left argument if the right one is [].
Finally, the unary minus - corrects the sign of the computed outcome.

This is strangely beautiful.

MATL, 7 bytes
2XN!dX>

Try it online! Or verify all test cases.
2XN  % Take input implicitly. Two-column 2D array with all combinations of 2 elements.
     % Each combination is a row. Elements in each row are in increasing order
!    % Transpose
d    % Difference of the two numbers in each column
X>   % Maximum value. Display implicitly

Turns out, this is the same idea as in Dennis' answer

Aww... Beat me to it!

Jelly, 5 bytes
Œcḅ-Ṁ

Try it online! or verify all test cases.
How it works
Œcḅ-Ṁ  Main link. Argument: A (integer array)

Œc     Generate all combinations of two elements of A, in order.
  ḅ-   Convert each pair from base -1 to integer.
       This maps [a, b] to b - a.
    Ṁ  Take the maximum of all computed differences.

Pyth, 9
eSsM.:-Vt

Try it here or run a Test Suite.
Finds the consecutive differences between each element, then finds each substring of that array. Finally, sum the elements and return the maximal one.
Explanation:
eSsM.:-Vt
eSsM.:-VtQQ   ## Auto-fill variables
      -VtQQ   ## Splat subtraction on each element of zip(Q[1:], Q)
    .:        ## Get all substrings
  sM          ## Sum each list
eS            ## Take the largest number

It was mentioned to me that that this algorithm works isn't entirely intuitive. Hopefully this example will illustrate why this algorithm works:
[a, b, c, d]
difference between each element (reversed because of how Pyth does this)
[b-a, c-b, d-c]
"substrings" or each continuous slice
[b-a], [c-b], [d-c], [b-a, c-b], [c-b, d-c], [b-a, c-b, d-c]
sum each
[b-a], [c-b], [d-c], [b-a+c-b], [c-b+d-c], [b-a+c-b+d-c]
simplify
[b-a], [c-b], [d-c], [c-a], [d-b], [d-a]

Pyth, 9
_hS-M.cQ2

Yay pfns!
_hS-M.cQ2

     .cQ2 # generate all 2-elements combinations of Q (argument)
   -M     # map-splat with -: for each combination, substract the elements together
  S       # tort
 h        # take the first
_         # absolute value

I believe _hS-M.cQ2 is equivalent.

@FryAmTheEggman ah, thanks. Now trying to think how I could reverse -'s argument order... since I have to use _hS and can't use eS

PowerShell v2+, 58 bytes
param($n)($n|%{($n[++$i..$n.count]|sort)[-1]-$_}|sort)[-1]

Takes input $n, pipes each element into a loop |%{...}. Each iteration, we slice $n based on pre-incremented ++$i to the end of the input array, |sort that, and take the maximal [-1], then subtract the current element $_. We then |sort all of those differences, and again take the maximal [-1].
Tosses out a verbose array-index error, because we try to slice past the end of the array. But, since STDERR is ignored by default, we don't care.

JavaScript (ES6), 57 54 bytes
a=>(m=Math.max)(...a.map((x,i)=>m(...a.slice(i+1))-x))

In JavaScript it's easier to take the max of the remainder of the array and subtract the current element. (In the case of the last element the result will still be -Infinity.) Edit: Saved 3 bytes thanks to @CharlieWynn.

I think (M=Math.max) and using M later will save you 3 bytes

@CharlieWynn Thanks, I'd only tried with (which doesn't help in this case).

J, 21 bytes
[:>./@;i.@#<@{."_1-/~

Takes an array of values as an argument and returns the result.
Explanation
[:>./@;i.@#<@{."_1-/~  Input: p
                  -/~  Make a table of all differences between every pair
          #            Get the count of values in p
       i.@             Create a range [0, 1, ..., len(p)-1]
             {."_1     Take that many values from each row of the table
           <@          Box each row of selected values
[:    ;                Unbox and concatenate them
  >./@                 Reduce it by the max and return

Java, 141 bytes
a->java.util.stream.IntStream.range(0,a.size()-1).map(i->a.subList(i+1,a.size()).stream().reduce(Math::max).get()-a.get(i)).max().getAsInt();

The lambda accepts an ArrayList and returns an Integer.
Ungolfed code with test cases:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.function.Function;
import java.util.stream.IntStream;

class Test {

    public static void main(String[] args) {
        Function<ArrayList<Integer>, Integer> f = a -> IntStream
            .range(0, a.size()-1)
            .map(i -> a.subList(i+1, a.size()).stream().reduce(Math::max).get() - a.get(i))
            .max()
            .getAsInt();

        System.out.println(f.apply(new ArrayList<>(Arrays.asList(1,2,3,4,5))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(1,99,2,105))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(99,1,99,100))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(99,1,1,2,1,3))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(5,4,3,3,1))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(5,4,3,1))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(5,2,1))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(5,4,1))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(55,45,20,1))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(5,1))));
        System.out.println(f.apply(new ArrayList<>(Arrays.asList(10,7,5,1))));
    }
}

As far as I know, Java doesn't have a way to look forward in a stream, and manipulating the method from which the stream is generated produces strange results. So doing a.remove(0) inside a map horribly breaks the stream.

Clojure, 99 bytes
(fn[x](apply max(map #(-(apply max(% 1))(apply min(% 0)))(map #(split-at % x)(range 1(count x))))))

Splits input list at first position then second and so on, so we get a list which looks like this:
[[[n1][n2 ... nk]][[n1 n2][n3 ... nk]]...[[n1...n(k-1)][nk]]] then for each pair subtracts minimum of the first elements from max of the second element and then find max from them. Would be shorter if Clojure's min max were taking sequences rather than any number of arguments.
See it online: https://ideone.com/b2nllT

VBA, 154
Takes in the input in column A starting in A1, outputs in C1.  Must be run with the last cell in A selected. Note that Excel auto-adds the spaces between terms in VBA, otherwise this could be golfed further.
Sub s
i = Selection.Row
r = "B1:B" + i-1
Range(r).FormulaArray = "MAX(A2:A$" + i + "-A1)"
Range(r).FillDown
Range("C1").Formula = "MAX(" + r + ")"
End Sub

Java, 116
Another java solution, i used this one to prove that, streams might looks nice, but not always useful for golfing.
int a(int[]a){int t,d=a[1]-a[0],i,j,l=a.length;for(i=0;i<l;i++)for(j=i+1;j<l;j++){t=a[j]-a[i];d=d<t?t:d;}return d;}

there is lot of space for improvements in this solution

ruby, 52 bytes
->a{b=[];(x=a.pop;b+=a.map{|v|x-v})while a[0];b.max}

pops possible sell prices and look at all of the previous to find profit. Then gets max profit.

R, 58 44 bytes
max(unlist(sapply(seq(y<-scan()),diff,x=y)))

ungolfed
y=scan()                #input
s=1:length(y)           #sequence of same length from 1
l = sapply(s,diff,x=y)  #applies the function diff to each 'lag' in sequence s
                        #and differencing on y
max(unlist(l))          #reforms as vector and finds maximum

EDIT: changed function. original below.
f=function(x)max(max(x[-1]-x[1]),if(length(x)-2)f(x[-1]))

or, if you're willing to put up with a bunch of warning messages, get rid of the -2 after length, for 56 bytes.
f=function(x)max(max(x[-1]-x[1]),if(length(x))f(x[-1]))

And if you feel like not trading and losing money when that's the only possibility, you can get down to 52
f=function(x)max(max(x-x[1]),if(length(x))f(x[-1]))

f= isn't needed.

@NoOneIsHere recursion won't work without it. I could use Recall, but it picks up more letters than I lose.

Oh, sorry. I always miss recursion.

C, 101 99 Bytes
int i,j,m,h;int f(int*a){m=1<<31;for(;a[i];i++){for(j=i+1;a[j];h=a[j++]-a[i],m=h<m?m:h);}return m;}

Input: null terminated array. E.g. {1,2,3,4,5,0}
Output: returns the best outcome
You can save 8 bytes (93 91 total) if you never want to lose money:
int i,j,m,h;int f(int*a){for(;a[i];i++){for(j=i+1;a[j];h=a[j++]-a[i],m=h<m?m:h);}return m;}